def test_ieee754(self): self.assertEqual(bytes([0b00111100, 0x0]), typeConverter._toIEEEFloat(1)) self.assertEqual(bytes([0b11000000, 0x0]), typeConverter._toIEEEFloat(-2)) self.assertEqual(bytes([0b11000000, 0x0]), typeConverter._toIEEEFloat(-2)) self.assertEqual( -2, typeConverter._IEEEFloatToFloat(bytes([0b11000000, 0x0])))
def test_motorStatusMessageByte(self): msg = MotorStatus(rpm=Rpm(2000), voltage=Voltage(5.5), current=Current(1), vibration=Vibration(0)) canmsg = MessageToCan(msg, 3) self.assertEqual(0x30A, canmsg.arbitration_id) bit = typeConverter._toIEEEFloat(0) self.assertEqual( bytes([0x07, 0xd0, 0x45, 0x80, 0x3c, 0x00, 0x00, 0x00]), canmsg.data)