mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-30 21:49:33 +00:00
Changed fromHex() to use an supplied buffer
Solves the problem with returning a pointer to local variable. Signed-off-by: Karl Thorén <karl.h.thoren@gmail.com>
This commit is contained in:
@@ -147,7 +147,9 @@ void AmsWebServer::temperaturePost() {
|
|||||||
if(debugger->isActive(RemoteDebug::DEBUG)) {
|
if(debugger->isActive(RemoteDebug::DEBUG)) {
|
||||||
debugger->printf("Addr: %s, name: %s\n", address.c_str(), name.c_str());
|
debugger->printf("Addr: %s, name: %s\n", address.c_str(), name.c_str());
|
||||||
}
|
}
|
||||||
config->updateTempSensorConfig(fromHex(address, 8), name.c_str(), common);
|
uint8_t hexStr[8];
|
||||||
|
fromHex(hexStr, address, 8);
|
||||||
|
config->updateTempSensorConfig(hexStr, name.c_str(), common);
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,12 +345,10 @@ String AmsWebServer::toHex(uint8_t* in, uint8_t size) {
|
|||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* AmsWebServer::fromHex(String in, uint8_t size) {
|
void AmsWebServer::fromHex(uint8_t *out, String in, uint8_t size) {
|
||||||
uint8_t ret[size];
|
|
||||||
for(int i = 0; i < size*2; i += 2) {
|
for(int i = 0; i < size*2; i += 2) {
|
||||||
ret[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
|
out[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmsWebServer::configWifiHtml() {
|
void AmsWebServer::configWifiHtml() {
|
||||||
@@ -786,13 +786,18 @@ void AmsWebServer::handleSave() {
|
|||||||
String encryptionKeyHex = server.arg("meterEncryptionKey");
|
String encryptionKeyHex = server.arg("meterEncryptionKey");
|
||||||
if(!encryptionKeyHex.isEmpty()) {
|
if(!encryptionKeyHex.isEmpty()) {
|
||||||
encryptionKeyHex.replace("0x", "");
|
encryptionKeyHex.replace("0x", "");
|
||||||
config->setMeterEncryptionKey(fromHex(encryptionKeyHex, 16));
|
uint8_t hexStr[16];
|
||||||
|
fromHex(hexStr, encryptionKeyHex, 16);
|
||||||
|
config->setMeterEncryptionKey(hexStr);
|
||||||
}
|
}
|
||||||
|
printD("Meter 8");
|
||||||
|
|
||||||
String authenticationKeyHex = server.arg("meterAuthenticationKey");
|
String authenticationKeyHex = server.arg("meterAuthenticationKey");
|
||||||
if(!authenticationKeyHex.isEmpty()) {
|
if(!authenticationKeyHex.isEmpty()) {
|
||||||
authenticationKeyHex.replace("0x", "");
|
authenticationKeyHex.replace("0x", "");
|
||||||
config->setMeterAuthenticationKey(fromHex(authenticationKeyHex, 16));
|
uint8_t hexStr[16];
|
||||||
|
fromHex(hexStr, encryptionKeyHex, 16);
|
||||||
|
config->setMeterAuthenticationKey(hexStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ private:
|
|||||||
void notFound();
|
void notFound();
|
||||||
|
|
||||||
String toHex(uint8_t* in, uint8_t size);
|
String toHex(uint8_t* in, uint8_t size);
|
||||||
uint8_t* fromHex(String in, uint8_t size);
|
void fromHex(uint8_t *out, String in, uint8_t size);
|
||||||
|
|
||||||
void printD(String fmt, ...);
|
void printD(String fmt, ...);
|
||||||
void printI(String fmt, ...);
|
void printI(String fmt, ...);
|
||||||
|
|||||||
Reference in New Issue
Block a user