<filename>PUS/SERVICES.py
#******************************************************************************
# (C) 2018, <NAME>, Austria                                            *
#                                                                             *
# The Space Python Library is free software; you can redistribute it and/or   *
# modify it under under the terms of the MIT License as published by the      *
# Massachusetts Institute of Technology.                                      *
#                                                                             *
# The Space Python Library is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of              *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT License    *
# for more details.                                                           *
#******************************************************************************
# PUS Services - Service Definition                                           *
#******************************************************************************
import CCSDS.DU, CCSDS.PACKET

#############
# constants #
#############
# -----------------------------------------------------------------------------
# PUS service 1: Telecommand Verification Service 
# TYPE / SUBTYPES
TC_ACK_TYPE = 1
TC_ACK_ACCEPT_SUCC = 1
TC_ACK_ACCEPT_FAIL = 2
TC_ACK_EXESTA_SUCC = 3
TC_ACK_EXESTA_FAIL = 4
TC_ACK_EXEPRO_SUCC = 5
TC_ACK_EXEPRO_FAIL = 6
TC_ACK_EXECUT_SUCC = 7
TC_ACK_EXECUT_FAIL = 8
# The position (offset) of the PUS service 1 attributes are global properties
# that can be changed via service1_setTCackParamsProperties()
DEFAULT_TC_ACK_APID_PARAM_BYTE_OFFSET = 10
DEFAULT_TC_ACK_SSC_PARAM_BYTE_OFFSET = 12
TC_ACK_APID_PARAM_BYTE_LENGTH = 2
TC_ACK_SSC_PARAM_BYTE_LENGTH = 2
TC_ACK_APID_PARAM_MASK = 0x1800
TC_ACK_SSC_PARAM_MASK = 0xC000

# -----------------------------------------------------------------------------
# PUS service 8: Function Management service
# TYPE / SUBTYPES
TC_FKT_TYPE = 8
TC_FKT_PERFORM_FUNCTION = 1

# -----------------------------------------------------------------------------
# PUS service 11: Onboard Scheduling service
# TYPE / SUBTYPES
TC_OBQ_TYPE = 11
TC_OBQ_UPLINK_SUBTYPES = [4, 128]   # 128 is TET specific

# -----------------------------------------------------------------------------
# PUS service 17: Test service
# TYPE / SUBTYPES
TC_TEST_TYPE = 17
TC_TEST_SUBTYPE = 1

####################
# global variables #
####################
# The position (offset) of the PUS service 1 attributes are global properties
# that can be changed via service1_setTCackParamsProperties()
s_tcAckAPIDparamByteOffset = DEFAULT_TC_ACK_APID_PARAM_BYTE_OFFSET
s_tcAckSSCparamByteOffset = DEFAULT_TC_ACK_SSC_PARAM_BYTE_OFFSET

#############
# functions #
#############
# -----------------------------------------------------------------------------
def service1_setTCackParamsProperties(tcAckAPIDparamByteOffset,
                                      tcAckSSCparamByteOffset):
  """changes the global positions of the PUS service 1 attributes"""
  global s_tcAckAPIDparamByteOffset, s_tcAckSSCparamByteOffset
  s_tcAckAPIDparamByteOffset = tcAckAPIDparamByteOffset
  s_tcAckSSCparamByteOffset = tcAckSSCparamByteOffset
# -----------------------------------------------------------------------------
def service1_getTCackMinPacketSize():
  """returns the minimal size of a PUS service 1 packet"""
  return (s_tcAckSSCparamByteOffset +
          TC_ACK_SSC_PARAM_BYTE_LENGTH +
          CCSDS.DU.CRC_BYTE_SIZE)
# -----------------------------------------------------------------------------
def service1_getTCackAPID(pusTMpacketDU):
  """retrieves the APID of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  return (pusTMpacketDU.getUnsigned(s_tcAckAPIDparamByteOffset,
                                    TC_ACK_APID_PARAM_BYTE_LENGTH) |
          TC_ACK_APID_PARAM_MASK)
# -----------------------------------------------------------------------------
def service1_setTCackAPID(pusTMpacketDU, apid):
  """sets the APID of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  pusTMpacketDU.setUnsigned(s_tcAckAPIDparamByteOffset,
                            TC_ACK_APID_PARAM_BYTE_LENGTH,
                            apid | TC_ACK_APID_PARAM_MASK)
