Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions
Updateable.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for Updateable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Updateable
 

Macros

#define UPDATE(item_)   ((item_)->update(item_))
 
#define STATUS(item_)   ((item_).updateable.status(&item_.updateable))
 
#define ENABLE(item_)   ((item_).updateable.enable(&item_.updateable))
 
#define DISABLE(item_)   ((item_).updateable.disable(&item_.updateable))
 
#define MAX_NAME_LENGTH   32
 
#define DISABLED   0
 
#define ENABLED   1
 

Typedefs

typedef struct Updateable Updateable
 

Enumerations

enum  UpdateableType { OUTPUT , SENSOR , SYSTEM }
 

Functions

void initUpdateable (Updateable *updateable, const char *name, int hz, UpdateableType utype, void *child)
 
int defaultUpdate (struct 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...
 

Macro Definition Documentation

◆ DISABLE

#define DISABLE (   item_)    ((item_).updateable.disable(&item_.updateable))

Definition at line 11 of file Updateable.h.

◆ DISABLED

#define DISABLED   0

Definition at line 14 of file Updateable.h.

◆ ENABLE

#define ENABLE (   item_)    ((item_).updateable.enable(&item_.updateable))

Definition at line 10 of file Updateable.h.

◆ ENABLED

#define ENABLED   1

Definition at line 15 of file Updateable.h.

◆ MAX_NAME_LENGTH

#define MAX_NAME_LENGTH   32

Definition at line 13 of file Updateable.h.

◆ STATUS

#define STATUS (   item_)    ((item_).updateable.status(&item_.updateable))

Definition at line 9 of file Updateable.h.

◆ UPDATE

#define UPDATE (   item_)    ((item_)->update(item_))

Definition at line 8 of file Updateable.h.

Typedef Documentation

◆ Updateable

typedef struct Updateable Updateable

Enumeration Type Documentation

◆ UpdateableType

Enumerator
OUTPUT 
SENSOR 
SYSTEM 

Definition at line 17 of file Updateable.h.

17 {
18 OUTPUT,
19 SENSOR,
20 SYSTEM
UpdateableType
Definition: Updateable.h:17
@ OUTPUT
Definition: Updateable.h:18
@ SYSTEM
Definition: Updateable.h:20
@ SENSOR
Definition: Updateable.h:19

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
#define ANSI_COLOR_YELLOW
Definition: Common.h:11
#define ANSI_COLOR_RESET
Definition: Common.h:15
char name[MAX_NAME_LENGTH]
Definition: Updateable.h:24
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
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}