Rewrite logging system and sync state with clients

This commit is contained in:
2024-08-28 02:32:34 +02:00
parent 481170792a
commit 9a3ae27a5f
6 changed files with 77 additions and 33 deletions

View File

@@ -9,8 +9,8 @@ int main(void)
char ch;
unsigned long i = 1;
running = true;
USART_Init();
Enable();
for (;;) {
// Process rx ring buffer
@@ -19,13 +19,11 @@ int main(void)
}
Sleep(3000);
if (!running)
continue;
// TODO: Main program
if (i >= 99999) i = 1;
USART_Printf("[CORE] Fetching sensors #%05lu...\r\n", i++);
if (running) {
// TODO: Main program
if (i >= 99999) i = 1;
Info("Fetching sensors #%05lu...", i++);
}
}
return 0;
@@ -33,39 +31,48 @@ int main(void)
void Enable(void)
{
USART_Printf("[CORE] Parsed 'CMD_RUN' token.\r\n");
Info("Parsed 'CMD_RUN' token.");
if (running == true) {
USART_Printf("[CORE] Error: Already running.\r\n");
Error("Already running.");
return;
}
running = true;
SetStateFlag(running);
Info("Program started.");
}
void Disable(void)
{
USART_Printf("[CORE] Parsed 'CMD_STOP' token.\r\n");
Info("Parsed 'CMD_STOP' token.");
if (running == false) {
USART_Printf("[CORE] Error: Already stopped.\r\n");
Error("Already stopped.");
return;
}
running = false;
SetStateFlag(running);
Info("Program stopped.");
}
void SetTemp(long val)
{
USART_Printf("[CORE] Parsed 'CMD_SET_TEMP', VAL='%ld'.\r\n", val);
Info("Parsed 'CMD_SET_TEMP', VAL='%ld'.", val);
if (val < 10) {
USART_Printf("[CORE] Error: Given temperature is too low.\r\n");
Error("Given temperature is too low.");
return;
} else if (val > 40) {
USART_Printf("[CORE] Error: Given temperature is too high.\r\n");
Error("Given temperature is too high.");
return;
}
}
void SetDewp(long val)
{
USART_Printf("[CORE] Parsed 'CMD_SET_DEWP', VAL='%ld'.\r\n", val);
Info("Parsed 'CMD_SET_DEWP', VAL='%ld'.", val);
if (val < 10) {
USART_Printf("[CORE] Error: Given dew point is too low.\r\n");
Error("Given dew point is too low.");
return;
} else if (val > 80) {
USART_Printf("[CORE] Error: Given dew point is too high.\r\n");
Error("Given dew point is too high.");
return;
}
}