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

Source Code for Module ais.allaistypes

  1  #!/usr/bin/env python 
  2   
  3  __version__ = '$Revision: 4791 $'.split()[1] 
  4  __date__ = '$Date: 2007-02-05 $'.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  ''' 
 34   
 35  import sys 
 36  from decimal import Decimal 
 37  from BitVector import BitVector 
 38   
 39  import binary, aisstring 
 40   
 41  # FIX: check to see if these will be needed 
 42  TrueBV  = BitVector(bitstring="1") 
 43  "Why always rebuild the True bit?  This should speed things up a bunch" 
 44  FalseBV = BitVector(bitstring="0") 
 45  "Why always rebuild the False bit?  This should speed things up a bunch" 
 46   
 47   
 48  fieldList = [ 
 49          'dac', 
 50          'reqDecimal', 
 51          'unavail_uint', 
 52          'anUInt', 
 53          'anInt', 
 54          'aBool', 
 55          'aStr', 
 56          'anUDecimal', 
 57          'aDecimal', 
 58          'aFloat', 
 59  ] 
 60   
61 -def encode(params, validate=False):
62 '''Create a alltypesmsg binary message payload to pack into an AIS Msg alltypesmsg. 63 64 Fields in params: 65 - dac(uint): Designated Area Code (field automatically set to "366") 66 - reqDecimal(decimal): required decimal value... FIX: scale or no? (field automatically set to "122") 67 - unavail_uint(uint): Unavailable unsigned integer 68 - anUInt(uint): NO unavailable unsigned integer 69 - anInt(int): NO unavailable signed integer 70 - aBool(bool): Simple bool 71 - aStr(aisstr6): An ais string of 5 characters 72 - anUDecimal(udecimal): An unsigned decimal. Allow smaller numbers 73 - aDecimal(decimal): A decimal 74 - aFloat(float): An IEEE floating point number 75 @param params: Dictionary of field names/values. Throws a ValueError exception if required is missing 76 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. 77 @rtype: BitVector 78 @return: encoded binary message (for binary messages, this needs to be wrapped in a msg 8 79 @note: The returned bits may not be 6 bit aligned. It is up to you to pad out the bits. 80 ''' 81 82 bvList = [] 83 bvList.append(binary.setBitVectorSize(BitVector(intVal=366),16)) 84 bvList.append(binary.bvFromSignedInt(122,8)) 85 if 'unavail_uint' in params: 86 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['unavail_uint']),2)) 87 else: 88 bvList.append(binary.setBitVectorSize(BitVector(intVal=3),2)) 89 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['anUInt']),2)) 90 bvList.append(binary.bvFromSignedInt(params['anInt'],3)) 91 if params["aBool"]: bvList.append(TrueBV) 92 else: bvList.append(FalseBV) 93 bvList.append(aisstring.encode(params['aStr'],30)) 94 bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['anUDecimal'])*Decimal('10')))),16)) 95 bvList.append(binary.bvFromSignedInt(int(Decimal(params['aDecimal'])*Decimal('10')),16)) 96 bvList.append(binary.float2bitvec(params['aFloat'])) 97 98 return binary.joinBV(bvList)
99
100 -def decode(bv, validate=False):
101 '''Unpack a alltypesmsg message 102 103 Fields in params: 104 - dac(uint): Designated Area Code (field automatically set to "366") 105 - reqDecimal(decimal): required decimal value... FIX: scale or no? (field automatically set to "122") 106 - unavail_uint(uint): Unavailable unsigned integer 107 - anUInt(uint): NO unavailable unsigned integer 108 - anInt(int): NO unavailable signed integer 109 - aBool(bool): Simple bool 110 - aStr(aisstr6): An ais string of 5 characters 111 - anUDecimal(udecimal): An unsigned decimal. Allow smaller numbers 112 - aDecimal(decimal): A decimal 113 - aFloat(float): An IEEE floating point number 114 @type bv: BitVector 115 @param bv: Bits defining a message 116 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. 117 @rtype: dict 118 @return: params 119 ''' 120 121 #Would be nice to check the bit count here.. 122 #if validate: 123 # assert (len(bv)==FIX: SOME NUMBER) 124 r = {} 125 r['dac']=366 126 r['reqDecimal']=122/Decimal('1') 127 r['unavail_uint']=int(bv[24:26]) 128 r['anUInt']=int(bv[26:28]) 129 r['anInt']=binary.signedIntFromBV(bv[28:31]) 130 r['aBool']=bool(int(bv[31:32])) 131 r['aStr']=aisstring.decode(bv[32:62]) 132 r['anUDecimal']=Decimal(int(bv[62:78]))/Decimal('10') 133 r['aDecimal']=Decimal(binary.signedIntFromBV(bv[78:94]))/Decimal('10') 134 r['aFloat']=binary.bitvec2float(bv[94:126]) 135 return r
136
137 -def decodedac(bv, validate=False):
138 return 366
139
140 -def decodereqDecimal(bv, validate=False):
141 return 122/Decimal('1')
142
143 -def decodeunavail_uint(bv, validate=False):
144 return int(bv[24:26])
145
146 -def decodeanUInt(bv, validate=False):
147 return int(bv[26:28])
148
149 -def decodeanInt(bv, validate=False):
150 return binary.signedIntFromBV(bv[28:31])
151
152 -def decodeaBool(bv, validate=False):
153 return bool(int(bv[31:32]))
154
155 -def decodeaStr(bv, validate=False):
156 return aisstring.decode(bv[32:62])
157
158 -def decodeanUDecimal(bv, validate=False):
159 return Decimal(int(bv[62:78]))/Decimal('10')
160
161 -def decodeaDecimal(bv, validate=False):
162 return Decimal(binary.signedIntFromBV(bv[78:94]))/Decimal('10')
163
164 -def decodeaFloat(bv, validate=False):
165 return binary.bitvec2float(bv[94:126])
166 167
168 -def printHtml(params, out=sys.stdout):
169 out.write("<h3>alltypesmsg<h3>\n") 170 out.write("<table border=\"1\">\n") 171 out.write("<tr bgcolor=\"orange\">\n") 172 out.write("<th align=\"left\">Field Name</th>\n") 173 out.write("<th align=\"left\">Type</th>\n") 174 out.write("<th align=\"left\">Value</th>\n") 175 out.write("<th align=\"left\">Value in Lookup Table</th>\n") 176 out.write("<th align=\"left\">Units</th>\n") 177 out.write("\n") 178 out.write("<tr>\n") 179 out.write("<td>dac</td>\n") 180 out.write("<td>uint</td>\n") 181 if 'dac' in params: 182 out.write(" <td>"+str(params['dac'])+"</td>\n") 183 out.write(" <td>"+str(params['dac'])+"</td>\n") 184 out.write("</tr>\n") 185 out.write("\n") 186 out.write("<tr>\n") 187 out.write("<td>reqDecimal</td>\n") 188 out.write("<td>decimal</td>\n") 189 if 'reqDecimal' in params: 190 out.write(" <td>"+str(params['reqDecimal'])+"</td>\n") 191 out.write(" <td>"+str(params['reqDecimal'])+"</td>\n") 192 out.write("</tr>\n") 193 out.write("\n") 194 out.write("<tr>\n") 195 out.write("<td>unavail_uint</td>\n") 196 out.write("<td>uint</td>\n") 197 if 'unavail_uint' in params: 198 out.write(" <td>"+str(params['unavail_uint'])+"</td>\n") 199 out.write(" <td>"+str(params['unavail_uint'])+"</td>\n") 200 out.write("</tr>\n") 201 out.write("\n") 202 out.write("<tr>\n") 203 out.write("<td>anUInt</td>\n") 204 out.write("<td>uint</td>\n") 205 if 'anUInt' in params: 206 out.write(" <td>"+str(params['anUInt'])+"</td>\n") 207 out.write(" <td>"+str(params['anUInt'])+"</td>\n") 208 out.write("</tr>\n") 209 out.write("\n") 210 out.write("<tr>\n") 211 out.write("<td>anInt</td>\n") 212 out.write("<td>int</td>\n") 213 if 'anInt' in params: 214 out.write(" <td>"+str(params['anInt'])+"</td>\n") 215 out.write(" <td>"+str(params['anInt'])+"</td>\n") 216 out.write("</tr>\n") 217 out.write("\n") 218 out.write("<tr>\n") 219 out.write("<td>aBool</td>\n") 220 out.write("<td>bool</td>\n") 221 if 'aBool' in params: 222 out.write(" <td>"+str(params['aBool'])+"</td>\n") 223 out.write(" <td>"+str(params['aBool'])+"</td>\n") 224 out.write("</tr>\n") 225 out.write("\n") 226 out.write("<tr>\n") 227 out.write("<td>aStr</td>\n") 228 out.write("<td>aisstr6</td>\n") 229 if 'aStr' in params: 230 out.write(" <td>"+str(params['aStr'])+"</td>\n") 231 out.write(" <td>"+str(params['aStr'])+"</td>\n") 232 out.write("</tr>\n") 233 out.write("\n") 234 out.write("<tr>\n") 235 out.write("<td>anUDecimal</td>\n") 236 out.write("<td>udecimal</td>\n") 237 if 'anUDecimal' in params: 238 out.write(" <td>"+str(params['anUDecimal'])+"</td>\n") 239 out.write(" <td>"+str(params['anUDecimal'])+"</td>\n") 240 out.write("</tr>\n") 241 out.write("\n") 242 out.write("<tr>\n") 243 out.write("<td>aDecimal</td>\n") 244 out.write("<td>decimal</td>\n") 245 if 'aDecimal' in params: 246 out.write(" <td>"+str(params['aDecimal'])+"</td>\n") 247 out.write(" <td>"+str(params['aDecimal'])+"</td>\n") 248 out.write("</tr>\n") 249 out.write("\n") 250 out.write("<tr>\n") 251 out.write("<td>aFloat</td>\n") 252 out.write("<td>float</td>\n") 253 if 'aFloat' in params: 254 out.write(" <td>"+str(params['aFloat'])+"</td>\n") 255 out.write(" <td>"+str(params['aFloat'])+"</td>\n") 256 out.write("</tr>\n") 257 out.write("</table>\n")
258
259 -def printFields(params, out=sys.stdout, format='std', fieldList=None):
260 '''Print a aFloat message to stdout. 261 262 Fields in params: 263 - dac(uint): Designated Area Code (field automatically set to "366") 264 - reqDecimal(decimal): required decimal value... FIX: scale or no? (field automatically set to "122") 265 - unavail_uint(uint): Unavailable unsigned integer 266 - anUInt(uint): NO unavailable unsigned integer 267 - anInt(int): NO unavailable signed integer 268 - aBool(bool): Simple bool 269 - aStr(aisstr6): An ais string of 5 characters 270 - anUDecimal(udecimal): An unsigned decimal. Allow smaller numbers 271 - aDecimal(decimal): A decimal 272 - aFloat(float): An IEEE floating point number 273 @param params: Dictionary of field names/values. 274 @param out: File like object to write to 275 @rtype: stdout 276 @return: text to out 277 ''' 278 279 if 'std'==format: 280 out.write("aFloat:\n") 281 if 'dac' in params: out.write(" dac: "+str(params['dac'])+"\n") 282 if 'reqDecimal' in params: out.write(" reqDecimal: "+str(params['reqDecimal'])+"\n") 283 if 'unavail_uint' in params: out.write(" unavail_uint: "+str(params['unavail_uint'])+"\n") 284 if 'anUInt' in params: out.write(" anUInt: "+str(params['anUInt'])+"\n") 285 if 'anInt' in params: out.write(" anInt: "+str(params['anInt'])+"\n") 286 if 'aBool' in params: out.write(" aBool: "+str(params['aBool'])+"\n") 287 if 'aStr' in params: out.write(" aStr: "+str(params['aStr'])+"\n") 288 if 'anUDecimal' in params: out.write(" anUDecimal: "+str(params['anUDecimal'])+"\n") 289 if 'aDecimal' in params: out.write(" aDecimal: "+str(params['aDecimal'])+"\n") 290 if 'aFloat' in params: out.write(" aFloat: "+str(params['aFloat'])+"\n") 291 elif 'csv'==format: 292 if None == options.fieldList: 293 options.fieldList = fieldList 294 needComma = False; 295 for field in fieldList: 296 if needComma: out.write(',') 297 needComma = True 298 if field in params: 299 out.write(str(params[field])) 300 # else: leave it empty 301 out.write("\n") 302 elif 'html'==format: 303 printHtml(params,out) 304 elif 'sql'==format: 305 sqlInsertStr(params,out) 306 else: 307 print "ERROR: unknown format:",format 308 assert False 309 310 return # Nothing to return
311 312 ###################################################################### 313 # SQL SUPPORT 314 ###################################################################### 315
316 -def sqlCreateStr(outfile=sys.stdout, fields=None, extraFields=None):
317 ''' 318 Return the SQL CREATE command for this message type 319 @param outfile: file like object to print to. 320 @param fields: which fields to put in the create. Defaults to all. 321 @param extraFields: A sequence of tuples containing (name,sql type) for additional fields 322 @return: sql create string 323 @rtype: str 324 325 @see: sqlCreate 326 ''' 327 outfile.write(str(sqlCreate(fields,extraFields)))
328
329 -def sqlCreate(fields=None, extraFields=None):
330 ''' 331 Return the sqlhelp object to create the table. 332 333 @param fields: which fields to put in the create. Defaults to all. 334 @param extraFields: A sequence of tuples containing (name,sql type) for additional fields 335 @return: An object that can be used to generate a return 336 @rtype: sqlhelp.create 337 ''' 338 if None == fields: fields = fieldList 339 import sqlhelp 340 c = sqlhelp.create('alltypesmsg') 341 if 'dac' in fields: c.addInt ('dac') 342 if 'reqDecimal' in fields: c.addDecimal('reqDecimal',3,0) 343 if 'unavail_uint' in fields: c.addInt ('unavail_uint') 344 if 'anUInt' in fields: c.addInt ('anUInt') 345 if 'anInt' in fields: c.addInt ('anInt') 346 if 'aBool' in fields: c.addBool('aBool') 347 if 'aStr' in fields: c.addVarChar(aStr,5) 348 if 'anUDecimal' in fields: c.addDecimal('anUDecimal',5,1) 349 if 'aDecimal' in fields: c.addDecimal('aDecimal',4,0) 350 if 'aFloat' in fields: c.addReal('aFloat') 351 352 return c
353
354 -def sqlInsertStr(params, outfile=sys.stdout, extraParams=None):
355 ''' 356 Return the SQL CREATE command for this message type 357 @param params: dictionary of values keyed by field name 358 @param outfile: file like object to print to. 359 @param extraParams: A sequence of tuples containing (name,sql type) for additional fields 360 @return: sql create string 361 @rtype: str 362 363 @see: sqlCreate 364 ''' 365 outfile.write(str(sqlInsert(params,extraParams)))
366 367
368 -def sqlInsert(params,extraParams=None):
369 ''' 370 Give the SQL insert statement 371 @param params: dict keyed by field name of values 372 @param extraParams: any extra fields that you have created beyond the normal ais message fields 373 @rtype: sqlhelp.insert 374 @return: insert class instance 375 @todo: allow optional type checking of params? 376 @warning: this will take invalid keys happily and do what??? 377 ''' 378 import sqlhelp 379 i = sqlhelp.insert('alltypesmsg') 380 for key in params: i.add(key,params[key]) 381 if None != extraParams: 382 for key in extraParams: 383 i.add(key,extraParams[key]) 384 385 return i
386 387 388 ###################################################################### 389 # UNIT TESTING 390 ###################################################################### 391 import unittest
392 -def testParams():
393 '''Return a params file base on the testvalue tags. 394 @rtype: dict 395 @return: params based on testvalue tags 396 ''' 397 params = {} 398 params['dac'] = 366 399 params['reqDecimal'] = Decimal('122') 400 params['unavail_uint'] = 2 401 params['anUInt'] = 1 402 params['anInt'] = -1 403 params['aBool'] = True 404 params['aStr'] = 'ASDF1' 405 params['anUDecimal'] = Decimal('9.5') 406 params['aDecimal'] = Decimal('-9.6') 407 params['aFloat'] = -1234.5678 408 409 return params
410
411 -class Testalltypesmsg(unittest.TestCase):
412 '''Use testvalue tag text from each type to build test case the alltypesmsg message'''
413 - def testEncodeDecode(self):
414 415 params = testParams() 416 bits = encode(params) 417 r = decode(bits) 418 419 # Check that each parameter came through ok. 420 self.failUnlessEqual(r['dac'],params['dac']) 421 self.failUnlessAlmostEqual(r['reqDecimal'],params['reqDecimal'],0) 422 self.failUnlessEqual(r['unavail_uint'],params['unavail_uint']) 423 self.failUnlessEqual(r['anUInt'],params['anUInt']) 424 self.failUnlessEqual(r['anInt'],params['anInt']) 425 self.failUnlessEqual(r['aBool'],params['aBool']) 426 self.failUnlessEqual(r['aStr'],params['aStr']) 427 self.failUnlessAlmostEqual(r['anUDecimal'],params['anUDecimal'],1) 428 self.failUnlessAlmostEqual(r['aDecimal'],params['aDecimal'],0) 429 self.failUnlessAlmostEqual(r['aFloat'],params['aFloat'],3)
430
431 -def addMsgOptions(parser):
432 parser.add_option('-d','--decode',dest='doDecode',default=False,action='store_true', 433 help='decode a "alltypesmsg" AIS message') 434 parser.add_option('-e','--encode',dest='doEncode',default=False,action='store_true', 435 help='encode a "alltypesmsg" AIS message') 436 parser.add_option('--unavail_uint-field', dest='unavail_uintField',default=3,metavar='uint',type='int' 437 ,help='Field parameter value [default: %default]') 438 parser.add_option('--anUInt-field', dest='anUIntField',metavar='uint',type='int' 439 ,help='Field parameter value [default: %default]') 440 parser.add_option('--anInt-field', dest='anIntField',metavar='int',type='int' 441 ,help='Field parameter value [default: %default]') 442 parser.add_option('--aBool-field', dest='aBoolField',metavar='bool',type='int' 443 ,help='Field parameter value [default: %default]') 444 parser.add_option('--aStr-field', dest='aStrField',metavar='aisstr6',type='string' 445 ,help='Field parameter value [default: %default]') 446 parser.add_option('--anUDecimal-field', dest='anUDecimalField',metavar='udecimal',type='string' 447 ,help='Field parameter value [default: %default]') 448 parser.add_option('--aDecimal-field', dest='aDecimalField',metavar='decimal',type='string' 449 ,help='Field parameter value [default: %default]') 450 parser.add_option('--aFloat-field', dest='aFloatField',metavar='float',type='float' 451 ,help='Field parameter value [default: %default]')
452 453 ############################################################ 454 if __name__=='__main__': 455 456 from optparse import OptionParser 457 parser = OptionParser(usage="%prog [options]", 458 version="%prog "+__version__) 459 460 parser.add_option('--doc-test',dest='doctest',default=False,action='store_true', 461 help='run the documentation tests') 462 parser.add_option('--unit-test',dest='unittest',default=False,action='store_true', 463 help='run the unit tests') 464 parser.add_option('-v','--verbose',dest='verbose',default=False,action='store_true', 465 help='Make the test output verbose') 466 467 # FIX: remove nmea from binary messages. No way to build the whole packet? 468 # FIX: or build the surrounding msg 8 for a broadcast? 469 typeChoices = ('binary','nmeapayload','nmea') # FIX: what about a USCG type message? 470 parser.add_option('-t','--type',choices=typeChoices,type='choice',dest='ioType' 471 ,default='nmeapayload' 472 ,help='What kind of string to expect ('+', '.join(typeChoices)+') [default: %default]') 473 474 475 outputChoices = ('std','html','csv','sql' ) 476 parser.add_option('-T','--output-type',choices=outputChoices,type='choice',dest='outputType' 477 ,default='std' 478 ,help='What kind of string to output ('+', '.join(outputChoices)+') [default: %default]') 479 480 parser.add_option('-o','--output',dest='outputFileName',default=None, 481 help='Name of the python file to write [default: stdout]') 482 483 parser.add_option('-f','--fields',dest='fieldList',default=None, action='append', 484 choices=fieldList, 485 help='Which fields to include in the output. Currently only for csv output [default: all]') 486 487 parser.add_option('-p','--print-csv-field-list',dest='printCsvfieldList',default=False,action='store_true', 488 help='Print the field name for csv') 489 490 parser.add_option('-c','--sql-create',dest='sqlCreate',default=False,action='store_true', 491 help='Print out an sql create command for the table.') 492 493 addMsgOptions(parser) 494 495 (options,args) = parser.parse_args() 496 success=True 497 498 if options.doctest: 499 import os; print os.path.basename(sys.argv[0]), 'doctests ...', 500 sys.argv= [sys.argv[0]] 501 if options.verbose: sys.argv.append('-v') 502 import doctest 503 numfail,numtests=doctest.testmod() 504 if numfail==0: print 'ok' 505 else: 506 print 'FAILED' 507 success=False 508 509 if not success: sys.exit('Something Failed') 510 del success # Hide success from epydoc 511 512 if options.unittest: 513 sys.argv = [sys.argv[0]] 514 if options.verbose: sys.argv.append('-v') 515 unittest.main() 516 517 outfile = sys.stdout 518 if None!=options.outputFileName: 519 outfile = file(options.outputFileName,'w') 520 521 522 if options.doEncode: 523 # First make sure all non required options are specified 524 if None==options.unavail_uintField: parser.error("missing value for unavail_uintField") 525 if None==options.anUIntField: parser.error("missing value for anUIntField") 526 if None==options.anIntField: parser.error("missing value for anIntField") 527 if None==options.aBoolField: parser.error("missing value for aBoolField") 528 if None==options.aStrField: parser.error("missing value for aStrField") 529 if None==options.anUDecimalField: parser.error("missing value for anUDecimalField") 530 if None==options.aDecimalField: parser.error("missing value for aDecimalField") 531 if None==options.aFloatField: parser.error("missing value for aFloatField") 532 msgDict={ 533 'dac': '366', 534 'reqDecimal': '122', 535 'unavail_uint': options.unavail_uintField, 536 'anUInt': options.anUIntField, 537 'anInt': options.anIntField, 538 'aBool': options.aBoolField, 539 'aStr': options.aStrField, 540 'anUDecimal': options.anUDecimalField, 541 'aDecimal': options.aDecimalField, 542 'aFloat': options.aFloatField, 543 } 544 545 bits = encode(msgDict) 546 if 'binary'==options.ioType: print str(bits) 547 elif 'nmeapayload'==options.ioType: 548 # FIX: figure out if this might be necessary at compile time 549 print "bitLen",len(bits) 550 bitLen=len(bits) 551 if bitLen%6!=0: 552 bits = bits + BitVector(size=(6 - (bitLen%6))) # Pad out to multiple of 6 553 print "result:",binary.bitvectoais6(bits)[0] 554 555 556 # FIX: Do not emit this option for the binary message payloads. Does not make sense. 557 elif 'nmea'==options.ioType: sys.exit("FIX: need to implement this capability") 558 else: sys.exit('ERROR: unknown ioType. Help!') 559 560 561 if options.sqlCreate: 562 sqlCreateStr(outfile,options.fieldList) 563 564 if options.printCsvfieldList: 565 # Make a csv separated list of fields that will be displayed for csv 566 if None == options.fieldList: options.fieldList = fieldList 567 import StringIO 568 buf = StringIO.StringIO() 569 for field in options.fieldList: 570 buf.write(field+',') 571 result = buf.getvalue() 572 if result[-1] == ',': print result[:-1] 573 else: print result 574 575 if options.doDecode: 576 for msg in args: 577 bv = None 578 if 'binary' == options.ioType: bv = BitVector(bitstring=msg) 579 elif 'nmeapayload'== options.ioType: bv = binary.ais6tobitvec(msg) 580 elif 'nmea' == options.ioType: bv = binary.ais6tobitvec(msg.split(',')[5]) 581 else: sys.exit('ERROR: unknown ioType. Help!') 582 583 printFields(decode(bv),out=outfile,format=options.outputType,fieldList=options.fieldList) 584