When method calls fail... *** RESOLVED!
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
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 returnpub 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
·
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
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
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!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
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
Which particular variables are being over-written ? That could give a better idea of where to look.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle
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
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
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.
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:=0As 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.
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··
Michael King
Application Engineer
R&D
Check out Project: PSAV Persistent Sailing Autonomous Vehicle