Package ais :: Module merge5
[hide private]
[frames] | no frames]

Source Code for Module ais.merge5

 1  #!/usr/bin/env python 
 2   
 3  # FIX: should just keep a set and output the uniq strings... no? 
 4   
 5  import sys 
 6   
 7  import binary, aisstring 
 8  import ais_msg_5 as m5 
 9  #print '#' , sys.argv[1] 
10   
11  if __name__=='__main__': 
12      print '# UserID, IMOnumber, callsign, name' 
13   
14      line1 = None 
15      for line in file(sys.argv[1]): 
16          #print 'line', line, 
17          #print 'line1',line1 
18          if line1==None: 
19              f1 = line.split(',') 
20              if len(f1) < 6:  
21                  print 'too short' 
22                  continue # bad line? 
23              if f1[2] != '1':  
24                  print 'was not 1',f1[2] 
25                  continue # must be the start of a group 
26              line1 = f1[5] 
27           
28              continue 
29          f2 = line.split(',') 
30          if f2[2] != '2':  
31              print 'bad line',line 
32              line1 = None 
33              continue # must be the 2nd half of a group 
34          nmeapayload = line1 + f2[5] 
35          line1=None 
36   
37          #print nmeapayload 
38   
39          bv = binary.ais6tobitvec(nmeapayload) 
40          print str(m5.decodeUserID(bv))+','+str(m5.decodeIMOnumber(bv))+','+aisstring.unpad(m5.decodecallsign(bv))+','+aisstring.unpad(m5.decodename(bv)) 
41