Exemple #1
0
 def iterheaps(self):
     while self.is_connected:
         self.acc_num.seek(0)
         heap_cnt = '\x00' + self.acc_num.read()
         if heap_cnt == self._tx_heap.get(S.HEAP_CNT_ID,'XX')[1]:
             #logger.debug('BorphSpeadServer.iterheaps: Waiting for HEAP_CNT=%s (currently %s)' % (S.hexify(self._tx_heap.get(S.HEAP_CNT_ID,'XX')[1]), S.hexify(heap_cnt)))
             time.sleep(.001)
             continue
         tme = time.time()
         tme = int(tme*1000)
         htme = S.pack(S.mkfmt(('u',64)),[[tme]])
         self._tx_heap[TIMESTAMP_ID] = (S.DIRECTADDR,htme)
         logger.info('BorphSpeadServer.iterheaps: Sending HEAP_CNT=%s' % S.hexify(heap_cnt))
         self._tx_heap[S.HEAP_CNT_ID] = (S.IMMEDIATEADDR, heap_cnt)
         for id,bram in self.brams.iteritems():
             bram.seek(0)
             self._tx_heap[id] = (S.DIRECTADDR, bram.read())
         yield self._tx_heap
     return
#! /usr/bin/env python

import spead as S, struct
from spead._spead import *
import sys

pkt = ''.join([
    S.pack(S.HDR_FMT, ((S.MAGIC, S.VERSION, 3),)),
    S.pack(S.ITEM_FMT, ((0, S.FRAME_CNT_ID, 3),)),
    S.pack(S.ITEM_FMT, ((1, 0x3333, 0),)),
    S.pack(S.ITEM_FMT, ((0, S.PAYLOAD_LENGTH_ID, 8),)),
    struct.pack('>1024d', *[3.1415]*1024)])

cmd = sys.argv[-1]
if   cmd.startswith('SpeadPacket'):
    if cmd == 'SpeadPacket':
        while True:
            p = SpeadPacket()
            p.unpack(pkt)
    elif cmd.split('.')[1] == 'unpack':
        p = SpeadPacket()
        while True: p.unpack(pkt)
    elif cmd.split('.')[1] == 'pack':
        p = SpeadPacket()
        p.unpack(pkt)
        while True: s = p.pack()
    elif cmd.split('.')[1] == 'set_items':
        p = SpeadPacket()
        i = [(0, 5, 3)] * 20
        while True: p.items = i
    elif cmd.split('.')[1] == 'payload': pass
import unittest, spead as S, spead._spead as _S, struct, sys, os

ex_pkts = {
    '2-pkt-heap+next-pkt': [
        ''.join([
            S.pack(S.HDR_FMT , ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 5),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 3),)),
            S.pack(S.ITEM_FMT, ((S.DIRECTADDR, 0x3333, 0),)),
            S.pack(S.ITEM_FMT, ((S.DIRECTADDR, 0x3334, 16),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_OFF_ID, 0),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_LEN_ID, 8),)),
            struct.pack('>d', 3.1415)]),
        ''.join([
            S.pack(S.HDR_FMT , ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 3),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 3),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_OFF_ID, 8),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_LEN_ID, 16),)),
            struct.pack('>d', 2.7182),
            struct.pack('>d', 1.4)]),
        ''.join([
            S.pack(S.HDR_FMT , ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 3),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 4),)),
            S.pack(S.ITEM_FMT, ((S.DIRECTADDR, 0x3333, 0),)),
            S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_LEN_ID, 8),)),
            struct.pack('>d', 1.57)]),],
    'normal': ''.join([
        S.pack(S.HDR_FMT , ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 3),)),
        S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 3),)),
        S.pack(S.ITEM_FMT, ((S.DIRECTADDR, 0x3333, 0),)),
        S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_LEN_ID, 8),)),
        struct.pack('>d', 3.1415)]),
import unittest, spead._spead as _S, spead as S
import socket, time, struct

