nicer solution skipping loracommand header

This commit is contained in:
Theo Arends 2024-05-21 17:10:19 +02:00
parent 08afd40823
commit 140e4791aa
1 changed files with 8 additions and 6 deletions

View File

@ -200,6 +200,7 @@ void LoraInput(void) {
#endif // USE_LORAWAN_BRIDGE #endif // USE_LORAWAN_BRIDGE
Lora->receive_time = 0; Lora->receive_time = 0;
char *rcvd_data = data;
if (TAS_LORA_REMOTE_COMMAND == data[0]) { if (TAS_LORA_REMOTE_COMMAND == data[0]) {
char *payload = data +1; // Skip TAS_LORA_REMOTE_COMMAND char *payload = data +1; // Skip TAS_LORA_REMOTE_COMMAND
char *command_part; char *command_part;
@ -212,7 +213,8 @@ void LoraInput(void) {
} }
} else { } else {
*--command_part = ' '; // Restore strtok_r '/0' *--command_part = ' '; // Restore strtok_r '/0'
data[0] = ' '; // Remove TAS_LORA_REMOTE_COMMAND header rcvd_data++; // Remove TAS_LORA_REMOTE_COMMAND header
packet_size--;
} }
} }
} }
@ -220,21 +222,21 @@ void LoraInput(void) {
bool raw = Lora->raw; bool raw = Lora->raw;
// Set raw mode if zeroes within data // Set raw mode if zeroes within data
for (uint32_t i = 0; i < packet_size; i++) { for (uint32_t i = 0; i < packet_size; i++) {
if (0 == data[i]) { if (0 == rcvd_data[i]) {
raw = true; raw = true;
break; break;
} }
} }
bool assume_json = (!raw && (data[0] == '{')); bool assume_json = (!raw && (rcvd_data[0] == '{'));
Response_P(PSTR("{\"LoRaReceived\":")); Response_P(PSTR("{\"LoRaReceived\":"));
if (assume_json) { if (assume_json) {
ResponseAppend_P(data); ResponseAppend_P(rcvd_data);
} else { } else {
ResponseAppend_P(PSTR("\"")); ResponseAppend_P(PSTR("\""));
if (raw) { if (raw) {
ResponseAppend_P(PSTR("%*_H"), packet_size, data); ResponseAppend_P(PSTR("%*_H"), packet_size, rcvd_data);
} else { } else {
ResponseAppend_P(EscapeJSONString(data).c_str()); ResponseAppend_P(EscapeJSONString(rcvd_data).c_str());
} }
ResponseAppend_P(PSTR("\"")); ResponseAppend_P(PSTR("\""));
} }