Interfaces were changed dramatically in COSMOS 4.0.0
One of our Ball Aerospace engineers asked how they could add a checksum to an existing COSMOS interface when talking to their target. COSMOS does not support this directly so it requires creating a custom interface. While this might sound daunting, the COSMOS interfaces were designed just for this type of extension and provide hooks for customization.
In this example we will assume the original interface is the COSMOS Serial Interface. In your target’s lib folder create a new interface called checksum_serial_interface.rb:
What we’re doing is overriding pre_write_packet in StreamInterface to allow us to modify the data before it is written to the packet and sent over the interface. We also override post_read_data to operate on data received before it is sent back to the COSMOS server and thus the tools. Note there is also a post_read_packet(packet) method which is called after post_read_data is called and after the COSMOS Packet has been created. All Interfaces inheriting from StreamInterface includes these callback methods, including SerialInterface, TcpipServerInterface, and TcpipClientInterface. Note that UdpInterface inherits directly from Interface and thus does NOT include these callbacks.
Then in your cmd_tlm_server.txt file for your target you use your new interface:
# interface name file name write read baud parity stop timeouts stream INTERFACE UART_INTERFACE checksum_serial_interface.rb COM1 COM1 115200 NONE 1 nil nil BURST
I added a comment line above the definition which describes the settings. For more information see the Serial Interface documentation.
This same technique can obviously be used to extend the the other TCPIP interfaces and can be used with all the various Streams COSMOS defines.
If you have a question which would benefit the community or find a possible bug please use our Github Issues. If you would like more information about a COSMOS training or support contract please contact us at firstname.lastname@example.org.