[LORA] Added WiPhone LoRa support (#1458)
* Added WiPhone LoRa support * Centralised raw-hex functions
This commit is contained in:
4 files changed
+171
-36
No files matched your search
+4
-28
@@ -54,7 +54,7 @@ void _rfbSend(byte* message) {
|
||||
|
||||
void _rfbSend(byte* message, int times) {
|
||||
char buffer[RF_MESSAGE_SIZE];
|
||||
_rfbToChar(message, buffer);
|
||||
_rawToHex(message, buffer, RF_MESSAGE_SIZE);
|
||||
Log.notice(F("[RFBRIDGE] Sending MESSAGE" CR));
|
||||
|
||||
for (int i = 0; i < times; i++) {
|
||||
@@ -99,7 +99,7 @@ void _rfbDecode() {
|
||||
char buffer[RF_MESSAGE_SIZE * 2 + 1] = {0};
|
||||
|
||||
if (action == RF_CODE_RFIN) {
|
||||
_rfbToChar(&_uartbuf[1], buffer);
|
||||
_rawToHex(&_uartbuf[1], buffer, RF_MESSAGE_SIZE);
|
||||
|
||||
Log.trace(F("Creating SRFB buffer" CR));
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
@@ -142,30 +142,6 @@ void _rfbAck() {
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
/*
|
||||
From an hexa char array ("A220EE...") to a byte array (half the size)
|
||||
*/
|
||||
bool _rfbToArray(const char* in, byte* out) {
|
||||
if (strlen(in) != RF_MESSAGE_SIZE * 2)
|
||||
return false;
|
||||
char tmp[3] = {0};
|
||||
for (unsigned char p = 0; p < RF_MESSAGE_SIZE; p++) {
|
||||
memcpy(tmp, &in[p * 2], 2);
|
||||
out[p] = strtol(tmp, NULL, 16);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
From a byte array to an hexa char array ("A220EE...", double the size)
|
||||
*/
|
||||
bool _rfbToChar(byte* in, char* out) {
|
||||
for (unsigned char p = 0; p < RF_MESSAGE_SIZE; p++) {
|
||||
sprintf_P(&out[p * 2], PSTR("%02X" CR), in[p]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
# if simpleReceiving
|
||||
void MQTTtoSRFB(char* topicOri, char* datacallback) {
|
||||
// RF DATA ANALYSIS
|
||||
@@ -255,7 +231,7 @@ void MQTTtoSRFB(char* topicOri, char* datacallback) {
|
||||
valueRPT = 1;
|
||||
|
||||
byte message_b[RF_MESSAGE_SIZE];
|
||||
_rfbToArray(datacallback, message_b);
|
||||
_hexToRaw(datacallback, message_b, RF_MESSAGE_SIZE);
|
||||
_rfbSend(message_b, valueRPT);
|
||||
// Acknowledgement to the GTWRF topic
|
||||
pub(subjectGTWSRFBtoMQTT, datacallback); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
|
||||
@@ -272,7 +248,7 @@ void MQTTtoSRFB(char* topicOri, JsonObject& SRFBdata) {
|
||||
if (raw) { // send raw in priority when defined in the json
|
||||
Log.trace(F("MQTTtoSRFB raw ok" CR));
|
||||
byte message_b[RF_MESSAGE_SIZE];
|
||||
_rfbToArray(raw, message_b);
|
||||
_hexToRaw(raw, message_b, RF_MESSAGE_SIZE);
|
||||
_rfbSend(message_b, valueRPT);
|
||||
} else {
|
||||
unsigned long data = SRFBdata["value"];
|
||||
|
||||
Reference in new issue
Block a user