I'm writing a little program grab some data off a CAN bus, using the popular Peak CanUsb dongles, for which they supply a suitable Windows API. So far so good, no issues, i'm getting data when i should.
For people who aren't CAN experts (basic) CAN has an 8 byte (64bit) payload, and individual parameters can be encoded by the bus architect into those bytes. For example, on a car, you might have the engine ecu sending the engine speed to the dash board to display to the driver, and engine speed might be encoded with a scaling of 1, and offset of zero, and a width of 16bits, and those two bytes might say be located in the 1st and 2nd byte of the CAN message.
Ie, the 8 bytes look like this (where X is don't care)
B0,B1,B2,B3,B4,B5,B6,B7
136,019,x,x,x,x,x,x
Here, we take 19, multiply it by 256 (4864) and add 136, for a total of 5000, ie "5000 rpm" for example
So that's an easy one, because to decode the data from the message payload you just grab the first two bytes, multiply the most significant byte by 2^8 and add it to the least significant byte and it's job done (ignoring the issues surrounds motorola and intel encodings for now....).
But, what if i want to decode values that don't fall on nice byte boundaries. Say a parameter was a 3 bit value (0 to 7), encoded into say the 23 to the 25th bit of the message bytes? It would start in the last two bits of the 3rd Byte, and finish on the 1st bit of the 4th byte.
In an embedded scenario id have no problem in doing some basic bit shifting and some bit masking or use some bitfield unions to pull out just the bits i'm interested in, but how do i do that in a windows environment?
I'm coding in visual studio, with .NET mostly in a visual basic forms style.
Whats the best way of approaching bitwise operations in a 64b native high level environment? Anyone have experience or ideas?