Ke Ao Teensy Flight Software
The software on the Teensy in the Ke Ao cubesat.
Loading...
Searching...
No Matches
pdu.h
Go to the documentation of this file.
1
7#ifndef _PDU_H
8#define _PDU_H
9
10#include "debug.h"
11#include "support/configCosmosKernel.h"
12#include <Arduino.h>
13#include <TeensyThreads.h>
14#include <stdint.h>
15
24#define PDU_CMD_OFFSET 48
25
26namespace Artemis {
27 namespace Devices {
29 class PDU {
30 public:
37 enum class PDU_Type : uint8_t {
38 NOP,
43 DataPong,
47 };
48
58 enum class PDU_SW : uint8_t {
59 None,
60 All,
61 SW_3V3_1,
62 SW_3V3_2,
63 SW_5V_1,
64 SW_5V_2,
65 SW_5V_3,
66 SW_5V_4,
67 SW_12V,
68 VBATT,
69 WDT,
70 HBRIDGE1,
71 HBRIDGE2,
72 BURN,
73 BURN1,
74 BURN2,
75 RPI,
76 };
77
85 std::map<std::string, PDU_SW> PDU_SW_Type = {
86 { "all", PDU_SW::All},
87 { "3v3_1", PDU_SW::SW_3V3_1},
88 { "3v3_2", PDU_SW::SW_3V3_2},
89 { "5v_1", PDU_SW::SW_5V_1},
90 { "5v_2", PDU_SW::SW_5V_2},
91 { "5v_3", PDU_SW::SW_5V_3},
92 { "5v_4", PDU_SW::SW_5V_4},
93 { "12v", PDU_SW::SW_12V},
94 { "vbatt", PDU_SW::VBATT},
95 { "wdt", PDU_SW::WDT},
96 {"hbridge1", PDU_SW::HBRIDGE1},
97 {"hbridge2", PDU_SW::HBRIDGE2},
98 { "burn", PDU_SW::BURN},
99 { "burn1", PDU_SW::BURN1},
100 { "burn2", PDU_SW::BURN2},
101 { "rpi", PDU_SW::RPI},
102 };
103
113 struct __attribute__((packed)) pdu_packet {
119 PDU_Type type = PDU_Type::NOP;
125 PDU_SW sw = PDU_SW::None;
132 uint8_t sw_state = 0;
133 };
152 struct __attribute__((packed)) pdu_telem {
158 PDU_Type type = PDU_Type::DataSwitchTelem;
168 uint8_t sw_state[12];
169 };
180 PDU(HardwareSerial *hw_serial, int baud_rate);
181 int32_t set_switch(PDU_SW sw, uint8_t enable);
182 int32_t get_switch(PDU_SW sw, string &ret);
183 int32_t send(pdu_packet packet);
184 int32_t recv(std::string &response);
185
186 private:
195 HardwareSerial *serial;
196 };
197 } // namespace Devices
198} // namespace Artemis
199
200#endif
The satellite's Power Distribution Unit (PDU).
Definition pdu.h:29
int32_t recv(std::string &response)
Receive a PDU packet from the PDU.
Definition pdu.cpp:68
int32_t send(pdu_packet packet)
Send a PDU packet to the PDU.
Definition pdu.cpp:36
int32_t get_switch(PDU_SW sw, string &ret)
Gets the state of a switch on the PDU.
Definition pdu.cpp:154
std::map< std::string, PDU_SW > PDU_SW_Type
Mapping of string switch names to corresponding switch enums.
Definition pdu.h:85
PDU_Type
Enumeration of PDU packet type.
Definition pdu.h:37
@ NOP
No particular packet type. Just raw data.
@ DataPong
A pong reply from the PDU.
@ CommandSetSwitch
A command to set a switch on the PDU.
@ DataSwitchStatus
A switch status reply from the PDU.
@ CommandPing
A ping packet sent to the PDU.
PDU_SW
Enumeration of PDU switches.
Definition pdu.h:58
@ SW_5V_2
The second 5V switch.
@ BURN1
The first burnwire switch.
@ SW_5V_1
The first 5V switch.
@ SW_5V_3
The third 5V switch.
@ None
No particular switch.
@ VBATT
The battery voltage switch.
@ WDT
The PDU's WatchDog Timer (WDT).
@ SW_3V3_1
The first 3.3V switch.
@ HBRIDGE2
The first H-bridge.
@ RPI
The Raspberry Pi power switch.
@ SW_3V3_2
The second 3.3V switch.
@ All
All switches on the PDU.
@ HBRIDGE1
The first H-bridge.
@ BURN2
The second burnwire switch.
@ SW_5V_4
The fourth 5V switch.
int32_t set_switch(PDU_SW sw, uint8_t enable)
Set a switch on the PDU.
Definition pdu.cpp:98
Definitions of Serial Console helper functions.
The PDU packet structure.
Definition pdu.h:113
The PDU telemetry packet structure.
Definition pdu.h:152