Addressing bytes of a buffer referenced by bits from another byte in the buffer
Don M
Posts: 1,652
in Propeller 1
Sounds like a crazy title but didn't know how else to write it.
I have a 12 byte buffer. In that buffer are the following:
02 00 01 05 02 00 07 01 02 05 14 14 indexed from 0 to 11 starting at the left end.
My question is how can I point to bytes 7 through 11 (01 02 05 14 14) by virtue of the 2 bytes 5 & 6 (00 07)?
I know that in bit form the 00 07 would be 0000 0111. So how do I reference byte 7 (01) from bit 0 of byte 6? Then bit 1 of byte 6 represents byte 8 and so on.
Maybe said another way- my "mask" from bytes 5 & 6 somehow references bytes 7, 8 & 9.
Sorry for my ignorance here. But thanks for any help.
Don
I have a 12 byte buffer. In that buffer are the following:
02 00 01 05 02 00 07 01 02 05 14 14 indexed from 0 to 11 starting at the left end.
My question is how can I point to bytes 7 through 11 (01 02 05 14 14) by virtue of the 2 bytes 5 & 6 (00 07)?
I know that in bit form the 00 07 would be 0000 0111. So how do I reference byte 7 (01) from bit 0 of byte 6? Then bit 1 of byte 6 represents byte 8 and so on.
Maybe said another way- my "mask" from bytes 5 & 6 somehow references bytes 7, 8 & 9.
Sorry for my ignorance here. But thanks for any help.
Don
Comments
In most cases, you'd fetch the word at bytes 5 and 6 ... probably one byte at a time because it's byte-aligned. Now you have the mask. Your starting address for referencing is 7. Do you want to pick up the bytes selected by the mask and shift them into a 32-bit word? There's not yet enough information about what you want to do.
Since bytes 5 & 6 equal 00 07 (or 0000 0111) I'd like to be able to point to bytes 7, 8 & 9. Similarly if bytes 5 & 6 were 00 04 (0000 0100) then I'd want to point to byte 9. Make sense?
This is a 23 byte message received from a coin accepter / changer during it's initialization and setup. I'll explain what each area of the message represents.
1 is the MDB level at which the changer operates
2 is the country currency code. 00 01 is USA
3 is the scaling factor. In this case it's 5 or $0.05
4 is the number of decimal points 2
5 is the representation of coin tubes available to store coins. 16 maximum. 00 07 is this in binary -> MSB 0000 0000 0000 0111 LSB What this is saying is that there are 3 tubes in this device that will hold coins 1, 2 & 3 (or 3, 2 & 1 as you look at it)
6 is the 16 coin channels and their hex value of each. Goes from LSB to MSB from coin 1 to coin 16 so the 01 means that channel 1 is worth 1 x the scaling factor which is a nickel. The next channel shows a 02 so that times the scaling factor equals a dime. The third is a 05 x scaling factor equals a quarter. The fourth and fifth are both 14H which is 20 decimal x scaling factor equals $1. The reason there are 2 channels the same value is for old type dollar coin and new.
So where am I going with this. There is another message received that indicates the inventory in each coin tube. The message is 18 bytes long (max). First 2 bytes indicate which tube is full by way of a binary representation. 2 bytes = 16 bits = 16 coin channels. If one of the bits is set then that coin tube is reported as full. The next 16 bytes report (in HEX) the number of coins in each tube. Different manufacturers of changers report in different ways. By that I mean 1 manufacturer might report the whole 18 byte string even though they only accept 5 coins whereas another may only report the first 2 bytes (mandatory) plus only the number of bytes that represent the number of different coins that it will accept. So in the case of my example above it only accepts nickel, dime, quarter, dollar1 and dollar2 so it's message is only 7 bytes long.
What I'm trying to do programatically is when the coin inventory message is received to truncate it to only show the actual tubes available. Then do some calculations based on the various byte values (scaling factor, decimal places and coin value) to get a dollar value.
So my question is how do I deal with the portion of the message (#5) and correlate the bits from bytes 6 & 7 which are MSB to LSB to the bytes 8 through 23 in #6 that are LSB to MSB?
Hope this helps. Thanks.