waveshare / L76X-GPS-Module

16 stars 9 forks source link

Large section of L76X_Gat_GNRMC(self) does nothing #3

Open BritishTechGuru opened 2 years ago

BritishTechGuru commented 2 years ago

This section of L76X_Gat_GNRMC(self) never ever executes. The only part that executes is after the except TypeError:

    try:
        for i in range(0, BUFFSIZE-71):
            if(ord(data[add]) == 36 and ord(data[add+1]) == 71 and (ord(data[add+2]) == 78 \
            or ord(data[add+2]) == 80) and ord(data[add+3]) == 82 and ord(data[add+4]) == 77 \
            and ord(data[add+5]) == 67):

end obfuscated section used to find $SGNYRMC

                    print("data printout")
                    print(data)
                    print("end of data prinout")
                    break
                    x = 0
                    z = 0
                    while(x < 12):
                        if(add+z >= BUFFSIZE-1):
                            return
                        if(ord(data[add+z]) == 44):#,
                            x = x + 1
                            if(x == 1):
                                Time = 0
                                for k in range(0, BUFFSIZE-1):
                                    if(add+z+k >= BUFFSIZE-1):
                                        return
                                    if(ord(data[add+z+k+1]) == 44):#,
                                        break
                                    if(ord(data[add+z+k+1]) == 46):#.
                                        break
                                    Time = (ord(data[add+z+k+1]) - 48) + Time*10
                                self.Time_H = Time/10000 + 8
                                self.Time_M = Time/100%100
                                self.Time_S = Time%100
                                if(self.Time_H >= 24):
                                     self.Time_H =  self.Time_H - 24
                            elif(x == 2):
                                if(ord(data[add+z+1]) == 65):#A
                                    self.Status = 1
                                else:
                                    self.Status = 0
                            elif(x == 3):
                                latitude = 0
                                for k in range(0, BUFFSIZE-1):
                                    if(add+z+k >= BUFFSIZE-1):
                                        return
                                    if(ord(data[add+z+k+1]) == 44):#,
                                        break
                                    if(ord(data[add+z+k+1]) == 46):#.
                                        continue
                                    latitude = (ord(data[add+z+k+1]) - 48) + latitude*10
                                self.Lat = latitude / 1000000.0
                            elif(x == 4):
                                self.Lat_area = data[add+z+1]
                            elif(x == 5):
                                longitude = 0
                                for k in range(0, BUFFSIZE-1):
                                    if(add+z+k >= BUFFSIZE-1):
                                        return
                                    if(ord(data[add+z+k+1]) == 44):#,
                                        break
                                    if(ord(data[add+z+k+1]) == 46):#.
                                        continue
                                    longitude = (ord(data[add+z+k+1]) - 48) + longitude*10

                                self.Lon = longitude / 1000000.0
                            elif(x == 6):
                                self.Lon_area = data[add+z+1]
                                return#Completion calculation
                        z = z + 1
            add = add + 1
BritishTechGuru commented 2 years ago

It would be excellent if speed, altitude and direction were reported back. Then it would be really usable code. As it is... It's not that great.

BritishTechGuru commented 2 years ago

Here's a sample of my output

%Run -c $EDITOR_CONTENT $PMTK251,1152001F $PMTK220,4002A $PMTK314,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,029 $PMTK255,12D b'$GNZDA,194050.148,12,07,2022,,4A\r\n$GNRMC,194050.148,A,3348.4428,N,08112.9034,W,0.00,266.92,120722,,,A69\r\n$GNVTG,266.92,T,,M,0.00,N,0.00,K,A2A\r\n$GNGGA,194050.148,3348.4428,N,08112.9034,W,1,8,1.16,162.3,M,-32.2,M,,70\r\n$GPGSA,A,3,02,15,11,13,29,18,05,20,,,,,2.41,1.16,2.11*00\r\n$BDGSA,A,3' def L76X_Gat_GNRMC(self):

Buffer size 1100 /n TypeError just executed The exception 36,71,78/80,82,77,67 just passed Already positioned Time 3: 40 : 50 Lon = 81.129026 Lat = 33.484428 Baidu coordinate 33.811467 ,81.224041 Google coordinate 81.133814 ,33.490543 b'$GNZDA,194054.148,12,07,2022,,4E\r\n$GNRMC,194054.148,A,3348.4428,N,08112.9034,W,0.00,266.92,120722,,,A6D\r\n$GNVTG,266.92,T,,M,0.00,N,0.00,K,A2A\r\n$GNGGA,194054.148,3348.4428,N,08112.9034,W,1,8,1.16,162.3,M,-32.2,M,,74\r\n$GPGSA,A,3,02,15,11,13,29,18,05,20,,,,,2.41,1.16,2.11*00\r\n$BDGSA,A,3' def L76X_Gat_GNRMC(self):

Buffer size 1100 /n TypeError just executed The exception 36,71,78/80,82,77,67 just passed Already positioned Time 3: 40 : 54 Lon = 81.129026 Lat = 33.484428 Baidu coordinate 33.811467 ,81.224041 Google coordinate 81.133814 ,33.490543 b'$GNZDA,194059.348,12,07,2022,,41\r\n$GNRMC,194059.348,A,3348.4428,N,08112.9034,W,0.00,266.92,120722,,,A62\r\n$GNVTG,266.92,T,,M,0.00,N,0.00,K,A2A\r\n$GNGGA,194059.348,3348.4428,N,08112.9034,W,1,8,1.16,162.3,M,-32.2,M,,7B\r\n$GPGSA,A,3,02,15,11,13,29,18,05,20,,,,,2.41,1.16,2.11*00\r\n$BDGSA,A,3' def L76X_Gat_GNRMC(self):

