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_)->updateable->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  type { SENSOR , SYSTEM }
 

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...
 

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_)->updateable->update(item_))

Definition at line 8 of file Updateable.h.

Typedef Documentation

◆ Updateable

typedef struct Updateable Updateable

Enumeration Type Documentation

◆ type

enum type
Enumerator
SENSOR 
SYSTEM 

Definition at line 17 of file Updateable.h.

17 {
18 SENSOR,
19 SYSTEM
20} type;
type
Definition: Updateable.h:17
@ SYSTEM
Definition: Updateable.h:19
@ SENSOR
Definition: Updateable.h:18

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