This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsotscon.h
110 lines (97 loc) · 4.16 KB
/
sotscon.h
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
110
#ifndef SHARK_OF_THE_SKY_CONTROL_H_
#define SHARK_OF_THE_SKY_CONTROL_H_
#include <stdbool.h>
#include <stdint.h>
#include "canlib/can.h"
#include "canlib/message_types.h" //defines VALVE_STATE enum
/*
* If we do not receive a MSG_VENT_VALVE_STATUS from the vent board every
* this many milliseconds (or MSG_INJ_VALVE_STATUS from injector), we will
* consider the state of that valve to be unknown
*/
#define MIN_TIME_BETWEEN_VALVE_UPDATE_MS 3000
/*
* If we do not receive any message from a given board every this many
* milliseconds, we will consider that board to be dead. We will issue an
* error, and we will decrement our count of boards
*/
#define MIN_TIME_BETWEEN_BOARD_HEARTBEAT_MS 3000
/*
* Call this function at bootup, and never again. It will reset all of the
* internal data. The reason this function needs to exist is that I can't
* statically initialize our internal data with microchip's compiler
*/
void init_sotscon(void);
/*
* Call this function every time we receive a CAN message over the bus.
* This will update our current knowledge of the rocket state. This function
* is not designed to be thread safe or particularly efficient, so it
* shouldn't be called from an ISR.
*
* TODO, add a buffering layer for CAN messages so that we don't have to call
* this from an ISR
*/
void handle_incoming_can_message(const can_msg_t *msg);
/*
* If we have received a VENT_VALVE_STATUS message in the last
* MIN_TIME_BETWEEN_VALVE_UPDATE_MS, this function will return either
* VALVE_OPEN or VALVE_CLOSED, depending on, you know, whether it's open
* or closed. If we haven't received that status message in the correct
* amount of time, this function will return VALVE_UNK.
*/
enum VALVE_STATE current_vent_valve_position(void);
/*
* Same idea as current_vent_valve_position. Returns open, closed, or unk
* if we haven't received a status message in MIN_TIME_BETWEEN_VALVE_UPDATE_MS
*/
enum VALVE_STATE current_inj_valve_position(void);
/*
* Returns the number of unique BOARD_UNIQUE_IDs that this code module has
* seen in the incoming CAN messages. Note that this does not always mean it
* will know how many boards are present, since if a board has not issued
* any CAN messages, this module will cannot know that it exists.
*
* If we have not received any CAN messages from a board in the last
* MIN_TIME_BETWEEN_BORAD_HEARTBEAT_MS milliseconds, that board will not be
* counted in the value that this function returns.
*/
uint8_t current_num_boards_connected(void);
/*
* Returns true if any boards that are connected to the CAN bus are believed
* to have any active errors. An error is defined as active if the board that
* sent it has not sent MAX_CONSECUTIVE_NOMINALS E_NOMINAL messages (the
* "everything is ok" message) since sending it.
*
* So if the vent board sends a "battery voltage low" error message, this
* function will return true until the vent board has sent MAX_CONSECUTIVE_NOMINALS
* "Everything is find" messages.
*/
bool any_errors_active(void);
/*
* Returns the tank pressure that we last received from minisensor. If we've
* never received a reading from minisensor, this will return 0. This function
* clamps its return value to 999, so if the pressure is above that, we won't
* be able to read it. Is this a problem re: the burst disk? Maybe.
*/
uint16_t current_tank_pressure(void);
/*
* These two functions return the last received battery voltages from vent and
* injector. These functions do not clamp their return values, so can return
* up to 65535.
*/
uint16_t current_vent_batt_mv(void);
uint16_t current_inj_batt_mv(void);
/*
* Gets the last position that we received from GPS board. It's your
* responsibility to decode the degrees, minutes, and decimal minutes
* into whatever format you want. *_dir is 'E', 'W', 'N', or 'S'
*/
void current_gps_position(uint8_t *latitude_deg,
uint8_t *latitude_min,
uint8_t *latitude_dmin,
uint8_t *latitude_dir,
uint8_t *longitude_deg,
uint8_t *longitude_min,
uint8_t *longitude_dmin,
uint8_t *longitude_dir);
#endif