Fixed Bug in LoRa Uart Parser, because I'm stupid
This commit is contained in:
parent
0967b6aa65
commit
b66d175948
@ -98,6 +98,7 @@ void LoRa_Process()
|
|||||||
static char packageInput[32];
|
static char packageInput[32];
|
||||||
static bool packageRecieved = false;
|
static bool packageRecieved = false;
|
||||||
static unsigned int bufferPtr = 0;
|
static unsigned int bufferPtr = 0;
|
||||||
|
int recievedSize = 0;
|
||||||
|
|
||||||
while (SerialLoRa.available() && packageRecieved == false)
|
while (SerialLoRa.available() && packageRecieved == false)
|
||||||
{
|
{
|
||||||
@ -109,6 +110,7 @@ void LoRa_Process()
|
|||||||
if (packageInput[bufferPtr] == '\n')
|
if (packageInput[bufferPtr] == '\n')
|
||||||
{
|
{
|
||||||
packageRecieved = true;
|
packageRecieved = true;
|
||||||
|
recievedSize = bufferPtr;
|
||||||
bufferPtr = 0;
|
bufferPtr = 0;
|
||||||
Debug_pushMessage("Got LoRa UART: %s\n", packageInput);
|
Debug_pushMessage("Got LoRa UART: %s\n", packageInput);
|
||||||
}
|
}
|
||||||
@ -119,8 +121,10 @@ void LoRa_Process()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageRecieved)
|
if (packageRecieved) {
|
||||||
Parse_LoRa_UartCommand(packageInput, bufferPtr);
|
Parse_LoRa_UartCommand(packageInput, recievedSize);
|
||||||
|
packageRecieved = false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -234,6 +238,7 @@ void printParameters(struct Configuration configuration)
|
|||||||
void Parse_LoRa_UartCommand(char input[], int size)
|
void Parse_LoRa_UartCommand(char input[], int size)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Debug_pushMessage("Start parsing, size: %d", size);
|
||||||
char delimiter[] = ";";
|
char delimiter[] = ";";
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char command[8];
|
char command[8];
|
||||||
@ -241,11 +246,28 @@ void Parse_LoRa_UartCommand(char input[], int size)
|
|||||||
|
|
||||||
ptr = strtok(input, delimiter);
|
ptr = strtok(input, delimiter);
|
||||||
|
|
||||||
|
ptr = strtok(input, delimiter);
|
||||||
|
|
||||||
while (ptr != NULL)
|
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);
|
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);
|
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"))
|
if (!strcmp(command, "ENABLE"))
|
||||||
{
|
{
|
||||||
globals.timer_disabled = false;
|
globals.timer_disabled = false;
|
||||||
|
Debug_pushMessage("Enabled by LoRa");
|
||||||
}
|
}
|
||||||
else if (!strcmp(command, "DISABLE"))
|
else if (!strcmp(command, "DISABLE"))
|
||||||
{
|
{
|
||||||
globals.timer_disabled = false;
|
globals.timer_disabled = true;
|
||||||
|
Debug_pushMessage("Disabled by LoRa");
|
||||||
}
|
}
|
||||||
else if (!strcmp(command, "RESET"))
|
else if (!strcmp(command, "RESET"))
|
||||||
{
|
{
|
||||||
@ -264,6 +288,7 @@ void Parse_LoRa_UartCommand(char input[], int size)
|
|||||||
PersistenceData.faction_1_timer = 0;
|
PersistenceData.faction_1_timer = 0;
|
||||||
PersistenceData.faction_2_timer = 0;
|
PersistenceData.faction_2_timer = 0;
|
||||||
PersistenceData.faction_3_timer = 0;
|
PersistenceData.faction_3_timer = 0;
|
||||||
|
Debug_pushMessage("Reset by LoRa");
|
||||||
}
|
}
|
||||||
else if (!strcmp(command, "TMRSTP"))
|
else if (!strcmp(command, "TMRSTP"))
|
||||||
{
|
{
|
||||||
|
@ -352,7 +352,7 @@ void tmrCallback_InputGetter()
|
|||||||
return;
|
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)
|
if (PersistenceData.activeFaction != FACTION_1)
|
||||||
{
|
{
|
||||||
@ -362,7 +362,7 @@ void tmrCallback_InputGetter()
|
|||||||
PersistenceData.activeFaction = FACTION_1;
|
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)
|
if (PersistenceData.activeFaction != FACTION_2)
|
||||||
{
|
{
|
||||||
@ -372,7 +372,7 @@ void tmrCallback_InputGetter()
|
|||||||
PersistenceData.activeFaction = FACTION_2;
|
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)
|
if (PersistenceData.activeFaction != FACTION_3)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user