Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions radsat-sk/spitballing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import struct

class GenericMessage(object):
preamble = bytes(69) # preamble is hard-coded and doesn't change.
def __init__(self,
data, # contains the raw data to be unpacked
timestamp=None, # time (in seconds) since Unix Epoch that the message was created
size=None, # size of the message in bytes (NOT including header)
type=None, # type of message
frameNum=0, # frame number of message
imageID=0, # image ID if applicable
body=None # the body of the message. Doesn't include the header (preamble, CRC, size, timestamp)
):

# if the data given can make up a message, strip off the header
if isinstance(data, bytes):
# see page 58 of the software design document
_, self.crc, self.size, self.timestamp, *self.body = struct.unpack('HHBI' + 'I' * len(data) - 9, data)

# at this point, the data contained in self.body is still encoded by protobuf. Need to decode.
a, b, c, d, e = protobuf_decode(self.body)

# otherwise, create a message with the given attributes
else:
self.timestamp = timestamp
self.size = size
self.type = type
self.frameNum = frameNum
self.imageID = imageID
self.body = body
self.data = None # no raw message given

# pack the data back into a string of bytes
def __generateRaw(self):
return struct.pack('HHBI' + 'I' * len(data) - 9, GenericMessage.preamble, self.crc, self.size, self.timestamp)

# convert the data into a csv format with appropriate values included
def convertToCsv(self):
return f'{self.timestamp},{self.size},{self.type},{self.frameNum},{self.body}'

"""-----------------------------
Public
-----------------------------"""

def generateLog(self):
return self.convertToCsv()

"""-----------------------------
Dunders
-----------------------------"""

def __bytes__(self):
if not data:
self.data = self.generateRaw()
return self.data

def __str__(self):
return str(self.data)

def __repr__(self):
return self.__str__()



class TelemetryMessage(GenericMessage):

def __generateRaw(self):
return struct.pack('some_string_here', GenericMessage.preamble, self.crc, self.size, self.timestamp)


# this function is where the bulk of the work will be. We need to determine what data is contained in
# the message and what data we want to save to a log.
def generateLog(self):
stringOut = self.convertToCsv()
file.writeLine(stringOut)
file.flush()
return self.convertToCsv()


def rawToMsg(rawData):
if rawData[64] == bytes(1):
return GenericMessage(rawData)
elif rawData[64] == bytes(1):
return TelemetryMessage(rawData)




raw = getSatMessage()
msg = rawToMsg(raw)

logger = Logger()

if isinstance(msg, GenericMessage):
logger.generic(msg)
elif isinstance(msg, TelemetryMessage):
logger.telemetry(msg)
28 changes: 28 additions & 0 deletions radsat-sk/testing/proto/RRadsat_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

224 changes: 224 additions & 0 deletions radsat-sk/testing/protobuf_messages/RFileTransfer.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/* file: fileTransfer.proto
* date: January 18 2021
*
* This proto file includes the raw definitions (using proto3 syntax) of
* messages that are to be compiled into C structs using the protoc library.
*
* The messages defined in this file will be used for file transfers, which
* focuses on the downlinked transmission of all data objects (images, telemetry
* data, etc.) from the RADSAT-SK Satellite to the Ground Station on Earth.
*/

syntax = "proto3";

// top level File Transfer message object
message file_transfer_message {
oneof message {
obc_telemetry ObcTelemetry = 1;
transceiver_telemetry TransceiverTelemetry = 2;
camera_telemetry CameraTelemetry = 3;
eps_telemetry EpsTelemetry = 4;
battery_telemetry BatteryTelemetry = 5;
antenna_telemetry AntennaTelemetry = 6;
dosimeter_data DosimeterData = 7;
image_packet ImagePacket = 8;
module_error_report ModuleErrorReport = 9;
component_error_report ComponentErrorReport = 10;
error_report_summary ErrorReportSummary = 11;
}
}

// Information about the state of the OBC
message obc_telemetry {
uint32 mode = 1; ///< Mode of operation at time of recording
uint32 uptime = 2; ///< Uptime (in ticks) since last reset (of any kind)
uint32 rtcTime = 3; ///< RTC Time (in unix time; seconds since Unix Epoch)
uint32 rtcTemperature = 4; ///< 10bit Temperature recorded by OBC's RTC
}


// Telemetry for the Receiver
// Used internally; not sent as standalone message
message receiver_telemetry {
float rxDoppler = 1; ///< Rx Telemetry receiver doppler.
float rxRssi = 2; ///< Rx Telemetry rssi measurement.
float busVoltage = 3; ///< Rx Telemetry bus voltage.
float totalCurrent = 4; ///< Tx Telemetry total current.
float txCurrent = 5; ///< Tx Telemetry transmitter current.
float rxCurrent = 6; ///< Tx Telemetry receiver current.
float powerAmplifierCurrent = 7; ///< Tx Telemetry power amplifier current.
float powerAmplifierTemperature = 8; ///< Rx Telemetry power amplifier temperature
float boardTemperature = 9; ///< Rx Telemetry board temperature.
uint32 uptime = 10; ///< Rx Uptime in Seconds.
uint32 frames = 11; ///< Rx Frames currently in Receive Buffer.
}

// Telemetry for the Transmitter
// Used internally; not sent as standalone message
message transmitter_telemetry {
float reflectedPower = 1; ///< Tx Telemetry reflected power.
float forwardPower = 2; ///< Tx Telemetry forward power.
float busVoltage = 3; ///< Tx Telemetry bus voltage.
float totalCurrent = 4; ///< Tx Telemetry total current.
float txCurrent = 5; ///< Tx Telemetry transmitter current.
float rxCurrent = 6; ///< Tx Telemetry receiver current.
float powerAmplifierCurrent = 7; ///< Tx Telemetry power amplifier current.
float powerAmplifierTemperature = 8; ///< Tx Telemetry power amplifier temperature.
float boardTemperature = 9; ///< Tx Telemetry board temperature.
uint32 uptime = 10; ///< Tx Uptime in Seconds.
}

