Robbie Hatley wrote:
> Greetings, group. I have a situation at work in which our software
(running
> on a PC) needs to talk to two different versions of our firmware
(running on
> circuit boards in boxes hundreds of feet away, communicating via RS232).
>
> The two firmware versions (1400 and 1600) are very similar, with 1600
having
> a few more members in each of several key structs used for communicating
and
> storing data. (Alas, the added members were scattered through the
structs
> by our firmware designer, instead of being added only at the end.
Sigh.)
>
> I use the 1600 structs in the PC software to hold data from both
firmware
> types, but for communications, the correct struct MUST be used,
> because the firmware is expecting a data packet of a certain length,
with
> the data members in a certain order.
In the spirit of more choices is better, if the common items are in the
same order and of the same size, consider defining the lookup table:
setup_t *psetup; /* dummy pointer */
#define NEWITEM(name) {offsetof(setup_t,name), sizeof(psetup->name) }
const struct {
size_t offset; /* offset of item only in setup_t */
size_t size; /* size of item only in setup_t */
} newitems[] = { /* new items in order */
NEWITEM (foo),
NEWITEM (bar),
...
};
Now write functions to copy a memory area, inserting or deleting space at
the indicated new parameter locations.
On the other hand, once the smaller struct has been defined, and it sounds
as if it has, write the conversion functions once (it sounds like they
have
been) and forget it. The newer one may be subject to additions, but that
doesn't affect the two functions.
--
Thad


|