Shop OBEX P1 Docs P2 Docs Learn Events
Bits from Byte Array? — Parallax Forums

Bits from Byte Array?

CapdiamontCapdiamont Posts: 218
edited 2012-12-21 23:14 in BASIC Stamp
OpenTrac decoder 21 Dec 2012 13_30.bs2

I am trying to figure out OpenTrac.org specification for radio. OpenTrac is supposed to be a simpler, more extensible version of APRS.
I have an array I need 6 MSB out of ten bytes for SSID. From what I can see I have it right, but it does not produce the expected result.
DEBUG BIN1 MyBytes.HIGHBIT(2) or DEBUG BIN1 MyBytes.BIT7(2) for testing does not work.
IndexTemp2.BIT0 = MyBytes.HIGHBIT(2) does not work.

The only thing I am using on the bs2 is the programming port for DEBUG and DEBUGIN communications. I am just doing a few element decoding routines in the BS2. The one I am working on is element 1, originating station. Uses Big E bit order.

Consists of nine bytes
1: length of message(09), bit 1 is only for if using extended element id. (09) is hex, meaning not extended and has 9 bytes after the first.
2: element id, this case (01)
3. This case, start of six byte callsign with SSID using MSB of each callsign byte. using (4E)
4. using (31)
5. using (56)
6. using (C7)
7. using (80)
8. using (80) callsign example N1VG and SSID 7
9. using (00) beginning of sequence word
10. using (00)

If I can get past bit problem I think I can get it from there.

Comments

  • SapphireSapphire Posts: 496
    edited 2012-12-21 19:32
    When you try to access bits in a byte array, the reference for the array is the first element of the modifier. That means when you do MyBytes.HIGHBIT(2) you are actually looking at bit 1 in the second byte of the MyBytes array. The array modifier takes on the size of the modifier. I suggest you only use .LOWBIT(x) for your modifier, and x will be the bit you want, starting at the base of the MyBytes array. For bit 0 of byte 0 in MyBytes, x will be 0. For bit 0 of byte 1 in MyBytes, x will be 8. For bit 7 of byte 4, x will be 31 and so on. You can't use the modifier element to reference the array element.
  • CapdiamontCapdiamont Posts: 218
    edited 2012-12-21 23:14
    Thanks! That has seemed to do the trick. Now to figure out other bugs and create new bugs.
Sign In or Register to comment.