Ke Ao Teensy Flight Software
The software on the Teensy in the Ke Ao cubesat.
Loading...
Searching...
No Matches
Artemis::Devices::PDU Class Reference

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_SWPDU_SW_Type
 Mapping of string switch names to corresponding switch enums.
 

Detailed Description

The satellite's Power Distribution Unit (PDU).

Member Enumeration Documentation

◆ PDU_SW

enum class Artemis::Devices::PDU::PDU_SW : uint8_t
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.

Todo:
verify the switches and names
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.

◆ PDU_Type

enum class Artemis::Devices::PDU::PDU_Type : uint8_t
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.

Constructor & Destructor Documentation

◆ PDU()

Artemis::Devices::PDU::PDU ( HardwareSerial *  hw_serial,
int  baud_rate 
)

Construct a new PDU::PDU object.

Parameters
hw_serialThe HardwareSerial object representing the serial connection used to communicate to the PDU.
baud_rateThe 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.

Member Function Documentation

◆ get_switch()

int32_t Artemis::Devices::PDU::get_switch ( PDU_SW  sw,
string &  ret 
)

Gets the state of a switch on the PDU.

Parameters
swThe switch, represented as a PDU_SW enum, to be checked.
Returns
int32_t The state of the switch. Can be either 1 (on) or 0 (off). If unable to get state of switch, returns -1.

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.

Todo:
Send to PacketComm packet -> then to ground

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.

◆ recv()

int32_t Artemis::Devices::PDU::recv ( std::string &  response)

Receive a PDU packet from the PDU.

Parameters
responseA pointer to the std::string holding the reply.
Returns
int32_t Returns the length of the received string if successful, -1 if unsuccessful.

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.

◆ send()

int32_t Artemis::Devices::PDU::send ( pdu_packet  packet)

Send a PDU packet to the PDU.

Parameters
packetThe pdu_packet to be sent.
Returns
int32_t Always returns zero.

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.

◆ set_switch()

int32_t Artemis::Devices::PDU::set_switch ( PDU_SW  sw,
uint8_t  _enable 
)

Set a switch on the PDU.

Parameters
swThe switch, represented as a PDU_SW enum, to be set.
_enableThe state to set the switch.
Returns
int32_t Returns 0 if switch sucessfully set, -1 if unsuccessful.

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.

Todo:
Send to PacketComm packet -> then to ground

Member Data Documentation

◆ PDU_SW_Type

std::map<std::string, PDU_SW> Artemis::Devices::PDU::PDU_SW_Type
Initial value:
= {
{ "all", PDU_SW::All},
{ "3v3_1", PDU_SW::SW_3V3_1},
{ "3v3_2", PDU_SW::SW_3V3_2},
{ "5v_1", PDU_SW::SW_5V_1},
{ "5v_2", PDU_SW::SW_5V_2},
{ "5v_3", PDU_SW::SW_5V_3},
{ "5v_4", PDU_SW::SW_5V_4},
{ "12v", PDU_SW::SW_12V},
{ "vbatt", PDU_SW::VBATT},
{ "wdt", PDU_SW::WDT},
{"hbridge1", PDU_SW::HBRIDGE1},
{"hbridge2", PDU_SW::HBRIDGE2},
{ "burn", PDU_SW::BURN},
{ "burn1", PDU_SW::BURN1},
{ "burn2", PDU_SW::BURN2},
{ "rpi", PDU_SW::RPI},
}
@ 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.
@ 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.

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.


The documentation for this class was generated from the following files: