Ke Ao Teensy Flight Software
The software on the Teensy in the Ke Ao cubesat.
Loading...
Searching...
No Matches
astrodev.h
Go to the documentation of this file.
1
6#ifndef ASTRODEV_H
7#define ASTRODEV_H
8
9#include "debug.h"
10#include "support/configCosmosKernel.h"
11#include "support/cosmos-errno.h"
12#include "support/packetcomm.h"
13#include <Arduino.h>
14#include <TeensyThreads.h>
15#include <atomic>
16
17namespace Artemis {
18 namespace Devices {
20 class Astrodev {
21 public:
23 static constexpr uint8_t SYNC0 = 'H';
25 static constexpr uint8_t SYNC1 = 'e';
33 static constexpr uint8_t TORADIO = 0x10;
41 static constexpr uint8_t TOTEENSY = 0x20;
48 static constexpr uint8_t MTU = 254;
58 static constexpr uint16_t PACKETCOMM_DATA_SIZE =
59 MTU - (COSMOS_SIZEOF(PacketComm::Header) + 2);
60
68 std::map<uint8_t, uint16_t> RF_BAUD = {
69 {0, 1200},
70 {1, 9600},
71 {2, 19200},
72 {3, 38400},
73 {4, 57600},
74 {5, 115200}
75 };
83 std::map<uint16_t, uint8_t> RF_INDEX = {
84 { 1200, 0},
85 { 9600, 1},
86 { 19200, 2},
87 { 38400, 3},
88 { 57600, 4},
89 {115200, 5}
90 };
98 std::map<uint8_t, uint16_t> UART_BAUD = {
99 {0, 9600},
100 {1, 19200},
101 {2, 38400},
102 {3, 57600},
103 {4, 115200}
104 };
112 std::map<uint16_t, uint8_t> UART_INDEX = {
113 { 9600, 0},
114 { 19200, 1},
115 { 38400, 2},
116 { 57600, 3},
117 {115200, 4}
118 };
119
126 enum class Command : uint8_t {
127 NAK = 0x00,
128 NOOP = 0x01,
129 RESET = 0x02,
130 TRANSMIT = 0x03,
131 RECEIVE = 0x04,
132 GETTCVCONFIG = 0x05,
133 SETTCVCONFIG = 0x06,
134 TELEMETRY = 0x07,
136 FLASH = 0x08,
137 RFCONFIG = 0x09,
138 BEACONDATA = 0x10,
139 BEACONCONFIG = 0x11,
140 FIRMWAREREV = 0x12,
141 DIOKEY = 0x13,
142 FIRMWAREUPDATE = 0x14,
143 FIRMWAREPACKET = 0x15,
144 WRITE_KEY_A_128 = 0x16,
145 WRITE_KEY_B_128 = 0x17,
146 WRITE_KEY_A_256 = 0x18,
147 WRITE_KEY_B_256 = 0x19,
148 FASTSETPA = 0x20,
149 GET_RTC = 0x41,
150 SET_RTC = 0x42,
151 ALARM_RTC = 0x43,
152 };
153
160 enum class Modulation : uint8_t {
168 };
169
177 enum class OACommand {
178 TELEMETRY_DUMP = 0x30,
180 PING_RETURN = 0x31,
181 CODE_UPLOAD = 0x32,
183 RADIO_RESET = 0x33,
184 PIN_TOGGLE = 0x34,
185 };
186
199 struct __attribute__((packed)) response {
201 uint8_t ack : 4;
203 bool buffer_full : 1;
205 bool gpio_a_high : 1;
207 bool gpio_b_high : 1;
210 };
286 uint16_t rx_crc_enable : 1;
297 uint16_t tx_crc_enable : 1;
329 uint16_t tlm_dump_enable : 1;
339 uint16_t oa_commands_enable : 1;
348 uint16_t code_upload_enable : 1;
357 uint16_t radio_reset_enable : 1;
367 };
429 uint16_t rx_afc_enable : 1;
440 uint16_t test_mode_rx_cw : 1;
451 uint16_t test_mode_tx_cw : 1;
461 uint16_t test_mode_tbd : 1;
470 uint16_t zeros : 4;
471 };
508 struct __attribute__((packed)) tcv_config {
588 uint32_t rx_frequency;
595 uint32_t tx_frequency;
601 uint8_t ax25_source[6];
608 uint8_t ax25_destination[6];
637 };
698 struct __attribute__((packed)) rf_config {
729 uint16_t tx_freq;
741 uint16_t rx_freq;
742 };
770 struct __attribute__((packed)) telemetry {
777 uint16_t op_counter;
786 int16_t msp430_temp;
794 unsigned time_count : 24;
803 uint8_t rssi;
810 uint32_t bytes_rx;
817 uint32_t bytes_tx;
826 uint8_t rssi_last;
839 uint16_t cs;
840 };
888 struct __attribute__((packed)) firmware {
896 float rev;
902 uint16_t cs;
903 };
926 struct __attribute__((packed)) realtimeclock {
933 uint16_t year;
940 uint8_t mon;
947 uint8_t day;
954 uint8_t dow;
961 uint8_t hour;
968 uint8_t min;
975 uint8_t sec;
983 uint8_t alarm_dow;
991 uint8_t alarm_day;
999 uint8_t alarm_hour;
1007 uint8_t alarm_min;
1008 };
1043 struct __attribute__((packed)) beacon_config {
1057 uint16_t cs;
1058 };
1059
1070 struct __attribute__((packed)) frame {
1091 struct header {
1093 uint8_t sync0;
1095 uint8_t sync1;
1138 uint8_t sizehi;
1141 uint8_t sizelo;
1148 uint16_t cs;
1149 } header;
1178 uint8_t header_bytes[8];
1179 } frame_header;
1198 uint8_t payload[MTU + 20];
1209 } frame_payload;
1210 };
1211
1212 telemetry last_telem;
1213 int32_t last_error = 0;
1214 std::atomic<bool> buffer_full;
1215 Command last_command = Command::NAK;
1216 tcv_config tcv_configuration;
1217
1218 // int32_t Queue(queue<PacketComm> &queue, mutex &mtx, const PacketComm
1219 // &p); int32_t DeQueue(queue<PacketComm> &queue, mutex &mtx, PacketComm
1220 // &p); int32_t PacketIn(PacketComm &p); int32_t PacketInSize(); int32_t
1221 // PacketOut(PacketComm &p); int32_t PacketOutSize(); int32_t
1222 // Clear(queue<PacketComm> &queue, mutex &mtx);
1223 Astrodev();
1224 Astrodev(HardwareSerial *hw_serial);
1225 int32_t InitializeSerial(HardwareSerial *hw_serial,
1226 uint32_t baud_rate = 38400);
1227 int32_t VerifyConnection();
1228 int32_t SendAstrodevFrame(frame &message);
1229 int32_t SendHeaderOnlyFrame(Command command);
1230 int32_t NoOp();
1231 int32_t Reset();
1232 int32_t GetTCVConfig();
1233 int32_t GetTelemetry();
1234 int32_t TransmitPacketFromRadio(Cosmos::Support::PacketComm &packet);
1235 int32_t SetTCVConfig();
1236 int32_t SetRFConfig(rf_config config);
1237 // int32_t SendData(vector<uint8_t> data);
1238 int32_t ReceiveAstrodevFrame(frame &message);
1239 uint16_t CalcCS(uint8_t *data, uint16_t size);
1240
1241 // For debugging purposes
1242 void setSerial(HardwareSerial *new_serial);
1243
1244 // ACKs
1245 std::atomic<bool> ack_noop;
1246 std::atomic<bool> ack_reset;
1247 std::atomic<bool> ack_transmit;
1248 std::atomic<bool> ack_setTCVConfig;
1249
1250 private:
1251 HardwareSerial *serial;
1252 bool running = true;
1253
1254 queue<vector<uint8_t>> queue_in;
1255 Threads::Mutex qmutex_in;
1256
1257 queue<PacketComm> packet_queue_out;
1258 Threads::Mutex qmutex_out;
1259 };
1260 } // namespace Devices
1261} // namespace Artemis
1262
1263#endif // ASTRODEV_H
The satellite's Astrodev (Li-3) radio.
Definition astrodev.h:20
int32_t GetTCVConfig()
Send a get transceiver configuration command to the Astrodev radio.
Definition astrodev.cpp:331
static constexpr uint8_t SYNC0
The first synchronization byte.
Definition astrodev.h:23
int32_t TransmitPacketFromRadio(Cosmos::Support::PacketComm &packet)
Command the Astrodev radio to transmit a PacketComm packet.
Definition astrodev.cpp:367
uint16_t CalcCS(uint8_t *data, uint16_t size)
Calculate a checksum.
Definition astrodev.cpp:510
int32_t SetTCVConfig()
Set transceiver configuration settings on the radio.
Definition astrodev.cpp:431
int32_t NoOp()
Send a no-operation (no-op) command to the Astrodev radio.
Definition astrodev.cpp:296
std::map< uint16_t, uint8_t > RF_INDEX
Mapping of RF baud rate to integer configuration values.
Definition astrodev.h:83
int32_t SendAstrodevFrame(frame &message)
Send an Astrodev frame to the radio.
Definition astrodev.cpp:156
int32_t InitializeSerial(HardwareSerial *hw_serial, uint32_t baud_rate=38400)
Initialization of the serial connection to the Astrodev radio.
Definition astrodev.cpp:42
void setSerial(HardwareSerial *new_serial)
Sets the serial connection used to communicate with the radio.
Definition astrodev.cpp:751
static constexpr uint16_t PACKETCOMM_DATA_SIZE
The maximum size of a PacketComm payload.
Definition astrodev.h:58
static constexpr uint8_t TOTEENSY
A response being sent from the radio.
Definition astrodev.h:41
std::map< uint8_t, uint16_t > RF_BAUD
Mapping of integer configuration values to RF baud rate.
Definition astrodev.h:68
Command
Enumeration of Astrodev commands.
Definition astrodev.h:126
@ TRANSMIT
Send bytes to Astrodev radio.
@ BEACONCONFIG
Set beacon configuration.
@ FLASH
Write to the Astrodev radio's flash memory.
@ GETTCVCONFIG
Get Astrodev radio configuration.
@ FIRMWAREPACKET
Firmware packet write.
@ GET_RTC
Get Real-Time Clock (RTC) values.
@ WRITE_KEY_B_256
Used to write to the firmware.
@ WRITE_KEY_A_256
Used to write to the firmware.
@ SET_RTC
Set Real-Time Clock (RTC).
@ WRITE_KEY_B_128
Used to write to the firmware.
@ RFCONFIG
Low level RF configuration.
@ RECEIVE
Receive bytes from Astrodev radio.
@ WRITE_KEY_A_128
Used to write to the firmware.
@ BEACONDATA
Set beacon contents.
@ FASTSETPA
Set power amplifier level (high speed)
@ DIOKEY
Digital I/O (DIO) key write.
@ RESET
Reset Astrodev radio processors and systems.
@ ALARM_RTC
An alarm on the Real-Time Clock (RTC).
@ SETTCVCONFIG
Set Astrodev radio configuration.
@ FIRMWAREUPDATE
Firmware update command.
@ FIRMWAREREV
Firmware number, a 4-byte float.
static constexpr uint8_t SYNC1
The second synchronization byte.
Definition astrodev.h:25
int32_t SendHeaderOnlyFrame(Command command)
Helper function to construct and send header-only command frames to the Astrodev radio.
Definition astrodev.cpp:258
int32_t ReceiveAstrodevFrame(frame &message)
Receive an Astrodev frame from the radio.
Definition astrodev.cpp:546
OACommand
Enumeration of Over-the-Air (OA) Astrodev commands.
Definition astrodev.h:177
@ RADIO_RESET
Soft reset the radio.
@ PING_RETURN
Responds with telemetry structure.
@ PIN_TOGGLE
Directly toggle over-the-air pin.
int32_t GetTelemetry()
Sends a get telemetry command to the Astrodev radio.
Definition astrodev.cpp:346
std::map< uint16_t, uint8_t > UART_INDEX
Mapping of serial baud rate to integer configuration values.
Definition astrodev.h:112
static constexpr uint8_t TORADIO
A command being sent from the Teensy.
Definition astrodev.h:33
Astrodev()
Construct a new Astrodev:: Astrodev object.
Definition astrodev.cpp:17
static constexpr uint8_t MTU
The Maximum Transmission Units (MTU).
Definition astrodev.h:48
Modulation
Enumeration of Astrodev modulation types.
Definition astrodev.h:160
int32_t VerifyConnection()
Verify serial connection to the Astrodev radio.
Definition astrodev.cpp:62
int32_t SetRFConfig(rf_config config)
Sets the RF configuration settings on the radio.
Definition astrodev.cpp:477
int32_t Reset()
Send a soft reset command to the Astrodev radio.
Definition astrodev.cpp:316
std::map< uint8_t, uint16_t > UART_BAUD
Mapping of integer configuration values to serial baud rate.
Definition astrodev.h:98
Definitions of Serial Console helper functions.
Structure for beacon configuration.
Definition astrodev.h:1043
uint8_t beacon_interval
The interval at which the beacon should be transmitted.
Definition astrodev.h:1051
uint16_t cs
Beacon configuration checksum.
Definition astrodev.h:1057
Structure for radio firmware version communication.
Definition astrodev.h:888
float rev
The firmware revision of the radio.
Definition astrodev.h:896
uint16_t cs
Firmware checksum.
Definition astrodev.h:902
The Astrodev frame header structure.
Definition astrodev.h:1091
uint8_t sync0
The first synchronization byte.
Definition astrodev.h:1093
uint8_t sync1
The second synchronization byte.
Definition astrodev.h:1095
uint16_t cs
Header checksum.
Definition astrodev.h:1148
uint8_t sizelo
The low byte of the payload size value.
Definition astrodev.h:1141
Command command
The packet command.
Definition astrodev.h:1118
uint8_t destination
The destination of the frame.
Definition astrodev.h:1108
Structure of Astrodev Command and Data Interface (CDI) frame.
Definition astrodev.h:1070
Structure for configuring discrete Astrodev radio functions.
Definition astrodev.h:235
uint16_t tlm_packet_logging_rate
Telemetry packet logging rate.
Definition astrodev.h:319
uint16_t tx_crc_enable
Enable CRC for transmitted packets.
Definition astrodev.h:297
uint16_t rx_crc_enable
Enable CRC for received packets.
Definition astrodev.h:286
uint16_t config2_pin13_functions
Pin 13 configuration options.
Definition astrodev.h:257
uint16_t radio_reset_enable
Enable radio reset.
Definition astrodev.h:357
uint16_t oa_commands_enable
Enable Over-the-Air (OA) commands.
Definition astrodev.h:339
uint16_t config1_pin14_dio_pattern
Pin 14 Digital I/O (DIO) enable pattern.
Definition astrodev.h:276
uint16_t config1_pin14_dio_enable
Pin 14 Digital I/O (DIO) enable options.
Definition astrodev.h:267
uint16_t tlm_packet_logging_enable
Enable telemetry packets.
Definition astrodev.h:307
uint16_t ext_event_pin12_functions
Pin 12 external event functions.
Definition astrodev.h:246
uint16_t factory_defaults_restored
Factory settings restore complete flag.
Definition astrodev.h:366
uint16_t tlm_dump_enable
Enable telemetry dump.
Definition astrodev.h:329
uint16_t code_upload_enable
Enable code uploading.
Definition astrodev.h:348
Structure for configuring more discrete Astrodev radio functions.
Definition astrodev.h:419
uint16_t rx_afc_enable
Enable receiver Automatic Frequency Control (AFC).
Definition astrodev.h:429
uint16_t zeros
Padding bits.
Definition astrodev.h:470
uint16_t test_mode_rx_cw
Enable receive Continuous Wave (CW) mode.
Definition astrodev.h:440
uint16_t test_mode_tbd
Enable a To-Be-Determined (TBD) test mode.
Definition astrodev.h:461
uint16_t test_mode_tx_cw
Enable transmit Continuous Wave (CW) mode.
Definition astrodev.h:451
Structure for radio Real-Time Clock (RTC) communication.
Definition astrodev.h:926
uint8_t min
The minute of a time.
Definition astrodev.h:968
uint8_t dow
The day of week of a date.
Definition astrodev.h:954
uint8_t hour
The hour of a time.
Definition astrodev.h:961
uint8_t sec
The second of a time.
Definition astrodev.h:975
uint8_t mon
The month of a date.
Definition astrodev.h:940
uint8_t alarm_day
The alarm day.
Definition astrodev.h:991
uint8_t day
The day of a date.
Definition astrodev.h:947
uint8_t alarm_hour
The alarm hour.
Definition astrodev.h:999
uint16_t year
The year of a date.
Definition astrodev.h:933
uint8_t alarm_dow
The alarm day of week.
Definition astrodev.h:983
uint8_t alarm_min
The alarm minute.
Definition astrodev.h:1007
The structure for a response from the Astrodev radio.
Definition astrodev.h:199
bool external_event_high
Whether or not an external event has been triggered.
Definition astrodev.h:209
bool gpio_a_high
Whether or not the GPIO A pin is on.
Definition astrodev.h:205
bool gpio_b_high
Whether or not the GPIO B pin is on.
Definition astrodev.h:207
uint8_t ack
The acknowledgement from the radio.
Definition astrodev.h:201
bool buffer_full
Whether or not the buffer is full.
Definition astrodev.h:203
Structure for configuring the RF functions of the Astrodev radio.
Definition astrodev.h:698
uint8_t front_end_level
The amplification level of the front end of the radio.
Definition astrodev.h:707
uint16_t rx_freq
The recieve frequency offset.
Definition astrodev.h:741
uint16_t tx_freq
The transmit frequency offset.
Definition astrodev.h:729
uint8_t power_amp_level
The amplification level of the power amplifier of the radio.
Definition astrodev.h:717
Structure for configuring the Astrodev radio.
Definition astrodev.h:508
uint16_t ax25_postamble_length
AX25 Mode transmit postamble length.
Definition astrodev.h:620
uint8_t tx_baud_rate
The RF transmit baud rate.
Definition astrodev.h:563
uint32_t tx_frequency
The operating frequency for the transmitter.
Definition astrodev.h:595
uint32_t rx_frequency
The operating frequency for the receiver.
Definition astrodev.h:588
uint8_t rx_baud_rate
The RF receive baud rate.
Definition astrodev.h:548
Devices::Astrodev::Modulation tx_modulation
The modulation for the transmitter.
Definition astrodev.h:581
function_config2 config2
More discrete radio function configuration.
Definition astrodev.h:636
Devices::Astrodev::Modulation rx_modulation
The modulation for the receiver.
Definition astrodev.h:572
function_config1 config1
Discrete radio function configuration.
Definition astrodev.h:628
uint16_t ax25_preamble_length
AX25 Mode transmit preamble length.
Definition astrodev.h:614
uint8_t interface_baud_rate
The baud rate of the radio's serial interface.
Definition astrodev.h:523
uint8_t power_amp_level
The transmit power amplifier level.
Definition astrodev.h:533
Structure for configuring telemetry data for the Astrodev radio.
Definition astrodev.h:770
uint8_t rtc_alarm_flag
Real-Time Clock (RTC) alarm flag.
Definition astrodev.h:833
uint8_t rssi
The Received Signal Strength Indicator (RSSI).
Definition astrodev.h:803
unsigned time_count
Timestamp of telemetry data.
Definition astrodev.h:794
uint16_t op_counter
Operations counter.
Definition astrodev.h:777
uint32_t bytes_rx
The total number of bytes received.
Definition astrodev.h:810
uint8_t rssi_last
The last recorded Recieved Signal Strength Indicator (RSSI).
Definition astrodev.h:826
int16_t msp430_temp
Radio temperature.
Definition astrodev.h:786
uint16_t cs
Telemetry checksum.
Definition astrodev.h:839
uint32_t bytes_tx
The total number of bytes transmitted.
Definition astrodev.h:817
The payload size/radio status field.
Definition astrodev.h:1128
response status
The status reply from the radio.
Definition astrodev.h:1130
uint8_t sizehi
The high byte of the payload size value.
Definition astrodev.h:1138
The header of the radio data frame.
Definition astrodev.h:1078
The payload of the radio data frame.
Definition astrodev.h:1188
firmware firmw
Firmware version.
Definition astrodev.h:1204
rf_config rf
RF configuration.
Definition astrodev.h:1202
tcv_config tcv
Transciever configuration.
Definition astrodev.h:1200
telemetry telem
Telemetry data.
Definition astrodev.h:1206
realtimeclock rtc
Real-Time Clock (RTC) data.
Definition astrodev.h:1208