Shop OBEX P1 Docs P2 Docs Learn Events
64 bit address to string comparison — Parallax Forums

64 bit address to string comparison

adriadri Posts: 34
edited 2009-07-08 11:21 in Propeller 1
Hi

I'm getting a 64 bit address sent back from a sensor that I want to compare with the address in string form to confirm it is the one I think it is. I've defined a DAT entry as

Sensor1 byte "E80000016C5DB828", 0

And then in the code I'm trying to do a strcomp(@Sensor1, @addr)

but it's failing because they are two different data types I suspect....

Is there a way to do that or do I have to convert the 64 bit address to a string first? And how's that done...

OR how do I do it with numerical comparison?

Many thanks

I'll keep reading..........

Adri

Comments

  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-07-06 15:22
    You could just AND them, but I think you'll have to do it in two 32-bit chunks as the prop is 32 bit [noparse]:)[/noparse] - H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • adriadri Posts: 34
    edited 2009-07-06 15:36
    Been a long time since I've done any coding...and it's showing...never was any good at bitwise operations anyway.

    If anyone's got the time to demo the sort of code that might work it'd be appreciated.

    TIA

    adri
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-06 15:53
    You're trying to compare a 64 bit value to an equivalent hexadecimal string. It is indeed like trying to compare apples to oranges. You need to get both things in the same form. It's easier to make your DAT information into a 64 bit value like this:

    Sensor1 byte "E80000016C5DB828", 0

    becomes

    Sensor1 long $01_00_00_E8, $28_B8_5D_6C

    Notice that the order of the bytes in each long is reversed. What I'm assuming here is that the 8 bytes shown in your hexadecimal string come in in the order shown so that "E8" is the 1st byte value. If you work out how the constants I've written are actually stored in memory, you'll see that the order works out correctly.

    If you read in the sensor address into another two long array called "Address", you'd compare them like

    IF Address[noparse][[/noparse] 0 ] == Sensor1[noparse][[/noparse] 0 ] AND Address[noparse][[/noparse] 1 ] == Sensor1[noparse][[/noparse] 1 ]
  • adriadri Posts: 34
    edited 2009-07-08 10:36
    Still struggling with this...sorry.

    In order to output to the parallax serial terminal the program is

    pst.hex(LONG[noparse][[/noparse]addr + 4],8)
    pst.hex(LONG[noparse][[/noparse]addr],8)

    I've tried any number of things but still can't get a comparison with Mike's suggested two longs array...

    If someone could suggest what's going wrong it'd be appreciated. It doesn't help that I'm having to leave this and come back to it every so often and then starting again each time...

    Ugh!

    Many thanks

    Nick
  • adriadri Posts: 34
    edited 2009-07-08 11:21
    solved...

    phew, now on to doing something with this thing!!!
Sign In or Register to comment.