Data: Encoder
Description
The Data Encoder
is a static function library that can help with encoding and decoding objects into their binary forms. Although it is not a direct component that can be added to the system, it is used by a number of modules to help with manipulating the data objects and storing them correctly in the data storage units.
Example Use Cases
- Decoding packets of data into messages
- Creating a series of packets storing byte data from a message
- Calculating checksums of data bytes for use when ensuring data has been validated correctly.
Module Implementation
There are a number of core functions for the encoder to perform. They can be broken up into three categories; storage, decoding and encoding. These are all static functions that help the data system to correctly turn data into the right format when required.
Storage:
The main function is the checksum function. This will return the number of positive bits (a 1, as opposed to a 0) within an array of bytes. It does this by first creating a map of all byte values (0 - 255) and determining the number of 1’s within each byte (from 0 to 8). For example, byte 5 can be represented as 00000101
, which contains 2 1’s, and byte 233 can be represented as 11101001
. As such, if two bytes (5.233
) were passed into the function, then the return value will be the sum of the positive bits in all bytes, evaluating to 7
, in this case.
where \(c\) is the checksum total, \(n\) is the number of bytes and \(b(B_n)\) is the bit counter function for a particular byte \(B_n\).
Encoding:
The encoding functions can convert a range of different data values into other data formats. The available data formats that can be converted between, in order from lowest to highest fidelity are:
- Bytes: A byte array of the binary data stored as memory code directly stored in the data storage system and on the telemetry packets that handle the TT&C transfer of data.
- Packets: A data packet is an internal structure for storing a list of binary data that can be processed by the TT&C system. It is used to handle an array of byte data.
- Message: An input message that typically stores a list of structured data that provides information about a particular component. Messages can be decomposed to their raw binary format for transfer and storage.
- Object: A generic class type that can be stored by the C# library. Objects can also be encoded into binary data and stored within.
As such, there are encoding functions that encode each of these types to each other and return the output of each. The main method that has the primary functionality is the EncodePacketToBytes
function. Here, it takes a list of packets that come from the telemetry system and combines them into one long array of bytes. It is then able to transpose the packets so they are ordered correctly and returns the final list of bytes that were stored within the packet.
Decoding:
Similar to the encoding process, the decoder functions can convert the lower forms of data (such as the byte arrays) to the higher more useful forms (such as messages and objects). Each of the different data structures can be converted between the values and for the cases of the data packets, the checksums are also calculated and inserted into the packet for checksum validation. In the DecodeBytesToPackets
function, depending on the packet size, \(n\) number of packets will be created where:
where \(b\) is the number of bytes and \(p\) is the packet size. The packets will break up a large array of bytes into individual packets that can be communicated separately on the communication system. The packets will then be recompiled back into their original form when encoded from the byte data.
Assumptions/Limitations
- The encoder and decoder system is fixed and is not a module that can be adjusted or implemented in the simulation.