Example of CCSDS packet generation
Closed this issue · 2 comments
Hi everyone,
I'm not familiar with the space standard packets and I'm trying to create messages using CCSDS format and I've found this library which seems really good for it.
Anyway, I don't really understand how to put my data inside a telemetry packet. Does anyone have an example of creation of a message including his data?
For instance I'm tring to create a CCSDS package in this way:
from CCSDS import PACKET
packet = PACKET.createIdlePacket()
However, I don't understand how to insert my data, for instance "latitude":10.4444, "longitude":xxx, "yaw":xxx etc.
Can anyone share a simple example of it using this library?
Thank you in advance
There are several ways to set the data in the packet, two of them are shown here:
Example 1: Simple example
import CCSDS.PACKET
# create the packet - contains only the CCSDS packet header
packet = CCSDS.PACKET.Packet()
print(packet.getDumpString())
# set the total size of the packet: 20 bytes
packet.setLen(20)
print(packet.getDumpString())
# set some field in the packet: see UTIL.DU
packet.setFloat(8, 4, 10.4444)
packet.setUnsigned(12, 2, 65535)
packet.setString(14, 4, "test")
print(packet.getDumpString())
# set the packet header: see CCSDS.PACKET
packet.applicationProcessId = 1234
packet.sequenceControlCount = 5678
packet.setPacketLength()
print(packet)
# set a CRC (if needed)
packet.setChecksum()
print(packet)
Example 2: set packet from layout template
import CCSDS.PACKET
import UTIL.DU
# prepare the layout template: data are placed after the CCSDS packet header
USER_DATA_BYTE_SIZE = 14
USER_DATA_ATTRIBUTES = {
"latitude": (2, 4, UTIL.DU.FLOAT),
"longitude": (6, 2, UTIL.DU.UNSIGNED),
"yaw": (8, 4, UTIL.DU.STRING)}
# create the packet according to the layout template
packet2 = CCSDS.PACKET.TMpacket(attributesSize2=USER_DATA_BYTE_SIZE,
attributeMap2=USER_DATA_ATTRIBUTES)
print(packet2)
# set some field in the packet
packet2.latitude = 10.4444
packet2.longitude = 65535
packet2.yaw = "test"
print(packet2.getDumpString())
# set the packet header: see CCSDS.PACKET
packet2.applicationProcessId = 1234
packet2.sequenceControlCount = 5678
packet2.setPacketLength()
print(packet2)
# set a CRC (if needed)
packet2.setChecksum()
print(packet2)
Thank you Stefan, it seems working well!