Monday, November 1, 2010

Communication Protocol

One of the big steps is developing a language for how all the nodes talk to each other.

There are several existing protocols like BACnet and LonWorks. These a both full featured but almost too complex for what I need right now. I looked to see if anyone had used an arduino with either of these protocols but my search turned up blank. So I decided to write my own.

Data is sent in packets. Each packet is like a letter that has a to and from address and carries a payload inside.

There are several types of packets based on what sort of data is being carried

The first three I plan on implementing are
  • TCP Packet - based on the Transmission Control Protocol, well a very simplified version but when a node receives one of these packets it sends a ack (acknowledgment) packet letting the sender know that the packet reached it destination.
  • UDP Packet - Based on the User Datagram Protocol, again a simplified version. These are packets that don't need acknowledgment. These is used when data is constantly being sent and lost packets would be outdated by the time they were resent
  • Broadcast - this is variant of UDP that doesn't have a set destination, rather it has a max number of hops that the packet will take and all nodes will take a look at it's data

Each packet has a 8 byte header and 2 byte footer. this a lot smaller than the 20 byte header of a standard TCP packet.

8 bits = 1 byte

So far my protocol looks like this
  1. 8 bits - Length of Packet (could be shorter if we don't need big packets
  2. 8 bits - Settings (could be smaller only using 2 bits right now
  3. 12 bits - From node, allows for 4096 nodes
  4. 4 bits - From ports (allows 16 ports on a node)
  5. 12 bits - To Node (or ttl Time to live, if broadcast)
  6. 4 bits - From Port
  7. 8 bits - Packet ID; So that packets can be put back in the right order
  8. 8 bits - Command; read, write, etc  (could be shorter)
  9. 56 bytes Payload
  10. 16 bits - Checksum (verifies data didn't get corrupted in transmission)

No comments:

Post a Comment