Artemis Teensy Flight Software
The software on the Teensy in the Artemis cubesat.
pdu.h
Go to the documentation of this file.
1 
7 #ifndef _PDU_H
8 #define _PDU_H
9 
10 #include "helpers.h"
12 #include <Arduino.h>
13 #include <TeensyThreads.h>
14 #include <stdint.h>
15 
17 #define PDU_CMD_OFFSET 48
19 #define NUMBER_OF_SWITCHES 12
20 
22 #define PDU_WARMUP_TIME 5 * SECONDS
24 #define PDU_RETRY_INTERVAL 1 * SECONDS
26 #define BURN_WIRE_ON_TIME 5 * SECONDS
28 #define DEPLOYMENT_DELAY 5 * SECONDS
35 #define DEPLOYMENT_LENGTH 60 * SECONDS
37 #define DEPLOYMENT_LOOP_INTERVAL 10 * SECONDS
39 #define HEATER_CHECK_INTERVAL 60 * SECONDS
41 #define PDU_COMMUNICATION_TIMEOUT 5 * SECONDS
42 
43 namespace Artemis {
44 namespace Devices {
46  class PDU {
47  public:
49  enum class PDU_Type : uint8_t {
50  NOP,
51  CommandPing,
52  CommandSetSwitch,
53  CommandGetSwitchStatus,
54  DataPong,
55  DataSwitchStatus,
56  DataSwitchTelem,
57  };
59  enum class PDU_SW : uint8_t {
60  None,
61  All,
62  SW_3V3_1,
63  SW_3V3_2,
64  SW_5V_1,
65  SW_5V_2,
66  SW_5V_3,
67  SW_5V_4,
68  SW_12V,
69  VBATT,
70  WDT,
71  HBRIDGE1,
72  HBRIDGE2,
73  BURN,
74  BURN1,
75  BURN2,
76  RPI,
77  };
79  enum class PDU_SW_State : bool {
80  SWITCH_OFF,
81  SWITCH_ON,
82  };
84  std::map<std::string, PDU_SW> PDU_SW_Type = {
85  { "all", PDU_SW::All},
86  { "3v3_1", PDU_SW::SW_3V3_1},
87  { "3v3_2", PDU_SW::SW_3V3_2},
88  { "5v_1", PDU_SW::SW_5V_1},
89  { "5v_2", PDU_SW::SW_5V_2},
90  { "5v_3", PDU_SW::SW_5V_3},
91  { "5v_4", PDU_SW::SW_5V_4},
92  { "12v", PDU_SW::SW_12V},
93  { "vbatt", PDU_SW::VBATT},
94  { "wdt", PDU_SW::WDT},
95  {"hbridge1", PDU_SW::HBRIDGE1},
96  {"hbridge2", PDU_SW::HBRIDGE2},
97  { "burn", PDU_SW::BURN},
98  { "burn1", PDU_SW::BURN1},
99  { "burn2", PDU_SW::BURN2},
100  { "rpi", PDU_SW::RPI},
101  };
102 
104  struct __attribute__((packed)) pdu_packet {
105  PDU_Type type = PDU_Type::NOP;
106  PDU_SW sw = PDU_SW::None;
107  uint8_t sw_state = 0;
108  };
110  struct __attribute__((packed)) pdu_telem {
111  PDU_Type type = PDU_Type::DataSwitchTelem;
112  uint8_t sw_state[NUMBER_OF_SWITCHES];
113  };
114 
115  PDU(HardwareSerial *hw_serial, int baud_rate);
116 
117  bool ping();
118  bool set_switch(PDU_SW sw, PDU_SW_State state);
119  bool set_heater(PDU_SW_State state);
120  bool set_burn_wire(PDU_SW_State state);
121  bool refresh_switch_states();
122 
129 
130  private:
132  HardwareSerial *serial;
133 
134  bool send(pdu_packet packet);
135  bool recv(pdu_packet *packet);
136  bool recv(pdu_telem *packet);
137  };
138 } // namespace Devices
139 } // namespace Artemis
140 
141 #endif
The PDU class.
Definition: pdu.h:46
PDU(HardwareSerial *hw_serial, int baud_rate)
Construct a new PDU object.
Definition: pdu.cpp:17
PDU_SW_State
Enumeration of PDU switch state.
Definition: pdu.h:79
std::map< std::string, PDU_SW > PDU_SW_Type
Mapping between PDU switches and their string names.
Definition: pdu.h:84
PDU_SW_State switch_states[NUMBER_OF_SWITCHES]
The status of each switch on the PDU.
Definition: pdu.h:128
bool set_burn_wire(PDU_SW_State state)
Wrapper function to set the burn wire switch.
Definition: pdu.cpp:202
PDU_Type
Enumeration of PDU packet types.
Definition: pdu.h:49
PDU_SW
Enumeration of PDU switches.
Definition: pdu.h:59
bool set_switch(PDU_SW sw, PDU_SW_State state)
Set a switch on the PDU.
Definition: pdu.cpp:149
bool refresh_switch_states()
Refresh the internal PDU class's switch states.
Definition: pdu.cpp:213
bool ping()
Ping the PDU.
Definition: pdu.cpp:119
bool set_heater(PDU_SW_State state)
Wrapper function to set the heater switch.
Definition: pdu.cpp:191
Headers and definitions common to all COSMOS Kernel.
The header file for helper functions.
PacketComm packet
The packet used throughout the channel.
Definition: pdu_channel.cpp:19
#define NUMBER_OF_SWITCHES
The number of switches on the PDU.
Definition: pdu.h:19
The PDU packet structure.
Definition: pdu.h:104
The PDU telemetry packet structure.
Definition: pdu.h:110