+ def handle_field_common_bus(self, b):
+ '''Common handling of bus ID details. Used for RX and TX.'''
+ bus_id = b[:4]
+ bus_num = struct.unpack('>L', bytearray(bus_id))
+ bus_txt = '.'.join(['{:d}'.format(b) for b in bus_id])
+ return bus_num, bus_txt
+
+ def handle_field_rx_bus(self, b):
+ '''Process receiver bus ID field of a PJON frame.'''
+
+ # When we get here, there always should be an RX ID already.
+ bus_num, bus_txt = self.handle_field_common_bus(b[:4])
+ rx_txt = "{} {}".format(bus_txt, self.frame_rx_id[-1])
+ self.frame_rx_id = (bus_num, self.frame_rx_id[0], rx_txt)
+
+ # Provide text representation for frame field, caller emits
+ # the annotation.
+ texts = [
+ 'RX_BUS {}'.format(bus_txt),
+ bus_txt,
+ ]
+ return texts
+
+ def handle_field_tx_bus(self, b):
+ '''Process transmitter bus ID field of a PJON frame.'''
+
+ # The TX ID field is optional, as is the use of bus ID fields.
+ # In the TX info case the TX bus ID is seen before the TX ID.
+ bus_num, bus_txt = self.handle_field_common_bus(b[:4])
+ self.frame_tx_id = (bus_num, None, bus_txt)
+
+ # Provide text representation for frame field, caller emits
+ # the annotation.
+ texts = [
+ 'TX_BUS {}'.format(bus_txt),
+ bus_txt,
+ ]
+ return texts
+
+ def handle_field_tx_id(self, b):
+ '''Process transmitter ID field of a PJON frame.'''
+
+ b = b[0]
+
+ id_txt = "{:d}".format(b)
+ if self.frame_tx_id is None:
+ self.frame_tx_id = (b, id_txt)
+ else:
+ tx_txt = "{} {}".format(self.frame_tx_id[-1], id_txt)
+ self.frame_tx_id = (self.frame_tx_id[0], b, tx_txt)
+
+ # Provide text representation for frame field, caller emits
+ # the annotation.
+ texts = [
+ 'TX_ID {}'.format(id_txt),
+ id_txt,
+ ]
+ return texts
+