Shop OBEX P1 Docs P2 Docs Learn Events
the @ is killing me... [resolved] — Parallax Forums

the @ is killing me... [resolved]

teddypteddyp Posts: 14
edited 2010-04-10 17:58 in Propeller 1
I'm trying to convert a decimal number to hex. I got the simple numbers object and take my decimal number (I'm using 200108) and pass it through the code..

joe := 200108
steve:=num.ihex(joe,8)

Now, the result I am looking for somewhere should be $00030DAC
I know my variable steve here is a pointer to the string, so if I were to try to display this with tv_text (I'll call it term here because that's what everyone else calls it) should'nt I just say
term.hex(@steve,8)
or
term.str(@steve)
neither of them work for me. I get garbage on the screen. What am I doing wrong?

Post Edited (teddyp) : 4/10/2010 6:01:14 PM GMT

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2010-04-09 19:51
    The address of the converted string is stored in the variable steve.· Use term.str(steve) to print it out.
  • teddypteddyp Posts: 14
    edited 2010-04-09 21:06
    Ok, thanks. That did work. Unfortunately it only works for data I assign though. It talks in the manual about runtime data and the @'s needed for offset information and such and I think I'm somewhere in there. What's going on is that I'm pulling data from a GPS. I have it stuck in a long and can display it no problem. But, I want to take this data and convert it to hex for some other stuff. I just can't figure out why it works with tv_text and nothing else. so, if that data is stored in GPRMCa[noparse][[/noparse]8] (from GPS float lite demo) and I can view it fine by using term.str(GPRMCa[noparse][[/noparse]8]) how can I modify it? if I set mark:=GPRMCa[noparse][[/noparse]8] and try to convert mark, or @mark, or @@mark I just keep getting addresses back or a blank result on the screen. This just isn't making sense to me.
  • kuronekokuroneko Posts: 3,623
    edited 2010-04-10 01:51
    teddyp said...
    I just can't figure out why it works with tv_text and nothing else. so, if that data is stored in GPRMCa[noparse][[/noparse]8] (from GPS float lite demo) and I can view it fine by using term.str(GPRMCa[noparse][[/noparse]8]) how can I modify it? if I set mark:=GPRMCa[noparse][[/noparse]8] and try to convert mark, or @mark, or @@mark I just keep getting addresses back or a blank result on the screen. This just isn't making sense to me.
    We may need to see some code at this stage. Otherwise we could sit here all eternity trying to guess what's wrong [noparse];)[/noparse]
  • teddypteddyp Posts: 14
    edited 2010-04-10 16:40
    Thanks for the continued support here. I thought it was from the float lite demo, but the code I'm playing with is actually Joshua Hintze's GPS code from the programming the prop book. full source: tp.propeller-chip.com/PCMProp/Chapter_09/Source/
    So, the code starts up full duplex serial and grabs the data from the gps...

    PUB main
      fdser.start(GPS_RXDATA, GPS_TXDATA, GPS_MODE, GPS_BAUD)'Serial transmission to GPS module
      cognew(readNEMA,@gps_stack)                           'Load NEMA into new cog
    
    PUB readNEMA
      Null[noparse][[/noparse]0] := 0
      repeat
       longfill(gps_buff,20,0)
       repeat while Rx <>= "$"      ' wait for the $ to insure we are starting with
         Rx := fdser.rx              '   a complete NMEA sentence 
       cptr := 0
    
       repeat while Rx <>= CR       '  continue to collect data until the end of the NMEA sentence 
         Rx := fdser.rx              '  get character from Rx Buffer
         if Rx == ","
           gps_buff[noparse][[/noparse]cptr++] := 0    '  If "," replace the character with 0
         else
           gps_buff[noparse][[/noparse]cptr++] := Rx   '  else save the character   
       
       if gps_buff == "G"             
         if gps_buff == "G"            
           if gps_buff == "A"            
               copy_buffer(@GPGGAb, @GPGGAa)
    
       if gps_buff == "R"             
         if gps_buff == "M"            
           if gps_buff == "C"           
               copy_buffer(@GPRMCb, @GPRMCa)
                       
       if gps_buff[noparse][[/noparse]0] == "P"
        if gps_buff == "G"  
         if gps_buff == "R"
          if gps_buff == "M"  
           if gps_buff == "Z"
               copy_buffer(@PGRMZb, @PGRMZa)
                    
    pub copy_buffer ( buffer,args)
             bytemove(buffer,@gps_buff,cptr) '  copy received data to buffer
             ptr := buffer
             arg := 0
             repeat j from 0 to 78           ' build array of pointers
              if byte[noparse][[/noparse]ptr] == 0               ' to each
                 if byte[noparse][[/noparse]ptr+1] == 0           ' record
                    long[noparse][[/noparse]args][noparse][[/noparse]arg] := Null     ' in 
                 else                            ' the
                    long[noparse][[/noparse]args][noparse][[/noparse]arg] := ptr+1     ' data buffer
                 arg++
              ptr++
              
    ' now we just need to return the pointer to the desired record
    
    



    the data is then loaded into the variables such as GPRMCa and GPGGAa. So, the data I want is located at GPRMCa[noparse][[/noparse]8] for example for the date. If I want to see the info on the screen, I use display.str(GPRMCa[noparse][[/noparse]8]) and BAM! I can see the date on my screen. Awesomeness. But I want to take that value for the date and convert it to hexadecimal. I have no idea where the value is. If I use display.hex(GPRMCa[noparse][[/noparse]8],8) I get say 00002662 out. That's telling me that it's a pointer to the data located in address $00002662, right? so if I did @GPRMCa[noparse][[/noparse]8] (which the compiler freaks out on, so I tried assigning another variable say steve:=GPRMCa[noparse][[/noparse]8] and then tried @steve) shouldn't it display the value at that address? Using the steve variable, I do display.hex(@steve,8) and I get another hex stream that just looks like an address like $0000266D. I used this example on purpose because it's usually only the last digit that is different and usually by about 10 or so. So, do I try display.hex(@@steve,8)? I get another value similar to the first two. I don't get why it can send out the value in string format, but try decimal or hex and I get these results. I'm currently trying to just see the data so I then use numbers or simple numbers to convert it to a hex string to be tooled with. When the GPS does not have a signal, the default date it outputs is 200108 or $30DAC. So, shouldn't one of those locations have $30DAC in it? It's driving me insane. confused.gif
  • mparkmpark Posts: 1,306
    edited 2010-04-10 17:20
    If GPRMCa[noparse]/noparse]8] (aka steve) is a pointer to data, use [b]long[noparse][[/noparse]GPRMCa[noparse][[/noparse]8[/b] to get that data (or word or byte depending on the data).

    The @ does the opposite of what you want.
  • teddypteddyp Posts: 14
    edited 2010-04-10 17:54
    Thanks! I think I'm making some progress then. I have the spin quick reference guide printed and hanging on the wall and I see now the "access long of main memory" for using long. I thought it was strictly declaration. Poor attention to detail on my part. At any rate, I tried what you suggested as in..

    steve:= long[noparse][[/noparse]GPRMCa[noparse][[/noparse]8]]
        display.str(GPRMCa[noparse][[/noparse]8])
        display.str(string(" | "))
        display.hex(steve,8)
    


    for the first part, I get the default date out (200108) but for the second part, I get 30303200 not essentially what I was expecting, but I think it may be the ascii for the data backwards, as in $30=0 and $32 =2 with 00 being EOT.
    so, if thats the case, then backwards it would be EOT 200 being half of the string displayed. which also means the second half is in the memory location either immediately after or before this one. Any idea how I go about accessing that? I was under the impression that I could just do something like GPRMCa[noparse][[/noparse]8]++. or perhaps a different offset hrm...
  • teddypteddyp Posts: 14
    edited 2010-04-10 17:58
    got it!!! mpark, where do I send your beer to?

    as per the language reference on page 130, I just did
        steve:= long[noparse][[/noparse]GPRMCa[noparse][[/noparse]8]]
        mike:=long[noparse][[/noparse]GPRMCa[noparse][[/noparse]8]][noparse][[/noparse]x1]
    
    


    now, steve =002 and mike =801, or the string 200108 backwards. Awesome! Thanks for the help everyone!

    I know it says x1 in there, its just a 1, the bb code stripped it out the first time.

    Post Edited (teddyp) : 4/10/2010 6:15:03 PM GMT
Sign In or Register to comment.