Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. Notice how they don't rely on delay().It would be a big help if you could describe how your program is supposed to work - i.e. a walk-through of the code.
The data you send in ACK and NAK looks like it could be figured out while you are writing the program and included as a pre-defined byte array
...R
The incoming data is 7 bytes
Byte 1 = 0xAF -- Header
Byte 2 = 0x1F -- Header
Byte 3 = DID_H -- Device ID High byte
Byte 4 = DID_L -- Device ID Low Byte
Byte 5 = 0x11 -- Direction - 0x11 is server to client - 0x22 is client to server
Byte 6 = CMD -- commands (see function execute in the code)
Byte 7 = CRC -- bytes 1 to 6 Xor'd - this is to check if incoming data is valid
the arduino pro mini receives the 7 bytes -> executes the command -> sends ACK
if the command is not in the list it sends NAK
the data is structured this way because if i wanted to add another device on the network this will allow me to
add it
Thanks