Hello all,
I have a question about shifting data.
Before everyone goes and asks for datasheets, schematics or example code, I can not give that out as part of a non-disclosure. The problem is fairly simple and straightforward anyways. (Also this is not a job, just helping a friend)
I am communicating with a sensor device using an HMI using ModbusTCP. The dimwits that designed the sensor didn't use the standard 16bit word for every register so every time they throw in an 8bit unsigned int it screws up the rest of the registers. Unfortunately fixing that is not something that's gonna happen any time soon.
The macro in the HMI uses standard C and has a few built in functions for reading registers.
The problem is that these functions only use unsigned shorts so 16bits each. (1 register)
This is the definition I have for some of the data: (Note the 1 byte in the middle)
Product Code Description – character string (32 bytes) 16 words
Constituent 1 Coefficient A– IEEE float (4 bytes) 2 words
Constituent 1 Coefficient B– IEEE float (4 bytes) 2 words
Constituent 1 Coefficient C– IEEE float (4 bytes) 2 words
Constituent 1 Use Log Fit - 8 bit integer (1 byte) 1= use log fit (1/2 Word........)
Constituent 2 Coefficient A– IEEE float (4 bytes)
Constituent 2 Coefficient B– IEEE float (4 bytes)
Constituent 2 Coefficient C– IEEE float (4 bytes)
Constituent 2 Use Log Fit - 8 bit integer (1 byte) 1= use log fit
Constituent 3 Coefficient A– IEEE float (4 bytes)
Constituent 3 Coefficient B– IEEE float (4 bytes)
Constituent 3 Coefficient C– IEEE float (4 bytes)
Constituent 3 Use Log Fit - 8 bit integer (1 byte) 1= use log fit
Everything is fine until I reach the "Use Log Fit" byte. After that, every single unsigned short is now offset by 8 bits.
I need a way to make this: x = data I don't want(The single byte). 0 = data i need.
{xxxxxxxx00000000}, {0000000000000000}, ....{00000000xxxxxxxx}
Into this:
{0000000000000000}, {0000000000000000}, ....{0000000000000000}
And no i'm not making that data out of thin air. It's just shifted to the left or right by 8 bits and then the data will be in order in the registers for the HMI to then display on screen.
I know I could split up every word into bytes and then do some bitwise operations to concatenate everything into words again but I was wondering if there was a simple way to do this without a lot of code.
Thanks.