// Information about the state of the Transceiver
message transceiver_telemetry {
receiver_telemetry receiver = 1; ///< Receiver Telemetry
transmitter_telemetry transmitter = 2; ///< Transmitter Telemetry
}

// Camera power related telemetry
// Used internally; not sent as standalone message
message camera_power_telemetry {
float current_3V3 = 1;
float current_5V = 2;
float current_SRAM_1 = 3;
float current_SRAM_2 = 4;
uint32 overcurrent_SRAM_1 = 5;
uint32 overcurrent_SRAM_2 = 6;
}

// Camera configuration related telemetry
// Used internally; not sent as standalone message
message camera_configuration_telemetry {
uint32 detectionThreshold = 1;
uint32 autoAdjustMode = 2;
uint32 exposure = 3;
uint32 autoGainControl = 4;
uint32 blueGain = 5;
uint32 redGain = 6;
}

// Information about the state of the Camera
message camera_telemetry {
uint32 uptime = 1; ///< Local uptime (since last startup) in seconds
camera_power_telemetry powerTelemetry = 2;
camera_configuration_telemetry cameraOneTelemetry = 3;
camera_configuration_telemetry cameraTwoTelemetry = 4;
}

// Data for the sun sensor telemetry
// Used internally; not sent as standalone message
message sun_sensor_data {
float xPos = 1;
float xNeg = 2;
float yPos = 3;
float yNeg = 4;
float zPos = 5;
float zNeg = 6;
}

// Information about the state of the Electrical Power Supply
message eps_telemetry {
sun_sensor_data sunSensorData = 1;
float outputVoltageBCR = 2;
float outputVoltageBatteryBus = 3;
float outputVoltage5VBus = 4;
float outputVoltage3V3Bus = 5;
float outputCurrentBCR_mA = 6;
float outputCurrentBatteryBus = 7;
float outputCurrent5VBus = 8;
float outputCurrent3V3Bus = 9;
float PdbTemperature = 10;
}

// Information about the state of the Battery
message battery_telemetry {
float outputVoltageBatteryBus = 1;
float outputVoltage5VBus = 2;
float outputVoltage3V3Bus = 3;
float outputCurrentBatteryBus = 4;
float outputCurrent5VBus = 5;
float outputCurrent3V3Bus = 6;
float batteryCurrentDirection = 7;
float motherboardTemp = 8;
float daughterboardTemp1 = 9;
float daughterboardTemp2 = 10;
float daughterboardTemp3 = 11;
}

// Telemetry data for a single antenna microcontroller
// Used internally; not sent as standalone message
message antenna_side_data {
uint32 deployedAntenna1 = 1;
uint32 deployedAntenna2 = 2;
uint32 deployedAntenna3 = 3;
uint32 deployedAntenna4 = 4;
uint32 armed = 5;
float boardTemp = 6;
uint32 uptime = 7;
}

// Information about the state of the Antenna
message antenna_telemetry {
antenna_side_data sideA = 1;
antenna_side_data sideB = 2;
}



// Payload Data for a single Dosimeter board
// Used internally; not sent as standalone message
message dosimeter_board_data {
float channelZero = 1; ///< COTS 2048mV REF IC, Shielding: none
float channelOne = 2; ///< COTS 2048mV REF IC, Shielding: 50 mil
float channelTwo = 3; ///< COTS 2048mV REF IC, Shielding: 100 mil
float channelThree = 4; ///< COTS 2048mV REF IC, Shielding: 200 mil
float channelFour = 5; ///< COTS 2048mV REF IC, Shielding: 20 mil
float channelFive = 6; ///< RADFET Experimental Dosimeter, Shielding: none
float channelSix = 7; ///< COTS 2048mV REF IC, Shielding: 300 mil
float channelSeven = 8; ///< Temperature Sensor
}

// Dosimeter Payload Data (both boards)
message dosimeter_data {
dosimeter_board_data boardOne = 1; ///< Payload Data from the first Dosimeter Board ("bottom" of the Satellite, beneath OBC)
dosimeter_board_data boardTwo = 2; ///< Payload Data from the second Dosimeter Board ("top" of the Satellite, beneath Antenna)
}

// Enum for image types (i.e. sizes)
enum image_type_t {
FullResolution = 0; ///< 1024 x 1024 = 1MB
HalfResolution = 1; ///< 512 x 512 = 256kB
QuarterResolution = 2; ///< 256 x 256 = 64kB
Thumbnail = 3; ///< 64 x 64 = 4kB
}

// Image Packet
message image_packet {
uint32 id = 1; ///< ID of the image
image_type_t type = 2; ///< Size of the image
bytes data = 3; ///< The raw image data
}

// Error Report (single module)
message module_error_report {
uint32 module = 1; ///< The unique ID of the module
int32 error = 2; ///< The ID of the error that occurred
}

// Error Report (single module)
message component_error_report {
uint32 component = 1; ///< The unique ID of the component
int32 error = 2; ///< The ID of the error that occurred
}

// record of the current error status for a particular module or component
// Used internally; not sent as standalone message
message error_record {
uint32 timeRecorded = 1; ///< Tick time that the last error was recorded
uint32 count = 2; ///< Current count of tracked errors
}

// Error Report (summary)
message error_report_summary {
repeated uint32 moduleErrorCount = 1; ///< Error counts for all modules
repeated uint32 componentErrorCount = 2; ///< Error counts for all components
}
Loading