Exemplo n.º 1
0
def _getPacketsAndDecoder():
    enc = UdpEncoder(udpsize=1316, physize=61)
    data = np.arange(1316, dtype=np.uint8) % 251
    phy_packets = enc.encode(data)

    dec = UdpDecoder(udpsize=1316, physize=61)

    return data, phy_packets, dec
Exemplo n.º 2
0
def test_increasesFrameCounter():
    enc = UdpEncoder(udpsize=1316, physize=61)
    for i in range(5):
        dummy = enc.encode(np.zeros(1316))  # 5 dummy packet

    phy_packets = enc.encode(np.zeros(1316))  # 6th packet
    nt.assert_array_equal(phy_packets[0][:2],
                          enc._encodeCounter(frameNumber=5, blockNumber=0))
Exemplo n.º 3
0
def test_addsFrameCounterToBeginningMidAndEnd():
    enc = UdpEncoder(udpsize=1316, physize=61)
    phy_packets = enc.encode(np.zeros(1316))

    for i, p in enumerate(phy_packets):
        C = enc._encodeCounter(frameNumber=0, blockNumber=i)
        nt.assert_array_equal(p[:2], C)
        nt.assert_array_equal(p[30:32], C)
        nt.assert_array_equal(p[58:60], C)
Exemplo n.º 4
0
def test_correctlyPutsData():
    enc = UdpEncoder(udpsize=1316, physize=61)
    data = np.arange(1316) % 256
    phy_packets = enc.encode(data)

    payloads = []
    for p in phy_packets:
        payloads.append(p[2:30])
        payloads.append(p[32:58])
    P = np.hstack(payloads)
    nt.assert_array_equal(data, P[:len(data)])
    nt.assert_array_equal(P[len(data):], np.zeros(len(P) - len(data)))
Exemplo n.º 5
0
def test_startsNewPacketOnNewFrameCounter():
    enc = UdpEncoder(udpsize=1316, physize=61)
    data = np.arange(1316, dtype=np.uint8) % 251
    phy_packets1 = enc.encode(data)
    phy_packets2 = enc.encode(data)

    dec = UdpDecoder(udpsize=1316, physize=61)

    phy_packets1_h = phy_packets1[:10]
    phy_packets2_h = phy_packets2[:10]

    for p in phy_packets1_h:
        assert dec.decode(p) is None
    assert len(dec.decode(phy_packets2_h[0])) == 1316
Exemplo n.º 6
0
def _test_packetEncodeDecode_variableSizes(udpsize, physize):
    enc = UdpEncoder(udpsize=udpsize, physize=physize)
    dec = UdpDecoder(udpsize=udpsize, physize=physize)
    txdata = []
    packets = []
    for i in range(32):
        d = np.random.randint(256, size=udpsize).astype(np.uint8)
        packets.extend(enc.encode(d))
        txdata.append(d)

    rxdata = []
    for p in packets:
        rx = dec.decode(p)
        if rx is not None:
            rxdata.append(rx)

    for t, r in zip(txdata, rxdata):
        nt.assert_array_equal(t, r)
Exemplo n.º 7
0
def txThread(stopEvent, txFifo, RX_PORT):
    rxSocket = socket(AF_INET, SOCK_DGRAM)
    rxSocket.bind(("localhost", RX_PORT))
    rxSocket.settimeout(0.1)

    enc = UdpEncoder(udpsize=1316, physize=61)
    while not stopEvent.isSet():
        try:
            data, addr = rxSocket.recvfrom(2048)
            payload = np.fromstring(data, dtype=np.uint8)
            packets = enc.encode(payload)
            #            print ("Sending %d bytes in %d packets..." % (len(payload), len(packets)))

            X = np.hstack(packets).astype(np.uint8)
            #        print(X.shape)
            p = (np.random.rand(len(X)) * 256).astype(np.uint8)
            txFifo.write(X)
        except OSError as e:
            pass
Exemplo n.º 8
0
def test_encodeCounter():
    enc = UdpEncoder(udpsize=1316, physize=61)

    nt.assert_array_equal(enc._encodeCounter(frameNumber=0, blockNumber=0),
                          np.zeros(2))

    nt.assert_array_equal(enc._encodeCounter(frameNumber=0, blockNumber=1),
                          np.array([192, 0]))

    nt.assert_array_equal(enc._encodeCounter(frameNumber=2, blockNumber=5),
                          np.array([204, 12]))

    nt.assert_array_equal(enc._encodeCounter(frameNumber=6, blockNumber=18),
                          np.array([60, 195]))

    nt.assert_array_equal(enc._encodeCounter(frameNumber=9, blockNumber=18),
                          np.array([3, 195]))

    nt.assert_array_equal(enc._encodeCounter(frameNumber=9, blockNumber=62),
                          np.array([3, 255]))
Exemplo n.º 9
0
def test_numberOfPackets():
    enc = UdpEncoder(udpsize=1316, physize=61)
    phy_packets = enc.encode(np.zeros(1316))

    # 7 overhead for counters
    assert len(phy_packets) == (1316 // (61 - 7)) + 1