Refactored MQTT payload handling into separate classes

This commit is contained in:
Gunnar Skjold
2021-01-17 20:11:04 +01:00
parent 53573184f3
commit 33070af111
23 changed files with 803 additions and 502 deletions

23
src/hexutils.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "hexutils.h";
String toHex(uint8_t* in) {
return toHex(in, sizeof(in)*2);
}
String toHex(uint8_t* in, uint8_t size) {
String hex;
for(int i = 0; i < size; i++) {
if(in[i] < 0x10) {
hex += '0';
}
hex += String(in[i], HEX);
}
hex.toUpperCase();
return hex;
}
void fromHex(uint8_t *out, String in, uint8_t size) {
for(int i = 0; i < size*2; i += 2) {
out[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
}
}