Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions
ControllerSystem.c File Reference
#include "../../Inc/Systems/ControllerSystem.h"
#include "../../Inc/Utils/Common.h"
Include dependency graph for ControllerSystem.c:

Go to the source code of this file.

Functions

void initControllerSystem (ControllerSystem *controller, const char *name, int hz, ControllerType type)
 Initializes the Controller System with initial settings. More...
 
int defaultAddMonitor (void *self, MonitorSystem *monitor)
 Adds a monitor to the controller. More...
 
int defaultRemoveMonitor (void *self, MonitorSystem *monitor)
 Removes a monitor from the controller. More...
 

Function Documentation

◆ defaultAddMonitor()

int defaultAddMonitor ( void *  self,
MonitorSystem monitor 
)

Adds a monitor to the controller.

Parameters
selfA pointer to the ControllerSystem structure.
monitorA pointer to the MonitorSystem structure to add.
Returns
SUCCESS if the monitor was added, FAILURE otherwise.

Definition at line 12 of file ControllerSystem.c.

12 {
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}
#define FAILURE
Definition: Common.h:6
#define SUCCESS
Definition: Common.h:5
#define MAX_MONITORS
MonitorSystem * monitors[MAX_MONITORS]
Here is the caller graph for this function:

◆ defaultRemoveMonitor()

int defaultRemoveMonitor ( void *  self,
MonitorSystem monitor 
)

Removes a monitor from the controller.

Parameters
selfA pointer to the ControllerSystem structure.
monitorA pointer to the MonitorSystem structure to remove.
Returns
SUCCESS if the monitor was removed, FAILURE otherwise.

Definition at line 22 of file ControllerSystem.c.

22 {
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}

◆ initControllerSystem()

void initControllerSystem ( ControllerSystem controller,
const char *  name,
int  hz,
ControllerType  type 
)

Initializes the Controller System with initial settings.

Parameters
controllerA pointer to the ControllerSystem structure.
nameThe name of the controller.
hzRate at which the controller is called (in hz).
typeThe type of controller (per ControllerType).

Definition at line 4 of file ControllerSystem.c.

5 {
6 initSystem(&controller->system, name, hz, CONTROLLER);
7 controller->type = type;
8 controller->num_monitors = 0;
9 controller->safety = NULL;
10}
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
int(* safety)(void *self)
ControllerType type
Here is the call graph for this function:
Here is the caller graph for this function: