add some OTA helpers
This commit is contained in:
parent
ea8535ffc8
commit
b7ee0b32b0
|
|
@ -547,6 +547,34 @@ void PrintHex83(uint8_t* data, uint8_t length)
|
|||
Serial.println();
|
||||
}
|
||||
|
||||
//===================================================================================================================
|
||||
// bufferChecksum() - compute 1 byte checksum on a byte stream
|
||||
//===================================================================================================================
|
||||
uint8_t bufferChecksum(uint8_t* buffer, uint8_t length) {
|
||||
uint8_t checksum=0;
|
||||
for (uint8_t i=0;i<length;i++)
|
||||
checksum += buffer[i];
|
||||
return (checksum^0xFF)+1;
|
||||
}
|
||||
|
||||
//===================================================================================================================
|
||||
// prepareSendBuffer() - returns the final size of the buf
|
||||
//===================================================================================================================
|
||||
uint8_t prepareStoreBuffer(char* hexdata, uint8_t*buf, uint8_t length) {
|
||||
for (uint8_t i=0; i<length;i++)
|
||||
buf[i] = BYTEfromHEX(hexdata[i*2], hexdata[i*2+1]);
|
||||
return length;
|
||||
}
|
||||
|
||||
//===================================================================================================================
|
||||
// validHexString() - walk a char stream and check all chars are valid ascii HEX chars
|
||||
//===================================================================================================================
|
||||
uint8_t validHexString(char* hex, uint16_t expectedByteCount) {
|
||||
for (uint16_t i=0;i<expectedByteCount*2;i++)
|
||||
if (hex[i]<48 || (hex[i]>57 && hex[i]< 65) || hex[i]>70) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//===================================================================================================================
|
||||
// resetUsingWatchdog() - Use watchdog to reset the MCU
|
||||
//===================================================================================================================
|
||||
|
|
|
|||
|
|
@ -78,5 +78,8 @@ uint8_t sendHEXPacket(RFM69& radio, uint16_t remoteID, uint8_t* sendBuf, uint8_t
|
|||
uint8_t BYTEfromHEX(char MSB, char LSB);
|
||||
uint8_t readSerialLine(char* input, char endOfLineChar=10, uint8_t maxLength=115, uint16_t timeout=1000);
|
||||
void PrintHex83(uint8_t* data, uint8_t length);
|
||||
uint8_t bufferChecksum(uint8_t* buffer, uint8_t length);
|
||||
uint8_t prepareStoreBuffer(char* hexdata, uint8_t*buf, uint8_t length);
|
||||
uint8_t validHexString(char* hex, uint16_t expectedByteCount);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue