Beispiel #1
0
    def to_packet(self, message: str) -> None:
        original_message = message
        if CommunicationSettings.check_sum == CheckSum.Hamming_code:
            message = Hamming.extractKey(message)

        self.key = int(message[0:CommunicationSettings.key_bits], 2)
        self.data = message[CommunicationSettings.
                            key_bits:CommunicationSettings.key_bits + 1]
        self.is_valid = CommunicationSettings.is_message_valid(message)

        if self.data == "1":
            self.retransmit = True
        elif self.data == "0":
            self.retransmit = False
        else:
            self.is_valid = False
    def to_packet(self, message: str) -> None:
        #TODO: Change this convertion to include the ability to decode hamming code
        original_message = message
        if CommunicationSettings.check_sum == CheckSum.Hamming_code:
            message = Hamming.extractKey(message)
        
        key_str = message[0:CommunicationSettings.key_bits]
        self.data = message[CommunicationSettings.key_bits: CommunicationSettings.data_bytes * 8 + CommunicationSettings.key_bits]

        self.key = int(key_str, 2)

        self.valid = CommunicationSettings.is_message_valid(original_message)
        if key_str == "".rjust(CommunicationSettings.key_bits, "1"):
            self.eot = True
        else:
            self.eot = False