- Muchas notas - Fran Acién

20240221 - OpenC3 (Cosmos) in the cloud sending the data of Open Day ESA

The script is this one:


from construct import Float32l, BitStruct, Struct, BitsInteger, Int16ub
import math

# Generate a OBC_Packet telemetry packet

CCSDS_TM_Packet_Header = BitStruct(
  "CCSDS_VERSION" / BitsInteger(3),
  "CCSDS_TYPE" / BitsInteger(1),
  "CCSDS_SECONDARY_HEADER_FLAG" / BitsInteger(1),
  "CCSDS_APID" / BitsInteger(11),
  "CCSDS_SEQUENCE_FLAG" / BitsInteger(2),
  "CCSDS_SEQUENCE_COUNT" / BitsInteger(14)
  )

TM_DATA = Struct(
  "TEMP" / Float32l,
  "PREASSURE" / Float32l,
  "ALTITUDE" / Float32l,
  "HUMIDITY" / Float32l,
  "X" / Float32l,
  "Y" / Float32l,
  "Z" / Float32l
  )

TLM = Struct(
  "CCSDS_TM_Packet_Header" / CCSDS_TM_Packet_Header,
  "CCSDS_PACKET_DATA_LENGTH" / Int16ub,
  "TM_DATA" / TM_DATA
  )

tm_data_dict = dict(
  TEMP = 1.22,
  PREASSURE = 1.23,
  ALTITUDE = 1.24,
  HUMIDITY = 1.25,
  X = 1.26,
  Y = 1.27,
  Z = 1.28
  )


tm_data = TM_DATA.build(tm_data_dict)

print(tm_data.hex())

ccsds_header_dict = dict(
  CCSDS_VERSION = 0b0,
  CCSDS_TYPE = 0b0,
  CCSDS_SECONDARY_HEADER_FLAG = 0b0,
  CCSDS_APID = 1,
  CCSDS_SEQUENCE_FLAG = 0b11,
  CCSDS_SEQUENCE_COUNT = 0b0
  )

packet= TLM.build(dict(
  CCSDS_TM_Packet_Header = ccsds_header_dict,
  CCSDS_PACKET_DATA_LENGTH =  len(tm_data) + 6 - 1,
  TM_DATA = tm_data_dict
  ))

ccsds_header = CCSDS_TM_Packet_Header.build(ccsds_header_dict)

print(' '.join('{:02x}'.format(x) for x in packet))

print("The lenght of data is {}, so is going to be {}. First part is {}, and packet {}".format(len(tm_data), len(tm_data) + 4 - 1, len(ccsds_header),len(packet)))

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(packet))
    sock.sendall(packet)

finally:
    # Close the socket
    print('closing socket')
    sock.close()

The interface is this one:

TELEMETRY PYTHON_CCSDS_EXAMPLE STATUS BIG_ENDIAN "Telemetry description"
  # Keyword      Name  BitSize Type   ID Description
  APPEND_ITEM CCSDSVER 3 UINT "CCSDS PACKET VERSION NUMBER (SEE CCSDS 133.0-B-1)"
  APPEND_ITEM CCSDSTYPE 1 UINT "CCSDS PACKET TYPE (COMMAND OR TELEMETRY)"
    STATE TLM 0
    STATE CMD 1
  APPEND_ITEM CCSDSSHF 1 UINT "CCSDS SECONDARY HEADER FLAG"
    STATE FALSE 0
    STATE TRUE 1
  APPEND_ID_ITEM CCSDSAPID 11 UINT 1 "CCSDS APPLICATION PROCESS ID"
  APPEND_ITEM CCSDSSEQFLAGS 2 UINT "CCSDS SEQUENCE FLAGS"
    STATE FIRST 0
    STATE CONT 1
    STATE LAST 2
    STATE NOGROUP 3
  APPEND_ITEM CCSDSSEQCNT 14 UINT "CCSDS PACKET SEQUENCE COUNT"
  APPEND_ITEM CCSDSLENGTH 16 UINT "CCSDS PACKET DATA LENGTH"
  APPEND_ITEM TEMP 32 FLOAT "Temperature of the SS" LITTLE_ENDIAN
  APPEND_ITEM PREASSURE 32 FLOAT "Preassure" LITTLE_ENDIAN
  APPEND_ITEM ALTITUDE 32 FLOAT "Alttitude" LITTLE_ENDIAN
  APPEND_ITEM HUMIDITY 32 FLOAT "Humidity" LITTLE_ENDIAN
  APPEND_ITEM X 32 FLOAT "X" LITTLE_ENDIAN
  APPEND_ITEM Y 32 FLOAT "Y" LITTLE_ENDIAN
  APPEND_ITEM Z 32 FLOAT "Z" LITTLE_ENDIAN



# Set VARIABLEs here to allow variation in your plugin
# See https://cosmosc2.com/docs/v5/plugins for more information
VARIABLE insisat_openday_target_name INSISAT_OPENDAY

# Modify this according to your actual target connection
# See https://cosmosc2.com/docs/v5/interfaces for more information
TARGET INSISAT_OPENDAY <%= insisat_openday_target_name %>
INTERFACE <%= insisat_openday_target_name %>_INT tcpip_server_interface.rb 8002 8002 10.0 nil LENGTH 32 16 1 1 "BIG_ENDIAN" 0 nil 100
  MAP_TARGET <%= insisat_openday_target_name %>

The output of the script should be the next one:

00 01 c0 00 00 21 f6 28 9c 3f a4 70 9d 3f 52 b8 9e 3f 00 00 a0 3f ae 47 a1 3f 5c 8f a2 3f 0a d7 a3 3f
The lenght of data is 28, so is going to be 31. First part is 4, and packet 34
sending b'\x00\x01\xc0\x00\x00!\xf6(\x9c?\xa4p\x9d?R\xb8\x9e?\x00\x00\xa0?\xaeG\xa1?\\\x8f\xa2?\n\xd7\xa3?'
closing socket

And in the software it should look like: 5ef729665e2c84f4be347dfa0176eae5.png

How to plot

The steps are:

  1. Left panel go to telemetry grapher
  2. Target-> INSISAT_OPENDAY_CLOUD, Select item -> TEMPERATURE.
  3. Add item
  4. Send telemtry with the example and you will see that is being plotted.