1
2
3 __version__ = '$Revision: 4791 $'.split()[1]
4 __date__ = '$Date: 2007-01-04 $'.split()[1]
5 __author__ = 'xmlbinmsg'
6
7 __doc__='''
8
9 Dump a waterlevel message from the nmea msg 8. This should be built
10 in to the binary messages. They need to be able to handle themselve.s
11
12 @requires: U{epydoc<http://epydoc.sourceforge.net/>} > 3.0alpha3
13 @requires: U{BitVector<http://cheeseshop.python.org/pypi/BitVector>}
14
15 @author: '''+__author__+'''
16 @version: ''' + __version__ +'''
17 @var __date__: Date of last svn commit
18 @undocumented: __version__ __author__ __doc__ parser
19 @status: under development
20 @license: Generated code has no license
21 '''
22
23 import sys
24 from decimal import Decimal
25 from BitVector import BitVector
26
27 import binary, aisstring
28
29
30
31 if __name__=='__main__':
32
33 from optparse import OptionParser
34 parser = OptionParser(usage="%prog [options]",
35 version="%prog "+__version__)
36
37 parser.add_option('--doc-test',dest='doctest',default=False,action='store_true',
38 help='run the documentation tests')
39 parser.add_option('--unit-test',dest='unittest',default=False,action='store_true',
40 help='run the unit tests')
41 parser.add_option('-v','--verbose',dest='verbose',default=False,action='store_true',
42 help='Make the test output verbose')
43
44 inputChoices = ('binary','nmeapayload','nmea')
45 parser.add_option('-t','--input=type',choices=inputChoices,type='choice',dest='inputType'
46 ,default='nmea'
47 ,help='What kind of string to expect ('+', '.join(inputChoices)+') [default: %default]')
48
49 outputChoices = ('std','html','xml')
50 parser.add_option('-T','--output-type',choices=outputChoices,type='choice',dest='outputType'
51 ,default='std'
52 ,help='What kind of string to output ('+', '.join(outputChoices)+') [default: %default]')
53
54 parser.add_option('-o','--output',dest='outputFileName',default=None,
55 help='Name of the python file to write [default: stdout]')
56
57 (options,args) = parser.parse_args()
58 success=True
59
60 if options.doctest:
61 import os; print os.path.basename(sys.argv[0]), 'doctests ...',
62 sys.argv= [sys.argv[0]]
63 if options.verbose: sys.argv.append('-v')
64 import doctest
65 numfail,numtests=doctest.testmod()
66 if numfail==0: print 'ok'
67 else:
68 print 'FAILED'
69 success=False
70
71 if not success: sys.exit('Something Failed')
72 del success
73
74 if options.unittest:
75 sys.argv = [sys.argv[0]]
76 if options.verbose: sys.argv.append('-v')
77 unittest.main()
78
79
80 outfile = sys.stdout
81 if None!=options.outputFileName:
82 outfile = file(options.outputFileName,'w')
83
84 bv=None
85 for msg in args:
86 if 'binary' == options.inputType: bv = BitVector(bitstring=msg)
87 elif 'nmeapayload' == options.inputType: bv = binary.ais6tobitvec(msg)
88 elif 'nmea' == options.inputType: bv = binary.ais6tobitvec(msg.split(',')[5])
89 else: sys.exit('ERROR: unknown inputType. Help!')
90
91 import ais_msg_8 as m8
92 m8dict = m8.decode(bv)
93 import waterlevel as wl
94 wl.printFields(wl.decode(m8dict['BinaryData']),out=outfile,format=options.outputType)
95