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_)->updateable->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 {
19 SYSTEM
21
22typedef struct Updateable {
24 int hz;
26 void (*update)(void* self);
27 int (*status)(struct Updateable* self);
28 int (*enable)(struct Updateable* self);
29 int (*disable)(struct Updateable* self);
31
32/*
33 * @brief Initializes the Updateable with initial settings.
34 *
35 * @param updateable A pointer to the Updateable structure.
36 * @param name The name of the updateable.
37 * @param hz Rate at which the updateable is called (in hz).
38*/
39void initUpdateable(Updateable* updateable, const char* name, int hz);
40
46void defaultUpdate(void* self);
47
54int defaultStatus(struct Updateable* self);
55
62int defaultEnable(struct Updateable* self);
63
70int defaultDisable(struct Updateable* self);
71
79int writeDataToFileImplementation(const char* filename, void* self);
80
81#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:24
int defaultDisable(struct Updateable *self)
Default disable function for Updateable objects.
Definition: Updateable.c:29
int writeDataToFileImplementation(const char *filename, void *self)
Write data to a file.
Definition: Updateable.c:34
void defaultUpdate(void *self)
Default update function for Updateable objects.
Definition: Updateable.c:16
type
Definition: Updateable.h:17
@ SYSTEM
Definition: Updateable.h:19
@ SENSOR
Definition: Updateable.h:18
int defaultStatus(struct Updateable *self)
Default status function for Updateable objects.
Definition: Updateable.c:20
void initUpdateable(Updateable *updateable, const char *name, int hz)
Definition: Updateable.c:6
void(* update)(void *self)
Definition: Updateable.h:26
int(* disable)(struct Updateable *self)
Definition: Updateable.h:29
int enabled
Definition: Updateable.h:25
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