# -----------------------------------------------------------------------------
def service1_getTCackSSC(pusTMpacketDU):
  """retrieves the SSC of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  return (pusTMpacketDU.getUnsigned(s_tcAckSSCparamByteOffset,
                                    TC_ACK_SSC_PARAM_BYTE_LENGTH) |
          TC_ACK_SSC_PARAM_MASK)
# -----------------------------------------------------------------------------
def service1_setTCackSSC(pusTMpacketDU, ssc):
  """sets the SSC of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  pusTMpacketDU.setUnsigned(s_tcAckSSCparamByteOffset,
                            TC_ACK_SSC_PARAM_BYTE_LENGTH,
                            ssc | TC_ACK_SSC_PARAM_MASK)

<filename>PUS/SERVICES.py
#******************************************************************************
# (C) 2018, <NAME>, Austria                                            *
#                                                                             *
# The Space Python Library is free software; you can redistribute it and/or   *
# modify it under under the terms of the MIT License as published by the      *
# Massachusetts Institute of Technology.                                      *
#                                                                             *
# The Space Python Library is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of              *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT License    *
# for more details.                                                           *
#******************************************************************************
# PUS Services - Service Definition                                           *
#******************************************************************************
import CCSDS.DU, CCSDS.PACKET

#############
# constants #
#############
# -----------------------------------------------------------------------------
# PUS service 1: Telecommand Verification Service 
# TYPE / SUBTYPES
TC_ACK_TYPE = 1
TC_ACK_ACCEPT_SUCC = 1
TC_ACK_ACCEPT_FAIL = 2
TC_ACK_EXESTA_SUCC = 3
TC_ACK_EXESTA_FAIL = 4
TC_ACK_EXEPRO_SUCC = 5
TC_ACK_EXEPRO_FAIL = 6
TC_ACK_EXECUT_SUCC = 7
TC_ACK_EXECUT_FAIL = 8
# The position (offset) of the PUS service 1 attributes are global properties
# that can be changed via service1_setTCackParamsProperties()
DEFAULT_TC_ACK_APID_PARAM_BYTE_OFFSET = 10
DEFAULT_TC_ACK_SSC_PARAM_BYTE_OFFSET = 12
TC_ACK_APID_PARAM_BYTE_LENGTH = 2
TC_ACK_SSC_PARAM_BYTE_LENGTH = 2
TC_ACK_APID_PARAM_MASK = 0x1800
TC_ACK_SSC_PARAM_MASK = 0xC000

# -----------------------------------------------------------------------------
# PUS service 8: Function Management service
# TYPE / SUBTYPES
TC_FKT_TYPE = 8
TC_FKT_PERFORM_FUNCTION = 1

# -----------------------------------------------------------------------------
# PUS service 11: Onboard Scheduling service
# TYPE / SUBTYPES
TC_OBQ_TYPE = 11
TC_OBQ_UPLINK_SUBTYPES = [4, 128]   # 128 is TET specific

# -----------------------------------------------------------------------------
# PUS service 17: Test service
# TYPE / SUBTYPES
TC_TEST_TYPE = 17
TC_TEST_SUBTYPE = 1

####################
# global variables #
####################
# The position (offset) of the PUS service 1 attributes are global properties
# that can be changed via service1_setTCackParamsProperties()
s_tcAckAPIDparamByteOffset = DEFAULT_TC_ACK_APID_PARAM_BYTE_OFFSET
s_tcAckSSCparamByteOffset = DEFAULT_TC_ACK_SSC_PARAM_BYTE_OFFSET

