Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Updateable.c
Go to the documentation of this file.
1#include "../../Inc/Utils/Updateable.h"
2#include "../../Inc/Utils/Common.h"
3
4#include <string.h>
5
6void initUpdateable(Updateable* updateable, const char* name, int hz, UpdateableType utype, void* child) {
7 // Initialize the updateable struct
8 updateable->hz = hz;
9 updateable->update = defaultUpdate;
10 updateable->status = defaultStatus;
11 updateable->enable = defaultEnable;
12 updateable->disable = defaultDisable;
13 updateable->enabled = DISABLED;
14 strncpy(updateable->name, name, MAX_NAME_LENGTH);
15 updateable->type = utype;
16 // Have a pointer to the child struct
17 updateable->child = child;
18}
19
21 // Print in yellow color
22 printf(ANSI_COLOR_YELLOW "Warning: Calling default Update Function for %s\n" ANSI_COLOR_RESET, self->name);
23 return _FAILURE;
24}
25
26int defaultStatus(struct Updateable* self) {
27 return self->enabled;
28}
29
30int defaultEnable(struct Updateable* self) {
31 self->enabled = ENABLED;
32 return _SUCCESS;
33}
34
35int defaultDisable(struct Updateable* self) {
36 self->enabled = DISABLED;
37 return _SUCCESS;
38}
39
40int writeDataToFileImplementation(const char* filename, void* self) {
41 FILE* file = fopen(filename, "w");
42 if (!file) {
43 perror("Failed to open file");
44 return _FAILURE;
45 }
46
47 printf("Writing data to file %s\n", filename);
48
49 fclose(file);
50 return _FAILURE;
51}
#define _FAILURE
Definition: Common.h:6
#define ANSI_COLOR_YELLOW
Definition: Common.h:11
#define ANSI_COLOR_RESET
Definition: Common.h:15
#define _SUCCESS
Definition: Common.h:5
int defaultEnable(struct Updateable *self)
Default enable function for Updateable objects.
Definition: Updateable.c:30
int defaultDisable(struct Updateable *self)
Default disable function for Updateable objects.
Definition: Updateable.c:35
int defaultUpdate(Updateable *self)
Default update function for Updateable objects.
Definition: Updateable.c:20
void initUpdateable(Updateable *updateable, const char *name, int hz, UpdateableType utype, void *child)
Definition: Updateable.c:6
int writeDataToFileImplementation(const char *filename, void *self)
Write data to a file.
Definition: Updateable.c:40
int defaultStatus(struct Updateable *self)
Default status function for Updateable objects.
Definition: Updateable.c:26
#define MAX_NAME_LENGTH
Definition: Updateable.h:13
#define ENABLED
Definition: Updateable.h:15
UpdateableType
Definition: Updateable.h:17
#define DISABLED
Definition: Updateable.h:14
int(* disable)(struct Updateable *self)
Definition: Updateable.h:30
int enabled
Definition: Updateable.h:26
int(* status)(struct Updateable *self)
Definition: Updateable.h:28
int(* update)(struct Updateable *self)
Definition: Updateable.h:27
void * child
Definition: Updateable.h:32
UpdateableType type
Definition: Updateable.h:31
char name[MAX_NAME_LENGTH]
Definition: Updateable.h:24
int(* enable)(struct Updateable *self)
Definition: Updateable.h:29