L76X-GPS-Module icon indicating copy to clipboard operation
L76X-GPS-Module copied to clipboard

Large section of L76X_Gat_GNRMC(self) does nothing

Open BritishTechGuru opened this issue 3 years ago • 12 comments

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 avatar Jul 12 '22 19:07 BritishTechGuru

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 avatar Jul 12 '22 19:07 BritishTechGuru

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,A*2A\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.1100\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,A*2A\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.1100\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,A*2A\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.1100\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,A*2A\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.1403\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 avatar Jul 12 '22 19:07 BritishTechGuru

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

BritishTechGuru avatar Jul 17 '22 19:07 BritishTechGuru

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.

gcd0318 avatar Dec 25 '23 16:12 gcd0318

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.

BritishTechGuru avatar Dec 26 '23 13:12 BritishTechGuru

Hi @BritishTechGuru ,

I'm a waveshare developer, and I don't like redundant code either, so I took a little time to write the following code about LC76G , which works on Raspberry PI 5 via i2c, maybe you can use the I2C of the LC76G module, I don't know if you have this module and of course I simply borrowed code from previous developers. raspberrypi5_i2c_lc76g.zip

In fact, the NMEA data for the L76X can be parsed using existing libraries like pynmea2(though I didn't test for compatibility on pico).

At present, I only focus on I2C nmea data acquisition. In my opinion, the form of UART only needs to receive the transmitted data through the UART serial port and analyze it,So I only need to get the NMEA raw data, the rest is only analysis, my method is to use the existing library analysis. If you have the idea of using UART to get better parsing results, feel free to share with me.I can provide the code I did a long time ago, which is very simple: UART takes the NMEA data frame and parses it into useful data using the parsing library. (I used some 5G modules with GNSS functionality and i did the code when I was not working for waveshare)

If you are interested in uart parsing code, maybe I can also write a simple example.

For the record, I am only interested in GNSS mods like l76g, l76x, etc. I want to help, I am not the maintainer of the project

Y1hsiaochunnn avatar Dec 20 '24 08:12 Y1hsiaochunnn

Hi @BritishTechGuru ,

I'm a waveshare developer, and I don't like redundant code either, so I took a little time to write the following code about LC76G , which works on Raspberry PI 5 via i2c, maybe you can use the I2C of the LC76G module, I don't know if you have this module and of course I simply borrowed code from previous developers. raspberrypi5_i2c_lc76g.zip

In fact, the NMEA data for the L76X can be parsed using existing libraries like pynmea2(though I didn't test for compatibility on pico).

At present, I only focus on I2C nmea data acquisition. In my opinion, the form of UART only needs to receive the transmitted data through the UART serial port and analyze it,So I only need to get the NMEA raw data, the rest is only analysis, my method is to use the existing library analysis. If you have the idea of using UART to get better parsing results, feel free to share with me.I can provide the code I did a long time ago, which is very simple: UART takes the NMEA data frame and parses it into useful data using the parsing library. (I used some 5G modules with GNSS functionality and i did the code when I was not working for waveshare)

If you are interested in uart parsing code, maybe I can also write a simple example.

For the record, I am only interested in GNSS mods like l76g, l76x, etc. I want to help, I am not the maintainer of the project

Just noticed and I'm pretty interested with this. Maybe take a try after traditional new year holiday

Looks good

gcd0318 avatar Jan 22 '25 13:01 gcd0318

Hi @BritishTechGuru ,

I'm a waveshare developer, and I don't like redundant code either, so I took a little time to write the following code about LC76G , which works on Raspberry PI 5 via i2c, maybe you can use the I2C of the LC76G module, I don't know if you have this module and of course I simply borrowed code from previous developers. raspberrypi5_i2c_lc76g.zip

In fact, the NMEA data for the L76X can be parsed using existing libraries like pynmea2(though I didn't test for compatibility on pico).

At present, I only focus on I2C nmea data acquisition. In my opinion, the form of UART only needs to receive the transmitted data through the UART serial port and analyze it,So I only need to get the NMEA raw data, the rest is only analysis, my method is to use the existing library analysis. If you have the idea of using UART to get better parsing results, feel free to share with me.I can provide the code I did a long time ago, which is very simple: UART takes the NMEA data frame and parses it into useful data using the parsing library. (I used some 5G modules with GNSS functionality and i did the code when I was not working for waveshare)

If you are interested in uart parsing code, maybe I can also write a simple example.

For the record, I am only interested in GNSS mods like l76g, l76x, etc. I want to help, I am not the maintainer of the project

I was happy with my code for reading the sentences from the incoming data. That seemed to work. GNSS just seemed to update far less frequently than GPS which is partly why I used GPS only. A more interesting development would be a code modification that would allow the reading of Galileo data though that might also need a different receiver module.

Ideally I'd like to see all of the code in a single block without any extra libraries.

BritishTechGuru avatar Jan 22 '25 23:01 BritishTechGuru

Just noticed and I'm pretty interested with this. Maybe take a try after traditional new year holiday

Looks good

I would love to see your take on it too :)

BritishTechGuru avatar Jan 22 '25 23:01 BritishTechGuru

Hi @BritishTechGuru @gcd0318 ,

As I said before, regardless of any GNSS module that supports multi-satellite systems such as GPS, Galileo, Beidou, etc. (these need to be checked), they will have a default acquisition rate such as 1 second and then output from UART by default. This acquisition rate could theoretically be adjusted by writing some kind of instruction, but I didn't go into this part to know if it was possible. Another option is to use i2c active queries, such as the one provided above.

Whatever it is, the GNSS module will output the standard NMEA data frame, which may be GPS, Galileo or Beidou. At this time, it can be parsed according to the data frame you need. Of course, you can write a string of algorithms to calculate it by yourself, but I use the NMEA parsing library, which is more convenient. If you want to go deeper into the parsing step, why not refer to the source code of these parsing libraries? As mentioned earlier with code redundancy, using an existing parsing library is a clean and sensible choice. Of course, everyone has different opinions

Y1hsiaochunnn avatar Jan 23 '25 03:01 Y1hsiaochunnn

By the way, if you focus on speed, I suggest to actively query through i2c. At present, I don't know what the limit of i2c is, but I confirmed with my colleagues that the positioning frequency of the GNSS module is adjustable by means of writing instructions.

I tried to grab the i2c logic and use a logic analyzer to analyze it, which was fast enough for use.

A lot of the configuration can be seen by querling the GNSS module datasheet, which is very useful.

Waveshare sample program will not do all these functions well Interface, usually how the customer needs to use how to adjust, if you encounter difficulties, ask for their assistance, they will answer Image

Y1hsiaochunnn avatar Jan 23 '25 03:01 Y1hsiaochunnn

By the way, if you focus on speed, I suggest to actively query through i2c. At present, I don't know what the limit of i2c is, but I confirmed with my colleagues that the positioning frequency of the GNSS module is adjustable by means of writing instructions.

I tried to grab the i2c logic and use a logic analyzer to analyze it, which was fast enough for use.

A lot of the configuration can be seen by querling the GNSS module datasheet, which is very useful.

Waveshare sample program will not do all these functions well Interface, usually how the customer needs to use how to adjust, if you encounter difficulties, ask for their assistance, they will answer Image

That looks interesting. It's a project that I'll probably return to at some point.

BritishTechGuru avatar Mar 25 '25 23:03 BritishTechGuru