def test_check_crc_returns_true_when_crc_correct(): # Given message_nb = bytes([0, 0]) payload = bytes([48, 48, 48, 48]) msg_id = bytes([48, 48, 48, 48]) topic = bytes([1, 0, 0, 0]) # When msg = UDPMessage(subtopic=message_nb, payload=payload, code=msg_id, topic=topic) # Then assert msg.check_crc() is True
def add_message(self, new_message: UDPMessage) -> NoReturn: """Add a message to the topic. The position of the message in rcv_message list will depend on subtopic (start at 1). :param new_message: The message to add to the topic. """ if type(new_message) is not UDPMessage: return self.count_rcv_msg += 1 if int.from_bytes(new_message.message_nb, 'little') > self.nb_packet or int.from_bytes( new_message.message_nb, 'little') <= 0: self.rcv_error = True return self.rcv_messages[int.from_bytes(new_message.message_nb, 'little') - 1] = new_message if new_message.check_crc() is False: self.rcv_error = True