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

Source Code for Module ais.exampleParser

  1  #!/usr/bin/env python 
  2   
  3  __version__ = '$Revision: 4791 $'.split()[1] 
  4  __date__ = '$Date: 2006-10-18 $'.split()[1] 
  5  __author__ = 'xmlbinmsg' 
  6   
  7  __doc__=''' 
  8   
  9  Autogenerated python functions to serialize/deserialize binary messages. 
 10   
 11  WRITTEN BY HAND.  THIS VERSION IS FOR ME TO WRITE THE CODE BEFORE 
 12  HAND.  Then I can create the code generator. 
 13   
 14   
 15  Generated by: ./xmlbinmsg.py 
 16   
 17  Need to then wrap these functions with the outer AIS packet and then 
 18  convert the whole binary blob to a NMEA string.  Those functions are 
 19  not currently provided in this file. 
 20   
 21  serialize: python to ais binary 
 22  deserialize: ais binary to python 
 23   
 24  The generated code uses translators.py, binary.py, and aisstring.py 
 25  which should be packaged with the resulting files. 
 26   
 27   
 28  @requires: U{epydoc<http://epydoc.sourceforge.net/>} > 3.0alpha3 
 29  @requires: U{BitVector<http://cheeseshop.python.org/pypi/BitVector>} 
 30   
 31  @author: '''+__author__+''' 
 32  @version: ''' + __version__ +''' 
 33  @var __date__: Date of last svn commit 
 34  @undocumented: __version__ __author__ __doc__ myparser 
 35  @status: under development 
 36  @license: Generated code has no license 
 37  ''' 
 38   
 39  import sys 
 40  from decimal import Decimal 
 41  from BitVector import BitVector 
 42   
 43  import binary 
44 -def waterlevelEncode(*aDict, **params):
45 '''Serializer for the waterlevel binary message 46 47 Keywords and types: 48 49 - dac: uint 50 - unavail_uint: uint 51 - uint: uint 52 FIX: generate CORRECT doctest string that does all the defaults 53 54 The default message: 55 56 >>> print waterlevelEncode() 57 1011011101100 58 59 @param aDict: for passing in a dictionary of keyword and values. 60 @param params: keyword dictionary or if a dict is passed, it will use that dict 61 @note: only use one of aDict or params 62 ''' 63 64 if len(aDict) > 1: 65 assert(False and 'Illegal call to with more than one param') 66 if len(aDict) == 1: 67 if not isinstance(dict,aDict): 68 assert(False and 'a single parameter must be a dictionary of key values') 69 if len(params)>0: 70 assert(False and 'Must not specify both a lookup table and keyvalues') 71 params=aDict 72 73 bvList = [] 74 75 76 ### FIELD: dac (type=uint) REQUIRED CONSTANT FIELD 77 bvList.append(binary.setBitVectorSize(BitVector(intVal=366))) 78 79 ### FIELD: unavail_uint (type=uint) 80 if 'unavail_uint' in params: bvList.append(binary.setBitVectorSize(BitVector(intVal=param[unavail_uint]),2)) 81 else: bvList.append(binary.setBitVectorSize(BitVector(intVal=3),2)) 82 83 ### FIELD: uint (type=uint) 84 if 'uint' in params: bvList.append(binary.setBitVectorSize(BitVector(intVal=param[uint]),2)) 85 else: bvList.append(BitVector(size=2)) 86 return binary.joinBV(bvList)
87 88 ############################################################ 89 if __name__=='__main__': 90 print waterlevelEncode() 91 from optparse import OptionParser 92 myparser = OptionParser(usage="%prog [options]", 93 version="%prog "+__version__) 94 95 #sys.exit('EARLY EXIT - FIX: remove') 96 myparser.add_option('--doc-test',dest='doctest',default=False,action='store_true', 97 help='run the documentation tests') 98 myparser.add_option('--unit-test',dest='unittest',default=False,action='store_true', 99 help='run the unit tests') 100 myparser.add_option('-v','--verbose',dest='verbose',default=False,action='store_true', 101 help='Make the test output verbose') 102 103 (options,args) = myparser.parse_args() 104 success=True 105 106 if options.doctest: 107 import os; print os.path.basename(sys.argv[0]), 'doctests ...', 108 sys.argv= [sys.argv[0]] 109 if options.verbose: sys.argv+='-v' 110 import doctest 111 numfail,numtests=doctest.testmod() 112 if numfail==0: print 'ok' 113 else: 114 print 'FAILED' 115 success=False 116 117 if not success: 118 sys.exit('Something Failed') 119 120 del success # Hide success from epydoc 121 122 123 if options.unittest: 124 sys.argv = [sys.argv[0]] 125 if options.verbose: sys.argv+='-v' 126 print 'Currently no unit tests' 127 #unittest.main() 128