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)
 
void defaultUpdate (void *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 29 of file Updateable.c.

29 {
30 self->enabled = DISABLED;
31 return SUCCESS;
32}
#define SUCCESS
Definition: Common.h:5
#define DISABLED
Definition: Updateable.h:14
int enabled
Definition: Updateable.h:25
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 24 of file Updateable.c.

24 {
25 self->enabled = ENABLED;
26 return SUCCESS;
27}
#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 20 of file Updateable.c.

20 {
21 return self->enabled;
22}
Here is the caller graph for this function:

◆ defaultUpdate()

void defaultUpdate ( void *  self)

Default update function for Updateable objects.

Parameters
selfPointer to the object to update.

Definition at line 16 of file Updateable.c.

16 {
17 printf("Warning: Calling default Sensor Update Function.\n");
18}
Here is the caller graph for this function:

◆ initUpdateable()

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

Definition at line 6 of file Updateable.c.

6 {
7 strncpy(updateable->name, name, MAX_NAME_LENGTH);
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}
int defaultEnable(struct Updateable *self)
Default enable function for Updateable objects.
Definition: Updateable.c:24
int defaultDisable(struct Updateable *self)
Default disable function for Updateable objects.
Definition: Updateable.c:29
void defaultUpdate(void *self)
Default update function for Updateable objects.
Definition: Updateable.c:16
int defaultStatus(struct Updateable *self)
Default status function for Updateable objects.
Definition: Updateable.c:20
#define MAX_NAME_LENGTH
Definition: Updateable.h:13
void(* update)(void *self)
Definition: Updateable.h:26
int(* disable)(struct Updateable *self)
Definition: Updateable.h:29
int(* status)(struct Updateable *self)
Definition: Updateable.h:27
char name[MAX_NAME_LENGTH]
Definition: Updateable.h:23
int(* enable)(struct Updateable *self)
Definition: Updateable.h:28
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 34 of file Updateable.c.

34 {
35 FILE* file = fopen(filename, "w");
36 if (!file) {
37 perror("Failed to open file");
38 return FAILURE;
39 }
40
41 printf("Writing data to file %s\n", filename);
42
43 fclose(file);
44 return FAILURE;
45}
#define FAILURE
Definition: Common.h:6