Refactor header inclusions and add main.h; implement searchPersonByUUID and addTimeEvent functions in users.c

This commit is contained in:
2025-04-24 19:53:52 +02:00
parent d60fcba0c8
commit e23ed280d8
9 changed files with 84 additions and 5 deletions
+2 -1
View File
@@ -5,7 +5,8 @@
"stdlib.h": "c",
"errno.h": "c",
"rfid_handler.h": "c",
"fcntl.h": "c"
"fcntl.h": "c",
"file_operations.h": "c"
},
"C_Cpp.errorSquiggles": "enabled"
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifndef __MAIN_H__
#define __MAIN_H__
#define TRUE 1
#define FALSE 0
#define BYTE uint8_t
#define MIN_X_TERMINAL_SIZE 80
#define MIN_Y_TERMINAL_SIZE 30
int main(int argc, char const **argv);
#endif
+1 -2
View File
@@ -4,9 +4,8 @@
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#define MIN_X_TERMINAL_SIZE 80
#define MIN_Y_TERMINAL_SIZE 30
void uartDialog(char *uart_adress, int terminal_x, int terminal_y);
+17 -2
View File
@@ -1,3 +1,5 @@
#include "main.h"
#include <stdint.h>
#include <time.h>
#include <unistd.h>
@@ -15,7 +17,9 @@ typedef struct person
uint32_t department;
time_t last_time_event;
uint32_t total;
time_t total;
BYTE available;
pthread_mutex_t lock;
} person_t;
@@ -40,7 +44,18 @@ uint16_t generateUUID(node_t *_head);
uint16_t searchUUIDByName(node_t *_head);
node_t *searchPersonByUUID(node_t *_head);
/**
* @brief Searches for a person in a linked list by their UUID.
*
* This function traverses a linked list starting from the given head node
* and searches for a node that matches the specified UUID.
*
* @param _head Pointer to the head node of the linked list.
* @param _uuid The UUID of the person to search for.
* @return Pointer to the node containing the person with the matching UUID,
* or NULL if no such person is found.
*/
node_t *searchPersonByUUID(node_t *_head, uint16_t _uuid);
/**
* @brief Adds a new person to the linked list.
BIN
View File
Binary file not shown.
+1
View File
@@ -12,6 +12,7 @@
#include "tui.h"
#include "rfid_handler.h"
#include "file_operations.h"
#include "main.h"
int main(int argc, char const **argv)
{
+1
View File
@@ -1,5 +1,6 @@
#include "rfid_handler.h"
#include "users.h"
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
+2
View File
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "main.h"
void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
{
+44
View File
@@ -1,4 +1,6 @@
#include "users.h"
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
@@ -31,6 +33,24 @@ uint16_t generateUUID
return uuid;
}
node_t *searchPersonByUUID
(
node_t *_head,
uint16_t _uuid
)
{
node_t *current = _head;
while (current != NULL)
{
if (current->user.uuid == _uuid)
{
return current;
}
current = current->next;
}
return NULL;
};
int addPersonToList
(
node_t **_head,
@@ -67,6 +87,7 @@ int addPersonToList
new_node->user.department = _department;
new_node->user.last_time_event = -255;
new_node->user.total = 0;
new_node->user.available = FALSE;
new_node->next = NULL;
@@ -83,5 +104,28 @@ int addPersonToList
}
current->next = new_node;
return 1;
}
int addTimeEvent
(
node_t *_person
)
{
time_t current_time = time(0);
if (_person == NULL)
{
return 0;
}
if (_person->user.available)
{
_person->user.total += (current_time - _person->user.last_time_event);
}
_person->user.available = !_person->user.available;
_person->user.last_time_event = current_time;
return 1;
}