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

Source Code for Module ais.ais_msg_18

   1  #!/usr/bin/env python 
   2   
   3  __version__ = '$Revision: 4791 $'.split()[1] 
   4  __date__ = '$Date: 2008-01-09 $'.split()[1] 
   5  __author__ = 'xmlbinmsg' 
   6   
   7  __doc__=''' 
   8   
   9  Autogenerated python functions to serialize/deserialize binary messages. 
  10   
  11  Generated by: ./aisxmlbinmsg2py.py 
  12   
  13  Need to then wrap these functions with the outer AIS packet and then 
  14  convert the whole binary blob to a NMEA string.  Those functions are 
  15  not currently provided in this file. 
  16   
  17  serialize: python to ais binary 
  18  deserialize: ais binary to python 
  19   
  20  The generated code uses translators.py, binary.py, and aisstring.py 
  21  which should be packaged with the resulting files. 
  22   
  23   
  24  @requires: U{epydoc<http://epydoc.sourceforge.net/>} > 3.0alpha3 
  25  @requires: U{BitVector<http://cheeseshop.python.org/pypi/BitVector>} 
  26   
  27  @author: '''+__author__+''' 
  28  @version: ''' + __version__ +''' 
  29  @var __date__: Date of last svn commit 
  30  @undocumented: __version__ __author__ __doc__ parser 
  31  @status: under development 
  32  @license: Generated code has no license 
  33  @todo: FIX: put in a description of the message here with fields and types. 
  34  ''' 
  35   
  36  import sys 
  37  from decimal import Decimal 
  38  from BitVector import BitVector 
  39   
  40  import binary, aisstring 
  41   
  42  # FIX: check to see if these will be needed 
  43  TrueBV  = BitVector(bitstring="1") 
  44  "Why always rebuild the True bit?  This should speed things up a bunch" 
  45  FalseBV = BitVector(bitstring="0") 
  46  "Why always rebuild the False bit?  This should speed things up a bunch" 
  47   
  48   
  49  fieldList = ( 
  50          'MessageID', 
  51          'RepeatIndicator', 
  52          'UserID', 
  53          'Reserved1', 
  54          'SOG', 
  55          'PositionAccuracy', 
  56          'longitude', 
  57          'latitude', 
  58          'COG', 
  59          'TrueHeading', 
  60          'TimeStamp', 
  61          'RegionalReserved', 
  62          'Spare', 
  63          'RAIM', 
  64          'CommStateSelector', 
  65          'CommState', 
  66  ) 
  67   
  68  fieldListPostgres = ( 
  69          'MessageID', 
  70          'RepeatIndicator', 
  71          'UserID', 
  72          'Reserved1', 
  73          'SOG', 
  74          'PositionAccuracy', 
  75          'Position',     # PostGIS data type 
  76          'COG', 
  77          'TrueHeading', 
  78          'TimeStamp', 
  79          'RegionalReserved', 
  80          'Spare', 
  81          'RAIM', 
  82          'CommStateSelector', 
  83          'CommState', 
  84  ) 
  85   
  86  toPgFields = { 
  87          'longitude':'Position', 
  88          'latitude':'Position', 
  89  } 
  90  ''' 
  91  Go to the Postgis field names from the straight field name 
  92  ''' 
  93   
  94  fromPgFields = { 
  95          'Position':('longitude','latitude',), 
  96  } 
  97  ''' 
  98  Go from the Postgis field names to the straight field name 
  99  ''' 
 100   
 101  pgTypes = { 
 102          'Position':'POINT', 
 103  } 
 104  ''' 
 105  Lookup table for each postgis field name to get its type. 
 106  ''' 
 107   
