So I have in my library the following struct define:
typedef struct
{
uint16_t id;
struct {
int8_t rtr : 1;
uint8_t length : 4;
} header;
uint8_t data[8];
} tCAN;
In this particular project, I need to manipulate 'data' as a whole number so I though of doing the following which I had tested on jdoodle C compiler (the uint_t's where replace with char/long there! ):
uint64_t *concat_data;
concat_msg = msg.data;
it compiles and outputs (with a warning) on jdoodle but comes with the following error in IDE:
cannot convert 'uint8_t [8] {aka unsigned char [8]}' to 'uint64_t* {aka long long unsigned int*}' in assignment
one other option (without modifying the library itself) would be to "shift in the bits" i guess but the pointer way is so much neater!
is there a way to use pointers here?
here's the code I tested (with error):
typedef struct
{
uint16_t id;
struct {
int8_t rtr : 1;
uint8_t length : 4;
} header;
uint8_t data[8];
} tCAN;
void setup() {
tCAN msg;
uint64_t *concat_msg;
Serial.begin(115200);
msg.data[0] = 0x01;
msg.data[1] = 0x02;
msg.data[2] = 0x03;
msg.data[3] = 0x04;
msg.data[4] = 0x05;
msg.data[5] = 0x06;
msg.data[6] = 0x07;
msg.data[7] = 0x07;
concat_msg = msg.data;
union {
uint64_t val;
struct {
uint32_t LSWord;
uint32_t MSWord;
};
} out;
out.val = *concat_msg;
Serial.print(out.MSWord, HEX);
Serial.println(out.LSWord, HEX);
}
void loop() {
// put your main code here, to run repeatedly:
}