Exemplo n.º 1
0
  def decode_nmea(self, strings):
    for msg in strings:
      msg_dict = ais_nmea_regex.search(msg).groupdict()
      if msg_dict['checksum'] != nmea_checksum_hex(msg):
        raise AisUnpackingException('Checksum failed')
    try:
      msgs = [ais_nmea_regex.search(line).groupdict() for line in strings]
    except AttributeError:
      raise AisUnpackingException('One or more NMEA lines were malformed (1)')
    if None in msgs:
      raise AisUnpackingException('Failed to parse message.')

    bits = []
    for msg in msgs:
      msg['fill_bits'] = int(msg['fill_bits'])
      bv = binary.ais6tobitvec(msg['body'])
      if int(msg['fill_bits']) > 0:
        bv = bv[:-msg['fill_bits']]
      bits.append(bv)
    bits = binary.joinBV(bits)
    self.decode_bits(bits)
Exemplo n.º 2
0
        buf = StringIO.StringIO()
        for field in options.fieldList:
            buf.write(field + ',')
        result = buf.getvalue()
        if result[-1] == ',': print result[:-1]
        else: print result

    if options.doDecode:
        if len(args) == 0: args = sys.stdin
        for msg in args:
            bv = None

            if msg[0] in ('$', '!') and msg[3:6] in ('VDM', 'VDO'):
                # Found nmea
                # FIX: do checksum
                bv = binary.ais6tobitvec(msg.split(',')[5])
            else:  # either binary or nmeapayload... expect mostly nmeapayloads
                # assumes that an all 0 and 1 string can not be a nmeapayload
                binaryMsg = True
                for c in msg:
                    if c not in ('0', '1'):
                        binaryMsg = False
                        break
                if binaryMsg:
                    bv = BitVector(bitstring=msg)
                else:  # nmeapayload
                    bv = binary.ais6tobitvec(msg)

            params = decode(bv)
            #print 'params:',params
            printFields(params,
Exemplo n.º 3
0
		buf = StringIO.StringIO()
		for field in options.fieldList:
			buf.write(field+',')
		result = buf.getvalue()
		if result[-1] == ',': print result[:-1]
		else: print result

	if options.doDecode:
		if len(args)==0: args = sys.stdin
		for msg in args:
			bv = None

			if msg[0] in ('$','!') and msg[3:6] in ('VDM','VDO'):
				# Found nmea
				# FIX: do checksum
				bv = binary.ais6tobitvec(msg.split(',')[5])
			else: # either binary or nmeapayload... expect mostly nmeapayloads
				# assumes that an all 0 and 1 string can not be a nmeapayload
				binaryMsg=True
				for c in msg:
					if c not in ('0','1'):
						binaryMsg=False
						break
				if binaryMsg:
					bv = BitVector(bitstring=msg)
				else: # nmeapayload
					bv = binary.ais6tobitvec(msg)

			printFields(decode(bv)
				    ,out=outfile
				    ,format=options.outputType
Exemplo n.º 4
0
def decode_aivdm(msg):
    bv = binary.ais6tobitvec(msg.split(',')[5])
    print decode(bv)
Exemplo n.º 5
0
from BitVector import BitVector
import binary
import ais_msg_1, ais_msg_8
import sls.waterlevel

if __name__=='__main__':

    # Try to parse some binary message
    if False:
        #nmeaStr='!BSVDM,1,1,,A,85MwpwQKf22M=5KEn7IONkp9nkF5PtBao=COt6;QOuwk82>:tltI,0*01,r003669717,1165850285'
	nmeaStr='!AIVDM,1,1,,A,85OpLV1Kf98p96dWWPLSViUfJlU@SV>cDF2Wq5>`=u8CnEFGCIOq,0*70,r003669983,1165795916'

	msgPayload = nmeaStr.split(',')[5]
	print 'nmea string:    ',nmeaStr
	print 'message payload:',msgPayload
	bv = binary.ais6tobitvec(msgPayload)
	print len(bv), bv

	msgDict = ais_msg_8.bin_broadcastDecode(bv)
	ais_msg_8.bin_broadcastPrintFields(msgDict)

	bv = bv[39:]

	print               'dac: ',bv[:10],int(bv[:10])
	bv = bv[10:]; print 'fid: ',bv[: 6],int(bv[: 6])
	bv = bv[ 6:]; print 'bits:',bv[:16],int(bv[:10])
	bv = bv[10:]; print 'len: ',len(bv)

    # Position message
    if False:
	nmeaStr = '!AIVDM,1,1,,B,15Mt9B001;rgAFhGKLaRK1v2040@,0*2A'
Exemplo n.º 6
0
def decode_aivdm(msg):
    bv = binary.ais6tobitvec(msg.split(',')[5])
    print decode(bv)
Exemplo n.º 7
0
Run a water level message from NMEA to decoded
'''

import sys
from BitVector import BitVector
import binary
import ais_msg_8
#import sls.header
import sls.waterlevel

if __name__=='__main__':

    print 'FIX: broken'
    vdm='!AIVDM,1,1,4,A,8030ot1?0@>PSpPPPC<2<oURAU=>T08f@02PSpPPP3C3<oU=d5<U00BH@02PSpPPP3C3EoU:A5<TwPPO@02PSpPPP2hk<oRWU5;si0Pl@02O<0PPPP3D<oPPEU;M418g@02PSpPPP2hlEoRQgU;j@17p@00,2*32'
    msg=vdm.split(',')[5]
    bvMsg = binary.ais6tobitvec(msg)

    msg8 = ais_msg_8.decode(bvMsg)
    bvMsg8 = msg8['BinaryData']
    del msg8['BinaryData']
    ais_msg_8.printFields(msg8)

    print

    # Now deal with the St Lawrence Seaway Header
    slsHdr = sls_header.decode(bvMsg8)
    bvHdr = slsHdr['BinaryData']
    del slsHdr['BinaryData']
    sls_header.printFields(slsHdr)

    #print slsHdr.keys()