def Read_Level1_Packet_From_BT_Stream(btSocket, mylocalBTAddress): while True: #print "Waiting for SMA level 1 packet from Bluetooth stream" start = btSocket.recv(1) # Need to add in some timeout stuff here while start != '\x7e': start = btSocket.recv(1) length1 = btSocket.recv(1) length2 = btSocket.recv(1) checksum = btSocket.recv(1) SrcAdd = bytearray(btSocket.recv(6)) DestAdd = bytearray(btSocket.recv(6)) packet = SMABluetoothPacket(length1, length2, checksum, btSocket.recv(1), btSocket.recv(1), SrcAdd, DestAdd) # Read the whole byte stream unaltered (this contains ESCAPED characters) b = bytearray(btSocket.recv(packet.TotalPayloadLength())) # Populate the SMABluetoothPacket object with the bytes packet.pushEscapedByteArray(b) # Tidy up the packet lengths packet.finish() if DestAdd == mylocalBTAddress and packet.ValidateHeaderChecksum(): break return packet
def Read_Level1_Packet_From_BT_Stream(btSocket, mylocalBTAddress=bytearray( [0x00, 0x00, 0x00, 0x00, 0x00, 0x00])): while True: #print "Waiting for SMA level 1 packet from Bluetooth stream" start = btSocket.recv(1) # Need to add in some timeout stuff here while start != '\x7e': start = btSocket.recv(1) length1 = btSocket.recv(1) length2 = btSocket.recv(1) checksum = btSocket.recv(1) SrcAdd = bytearray(btSocket.recv(6)) DestAdd = bytearray(btSocket.recv(6)) packet = SMABluetoothPacket(length1, length2, checksum, btSocket.recv(1), btSocket.recv(1), SrcAdd, DestAdd) # Read the whole byte stream unaltered (this contains ESCAPED characters) b = bytearray(btSocket.recv(packet.TotalPayloadLength())) # Populate the SMABluetoothPacket object with the bytes packet.pushEscapedByteArray(b) # Tidy up the packet lengths packet.finish() # Output some progress indicators # print "Received Level 1 BT packet cmd={1:04x}h len={0:04x}h bytes".format(packet.TotalPayloadLength(), packet.CommandCode()) #print packet.DisplayPacketDebugInfo("Received") #print ("*") if DestAdd == mylocalBTAddress and packet.ValidateHeaderChecksum(): break return packet