fsm_get_time()
This commit is contained in:
parent
7f7c390b61
commit
5aa8c84ade
|
@ -46,6 +46,8 @@ typedef struct tool_list {int value; struct tool_list *suiv;} tool_list ;
|
|||
typedef struct data_list {int value; struct data_list *suiv;} data_list ;
|
||||
typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ;
|
||||
|
||||
// --------------------------------------------------------------- WIP ------
|
||||
void fsm_get_time();
|
||||
// --------------------------------------------------------------- WIP ------
|
||||
typedef struct unit {int event; struct unit *prev; struct unit *next;} unit;
|
||||
typedef struct {unit *first; unit *last;} journal; // structure d'accès au journal
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "../../include/fsm.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -34,11 +36,25 @@
|
|||
/******************************************************************************/
|
||||
|
||||
|
||||
void fsm_get_time()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf(" Seconds since Jan. 1, 1970: %ld\n", tv.tv_sec);
|
||||
|
||||
time_t current_time = time(NULL);
|
||||
// Check if the time retrieval was successful
|
||||
if (current_time == ((time_t)-1)) printf("Error getting current time.\n");
|
||||
// Convert to local time format and print
|
||||
printf(" Current timestamp: %ld\n", current_time);
|
||||
printf(" Current time: %s", ctime(¤t_time));
|
||||
}
|
||||
|
||||
void fsm_journal_init (journal *jj)
|
||||
{
|
||||
jj->first = NULL;
|
||||
jj->last = NULL;
|
||||
fsm_get_time();
|
||||
}
|
||||
|
||||
void fsm_journal_clear (journal *jj)
|
||||
|
@ -122,12 +138,15 @@ int fsm_journal_length (journal jj)
|
|||
void fsm_journal_seek (journal jj, int event)
|
||||
{
|
||||
unit *a_unit = jj.first;
|
||||
int nb = 0;
|
||||
while (a_unit)
|
||||
{
|
||||
if (event == a_unit->event)
|
||||
printf ("> event %d found in journal\n", a_unit->event);
|
||||
if (event == a_unit->event) nb++;
|
||||
a_unit = a_unit->next;
|
||||
}
|
||||
if (nb > 0) printf ("> event %d found %d times in journal\n", event, nb);
|
||||
else printf ("> event %d not found in journal\n", event);
|
||||
fsm_get_time();
|
||||
}
|
||||
|
||||
void fsm_journal_view (journal jj)
|
||||
|
@ -154,6 +173,7 @@ void fsm_journal_test()
|
|||
printf ("push front > %d\n", fsm_journal_push_front (&exemple, 1));
|
||||
|
||||
fsm_journal_view (exemple);
|
||||
fsm_journal_seek (exemple, 2);
|
||||
|
||||
printf ("pop back > %d\n", fsm_journal_pop_back (&exemple));
|
||||
printf ("pop back > %d\n", fsm_journal_pop_back (&exemple));
|
||||
|
|
Loading…
Reference in New Issue