Refactor UART handling and TUI integration: update UART thread structure and improve dialog management for better user experience.

This commit is contained in:
2025-05-18 16:38:04 +02:00
parent 9e6dfc7d0e
commit 12749c4552
5 changed files with 53 additions and 17 deletions
+2 -2
View File
@@ -28,5 +28,5 @@
30,Marketa,Rezacova,3039,1,0,0 30,Marketa,Rezacova,3039,1,0,0
31,Libor,Hanak,3040,1747561377,0,1 31,Libor,Hanak,3040,1747561377,0,1
32,Libor,Hanak,3040,1,0,0 32,Libor,Hanak,3040,1,0,0
17767,Grzegorz,Brzeczyszczykiewicz,2502,0,0,0 17767,Grzegorz,Brzeczyszczykiewicz,2502,1747576503,0,1
9158,Zima,Tomas,2440,1747561372,0,1 9158,Tomas,Zima,2440,1747573483,12084,1
1 1 Klara Novotna 3010 1 0 0
28 30 Marketa Rezacova 3039 1 0 0
29 31 Libor Hanak 3040 1747561377 0 1
30 32 Libor Hanak 3040 1 0 0
31 17767 Grzegorz Brzeczyszczykiewicz 2502 0 1747576503 0 0 1
32 9158 Zima Tomas Tomas Zima 2440 1747561372 1747573483 0 12084 1
+1 -1
View File
@@ -24,6 +24,6 @@ void *uartListener(void *arg);
uint16_t parseIncommingPacket(BYTE *_packet); uint16_t parseIncommingPacket(BYTE *_packet);
void sendPacketToDevice(int _uart, node_t *_person); void sendPacketToDevice(int _uart, node_t *_person, BYTE state);
#endif #endif
+37 -11
View File
@@ -129,14 +129,16 @@ void *uartListener(void *arg)
if (crc == packet[5]) if (crc == packet[5])
{ {
BYTE success;
uint16_t r_uuid = parseIncommingPacket(packet); uint16_t r_uuid = parseIncommingPacket(packet);
node_t *selected = searchPersonByUUID(person_list, r_uuid); node_t *selected = searchPersonByUUID(person_list, r_uuid);
addTimeEvent(selected, person_list); success = addTimeEvent(selected, person_list);
//sendPacketToDevice(uart, selected); sendPacketToDevice(uart, selected, success);
} }
else else
{ {
// fprintf(stderr, "Chyba CRC!\n"); //fprintf(stderr, "Chyba CRC!\n");
sendPacketToDevice(uart, NULL, 0);
} }
state = SYNC0; state = SYNC0;
} }
@@ -158,20 +160,43 @@ uint16_t parseIncommingPacket(BYTE *_packet)
return r_id; return r_id;
} }
void sendPacketToDevice(int _uart, node_t *_person) void sendPacketToDevice(int _uart, node_t *_person, BYTE state)
{ {
BYTE packet[72]; BYTE packet[76];
int offset = 0; int offset = 0;
packet[0] = 0xFF; packet[0] = 0xFF;
packet[1] = 0X55; packet[1] = 0x55;
offset += 2; packet[2] = state;
memcpy(packet + offset, _person->user.name, 32); offset += 3;
if (_person)
{
memset(packet + offset, 0, 32);
if (_person->user.name)
{
strncpy((char *)(packet + offset), _person->user.name, 31);
packet[offset + 31] = '\0';
}
offset += 32; offset += 32;
memcpy(packet + offset, _person->user.surname, 32);
memset(packet + offset, 0, 32);
if (_person->user.surname)
{
strncpy((char *)(packet + offset), _person->user.surname, 31);
packet[offset + 31] = '\0';
}
offset += 32; offset += 32;
}
else
{
memset(packet + offset, 0, 64);
offset += 64;
}
time_t current_time = time(NULL); time_t current_time = time(NULL);
memcpy(packet + offset, &current_time, sizeof(time_t)); memcpy(packet + offset, &current_time, sizeof(time_t));
offset += time(NULL); offset += sizeof(time_t);
BYTE crc = 0; BYTE crc = 0;
for (int i = 0; i < offset; i++) for (int i = 0; i < offset; i++)
{ {
@@ -179,5 +204,6 @@ void sendPacketToDevice(int _uart, node_t *_person)
} }
packet[offset] = crc; packet[offset] = crc;
offset += 1; offset += 1;
write(_uart, packet, 72);
write(_uart, packet, offset);
} }
+4
View File
@@ -484,6 +484,10 @@ void personSearch(list_t *person_list, int terminal_x, int terminal_y)
void personInfo(list_t *_list, node_t *_person, int terminal_x, int terminal_y) void personInfo(list_t *_list, node_t *_person, int terminal_x, int terminal_y)
{ {
if (_person == NULL || _list == NULL)
{
return;
}
int win_height = 14; int win_height = 14;
int win_width = 60; int win_width = 60;
int start_y = (terminal_y - win_height) / 2; int start_y = (terminal_y - win_height) / 2;
+7 -1
View File
@@ -245,6 +245,7 @@ int addTimeEvent(
list_t *_list) list_t *_list)
{ {
time_t current_time = time(0); time_t current_time = time(0);
BYTE type;
if (_person == NULL) if (_person == NULL)
{ {
@@ -261,10 +262,15 @@ int addTimeEvent(
} }
_person->user.available = !_person->user.available; _person->user.available = !_person->user.available;
if (_person->user.available == TRUE)
type = 1;
else
type = 2;
_person->user.last_time_event = current_time; _person->user.last_time_event = current_time;
pthread_mutex_unlock(&_list->lock); pthread_mutex_unlock(&_list->lock);
return 1; return type;
} }
int removePersonFromList(list_t *_list, node_t **_person) int removePersonFromList(list_t *_list, node_t **_person)