test-kod-bez/src/main.c
2025-10-24 09:04:29 +03:00

69 lines
1.2 KiB
C

#include "main.h"
#if __cplusplus
#pragma message ("plus")
#else
#pragma message ("pure")
#endif
// Перечисление статусов машины состояния
enum bigLoopOsState_e {
OS_first = 0,
OS_masterWorker,
OS_slaveWorker,
OS_wait,
OS_last
} bigLoopOsState;
// Текстовые надписи соответствующие статусам машины состояния
const char* bigLoopOsStateNames[OS_last] = {
"starting...",
"master worker",
"slave worker",
"waiting"
};
// BIG LOOP OS
int main(void) {
bigLoopOsState = OS_first;
while(1) {
if (bigLoopOsState == OS_last) {
bigLoopOsState = OS_first;
}
printf("OS: Current state is: %s\n", bigLoopOsStateNames[bigLoopOsState]);
switch (bigLoopOsState) {
case OS_first:
break;
case OS_masterWorker:
WORK_master();
break;
case OS_slaveWorker:
WORK_slave();
break;
case OS_wait:
sleep (1);
break;
default:
printf("OS: Wrong state, going to first state");
bigLoopOsState = OS_first;
sleep (3);
printf("\033[2J\033[H");
break;
}
bigLoopOsState++;
// Для контроля
sleep (1);
}
return 0;
}