Ejemplo n.º 1
0
def make_packet(payload,
                samples_per_symbol,
                bits_per_symbol,
                access_code=default_access_code,
                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 access_code:           string of ascii 0's and 1's
    @param whitener_offset        offset into whitener string to use [0-16)
    
    Packet will have access code at the beginning, followed by length, payload
    and finally CRC-32.
    """
    if not is_1_0_string(access_code):
        raise ValueError, "access_code must be a string containing only 0's and 1's (%r)" % (
            access_code, )

    if not whitener_offset >= 0 and whitener_offset < 16:
        raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (
            whitener_offset, )

    (packed_access_code,
     padded) = conv_1_0_string_to_packed_binary_string(access_code)
    (packed_preamble,
     ignore) = conv_1_0_string_to_packed_binary_string(preamble)

    payload_with_crc = crc.gen_and_append_crc32(payload)
    #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:])

    L = len(payload_with_crc)
    MAXLEN = len(random_mask_tuple)
    if L > MAXLEN:
        raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN, )

    if whitening:
        pkt = ''.join((packed_preamble, packed_access_code,
                       make_header(L, whitener_offset),
                       whiten(payload_with_crc, whitener_offset), '\x55'))
    else:
        pkt = ''.join(
            (packed_preamble, packed_access_code,
             make_header(L, whitener_offset), (payload_with_crc), '\x55'))

    if pad_for_usrp:
        pkt = pkt + (_npadding_bytes(len(pkt), int(samples_per_symbol),
                                     bits_per_symbol) * '\x55')

    #print "make_packet: len(pkt) =", len(pkt)
    return pkt
Ejemplo n.º 2
0
def make_packet(payload, samples_per_symbol, bits_per_symbol,
                preamble=default_preamble, access_code=default_access_code,
                pad_for_usrp=True, whitener_offset=0, whitening=True):
    """
    Build a packet, given access code, payload, and whitener offset

    Args:
        payload: packet payload, len [0, 4096]
        samples_per_symbol: samples per symbol (needed for padding calculation) (int)
        bits_per_symbol: (needed for padding calculation) (int)
        preamble: string of ascii 0's and 1's
        access_code: string of ascii 0's and 1's
        pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples(512 bytes)
        whitener_offset: offset into whitener string to use [0-16)
        whitening: Whether to turn on data whitening(scrambling) (boolean)
    
    Packet will have access code at the beginning, followed by length, payload
    and finally CRC-32.
    """
    if not is_1_0_string(preamble):
        raise ValueError, "preamble must be a string containing only 0's and 1's (%r)" % (preamble,)

    if not is_1_0_string(access_code):
        raise ValueError, "access_code must be a string containing only 0's and 1's (%r)" % (access_code,)

    if not whitener_offset >=0 and whitener_offset < 16:
        raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,)

    (packed_access_code, padded) = conv_1_0_string_to_packed_binary_string(access_code)
    (packed_preamble, ignore) = conv_1_0_string_to_packed_binary_string(preamble)
    
    payload_with_crc = crc.gen_and_append_crc32(payload)
    #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:])

    L = len(payload_with_crc)
    MAXLEN = len(random_mask_tuple)
    if L > MAXLEN:
        raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)

    if whitening:
        pkt = ''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
                       whiten(payload_with_crc, whitener_offset), '\x55'))
    else:
        pkt = ''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
                       (payload_with_crc), '\x55'))

    if pad_for_usrp:
        pkt = pkt + (_npadding_bytes(len(pkt), int(samples_per_symbol), bits_per_symbol) * '\x55')

    #print "make_packet: len(pkt) =", len(pkt)
    return pkt
Ejemplo n.º 3
0
def make_packet(payload,
                samples_per_symbol,
                bits_per_symbol,
                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:])

    L = len(payload_with_crc)
    MAXLEN = len(random_mask_tuple)
    if L > MAXLEN:
        raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN, )

    pkt_hd = make_header(L, whitener_offset)
    pkt_dt = ''.join((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

    #print "make_packet: len(pkt) =", len(pkt)

    return pkt
Ejemplo n.º 4
0
def make_packet(payload, samples_per_symbol, bits_per_symbol,
                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 "pkt =", string_to_hex_list(payload)
#    print "outbound crc =", string_to_hex_list(payload_with_crc[-4:])

    L = len(payload_with_crc)
    MAXLEN = len(random_mask_tuple)
    if L > MAXLEN:
        raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)

    pkt_hd = make_header(L, whitener_offset)
    pkt_dt = ''.join((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

    #print "make_packet: len(pkt) =", len(pkt)

    return pkt
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def make_packet(payload,
                samples_per_symbol,
                bits_per_symbol,
                preamble=default_preamble,
                access_code=default_access_code,
                pad_for_usrp=True,
                whitener_offset=0,
                whitening=True,
                calc_crc=True):
    """
    Build a packet, given access code, payload, and whitener offset

    Args:
        payload: packet payload, len [0, 4096]
        samples_per_symbol: samples per symbol (needed for padding calculation) (int)
        bits_per_symbol: (needed for padding calculation) (int)
        preamble: string of ascii 0's and 1's
        access_code: string of ascii 0's and 1's
        pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples(512 bytes)
        whitener_offset: offset into whitener string to use [0-16)
        whitening: Whether to turn on data whitening(scrambling) (boolean)
        calc_crc: Whether to calculate CRC32 or not (boolean)

    Packet will have access code at the beginning, followed by length, payload
    and finally CRC-32.
    """
    if not is_1_0_string(preamble):
        raise ValueError, "preamble must be a string containing only 0's and 1's (%r)" % (
            preamble, )

    if not is_1_0_string(access_code):
        raise ValueError, "access_code must be a string containing only 0's and 1's (%r)" % (
            access_code, )

    if not whitener_offset >= 0 and whitener_offset < 16:
        raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (
            whitener_offset, )

    (packed_access_code,
     padded) = conv_1_0_string_to_packed_binary_string(access_code)
    (packed_preamble,
     ignore) = conv_1_0_string_to_packed_binary_string(preamble)

    if (calc_crc):
        payload_with_crc = crc.gen_and_append_crc32(payload)
    else:
        payload_with_crc = payload
    #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:])

    L = len(payload_with_crc)
    MAXLEN = len(random_mask_tuple)
    if L > MAXLEN:
        raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN, )

    if whitening:
        pkt = ''.join((packed_preamble, packed_access_code,
                       make_header(L, whitener_offset),
                       whiten(payload_with_crc, whitener_offset), '\x55'))
    else:
        pkt = ''.join(
            (packed_preamble, packed_access_code,
             make_header(L, whitener_offset), (payload_with_crc), '\x55'))

    if pad_for_usrp:
        pkt = pkt + (_npadding_bytes(len(pkt), int(samples_per_symbol),
                                     bits_per_symbol) * '\x55')

    #print "make_packet: len(pkt) =", len(pkt)
    return pkt
Ejemplo n.º 7
0
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