Buffer size 1100 /n TypeError just executed The exception 36,71,78/80,82,77,67 just passed Already positioned Time 3: 40 : 59 Lon = 81.129026 Lat = 33.484428 Baidu coordinate 33.811467 ,81.224041 Google coordinate 81.133814 ,33.490543 b'$GNZDA,194104.148,12,07,2022,,4A\r\n$GNRMC,194104.148,A,3348.4428,N,08112.9034,W,0.00,266.92,120722,,,A69\r\n$GNVTG,266.92,T,,M,0.00,N,0.00,K,A2A\r\n$GNGGA,194104.148,3348.4428,N,08112.9034,W,1,7,1.68,162.3,M,-32.2,M,,76\r\n$GPGSA,A,3,02,15,11,13,29,05,20,,,,,,4.47,1.68,4.14*03\r\n$BDGSA,A,3,,' def L76X_Gat_GNRMC(self):

Buffer size 1100 /n TypeError just executed The exception 36,71,78/80,82,77,67 just passed Already positioned Time 3: 41 : 4 Lon = 81.129026 Lat = 33.484428 Baidu coordinate 33.811467 ,81.224041 Google coordinate 81.133814 ,33.490543

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── MicroPython v1.19.1 on 2022-06-18; Raspberry Pi Pico with RP2040 Type "help()" for more information.

BritishTechGuru commented 2 years ago

I fixed the problems in the code. I suggest you look here: https://github.com/BritishTechGuru/PI-Pico-L76B

gcd0318 commented 8 months ago

This section of L76X_Gat_GNRMC(self) never ever executes. The only part that executes is after the except TypeError:

    try:
        for i in range(0, BUFFSIZE-71):
            if(ord(data[add]) == 36 and ord(data[add+1]) == 71 and (ord(data[add+2]) == 78 \
            or ord(data[add+2]) == 80) and ord(data[add+3]) == 82 and ord(data[add+4]) == 77 \
            and ord(data[add+5]) == 67):

end obfuscated section used to find $SGNYRMC

                    print("data printout")
                    print(data)
                    print("end of data prinout")
                    break
                    x = 0
                    z = 0
                    while(x < 12):
                        if(add+z >= BUFFSIZE-1):
                            return
                        if(ord(data[add+z]) == 44):#,
                            x = x + 1
                            if(x == 1):
                                Time = 0
                                for k in range(0, BUFFSIZE-1):
                                    if(add+z+k >= BUFFSIZE-1):
                                        return
                                    if(ord(data[add+z+k+1]) == 44):#,
                                        break
                                    if(ord(data[add+z+k+1]) == 46):#.
                                        break
                                    Time = (ord(data[add+z+k+1]) - 48) + Time*10
                                self.Time_H = Time/10000 + 8
                                self.Time_M = Time/100%100
                                self.Time_S = Time%100
                                if(self.Time_H >= 24):
                                     self.Time_H =  self.Time_H - 24
                            elif(x == 2):
                                if(ord(data[add+z+1]) == 65):#A
                                    self.Status = 1
                                else:
                                    self.Status = 0
                            elif(x == 3):
                                latitude = 0
                                for k in range(0, BUFFSIZE-1):
                                    if(add+z+k >= BUFFSIZE-1):
                                        return
                                    if(ord(data[add+z+k+1]) == 44):#,
                                        break
                                    if(ord(data[add+z+k+1]) == 46):#.
                                        continue
                                    latitude = (ord(data[add+z+k+1]) - 48) + latitude*10
                                self.Lat = latitude / 1000000.0
                            elif(x == 4):
                                self.Lat_area = data[add+z+1]
                            elif(x == 5):
                                longitude = 0
                                for k in range(0, BUFFSIZE-1):
                                    if(add+z+k >= BUFFSIZE-1):
                                        return
                                    if(ord(data[add+z+k+1]) == 44):#,
                                        break
                                    if(ord(data[add+z+k+1]) == 46):#.
                                        continue
                                    longitude = (ord(data[add+z+k+1]) - 48) + longitude*10

                                self.Lon = longitude / 1000000.0
                            elif(x == 6):
                                self.Lon_area = data[add+z+1]
                                return#Completion calculation
                        z = z + 1
            add = add + 1

In fact it works if serial port returned valid data. But in most cases no valid data read via serial. But it is really odd that, serial is sending valid gps data all time. I'm not sure it were caused by pyserial, maybe bugs or some wrong configuration.

BritishTechGuru commented 8 months ago

One day I will return to this code. For the moment what I have works. The Waveshare people rewrote their code after I took their god-awful code and reworked it to be functional. They still have 4 program files where I think the whole lot would be better as one file and very few lines of code.

I have not tried yet - I have somany other things on my plate but.... The L76 is sending packets of data continually so the necessities would be open the port set the buffer size fill the buffer from the port deal with the buffered data.

I don't see that opening a port and filling a buffer with data needs to take up 3 separate code files or indeed as much code as Waveshare gives us. When I rewrote their awful program, I cut 200 lines of nonsense out.

The problem as I see it with the original code - somebody was trying to show off and make out they were a better coder than they were. Small is beautiful with code.

The only reason I have not delved deeper is what's there seems to work and I'm on other priojects right now.