schwehr / libais

C++ decoder for Automatic Identification System for tracking ships and decoding maritime information
Other
215 stars 94 forks source link

A lot of errors #199

Open klint-k opened 4 years ago

klint-k commented 4 years ago

I found two file on the internet. nmea_data_sample.txt nmea_sample.txt

it wound up with about a lot of errors. The out up dict is large. This is a link for the dict that i got changed to a file. https://github.com/klint-k/pynmea2_errors/blob/master/bad_vdm.txt

The script that i wrote:

with open('nmea-sample.txt','rt') as file_obj:
    nmea_obj = file_obj.readlines()

with open('nmea_data_sample.txt','rt') as file_obj:
    nmea_obj += file_obj.readlines()

bad = {}

for k in nmea_obj:
    t = k.split(',')
    #print()
    if t[-1] == '0*26\n' or t[-1] == '0*25\n':
        pass
##    elif t[0] != "!AIVDM":
##        print(t)
##        pass
    elif t[0][3:] != "VDM":
        print(t[0][3:])
        pass
    elif t[1] == '1':
        #print(t)
        try:
            x = ais.decode(t[-2], 0)
            #print(x)
        except _ais.DecodeError:
            try:
                x = ais.decode(t[-2], 1)
                #print(x)
            except _ais.DecodeError:
                try:
                    x = ais.decode(t[-2], 3)
                    #print(x)
                except Exception as e:
                    bad[k] = e
                    print(e)
                    pass
        except Exception as e:
            bad[k] = e
            print(e)
        else:
            for i in x:
                #print('%s: %s' % (i, x[i]))
                pass
    elif t[1] == '2' and t[2] == '1':
        store = t
    elif t[1] == '2' and t[2] == '2':
        try:
            #store += t
            #print(store)
            #print(t)
            x = ais.decode(store[-2] + t[-2], 2)
            #print(x)
        except Exception as e:
            bad[str(k) + str(store)] = e
            #bad.append(store)
            #bad.append(t)
            print(e)
        else:
            for i in x:
                #print('%s: %s' % (i, x[i]))
                pass
            store = ''