def tup_message_init_bind(bankId, bindingFlag): if isinstance(bankId, int) and isinstance(bindingFlag, int): if 0 <= bankId <= 255 and 0 <= bindingFlag <= 255: message = SmpMessage(TupMessage.CMD_BIND_EFFECT.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, bankId)).addValue( SmpValue(SmpType.SMP_TYPE_UINT8, bindingFlag)) return message
def tup_message_init_load(bankId, effectId): if isinstance(effectId, int) and isinstance(bankId, int): if effectId >= 0 and \ effectId <= 65535 and \ bankId >= 0 and \ bankId <= 255: message = SmpMessage(TupMessage.CMD_LOAD.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, bankId)).addValue( SmpValue(SmpType.SMP_TYPE_UINT16, effectId)) return message
def test_init_error(self): self.assertEqual(SmpMessage(TupMessage.ERROR.value), tup_message_init_error()) message = SmpMessage(TupMessage.ERROR.value) message.addValue( SmpValue(SmpType.SMP_TYPE_UINT32, TupMessage.CMD_GET_SENSOR_VALUE.value)) self.assertEqual( message, tup_message_init_error(TupMessage.CMD_GET_SENSOR_VALUE))
def tup_message_init_set_input(bankId, inputs): if not isinstance(bankId, int): return if bankId < 0 and bankId > 255: return message = SmpMessage(TupMessage.CMD_SET_INPUT_VALUE.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, bankId)) for value in inputs: if isinstance(value, Input): message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, value.id)).addValue( SmpValue(SmpType.SMP_TYPE_INT32, value.value)) return message
def tup_message_init_set_parameter(bankId, parameters): if not isinstance(bankId, int): return if bankId < 0 or bankId > 255: return message = SmpMessage(TupMessage.CMD_SET_PARAMETER.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, bankId)) for parameter in parameters: if isinstance(parameter, Parameter): message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, parameter.id)).addValue( SmpValue(SmpType.SMP_TYPE_UINT32, parameter.value)) return message
def test_init_set_input(self): inputs = [Input(5, 0x42), Input(10, -42)] message = SmpMessage(TupMessage.CMD_SET_INPUT_VALUE.value) message.addValue(SmpValue( SmpType.SMP_TYPE_UINT8, 0x12 # Id of effect )).addValue(SmpValue( SmpType.SMP_TYPE_UINT8, 5 # Id 1 )).addValue(SmpValue( SmpType.SMP_TYPE_INT32, 0x42 # parameter 1 )).addValue(SmpValue( SmpType.SMP_TYPE_UINT8, 10 # Id 2 )).addValue(SmpValue( SmpType.SMP_TYPE_INT32, -42 # parameter 2 )) self.assertEqual(message, tup_message_init_set_input(0x12, inputs))
def test_init_set_parameters(self): parameters = [Parameter(5, 0x42), Parameter(10, 0x25)] message = SmpMessage(TupMessage.CMD_SET_PARAMETER.value) message.addValue(SmpValue( SmpType.SMP_TYPE_UINT8, 0x25 # Id of effect )).addValue(SmpValue( SmpType.SMP_TYPE_UINT8, 5 # Id 1 )).addValue(SmpValue( SmpType.SMP_TYPE_UINT32, 0x42 # parameter 1 )).addValue(SmpValue( SmpType.SMP_TYPE_UINT8, 10 # Id 2 )).addValue(SmpValue( SmpType.SMP_TYPE_UINT32, 0x25 # parameter 2 )) self.assertEqual(message, tup_message_init_set_parameter(0x25, parameters))
def test_init_stop(self): message = SmpMessage(TupMessage.CMD_STOP.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, 0x25)) self.assertEqual(tup_message_init_stop(0x25), message)
def test_init_bind(self): message = SmpMessage(TupMessage.CMD_BIND_EFFECT.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, 0x42)).addValue( SmpValue(SmpType.SMP_TYPE_UINT8, 0x25)) self.assertEqual(tup_message_init_bind(0x42, 0x25), message)
def test_init_load(self): message = SmpMessage(TupMessage.CMD_LOAD.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, 0x42)).addValue( SmpValue(SmpType.SMP_TYPE_UINT16, 0x4242)) self.assertEqual(tup_message_init_load(0x42, 0x4242), message)
def tup_message_init_error(messageType=None): message = SmpMessage(TupMessage.ERROR.value) if messageType is not None and isinstance(messageType, TupMessage): message.addValue(SmpValue(SmpType.SMP_TYPE_UINT32, messageType.value)) return message
def tup_message_init_stop(bankId): if isinstance(bankId, int): if 0 <= bankId <= 255: message = SmpMessage(TupMessage.CMD_STOP.value) message.addValue(SmpValue(SmpType.SMP_TYPE_UINT8, bankId)) return message