Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions
Updateable.c File Reference
#include "../../Inc/Utils/Updateable.h"
#include "../../Inc/Utils/Common.h"
#include <string.h>
Include dependency graph for Updateable.c:

Go to the source code of this file.

Functions

void initUpdateable (Updateable *updateable, const char *name, int hz, UpdateableType utype, void *child)
 
int defaultUpdate (Updateable *self)
 Default update function for Updateable objects. More...
 
int defaultStatus (struct Updateable *self)
 Default status function for Updateable objects. More...
 
int defaultEnable (struct Updateable *self)
 Default enable function for Updateable objects. More...
 
int defaultDisable (struct Updateable *self)
 Default disable function for Updateable objects. More...
 
int writeDataToFileImplementation (const char *filename, void *self)
 Write data to a file. More...
 

Function Documentation

◆ defaultDisable()

int defaultDisable ( struct Updateable *  self)

Default disable function for Updateable objects.

Parameters
selfPointer to the Updateable object.
Returns
int Status after disabling the Updateable object.

Definition at line 35 of file Updateable.c.

35 {
36 self->enabled = DISABLED;
37 return _SUCCESS;
38}
#define _SUCCESS
Definition: Common.h:5
#define DISABLED
Definition: Updateable.h:14
int enabled
Definition: Updateable.h:26
Here is the caller graph for this function:

◆ defaultEnable()

int defaultEnable ( struct Updateable *  self)

Default enable function for Updateable objects.

Parameters
selfPointer to the Updateable object.
Returns
int Status after enabling the Updateable object.

Definition at line 30 of file Updateable.c.

30 {
31 self->enabled = ENABLED;
32 return _SUCCESS;
33}
#define ENABLED
Definition: Updateable.h:15
Here is the caller graph for this function:

◆ defaultStatus()

int defaultStatus ( struct Updateable *  self)

Default status function for Updateable objects.

Parameters
selfPointer to the Updateable object.
Returns
int Status of the Updateable object.

Definition at line 26 of file Updateable.c.

26 {
27 return self->enabled;
28}
Here is the caller graph for this function:

◆ defaultUpdate()

int defaultUpdate ( struct Updateable *  self)

Default update function for Updateable objects.

Parameters
selfPointer to the Updateable object to update.

Definition at line 20 of file Updateable.c.

20 {
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}
#define _FAILURE
Definition: Common.h:6
Here is the caller graph for this function:

◆ initUpdateable()

void initUpdateable ( Updateable *  updateable,
const char *  name,
int  hz,
UpdateableType  utype,
void *  child 
)

Definition at line 6 of file Updateable.c.

6 {
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}
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
int defaultStatus(struct Updateable *self)
Default status function for Updateable objects.
Definition: Updateable.c:26
#define MAX_NAME_LENGTH
Definition: Updateable.h:13
int(* disable)(struct Updateable *self)
Definition: Updateable.h:30
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeDataToFileImplementation()

int writeDataToFileImplementation ( const char *  filename,
void *  self 
)

Write data to a file.

Parameters
filenameName of the file to write to.
selfPointer to the object whose data is to be written.
Returns
_SUCCESS if the data was written, _FAILURE otherwise.

Definition at line 40 of file Updateable.c.

40 {
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}