libgs.protocols.protocolbase.ProtocolBase.set_handler

ProtocolBase.set_handler(func)[source]

Set a callback message handler for received data.

This method is called by the groundstation class as it is set up, and it is expected that the protocol calls the callback function whenever it receives any data from the spacecraft. The groundstation will then take appropriate action to log the data in the mysql database.

The callback function takes a single argument msg, which has to comply with the following requirements:

  • It shall be a string
  • It shall either be a series of hexadecimal values corresponding to the received bytes (e.g. ‘AB-CD-00-01’)
  • Or it shall be a string starting with the word ‘FAILURE’. This shall be the case if any error occurs that means a byte sequence cannot be returned. It will be stored in the database and logged for posteriority.

Note

The bytes2hex() function can be used to convert a bytearray into an appropriately formatted HEX-string.

Parameters:func – The callback function
Returns:None