Ke Ao Teensy Flight Software
The software on the Teensy in the Ke Ao cubesat.
|
The satellite's Power Distribution Unit (PDU). More...
#include <pdu.h>
Classes | |
struct | pdu_packet |
The PDU packet structure. More... | |
struct | pdu_telem |
The PDU telemetry packet structure. More... | |
Public Types | |
enum class | PDU_Type : uint8_t { NOP , CommandPing , CommandSetSwitch , CommandGetSwitchStatus , DataPong , DataSwitchStatus , DataSwitchTelem } |
Enumeration of PDU packet type. More... | |
enum class | PDU_SW : uint8_t { None , All , SW_3V3_1 , SW_3V3_2 , SW_5V_1 , SW_5V_2 , SW_5V_3 , SW_5V_4 , SW_12V , VBATT , WDT , HBRIDGE1 , HBRIDGE2 , BURN , BURN1 , BURN2 , RPI } |
Enumeration of PDU switches. More... | |
Public Member Functions | |
PDU (HardwareSerial *hw_serial, int baud_rate) | |
Construct a new PDU::PDU object. | |
int32_t | set_switch (PDU_SW sw, uint8_t enable) |
Set a switch on the PDU. | |
int32_t | get_switch (PDU_SW sw, string &ret) |
Gets the state of a switch on the PDU. | |
int32_t | send (pdu_packet packet) |
Send a PDU packet to the PDU. | |
int32_t | recv (std::string &response) |
Receive a PDU packet from the PDU. | |
Public Attributes | |
std::map< std::string, PDU_SW > | PDU_SW_Type |
Mapping of string switch names to corresponding switch enums. | |
The satellite's Power Distribution Unit (PDU).
|
strong |
Enumeration of PDU switches.
This enum represents the switches on the PDU using a 1-byte value. Using these identifiers, we can determine which switch is being referenced.
Enumerator | |
---|---|
None | No particular switch. |
All | All switches on the PDU. |
SW_3V3_1 | The first 3.3V switch. |
SW_3V3_2 | The second 3.3V switch. |
SW_5V_1 | The first 5V switch. |
SW_5V_2 | The second 5V switch. |
SW_5V_3 | The third 5V switch. |
SW_5V_4 | The fourth 5V switch. |
SW_12V | The 12V switch. |
VBATT | The battery voltage switch. |
WDT | The PDU's WatchDog Timer (WDT). |
HBRIDGE1 | The first H-bridge. |
HBRIDGE2 | The first H-bridge. |
BURN | The burnwire. |
BURN1 | The first burnwire switch. |
BURN2 | The second burnwire switch. |
RPI | The Raspberry Pi power switch. |
|
strong |
Enumeration of PDU packet type.
This enum represents the type of PDU packet using a 1-byte value. Using these identifiers, we can determine what the command is.
Enumerator | |
---|---|
NOP | No particular packet type. Just raw data. |
CommandPing | A ping packet sent to the PDU. |
CommandSetSwitch | A command to set a switch on the PDU. |
CommandGetSwitchStatus | A command to get the status of a switch on the PDU. |
DataPong | A pong reply from the PDU. |
DataSwitchStatus | A switch status reply from the PDU. |
DataSwitchTelem | A switch status telemetry report for all switches on the PDU. |
Artemis::Devices::PDU::PDU | ( | HardwareSerial * | hw_serial, |
int | baud_rate | ||
) |
Construct a new PDU::PDU object.
hw_serial | The HardwareSerial object representing the serial connection used to communicate to the PDU. |
baud_rate | The speed of the serial connection to the PDU. |
The passed-in serial connection is copied to the private, internal serial variable. The private variable is then used to initialize the serial connection.
int32_t Artemis::Devices::PDU::get_switch | ( | PDU_SW | sw, |
string & | ret | ||
) |
Gets the state of a switch on the PDU.
sw | The switch, represented as a PDU_SW enum, to be checked. |
A pdu_packet is created, with header data specifying the switch to be checked.
The packet is sent to the PDU, and a response is awaited. If, after 5 seconds, no response is received, the attempt is a failure and a message is printed. After 5 failed attempts, the packet is dropped.
In the special case of the switch to be checked is in fact all the switches on the PDU, iterate over all the bytes in the reply packet. If any of the switches are off, represented by any byte in the reply packet's payload being zero, return 0. Only if all switches are on (all bits are one), return 1.
Otherwise, the fourth byte of the reply packet has the switch's state.
int32_t Artemis::Devices::PDU::recv | ( | std::string & | response | ) |
Receive a PDU packet from the PDU.
response | A pointer to the std::string holding the reply. |
The serial receive buffer is checked for available bytes.
If there are any, they are read in and saved to the string pointer.
If no bytes are available in the serial receive buffer, -1 is returned.
int32_t Artemis::Devices::PDU::send | ( | pdu_packet | packet | ) |
packet | The pdu_packet to be sent. |
The packet is copied into a character array.
The payload of the packet is converted to ASCII characters, then sent to the PDU via the serial connection.
The raw packet contents are also printed to the Teensy's serial connection for debugging purposes.
int32_t Artemis::Devices::PDU::set_switch | ( | PDU_SW | sw, |
uint8_t | _enable | ||
) |
Set a switch on the PDU.
sw | The switch, represented as a PDU_SW enum, to be set. |
_enable | The state to set the switch. |
A pdu_packet is created, with header data specifying the switch to be set and its desired status. Positive values are automatically corrected to 1 (on), and values less than 1 are corrected to 0 (off).
The packet is sent to the PDU, and a response is awaited. If, after 5 seconds, no response is received, the attempt is a failure and a message is printed. After 5 failed attempts, the packet is dropped.
std::map<std::string, PDU_SW> Artemis::Devices::PDU::PDU_SW_Type |
Mapping of string switch names to corresponding switch enums.
This map associates string switch name keys with PDU_SW values, allowing for easy translation between string switch names and switch enums.