def make_packet(payload, samples_per_symbol, bps, fec_n, fec_k, pad_for_usrp=True, whitener_offset=0, whitening=True): """ Build a packet, given access code, payload, and whitener offset @param payload: packet payload, len [0, 4096] @param samples_per_symbol: samples per symbol (needed for padding calculation) @type samples_per_symbol: int @param bits_per_symbol: (needed for padding calculation) @type bits_per_symbol: int @param whitener_offset offset into whitener string to use [0-16) @param whitening: Turn whitener on or off @type whitening: bool Packet will have access code at the beginning, followed by length, payload and finally CRC-32. """ if not whitener_offset >=0 and whitener_offset < 16: raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,) payload_with_crc = crc.gen_and_append_crc32(payload) #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:]) if (fec_n > 0 and fec_k > 0): enc_payload_with_crc = crc.tx_wrapper(payload_with_crc, fec_n, fec_k, bps) else: enc_payload_with_crc = payload_with_crc L = len(enc_payload_with_crc) MAXLEN = len(random_mask_tuple) if L > MAXLEN: raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,) ### apurv++: replace above code by this one ### pkt_dt = ''.join((enc_payload_with_crc, '\x55')) if 0: print "original: " printlst = list() for x in enc_payload_with_crc: t = hex(ord(x)).replace('0x', '') if(len(t) == 1): t = '0' + t printlst.append(t) printable = ''.join(printlst) print printable packet_length = len(pkt_dt) if(whitening): pkt = whiten(pkt_dt, whitener_offset) else: pkt = pkt_dt ### apurv++: end replace ### if 0: print "whitened: " printlst = list() for x in pkt: t = hex(ord(x)).replace('0x', '') if(len(t) == 1): t = '0' + t printlst.append(t) printable = ''.join(printlst) print printable sys.stdout.flush() #print "make_packet: len(pkt) =", len(pkt) return pkt
def make_packet(payload, samples_per_symbol, bps, fec_n, fec_k, pad_for_usrp=True, whitener_offset=0, whitening=True): """ Build a packet, given access code, payload, and whitener offset @param payload: packet payload, len [0, 4096] @param samples_per_symbol: samples per symbol (needed for padding calculation) @type samples_per_symbol: int @param bits_per_symbol: (needed for padding calculation) @type bits_per_symbol: int @param whitener_offset offset into whitener string to use [0-16) @param whitening: Turn whitener on or off @type whitening: bool Packet will have access code at the beginning, followed by length, payload and finally CRC-32. """ if not whitener_offset >= 0 and whitener_offset < 16: raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % ( whitener_offset, ) # generate 1 OFDM symbol of training payload # training_symbol = '' data_carriers = 64 if 1: training_boundary = 2 * (data_carriers * bps) / 8 training_symbol = payload[0:training_boundary] payload = payload[training_boundary:] payload_with_crc = crc.gen_and_append_crc32(payload) #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:]) if (fec_n > 0 and fec_k > 0): enc_payload_with_crc = crc.tx_wrapper(payload_with_crc, fec_n, fec_k, bps) else: enc_payload_with_crc = payload_with_crc enc_payload_with_crc = training_symbol + enc_payload_with_crc L = len(enc_payload_with_crc) MAXLEN = len(random_mask_tuple) if L > MAXLEN: raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN, ) """ apurv--: take out the header, we have our own multihop hdr now (ref rainier sink) pkt_hd = make_header(L, whitener_offset) pkt_dt = ''.join((enc_payload_with_crc, '\x55')) packet_length = len(pkt_hd) + len(pkt_dt) if pad_for_usrp: usrp_packing = _npadding_bytes(packet_length, samples_per_symbol, bits_per_symbol) * '\x55' pkt_dt = pkt_dt + usrp_packing if(whitening): pkt = pkt_hd + whiten(pkt_dt, whitener_offset) else: pkt = pkt_hd + pkt_dt """ ### apurv++: replace above code by this one ### #pkt_dt = ''.join((enc_payload_with_crc, '\x55')) pkt_dt = enc_payload_with_crc if 0: print "original: " printlst = list() for x in enc_payload_with_crc: t = hex(ord(x)).replace('0x', '') if (len(t) == 1): t = '0' + t printlst.append(t) printable = ''.join(printlst) print printable packet_length = len(pkt_dt) if (whitening): pkt = whiten(pkt_dt, whitener_offset) else: pkt = pkt_dt ### apurv++: end replace ### if 0: print "whitened: " printlst = list() for x in pkt: t = hex(ord(x)).replace('0x', '') if (len(t) == 1): t = '0' + t printlst.append(t) printable = ''.join(printlst) print printable sys.stdout.flush() #print "make_packet: len(pkt) =", len(pkt) return pkt
def make_packet(payload, samples_per_symbol, bps, fec_n, fec_k, pad_for_usrp=True, whitener_offset=0, whitening=True): """ Build a packet, given access code, payload, and whitener offset @param payload: packet payload, len [0, 4096] @param samples_per_symbol: samples per symbol (needed for padding calculation) @type samples_per_symbol: int @param bits_per_symbol: (needed for padding calculation) @type bits_per_symbol: int @param whitener_offset offset into whitener string to use [0-16) @param whitening: Turn whitener on or off @type whitening: bool Packet will have access code at the beginning, followed by length, payload and finally CRC-32. """ if not whitener_offset >=0 and whitener_offset < 16: raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,) # generate 1 OFDM symbol of training payload # training_symbol = '' data_carriers = 64 if 1: training_boundary = 2*(data_carriers*bps)/8 training_symbol = payload[0:training_boundary] payload = payload[training_boundary:] payload_with_crc = crc.gen_and_append_crc32(payload) #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:]) if (fec_n > 0 and fec_k > 0): enc_payload_with_crc = crc.tx_wrapper(payload_with_crc, fec_n, fec_k, bps) else: enc_payload_with_crc = payload_with_crc enc_payload_with_crc = training_symbol + enc_payload_with_crc L = len(enc_payload_with_crc) MAXLEN = len(random_mask_tuple) if L > MAXLEN: raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,) """ apurv--: take out the header, we have our own multihop hdr now (ref rainier sink) pkt_hd = make_header(L, whitener_offset) pkt_dt = ''.join((enc_payload_with_crc, '\x55')) packet_length = len(pkt_hd) + len(pkt_dt) if pad_for_usrp: usrp_packing = _npadding_bytes(packet_length, samples_per_symbol, bits_per_symbol) * '\x55' pkt_dt = pkt_dt + usrp_packing if(whitening): pkt = pkt_hd + whiten(pkt_dt, whitener_offset) else: pkt = pkt_hd + pkt_dt """ ### apurv++: replace above code by this one ### #pkt_dt = ''.join((enc_payload_with_crc, '\x55')) pkt_dt = enc_payload_with_crc if 0: print "original: " printlst = list() for x in enc_payload_with_crc: t = hex(ord(x)).replace('0x', '') if(len(t) == 1): t = '0' + t printlst.append(t) printable = ''.join(printlst) print printable packet_length = len(pkt_dt) if(whitening): pkt = whiten(pkt_dt, whitener_offset) else: pkt = pkt_dt ### apurv++: end replace ### if 0: print "whitened: " printlst = list() for x in pkt: t = hex(ord(x)).replace('0x', '') if(len(t) == 1): t = '0' + t printlst.append(t) printable = ''.join(printlst) print printable sys.stdout.flush() #print "make_packet: len(pkt) =", len(pkt) return pkt