Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Updateable.h
Go to the documentation of this file.
1#ifndef RENSSELAERMOTORSPORT_UPDATEABLE_H
2#define RENSSELAERMOTORSPORT_UPDATEABLE_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#define UPDATE(item_) ((item_)->update(item_))
9#define STATUS(item_) ((item_).updateable.status(&item_.updateable))
10#define ENABLE(item_) ((item_).updateable.enable(&item_.updateable))
11#define DISABLE(item_) ((item_).updateable.disable(&item_.updateable))
12
13#define MAX_NAME_LENGTH 32
14#define DISABLED 0
15#define ENABLED 1
16
17typedef enum {
20 SYSTEM
22
23typedef struct Updateable {
25 int hz;
27 int (*update)(struct Updateable* self);
28 int (*status)(struct Updateable* self);
29 int (*enable)(struct Updateable* self);
30 int (*disable)(struct Updateable* self);
32 void* child;
34
35/*
36 * @brief Initializes the Updateable with initial settings.
37 *
38 * @param updateable Pointer to the Updateable struct.
39 * @param name Name of the Updateable object.
40 * @param hz Rate at which the Updateable is called (in Hz).
41 * @param utype Type of the Updateable object (per UpdateableType).
42 * @param child Pointer to the child object that this Updateable will manage.
43 * @return void
44*/
45void initUpdateable(Updateable* updateable, const char* name, int hz, UpdateableType utype, void* child);
46
52int defaultUpdate(struct Updateable* self);
53
60int defaultStatus(struct Updateable* self);
61
68int defaultEnable(struct Updateable* self);
69
76int defaultDisable(struct Updateable* self);
77
85int writeDataToFileImplementation(const char* filename, void* self);
86
87#endif // RENSSELAERMOTORSPORT_UPDATEABLE_H
#define MAX_NAME_LENGTH
Definition: Updateable.h:13
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
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 defaultUpdate(struct 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
UpdateableType
Definition: Updateable.h:17
@ OUTPUT
Definition: Updateable.h:18
@ SYSTEM
Definition: Updateable.h:20
@ SENSOR
Definition: Updateable.h:19
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