def app_in(self, msg): # Generate messages global d_msg_len, d_mac_id, d_seq_nr, d_msg if self.debug: print "******************************** \nGenerating messages ...\n******************************** " print "" print "MAC:app_in: got something:", msg data = msg if (pmt.is_pair(msg)): data = pmt.cdr(msg) #if self.debug: print "mac.py:app_in: pmt_is_pair \n" elif (pmt.is_eof_object(msg)): if self.debug: print "MAC: exiting" return elif (pmt.is_blob(msg)): data = pmt.cdr(msg) if self.debug: print "data is blob" else: if self.debug: print "MAC: unknown input" return if pmt.is_u8vector(data): "data is u8vector" data_elements = pmt.u8vector_elements(data) if self.debug: print "Data from Application Layer: ", data_elements, "\n" print "Data length :", len(data_elements), "\n" d_msg = [] if pmt.is_symbol(data): dataString = pmt.symbol_to_string(data) if self.debug: print "len(pmt.symbol_to_string(data)): ", len( dataString), "pmt.symbol_to_string(data): ", dataString generate_mac(data, len(dataString), self.debug, d_mac_id, d_seq_nr, self.no_self_loop) else: generate_mac(data, pmt.length(data), self.debug, d_mac_id, d_seq_nr, self.no_self_loop) generatedMacPayload = pmt.make_u8vector(len(d_msg), 0) for i in range(len(d_msg)): #if (pmt.is_vector(data)): #print "d_msg[",i,"]: ", d_msg[i], " ; type: ", type(d_msg[i]) # pmt.vector_set(generatedMacPayload, i, pmt.to_pmt(d_msg[i])) pmt.u8vector_set(generatedMacPayload, i, d_msg[i]) #else: pmt.u8vector_set(generatedMacPayload, i, d_msg[i]) self.message_port_pub(pmt.intern("pdu out"), pmt.cons(pmt.PMT_NIL, generatedMacPayload)) print print "**********************************" print if self.debug: print "Data Published to physical Layer: ", pmt.u8vector_elements( generatedMacPayload), "\n"
def handle_msg_fft_average(self, msg_pmt): # PMT TYPE CHECK AND UNPACKING if pmt.is_symbol(msg_pmt): msg_str = pmt.symbol_to_string(msg_pmt) if msg_str == "FFT_AVG_FINISH_ACK": self.top_block.rise_fft_avg_flag() elif pmt.is_f32vector(msg_pmt): data = pmt.f32vector_elements(msg_pmt) self.fft_data_buffer = data
def handle_msg_energy(self, msg_pmt): # PMT TYPE CHECK AND UNPACKING if pmt.is_symbol(msg_pmt): msg_str = pmt.symbol_to_string(msg_pmt) if msg_str == "E_FINISH_ACK": self.top_block.rise_energy_flag() elif pmt.is_f32vector(msg_pmt): data = pmt.f32vector_elements(msg_pmt) self.top_block.on_receive_pkt_data(data)
def parse_packet(self, packet): if not pmt.is_symbol(packet): if self.__debug: print("PMT is no symbol (string)") return packet = pmt.to_python(packet) if len(packet) != 24: if self.__debug: print("Message length invalid:", len(packet)) return if '11' in packet: if self.__debug: print("Discarding packet, because of repetitive 1's") return if packet[20] == '1' and packet[22] == '1': if self.__debug: print("Discarding packet, because on and off is both set") return info = "DIP " if packet[0] == '0': info += "1" if packet[2] == '0': info += "2" if packet[4] == '0': info += "3" if packet[6] == '0': info += "4" if packet[8] == '0': info += "5" info += " Key " if packet[10] == '0': info += "A" if packet[12] == '0': info += "B" if packet[14] == '0': info += "C" if packet[16] == '0': info += "D" if packet[18] == '0': info += "E" if packet[20] == '1': info += " off" if packet[22] == '1': info += " on" print(info)
def decode_packet(self, packet): if not pmt.is_symbol(packet): print("[WARN] PMT is no symbol (string)") return packet = str(pmt.to_python(packet)) print(packet) repititions = packet.split("-1-") if len(repititions) > 1 and len( repititions[1]) == 33 and not '?' in packet: payload = repititions[1] print(f"[INFO] Temperature: {self.getTemp(payload[9:17])}°C") else: print("[INFO] Invalid packet: " + packet)
def handle_msg(self, msg_pmt): msg = pmt.cdr(msg_pmt) if not pmt.is_u8vector(msg): print('[ERROR] Received invalid message type. Expected u8vector') return packet = bytes(pmt.u8vector_elements(msg)) meta = pmt.car(msg_pmt) transmitter = pmt.dict_ref( meta, pmt.intern('transmitter'), pmt.PMT_NIL) if pmt.is_symbol(transmitter): print('-> Packet from', pmt.symbol_to_string(transmitter), file=self.file) try: data = self.format.parse(packet) except ConstructError as e: print(f'Could not parse telemetry beacon {e}', file=self.file) return if data: print(data, file=self.file)