Shop OBEX P1 Docs P2 Docs Learn Events
Proper way to store and retrieve strings from DAT table? — Parallax Forums

Proper way to store and retrieve strings from DAT table?

WBA ConsultingWBA Consulting Posts: 2,934
edited 2014-11-01 21:52 in Propeller 1
My current project (GPS based Scavenger Hunt) requires a data table that will store 3 pieces of data for 5 items that will be called in groups like in a table sort of like this:



String (clue)
Latitude
Longitude


Maidu Center
38.745843
-121.252334


Location2
38.739822
-121.252056


Location3
38.734363
-121.252490


Location4
38.732386
-121.252764


Last Location
38.736832
-121.252886










I have been laying around with the DAT section code from page 109 of the Propeller Education Kit labs book. However, even though I can store a string with a byte size alignment without issue, I can't figure out how to retrieve just a single string in an array. In other words, if this is my DAT section:
DAT
ClueData                byte    "clue1", "clue2", "clue3", 0

Then how do I pull the second string (clue2) to send to an LCD? All of my attempts to pick one item, just shoot out everything under cluedata; all I can get is "clue1clue2clue3" on the LCD.

Also, how do is store the lat/long? Can I store 38.734363 in a DAT array and have it be usable for my great circle math formulas?

Lastly, if I want the user of my code to have an easy way to modify the code to their clues, latitudes, longitudes, is there a better way than a DAT array?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-04-02 23:04
    Re: string table, have a look at page 173 of the Propeller Manual (rev 1.2). The example shown should be close enough to what you want. It all depends on how you want to access your strings, i.e. strictly sequentally or random access. Floats can be stored as is, e.g.
    long    1.0
    
    The Manual example boils down to:
    CON
      _clkmode = XTAL1|PLL16X
      _xinfreq = 5_000_000
    
    OBJ
      serial: "FullDuplexSerial"
      
    PUB null | n
    
      serial.start(31, 30, %0000, 115200)
      waitcnt(clkfreq*3 + cnt)
      
      repeat n from 0 to 2
        serial.str(@@clue_T[n])
        serial.tx(13)
    
    DAT
    
    clue_T  word    @clue_0, @clue_1, @clue_2
    
    clue_0  byte    "1st clue", 0
    clue_1  byte    "2nd clue", 0
    clue_2  byte    "3rd clue", 0
    
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2012-04-03 01:47
    kuroneko,
    Thanks, that did the trick. I now have tables squared away for the clues, latitudes, and longitudes. Also, since the byte aligned string data will flow out together, I added in some hex codes for the LCD so each clue handles it's own positioning. ( IE: $0c is CLS which positions on the first row, position 0, and $94 is position 0 on the 2nd row). So that I have default lat/longs in the code, I just filled all 5 with Parallax's lat/long. Clue_0 is basically a null because I am using it to determine if it is the first time the unit is powered up so I know whether or not to display instructions.

    Here's the DAT table:
    DAT
    clue_T  word    @clue_0, @clue_1, @clue_2, @clue_3, @clue_4, @clue_5
    lat_T   word    @lat_0, @lat_1, @lat_2, @lat_3, @lat_4, @lat_5
    long_T  word    @long_0, @long_1, @long_2, @long_3, @long_4, @long_5  
    
    clue_0  byte    "Start", 0
    clue_1  byte    $0c, "1st", $94, " clue", 0 
    clue_2  byte    $0c, "2nd", $94, " clue", 0
    clue_3  byte    $0c, "3rd", $94, " clue", 0
    clue_4  byte    $0c, "4th", $94, " clue", 0
    clue_5  byte    $0c, "5th", $94, " clue", 0
    
    ' Parallax = 38.813195,-121.296108
    
    lat_0  long    0
    lat_1  long    38.813195 
    lat_2  long    38.813195
    lat_3  long    38.813195
    lat_4  long    38.813195
    lat_5  long    38.813195
    
    long_0  long    0
    long_1  long    -121.296108   
    long_2  long    -121.296108  
    long_3  long    -121.296108  
    long_4  long    -121.296108  
    long_5  long    -121.296108 
    

    And to call out the clues, I am using the following code (EEDATA[2] is the current clue number. I save an array of variables to EEPROM so that powering down doesn't reset you to the first clue):
    idx := EEDATA[2]                        ' Assign clue number to idx
      lcd.str(@@clue_T[idx])                  ' Display clue
    

    Thanks to your help, all I have to do now is merge my EEPROM storage/retrieval code, Splash screen code, and my GPS distance measuring code. Since they are all done and working separately, it should be fairly easy from here on out.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2012-04-03 02:03
    Another thought, to make it easy to enter the clues, latitudes, and longitudes without entering on the wrong line, is there any reason I can't do this (it compiles, but since my code that will pull from the DAT section isn't complete, I don't know if it works):
    DAT
    clue_T  word    @clue_0, @clue_1, @clue_2, @clue_3, @clue_4, @clue_5
    lat_T   word    @lat_0, @lat_1, @lat_2, @lat_3, @lat_4, @lat_5
    long_T  word    @long_0, @long_1, @long_2, @long_3, @long_4, @long_5
    
    ' Parallax = 38.813195,-121.296108
    
    clue_0  byte    "Start", 0
    lat_0   long    0
    long_0  long    0
    
    clue_1  byte    $0c, "1st", $94, " clue", 0 
    lat_1   long    38.813195
    long_1  long    -121.296108  
    
    clue_2  byte    $0c, "2nd", $94, " clue", 0 
    lat_2   long    38.813195
    long_2  long    -121.296108 
    
    clue_3  byte    $0c, "3rd", $94, " clue", 0
    lat_3   long    38.813195
    long_3  long    -121.296108
    
    clue_4  byte    $0c, "4th", $94, " clue", 0 
    lat_4   long    38.813195
    long_4  long    -121.296108 
    
    clue_5  byte    $0c, "5th", $94, " clue", 0
    lat_5   long    38.813195
    long_5  long    -121.296108  
    
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-03 02:13
    Should work fine. In this case however I'd put the longs (known quantities) first and the string last. Then you only need one table (which points to elements with latitude at offset +0, longitude at +4 and the clue at +8), e.g.
    DAT
    clue_T  word    @clue_0, @clue_1, @clue_2, @clue_3, @clue_4, @clue_5
    
    ' Parallax = 38.813195,-121.296108
    
    clue_0  long    0
            long    0
            byte    "Start", 0
    
    clue_1  long    38.813195
            long    -121.296108  
            byte    $0c, "1st", $94, " clue", 0 
    
    clue_2  long    38.813195
            long    -121.296108 
            byte    $0c, "2nd", $94, " clue", 0 
    
    clue_3  long    38.813195
            long    -121.296108
            byte    $0c, "3rd", $94, " clue", 0
    
    clue_4  long    38.813195
            long    -121.296108 
            byte    $0c, "4th", $94, " clue", 0 
    
    clue_5  long    38.813195
            long    -121.296108
            byte    $0c, "5th", $94, " clue", 0
    
    In this case latitude is long[@@clue_T[n]][0], longitude is long[@@clue_T[n]][1] and the string address is @@clue_T[n] + 8.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2012-04-04 13:59
    Kuroneko,
    Thanks again for the help. Last night I completed the data table section of my code using your suggestions and it works well. I even had time to work on some of the GPS distance math using coordinates from the data table and it worked clean as well. I have a weird issue with the LCD, but I believe I may be missing some delays somewhere in my code. The backlight will flicker once in a while as if I am turning it off/on really quick and a few times it never displayed anything until I reset the prop a second time.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-04 17:11
    One limitation with the Object Address Pluss Symbol (@@) is it can only be used in variable expresions.

    I've had times when I've needed to know this offset to use it other ways.

    I believe this offset is always 16 but I'm not sure.

    This is how I computed the offset when needed (using your example data).
    PUB GetOffset
      result := @clue_0 - clue_T[0]
    DAT
    clue_T  word    @clue_0, @clue_1, @clue_2
    clue_0  long    0
            long    0
            byte    "Start", 0
    clue_1  long    38.813195
            long    -121.296108  
            byte    $0c, "1st", $94, " clue", 0 
    clue_2  long    38.813195
            long    -121.296108 
            byte    $0c, "2nd", $94, " clue", 0 
     
    

    The method "GetOffset" should return the offset value.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2014-11-01 21:52
    So, I recently picked this project back up off the backburner since Parallax just added the new GPS module with the Propeller on board for only $35. As I am looking at a bunch of my code to refresh myself, I caught that I had this thread still tagged as unsolved. I just changed it to solved.

    Hoping to have my prototype done soon. I have it completely build (but with a Quickstart and PMB-648 GPS) and my latest version of code is about 90% complete. Just have to figure out a bug with how my code validates when the GPS flags that it has a valid fix and do a few more minor tweaks. I will be buying one of the new VPN1513 GPS modules, product 28510, to make a second unit. The total cost of the project will be under $100 now that the Propeller and GPS is only $35.
Sign In or Register to comment.