I have a serial communications protocol with several commands, all of which are specified in a text file. I have a library that provides a basic method of communicating, but I want to add parsing without having to hard-code all of the structures specifying the packet formats. From what I've found, this may be possible using XML or JSON, but I don't know where to start.
An example of a command format specified in my text file would be something like:
[255]
Name = Get Relay State
Param1 = Relay Number, uint8_t
Result1 = Relay State, uint8_t
So, the byte array a request of this command to get relay 1 would be FF 01
and its response would be something like FF 00
(indicating the relay is open).
This is a highly simplified example as there are hundreds of these commands, each with numerous inputs and outputs.
Is there some way I can extract the values, field names, and command name without explicitly declaring a struct
for every input and output in each command? I've done that with several so far but even with using code generation tools it is not flexible to changes in the protocol.