example_pkt = "".join(
    [
        S.pack(S.HDR_FMT, ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 3),)),
        S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 3),)),
        S.pack(S.ITEM_FMT, ((S.DIRECTADDR, 0x3333, 0),)),
        S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_LEN_ID, 8),)),
        struct.pack(">d", 3.1415),
    ]
)

term_pkt = "".join(
    [
        S.pack(S.HDR_FMT, ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 2),)),
        S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 0),)),
        S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.STREAM_CTRL_ID, S.STREAM_CTRL_TERM_VAL),)),
    ]
)


def loopback(data, port=8888):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 200000)
    sock.connect(("localhost", port))
    sock.send(data)
    sock.close()

import unittest, spead._spead as _S, spead as S
import socket, time, struct

example_pkt = ''.join([
    S.pack(S.HDR_FMT, ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 3), )),
    S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 3), )),
    S.pack(S.ITEM_FMT, ((S.DIRECTADDR, 0x3333, 0), )),
    S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.PAYLOAD_LEN_ID, 8), )),
    struct.pack('>d', 3.1415)
])

term_pkt = ''.join([
    S.pack(S.HDR_FMT, ((S.MAGIC, S.VERSION, S.ITEMSIZE, S.ADDRSIZE, 0, 2), )),
    S.pack(S.ITEM_FMT, ((S.IMMEDIATEADDR, S.HEAP_CNT_ID, 0), )),
    S.pack(S.ITEM_FMT,
           ((S.IMMEDIATEADDR, S.STREAM_CTRL_ID, S.STREAM_CTRL_TERM_VAL), )),
])


def loopback(data, port=8888):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 200000)
    sock.connect(('localhost', port))
    sock.send(data)
    sock.close()


PORT = 8888
packet_in_callback = None
data_in_readout = False
Exemple #6
0
#! /usr/bin/env python

import spead as S, struct
from spead._spead import *
import sys

pkt = ''.join([
    S.pack(S.HDR_FMT, ((S.MAGIC, S.VERSION, 3), )),
    S.pack(S.ITEM_FMT, ((0, S.FRAME_CNT_ID, 3), )),
    S.pack(S.ITEM_FMT, ((1, 0x3333, 0), )),
    S.pack(S.ITEM_FMT, ((0, S.PAYLOAD_LENGTH_ID, 8), )),
    struct.pack('>1024d', *[3.1415] * 1024)
])

cmd = sys.argv[-1]
if cmd.startswith('SpeadPacket'):
    if cmd == 'SpeadPacket':
        while True:
            p = SpeadPacket()
            p.unpack(pkt)
    elif cmd.split('.')[1] == 'unpack':
        p = SpeadPacket()
        while True:
            p.unpack(pkt)
    elif cmd.split('.')[1] == 'pack':
        p = SpeadPacket()
        p.unpack(pkt)
        while True:
            s = p.pack()
    elif cmd.split('.')[1] == 'set_items':
        p = SpeadPacket()
Exemple #7
0
 def test_pack(self):
     self.assertEqual(S.pack(S.DEFAULT_FMT, ((2 ** 32 + 2 ** 8,),)), "\x01\x00\x00\x01\x00")
     self.assertEqual(S.pack(S.ITEM_FMT, ((0, 4, 8),)), "\x00\x00\x04\x00\x00\x00\x00\x08")
     self.assertEqual(S.pack(S.FORMAT_FMT, (("u", 8),)), "u\x00\x00\x08")
Exemple #8
0
 def test_pack(self):
     self.assertEqual(S.pack(S.DEFAULT_FMT, ((2**32+2**8,),)), 
         '\x01\x00\x00\x01\x00')
     self.assertEqual(S.pack(S.ITEM_FMT, ((0, 4, 8),)), 
         '\x00\x00\x04\x00\x00\x00\x00\x08')
     self.assertEqual(S.pack(S.FORMAT_FMT, (('u', 8),)), 'u\x00\x00\x08')