NMEA句子带有意外字符

问题描述

我正在使用python通过树莓派上的i2c从u-blox NEO-M9N芯片读取数据。

目前,我还没有构建脚本的其余部分,但是我对芯片的输出有些困惑,因为它似乎包含了不属于该芯片的个字符,例如 °,¬或Á。有时,这些字符似乎可以代替看起来相似的字符: 021120在几行中是正确的,然后由距离不远的0²1±20 代替。

对于5到50行之间的句子,句子可能都是正确的,然后我会得到类似的信息(我已经用X代替了GPS坐标的一部分,但是你明白了):

$GNRMC,204107.00,A,XX.20¶46,N,XX.47371,E,0.844,021±20,V*17
$GNRMC,204108.00¬A,XX.20603,XX.47454,0.921,021120,V*1B

您知道这可能是什么原因吗?我非常确定,这以后会弄乱我想要的数据...


这是我用来读取数据的代码:

import time
import json
import smbus
import logging 

BUS = None
address = 0x42
gpsReadInterval = 0.1
LOG = logging.getLogger()

# taken and (poorly) adapted from
# http://ava.upuaut.net/?p=768

def connectBus():
    global BUS
    BUS = smbus.SMBus(1)

def parseResponse(gpsLine):
    gpsChars = ''.join(chr(c) for c in gpsLine)
    if "GNRMC" not in gpsChars:
        return False
    
    print(gpsChars)

def readGPS():
    c = None
    response = []
    try:
        while True: # Newline,or bad char.
            c = BUS.read_byte(address)
            if c == 255:
                return False
            elif c == 10:
                break
            else:
                response.append(c)
        parseResponse(response)
    except IOError:
        time.sleep(0.5)
        connectBus()

connectBus()
while True:
    readGPS()
    time.sleep(gpsReadInterval)

解决方法

为了后人,有人帮我解决了:Fix special characters with closest equivalent without map

这确实是硬件问题,但可以使用此人的答案通过软件修复

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...