Refactor header inclusions and add main.h; implement searchPersonByUUID and addTimeEvent functions in users.c
This commit is contained in:
Vendored
+2
-1
@@ -5,7 +5,8 @@
|
|||||||
"stdlib.h": "c",
|
"stdlib.h": "c",
|
||||||
"errno.h": "c",
|
"errno.h": "c",
|
||||||
"rfid_handler.h": "c",
|
"rfid_handler.h": "c",
|
||||||
"fcntl.h": "c"
|
"fcntl.h": "c",
|
||||||
|
"file_operations.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.errorSquiggles": "enabled"
|
"C_Cpp.errorSquiggles": "enabled"
|
||||||
}
|
}
|
||||||
@@ -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
@@ -4,9 +4,8 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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);
|
void uartDialog(char *uart_adress, int terminal_x, int terminal_y);
|
||||||
|
|
||||||
|
|||||||
+17
-2
@@ -1,3 +1,5 @@
|
|||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -15,7 +17,9 @@ typedef struct person
|
|||||||
uint32_t department;
|
uint32_t department;
|
||||||
|
|
||||||
time_t last_time_event;
|
time_t last_time_event;
|
||||||
uint32_t total;
|
time_t total;
|
||||||
|
|
||||||
|
BYTE available;
|
||||||
|
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
} person_t;
|
} person_t;
|
||||||
@@ -40,7 +44,18 @@ uint16_t generateUUID(node_t *_head);
|
|||||||
|
|
||||||
uint16_t searchUUIDByName(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.
|
* @brief Adds a new person to the linked list.
|
||||||
|
|||||||
BIN
Binary file not shown.
@@ -12,6 +12,7 @@
|
|||||||
#include "tui.h"
|
#include "tui.h"
|
||||||
#include "rfid_handler.h"
|
#include "rfid_handler.h"
|
||||||
#include "file_operations.h"
|
#include "file_operations.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
int main(int argc, char const **argv)
|
int main(int argc, char const **argv)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "rfid_handler.h"
|
#include "rfid_handler.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||||
{
|
{
|
||||||
|
|||||||
+44
@@ -1,4 +1,6 @@
|
|||||||
#include "users.h"
|
#include "users.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -31,6 +33,24 @@ uint16_t generateUUID
|
|||||||
return uuid;
|
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
|
int addPersonToList
|
||||||
(
|
(
|
||||||
node_t **_head,
|
node_t **_head,
|
||||||
@@ -67,6 +87,7 @@ int addPersonToList
|
|||||||
new_node->user.department = _department;
|
new_node->user.department = _department;
|
||||||
new_node->user.last_time_event = -255;
|
new_node->user.last_time_event = -255;
|
||||||
new_node->user.total = 0;
|
new_node->user.total = 0;
|
||||||
|
new_node->user.available = FALSE;
|
||||||
|
|
||||||
new_node->next = NULL;
|
new_node->next = NULL;
|
||||||
|
|
||||||
@@ -85,3 +106,26 @@ int addPersonToList
|
|||||||
|
|
||||||
return 1;
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user