I’m working on a project where several imps are communicating with commercial A/V equipment; projectors, amplifiers, displays, etc. The imps communicate with the equipment over RS232.
Some manufacturers use protocols that have unique start frame and stop frame delimiting characters, and I’ve had no problem writing uart callbacks for these. ie. if the incoming byte is STX, clear my incoming packet array, append subsequent incoming bytes until I get an ETX byte, packet is complete, parse it…
The problem is some manufacturers use much less friendly framing, and I’m having trouble figuring out how to approach these in terms of the incoming serial receive callback.
For example, one manufacturer, for all of the serial packets the equipment transmits to the imp, uses a frame format that:
- has no unique start character across all commands
- has no unique stop character across all commands (last byte is a checksum)
- the first incoming character can appear elsewhere in the frame
- NAK messages are framed differently than ACK messages (ie. start character, length, etc.)
Here’s a concrete example. For a particular line of NEC projectors, a power on command:
Sent from Imp to projector:
02H 00H FFH F0H 00H CHECKSUM
ACK message received:
22H 00H 01H 01H 00H CHECKSUM
or NAK message received:
A2H 00H 01H 01H 02H DATA01 DATA02 CHECKSUM
where DATA01 could be 00H to 04H and DATA02 could be 00H to 0CH. Last byte is always a checksum byte.
So, how do I detect that a received frame is complete and ready to parse, and how do I detect the start of the frame so I can clear my packet buffer for the new frame?
Would appreciate any suggestions or reading material.
Cheers,
Ken C.