Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
ControllerSystem.c
Go to the documentation of this file.
1#include "../../Inc/Systems/ControllerSystem.h"
2#include "../../Inc/Utils/Common.h"
3
4void initControllerSystem(ControllerSystem* controller, const char* name, int hz,
6 initSystem(&controller->system, name, hz, CONTROLLER);
7 controller->type = type;
8 controller->num_monitors = 0;
9 controller->safety = NULL;
10}
11
12int defaultAddMonitor(void* self, MonitorSystem* monitor) {
13 ControllerSystem* controller = (ControllerSystem*)self;
14 if (controller->num_monitors >= MAX_MONITORS) {
15 printf("Cannot add more monitors to the controller\n");
16 return FAILURE;
17 }
18 controller->monitors[controller->num_monitors++] = monitor;
19 return SUCCESS;
20}
21
22int defaultRemoveMonitor(void* self, MonitorSystem* monitor) {
23 ControllerSystem* controller = (ControllerSystem*)self;
24 for (int i = 0; i < controller->num_monitors; i++) {
25 if (controller->monitors[i] == monitor) {
26 for (int j = i; j < controller->num_monitors - 1; j++) {
27 controller->monitors[j] = controller->monitors[j + 1];
28 }
29 controller->num_monitors--;
30 return SUCCESS;
31 }
32 }
33 printf("Monitor not found in the controller\n");
34 return FAILURE;
35}
#define FAILURE
Definition: Common.h:6
#define SUCCESS
Definition: Common.h:5
int defaultRemoveMonitor(void *self, MonitorSystem *monitor)
Removes a monitor from the controller.
int defaultAddMonitor(void *self, MonitorSystem *monitor)
Adds a monitor to the controller.
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type)
Initializes the Controller System with initial settings.
#define MAX_MONITORS
ControllerType
void initSystem(System *system, const char *name, int hz, SystemType type)
Initializes a System object.
Definition: System.c:3
@ CONTROLLER
Definition: System.h:14
type
Definition: Updateable.h:17
MonitorSystem * monitors[MAX_MONITORS]
int(* safety)(void *self)
ControllerType type