Compare Nmea line in a single file

15 views Asked by At

i hope you can help me. I have a NMEA File that contain a lot of string information.Mainly it contain GNGGA and GNRMC information.

Many lines as this:

<NMEA(GNRMC, time=03:39:08.500000, status=A, lat=22.5722731667, NS=N, lon=114.0783976667, EW=E, spd=27.252, cog=92.02, date=2021-06-29, mv=, mvEW=, posMode=D, navStatus=V)>

<NMEA(GNGGA, time=03:39:08.500000, lat=22.5722731667, NS=N, lon=114.0783976667, EW=E, quality=2, numSV=12, HDOP=0.77, alt=34.4, altUnit=M, sep=-2.3, sepUnit=M, diffAge=1.5, diffStation=3740)>

Everytime i have no information which the file cointain it before, it can be RMC or GGA. What i need: Find the first GGA or RMC. If the first in the file is GGA then i should take the timestamp and scroll again the file for the first RMC with the same timestamp. In case the first in the file is the RMC i should do the same. Then if the status == A in RMC then i should take all the coordinated from the GGA

I have to plot the latitude and longitude from GGA just when at the same time in RMC the coordinated are labeled as valid so when status=A.

inp=open(r"C:\Users\temp.txt",'r')
for line in inp:
    if line.startswith('<NMEA(GNRMC'):
        rmc_rt=line.split(",")
        TimeRMC = rmc_rt[1].partition("time=")
        Status=rmc_rt[2].partition("status=")
        for line2 in inp:
            if line2.startswith('<NMEA(GNGGA'):
                rt=line2.split(",")
                Time = rt[1].partition("time=")
                if (str(Time[2]) == str(TimeRMC[2])):
                    Lat = rt[2].partition("lat=")
                    Lon = rt[4].partition("lon=")
                    print(line)
                    print(line2)

As last thing could be that the number of GGA is less then number of lines of RMC.So i should avoid any index error.

i tried this code but for some reason it print just the first line it found:

<NMEA(GNRMC, time=03:39:08.500000, status=A, lat=22.5722731667, NS=N, lon=114.0783976667, EW=E, spd=27.252, cog=92.02, date=2021-06-29, mv=, mvEW=, posMode=D, navStatus=V)>

<NMEA(GNGGA, time=03:39:08.500000, lat=22.5722731667, NS=N, lon=114.0783976667, EW=E, quality=2, numSV=12, HDOP=0.77, alt=34.4, altUnit=M, sep=-2.3, sepUnit=M, diffAge=1.5, diffStation=3740)>

It is missing all other lines that respect this condition.

0

There are 0 answers