Skip to content

Instantly share code, notes, and snippets.

@basicxman
Created February 6, 2012 00:52
Show Gist options
  • Select an option

  • Save basicxman/1748699 to your computer and use it in GitHub Desktop.

Select an option

Save basicxman/1748699 to your computer and use it in GitHub Desktop.
startSequence = [0x0D, 0x0E, 0x7E]
expectedByte = 0
packetByteCount = 0
currentPacketID = 0
dataSize = 0
loop:
byte = getByte()
if byte == startSequence[expectedByte]:
expectedByte += 1
if expectedByte == startSequence.size:
packet = new Packet
packetByteCount = 0
expectedByte = 0
continue
if packetByteCount == 0:
currentPacketID = byte
else if packetByteCount == 1:
dataSize = byte
else if packetByteCount == dateSize + 3:
# At the trailer byte
if checksumIsCorrect():
processPacket()
else:
packet.push(byte)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment