diff --git a/TestList.csv b/TestList.csv index 598e60c..5686696 100644 --- a/TestList.csv +++ b/TestList.csv @@ -28,5 +28,5 @@ 30,Marketa,Rezacova,3039,1,0,0 31,Libor,Hanak,3040,1747561377,0,1 32,Libor,Hanak,3040,1,0,0 -17767,Grzegorz,Brzeczyszczykiewicz,2502,0,0,0 -9158,Zima,Tomas,2440,1747561372,0,1 +17767,Grzegorz,Brzeczyszczykiewicz,2502,1747576503,0,1 +9158,Tomas,Zima,2440,1747573483,12084,1 diff --git a/include/rfid_handler.h b/include/rfid_handler.h index d8ecc4f..0085830 100644 --- a/include/rfid_handler.h +++ b/include/rfid_handler.h @@ -24,6 +24,6 @@ void *uartListener(void *arg); uint16_t parseIncommingPacket(BYTE *_packet); -void sendPacketToDevice(int _uart, node_t *_person); +void sendPacketToDevice(int _uart, node_t *_person, BYTE state); #endif diff --git a/src/rfid_handler.c b/src/rfid_handler.c index f0b3920..6112507 100644 --- a/src/rfid_handler.c +++ b/src/rfid_handler.c @@ -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, ¤t_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); } \ No newline at end of file diff --git a/src/tui.c b/src/tui.c index 8118068..8f4a0c9 100644 --- a/src/tui.c +++ b/src/tui.c @@ -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; diff --git a/src/users.c b/src/users.c index fa28571..794feb9 100644 --- a/src/users.c +++ b/src/users.c @@ -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)