Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
ExternalSystem.c
Go to the documentation of this file.
1#include "../../Inc/Systems/ExternalSystem.h"
2#include "../../Inc/Utils/Common.h"
3#include "../../Inc/Utils/Updateable.h"
4#include "../../Inc/Scheduler/Task.h"
5
6void initExternalSystem(ExternalSystem* external, const char* name, int hz,
7 ExternalType type, int (*updateExternal)(ExternalSystem* external),
8 int (*check_heartbeat)(void* self), void* child) {
9 initSystem(&external->system, name, hz, EXTERNAL, external);
10 external->type = type;
11 external->comms = NULL;
12 external->check_heartbeat = check_heartbeat;
13 external->updateExternal = updateExternal;
14 external->child = child;
15
16 // Set the updateable function to generic external system update
18}
19
20int e_defaultUpdate(Updateable* updateable) {
21 // Cast the child pointer to a external system
22 System* system = (System*)updateable->child;
23 ExternalSystem* external = (ExternalSystem*)system->child;
24
25 // Perform the heartbeat check
26 if (external->check_heartbeat(external) == _FAILURE) {
27 return _FAILURE;
28 }
29
30 // Perform the external system update
31 if (external->updateExternal(external) == _FAILURE) {
32 return _FAILURE;
33 }
34
35 return _SUCCESS;
36}
#define _FAILURE
Definition: Common.h:6
#define _SUCCESS
Definition: Common.h:5
void initExternalSystem(ExternalSystem *external, const char *name, int hz, ExternalType type, int(*updateExternal)(ExternalSystem *external), int(*check_heartbeat)(void *self), void *child)
Definition: ExternalSystem.c:6
int e_defaultUpdate(Updateable *updateable)
ExternalType
@ EXTERNAL
Definition: System.h:12
void initSystem(System *system, const char *name, int hz, SystemType type, void *child)
Initializes a System object.
Definition: System.c:3
ExternalType type
int(* updateExternal)(struct ExternalSystem *external)
CommsSystem * comms
int(* check_heartbeat)(void *self)
Definition: System.h:17
Updateable updateable
Definition: System.h:18
void * child
Definition: System.h:20
int(* update)(struct Updateable *self)
Definition: Updateable.h:27
void * child
Definition: Updateable.h:32