#############
# functions #
#############
# -----------------------------------------------------------------------------
def service1_setTCackParamsProperties(tcAckAPIDparamByteOffset,
                                      tcAckSSCparamByteOffset):
  """changes the global positions of the PUS service 1 attributes"""
  global s_tcAckAPIDparamByteOffset, s_tcAckSSCparamByteOffset
  s_tcAckAPIDparamByteOffset = tcAckAPIDparamByteOffset
  s_tcAckSSCparamByteOffset = tcAckSSCparamByteOffset
# -----------------------------------------------------------------------------
def service1_getTCackMinPacketSize():
  """returns the minimal size of a PUS service 1 packet"""
  return (s_tcAckSSCparamByteOffset +
          TC_ACK_SSC_PARAM_BYTE_LENGTH +
          CCSDS.DU.CRC_BYTE_SIZE)
# -----------------------------------------------------------------------------
def service1_getTCackAPID(pusTMpacketDU):
  """retrieves the APID of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  return (pusTMpacketDU.getUnsigned(s_tcAckAPIDparamByteOffset,
                                    TC_ACK_APID_PARAM_BYTE_LENGTH) |
          TC_ACK_APID_PARAM_MASK)
# -----------------------------------------------------------------------------
def service1_setTCackAPID(pusTMpacketDU, apid):
  """sets the APID of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  pusTMpacketDU.setUnsigned(s_tcAckAPIDparamByteOffset,
                            TC_ACK_APID_PARAM_BYTE_LENGTH,
                            apid | TC_ACK_APID_PARAM_MASK)
# -----------------------------------------------------------------------------
def service1_getTCackSSC(pusTMpacketDU):
  """retrieves the SSC of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  return (pusTMpacketDU.getUnsigned(s_tcAckSSCparamByteOffset,
                                    TC_ACK_SSC_PARAM_BYTE_LENGTH) |
          TC_ACK_SSC_PARAM_MASK)
# -----------------------------------------------------------------------------
def service1_setTCackSSC(pusTMpacketDU, ssc):
  """sets the SSC of the related TC packet in the datafield attribute"""
  # filters the relevant bits"""
  pusTMpacketDU.setUnsigned(s_tcAckSSCparamByteOffset,
                            TC_ACK_SSC_PARAM_BYTE_LENGTH,
                            ssc | TC_ACK_SSC_PARAM_MASK)

#****************************************************************************** # (C) 2018, <NAME>, Austria                                            * #                                                                             * # The Space Python Library is free software; you can redistribute it and/or   * # modify it under under the terms of the MIT License as published by the      * # Massachusetts Institute of Technology.                                      * #                                                                             * # The Space Python Library is distributed in the hope that it will be useful, * # but WITHOUT ANY WARRANTY; without even the implied warranty of              * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT License    * # for more details.                                                           * #****************************************************************************** # PUS Services - Service Definition                                           * #****************************************************************************** ############# # constants # ############# # ----------------------------------------------------------------------------- # PUS service 1: Telecommand Verification Service # TYPE / SUBTYPES # The position (offset) of the PUS service 1 attributes are global properties # that can be changed via service1_setTCackParamsProperties() # ----------------------------------------------------------------------------- # PUS service 8: Function Management service # TYPE / SUBTYPES # ----------------------------------------------------------------------------- # PUS service 11: Onboard Scheduling service # TYPE / SUBTYPES # 128 is TET specific # ----------------------------------------------------------------------------- # PUS service 17: Test service # TYPE / SUBTYPES #################### # global variables # #################### # The position (offset) of the PUS service 1 attributes are global properties # that can be changed via service1_setTCackParamsProperties() ############# # functions # ############# # ----------------------------------------------------------------------------- changes the global positions of the PUS service 1 attributes # ----------------------------------------------------------------------------- returns the minimal size of a PUS service 1 packet # ----------------------------------------------------------------------------- retrieves the APID of the related TC packet in the datafield attribute # filters the relevant bits""" # ----------------------------------------------------------------------------- sets the APID of the related TC packet in the datafield attribute # filters the relevant bits""" # ----------------------------------------------------------------------------- retrieves the SSC of the related TC packet in the datafield attribute # filters the relevant bits""" # ----------------------------------------------------------------------------- sets the SSC of the related TC packet in the datafield attribute # filters the relevant bits"""