-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dispatcher.cpp
109 lines (84 loc) · 2.54 KB
/
Dispatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "Dispatcher.h"
#include <Arduino.h>
#include <HardwareSerial.h>
//Magic timing library stuff
#include <MY17_Can_Library.h>
#include "Types.h"
#include "Input.h"
#include "State.h"
#include "Output.h"
#include "Pins.h"
#include "Pin_Manager.h"
#include "State.h"
/******* BEGIN forward declarations ***********/
void initialize_structs();
/******** END forward declarations ***********/
/*********** BEGIN state structs *************/
static Input_T input;
static Front_Can_Node_Input_T front_can_node_input;
static Rear_Can_Node_Input_T rear_can_node_input;
static Speed_Input_T speed;
static Dash_Input_T dash_input;
static Bms_Input_T bms_input;
static Mc_Input_T mc_input;
static Current_Sensor_Input_T current_sensor_input;
static Shutdown_Input_T shutdown_input;
static State_T state;
static Precharge_State_T precharge_state;
static Drive_State_T drive_state;
static Message_State_T message_state;
static Other_State_T other_state;
static Output_T output;
static Can_Output_T can_output;
static Pin_Output_T pin_output;
static Onboard_Output_T onboard_output;
static Xbee_Output_T xbee_output;
/************* END state structs *************/
/********** BEGIN public method definitions *********/
void Dispatch_begin() {
// Initialize Serial and wait to make sure it's initialized
Serial.begin(115200);
// Onboard logger
Serial1.begin(115200);
// Xbee
Serial2.begin(57600);
delay(50);
// Initialize all pins besides CAN
Pin_Manager::setup_pins();
// Initialize CAN
Can_Init(500000);
// Initialize state variables
initialize_structs();
// Start event loop
Serial.println("Started VCU");
Serial1.println("CAR POWERED ON");
Serial2.println("CAR POWERED ON");
}
void Dispatch_run() {
input.msTicks = millis();
Input_fill_input(&input);
State_update_state(&input, &state, &output);
Output_empty_output(&input, &state, &output);
}
void initialize_structs() {
input.front_can_node = &front_can_node_input;
input.rear_can_node = &rear_can_node_input;
input.speed = &speed;
input.dash = &dash_input;
input.bms = &bms_input;
input.mc = &mc_input;
input.current_sensor = ¤t_sensor_input;
input.shutdown = &shutdown_input;
Input_initialize(&input);
state.precharge = &precharge_state;
state.drive = &drive_state;
state.message = &message_state;
state.other = &other_state;
State_initialize(&state);
output.can = &can_output;
output.pin = &pin_output;
output.onboard = &onboard_output;
output.xbee = &xbee_output;
Output_initialize(&output);
}
/********** END method definitions ***********/