def decode(self,decoded_msg): df = bin2dec(decoded_msg[:5]) # Sanity check DF value if df not in [0, 4, 5, 11, 16, 17, 19, 20, 21, 22, 24]: return # Detect extended messages extended = False if LENGTH * 2 == len(decoded_msg): extended = True # Verify parity if self.check_parity and 0 != get_parity(decoded_msg, extended): return if "csv" == self.output_type: ca = bin2dec(decoded_msg[5:8]) tc = bin2dec(decoded_msg[32:37]) icao = bin2dec(decoded_msg[8:32]) callsign = None speed = -1 heading = -1 position = None odd_even = -1 if df in [11, 17]: if tc >= 1 and tc <= 4: callsign = get_callsign(decoded_msg) elif tc >= 9 and tc <= 18: odd_even = decoded_msg[53] if icao not in planes: planes[icao] = {} if 1 == odd_even: planes[icao]["odd"] = get_position_data(decoded_msg) else: planes[icao]["even"] = get_position_data(decoded_msg) if "odd" in planes[icao] and "even" in planes[icao]: position = get_position(planes[icao]["even"][0], planes[icao]["odd"][0], planes[icao]["even"][1], planes[icao]["odd"][1], odd_even) elif tc == 19: speed_heading = get_speed_heading(decoded_msg) speed = speed_heading[0] heading = speed_heading[1] self.tx_msgq.insert_tail(gr.message_from_string("%X,%s,%s,%s,%s,%s,%s,%s,%s\n" % \ (icao, callsign if callsign else "", int(speed) if speed != -1 else "", int(heading) if heading != -1 else "", "%.02f,%.02f" % (position[0], position[1]) if position else "", odd_even if odd_even != -1 else "", df if df != -1 else "", ca if ca != -1 else "", tc if tc != -1 else ""))) elif "hex" == self.output_type: self.tx_msgq.insert_tail(gr.message_from_string("*%X;\n" % bin2dec(decoded_msg)))
def work(self, input_items, output_items): nread = self.nitems_read(0) in0 = input_items[0] in0_len = len(in0) # Look for preamble tag for tag in self.get_tags_in_window(0, 0, in0_len, pmt.intern("adsb_preamble")): offset_start = tag.offset - nread offset_end = tag.offset - nread + LENGTH * 2 * 2 if offset_end > in0_len: # Need to wait for buffer to fill before processing return 0 # Try extended length message decoding first bin = in0[offset_start:offset_end] decoded_msg = self.decode(bin, LENGTH * 2) if LENGTH * 2 == len(decoded_msg): self.tx_msgq.insert_tail(gr.message_from_string(decoded_msg)) continue # Failed decoding of extended message - try standard length bin = bin[0:LENGTH * 2] decoded_msg = self.decode(bin, LENGTH) if LENGTH == len(decoded_msg): self.tx_msgq.insert_tail(gr.message_from_string(decoded_msg, LENGTH)) continue return in0_len
def send_pkt2(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: #print '[TxPath] Data Requested' pkt = scsf_packet_utils.make_packet(payload, self._samples_per_symbol, 2, self._access_code, self._pad_for_usrp, 1) msg = gr.message_from_string(pkt) scsf_msg = gr.message_from_string(struct.pack('!b', 0)) self.scsf_encoder.msgq().insert_tail(scsf_msg) scsf_msg = gr.message_from_string(struct.pack('!b', 0)) self.scsf_encoder.msgq().insert_tail(scsf_msg) self._pkt_input_scsf.msgq().insert_tail(msg)
def test_301(self): src = gr.message_source(gr.sizeof_char) dst = gr.vector_sink_b() self.fg.connect(src, dst) src.msgq().insert_tail(gr.message_from_string('01234')) src.msgq().insert_tail(gr.message_from_string('5')) src.msgq().insert_tail(gr.message_from_string('')) src.msgq().insert_tail(gr.message_from_string('6789')) src.msgq().insert_tail(gr.message(1)) # send EOF self.fg.run() self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
def test_301(self): # Use itemsize, limit constructor src = blocks.message_source(gr.sizeof_char) dst = gr.vector_sink_b() tb = gr.top_block() tb.connect(src, dst) src.msgq().insert_tail(gr.message_from_string('01234')) src.msgq().insert_tail(gr.message_from_string('5')) src.msgq().insert_tail(gr.message_from_string('')) src.msgq().insert_tail(gr.message_from_string('6789')) src.msgq().insert_tail(gr.message(1)) # send EOF tb.run() self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
def __init__(self, code_index, code_size=31, DataRate_Kbps=850, Nburst=32, Ncpb=16, MeanPRF_KHz=15600, Nsync=64, deltaL=16, Nsdf=8, bypass_conv_enc=0, isRangingPacket=0, msgq_limit=2): """ Hierarchical block for the IEEE 802.15.4a UWB modulation. Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples @param bypass_conv_enc: bypass the convolutional encoding (1) or not (0)[default] @type bypass_conv_enc: int """ gr.hier_block2.__init__(self, "ieee804154a_uwb_mod_pkt", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature # setting parameters self.code_index = code_index self.code_size = code_size self.DataRate_Kbps = DataRate_Kbps self.Nburst = Nburst self.Ncpb = Ncpb self.MeanPRF_KHz = MeanPRF_KHz self.Nsync = Nsync self.deltaL = deltaL self.Nsdf = Nsdf self.bypass_conv_enc = bypass_conv_enc self.isRangingPacket = bypass_conv_enc ############ THE SYNCH PATH # synchronization header self.synch_seq = ieee802_15_4a.msg_formatter.set_synch(self.code_size, self.code_index, self.Nsync, self.deltaL, self.Nsdf) self.synch_msg = gr.message_from_string(self.synch_seq) self._synch_input = blocks.message_source(gr.sizeof_char, msgq_limit) ############ THE MAIN PATH # accepts messages from the outside world self._pkt_input = blocks.message_source(gr.sizeof_char, msgq_limit) # convolutional encoding self._convolutional_encoder = ieee802_15_4a.conv_encoder (self.bypass_conv_enc); # BPSK BPM modulator self._modulator = ieee802_15_4a.bpsk_bpm_modulator(self.code_index, self.Nburst, self.Ncpb) # connect the blocks self.connect(self._pkt_input, self._convolutional_encoder, self._modulator) # THE CONNECTION BETWEEN THE PATHS self.delay = blocks.delay (gr.sizeof_char, len(self.synch_seq)) self.sum2 = blocks.or_bb(1); self.connect (self._synch_input, (self.sum2, 0)) self.connect (self._modulator, self.delay) self.connect (self.delay, (self.sum2, 1)) self.connect (self.sum2, self)
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: info = ofdm_packet_utils.get_info(payload, self._regime, self._symbol_time) N_cbps = info["N_cbps"] N_bpsc = info["N_bpsc"] N_rate = info["rate"] N_sym = info["N_sym"] (pkt,Length) = ofdm_packet_utils.ieee802_11_make(payload,self._regime, self._symbol_time) #print ofdm_packet_utils.asciistr_to_bin(pkt) #print "Length ", Length (pkt_scrambled,Length) = ofdm_packet_utils.scrambler(pkt,Length) #print ofdm_packet_utils.asciistr_to_bin(pkt_scrambled) #print "Length after scrambling ", Length pkt_coded = ofdm_packet_utils.conv_encoder(pkt_scrambled, Length, self._regime, N_cbps, N_bpsc, N_sym, N_rate) #print ofdm_packet_utils.asciistr_to_bin(pkt_coded) pkt_interleaved = ofdm_packet_utils.interleaver(pkt_coded , self._regime, N_cbps, N_bpsc) #print ofdm_packet_utils.asciistr_to_bin(pkt_interleaved) msg = gr.message_from_string(pkt_interleaved) #if self._pkt_input.msgq().full_p(): # print "Queue full, are u sure you want to insert stuff in it?" #if self._pkt_input.msgq().empty_p(): # print "Queue empty, feel free to insert stuff in it!" self._pkt_input.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): if eof: msg = gr.message( 1) # tell self._pkt_input we're not sending any more packets else: msg = gr.message_from_string(payload) self.pkt_input.msgq().insert_tail(msg)
def no_test_001_pad(self): s = "abcd" x = self.make_waveform(s) m = self.tobytes(x) msg = gr.message_from_string(m) Ntx = 2 msg.set_arg1(Ntx) msg.set_arg2(len(x)/Ntx) pad = rf.pad() dst = gr.vector_sink_c() pad.inputQ().insert_tail(msg) pad.shutdown() # schedules shutdown self.tb.connect (pad, dst) pad.set_npost(3) self.tb.run() result_data = dst.data () block_size = pad.block_size() # prepad:(1+npre)*Ntx, postpad:(1+npost)*Ntx pre_pad = int(1+pad.npre())*Ntx*block_size post_pad = int(1+pad.npost())*Ntx*block_size pad_size = pre_pad + post_pad - len(x)%block_size self.assertComplexTuplesAlmostEqual (tuple(x), \ result_data[pre_pad:pre_pad+len(x)], len(x)+1 ) self.assertEqual(len(result_data), len(x)+pad_size ) self.assertEqual(phy.phyglobal.ctrlQ().count(), 1)
def send_packet(self, num=1): # NOTE: we keep this to allow discontinuous operation """ send a packet of options.size symbols from the datafile """ msgq = self.msg.msgq() payload = [0] * self.size payload[0] = 1 payload = array.array('B', payload) * num msgq.insert_tail(gr.message_from_string(payload.tostring()))
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: # print "original_payload =", string_to_hex_list(payload) pkt = packet_utils.make_packet(payload, self._modulator.samples_per_symbol(), self._modulator.bits_per_symbol(), self._access_code, self._pad_for_usrp, self._whitener_offset, True, self.coder) #print "pkt =", string_to_hex_list(pkt) msg = gr.message_from_string(pkt) if self._use_whitener_offset is True: self._whitener_offset = (self._whitener_offset + 1) % 16 self._pkt_input.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): print self.msgq.count() if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: msg = gr.message_from_string(payload) self.msgq.insert_tail(msg)
def get_temp_from_sensor(self): self._serial.write(chr(TEMPSENSOR_ADDR)) temp_val = map(ord, self._serial.read(2)) temp_string = str(temp_val[0]) + str(temp_val[1]) arr = numpy.array(float(temp_string) / 10.0, numpy.float32) print "Read Temperature from Sensor: %s" % (arr) return gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, 1)
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message( 1) # tell self._pkt_input we're not sending any more packets else: info = ofdm_packet_utils.get_info(payload, self._regime, self._symbol_time) N_cbps = info["N_cbps"] N_bpsc = info["N_bpsc"] N_rate = info["rate"] N_sym = info["N_sym"] (pkt, Length) = ofdm_packet_utils.ftw_make(payload, self._regime, self._symbol_time) (pkt_scrambled, Length) = ofdm_packet_utils.scrambler(pkt, Length) # print # print conv_packed_binary_string_to_1_0_string(pkt_scrambled) pkt_coded = ofdm_packet_utils.conv_encoder(pkt_scrambled, Length, self._regime, N_cbps, N_bpsc, N_sym, N_rate) # print # print conv_packed_binary_string_to_1_0_string(pkt_coded) pkt_interleaved = ofdm_packet_utils.interleaver( pkt_coded, self._regime, N_cbps, N_bpsc) # print # print conv_packed_binary_string_to_1_0_string(pkt_interleaved) msg = gr.message_from_string(pkt_interleaved) self._pkt_input.msgq().insert_tail(msg)
def send_pkt(self, mac_msg, eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: info = mac_msg["INFO"] # this dictionary vector contains tx information that will be used during the encoding process N_cbps = info["N_cbps"] # Upload the number of Coded bits per OFDM Symbol N_bpsc = info["N_bpsc"] # Upload the number of Coded bits per sub-carrier N_rate = info["rate"] # Upload the data rate code N_sym = info["N_sym"] # Upload the OFDM Symbols' number # MODIFIED FROM ORIGINAL # It is necessary to update the payload and length field on every packet transmitted (pkt,Length) = mac_msg["MPDU"], mac_msg["LENGTH"] #print"Txtime in microseconds:",info["txtime"] #print"Length of MPDU in bytes = ", info["packet_len"] #print"Number of DATA OFDM symbols = ", info["N_sym"] #print"Number of padding bits = ", info["N_pad"] # Encoding operations (pkt_scrambled,Length) = ofdm_packet_utils.scrambler(pkt,Length) pkt_coded = ofdm_packet_utils.conv_encoder(pkt_scrambled, Length, self._regime, N_cbps, N_bpsc, N_sym, N_rate) pkt_interleaved = ofdm_packet_utils.interleaver(pkt_coded , self._regime, N_cbps, N_bpsc) msg = gr.message_from_string(pkt_interleaved) self._pkt_input.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: # print "original_payload =", string_to_hex_list(payload) if self._adaptive_coding_enabled: pkt = digital_ll.ofdm_packet_util.make_packet(payload, 1, 1, self._pad_for_usrp, self._use_coding, self._variable_coding_block_length, True, self._rfcenterfreq, self._bandwidth, self._logging, whitening=True, percent_bw_occupied=self._percent_bw_occupied) else: pkt = digital_ll.ofdm_packet_util.make_packet(payload, 1, 1, self._pad_for_usrp, self._use_coding, self._coding_block_length, False, self._rfcenterfreq, self._bandwidth, self._logging, whitening=True, percent_bw_occupied=self._percent_bw_occupied) #print "pkt =", string_to_hex_list(pkt) msg = gr.message_from_string(pkt) self._pkt_input.msgq().insert_tail(msg)
def bar(mpif): time.sleep(5.0) sys.stderr.write("bar running ...\n") """ ## packet 1 MCS = 5 data = "helloworld"*10 v = hydra.mimo.txvector() v.set_length(len(data) ) v.set_power(8000.0) v.set_rate(MCS) h = v.to_string() s = h+data mpif.tx.inputQ().insert_tail(gr.message_from_string(s, hydra.mpif.TXDATA) ) ## packets 2 to L L = 100 #for k in range(L): """ k = 0 m_monitor = hydra.mimo.mac_monitor() while 1: k = (k + 1) % 1000 time.sleep(1.0) MCS = k % RATE_LIMIT # data = "helloworld"*(k%10+10) # create data to send data = "helloworld" * 10 # create data to send # create 802.11 data packet macdata = hydra.mimo.mimo_mac.ieee80211_data(data) v = hydra.mimo.txvector() v.set_length(len(macdata)) v.set_power(8000.0) v.set_rate(MCS) h = v.to_string() s = h + macdata mpif.tx.inputQ().insert_tail(gr.message_from_string(s, hydra.mpif.TXDATA))
def send_pkt(self, payload='', eof=False): if eof: msg = gr.message(1) else: pkt = ofdm_packet_utils.make_packet(payload, 1, 1, False, whiten=False) msg = gr.message_from_string(pkt) self.ofdm_mapper.msgq().insert_tail(msg)
def send_pkt(self, seqNr, addressInfo, payload='', eof=False): """ Send the payload. @param seqNr: sequence number of packet @type seqNr: byte @param addressInfo: address information for packet @type addressInfo: string @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self.pkt_input we're not sending any more packets else: FCF = make_FCF() pkt = make_ieee802_15_4_packet(FCF, seqNr, addressInfo, payload, self.pad_for_usrp) print "pkt =", packet_utils.string_to_hex_list(pkt), len(pkt) msg = gr.message_from_string(pkt) self.pkt_input.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ fqueue = open('./queuepkt', 'a') if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: #print "original_payload =", string_to_hex_list(payload) pkt = ofdm_packet_utils.make_packet(payload, 1, 1, self._pad_for_usrp, whitening=True) msg = gr.message_from_string(pkt) print>> fqueue, "%.2f \t len(pkt): %d \t pkt_in_queue_before_insert %d" % (time.clock(), len(pkt), self._pkt_input.msgq().count()) if 0: print "len(pkt)=", len(pkt) print "pkt =", ofdm_packet_utils.string_to_hex_list(pkt) self._pkt_input.msgq().insert_tail(msg)
def _handler_ser(self, samples): num = len(samples) / 2 arr = numpy.zeros(num, numpy.float32) for i in range(num): old_err = self._err_array[self._err_index] # record error ref = samples[i * 2] res = samples[i * 2 + 1] if ref == res: self._err_array[self._err_index] = 0 else: self._err_array[self._err_index] = 1 # update number of errors self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err # increment index self._err_index = (self._err_index + 1) % self._max_samples self._num_samps = min(self._num_samps + 1, self._max_samples) # write sample arr[i] = float(self._num_errs) / float(self._num_samps) # write message msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) self._msgq_source.insert_tail(msg) # change value of ser_ which is geted by external programs self.ser_ = arr[num - 1]
def send_pkt(self, payload=None, eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: print("Done sending pkts") msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: pkt = packet_utils2.make_packet(payload, self._modulator.samples_per_symbol(), self._modulator.bits_per_symbol(), self._access_code, self._pad_for_usrp, self._whitener_offset) print "pkt_utils returned ", pkt if self._use_whitener_offset is True: self._whitener_offset = (self._whitener_offset + 1) % 16 if pkt: print("SENDING PACKET\n"); msg = gr.message_from_string(pkt) print("msg set") self._pkt_input.msgq().insert_tail(msg) #else do nothing print("msg added to msgq")
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self.pkt_input we're not sending any more packets else: sync = chr(0xff) * 16 start_frame_delim = chr(0xa0) + chr(0xf3) preamble = sync + start_frame_delim signal = chr(0x0A) # 0x0A = 1 Mpbs, 0x14 = 2 Mbps service = chr(0x00) # 802.11 Original Spec length = chr(((len(payload) + 4)<< 3) & 0xff) + \ chr(((len(payload) + 4)>> 5) & 0xff) plcp_header = signal + service + length plcp_crc = bbn.crc16(plcp_header) plcp_header += chr(plcp_crc & 0xff) + chr(plcp_crc >> 8) payload_crc = bbn.crc32_le(payload) payload_crc_str = chr((payload_crc >> 0) & 0xff) + \ chr((payload_crc >> 8) & 0xff) + \ chr((payload_crc >> 16) & 0xff) + \ chr((payload_crc >> 24) & 0xff) msg = gr.message_from_string(preamble + plcp_header + payload + payload_crc_str +\ chr(0)*7); self.pkt_input.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: info = ofdm_packet_utils.get_info(payload, self._regime, self._symbol_time) N_cbps = info["N_cbps"] N_bpsc = info["N_bpsc"] N_rate = info["rate"] N_sym = info["N_sym"] (pkt,Length) = ofdm_packet_utils.ftw_make(payload,self._regime, self._symbol_time) (pkt_scrambled,Length) = ofdm_packet_utils.scrambler(pkt,Length) # print # print conv_packed_binary_string_to_1_0_string(pkt_scrambled) pkt_coded = ofdm_packet_utils.conv_encoder(pkt_scrambled, Length, self._regime, N_cbps, N_bpsc, N_sym, N_rate) # print # print conv_packed_binary_string_to_1_0_string(pkt_coded) pkt_interleaved = ofdm_packet_utils.interleaver(pkt_coded , self._regime, N_cbps, N_bpsc) # print # print conv_packed_binary_string_to_1_0_string(pkt_interleaved) msg = gr.message_from_string(pkt_interleaved) self._pkt_input.msgq().insert_tail(msg)
def get_temperature(self): self._SBHS.write(chr(TEMPERATURE)) temp_val = map(ord, self._SBHS.read(2)) #reads in hexadecimal temp_string = str(temp_val[0]) + str(temp_val[1]) arr = numpy.array(float(temp_string)/10.0, numpy.float32) print "Temperature Read: %s" %(arr) return gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, 1)
def send_pkt(self, payload='',eof=False): if eof: msg = gr.message(1) else: msg = gr.message_from_string(payload) # send message twice for i in range(2): self._pkt_source.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): if eof: msg = gr.message(1) else: msg = gr.message_from_string(payload) # send message twice for i in range(2): self._pkt_source.msgq().insert_tail(msg)
def rx_callback(ok, payload): global n_rcvd, n_right n_rcvd += 1 if ok: n_right += 1 tb.audio_tx.msgq().insert_tail(gr.message_from_string(payload)) print "ok = %r n_rcvd = %4d n_right = %4d" % (ok, n_rcvd, n_right)
def rx_callback(ok, payload): global n_rcvd, n_right n_rcvd += 1 if ok: n_right += 1 tb.audio_tx.msgq().insert_tail(gr.message_from_string(payload)) print "ok = %r n_rcvd = %4d n_right = %4d" % ( ok, n_rcvd, n_right)
def push(self, item): """! Push an item into the back of the queue. @param item the item """ if self._vlen == 1: item = [item] arr = numpy.array(item, self._numpy) msg = gr.message_from_string(arr.tostring(), 0, self._item_size, self._vlen) self._msgq.insert_tail(msg)
def bar(tx): time.sleep(1) print "bar running" pkt = "helloworld" print pkt msg = gr.message_from_string(pkt) print msg msg = tx.msgq().insert_tail(msg) print "insert"
def run(self): """ Infinite polling loop. """ while True: time.sleep(1.0/self._probe_rate) arr = numpy.array(self._probe_callback(), numpy.float32) msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, 1) self._msgq.insert_tail(msg)
def send_samples(self, payload='', time=None): msg = gr.message_from_string(payload) if time is not None: secs = long(time) frac_secs = time - long(time) msg.set_timestamp(secs, frac_secs) else: #print "[TRANSMIT_PATH] WARNING: no timestamp!" pass self.tx.msgq().insert_tail(msg)
def generate_time_diff(self): pc_time = time.time() usrp_time = self.u.get_time_now().get_real_secs() tdiff = pc_time - usrp_time print tdiff time_diff = struct.pack('!d', tdiff) msg = gr.message_from_string(time_diff) return msg
def send_pkt(payload='', eof=False, timeValid=False, timestamp=0): if eof: msg = gr.message(1) else: msg = gr.message_from_string(payload) if timeValid: secs = long(timestamp) frac_secs = timestamp - long(timestamp) msg.set_timestamp(secs, frac_secs) return tb.txpath.msgq().insert_tail(msg)
def send_pkt(payload='', timestamp=None, eof=False): if eof: msg = gr.message(1) else: msg = gr.message_from_string(payload) if timestamp is not None: secs = long(timestamp) frac_secs = timestamp - long(timestamp) msg.set_timestamp(secs, frac_secs) return tb.txpath.msgq().insert_tail(msg)
def send_pkt(self, payload): """ Wrap the payload in a packet and push onto the message queue. @param payload string, data to send """ packet = packet_utils.make_packet(payload, self._samples_per_symbol, self._bits_per_symbol, self._access_code, self._pad_for_usrp) msg = gr.message_from_string(packet) self._msgq_out.insert_tail(msg)
def fill_queue(self, txDataList): message_str = "" for bit in txDataList: if bit == 1: message_str += b'\x01' elif bit == 0: message_str += b'\x00' else: print "Error passing data to flowgraph. Exiting..." exit(1) self.source_queue.handle(gr.message_from_string(message_str)) message_str = ""
def send_pkt(self, payload): """ Wrap the payload in a packet and push onto the message queue. Args: payload: string, data to send """ packet = cc1111_packet_utils.make_packet( payload, self._samples_per_symbol, self._bits_per_symbol, self._preamble, self._access_code, self._pad_for_usrp, self._do_whitening, self._add_crc) msg = gr.message_from_string(packet) self._msgq_out.insert_tail(msg)
def _handler_ber(self, samples): num = len(samples)/2 arr = numpy.zeros(num, numpy.float32) for i in range(num): old_err = self._err_array[self._err_index] #record error self._err_array[self._err_index] = _1s_counts[samples[i*2] ^ samples[i*2 + 1]] self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err #increment index self._err_index = (self._err_index + 1)%self._max_samples self._num_samps = min(self._num_samps + 1, self._max_samples) #write sample arr[i] = float(self._num_errs)/float(self._num_samps*self._bits_per_symbol) #write message msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) self._msgq_source.insert_tail(msg)
def test_1(self): data = ('hello', 'you', 'there') tx_msgq = gr.msg_queue() rx_msgq = gr.msg_queue() for d in data: tx_msgq.insert_tail(gr.message_from_string(d)) tb = gr.top_block() src = gr.message_source(gr.sizeof_char, tx_msgq, "packet_length") snk = gr.message_sink(gr.sizeof_char, rx_msgq, False, "packet_length") tb.connect(src, snk) tb.start() time.sleep(1) tb.stop() for d in data: msg = rx_msgq.delete_head() contents = msg.to_string() self.assertEqual(d, contents)
def send_pkt(self, payload='', eof=False): """ Send the payload. Args: payload: data to send (string) """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: # print "original_payload =", string_to_hex_list(payload) pkt = ofdm_packet_utils.make_packet(payload, 1, 1, self._pad_for_usrp, whitening=True) #print "pkt =", string_to_hex_list(pkt) msg = gr.message_from_string(pkt) self._pkt_input.msgq().insert_tail(msg)
def send_pkt(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message( 1) # tell self._pkt_input we're not sending any more packets else: # print "original_payload =", string_to_hex_list(payload) if self._adaptive_coding_enabled: pkt = digital_ll.ofdm_packet_util.make_packet( payload, 1, 1, self._pad_for_usrp, self._use_coding, self._variable_coding_block_length, True, self._rfcenterfreq, self._bandwidth, self._logging, whitening=True, percent_bw_occupied=self._percent_bw_occupied) else: pkt = digital_ll.ofdm_packet_util.make_packet( payload, 1, 1, self._pad_for_usrp, self._use_coding, self._coding_block_length, False, self._rfcenterfreq, self._bandwidth, self._logging, whitening=True, percent_bw_occupied=self._percent_bw_occupied) #print "pkt =", string_to_hex_list(pkt) msg = gr.message_from_string(pkt) self._pkt_input.msgq().insert_tail(msg)
def get_mlat_positions(self): msg = None try: msg = self._sock.recv(1024) except socket.error: pass if msg: for line in msg.splitlines(True): if line.endswith("\n"): if self._remnant: line = self._remnant + line self._remnant = None self._queue.insert_tail(gr.message_from_string(line)) else: if self._remnant is not None: raise Exception("Malformed data: " + line) else: self._remnant = line
def enqueue_signal(self, id, signal): if not self.src_id_valid(id): raise RuntimeError, "Src ID invalid" if not self.src_ready(id): return False if self.is_const[id]: raise RuntimeError, "Can't enqueue signal in constant source" try: signal = numpy.array(signal, dtype=numpy.float32) msg = gr.message_from_string(signal.tostring()) self.sources[id].msgq().insert_tail(msg) self.lengths[id] = len(signal) return True except Exception, ex: print repr(ex) raise RuntimeError, "FAILED to enqueue signal?"
def send_pkt(self, payload='', eof=False, time_flag=False, time=0): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: # print "original_payload =", string_to_hex_list(payload) pkt = ofdm_packet_utils.make_packet(payload, 1, 1, self._pad_for_usrp, whitening=True) #print "pkt =", string_to_hex_list(pkt) msg = gr.message_from_string(pkt) if time_flag: msg.set_timestamp(long(time), time-long(time)) self._pkt_input.msgq().insert_tail(msg)
def send_tinyos_pkt_add_crc(self, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ print "GR: ieee802_15_4_pkt: ########## SDR sending a TinyOS packet ###########" if eof: msg = gr.message( 1) # tell self.pkt_input we're not sending any more packets else: pkt = make_tinyos_packet_add_crc(payload, self.pad_for_usrp) print "GR: ieee802_15_4_pkt: pkt =", packet_utils.string_to_hex_list( pkt), len(pkt) msg = gr.message_from_string(pkt) self.pkt_input.msgq().insert_tail(msg) print "GR: ieee802_15_4_pkt: ########## SDR inserted packet in message Queue ###########"
def _handler_ser(self, samples): num = len(samples)/2 arr = numpy.zeros(num, numpy.float32) for i in range(num): old_err = self._err_array[self._err_index] #record error ref = samples[i*2] res = samples[i*2 + 1] if ref == res: self._err_array[self._err_index] = 0 else: self._err_array[self._err_index] = 1 #update number of errors self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err #increment index self._err_index = (self._err_index + 1)%self._max_samples self._num_samps = min(self._num_samps + 1, self._max_samples) #write sample arr[i] = float(self._num_errs)/float(self._num_samps) #write message msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) self._msgq_source.insert_tail(msg)
def send_pkt(self, payload='', eof=False): """ Send the payload. Args: payload: data to send (string) """ if eof: msg = gr.message( 1) # tell self._pkt_input we're not sending any more packets else: # print "original_payload =", string_to_hex_list(payload) pkt = packet_utils.make_packet( payload, self._modulator.samples_per_symbol(), self._modulator.bits_per_symbol(), self._preamble, self._access_code, self._pad_for_usrp, self._whitener_offset) #print "pkt =", string_to_hex_list(pkt) msg = gr.message_from_string(pkt) if self._use_whitener_offset is True: self._whitener_offset = (self._whitener_offset + 1) % 16 self._pkt_input.msgq().insert_tail(msg)
def send_pkt(self, seqNr, addressInfo, payload='', eof=False): """ Send the payload. @param seqNr: sequence number of packet @type seqNr: byte @param addressInfo: address information for packet @type addressInfo: string @param payload: data to send @type payload: string """ if eof: msg = gr.message( 1) # tell self.pkt_input we're not sending any more packets else: FCF = make_FCF() pkt = make_ieee802_15_4_packet(FCF, seqNr, addressInfo, payload, self.pad_for_usrp) print "pkt =", packet_utils.string_to_hex_list(pkt), len(pkt) msg = gr.message_from_string(pkt) self.pkt_input.msgq().insert_tail(msg)
def fill_queue_vector(self, bb_list, hop_select_list): # baseband and select values must be the same if len(bb_list) != len(hop_select_list): print "Fatal Error: hop select list must be same length as baseband list" exit(1) # create a vector entry of the bb bits and corresponding enables #vector_sample = numpy.array([b'\x00', 0, 0, 0]) vector_sample = [b'\x00', b'\x00', b'\x00', b'\x00'] # now we make a u8 vector out of this #vector_pmt = pmt.make_u8vector(4, b'\x00') for i in xrange(len(bb_list)): # assign first vector element to bb value vector_sample[0] = b'\x01' if bb_list[i] == 1 else b'\x00' if hop_select_list[i] == 0: vector_sample[1] = b'\x01' vector_sample[2] = b'\x00' vector_sample[3] = b'\x00' elif hop_select_list[i] == 1: vector_sample[1] = b'\x00' vector_sample[2] = b'\x01' vector_sample[3] = b'\x00' elif hop_select_list[i] == 2: vector_sample[1] = b'\x00' vector_sample[2] = b'\x00' vector_sample[3] = b'\x01' else: print "Fatal Error: hop select out of range; must be 0-2" exit(1) #vector_pmt = pmt.to_pmt(vector_sample) vector_str = "" for uchar in vector_sample: vector_str += uchar message = gr.message_from_string(vector_str) self.source_queue_v.insert_tail(message)
def send_pkt(self, am_group, module_src, module_dst, dst_addr, src_addr, msg_type, payload='', eof=False): """ Send the payload. @param payload: data to send @type payload: string """ if eof: msg = gr.message(1) # tell self.pkt_input we're not sending any more packets else: #print "original_payload =", string_to_hex_list(payload) pkt = make_sos_packet(am_group, module_src, module_dst, dst_addr, src_addr, msg_type, payload, self.cc1k_mod.spb, self._access_code, self.pad_for_usrp) #print "pkt =", str(map(hex, map(ord, pkt))) msg = gr.message_from_string(pkt) self.pkt_input.msgq().insert_tail(msg)
def recv_pkt(self, ok, payload): msg = gr.message_from_string(payload, 0, self._item_size_out, len(payload) / self._item_size_out) if ok: self._msgq_out.insert_tail(msg)