I have a pair of wireless Arduinos (Moteino) . One of them, battery operated, does a lot of processing:
- receives (wireless serial) sensor selection commands;
- sends (wireless serial) sensor data packets
- send and receive via RS485 on a long twisted, a 5 byte data packet from a proprietary microcontroller by half-duplex. I am using a MAX485 chip with the Arduino softserial library.
I would like to optimize the RS485 routines. The proprietary u-controller sends and receives a fixed sequence of 5 Hex bytes (0x02, 0x88, 0x31, 0x00, 0x04). All bytes remain exactly the same except for the 4th Hex byte sequence which can take on 4 different values (0x00 or 0x04 or 0x06 or 0x08) which represents different states of the device (motor controller).
What would be the fastest execution technique to read or peek at the 5 bytes to see if the 4th byte has changed? The simplest but requiring the most execution time overhead I thought would be to read in the serial data, check that the initial 3 bytes are in correct sequence (0x02, 0x88, 0x31...) and then read the 4th byte which carries the info I need. Are there any faster methods that could be used?
thanks