badger/lbus_access.py
def _exchange(self, addrs, values=None, drop_reply=False, burst=False):
        """Exchange a single low level message
        """

        if not burst:
            msg = numpy.zeros(2+2*len(addrs), dtype=be32)
        else:
            msg = numpy.zeros(2+2+len(addrs), dtype=be32)

        msg[0] = random.randint(0, 0xffffffff)
        msg[1] = msg[0] ^ 0xffffffff

        if not burst:
            for i, (A, V) in enumerate(zip(addrs, values), 1):
                A &= 0x00ffffff
                if V is None:
                    A |= 0x10000000
                msg[2*i] = A
                msg[2*i+1] = V or 0
        else:
            RC = (len(addrs) & 0x00ffffff) | 0x20000000
            A = addrs[0]
            A &= 0x00ffffff
            if values[0] is None:
                A |= 0x10000000
            msg[2] = RC
            msg[3] = A
            for i, V in enumerate(values, 4):
                msg[i] = V or 0

        tosend = msg.tostring()
        if False:
            mm = ".".join(["%8.8x" % x for x in msg])
            print("%s Send (%d) %s" % (self.dest, len(tosend), mm))
        self.sock.sendto(tosend, self.dest)

        if drop_reply:
            return None

        while True:
            reply, src = self.sock.recvfrom(15000)
            # print("%s Recv (%d) %s", src, len(reply), binascii.hexlify(reply))

            byte_align = 8 if not burst else 4
            if len(reply) % byte_align:
                reply = reply[:-(len(reply) % byte_align)]

            if len(tosend) != len(reply):
                print("Reply truncated %d %d" % (len(tosend), len(reply)))
                continue

            reply = numpy.frombuffer(reply, be32)
            if (msg[:2] != reply[:2]).any():
                print('Ignore reply w/o matching nonce %s %s' % (msg[:2], reply[:2]))
                continue
            elif not burst and (msg[2::2] != reply[2::2]).any():
                print('reply addresses are out of order')
                continue
            elif burst and (msg[2:3] != reply[2:3]).any():
                print('Non-matching start address')
                continue
            break

        ret = reply[3::2] if not burst else reply[4::1]
        return ret
Exchange a single low level message
        
Exchange a single low level message
Exchange a single low level message
def _exchange(self, addrs, values=None, drop_reply=False, burst=False):
        if not burst:
            msg = numpy.zeros(2+2*len(addrs), dtype=be32)
        else:
            msg = numpy.zeros(2+2+len(addrs), dtype=be32)
        msg[0] = random.randint(0, 0xffffffff)
        msg[1] = msg[0] ^ 0xffffffff
        if not burst:
            for i, (A, V) in enumerate(zip(addrs, values), 1):
                A &= 0x00ffffff
                if V is None:
                    A |= 0x10000000
                msg[2*i] = A
                msg[2*i+1] = V or 0
        else:
            RC = (len(addrs) & 0x00ffffff) | 0x20000000
            A = addrs[0]
            A &= 0x00ffffff
            if values[0] is None:
                A |= 0x10000000
            msg[2] = RC
            msg[3] = A
            for i, V in enumerate(values, 4):
                msg[i] = V or 0
        tosend = msg.tostring()
        if False:
            mm = ".".join(["%8.8x" % x for x in msg])
            print("%s Send (%d) %s" % (self.dest, len(tosend), mm))
        self.sock.sendto(tosend, self.dest)
        if drop_reply:
            return None
        while True:
            reply, src = self.sock.recvfrom(15000)
            byte_align = 8 if not burst else 4
            if len(reply) % byte_align:
                reply = reply[:-(len(reply) % byte_align)]
            if len(tosend) != len(reply):
                print("Reply truncated %d %d" % (len(tosend), len(reply)))
                continue
            reply = numpy.frombuffer(reply, be32)
            if (msg[:2] != reply[:2]).any():
                print('Ignore reply w/o matching nonce %s %s' % (msg[:2], reply[:2]))
                continue
            elif not burst and (msg[2::2] != reply[2::2]).any():
                print('reply addresses are out of order')
                continue
            elif burst and (msg[2:3] != reply[2:3]).any():
                print('Non-matching start address')
                continue
            break
        ret = reply[3::2] if not burst else reply[4::1]
        return ret
def _exchange ( self , addrs , values = None , drop_reply = False , burst = False ) : if not burst : msg = numpy . zeros ( 2 + 2 * len ( addrs ) , dtype = be32 ) else : msg = numpy . zeros ( 2 + 2 + len ( addrs ) , dtype = be32 ) msg [ 0 ] = random . randint ( 0 , 0xffffffff ) msg [ 1 ] = msg [ 0 ] ^ 0xffffffff if not burst : for i , ( A , V ) in enumerate ( zip ( addrs , values ) , 1 ) : A &= 0x00ffffff if V is None : A |= 0x10000000 msg [ 2 * i ] = A msg [ 2 * i + 1 ] = V or 0 else : RC = ( len ( addrs ) & 0x00ffffff ) | 0x20000000 A = addrs [ 0 ] A &= 0x00ffffff if values [ 0 ] is None : A |= 0x10000000 msg [ 2 ] = RC msg [ 3 ] = A for i , V in enumerate ( values , 4 ) : msg [ i ] = V or 0 tosend = msg . tostring ( ) if False : mm = "." . join ( [ "%8.8x" % x for x in msg ] ) print ( "%s Send (%d) %s" % ( self . dest , len ( tosend ) , mm ) ) self . sock . sendto ( tosend , self . dest ) if drop_reply : return None while True : reply , src = self . sock . recvfrom ( 15000 ) byte_align = 8 if not burst else 4 if len ( reply ) % byte_align : reply = reply [ : - ( len ( reply ) % byte_align ) ] if len ( tosend ) != len ( reply ) : print ( "Reply truncated %d %d" % ( len ( tosend ) , len ( reply ) ) ) continue reply = numpy . frombuffer ( reply , be32 ) if ( msg [ : 2 ] != reply [ : 2 ] ) . any ( ) : print ( 'Ignore reply w/o matching nonce %s %s' % ( msg [ : 2 ] , reply [ : 2 ] ) ) continue elif not burst and ( msg [ 2 : : 2 ] != reply [ 2 : : 2 ] ) . any ( ) : print ( 'reply addresses are out of order' ) continue elif burst and ( msg [ 2 : 3 ] != reply [ 2 : 3 ] ) . any ( ) : print ( 'Non-matching start address' ) continue break ret = reply [ 3 : : 2 ] if not burst else reply [ 4 : : 1 ] return ret
Exchange a single low level message
Exchange a single low level message
"""Exchange a single low level message
        """ # print("%s Recv (%d) %s", src, len(reply), binascii.hexlify(reply))
self
addrs
values
drop_reply
burst