Shop OBEX P1 Docs P2 Docs Learn Events
When method calls fail... *** RESOLVED! — Parallax Forums

When method calls fail... *** RESOLVED!

Sniper KingSniper King Posts: 221
edited 2008-09-24 16:22 in Propeller 1
In the software I am writing i am having trouble with method calls.· Everything is fine until a certain criteria is met then when I call the method I need to use the chip crashes.· if I move all the method's code to the loop I am running, it works.· Move it back and it fails. ·Anybody else have this problem

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··


Michael King
Application Engineer
R&D

Check out Project: PSAV Persistent Sailing Autonomous Vehicle

Post Edited (Sniper King) : 9/24/2008 4:22:44 PM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-18 21:39
    Is the method in a Spin cog you've started from a parent cog? If so, have you allocated enough stack space?

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-09-18 21:39
    memory stomp methinks.
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 17:14
    Per Mike green I put a cap on the GPS Parsing routine but I am still having the same issue.· I am starting to think that my local variables are having issues but I am not sure what.· Here is some code that I have written.· Two methods that seem to send this thing spinning out of control (no pun intended! LOL)

    pub SendFix :Value  |BUF1 , x  , j 
    buf1:=0
    ''Debug.str(string("Sendfix",13))
     
    x:=0
    byte[noparse][[/noparse]BUF1+x]:="<"
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    repeat j from 0 to 7
      x++
      byte[noparse][[/noparse]BUF1+x]:=serial[noparse][[/noparse]j]
       
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    x++
    byte[noparse][[/noparse]BUF1+x]:="N"
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
     
    repeat j from 0 to strsize(@latitude)-1
      x++
      byte[noparse][[/noparse]BUF1+x]:=latitude[noparse][[/noparse]j]
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    repeat j from 0 to strsize(@Longitude)-1
      x++
      byte[noparse][[/noparse]BUF1+x]:=longitude[noparse][[/noparse]j]
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"                                   
    x++
    byte[noparse][[/noparse]BUF1+x]:=bftmode[noparse][[/noparse]0]
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    x++
    byte[noparse][[/noparse]BUF1+x]:=answer[noparse][[/noparse]0]
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    x++
    byte[noparse][[/noparse]BUF1+x]:=separation[noparse][[/noparse]0]
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    x++
    byte[noparse][[/noparse]BUF1+x]:=">"
    x++
    byte[noparse][[/noparse]BUF1+x]:=0
      
    maxpwr(1)  ' Turn on Modem
       
    waitcnt(20_000_000+cnt)  
       comm.str(BUF1)
       waitcnt(30000000+cnt)
    buf1:=0  
    
     return
    
    


    pub GetCoords :Value   |BUF3 ,d8, decdd ,idx ,i 
    
    buf3:=0
     
    i:=0
       
     ' Create floating string of Latitude (DD.dddddd)  *********************
        bytefill(@latitude,0,14)
        'Latitude
       bytemove(BUF3,gps.latitude,strsize(gps.latitude))
         repeat until i==2
           latitude[noparse][[/noparse]i]:=byte[noparse][[/noparse]BUF3+i]
           i++
      d8 := atoi(gps.latitude+2,2) * 100_000 / 6           ' 8 digit, frac degrees. intermediate needed before conv to string for accuracy.
      d8 += atoi(gps.latitude+5,4) * 10 /6
      decDD    := num.ToStr(d8,Num#DEC6)       
      
      latitude[noparse][[/noparse]i]:="."
       
       repeat idx from 1 to 6
         latitude[noparse][[/noparse]idx+2]:=byte[noparse][[/noparse]decdd+idx]
         
       decdd:=0
        
          
     ' Create Floating string of Longitude (DDD.dddddd) *********************
     i:=0
     BUF3:=0
     bytefill(@longitude,0,14)
     'Longitude
     bytemove(BUF3,gps.longitude,5)
       repeat until i==3
         longitude[noparse][[/noparse]i]:=byte[noparse][[/noparse]BUF3+i]
         i++
      d8 := atoi(gps.longitude+3,2) * 100_000 / 6           ' 8 digit, frac degrees. intermediate needed before conv to string for accuracy.
      d8 += atoi(gps.longitude+6,4) * 10 /6
      decDD    := num.ToStr(d8,Num#DEC7)       
      
     longitude[noparse][[/noparse]i]:="."
         repeat idx from 1 to 6
           longitude[noparse][[/noparse]idx+3]:=byte[noparse][[/noparse]decdd+idx]
         
        Longitude[noparse][[/noparse]idx+4]:=0
      
        
        'bytemove(@buf,gps.heading,strsize(gps.heading))
        heading:=str2float(gps.heading) ' Float Heading                          
      
           
        'bytemove(@buf,@latitude,strsize(@latitude)+2)
      
        
        
      BUF3:=0
     ' Add sign on latitude
      i:=0     
       if byte[noparse][[/noparse]gps.N_S]=="S"
        lats:=fp.fneg(lats)
        BUF3:=0
       
        byte[noparse][[/noparse]BUF3+0]:="-"
         repeat until  i==strsize(@latitude)-1
           byte[noparse][[/noparse]BUF3+(1+i)]:=latitude[noparse][[/noparse]i]
           i++
        bytemove(@latitude,BUF3,strsize(BUF3))
        debug.dec( strsize(buf3) )
      lats:=str2float(@latitude)    ' Float Latitude  
      ' Add sign on longitude
      i:=0   
      if byte[noparse][[/noparse]gps.E_W]=="W"
        lngs:=fp.fneg(lngs)  
         BUF3:=0   
       i:=0
             byte[noparse][[/noparse]BUF3+0]:="-"
         repeat until  i==strsize(@longitude)-1
          byte[noparse][[/noparse]BUF3+(i+1)]:=longitude[noparse][[/noparse]i]
          i++
          byte[noparse][[/noparse]buf3+i+1]:=0
       bytemove(@longitude,BUF3,strsize(BUF3))
       debug.dec( strsize(buf3) )  
     
        
     lngs:=str2float(@longitude) ' Float Longitude
      
     
     'debug.str(string("Getcoords")) 
    return
      
    

       
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Mike CookMike Cook Posts: 829
    edited 2008-09-22 17:44
    Not that I’m the sharpest knife in the drawer………but it looks to me that you are writing characters to BUF1.
    ·
    Personally I would create an array in the VAR section, to allocate some space. Something like
    ·
    VAR
        BUF1[noparse][[/noparse]64]
    
     
    

    ·
    ·
    Then use that as you ‘string buffer’. It seems to me that your stomping on something because your buffer is not defined.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 17:59
    Isn't Buf1 defined in my local variables in my PUB section?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-22 18:06
    Don't forget that the forum software gobbles stuff in square brackets. You need to put a space after the opening bracket like Buf1[noparse][[/noparse] 64]. That's another reason for including larger pieces of code as attachments to a message rather than cutting and pasting into the message.

    Also, don't forget that, when you allocate arrays as local variables, they're always allocated as longs and the space is allocated in the stack. If you don't allow for that space, the stack will eventually run out of space, particularly when you may have video buffers in the high end of memory.
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 19:15
    Here is my code...· I really need help with this.· I have disabled everything that my software should do in the Control Method except the GetGPSReady method and it still fails.· This is where I am leaning as the GetGPSReady method calls the GPS_IO_mini_PNAV routine.· I have preventitive measures in place there to prevent these variable from getting overwritten.· Still the program spins out of control on every run.· However it happens at random places not the same place but always follows the GPS_IO_mini_PNAV calls.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-22 20:24
    buf1:=0
    ''Debug.str(string("Sendfix",13))  
    x:=0
    byte[noparse][[/noparse]BUF1+x]:="<"
    x++
    byte[noparse][[/noparse]BUF1+x]:="*"
    repeat j from 0 to 7
      x++
      byte[noparse][[/noparse]BUF1+x]:=serial[noparse][[/noparse]j]
       
    x++
    
    
    

    BUf1 is a long, set to 0 , byte[noparse][[/noparse]buf1+x] is writing to first 8 bytes of memory (i.e. byte at location 0+7) - really what you want?
    Similar questio about buf3 in the other routine
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 20:28
    In that routine i want to clear the BUF1 buffer that I am filling. What would be a good way to do that?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-22 20:35
    I've noticed several places where you use "<>=" where I think you meant "<>". The former is an assignment; the latter, a comparison.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 20:37
    Ok changing that now.... Thanks phil!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-22 20:37
    fill with zero

    bytefill(address, 0, size) - address is address of first byte of memory buffer, size is no of bytes

    e.g.
    byte buf[noparse][[/noparse]20]

    bytefill(@buf,0,20)

    2nd problem is that buf1 and buf4 are longs and not byte array so they are 4 bytes in size and writing 8 bytes will cause problems

    you can't define byte locals, so

    pub SendFix :Value· |buf[noparse][[/noparse]20],BUF1 , x· , j
    buf1:=@buf

    bytefill(buf1,0,80)
    buf[noparse][[/noparse]20] defines array 20 longs - which is 80 bytes.
    buf1:=@buf puts address of 1st byte of buf in buf1 which looks like it would work for the rest of your code.

    Change the 20 to the size you need - take size in bytes round up to next 4 and divide by 4. Make sure you set array size and bytefill size to same.
    You need to do something similar for the other routine.

    Also this allocates the 20 longs on the stack for the cog, so if it isn't on the main cog make sure the stack size is large enough
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-22 20:40
    Michael,

    A couple questions, if you don't mind:

    1. is this mission-critical software that lives depend on?

    2. Are you working against a tight deadline?

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 20:41
    Ok, that is changes in the whole file. I only found it in the GPS_IO_mini_PNAV object but it is changed now. Still broken though...:-(

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Sniper KingSniper King Posts: 221
    edited 2008-09-22 21:03
    This is not too time sensitive but the demo is on the 5th of OCT. This is just a proof of concept so no lives are at risk... yet...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Sniper KingSniper King Posts: 221
    edited 2008-09-23 16:19
    On the Stack passing to and from a cog, is this the amount of bytes that are possibly able to go to and from the cog?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Sniper KingSniper King Posts: 221
    edited 2008-09-23 16:22
    This is my GPS Parsing routine as it has helped resolve·some of the issues I was having but I still find that·some of my variables are being overwritten.· My method calls all work but my local variables are being overwritten now.· So my problem is not gone it has just moved.

    CON
      CR = 13                                               ' ASCII <CR>
      LF = 10                                               ' ASCII <LF>
      
    VAR  
    long gps_stack[noparse][[/noparse]100]   
    byte Rx',cksum 
     Byte EW[noparse][[/noparse]5]  
       byte NS[noparse][[/noparse]5]
       Byte VLD[noparse][[/noparse]5] 
       
       
       Byte LNG[noparse][[/noparse]25]
       byte lat[noparse][[/noparse]25] 
       Byte spd[noparse][[/noparse]10]
       byte DT[noparse][[/noparse]10]
       byte HD[noparse][[/noparse]10]
       byte GPS_Buff[noparse][[/noparse]100]  
       long cog,cptr
       long Null[noparse][[/noparse]1]
        
       long i
       long j
      
        
    OBJ
      uart :  "Fullduplexserial"
      'debug : "SerialMirror"
    PUB start(serRecv,serXmit) : okay
       'debud.start(31,30,0,9600)
    '' Starts uart object (at baud specified) in a cog
    '' -- returns false if no cog available
      okay := uart.start(serRecv,serXmit,0,4800)            ' for USGlobeSat model 408 mode is 0 
                                                            ' for serial PC simulator  mode is 1
      return cog := cognew(readNEMA,@gps_stack) + 1
      
    PUB readNEMA
       'debud.str(string("here"))  
      Null[noparse][[/noparse]0] := 0
      repeat
       longfill(@GPS_Buff,0,99)     ' zeroes the memory space
       repeat while Rx <>= "$"      ' wait for the $ to insure we are starting with
         Rx := uart.rx              ' a complete NMEA sentence 
       cptr := 0
       repeat while (Rx <> CR)  and (cptr<79)   '  continue to collect data until the end of the NMEA sentence 
         Rx := uart.rx              '  get character from Rx Buffer
         if Rx == ","
           GPS_Buff[noparse][[/noparse]cptr++] := "^"    '  If "," replace the character with 0
         else
           GPS_Buff[noparse][[/noparse]cptr++] := Rx   '  else save the character   
       
       i:=0
       j:=0
       if GPS_Buff[noparse][[/noparse]2] == "R"             
         if GPS_Buff[noparse][[/noparse]3] == "M"            
           if GPS_Buff[noparse][[/noparse]4] == "C"           
                
              
                repeat until GPS_Buff[noparse][[/noparse]i]=="^" 
                 
                 i++
                 
            i++
            'debug.str(string("Header"))
            'debug.str(string(13))   
                repeat until GPS_Buff[noparse][[/noparse]i]=="^"
                 
                 i++
                 
            i++
            'debug.str(string("Time"))
            'debug.str(string(13))     
              
            
             ' Valid ***************************
              repeat until GPS_Buff[noparse][[/noparse]i]=="^" or j=>2
                  VLD[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                   I++
                   
                   
                   j++
            vld[noparse][[/noparse]j]:=0
            
             'debug.str(@vld)
             'debug.str(string(13))    
             
            i++ 
                      j:=0
               
                repeat until GPS_Buff[noparse][[/noparse]i]=="^" or j=>18
                 lat[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                   i++  
                   j++
                   
            lat[noparse][[/noparse]j]:=0
            'debug.str(@lat)
             'debug.str(string(13))  
             j:=0
             i++
             
              repeat until GPS_Buff[noparse][[/noparse]i]=="^" or j=>2 
                 NS[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                 i++
                 j++
            ns[noparse][[/noparse]j]:=0
            'debug.str(@ns)
             'debug.str(string(13))  
            j:=0
            i++
              repeat until GPS_Buff[noparse][[/noparse]i]=="^" or j=>18 
                 lng[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                 i++
                 j++
            lng[noparse][[/noparse]j]:=0
            'debug.str(@lng)
             'debug.str(string(13))  
            j:=0
            i++
              repeat until GPS_Buff[noparse][[/noparse]i]=="^"  or j=>2 
                 EW[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                 i++
                 j++
            ew[noparse][[/noparse]j]:=0
            'debug.str(@ew)
             'debug.str(string(13))  
             j:=0
            i++ 
              repeat until GPS_Buff[noparse][[/noparse]i]=="^" or j=>4 
                 Spd[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                 i++
                 j++ 
            spd[noparse][[/noparse]j]:=0
            'debug.str(@spd)
             'debug.str(string(13))  
             j:=0
            i++ 
              repeat until GPS_Buff[noparse][[/noparse]i]=="^"   or j=>4 
                 HD[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                 
                 i++
                 j++
            hd[noparse][[/noparse]j]:=0
            'debug.str(@hd)
             'debug.str(string(13))  
             j:=0
             i++
              repeat until GPS_Buff[noparse][[/noparse]i]=="^"  or j=>7 
                 DT[noparse][[/noparse]j]:=GPS_Buff[noparse][[/noparse]i]
                 i++
                 j++
            dt[noparse][[/noparse]j]:=0
            'debug.str(@DT)
             'debug.str(string(13))    
    
    pub valid
       return @vld
    pub speed
       return @spd
    pub heading
       return @hd
       
    pub date
       return @dt
     
    pub latitude
       return @lat
        
    pub N_S
       return NS[noparse][[/noparse]0]
         
    pub longitude
       return @lng
        
    pub E_W
       return ew[noparse][[/noparse]0]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • hippyhippy Posts: 1,981
    edited 2008-09-23 17:42
    Sniper King said...
    This is my GPS Parsing routine as it has helped resolve some of the issues I was having but I still find that some of my variables are being overwritten. My method calls all work but my local variables are being overwritten now. So my problem is not gone it has just moved.

    Which particular variables are being over-written ? That could give a better idea of where to look.
  • Sniper KingSniper King Posts: 221
    edited 2008-09-23 17:48
    I happens back in the main cog.· the GPS routine passes back to right stuff.· Then i try to change it from DDMM.mmmm to DD.ddddd and the math is getting killed.· I get all wrong values.· The math is being stored in d8 in the Getcoords method.· D8 is going nuts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Sniper KingSniper King Posts: 221
    edited 2008-09-23 20:30
    OK, I think I have narrowed it down to here...
    Everything works except this....

    pub GetCoords    |idx ,i  ,d8,decdd
    debug.str(string(13))
        
     
     
       
     ' Create floating string of Latitude (DD.dddddd)  *********************
       Bytefill(@buf,0,99)    
      bytefill(@latitude,0,15) 
         bytemove(@buf,gps.latitude,strsize(gps.latitude))  'This works! @buf == GPS.latitude
         
      
         repeat i from 0 to 1
         
           latitude[noparse][[/noparse]i]:=buf[noparse][[/noparse]i]  Put the first two digits of the Latitude into @latitude
        
      
      d8 := atoi(buf[noparse][[/noparse]2],2) * 100_000 / 6           ' These three lines get the MM and mmmm and convert it to .ddddd
      d8 += atoi(buf[noparse][[/noparse]5],4) * 10 /6
      decdd:= num.ToStr(d8,Num#DEC6)       
       
      latitude[noparse][[/noparse]i]:="."
       
       repeat idx from 1 to 6
         latitude[noparse][[/noparse]idx+2]:=byte[noparse][[/noparse]decdd+idx]  'This finishes the conversion DD.ddddd
         
      i:=0
      
    
    


    ·here is the atoi method.· This takes a string and makes in an integer
    PUB atoi( pptr,c)| ptrr ,signs                                ' convert c characters into number
      result := signs := 0
      if byte[noparse][[/noparse]pptr] == "-"
          signs++
          pptr++
      c--    
      repeat ptrr from 0 to c
        if byte[noparse][[/noparse]pptr+ptrr] == 0                             ' stop if null
             quit
             
        if byte[noparse][[/noparse]pptr+ptrr] == "."                           ' stop if decimal point
             quit
        else     
           result := result * 10 + (byte[noparse][[/noparse]pptr+ptrr] - "0")
      if signs == 1
        result := -result
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-23 20:49
    the calls to atoi dont pass address o buf, you need @buf+2 and @buf+4
  • Sniper KingSniper King Posts: 221
    edited 2008-09-23 23:03
    I wanted to take the time for all of you who have taken the time to look at this.· I have learned volumes of information about memory management... but not enough so it would seem...LOL...whimper...



    I am still stomping on memory I think.· The getcoords routine worked before and now it fails the math.· I have been all over this software and I can't find the problem.· Can running multiple FullDuplexSerial objects create memory stomping issues?· That and the cog I start with the GPS_IO_mini_PNAV object regarding the GPS_stack variable.· I just don't know and I am getting depressed and code tired (it all looks the same)!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-23 23:10
    Running multiple FSD objects by itself doesn't cause any memory stomping. Each instance has its own variable area.

    You need to take a short break, then go through the whole program line by line and use a highlighter for any line that uses a pointer or an array subscript that's not a constant, then go back and stop at each highlighted line and ask yourself whether that line can overstore something that it shouldn't. If so, either insert some kind of consistency check or rewrite that portion of the routine. Get a friend to help you. Sometimes they'll ask the "stupid question" that will identify a piece of broken code. This sounds tedious and it is, but may be the way to get this working.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-23 23:26
    I would take a careful look at this code
        repeat i from 0 to 1
         
           latitude[noparse][[/noparse]i]:=buf[noparse][[/noparse]i]  Put the first two digits of the Latitude into @latitude
      
    !!! does the above repeat finish with i equal to 1 or 2 - you depend on it below, I believe you expect it to be 2
    !!! but I am not sure about this  
      
      d8 := atoi(buf[noparse][[/noparse]2],2) * 100_000 / 6           ' These three lines get the MM and mmmm and convert it to .ddddd 
      d8 += atoi(buf[noparse][[/noparse]5],4) * 10 /6
     
    !!! as I mentioned atoi isn't passing buf addresses
    
      decdd:= num.ToStr(d8,Num#DEC6)       
       
      latitude[noparse][[/noparse]i]:="."
    
     
    !!! comment I made above about what value of i are you expecting. I would use a constant, there isn't a reason to use i here
       
       repeat idx from 1 to 6
         latitude[noparse][[/noparse]idx+2]:=byte[noparse][[/noparse]decdd+idx]  'This finishes the conversion DD.ddddd
    
     
    !!! are you planning on skipping the 1st char in hte returned string from tostr or not
    !!! if not then it should be from 0 to 5 and then the question is what puts the string terminator 0 in the buffer
         
      i:=0
    
    

    As Mike says I would walk through this code with a specific example, writing down what you expect each buffer to be. If you still can't see the problem, then add print statements of each buffer comparing with what you expect.
  • Sniper KingSniper King Posts: 221
    edited 2008-09-23 23:49
    The bolded area below produces a bunch of jibberish!· This isn't happening here.· But the comparisons to buf work!· the repeat from 0 to 1 does put the fist two bytes that are in buf into @latitude but the debug shows a mess of characters.· With that knowledge, I would think that it was something happening somewhere else at the same time overwriting buf before I can debug it.
      repeat i from 0 to 1
         
           latitude[noparse][[/noparse]i]:=buf[noparse][[/noparse]i]  Put the first two digits of the Latitude into @latitude
       !!! does the above repeat finish with i equal to 1 or 2 - you depend on it below, I believe you expect it to be 2
    !!! but I am not sure about this  
      
      
     
    [b]repeat until I==15[/b]
    [b]   debug.str(Buf(i))[/b]
    [b]   i++[/b]
     
     
     
     
    d8 := atoi(buf[noparse][[/noparse]2],2) * 100_000 / 6           ' These three lines get the MM and mmmm and convert it to .ddddd 
      d8 += atoi(buf[noparse][[/noparse]5],4) * 10 /6
     
    !!! as I mentioned atoi isn't passing buf addresses
    
      decdd:= num.ToStr(d8,Num#DEC6)       
       
      latitude[noparse][[/noparse]i]:="."
    
     
    !!! comment I made above about what value of i are you expecting. I would use a constant, there isn't a reason to use i here
       
       repeat idx from 1 to 6
         latitude[noparse][[/noparse]idx+2]:=byte[noparse][[/noparse]decdd+idx]  'This finishes the conversion DD.ddddd
    
     
    !!! are you planning on skipping the 1st char in hte returned string from tostr or not
    !!! if not then it should be from 0 to 5 and then the question is what puts the string terminator 0 in the buffer
         
      i:=0
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-23 23:55
    debug.str is expecting a memory address of a string, you are passing in each char. i would

     
    repeat j from 0 to 15
      debug.hex(buf[noparse][[/noparse]j], 2)
      debug.tx(" ")
     
    

    and add j to the list of local args. This 1: uses different variables from the code so debug doesn't change the· code behavour and 2: prints the buffer as separate chars in hex (use help->char char ("0" is $32, etc)) so you can see what is happening even if the buffer contains non-printable chars
  • Sniper KingSniper King Posts: 221
    edited 2008-09-24 16:22
    Again, thank you everybody but especially Mike Green and Timmoore!· There was memory stomping when i started this thread.· you guys helped me find this.· The latest problem was not memory related it was the proverbial stupid mistake of parsing the string wrong!· you guys are great!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D

    Check out Project: PSAV Persistent Sailing Autonomous Vehicle
Sign In or Register to comment.