I am having some difficulty trying to reinterpret data to pull information out of messages. I've tried to recreate the problem here.
I am receiving a series of long integers (32 bits) by popping them off a stack. I need to assemble these into 4 word(16 byte) packets. The struct I recreated below resembles the first word of a given packet. The difficulty I am having is that in order to determine which word is the starting packet, as well as which type of packet is which I need to be able to read the octal value of the data in the s5 member of the struct.
Simply put, for each message, I need to interpret bits 16-31 as a 16 bit integer regardless if it crosses bit boundaries on other messages.
I would have thought this would be a much easier task, but I cannot seem to get it to work. Here is what I have tried. I'm just getting Null values.
struct S
{
uint8_t s1 :8;
short s2 :2;
bool s3 :1;
int s4 :5;
uint16_t s5 :16;
};
int main() {
S s;
s.s1 = 3;
s.s2 = 2;
s.s3 = true;
s.s4 = 1;
s.s5 = 02050;
long l;
memcpy(&l, &s, sizeof(S));
std::deque<long> d;
d.push_back(l);
cout << *((uint16_t*)(&d.front()+2)) <<endl;