Srfb bugs (#807)

* Correct buffer processing

was missing an instruction due to a previous refactoring

* Correct duplicate condition

* Avoid publishing \n into the raw value

* Merge extract_char and value_from_service_data functions
This commit is contained in:
Florian authored and GitHub committed 2020-11-28 17:16:15 -06:00
1 parent fd2d25bf31
commit b2c05156b2
4 files changed
+51 -73

No files matched your search

+22 -14
View File
@@ -28,7 +28,7 @@
#include "User_config.h"
// Macros and structure to enable the duplicates removing on the following gateways
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
// array to store previous received RFs, IRs codes and their timestamps
struct ReceivedSignal {
SIGNAL_SIZE_UL_ULL value;
@@ -223,19 +223,27 @@ void revert_hex_data(const char* in, char* out, int l) {
out[l - 1] = '\0';
}
void extract_char(const char* token_char, char* subset, int start, int l, bool reverse, bool isNumber) {
if (isNumber) {
if (reverse)
revert_hex_data(token_char + start, subset, l + 1);
long long_value = strtoul(subset, NULL, 16);
sprintf(subset, "%ld", long_value);
/**
* Retrieve an unsigned long value from a char array extract representing hexadecimal data, reversed or not,
* This value can represent a negative value if canBeNegative is set to true
*/
long value_from_hex_data(const char* service_data, int offset, int data_length, bool reverse, bool canBeNegative = true) {
char data[data_length + 1];
memcpy(data, &service_data[offset], data_length);
data[data_length] = '\0';
long value;
if (reverse) {
// reverse data order
char rev_data[data_length + 1];
revert_hex_data(data, rev_data, data_length + 1);
value = strtol(rev_data, NULL, 16);
} else {
if (reverse)
revert_hex_data(token_char + start, subset, l + 1);
else
strncpy(subset, token_char + start, l + 1);
value = strtol(data, NULL, 16);
}
subset[l] = '\0';
if (value > 65000 && data_length <= 4 && canBeNegative)
value = value - 65535;
Log.trace(F("value %D" CR), value);
return value;
}
char* ip2CharArray(IPAddress ip) { //from Nick Lee https://stackoverflow.com/questions/28119653/arduino-display-ethernet-localip
@@ -1402,7 +1410,7 @@ void stateMeasures() {
}
#endif
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
/**
* Store signal values from RF, IR, SRFB or Weather stations so as to avoid duplicates
*/
@@ -1460,7 +1468,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& jsondata = jsonBuffer.parseObject(datacallback);
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
if (strstr(topicOri, subjectMultiGTWKey) != NULL) { // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway
SIGNAL_SIZE_UL_ULL data = jsondata.success() ? jsondata["value"] : STRTO_UL_ULL(datacallback, NULL, 10);
if (data != 0 && !isAduplicateSignal(data)) {