108 -def encode(params, validate=False):
109 '''Create a positionb binary message payload to pack into an AIS Msg positionb. 110 111 Fields in params: 112 - MessageID(uint): AIS message number. Must be 18 (field automatically set to "18") 113 - RepeatIndicator(uint): Indicated how many times a message has been repeated 114 - UserID(uint): Unique ship identification number (MMSI) 115 - Reserved1(uint): Reseverd for definition by a compentent regional or local authority. Should be set to zero. (field automatically set to "0") 116 - SOG(udecimal): Speed over ground 117 - PositionAccuracy(uint): Accuracy of positioning fixes 118 - longitude(decimal): Location of the vessel East West location 119 - latitude(decimal): Location of the vessel North South location 120 - COG(udecimal): Course over ground 121 - TrueHeading(uint): True heading (relative to true North) 122 - TimeStamp(uint): UTC second when the report was generated 123 - RegionalReserved(uint): Reserved for definition by a regional authority. (field automatically set to "0") 124 - Spare(uint): Not used. Should be set to zero. (field automatically set to "0") 125 - RAIM(bool): Receiver autonomous integrity monitoring flag 126 - CommStateSelector(uint): SOTDMA or ITDMA 127 - CommState(uint): Not decoded by this software yet 128 @param params: Dictionary of field names/values. Throws a ValueError exception if required is missing 129 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. 130 @rtype: BitVector 131 @return: encoded binary message (for binary messages, this needs to be wrapped in a msg 8 132 @note: The returned bits may not be 6 bit aligned. It is up to you to pad out the bits. 133 ''' 134 135 bvList = [] 136 bvList.append(binary.setBitVectorSize(BitVector(intVal=18),6)) 137 if 'RepeatIndicator' in params: 138 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2)) 139 else: 140 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2)) 141 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30)) 142 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),8)) 143 if 'SOG' in params: 144 bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['SOG'])*Decimal('10')))),10)) 145 else: 146 bvList.append(binary.setBitVectorSize(BitVector(intVal=int(1023)),10)) 147 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['PositionAccuracy']),1)) 148 if 'longitude' in params: 149 bvList.append(binary.bvFromSignedInt(int(Decimal(params['longitude'])*Decimal('600000')),28)) 150 else: 151 bvList.append(binary.bvFromSignedInt(108600000,28)) 152 if 'latitude' in params: 153 bvList.append(binary.bvFromSignedInt(int(Decimal(params['latitude'])*Decimal('600000')),27)) 154 else: 155 bvList.append(binary.bvFromSignedInt(54600000,27)) 156 if 'COG' in params: 157 bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['COG'])*Decimal('10')))),12)) 158 else: 159 bvList.append(binary.setBitVectorSize(BitVector(intVal=int(3600)),12)) 160 if 'TrueHeading' in params: 161 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TrueHeading']),9)) 162 else: 163 bvList.append(binary.setBitVectorSize(BitVector(intVal=511),9)) 164 if 'TimeStamp' in params: 165 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TimeStamp']),6)) 166 else: 167 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6)) 168 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4)) 169 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4)) 170 if params["RAIM"]: bvList.append(TrueBV) 171 else: bvList.append(FalseBV) 172 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['CommStateSelector']),1)) 173 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['CommState']),19)) 174 175 return binary.joinBV(bvList)
176
177 -def decode(bv, validate=False):
178 '''Unpack a positionb message 179 180 Fields in params: 181 - MessageID(uint): AIS message number. Must be 18 (field automatically set to "18") 182 - RepeatIndicator(uint): Indicated how many times a message has been repeated 183 - UserID(uint): Unique ship identification number (MMSI) 184 - Reserved1(uint): Reseverd for definition by a compentent regional or local authority. Should be set to zero. (field automatically set to "0") 185 - SOG(udecimal): Speed over ground 186 - PositionAccuracy(uint): Accuracy of positioning fixes 187 - longitude(decimal): Location of the vessel East West location 188 - latitude(decimal): Location of the vessel North South location 189 - COG(udecimal): Course over ground 190 - TrueHeading(uint): True heading (relative to true North) 191 - TimeStamp(uint): UTC second when the report was generated 192 - RegionalReserved(uint): Reserved for definition by a regional authority. (field automatically set to "0") 193 - Spare(uint): Not used. Should be set to zero. (field automatically set to "0") 194 - RAIM(bool): Receiver autonomous integrity monitoring flag 195 - CommStateSelector(uint): SOTDMA or ITDMA 196 - CommState(uint): Not decoded by this software yet 197 @type bv: BitVector 198 @param bv: Bits defining a message 199 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. 200 @rtype: dict 201 @return: params 202 ''' 203 204 #Would be nice to check the bit count here.. 205 #if validate: 206 # assert (len(bv)==FIX: SOME NUMBER) 207 r = {} 208 r['MessageID']=18 209 r['RepeatIndicator']=int(bv[6:8]) 210 r['UserID']=int(bv[8:38]) 211 r['Reserved1']=0 212 r['SOG']=Decimal(int(bv[46:56]))/Decimal('10') 213 r['PositionAccuracy']=int(bv[56:57]) 214 r['longitude']=Decimal(binary.signedIntFromBV(bv[57:85]))/Decimal('600000') 215 r['latitude']=Decimal(binary.signedIntFromBV(bv[85:112]))/Decimal('600000') 216 r['COG']=Decimal(int(bv[112:124]))/Decimal('10') 217 r['TrueHeading']=int(bv[124:133]) 218 r['TimeStamp']=int(bv[133:139]) 219 r['RegionalReserved']=0 220 r['Spare']=0 221 r['RAIM']=bool(int(bv[147:148])) 222 r['CommStateSelector']=int(bv[148:149]) 223 r['CommState']=int(bv[149:168]) 224 return r
225
226 -def decodeMessageID(bv, validate=False):
227 return 18
228
229 -def decodeRepeatIndicator(bv, validate=False):
230 return int(bv[6:8])
231
232 -def decodeUserID(bv, validate=False):
233 return int(bv[8:38])
234
235 -def decodeReserved1(bv, validate=False):
236 return 0
237
238 -def decodeSOG(bv, validate=False):
239 return Decimal(int(bv[46:56]))/Decimal('10')
240
241 -def decodePositionAccuracy(bv, validate=False):
242 return int(bv[56:57])
243
244 -def decodelongitude(bv, validate=False):
245 return Decimal(binary.signedIntFromBV(bv[57:85]))/Decimal('600000')
246
247 -def decodelatitude(bv, validate=False):
248 return Decimal(binary.signedIntFromBV(bv[85:112]))/Decimal('600000')
249
250 -def decodeCOG(bv, validate=False):
251 return Decimal(int(bv[112:124]))/Decimal('10')
252
253 -def decodeTrueHeading(bv, validate=False):
254 return int(bv[124:133])
255
256 -def decodeTimeStamp(bv, validate=False):
257 return int(bv[133:139])
258
259 -def decodeRegionalReserved(bv, validate=False):
260 return 0
261
262 -def decodeSpare(bv, validate=False):
263 return 0
264
265 -def decodeRAIM(bv, validate=False):
266 return bool(int(bv[147:148]))
267
268 -def decodeCommStateSelector(bv, validate=False):
269 return int(bv[148:149])
270
271 -def decodeCommState(bv, validate=False):
272 return int(bv[149:168])
273 274
275 -def printHtml(params, out=sys.stdout):
276 out.write("<h3>positionb</h3>\n") 277 out.write("<table border=\"1\">\n") 278 out.write("<tr bgcolor=\"orange\">\n") 279 out.write("<th align=\"left\">Field Name</th>\n") 280 out.write("<th align=\"left\">Type</th>\n") 281 out.write("<th align=\"left\">Value</th>\n") 282 out.write("<th align=\"left\">Value in Lookup Table</th>\n") 283 out.write("<th align=\"left\">Units</th>\n") 284 out.write("\n") 285 out.write("<tr>\n") 286 out.write("<td>MessageID</td>\n") 287 out.write("<td>uint</td>\n") 288 if 'MessageID' in params: 289 out.write(" <td>"+str(params['MessageID'])+"</td>\n") 290 out.write(" <td>"+str(params['MessageID'])+"</td>\n") 291 out.write("</tr>\n") 292 out.write("\n") 293 out.write("<tr>\n") 294 out.write("<td>RepeatIndicator</td>\n") 295 out.write("<td>uint</td>\n") 296 if 'RepeatIndicator' in params: 297 out.write(" <td>"+str(params['RepeatIndicator'])+"</td>\n") 298 if str(params['RepeatIndicator']) in RepeatIndicatorDecodeLut: 299 out.write("<td>"+RepeatIndicatorDecodeLut[str(params['RepeatIndicator'])]+"</td>") 300 else: 301 out.write("<td><i>Missing LUT entry</i></td>") 302 out.write("</tr>\n") 303 out.write("\n") 304 out.write("<tr>\n") 305 out.write("<td>UserID</td>\n") 306 out.write("<td>uint</td>\n") 307 if 'UserID' in params: 308 out.write(" <td>"+str(params['UserID'])+"</td>\n") 309 out.write(" <td>"+str(params['UserID'])+"</td>\n") 310 out.write("</tr>\n") 311 out.write("\n") 312 out.write("<tr>\n") 313 out.write("<td>Reserved1</td>\n") 314 out.write("<td>uint</td>\n") 315 if 'Reserved1' in params: 316 out.write(" <td>"+str(params['Reserved1'])+"</td>\n") 317 out.write(" <td>"+str(params['Reserved1'])+"</td>\n") 318 out.write("</tr>\n") 319 out.write("\n") 320 out.write("<tr>\n") 321 out.write("<td>SOG</td>\n") 322 out.write("<td>udecimal</td>\n") 323 if 'SOG' in params: 324 out.write(" <td>"+str(params['SOG'])+"</td>\n") 325 if str(params['SOG']) in SOGDecodeLut: 326 out.write("<td>"+SOGDecodeLut[str(params['SOG'])]+"</td>") 327 else: 328 out.write("<td><i>Missing LUT entry</i></td>") 329 out.write("<td>knots</td>\n") 330 out.write("</tr>\n") 331 out.write("\n") 332 out.write("<tr>\n") 333 out.write("<td>PositionAccuracy</td>\n") 334 out.write("<td>uint</td>\n") 335 if 'PositionAccuracy' in params: 336 out.write(" <td>"+str(params['PositionAccuracy'])+"</td>\n") 337 if str(params['PositionAccuracy']) in PositionAccuracyDecodeLut: 338 out.write("<td>"+PositionAccuracyDecodeLut[str(params['PositionAccuracy'])]+"</td>") 339 else: 340 out.write("<td><i>Missing LUT entry</i></td>") 341 out.write("</tr>\n") 342 out.write("\n") 343 out.write("<tr>\n") 344 out.write("<td>longitude</td>\n") 345 out.write("<td>decimal</td>\n") 346 if 'longitude' in params: 347 out.write(" <td>"+str(params['longitude'])+"</td>\n") 348 out.write(" <td>"+str(params['longitude'])+"</td>\n") 349 out.write("<td>degrees</td>\n") 350 out.write("</tr>\n") 351 out.write("\n") 352 out.write("<tr>\n") 353 out.write("<td>latitude</td>\n") 354 out.write("<td>decimal</td>\n") 355 if 'latitude' in params: 356 out.write(" <td>"+str(params['latitude'])+"</td>\n") 357 out.write(" <td>"+str(params['latitude'])+"</td>\n") 358 out.write("<td>degrees</td>\n") 359 out.write("</tr>\n") 360 out.write("\n") 361 out.write("<tr>\n") 362 out.write("<td>COG</td>\n") 363 out.write("<td>udecimal</td>\n") 364 if 'COG' in params: 365 out.write(" <td>"+str(params['COG'])+"</td>\n") 366 out.write(" <td>"+str(params['COG'])+"</td>\n") 367 out.write("<td>degrees</td>\n") 368 out.write("</tr>\n") 369 out.write("\n") 370 out.write("<tr>\n") 371 out.write("<td>TrueHeading</td>\n") 372 out.write("<td>uint</td>\n") 373 if 'TrueHeading' in params: 374 out.write(" <td>"+str(params['TrueHeading'])+"</td>\n") 375 out.write(" <td>"+str(params['TrueHeading'])+"</td>\n") 376 out.write("<td>degrees</td>\n") 377 out.write("</tr>\n") 378 out.write("\n") 379 out.write("<tr>\n") 380 out.write("<td>TimeStamp</td>\n") 381 out.write("<td>uint</td>\n") 382 if 'TimeStamp' in params: 383 out.write(" <td>"+str(params['TimeStamp'])+"</td>\n") 384 if str(params['TimeStamp']) in TimeStampDecodeLut: 385 out.write("<td>"+TimeStampDecodeLut[str(params['TimeStamp'])]+"</td>") 386 else: 387 out.write("<td><i>Missing LUT entry</i></td>") 388 out.write("<td>seconds</td>\n") 389 out.write("</tr>\n") 390 out.write("\n") 391 out.write("<tr>\n") 392 out.write("<td>RegionalReserved</td>\n") 393 out.write("<td>uint</td>\n") 394 if 'RegionalReserved' in params: 395 out.write(" <td>"+str(params['RegionalReserved'])+"</td>\n") 396 out.write(" <td>"+str(params['RegionalReserved'])+"</td>\n") 397 out.write("</tr>\n") 398 out.write("\n") 399 out.write("<tr>\n") 400 out.write("<td>Spare</td>\n") 401 out.write("<td>uint</td>\n") 402 if 'Spare' in params: 403 out.write(" <td>"+str(params['Spare'])+"</td>\n") 404 out.write(" <td>"+str(params['Spare'])+"</td>\n") 405 out.write("</tr>\n") 406 out.write("\n") 407 out.write("<tr>\n") 408 out.write("<td>RAIM</td>\n") 409 out.write("<td>bool</td>\n") 410 if 'RAIM' in params: 411 out.write(" <td>"+str(params['RAIM'])+"</td>\n") 412 if str(params['RAIM']) in RAIMDecodeLut: 413 out.write("<td>"+RAIMDecodeLut[str(params['RAIM'])]+"</td>") 414 else: 415 out.write("<td><i>Missing LUT entry</i></td>") 416 out.write("</tr>\n") 417 out.write("\n") 418 out.write("<tr>\n") 419 out.write("<td>CommStateSelector</td>\n") 420 out.write("<td>uint</td>\n") 421 if 'CommStateSelector' in params: 422 out.write(" <td>"+str(params['CommStateSelector'])+"</td>\n") 423 if str(params['CommStateSelector']) in CommStateSelectorDecodeLut: 424 out.write("<td>"+CommStateSelectorDecodeLut[str(params['CommStateSelector'])]+"</td>") 425 else: 426 out.write("<td><i>Missing LUT entry</i></td>") 427 out.write("</tr>\n") 428 out.write("\n") 429 out.write("<tr>\n") 430 out.write("<td>CommState</td>\n") 431 out.write("<td>uint</td>\n") 432 if 'CommState' in params: 433 out.write(" <td>"+str(params['CommState'])+"</td>\n") 434 out.write(" <td>"+str(params['CommState'])+"</td>\n") 435 out.write("</tr>\n") 436 out.write("</table>\n")
437 438
439 -def printKml(params, out=sys.stdout):
440 '''KML (Keyhole Markup Language) for Google Earth, but without the header/footer''' 441 out.write("\ <Placemark>\n") 442 out.write("\t <name>"+str(params['UserID'])+"</name>\n") 443 out.write("\t\t<description>\n") 444 import StringIO 445 buf = StringIO.StringIO() 446 printHtml(params,buf) 447 import cgi 448 out.write(cgi.escape(buf.getvalue())) 449 out.write("\t\t</description>\n") 450 out.write("\t\t<styleUrl>#m_ylw-pushpin_copy0</styleUrl>\n") 451 out.write("\t\t<Point>\n") 452 out.write("\t\t\t<coordinates>") 453 out.write(str(params['longitude'])) 454 out.write(',') 455 out.write(str(params['latitude'])) 456 out.write(",0</coordinates>\n") 457 out.write("\t\t</Point>\n") 458 out.write("\t</Placemark>\n")
459
460 -def printFields(params, out=sys.stdout, format='std', fieldList=None, dbType='postgres'):
461 '''Print a positionb message to stdout. 462 463 Fields in params: 464 - MessageID(uint): AIS message number. Must be 18 (field automatically set to "18") 465 - RepeatIndicator(uint): Indicated how many times a message has been repeated 466 - UserID(uint): Unique ship identification number (MMSI) 467 - Reserved1(uint): Reseverd for definition by a compentent regional or local authority. Should be set to zero. (field automatically set to "0") 468 - SOG(udecimal): Speed over ground 469 - PositionAccuracy(uint): Accuracy of positioning fixes 470 - longitude(decimal): Location of the vessel East West location 471 - latitude(decimal): Location of the vessel North South location 472 - COG(udecimal): Course over ground 473 - TrueHeading(uint): True heading (relative to true North) 474 - TimeStamp(uint): UTC second when the report was generated 475 - RegionalReserved(uint): Reserved for definition by a regional authority. (field automatically set to "0") 476 - Spare(uint): Not used. Should be set to zero. (field automatically set to "0") 477 - RAIM(bool): Receiver autonomous integrity monitoring flag 478 - CommStateSelector(uint): SOTDMA or ITDMA 479 - CommState(uint): Not decoded by this software yet 480 @param params: Dictionary of field names/values. 481 @param out: File like object to write to 482 @rtype: stdout 483 @return: text to out 484 ''' 485 486 if 'std'==format: 487 out.write("positionb:\n") 488 if 'MessageID' in params: out.write(" MessageID: "+str(params['MessageID'])+"\n") 489 if 'RepeatIndicator' in params: out.write(" RepeatIndicator: "+str(params['RepeatIndicator'])+"\n") 490 if 'UserID' in params: out.write(" UserID: "+str(params['UserID'])+"\n") 491 if 'Reserved1' in params: out.write(" Reserved1: "+str(params['Reserved1'])+"\n") 492 if 'SOG' in params: out.write(" SOG: "+str(params['SOG'])+"\n") 493 if 'PositionAccuracy' in params: out.write(" PositionAccuracy: "+str(params['PositionAccuracy'])+"\n") 494 if 'longitude' in params: out.write(" longitude: "+str(params['longitude'])+"\n") 495 if 'latitude' in params: out.write(" latitude: "+str(params['latitude'])+"\n") 496 if 'COG' in params: out.write(" COG: "+str(params['COG'])+"\n") 497 if 'TrueHeading' in params: out.write(" TrueHeading: "+str(params['TrueHeading'])+"\n") 498 if 'TimeStamp' in params: out.write(" TimeStamp: "+str(params['TimeStamp'])+"\n") 499 if 'RegionalReserved' in params: out.write(" RegionalReserved: "+str(params['RegionalReserved'])+"\n") 500 if 'Spare' in params: out.write(" Spare: "+str(params['Spare'])+"\n") 501 if 'RAIM' in params: out.write(" RAIM: "+str(params['RAIM'])+"\n") 502 if 'CommStateSelector' in params: out.write(" CommStateSelector: "+str(params['CommStateSelector'])+"\n") 503 if 'CommState' in params: out.write(" CommState: "+str(params['CommState'])+"\n") 504 elif 'csv'==format: 505 if None == options.fieldList: 506 options.fieldList = fieldList 507 needComma = False; 508 for field in fieldList: 509 if needComma: out.write(',') 510 needComma = True 511 if field in params: 512 out.write(str(params[field])) 513 # else: leave it empty 514 out.write("\n") 515 elif 'html'==format: 516 printHtml(params,out) 517 elif 'sql'==format: 518 sqlInsertStr(params,out,dbType=dbType) 519 elif 'kml'==format: 520 printKml(params,out) 521 elif 'kml-full'==format: 522 out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") 523 out.write("<kml xmlns=\"http://earth.google.com/kml/2.1\">\n") 524 out.write("<Document>\n") 525 out.write(" <name>positionb</name>\n") 526 printKml(params,out) 527 out.write("</Document>\n") 528 out.write("</kml>\n") 529 else: 530 print "ERROR: unknown format:",format 531 assert False 532 533 return # Nothing to return
534 535 RepeatIndicatorEncodeLut = { 536 'default':'0', 537 'do not repeat any more':'3', 538 } #RepeatIndicatorEncodeLut 539 540 RepeatIndicatorDecodeLut = { 541 '0':'default', 542 '3':'do not repeat any more', 543 } # RepeatIndicatorEncodeLut 544 545 SOGEncodeLut = { 546 '102.2 knots or higher':'102.2', 547 } #SOGEncodeLut 548 549 SOGDecodeLut = { 550 '102.2':'102.2 knots or higher', 551 } # SOGEncodeLut 552 553 PositionAccuracyEncodeLut = { 554 'low (greater than 10 m)':'0', 555 'high (less than 10 m)':'1', 556 } #PositionAccuracyEncodeLut 557 558 PositionAccuracyDecodeLut = { 559 '0':'low (greater than 10 m)', 560 '1':'high (less than 10 m)', 561 } # PositionAccuracyEncodeLut 562 563 TimeStampEncodeLut = { 564 'not available/default':'60', 565 'manual input':'61', 566 'dead reckoning':'62', 567 'inoperative':'63', 568 } #TimeStampEncodeLut 569 570 TimeStampDecodeLut = { 571 '60':'not available/default', 572 '61':'manual input', 573 '62':'dead reckoning', 574 '63':'inoperative', 575 } # TimeStampEncodeLut 576 577 RAIMEncodeLut = { 578 'not in use':'False', 579 'in use':'True', 580 } #RAIMEncodeLut 581 582 RAIMDecodeLut = { 583 'False':'not in use', 584 'True':'in use', 585 } # RAIMEncodeLut 586 587 CommStateSelectorEncodeLut = { 588 'SOTDMA':'0', 589 'ITDMA':'1', 590 } #CommStateSelectorEncodeLut 591 592 CommStateSelectorDecodeLut = { 593 '0':'SOTDMA', 594 '1':'ITDMA', 595 } # CommStateSelectorEncodeLut 596 597 ###################################################################### 598 # SQL SUPPORT 599 ###################################################################### 600 601 dbTableName='positionb' 602 'Database table name' 603
604 -def sqlCreateStr(outfile=sys.stdout, fields=None, extraFields=None 605 ,addCoastGuardFields=True 606 ,dbType='postgres' 607 ):
608 ''' 609 Return the SQL CREATE command for this message type 610 @param outfile: file like object to print to. 611 @param fields: which fields to put in the create. Defaults to all. 612 @param extraFields: A sequence of tuples containing (name,sql type) for additional fields 613 @param addCoastGuardFields: Add the extra fields that come after the NMEA check some from the USCG N-AIS format 614 @param dbType: Which flavor of database we are using so that the create is tailored ('sqlite' or 'postgres') 615 @type addCoastGuardFields: bool 616 @return: sql create string 617 @rtype: str 618 619 @see: sqlCreate 620 ''' 621 # FIX: should this sqlCreate be the same as in LaTeX (createFuncName) rather than hard coded? 622 outfile.write(str(sqlCreate(fields,extraFields,addCoastGuardFields,dbType=dbType)))
623
624 -def sqlCreate(fields=None, extraFields=None, addCoastGuardFields=True, dbType='postgres'):
625 ''' 626 Return the sqlhelp object to create the table. 627 628 @param fields: which fields to put in the create. Defaults to all. 629 @param extraFields: A sequence of tuples containing (name,sql type) for additional fields 630 @param addCoastGuardFields: Add the extra fields that come after the NMEA check some from the USCG N-AIS format 631 @type addCoastGuardFields: bool 632 @param dbType: Which flavor of database we are using so that the create is tailored ('sqlite' or 'postgres') 633 @return: An object that can be used to generate a return 634 @rtype: sqlhelp.create 635 ''' 636 if None == fields: fields = fieldList 637 import sqlhelp 638 c = sqlhelp.create('positionb',dbType=dbType) 639 c.addPrimaryKey() 640 if 'MessageID' in fields: c.addInt ('MessageID') 641 if 'RepeatIndicator' in fields: c.addInt ('RepeatIndicator') 642 if 'UserID' in fields: c.addInt ('UserID') 643 if 'Reserved1' in fields: c.addInt ('Reserved1') 644 if 'SOG' in fields: c.addDecimal('SOG',4,1) 645 if 'PositionAccuracy' in fields: c.addInt ('PositionAccuracy') 646 if dbType != 'postgres': 647 if 'longitude' in fields: c.addDecimal('longitude',8,5) 648 if dbType != 'postgres': 649 if 'latitude' in fields: c.addDecimal('latitude',8,5) 650 if 'COG' in fields: c.addDecimal('COG',4,1) 651 if 'TrueHeading' in fields: c.addInt ('TrueHeading') 652 if 'TimeStamp' in fields: c.addInt ('TimeStamp') 653 if 'RegionalReserved' in fields: c.addInt ('RegionalReserved') 654 if 'Spare' in fields: c.addInt ('Spare') 655 if 'RAIM' in fields: c.addBool('RAIM') 656 if 'CommStateSelector' in fields: c.addInt ('CommStateSelector') 657 if 'CommState' in fields: c.addInt ('CommState') 658 659 if addCoastGuardFields: 660 # c.addInt('cg_rssi') # Relative signal strength indicator 661 # c.addInt('cg_d') # dBm receive strength 662 # c.addInt('cg_T') # Receive timestamp from the AIS equipment 663 # c.addInt('cg_S') # Slot received in 664 # c.addVarChar('cg_x',10) # Idonno 665 c.addVarChar('cg_r',15) # Receiver station ID - should usually be an MMSI, but sometimes is a string 666 c.addInt('cg_sec') # UTC seconds since the epoch 667 668 c.addTimestamp('cg_timestamp') # UTC decoded cg_sec - not actually in the data stream 669 670 if dbType == 'postgres': 671 #--- EPSG 4326 : WGS 84 672 #INSERT INTO "spatial_ref_sys" ("srid","auth_name","auth_srid","srtext","proj4text") VALUES (4326,'EPSG',4326,'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]','+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs '); 673 c.addPostGIS('Position','POINT',2,SRID=4326); 674 675 return c
676
677 -def sqlInsertStr(params, outfile=sys.stdout, extraParams=None, dbType='postgres'):
678 ''' 679 Return the SQL INSERT command for this message type 680 @param params: dictionary of values keyed by field name 681 @param outfile: file like object to print to. 682 @param extraParams: A sequence of tuples containing (name,sql type) for additional fields 683 @return: sql create string 684 @rtype: str 685 686 @see: sqlCreate 687 ''' 688 outfile.write(str(sqlInsert(params,extraParams,dbType=dbType)))
689 690
691 -def sqlInsert(params,extraParams=None,dbType='postgres'):
692 ''' 693 Give the SQL INSERT statement 694 @param params: dict keyed by field name of values 695 @param extraParams: any extra fields that you have created beyond the normal ais message fields 696 @rtype: sqlhelp.insert 697 @return: insert class instance 698 @todo: allow optional type checking of params? 699 @warning: this will take invalid keys happily and do what??? 700 ''' 701 import sqlhelp 702 i = sqlhelp.insert('positionb',dbType=dbType) 703 704 if dbType=='postgres': 705 finished = [] 706 for key in params: 707 if key in finished: 708 continue 709 710 if key not in toPgFields and key not in fromPgFields: 711 if type(params[key])==Decimal: i.add(key,float(params[key])) 712 else: i.add(key,params[key]) 713 else: 714 if key in fromPgFields: 715 val = params[key] 716 # Had better be a WKT type like POINT(-88.1 30.321) 717 i.addPostGIS(key,val) 718 finished.append(key) 719 else: 720 # Need to construct the type. 721 pgName = toPgFields[key] 722 #valStr='GeomFromText(\''+pgTypes[pgName]+'(' 723 valStr=pgTypes[pgName]+'(' 724 vals = [] 725 for nonPgKey in fromPgFields[pgName]: 726 vals.append(str(params[nonPgKey])) 727 finished.append(nonPgKey) 728 valStr+=' '.join(vals)+')' 729 i.addPostGIS(pgName,valStr) 730 else: 731 for key in params: 732 if type(params[key])==Decimal: i.add(key,float(params[key])) 733 else: i.add(key,params[key]) 734 735 if None != extraParams: 736 for key in extraParams: 737 i.add(key,extraParams[key]) 738 739 return i
740 741 ###################################################################### 742 # LATEX SUPPORT 743 ###################################################################### 744
745 -def latexDefinitionTable(outfile=sys.stdout 746 ):
747 ''' 748 Return the LaTeX definition table for this message type 749 @param outfile: file like object to print to. 750 @type outfile: file obj 751 @return: LaTeX table string via the outfile 752 @rtype: str 753 754 ''' 755 o = outfile 756 757 o.write(''' 758 \\begin{table}%[htb] 759 \\centering 760 \\begin{tabular}{|l|c|l|} 761 \\hline 762 Parameter & Number of bits & Description 763 \\\\ \\hline\\hline 764 MessageID & 6 & AIS message number. Must be 18 \\\\ \hline 765 RepeatIndicator & 2 & Indicated how many times a message has been repeated \\\\ \hline 766 UserID & 30 & Unique ship identification number (MMSI) \\\\ \hline 767 Reserved1 & 8 & Reseverd for definition by a compentent regional or local authority. Should be set to zero. \\\\ \hline 768 SOG & 10 & Speed over ground \\\\ \hline 769 PositionAccuracy & 1 & Accuracy of positioning fixes \\\\ \hline 770 longitude & 28 & Location of the vessel East West location \\\\ \hline 771 latitude & 27 & Location of the vessel North South location \\\\ \hline 772 COG & 12 & Course over ground \\\\ \hline 773 TrueHeading & 9 & True heading (relative to true North) \\\\ \hline 774 TimeStamp & 6 & UTC second when the report was generated \\\\ \hline 775 RegionalReserved & 4 & Reserved for definition by a regional authority. \\\\ \hline 776 Spare & 4 & Not used. Should be set to zero. \\\\ \hline 777 RAIM & 1 & Receiver autonomous integrity monitoring flag \\\\ \hline 778 CommStateSelector & 1 & SOTDMA or ITDMA \\\\ \hline 779 CommState & 19 & Not decoded by this software yet\\\\ \\hline \\hline 780 Total bits & 168 & Appears to take 1 slot \\\\ \\hline 781 \\end{tabular} 782 \\caption{AIS message number 18: Standard Class B equipment position report} 783 \\label{tab:positionb} 784 \\end{table} 785 ''')
786 787 ###################################################################### 788 # Text Definition 789 ###################################################################### 790
791 -def textDefinitionTable(outfile=sys.stdout 792 ,delim='\t' 793 ):
794 ''' 795 Return the text definition table for this message type 796 @param outfile: file like object to print to. 797 @type outfile: file obj 798 @return: text table string via the outfile 799 @rtype: str 800 801 ''' 802 o = outfile 803 o.write('''Parameter'''+delim+'Number of bits'''+delim+'''Description 804 MessageID'''+delim+'''6'''+delim+'''AIS message number. Must be 18 805 RepeatIndicator'''+delim+'''2'''+delim+'''Indicated how many times a message has been repeated 806 UserID'''+delim+'''30'''+delim+'''Unique ship identification number (MMSI) 807 Reserved1'''+delim+'''8'''+delim+'''Reseverd for definition by a compentent regional or local authority. Should be set to zero. 808 SOG'''+delim+'''10'''+delim+'''Speed over ground 809 PositionAccuracy'''+delim+'''1'''+delim+'''Accuracy of positioning fixes 810 longitude'''+delim+'''28'''+delim+'''Location of the vessel East West location 811 latitude'''+delim+'''27'''+delim+'''Location of the vessel North South location 812 COG'''+delim+'''12'''+delim+'''Course over ground 813 TrueHeading'''+delim+'''9'''+delim+'''True heading (relative to true North) 814 TimeStamp'''+delim+'''6'''+delim+'''UTC second when the report was generated 815 RegionalReserved'''+delim+'''4'''+delim+'''Reserved for definition by a regional authority. 816 Spare'''+delim+'''4'''+delim+'''Not used. Should be set to zero. 817 RAIM'''+delim+'''1'''+delim+'''Receiver autonomous integrity monitoring flag 818 CommStateSelector'''+delim+'''1'''+delim+'''SOTDMA or ITDMA 819 CommState'''+delim+'''19'''+delim+'''Not decoded by this software yet 820 Total bits'''+delim+'''168'''+delim+'''Appears to take 1 slot''')
821 822 823 ###################################################################### 824 # UNIT TESTING 825 ###################################################################### 826 import unittest
827 -def testParams():
828 '''Return a params file base on the testvalue tags. 829 @rtype: dict 830 @return: params based on testvalue tags 831 ''' 832 params = {} 833 params['MessageID'] = 18 834 params['RepeatIndicator'] = 1 835 params['UserID'] = 1193046 836 params['Reserved1'] = 0 837 params['SOG'] = Decimal('101.9') 838 params['PositionAccuracy'] = 1 839 params['longitude'] = Decimal('-122.16328055555556') 840 params['latitude'] = Decimal('37.424458333333334') 841 params['COG'] = Decimal('34.5') 842 params['TrueHeading'] = 41 843 params['TimeStamp'] = 35 844 params['RegionalReserved'] = 0 845 params['Spare'] = 0 846 params['RAIM'] = False 847 params['CommStateSelector'] = 0 848 params['CommState'] = 0 849 850 return params
851
852 -class Testpositionb(unittest.TestCase):
853 '''Use testvalue tag text from each type to build test case the positionb message'''
854 - def testEncodeDecode(self):
855 856 params = testParams() 857 bits = encode(params) 858 r = decode(bits) 859 860 # Check that each parameter came through ok. 861 self.failUnlessEqual(r['MessageID'],params['MessageID']) 862 self.failUnlessEqual(r['RepeatIndicator'],params['RepeatIndicator']) 863 self.failUnlessEqual(r['UserID'],params['UserID']) 864 self.failUnlessEqual(r['Reserved1'],params['Reserved1']) 865 self.failUnlessAlmostEqual(r['SOG'],params['SOG'],1) 866 self.failUnlessEqual(r['PositionAccuracy'],params['PositionAccuracy']) 867 self.failUnlessAlmostEqual(r['longitude'],params['longitude'],5) 868 self.failUnlessAlmostEqual(r['latitude'],params['latitude'],5) 869 self.failUnlessAlmostEqual(r['COG'],params['COG'],1) 870 self.failUnlessEqual(r['TrueHeading'],params['TrueHeading']) 871 self.failUnlessEqual(r['TimeStamp'],params['TimeStamp']) 872 self.failUnlessEqual(r['RegionalReserved'],params['RegionalReserved']) 873 self.failUnlessEqual(r['Spare'],params['Spare']) 874 self.failUnlessEqual(r['RAIM'],params['RAIM']) 875 self.failUnlessEqual(r['CommStateSelector'],params['CommStateSelector']) 876 self.failUnlessEqual(r['CommState'],params['CommState'])
877
878 -def addMsgOptions(parser):
879 parser.add_option('-d','--decode',dest='doDecode',default=False,action='store_true', 880 help='decode a "positionb" AIS message') 881 parser.add_option('-e','--encode',dest='doEncode',default=False,action='store_true', 882 help='encode a "positionb" AIS message') 883 parser.add_option('--RepeatIndicator-field', dest='RepeatIndicatorField',default=0,metavar='uint',type='int' 884 ,help='Field parameter value [default: %default]') 885 parser.add_option('--UserID-field', dest='UserIDField',metavar='uint',type='int' 886 ,help='Field parameter value [default: %default]') 887 parser.add_option('--SOG-field', dest='SOGField',default=Decimal('102.3'),metavar='udecimal',type='string' 888 ,help='Field parameter value [default: %default]') 889 parser.add_option('--PositionAccuracy-field', dest='PositionAccuracyField',metavar='uint',type='int' 890 ,help='Field parameter value [default: %default]') 891 parser.add_option('--longitude-field', dest='longitudeField',default=Decimal('181'),metavar='decimal',type='string' 892 ,help='Field parameter value [default: %default]') 893 parser.add_option('--latitude-field', dest='latitudeField',default=Decimal('91'),metavar='decimal',type='string' 894 ,help='Field parameter value [default: %default]') 895 parser.add_option('--COG-field', dest='COGField',default=Decimal('360'),metavar='udecimal',type='string' 896 ,help='Field parameter value [default: %default]') 897 parser.add_option('--TrueHeading-field', dest='TrueHeadingField',default=511,metavar='uint',type='int' 898 ,help='Field parameter value [default: %default]') 899 parser.add_option('--TimeStamp-field', dest='TimeStampField',default=60,metavar='uint',type='int' 900 ,help='Field parameter value [default: %default]') 901 parser.add_option('--RAIM-field', dest='RAIMField',metavar='bool',type='int' 902 ,help='Field parameter value [default: %default]') 903 parser.add_option('--CommStateSelector-field', dest='CommStateSelectorField',metavar='uint',type='int' 904 ,help='Field parameter value [default: %default]') 905 parser.add_option('--CommState-field', dest='CommStateField',metavar='uint',type='int' 906 ,help='Field parameter value [default: %default]')
907 908 ############################################################ 909 if __name__=='__main__': 910 911 from optparse import OptionParser 912 parser = OptionParser(usage="%prog [options]", 913 version="%prog "+__version__) 914 915 parser.add_option('--doc-test',dest='doctest',default=False,action='store_true', 916 help='run the documentation tests') 917 parser.add_option('--unit-test',dest='unittest',default=False,action='store_true', 918 help='run the unit tests') 919 parser.add_option('-v','--verbose',dest='verbose',default=False,action='store_true', 920 help='Make the test output verbose') 921 922 # FIX: remove nmea from binary messages. No way to build the whole packet? 923 # FIX: or build the surrounding msg 8 for a broadcast? 924 typeChoices = ('binary','nmeapayload','nmea') # FIX: what about a USCG type message? 925 parser.add_option('-t','--type',choices=typeChoices,type='choice',dest='ioType' 926 ,default='nmeapayload' 927 ,help='What kind of string to write for encoding ('+', '.join(typeChoices)+') [default: %default]') 928 929 930 outputChoices = ('std','html','csv','sql' , 'kml','kml-full') 931 parser.add_option('-T','--output-type',choices=outputChoices,type='choice',dest='outputType' 932 ,default='std' 933 ,help='What kind of string to output ('+', '.join(outputChoices)+') [default: %default]') 934 935 parser.add_option('-o','--output',dest='outputFileName',default=None, 936 help='Name of the python file to write [default: stdout]') 937 938 parser.add_option('-f','--fields',dest='fieldList',default=None, action='append', 939 choices=fieldList, 940 help='Which fields to include in the output. Currently only for csv output [default: all]') 941 942 parser.add_option('-p','--print-csv-field-list',dest='printCsvfieldList',default=False,action='store_true', 943 help='Print the field name for csv') 944 945 parser.add_option('-c','--sql-create',dest='sqlCreate',default=False,action='store_true', 946 help='Print out an sql create command for the table.') 947 948 parser.add_option('--latex-table',dest='latexDefinitionTable',default=False,action='store_true', 949 help='Print a LaTeX table of the type') 950 951 parser.add_option('--text-table',dest='textDefinitionTable',default=False,action='store_true', 952 help='Print delimited table of the type (for Word table importing)') 953 parser.add_option('--delimt-text-table',dest='delimTextDefinitionTable',default='\t' 954 ,help='Delimiter for text table [default: \'%default\'](for Word table importing)') 955 956 957 dbChoices = ('sqlite','postgres') 958 parser.add_option('-D','--db-type',dest='dbType',default='postgres' 959 ,choices=dbChoices,type='choice' 960 ,help='What kind of database ('+', '.join(dbChoices)+') [default: %default]') 961 962 addMsgOptions(parser) 963 964 (options,args) = parser.parse_args() 965 success=True 966 967 if options.doctest: 968 import os; print os.path.basename(sys.argv[0]), 'doctests ...', 969 sys.argv= [sys.argv[0]] 970 if options.verbose: sys.argv.append('-v') 971 import doctest 972 numfail,numtests=doctest.testmod() 973 if numfail==0: print 'ok' 974 else: 975 print 'FAILED' 976 success=False 977 978 if not success: sys.exit('Something Failed') 979 del success # Hide success from epydoc 980 981 if options.unittest: 982 sys.argv = [sys.argv[0]] 983 if options.verbose: sys.argv.append('-v') 984 unittest.main() 985 986 outfile = sys.stdout 987 if None!=options.outputFileName: 988 outfile = file(options.outputFileName,'w') 989 990 991 if options.doEncode: 992 # First make sure all non required options are specified 993 if None==options.RepeatIndicatorField: parser.error("missing value for RepeatIndicatorField") 994 if None==options.UserIDField: parser.error("missing value for UserIDField") 995 if None==options.SOGField: parser.error("missing value for SOGField") 996 if None==options.PositionAccuracyField: parser.error("missing value for PositionAccuracyField") 997 if None==options.longitudeField: parser.error("missing value for longitudeField") 998 if None==options.latitudeField: parser.error("missing value for latitudeField") 999 if None==options.COGField: parser.error("missing value for COGField") 1000 if None==options.TrueHeadingField: parser.error("missing value for TrueHeadingField") 1001 if None==options.TimeStampField: parser.error("missing value for TimeStampField") 1002 if None==options.RAIMField: parser.error("missing value for RAIMField") 1003 if None==options.CommStateSelectorField: parser.error("missing value for CommStateSelectorField") 1004 if None==options.CommStateField: parser.error("missing value for CommStateField") 1005 msgDict={ 1006 'MessageID': '18', 1007 'RepeatIndicator': options.RepeatIndicatorField, 1008 'UserID': options.UserIDField, 1009 'Reserved1': '0', 1010 'SOG': options.SOGField, 1011 'PositionAccuracy': options.PositionAccuracyField, 1012 'longitude': options.longitudeField, 1013 'latitude': options.latitudeField, 1014 'COG': options.COGField, 1015 'TrueHeading': options.TrueHeadingField, 1016 'TimeStamp': options.TimeStampField, 1017 'RegionalReserved': '0', 1018 'Spare': '0', 1019 'RAIM': options.RAIMField, 1020 'CommStateSelector': options.CommStateSelectorField, 1021 'CommState': options.CommStateField, 1022 } 1023 1024 bits = encode(msgDict) 1025 if 'binary'==options.ioType: print str(bits) 1026 elif 'nmeapayload'==options.ioType: 1027 # FIX: figure out if this might be necessary at compile time 1028 print "bitLen",len(bits) 1029 bitLen=len(bits) 1030 if bitLen%6!=0: 1031 bits = bits + BitVector(size=(6 - (bitLen%6))) # Pad out to multiple of 6 1032 print "result:",binary.bitvectoais6(bits)[0] 1033 1034 1035 # FIX: Do not emit this option for the binary message payloads. Does not make sense. 1036 elif 'nmea'==options.ioType: sys.exit("FIX: need to implement this capability") 1037 else: sys.exit('ERROR: unknown ioType. Help!') 1038 1039 1040 if options.sqlCreate: 1041 sqlCreateStr(outfile,options.fieldList,dbType=options.dbType) 1042 1043 if options.latexDefinitionTable: 1044 latexDefinitionTable(outfile) 1045 1046 # For conversion to word tables 1047 if options.textDefinitionTable: 1048 textDefinitionTable(outfile,options.delimTextDefinitionTable) 1049 1050 if options.printCsvfieldList: 1051 # Make a csv separated list of fields that will be displayed for csv 1052 if None == options.fieldList: options.fieldList = fieldList 1053 import StringIO 1054 buf = StringIO.StringIO() 1055 for field in options.fieldList: 1056 buf.write(field+',') 1057 result = buf.getvalue() 1058 if result[-1] == ',': print result[:-1] 1059 else: print result 1060 1061 if options.doDecode: 1062 if len(args)==0: args = sys.stdin 1063 for msg in args: 1064 bv = None 1065 1066 if msg[0] in ('$','!') and msg[3:6] in ('VDM','VDO'): 1067 # Found nmea 1068 # FIX: do checksum 1069 bv = binary.ais6tobitvec(msg.split(',')[5]) 1070 else: # either binary or nmeapayload... expect mostly nmeapayloads 1071 # assumes that an all 0 and 1 string can not be a nmeapayload 1072 binaryMsg=True 1073 for c in msg: 1074 if c not in ('0','1'): 1075 binaryMsg=False 1076 break 1077 if binaryMsg: 1078 bv = BitVector(bitstring=msg) 1079 else: # nmeapayload 1080 bv = binary.ais6tobitvec(msg) 1081 1082 printFields(decode(bv) 1083 ,out=outfile 1084 ,format=options.outputType 1085 ,fieldList=options.fieldList 1086 ,dbType=options.dbType 1087 ) 1088