diff --git a/Software/src/lora_net.cpp b/Software/src/lora_net.cpp index 870c995..3ee05ee 100644 --- a/Software/src/lora_net.cpp +++ b/Software/src/lora_net.cpp @@ -98,6 +98,7 @@ void LoRa_Process() static char packageInput[32]; static bool packageRecieved = false; static unsigned int bufferPtr = 0; + int recievedSize = 0; while (SerialLoRa.available() && packageRecieved == false) { @@ -109,6 +110,7 @@ void LoRa_Process() if (packageInput[bufferPtr] == '\n') { packageRecieved = true; + recievedSize = bufferPtr; bufferPtr = 0; Debug_pushMessage("Got LoRa UART: %s\n", packageInput); } @@ -119,8 +121,10 @@ void LoRa_Process() } } - if (packageRecieved) - Parse_LoRa_UartCommand(packageInput, bufferPtr); + if (packageRecieved) { + Parse_LoRa_UartCommand(packageInput, recievedSize); + packageRecieved = false; + } #endif } @@ -234,6 +238,7 @@ void printParameters(struct Configuration configuration) void Parse_LoRa_UartCommand(char input[], int size) { + Debug_pushMessage("Start parsing, size: %d", size); char delimiter[] = ";"; char *ptr; char command[8]; @@ -241,11 +246,28 @@ void Parse_LoRa_UartCommand(char input[], int size) ptr = strtok(input, delimiter); + ptr = strtok(input, delimiter); + while (ptr != NULL) { - strncpy(command, ptr, sizeof(command)); + strncpy(command, ptr, sizeof(command) - 1); // Platz für Nullterminator lassen + command[sizeof(command) - 1] = '\0'; // Nullterminator setzen + ptr = strtok(NULL, delimiter); - strncpy(value, ptr, sizeof(value)); + + if (ptr != NULL) + { + strncpy(value, ptr, sizeof(value) - 1); // Platz für Nullterminator lassen + value[sizeof(value) - 1] = '\0'; // Nullterminator setzen + } + else + { + // Wenn ptr NULL ist, setze value auf leeren String + value[0] = '\0'; + } + + // Hier kannst du den Wert und das Kommando verarbeiten + Debug_pushMessage("Command: %s, Value: %s", command, value); } Debug_pushMessage("Parsed LoRa UART Command: %s Value: %s\n", command, value); @@ -253,10 +275,12 @@ void Parse_LoRa_UartCommand(char input[], int size) if (!strcmp(command, "ENABLE")) { globals.timer_disabled = false; + Debug_pushMessage("Enabled by LoRa"); } else if (!strcmp(command, "DISABLE")) { - globals.timer_disabled = false; + globals.timer_disabled = true; + Debug_pushMessage("Disabled by LoRa"); } else if (!strcmp(command, "RESET")) { @@ -264,6 +288,7 @@ void Parse_LoRa_UartCommand(char input[], int size) PersistenceData.faction_1_timer = 0; PersistenceData.faction_2_timer = 0; PersistenceData.faction_3_timer = 0; + Debug_pushMessage("Reset by LoRa"); } else if (!strcmp(command, "TMRSTP")) { diff --git a/Software/src/main.cpp b/Software/src/main.cpp index add8513..eaaee27 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -352,7 +352,7 @@ void tmrCallback_InputGetter() return; } - if (btnState[0] == FAC_1_TRG_PRESSED && globals.timer_disabled == false) + if (btnState[0] == FAC_1_TRG_PRESSED && globals.timer_disabled != true) { if (PersistenceData.activeFaction != FACTION_1) { @@ -362,7 +362,7 @@ void tmrCallback_InputGetter() PersistenceData.activeFaction = FACTION_1; } - if (btnState[1] == FAC_2_TRG_PRESSED && globals.timer_disabled == false) + if (btnState[1] == FAC_2_TRG_PRESSED && globals.timer_disabled != true) { if (PersistenceData.activeFaction != FACTION_2) { @@ -372,7 +372,7 @@ void tmrCallback_InputGetter() PersistenceData.activeFaction = FACTION_2; } - if (btnState[2] == FAC_3_TRG_PRESSED && globals.timer_disabled == false) + if (btnState[2] == FAC_3_TRG_PRESSED && globals.timer_disabled != true) { if (PersistenceData.activeFaction != FACTION_3) {