Continuation from cog31s GPS issue.
| Author | Message | ||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6543 |
Don't know what happend to my first post and not able to edit it. Most of the time your tfrgps sub runs without being interrupted by the serial routine. When it DOES coincide, you notice the longer times. I added a global counter to record the number of calls to the spcomrec4 sub during the tfrgps sub and added the count to the printout. This was run on an explore64 and a real GPS. It is likely that my GPS is configured differently to yours so I would expect some variation but it does suggest that the timing differences you see are caused by the program flow, not an underlining problem with MMBasic. Modified program: OPTION EXPLICIT OPTION AUTORUN ON CONST top1s=31 '16 CONST cnbcde = 3 CONST cnbch = 18 CONST cnbbuf = 10 CONST ccptvdg = 5 'comptage nb sec sans reception com CONST maxto = 500 'ex ime out 5 sec DIM i AS INTEGER DIM i1 AS INTEGER DIM i2 AS INTEGER DIM intCall AS INTEGER DIM tmcde(cnbcde) AS STRING LENGTH 3 DIM nbcde AS INTEGER DIM tmgps(cnbcde,cnbch) AS STRING LENGTH 20 DIM nbgps(cnbcde) AS INTEGER DIM ptcde AS INTEGER DIM ptgps AS INTEGER DIM flggps(cnbbuf) AS INTEGER DIM txcrc AS STRING DIM nbcar AS INTEGER DIM cptm3 AS INTEGER DIM cptvdg AS INTEGER DIM ptime1 AS FLOAT DIM ptime2 AS FLOAT DIM validgps AS INTEGER DIM tmbuf(cnbbuf) AS STRING DIM flgtmbuf(cnbbuf) AS INTEGER DIM ptWrite AS INTEGER DIM ptRead AS INTEGER DIM txbufgps AS STRING DIM txchamp AS STRING DIM flgf AS INTEGER i=0 i=i+1:tmcde(i)="GGA" i=i+1:tmcde(i)="GSA" i=i+1:tmcde(i)="RMC" nbcde=i txbufgps="" flgf=0 OPEN "COM1:9600,255,spcomrec4" AS #2 ptWrite=0 ptRead=0 FOR i=1 TO cnbbuf tmbuf(i)="" flgtmbuf(i)=0 NEXT i '***************************** DO ptime1=TIMER intCall = 0 tfrgps ptime2=TIMER IF ptime2-ptime1>50 THEN PRINT TIME$;" ->";STR$((ptime2-ptime1)/1000,4,3);" ";STR$(intCall) END IF PAUSE(10) LOOP '***************************** SUB tfrgps() 'store in database LOCAL txt AS STRING LOCAL flgg AS INTEGER FOR i=1 TO cnbbuf ptRead=ptRead+1 IF ptRead>cnbbuf THEN ptRead=1 IF flgtmbuf(ptRead)=0 THEN EXIT FOR IF flgtmbuf(ptRead)=2 THEN txt=tmbuf(ptRead) spgps(txt,flgg) IF flgg>0 THEN flgtmbuf(ptRead)=0 calccrc2(txt) IF (validgps AND 16)=16 THEN rangegps(txt,flgg) END IF END IF END IF NEXT i END SUB SUB calccrc2(txc AS STRING) LOCAL jc AS INTEGER LOCAL ic AS INTEGER LOCAL i3 AS INTEGER jc=INSTR(txc,"*") IF jc>2 THEN ic=0 FOR i3=2 TO jc-1 ic=ic XOR ASC(MID$(txc,i3,1)) NEXT i3 END IF txcrc=HEX$(ic) IF LEN(txcrc)=1 THEN txcrc="0"+txcrc IF txcrc=RIGHT$(txc,2) THEN validgps=(validgps OR 16) ELSE validgps=(validgps AND &hEF ) PRINT txc PRINT txcrc;"<>";RIGHT$(txc,2) END IF END SUB SUB spgps(txg AS STRING, ergp AS INTEGER) LOCAL i AS INTEGER ergp=0 FOR i=1 TO nbcde IF MID$(txg,4,3)=tmcde(i) THEN 'for gps($gp) or glosnass($gn) frames ergp=i EXIT FOR END IF NEXT i END SUB SUB rangegps(txcrc AS STRING, flge AS INTEGER) LOCAL b$ AS STRING LENGTH 1 IF LEFT$(txcrc,1)="$" THEN ptgps=0 ptcde=flge txchamp="" FOR i2=1 TO LEN(txcrc) b$=MID$(txcrc,i2,1) IF b$="," THEN ptgps=ptgps+1 tmgps(ptcde,ptgps)=txchamp txchamp="" ELSE IF ASC(b$)>31 THEN txchamp=txchamp+b$ END IF NEXT i2 ptgps=ptgps+1 IF ptgps<=cnbch THEN tmgps(ptcde,ptgps)=txchamp END IF flggps(ptcde)=2 nbgps(ptcde)=ptgps END IF END SUB SUB spcomrec4 LOCAL tx$ AS STRING 'length 3 LOCAL i1 AS INTEGER LOCAL i2 AS INTEGER LOCAL a$ AS STRING LENGTH 1 LOCAL vai AS INTEGER intCall = intCall + 1 i1=LOC(#2) IF i1=0 THEN EXIT SUB ELSE tx$=INPUT$(i1,#2) FOR i2=1 TO i1 a$=MID$(tx$,i2,1) vai=ASC(a$) IF a$="$" THEN ptWrite=ptWrite+1 IF ptWrite>cnbbuf THEN ptWrite=1 tmbuf(ptWrite)="" flgtmbuf(ptWrite)=1 END IF IF vai=10 THEN flgtmbuf(ptWrite)=2 ELSE IF vai>31 THEN tmbuf(ptWrite)=tmbuf(ptWrite)+a$ END IF NEXT i2 ENDIF END SUB VK7JH MMedit |
||||