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
+39 -13
View File
@@ -129,14 +129,16 @@ void *uartListener(void *arg)
if (crc == packet[5])
{
BYTE success;
uint16_t r_uuid = parseIncommingPacket(packet);
node_t *selected = searchPersonByUUID(person_list, r_uuid);
addTimeEvent(selected, person_list);
//sendPacketToDevice(uart, selected);
success = addTimeEvent(selected, person_list);
sendPacketToDevice(uart, selected, success);
}
else
{
// fprintf(stderr, "Chyba CRC!\n");
//fprintf(stderr, "Chyba CRC!\n");
sendPacketToDevice(uart, NULL, 0);
}
state = SYNC0;
}
@@ -158,20 +160,43 @@ uint16_t parseIncommingPacket(BYTE *_packet)
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;
packet[0] = 0xFF;
packet[1] = 0X55;
offset += 2;
memcpy(packet + offset, _person->user.name, 32);
offset += 32;
memcpy(packet + offset, _person->user.surname, 32);
offset += 32;
packet[1] = 0x55;
packet[2] = state;
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;
memset(packet + offset, 0, 32);
if (_person->user.surname)
{
strncpy((char *)(packet + offset), _person->user.surname, 31);
packet[offset + 31] = '\0';
}
offset += 32;
}
else
{
memset(packet + offset, 0, 64);
offset += 64;
}
time_t current_time = time(NULL);
memcpy(packet + offset, &current_time, sizeof(time_t));
offset += time(NULL);
offset += sizeof(time_t);
BYTE crc = 0;
for (int i = 0; i < offset; i++)
{
@@ -179,5 +204,6 @@ void sendPacketToDevice(int _uart, node_t *_person)
}
packet[offset] = crc;
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)
{
if (_person == NULL || _list == NULL)
{
return;
}
int win_height = 14;
int win_width = 60;
int start_y = (terminal_y - win_height) / 2;
+7 -1
View File
@@ -245,6 +245,7 @@ int addTimeEvent(
list_t *_list)
{
time_t current_time = time(0);
BYTE type;
if (_person == NULL)
{
@@ -261,10 +262,15 @@ int addTimeEvent(
}
_person->user.available = !_person->user.available;
if (_person->user.available == TRUE)
type = 1;
else
type = 2;
_person->user.last_time_event = current_time;
pthread_mutex_unlock(&_list->lock);
return 1;
return type;
}
int removePersonFromList(list_t *_list, node_t **_person)