Hello all,
I am trying to keep my coding easy for everyone to use. I have some
ARINC data that need to go out which 12 Bytes long. The first byte is
the command word, the next 10 bytes represent 40 devices in the system
with four command that can be issue per device. So within the each
byte of the 10 bytes a command comprises 4 device. The last byte is a
send flag.
I first tried creating a struct like the following...
struct CMD_DEVICE {
unsigned char cmd;
unsigned char device[40]:2;
unsigned char flag;
};
As I found out, this is illegal in C and can't be used. Okay, the
next try was to do the following..
struct DEVICE {
unsigned char device:2;
};
struct CMD_DEVICE {
unsigned char cmd;
struct CMD_DEVICE device[40];
unsigned char flag;
};
Which compiles fine, but the memory footprint is off and is treating
each 'device' struct as a byte and not a bit-field. So I can't use
that. I can get it to work like the following
struct CMD_DEVICE {
unsigned char cmd;
unsigned char dev1:2;
unsigned char dev1:2;
...
unsigned char dev39:2;
unsigned char dev40:2;
unsigned char flag;
};
This is fine and work okay, as I can tell so far, but it just looks
nasty and ugly as a declaration. The problem is that I have similar
ARINC data that comes down and it 3 or 4 bits. I would like to avoid
creating a huge structure declaration for each type. Is there a better
way of doing this? Any help is greatly appreciated.
Mark