Skip to content

Commit

Permalink
sprintf replaced, saving lot of flash
Browse files Browse the repository at this point in the history
watchdog timer enabled by default
  • Loading branch information
loetmeister committed Jun 30, 2021
1 parent e1587fe commit 834c460
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 15 additions & 6 deletions libraries/src/HBWired.cpp
Expand Up @@ -550,7 +550,7 @@ void HBWDevice::processEvent(byte const * const frameData, byte frameDataLength,
processEventSetLock(frameData[2], frameData[3] & 0x01);
break;
case 'n': // Seriennummer
determineSerial(txFrame.data);
determineSerial(txFrame.data, getOwnAddress());
txFrame.dataLength = 10;
onlyAck = false;
break;
Expand Down Expand Up @@ -672,7 +672,7 @@ byte HBWDevice::broadcastAnnounce(byte channel) {
txFrame.data[3] = hardware_version;
txFrame.data[4] = firmware_version / 0x100;
txFrame.data[5] = firmware_version & 0xFF;
determineSerial(txFrame.data + 6);
determineSerial(txFrame.data + 6, getOwnAddress());
// only send, if bus is free. Don't send in zeroCommunication mode, return with "bus busy" instead
return (pendingActions.zeroCommunicationActive ? BUS_BUSY : sendFrame(true));
};
Expand Down Expand Up @@ -786,13 +786,22 @@ void HBWDevice::readAddressFromEEPROM(){
}


void HBWDevice::determineSerial(byte* buf) {
char numAsStr[20];
sprintf(numAsStr, "%07lu", getOwnAddress() % 10000000L );
void HBWDevice::determineSerial(uint8_t* buf, uint32_t address) {

buf[0] = 'H';
buf[1] = 'B';
buf[2] = 'W';
memcpy(buf+3, numAsStr, 7);

// append last 7 digits of own address
uint8_t* pEnd = &buf[9];
while (pEnd != &buf[2])
{
*pEnd-- = '0' + (address % 10); // store as string
if (address)
{
address /= 10;
}
}
};


Expand Down
6 changes: 3 additions & 3 deletions libraries/src/HBWired.h
Expand Up @@ -19,7 +19,7 @@
// #define Support_HBWLink_InfoEvent

// #define Support_ModuleReset // enable reset comand, to restart module "!!" (hexstring 2121)
// #define Support_WDT // enable 1 second watchdog timer
#define Support_WDT // enable 1 second watchdog timer


class HBWDevice;
Expand Down Expand Up @@ -151,7 +151,7 @@ class HBWDevice {
NO_ACK // 2 -> three times no ACK (cannot occur for broadcasts or ACKs)
};

private:
private:
uint8_t numChannels; // number of channels
HBWChannel** channels; // channels
HBWLinkSender* linkSender;
Expand Down Expand Up @@ -228,7 +228,7 @@ class HBWDevice {
void crc16Shift(uint8_t, uint16_t*);

void readAddressFromEEPROM();
void determineSerial(uint8_t*);
void determineSerial(uint8_t*, uint32_t address);

void processEventGetLevel(uint8_t channel, uint8_t command);
void processEventSetLock(uint8_t channel, boolean inhibit);
Expand Down

0 comments on commit 834c460

Please sign in to comment.