Ejemplo n.º 1
0
	def __init__( self, ais_state ):
		# Find the corresponding message struct and function
		try:
			msg_struct = getattr( aisparser, "aismsg_" + str(ais_state.msgid) )
			msg_func = getattr( aisparser, "parse_ais_" + str(ais_state.msgid) )
			self.data = msg_struct()

			# Parse the message
			msg_func( ais_state, self.data )

			# If this is a message 6 or 8 try to parse the binary message
			if ais_state.msgid in [6,8]:
				ais_msg = self.data
				self.binary_state = aisparser.binary_state()
				self.binary_state.dac = ais_msg.app_id >> 6
				self.binary_state.fi = ais_msg.app_id & 0x3F
				self.binary_state.six_state = ais_msg.data

#				print "dac = %d" % (self.binary_state.dac)
#				print "fi  = %d" % (ord(self.binary_state.fi))
				if self.binary_state.dac in [366,316] and ord(self.binary_state.fi) in [1,2,32,]:
					# Looks like a St. Lawrence Seaway Message
#					print "St. Lawrence Seaway"
					self.seaway_spare = aisparser.get_6bit( self.binary_state.six_state, 2 )
					self.seaway_msgid = aisparser.get_6bit( self.binary_state.six_state, 6 )

					if (ord(self.binary_state.fi),self.seaway_msgid) in [(1,1),(1,2),(1,3),(1,6),(2,1),(2,2),(32,1)]:
						msg_struct = getattr( aisparser, "seaway%d_%d" % (ord(self.binary_state.fi),self.seaway_msgid))
						msg_func = getattr( aisparser, "parse_seaway%d_%d" % (ord(self.binary_state.fi),self.seaway_msgid))
						self.binary_data = msg_struct()
						msg_func( self.binary_state, self.binary_data)
						self.binary_type = "seaway"
					elif (ord(self.binary_state.fi),self.seaway_msgid) in [(1,4),(1,5),(2,3)]:
						msg_struct = getattr( aisparser, "pawss%d_%d" % (ord(self.binary_state.fi),self.seaway_msgid))
						msg_func = getattr( aisparser, "parse_pawss%d_%d" % (ord(self.binary_state.fi),self.seaway_msgid))
						self.binary_data = msg_struct()
						msg_func( self.binary_state, self.binary_data)
						self.binary_type = "seaway"
				elif self.binary_state.dac == 1 and ord(self.binary_state.fi) in [11,12,13,14,15,16,17]:
					# Looks like an IMO message
					msg_struct = getattr( aisparser, "imo%d_%d" % (self.binary_state.dac,ord(self.binary_state.fi)))
					msg_func = getattr( aisparser, "parse_seaway%d_%d" % (self.binary_state.dac,ord(self.binary_state.fi)))
					self.binary_data = msg_struct()
					msg_func( self.binary_state, self.binary_data)
					self.binary_type = "imo"
		except AttributeError:
			self.data = None
			raise
Ejemplo n.º 2
0
    def LoadFile(self):
        """
        Re-Assemble the data into full packets
        """
        # Initialize the AIS Parser class
        ais_state = aisparser.ais_state()


        # Process the whole file
        info = os.stat( self.filename )

        dialog = wx.ProgressDialog("Loading %s" % (self.filename),
                               "Time remaining",
                               info[stat.ST_SIZE],
                               style=wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME)


        ais_file = open( self.filename, "r" )
        old_pos = 0
        while 1:
            line = ais_file.readline().strip()
            if not line:
                break
            pos = ais_file.tell()
            if pos > old_pos + 4e3:
                keepGoing = dialog.Update(pos)
                old_pos = pos

            result = aisparser.assemble_vdm( ais_state, line )
            if result == 0:
                ais_state.msgid = aisparser.get_6bit( ais_state.six_state, 6 )
                ais_state.msg = AisMessage( ais_state )
                if ais_state.msg.data:
                    self.ais_info.append( ais_state )
                # Re-start the parser, creating a new ais_state object
                ais_state = aisparser.ais_state()
        ais_file.close()
        dialog.Destroy()
import aisparser
import fileinput

s=fileinput.input()

#with open('log_ais_web2day.log', 'r') as f:
#	s=f.readlines()

ais_state = aisparser.ais_state()

for p in s:
    result = aisparser.assemble_vdm( ais_state, p )
#    print "%s : %s" % (result, p)
    if( result == 0):
        ais_state.msgid = aisparser.get_6bit( ais_state.six_state, 6 )
#        print "msgid = %d" % (ais_state.msgid)

        if ais_state.msgid == 1:
            msg = aisparser.aismsg_1()
            aisparser.parse_ais_1( ais_state, msg )
            (status,lat_dd,long_ddd) = aisparser.pos2ddd(msg.latitude, msg.longitude)

#            print "%s,%d,%s,%s" % (p[0:19],msg.userid,lat_dd,long_ddd)
#            print "mmsi     : %d" % (msg.userid)
#            print "latitude : %d" % (msg.latitude)
#            print "longitude: %d" % (msg.longitude)
#            print "lat_dd   : %s" % (lat_dd)
#            print "long_ddd : %s" % (long_ddd)
#            print "pos_acc  : %d" % (ord(msg.pos_acc))
Ejemplo n.º 4
0
# Retrieve the last ship info
#last_info = shelve.open( '/tmp/last_ship' )
last_info = {}
last_xml = time.time() - 50

done = 0
try:
    while not done:
        # Read AIS messages from the source
        data = sf.readline()

        # Parse the data
        result = aisparser.assemble_vdm( ais_state, data )
        if( result == 0):
            ais_state.msgid = aisparser.get_6bit( ais_state.six_state, 6 )
            if debug: print "msgid = %d" % (ais_state.msgid)

            # Message 1: Position Update
            if ais_state.msgid == 1:
               msg = aisparser.aismsg_1()
               aisparser.parse_ais_1( ais_state, msg )
               msg.msgid = 1

               if debug:
                   print "msgid    : %d" % (ord(msg.msgid))
                   print "mmsi     : %d" % (msg.userid)
                   print "latitude : %d" % (msg.latitude)
                   print "longitude: %d" % (msg.longitude)

               # Update the ship info