In the embedded application I'm working on, I often have to package data from several different objects that will be sent through the serial port. Similarly, data arrives at the serial port, which must be written to several different objects.
For compatibility reasons, organizing data in packages does not allow you to sequentially put all the data associated with a single object in a package. Therefore, I cannot easily vectorize, etc. Data from each object, and then put it all in a package.
I can achieve the proper functionality using the very large number of getters / mutators that the package class uses to create / decode transmitted / received packets. But it does not seem very elegant.
I could make the package class a friend of the classes that it retrieves / writes data from / to, but I was always told to avoid using friends, as this type violates object-oriented principles.
Ideally, the classes that process the actual application do not know anything about the package class (and should not only provide getters / mutators exclusively for it), and they will simply have new data if the package gets between updates.
I thought that maybe I could pass references or pointers to the corresponding member variables to the package class at startup, but this is also difficult because all members do not have the same size. Perhaps I can also convey size information? Would it be possible to vectorize the list of void pointers to a member and the size of pairs of elements so that the package class does not need a huge number of arguments to its constructor?
I am not sure how well I described this problem, but I can of course provide clarifications and additional information if that helps. Thanks so much for any ideas.
A shortened example of the tx package class currently:
class PacketTx { private: uint8_t buffer[MAX_PACKET_SIZE];
This example does not include a heading, checksum, etc., but it should give a general idea of ββwhat causes my headache.