本文整理汇总了Python中bitstring.BitStream.readlist方法的典型用法代码示例。如果您正苦于以下问题:Python BitStream.readlist方法的具体用法?Python BitStream.readlist怎么用?Python BitStream.readlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.BitStream
的用法示例。
在下文中一共展示了BitStream.readlist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BitStream
# 需要导入模块: from bitstring import BitStream [as 别名]
# 或者: from bitstring.BitStream import readlist [as 别名]
messageBuffer = BitStream()
i = 0
pumpSession = MedtronicSession()
for packet in cap:
# Make sure the data is coming from one of the USB endpoints we care about.
# Skip anything else
usbEndpoint = int( packet.usb.endpoint_number, 16 )
if( usbEndpoint != INCOMING_ENDPOINT and
usbEndpoint != OUTGOING_ENDPOINT ):
continue
usbBuffer = BitStream('0x%s' % ( packet.data.usb_capdata.replace( ':', '' ) ) )
usbHeader = usbBuffer.readlist( 'bytes:3, uint:8' )
# Validate the header
if( usbEndpoint == OUTGOING_ENDPOINT and usbHeader[0].encode( 'hex' ) != '000000' ):
print 'Unexpected USB Header. Expected "0x000000", got "0x%s".' % ( usbHeader[0].encode( 'hex' ) )
raise Exception
if( usbEndpoint == INCOMING_ENDPOINT and usbHeader[0] != 'ABC' ):
print 'Unexpected USB Header. Expected "0x414243", got "0x%s".' % ( usbHeader[0].encode( 'hex' ) )
raise Exception
messageBuffer.append( usbBuffer.read( usbHeader[1] * 8 ) )
# Clear the messageBuffer if we have a full message
# TODO - we need to be able to figure out if all 60 bytes are conusumed, but it's the end of the message
if( usbHeader[1] < USB_PACKET_SIZE ):
print >> sys.stderr, 'Message %s' % ( 'OUT' if usbEndpoint == OUTGOING_ENDPOINT else 'IN' )