Previous reading is 20240320 - Ground segment - Workshop 1 - Define you OpenC3 COSMOS system
TODO: Cleanup the next note
In this guide I am going to show you:
- How to create a new
In the previous guide we were able to create our own OpenC3 COSMOS plugin. In this guide we will simulate telemetry using python and construct.
Define our telemetry
The telemetry has the next information:
TELEMETRY BOB STATUS BIG_ENDIAN "Telemetry description"
# Keyword Name BitSize Type ID Description
APPEND_ID_ITEM ID 16 INT 1 "Identifier"
APPEND_ITEM VALUE 32 FLOAT "Value"
APPEND_ITEM BOOL 8 UINT "Boolean"
STATE FALSE 0
STATE TRUE 1
APPEND_ITEM LABEL 0 STRING "The label to apply"
We are going to define the telemetry using python and construct. It would look something like:
from construct import Struct, Int16ub, Float32b, Bit, CString
import math
# Define BOB telemetry packet
BOB = Struct(
"ID" / Int16ub,
"VALUE" / Float32b,
"BOOL" / Bit,
"LABEL" / CString("utf8")
)
bob_data_dict = dict(
ID = 1,
VALUE = 3.27,
BOOL = 0b0,
LABEL = "Hello world"
)
bob_packet = BOB.build(bob_data_dict)
#%%
# Send the packet over TCP
import socket
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the server and port
server_address = ('cosmos.insightsat.com', 8002)
sock.connect(server_address)
try:
# Prepare the binary data
message = bytes([3, 1, 250])
# Send data
print('sending {!r}'.format(bob_packet))
sock.sendall(bob_packet)
finally:
# Close the socket
print('closing socket')
sock.close()
After executing it, we would see that the server were able to process our telemetry.