1
2
3 __version__ = '$Revision: 4791 $'.split()[1]
4 __date__ = '$Date: 2007-11-07 $'.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
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 'SeqNum',
54 'DestinationID',
55 'RetransmitFlag',
56 'Spare',
57 'dac',
58 'fid',
59 'month',
60 'day',
61 'window1_longitude',
62 'window1_latitude',
63 'fromhour1',
64 'frommin1',
65 'tohour1',
66 'tomin1',
67 'curdir1',
68 'curspeed1',
69 'window2_longitude',
70 'window2_latitude',
71 'fromhour2',
72 'frommin2',
73 'tohour2',
74 'tomin2',
75 'curdir2',
76 'curspeed2',
77 'window3_longitude',
78 'window3_latitude',
79 'fromhour3',
80 'frommin3',
81 'tohour3',
82 'tomin3',
83 'curdir3',
84 'curspeed3',
85 )
86
87 fieldListPostgres = (
88 'MessageID',
89 'RepeatIndicator',
90 'UserID',
91 'SeqNum',
92 'DestinationID',
93 'RetransmitFlag',
94 'Spare',
95 'dac',
96 'fid',
97 'month',
98 'day',
99 'window1',
100 'fromhour1',
101 'frommin1',
102 'tohour1',
103 'tomin1',
104 'curdir1',
105 'curspeed1',
106 'window2',
107 'fromhour2',
108 'frommin2',
109 'tohour2',
110 'tomin2',
111 'curdir2',
112 'curspeed2',
113 'window3',
114 'fromhour3',
115 'frommin3',
116 'tohour3',
117 'tomin3',
118 'curdir3',
119 'curspeed3',
120 )
121
122 toPgFields = {
123 'window1_longitude':'window1',
124 'window1_latitude':'window1',
125 'window2_longitude':'window2',
126 'window2_latitude':'window2',
127 'window3_longitude':'window3',
128 'window3_latitude':'window3',
129 }
130 '''
131 Go to the Postgis field names from the straight field name
132 '''
133
134 fromPgFields = {
135 'window1':('window1_longitude','window1_latitude',),
136 'window2':('window2_longitude','window2_latitude',),
137 'window3':('window3_longitude','window3_latitude',),
138 }
139 '''
140 Go from the Postgis field names to the straight field name
141 '''
142
143 pgTypes = {
144 'window1':'POINT',
145 'window2':'POINT',
146 'window3':'POINT',
147 }
148 '''
149 Lookup table for each postgis field name to get its type.
150 '''
151
152 -def encode(params, validate=False):
153 '''Create a imo_tidal_window binary message payload to pack into an AIS Msg imo_tidal_window.
154
155 Fields in params:
156 - MessageID(uint): AIS message number. Must be 6 (field automatically set to "6")
157 - RepeatIndicator(uint): Indicated how many times a message has been repeated
158 - UserID(uint): MMSI number of transmitter broadcasting the message
159 - SeqNum(uint): Sequence number as described in 5.3.1. Assigned to each station
160 - DestinationID(uint): Unique ship identification number (MMSI)
161 - RetransmitFlag(bool): Should be set upon retransmission
162 - Spare(uint): Must be 0 (field automatically set to "0")
163 - dac(uint): Designated Area Code - part 1 of the IAI (field automatically set to "1")
164 - fid(uint): Functional Identifier - part 2 of the IAI (field automatically set to "11")
165 - month(uint): UTC month
166 - day(uint): UTC day
167 - window1_longitude(decimal): Not sure what this position is for? Center? East West location
168 - window1_latitude(decimal): Not sure what this position is for? Center? North South location
169 - fromhour1(uint): From UTC hour
170 - frommin1(uint): From UTC minute
171 - tohour1(uint): To UTC hour
172 - tomin1(uint): To UTC minute
173 - curdir1(uint): Current direction
174 - curspeed1(udecimal): Current speed
175 - window2_longitude(decimal): Not sure what this position is for? Center? East West location
176 - window2_latitude(decimal): Not sure what this position is for? Center? North South location
177 - fromhour2(uint): From UTC hour
178 - frommin2(uint): From UTC minute
179 - tohour2(uint): To UTC hour
180 - tomin2(uint): To UTC minute
181 - curdir2(uint): Current direction
182 - curspeed2(udecimal): Current speed
183 - window3_longitude(decimal): Not sure what this position is for? Center? East West location
184 - window3_latitude(decimal): Not sure what this position is for? Center? North South location
185 - fromhour3(uint): From UTC hour
186 - frommin3(uint): From UTC minute
187 - tohour3(uint): To UTC hour
188 - tomin3(uint): To UTC minute
189 - curdir3(uint): Current direction
190 - curspeed3(udecimal): Current speed
191 @param params: Dictionary of field names/values. Throws a ValueError exception if required is missing
192 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented.
193 @rtype: BitVector
194 @return: encoded binary message (for binary messages, this needs to be wrapped in a msg 8
195 @note: The returned bits may not be 6 bit aligned. It is up to you to pad out the bits.
196 '''
197
198 bvList = []
199 bvList.append(binary.setBitVectorSize(BitVector(intVal=6),6))
200 if 'RepeatIndicator' in params:
201 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
202 else:
203 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
204 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
205 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SeqNum']),2))
206 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestinationID']),30))
207 if params["RetransmitFlag"]: bvList.append(TrueBV)
208 else: bvList.append(FalseBV)
209 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),1))
210 bvList.append(binary.setBitVectorSize(BitVector(intVal=1),10))
211 bvList.append(binary.setBitVectorSize(BitVector(intVal=11),6))
212 if 'month' in params:
213 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['month']),4))
214 else:
215 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4))
216 if 'day' in params:
217 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['day']),5))
218 else:
219 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),5))
220 if 'window1_longitude' in params:
221 bvList.append(binary.bvFromSignedInt(int(Decimal(params['window1_longitude'])*Decimal('600000')),28))
222 else:
223 bvList.append(binary.bvFromSignedInt(108600000,28))
224 if 'window1_latitude' in params:
225 bvList.append(binary.bvFromSignedInt(int(Decimal(params['window1_latitude'])*Decimal('600000')),27))
226 else:
227 bvList.append(binary.bvFromSignedInt(54600000,27))
228 if 'fromhour1' in params:
229 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['fromhour1']),5))
230 else:
231 bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
232 if 'frommin1' in params:
233 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['frommin1']),6))
234 else:
235 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
236 if 'tohour1' in params:
237 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tohour1']),5))
238 else:
239 bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
240 if 'tomin1' in params:
241 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tomin1']),6))
242 else:
243 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
244 if 'curdir1' in params:
245 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['curdir1']),9))
246 else:
247 bvList.append(binary.setBitVectorSize(BitVector(intVal=360),9))
248 if 'curspeed1' in params:
249 bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['curspeed1'])*Decimal('10')))),7))
250 else:
251 bvList.append(binary.setBitVectorSize(BitVector(intVal=int(127)),7))
252 if 'window2_longitude' in params:
253 bvList.append(binary.bvFromSignedInt(int(Decimal(params['window2_longitude'])*Decimal('600000')),28))
254 else:
255 bvList.append(binary.bvFromSignedInt(108600000,28))
256 if 'window2_latitude' in params:
257 bvList.append(binary.bvFromSignedInt(int(Decimal(params['window2_latitude'])*Decimal('600000')),27))
258 else:
259 bvList.append(binary.bvFromSignedInt(54600000,27))
260 if 'fromhour2' in params:
261 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['fromhour2']),5))
262 else:
263 bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
264 if 'frommin2' in params:
265 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['frommin2']),6))
266 else:
267 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
268 if 'tohour2' in params:
269 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tohour2']),5))
270 else:
271 bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
272 if 'tomin2' in params:
273 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tomin2']),6))
274 else:
275 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
276 if 'curdir2' in params:
277 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['curdir2']),9))
278 else:
279 bvList.append(binary.setBitVectorSize(BitVector(intVal=360),9))
280 if 'curspeed2' in params:
281 bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['curspeed2'])*Decimal('10')))),7))
282 else:
283 bvList.append(binary.setBitVectorSize(BitVector(intVal=int(127)),7))
284 if 'window3_longitude' in params:
285 bvList.append(binary.bvFromSignedInt(int(Decimal(params['window3_longitude'])*Decimal('600000')),28))
286 else:
287 bvList.append(binary.bvFromSignedInt(108600000,28))
288 if 'window3_latitude' in params:
289 bvList.append(binary.bvFromSignedInt(int(Decimal(params['window3_latitude'])*Decimal('600000')),27))
290 else:
291 bvList.append(binary.bvFromSignedInt(54600000,27))
292 if 'fromhour3' in params:
293 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['fromhour3']),5))
294 else:
295 bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
296 if 'frommin3' in params:
297 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['frommin3']),6))
298 else:
299 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
300 if 'tohour3' in params:
301 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tohour3']),5))
302 else:
303 bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
304 if 'tomin3' in params:
305 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tomin3']),6))
306 else:
307 bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
308 if 'curdir3' in params:
309 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['curdir3']),9))
310 else:
311 bvList.append(binary.setBitVectorSize(BitVector(intVal=360),9))
312 if 'curspeed3' in params:
313 bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['curspeed3'])*Decimal('10')))),7))
314 else:
315 bvList.append(binary.setBitVectorSize(BitVector(intVal=int(127)),7))
316
317 return binary.joinBV(bvList)
318
319 -def decode(bv, validate=False):
320 '''Unpack a imo_tidal_window message
321
322 Fields in params:
323 - MessageID(uint): AIS message number. Must be 6 (field automatically set to "6")
324 - RepeatIndicator(uint): Indicated how many times a message has been repeated
325 - UserID(uint): MMSI number of transmitter broadcasting the message
326 - SeqNum(uint): Sequence number as described in 5.3.1. Assigned to each station
327 - DestinationID(uint): Unique ship identification number (MMSI)
328 - RetransmitFlag(bool): Should be set upon retransmission
329 - Spare(uint): Must be 0 (field automatically set to "0")
330 - dac(uint): Designated Area Code - part 1 of the IAI (field automatically set to "1")
331 - fid(uint): Functional Identifier - part 2 of the IAI (field automatically set to "11")
332 - month(uint): UTC month
333 - day(uint): UTC day
334 - window1_longitude(decimal): Not sure what this position is for? Center? East West location
335 - window1_latitude(decimal): Not sure what this position is for? Center? North South location
336 - fromhour1(uint): From UTC hour
337 - frommin1(uint): From UTC minute
338 - tohour1(uint): To UTC hour
339 - tomin1(uint): To UTC minute
340 - curdir1(uint): Current direction
341 - curspeed1(udecimal): Current speed
342 - window2_longitude(decimal): Not sure what this position is for? Center? East West location
343 - window2_latitude(decimal): Not sure what this position is for? Center? North South location
344 - fromhour2(uint): From UTC hour
345 - frommin2(uint): From UTC minute
346 - tohour2(uint): To UTC hour
347 - tomin2(uint): To UTC minute
348 - curdir2(uint): Current direction
349 - curspeed2(udecimal): Current speed
350 - window3_longitude(decimal): Not sure what this position is for? Center? East West location
351 - window3_latitude(decimal): Not sure what this position is for? Center? North South location
352 - fromhour3(uint): From UTC hour
353 - frommin3(uint): From UTC minute
354 - tohour3(uint): To UTC hour
355 - tomin3(uint): To UTC minute
356 - curdir3(uint): Current direction
357 - curspeed3(udecimal): Current speed
358 @type bv: BitVector
359 @param bv: Bits defining a message
360 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented.
361 @rtype: dict
362 @return: params
363 '''
364
365
366
367
368 r = {}
369 r['MessageID']=6
370 r['RepeatIndicator']=int(bv[6:8])
371 r['UserID']=int(bv[8:38])
372 r['SeqNum']=int(bv[38:40])
373 r['DestinationID']=int(bv[40:70])
374 r['RetransmitFlag']=bool(int(bv[70:71]))
375 r['Spare']=0
376 r['dac']=1
377 r['fid']=11
378 r['month']=int(bv[88:92])
379 r['day']=int(bv[92:97])
380 r['window1_longitude']=Decimal(binary.signedIntFromBV(bv[97:125]))/Decimal('600000')
381 r['window1_latitude']=Decimal(binary.signedIntFromBV(bv[125:152]))/Decimal('600000')
382 r['fromhour1']=int(bv[152:157])
383 r['frommin1']=int(bv[157:163])
384 r['tohour1']=int(bv[163:168])
385 r['tomin1']=int(bv[168:174])
386 r['curdir1']=int(bv[174:183])
387 r['curspeed1']=Decimal(int(bv[183:190]))/Decimal('10')
388 r['window2_longitude']=Decimal(binary.signedIntFromBV(bv[190:218]))/Decimal('600000')
389 r['window2_latitude']=Decimal(binary.signedIntFromBV(bv[218:245]))/Decimal('600000')
390 r['fromhour2']=int(bv[245:250])
391 r['frommin2']=int(bv[250:256])
392 r['tohour2']=int(bv[256:261])
393 r['tomin2']=int(bv[261:267])
394 r['curdir2']=int(bv[267:276])
395 r['curspeed2']=Decimal(int(bv[276:283]))/Decimal('10')
396 r['window3_longitude']=Decimal(binary.signedIntFromBV(bv[283:311]))/Decimal('600000')
397 r['window3_latitude']=Decimal(binary.signedIntFromBV(bv[311:338]))/Decimal('600000')
398 r['fromhour3']=int(bv[338:343])
399 r['frommin3']=int(bv[343:349])
400 r['tohour3']=int(bv[349:354])
401 r['tomin3']=int(bv[354:360])
402 r['curdir3']=int(bv[360:369])
403 r['curspeed3']=Decimal(int(bv[369:376]))/Decimal('10')
404 return r
405
408
411
414
416 return int(bv[38:40])
417
419 return int(bv[40:70])
420
422 return bool(int(bv[70:71]))
423
426
429
432
434 return int(bv[88:92])
435
437 return int(bv[92:97])
438
441
444
446 return int(bv[152:157])
447
449 return int(bv[157:163])
450
452 return int(bv[163:168])
453
455 return int(bv[168:174])
456
458 return int(bv[174:183])
459
461 return Decimal(int(bv[183:190]))/Decimal('10')
462
465
468
470 return int(bv[245:250])
471
473 return int(bv[250:256])
474
476 return int(bv[256:261])
477
479 return int(bv[261:267])
480
482 return int(bv[267:276])
483
485 return Decimal(int(bv[276:283]))/Decimal('10')
486
489
492
494 return int(bv[338:343])
495
497 return int(bv[343:349])
498
500 return int(bv[349:354])
501
503 return int(bv[354:360])
504
506 return int(bv[360:369])
507
509 return Decimal(int(bv[369:376]))/Decimal('10')
510
511
513 out.write("<h3>imo_tidal_window</h3>\n")
514 out.write("<table border=\"1\">\n")
515 out.write("<tr bgcolor=\"orange\">\n")
516 out.write("<th align=\"left\">Field Name</th>\n")
517 out.write("<th align=\"left\">Type</th>\n")
518 out.write("<th align=\"left\">Value</th>\n")
519 out.write("<th align=\"left\">Value in Lookup Table</th>\n")
520 out.write("<th align=\"left\">Units</th>\n")
521 out.write("\n")
522 out.write("<tr>\n")
523 out.write("<td>MessageID</td>\n")
524 out.write("<td>uint</td>\n")
525 if 'MessageID' in params:
526 out.write(" <td>"+str(params['MessageID'])+"</td>\n")
527 out.write(" <td>"+str(params['MessageID'])+"</td>\n")
528 out.write("</tr>\n")
529 out.write("\n")
530 out.write("<tr>\n")
531 out.write("<td>RepeatIndicator</td>\n")
532 out.write("<td>uint</td>\n")
533 if 'RepeatIndicator' in params:
534 out.write(" <td>"+str(params['RepeatIndicator'])+"</td>\n")
535 if str(params['RepeatIndicator']) in RepeatIndicatorDecodeLut:
536 out.write("<td>"+RepeatIndicatorDecodeLut[str(params['RepeatIndicator'])]+"</td>")
537 else:
538 out.write("<td><i>Missing LUT entry</i></td>")
539 out.write("</tr>\n")
540 out.write("\n")
541 out.write("<tr>\n")
542 out.write("<td>UserID</td>\n")
543 out.write("<td>uint</td>\n")
544 if 'UserID' in params:
545 out.write(" <td>"+str(params['UserID'])+"</td>\n")
546 out.write(" <td>"+str(params['UserID'])+"</td>\n")
547 out.write("</tr>\n")
548 out.write("\n")
549 out.write("<tr>\n")
550 out.write("<td>SeqNum</td>\n")
551 out.write("<td>uint</td>\n")
552 if 'SeqNum' in params:
553 out.write(" <td>"+str(params['SeqNum'])+"</td>\n")
554 out.write(" <td>"+str(params['SeqNum'])+"</td>\n")
555 out.write("</tr>\n")
556 out.write("\n")
557 out.write("<tr>\n")
558 out.write("<td>DestinationID</td>\n")
559 out.write("<td>uint</td>\n")
560 if 'DestinationID' in params:
561 out.write(" <td>"+str(params['DestinationID'])+"</td>\n")
562 out.write(" <td>"+str(params['DestinationID'])+"</td>\n")
563 out.write("</tr>\n")
564 out.write("\n")
565 out.write("<tr>\n")
566 out.write("<td>RetransmitFlag</td>\n")
567 out.write("<td>bool</td>\n")
568 if 'RetransmitFlag' in params:
569 out.write(" <td>"+str(params['RetransmitFlag'])+"</td>\n")
570 if str(params['RetransmitFlag']) in RetransmitFlagDecodeLut:
571 out.write("<td>"+RetransmitFlagDecodeLut[str(params['RetransmitFlag'])]+"</td>")
572 else:
573 out.write("<td><i>Missing LUT entry</i></td>")
574 out.write("</tr>\n")
575 out.write("\n")
576 out.write("<tr>\n")
577 out.write("<td>Spare</td>\n")
578 out.write("<td>uint</td>\n")
579 if 'Spare' in params:
580 out.write(" <td>"+str(params['Spare'])+"</td>\n")
581 out.write(" <td>"+str(params['Spare'])+"</td>\n")
582 out.write("</tr>\n")
583 out.write("\n")
584 out.write("<tr>\n")
585 out.write("<td>dac</td>\n")
586 out.write("<td>uint</td>\n")
587 if 'dac' in params:
588 out.write(" <td>"+str(params['dac'])+"</td>\n")
589 out.write(" <td>"+str(params['dac'])+"</td>\n")
590 out.write("</tr>\n")
591 out.write("\n")
592 out.write("<tr>\n")
593 out.write("<td>fid</td>\n")
594 out.write("<td>uint</td>\n")
595 if 'fid' in params:
596 out.write(" <td>"+str(params['fid'])+"</td>\n")
597 out.write(" <td>"+str(params['fid'])+"</td>\n")
598 out.write("</tr>\n")
599 out.write("\n")
600 out.write("<tr>\n")
601 out.write("<td>month</td>\n")
602 out.write("<td>uint</td>\n")
603 if 'month' in params:
604 out.write(" <td>"+str(params['month'])+"</td>\n")
605 out.write(" <td>"+str(params['month'])+"</td>\n")
606 out.write("</tr>\n")
607 out.write("\n")
608 out.write("<tr>\n")
609 out.write("<td>day</td>\n")
610 out.write("<td>uint</td>\n")
611 if 'day' in params:
612 out.write(" <td>"+str(params['day'])+"</td>\n")
613 out.write(" <td>"+str(params['day'])+"</td>\n")
614 out.write("</tr>\n")
615 out.write("\n")
616 out.write("<tr>\n")
617 out.write("<td>window1_longitude</td>\n")
618 out.write("<td>decimal</td>\n")
619 if 'window1_longitude' in params:
620 out.write(" <td>"+str(params['window1_longitude'])+"</td>\n")
621 out.write(" <td>"+str(params['window1_longitude'])+"</td>\n")
622 out.write("<td>degrees</td>\n")
623 out.write("</tr>\n")
624 out.write("\n")
625 out.write("<tr>\n")
626 out.write("<td>window1_latitude</td>\n")
627 out.write("<td>decimal</td>\n")
628 if 'window1_latitude' in params:
629 out.write(" <td>"+str(params['window1_latitude'])+"</td>\n")
630 out.write(" <td>"+str(params['window1_latitude'])+"</td>\n")
631 out.write("<td>degrees</td>\n")
632 out.write("</tr>\n")
633 out.write("\n")
634 out.write("<tr>\n")
635 out.write("<td>fromhour1</td>\n")
636 out.write("<td>uint</td>\n")
637 if 'fromhour1' in params:
638 out.write(" <td>"+str(params['fromhour1'])+"</td>\n")
639 out.write(" <td>"+str(params['fromhour1'])+"</td>\n")
640 out.write("<td>hours</td>\n")
641 out.write("</tr>\n")
642 out.write("\n")
643 out.write("<tr>\n")
644 out.write("<td>frommin1</td>\n")
645 out.write("<td>uint</td>\n")
646 if 'frommin1' in params:
647 out.write(" <td>"+str(params['frommin1'])+"</td>\n")
648 out.write(" <td>"+str(params['frommin1'])+"</td>\n")
649 out.write("<td>minutes</td>\n")
650 out.write("</tr>\n")
651 out.write("\n")
652 out.write("<tr>\n")
653 out.write("<td>tohour1</td>\n")
654 out.write("<td>uint</td>\n")
655 if 'tohour1' in params:
656 out.write(" <td>"+str(params['tohour1'])+"</td>\n")
657 out.write(" <td>"+str(params['tohour1'])+"</td>\n")
658 out.write("<td>hours</td>\n")
659 out.write("</tr>\n")
660 out.write("\n")
661 out.write("<tr>\n")
662 out.write("<td>tomin1</td>\n")
663 out.write("<td>uint</td>\n")
664 if 'tomin1' in params:
665 out.write(" <td>"+str(params['tomin1'])+"</td>\n")
666 out.write(" <td>"+str(params['tomin1'])+"</td>\n")
667 out.write("<td>minutes</td>\n")
668 out.write("</tr>\n")
669 out.write("\n")
670 out.write("<tr>\n")
671 out.write("<td>curdir1</td>\n")
672 out.write("<td>uint</td>\n")
673 if 'curdir1' in params:
674 out.write(" <td>"+str(params['curdir1'])+"</td>\n")
675 out.write(" <td>"+str(params['curdir1'])+"</td>\n")
676 out.write("<td>degrees</td>\n")
677 out.write("</tr>\n")
678 out.write("\n")
679 out.write("<tr>\n")
680 out.write("<td>curspeed1</td>\n")
681 out.write("<td>udecimal</td>\n")
682 if 'curspeed1' in params:
683 out.write(" <td>"+str(params['curspeed1'])+"</td>\n")
684 out.write(" <td>"+str(params['curspeed1'])+"</td>\n")
685 out.write("<td>knots</td>\n")
686 out.write("</tr>\n")
687 out.write("\n")
688 out.write("<tr>\n")
689 out.write("<td>window2_longitude</td>\n")
690 out.write("<td>decimal</td>\n")
691 if 'window2_longitude' in params:
692 out.write(" <td>"+str(params['window2_longitude'])+"</td>\n")
693 out.write(" <td>"+str(params['window2_longitude'])+"</td>\n")
694 out.write("<td>degrees</td>\n")
695 out.write("</tr>\n")
696 out.write("\n")
697 out.write("<tr>\n")
698 out.write("<td>window2_latitude</td>\n")
699 out.write("<td>decimal</td>\n")
700 if 'window2_latitude' in params:
701 out.write(" <td>"+str(params['window2_latitude'])+"</td>\n")
702 out.write(" <td>"+str(params['window2_latitude'])+"</td>\n")
703 out.write("<td>degrees</td>\n")
704 out.write("</tr>\n")
705 out.write("\n")
706 out.write("<tr>\n")
707 out.write("<td>fromhour2</td>\n")
708 out.write("<td>uint</td>\n")
709 if 'fromhour2' in params:
710 out.write(" <td>"+str(params['fromhour2'])+"</td>\n")
711 out.write(" <td>"+str(params['fromhour2'])+"</td>\n")
712 out.write("<td>hours</td>\n")
713 out.write("</tr>\n")
714 out.write("\n")
715 out.write("<tr>\n")
716 out.write("<td>frommin2</td>\n")
717 out.write("<td>uint</td>\n")
718 if 'frommin2' in params:
719 out.write(" <td>"+str(params['frommin2'])+"</td>\n")
720 out.write(" <td>"+str(params['frommin2'])+"</td>\n")
721 out.write("<td>minutes</td>\n")
722 out.write("</tr>\n")
723 out.write("\n")
724 out.write("<tr>\n")
725 out.write("<td>tohour2</td>\n")
726 out.write("<td>uint</td>\n")
727 if 'tohour2' in params:
728 out.write(" <td>"+str(params['tohour2'])+"</td>\n")
729 out.write(" <td>"+str(params['tohour2'])+"</td>\n")
730 out.write("<td>hours</td>\n")
731 out.write("</tr>\n")
732 out.write("\n")
733 out.write("<tr>\n")
734 out.write("<td>tomin2</td>\n")
735 out.write("<td>uint</td>\n")
736 if 'tomin2' in params:
737 out.write(" <td>"+str(params['tomin2'])+"</td>\n")
738 out.write(" <td>"+str(params['tomin2'])+"</td>\n")
739 out.write("<td>minutes</td>\n")
740 out.write("</tr>\n")
741 out.write("\n")
742 out.write("<tr>\n")
743 out.write("<td>curdir2</td>\n")
744 out.write("<td>uint</td>\n")
745 if 'curdir2' in params:
746 out.write(" <td>"+str(params['curdir2'])+"</td>\n")
747 out.write(" <td>"+str(params['curdir2'])+"</td>\n")
748 out.write("<td>degrees</td>\n")
749 out.write("</tr>\n")
750 out.write("\n")
751 out.write("<tr>\n")
752 out.write("<td>curspeed2</td>\n")
753 out.write("<td>udecimal</td>\n")
754 if 'curspeed2' in params:
755 out.write(" <td>"+str(params['curspeed2'])+"</td>\n")
756 out.write(" <td>"+str(params['curspeed2'])+"</td>\n")
757 out.write("<td>knots</td>\n")
758 out.write("</tr>\n")
759 out.write("\n")
760 out.write("<tr>\n")
761 out.write("<td>window3_longitude</td>\n")
762 out.write("<td>decimal</td>\n")
763 if 'window3_longitude' in params:
764 out.write(" <td>"+str(params['window3_longitude'])+"</td>\n")
765 out.write(" <td>"+str(params['window3_longitude'])+"</td>\n")
766 out.write("<td>degrees</td>\n")
767 out.write("</tr>\n")
768 out.write("\n")
769 out.write("<tr>\n")
770 out.write("<td>window3_latitude</td>\n")
771 out.write("<td>decimal</td>\n")
772 if 'window3_latitude' in params:
773 out.write(" <td>"+str(params['window3_latitude'])+"</td>\n")
774 out.write(" <td>"+str(params['window3_latitude'])+"</td>\n")
775 out.write("<td>degrees</td>\n")
776 out.write("</tr>\n")
777 out.write("\n")
778 out.write("<tr>\n")
779 out.write("<td>fromhour3</td>\n")
780 out.write("<td>uint</td>\n")
781 if 'fromhour3' in params:
782 out.write(" <td>"+str(params['fromhour3'])+"</td>\n")
783 out.write(" <td>"+str(params['fromhour3'])+"</td>\n")
784 out.write("<td>hours</td>\n")
785 out.write("</tr>\n")
786 out.write("\n")
787 out.write("<tr>\n")
788 out.write("<td>frommin3</td>\n")
789 out.write("<td>uint</td>\n")
790 if 'frommin3' in params:
791 out.write(" <td>"+str(params['frommin3'])+"</td>\n")
792 out.write(" <td>"+str(params['frommin3'])+"</td>\n")
793 out.write("<td>minutes</td>\n")
794 out.write("</tr>\n")
795 out.write("\n")
796 out.write("<tr>\n")
797 out.write("<td>tohour3</td>\n")
798 out.write("<td>uint</td>\n")
799 if 'tohour3' in params:
800 out.write(" <td>"+str(params['tohour3'])+"</td>\n")
801 out.write(" <td>"+str(params['tohour3'])+"</td>\n")
802 out.write("<td>hours</td>\n")
803 out.write("</tr>\n")
804 out.write("\n")
805 out.write("<tr>\n")
806 out.write("<td>tomin3</td>\n")
807 out.write("<td>uint</td>\n")
808 if 'tomin3' in params:
809 out.write(" <td>"+str(params['tomin3'])+"</td>\n")
810 out.write(" <td>"+str(params['tomin3'])+"</td>\n")
811 out.write("<td>minutes</td>\n")
812 out.write("</tr>\n")
813 out.write("\n")
814 out.write("<tr>\n")
815 out.write("<td>curdir3</td>\n")
816 out.write("<td>uint</td>\n")
817 if 'curdir3' in params:
818 out.write(" <td>"+str(params['curdir3'])+"</td>\n")
819 out.write(" <td>"+str(params['curdir3'])+"</td>\n")
820 out.write("<td>degrees</td>\n")
821 out.write("</tr>\n")
822 out.write("\n")
823 out.write("<tr>\n")
824 out.write("<td>curspeed3</td>\n")
825 out.write("<td>udecimal</td>\n")
826 if 'curspeed3' in params:
827 out.write(" <td>"+str(params['curspeed3'])+"</td>\n")
828 out.write(" <td>"+str(params['curspeed3'])+"</td>\n")
829 out.write("<td>knots</td>\n")
830 out.write("</tr>\n")
831 out.write("</table>\n")
832
833
835 '''KML (Keyhole Markup Language) for Google Earth, but without the header/footer'''
836 out.write("\ <Placemark>\n")
837 out.write("\t <name>"+str(params['UserID'])+"</name>\n")
838 out.write("\t\t<description>\n")
839 import StringIO
840 buf = StringIO.StringIO()
841 printHtml(params,buf)
842 import cgi
843 out.write(cgi.escape(buf.getvalue()))
844 out.write("\t\t</description>\n")
845 out.write("\t\t<styleUrl>#m_ylw-pushpin_copy0</styleUrl>\n")
846 out.write("\t\t<Point>\n")
847 out.write("\t\t\t<coordinates>")
848 out.write(str(params['window1_longitude']))
849 out.write(',')
850 out.write(str(params['window1_latitude']))
851 out.write(",0</coordinates>\n")
852 out.write("\t\t</Point>\n")
853 out.write("\t</Placemark>\n")
854
855 -def printFields(params, out=sys.stdout, format='std', fieldList=None, dbType='postgres'):
856 '''Print a imo_tidal_window message to stdout.
857
858 Fields in params:
859 - MessageID(uint): AIS message number. Must be 6 (field automatically set to "6")
860 - RepeatIndicator(uint): Indicated how many times a message has been repeated
861 - UserID(uint): MMSI number of transmitter broadcasting the message
862 - SeqNum(uint): Sequence number as described in 5.3.1. Assigned to each station
863 - DestinationID(uint): Unique ship identification number (MMSI)
864 - RetransmitFlag(bool): Should be set upon retransmission
865 - Spare(uint): Must be 0 (field automatically set to "0")
866 - dac(uint): Designated Area Code - part 1 of the IAI (field automatically set to "1")
867 - fid(uint): Functional Identifier - part 2 of the IAI (field automatically set to "11")
868 - month(uint): UTC month
869 - day(uint): UTC day
870 - window1_longitude(decimal): Not sure what this position is for? Center? East West location
871 - window1_latitude(decimal): Not sure what this position is for? Center? North South location
872 - fromhour1(uint): From UTC hour
873 - frommin1(uint): From UTC minute
874 - tohour1(uint): To UTC hour
875 - tomin1(uint): To UTC minute
876 - curdir1(uint): Current direction
877 - curspeed1(udecimal): Current speed
878 - window2_longitude(decimal): Not sure what this position is for? Center? East West location
879 - window2_latitude(decimal): Not sure what this position is for? Center? North South location
880 - fromhour2(uint): From UTC hour
881 - frommin2(uint): From UTC minute
882 - tohour2(uint): To UTC hour
883 - tomin2(uint): To UTC minute
884 - curdir2(uint): Current direction
885 - curspeed2(udecimal): Current speed
886 - window3_longitude(decimal): Not sure what this position is for? Center? East West location
887 - window3_latitude(decimal): Not sure what this position is for? Center? North South location
888 - fromhour3(uint): From UTC hour
889 - frommin3(uint): From UTC minute
890 - tohour3(uint): To UTC hour
891 - tomin3(uint): To UTC minute
892 - curdir3(uint): Current direction
893 - curspeed3(udecimal): Current speed
894 @param params: Dictionary of field names/values.
895 @param out: File like object to write to
896 @rtype: stdout
897 @return: text to out
898 '''
899
900 if 'std'==format:
901 out.write("imo_tidal_window:\n")
902 if 'MessageID' in params: out.write(" MessageID: "+str(params['MessageID'])+"\n")
903 if 'RepeatIndicator' in params: out.write(" RepeatIndicator: "+str(params['RepeatIndicator'])+"\n")
904 if 'UserID' in params: out.write(" UserID: "+str(params['UserID'])+"\n")
905 if 'SeqNum' in params: out.write(" SeqNum: "+str(params['SeqNum'])+"\n")
906 if 'DestinationID' in params: out.write(" DestinationID: "+str(params['DestinationID'])+"\n")
907 if 'RetransmitFlag' in params: out.write(" RetransmitFlag: "+str(params['RetransmitFlag'])+"\n")
908 if 'Spare' in params: out.write(" Spare: "+str(params['Spare'])+"\n")
909 if 'dac' in params: out.write(" dac: "+str(params['dac'])+"\n")
910 if 'fid' in params: out.write(" fid: "+str(params['fid'])+"\n")
911 if 'month' in params: out.write(" month: "+str(params['month'])+"\n")
912 if 'day' in params: out.write(" day: "+str(params['day'])+"\n")
913 if 'window1_longitude' in params: out.write(" window1_longitude: "+str(params['window1_longitude'])+"\n")
914 if 'window1_latitude' in params: out.write(" window1_latitude: "+str(params['window1_latitude'])+"\n")
915 if 'fromhour1' in params: out.write(" fromhour1: "+str(params['fromhour1'])+"\n")
916 if 'frommin1' in params: out.write(" frommin1: "+str(params['frommin1'])+"\n")
917 if 'tohour1' in params: out.write(" tohour1: "+str(params['tohour1'])+"\n")
918 if 'tomin1' in params: out.write(" tomin1: "+str(params['tomin1'])+"\n")
919 if 'curdir1' in params: out.write(" curdir1: "+str(params['curdir1'])+"\n")
920 if 'curspeed1' in params: out.write(" curspeed1: "+str(params['curspeed1'])+"\n")
921 if 'window2_longitude' in params: out.write(" window2_longitude: "+str(params['window2_longitude'])+"\n")
922 if 'window2_latitude' in params: out.write(" window2_latitude: "+str(params['window2_latitude'])+"\n")
923 if 'fromhour2' in params: out.write(" fromhour2: "+str(params['fromhour2'])+"\n")
924 if 'frommin2' in params: out.write(" frommin2: "+str(params['frommin2'])+"\n")
925 if 'tohour2' in params: out.write(" tohour2: "+str(params['tohour2'])+"\n")
926 if 'tomin2' in params: out.write(" tomin2: "+str(params['tomin2'])+"\n")
927 if 'curdir2' in params: out.write(" curdir2: "+str(params['curdir2'])+"\n")
928 if 'curspeed2' in params: out.write(" curspeed2: "+str(params['curspeed2'])+"\n")
929 if 'window3_longitude' in params: out.write(" window3_longitude: "+str(params['window3_longitude'])+"\n")
930 if 'window3_latitude' in params: out.write(" window3_latitude: "+str(params['window3_latitude'])+"\n")
931 if 'fromhour3' in params: out.write(" fromhour3: "+str(params['fromhour3'])+"\n")
932 if 'frommin3' in params: out.write(" frommin3: "+str(params['frommin3'])+"\n")
933 if 'tohour3' in params: out.write(" tohour3: "+str(params['tohour3'])+"\n")
934 if 'tomin3' in params: out.write(" tomin3: "+str(params['tomin3'])+"\n")
935 if 'curdir3' in params: out.write(" curdir3: "+str(params['curdir3'])+"\n")
936 if 'curspeed3' in params: out.write(" curspeed3: "+str(params['curspeed3'])+"\n")
937 elif 'csv'==format:
938 if None == options.fieldList:
939 options.fieldList = fieldList
940 needComma = False;
941 for field in fieldList:
942 if needComma: out.write(',')
943 needComma = True
944 if field in params:
945 out.write(str(params[field]))
946
947 out.write("\n")
948 elif 'html'==format:
949 printHtml(params,out)
950 elif 'sql'==format:
951 sqlInsertStr(params,out,dbType=dbType)
952 elif 'kml'==format:
953 printKml(params,out)
954 elif 'kml-full'==format:
955 out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
956 out.write("<kml xmlns=\"http://earth.google.com/kml/2.1\">\n")
957 out.write("<Document>\n")
958 out.write(" <name>imo_tidal_window</name>\n")
959 printKml(params,out)
960 out.write("</Document>\n")
961 out.write("</kml>\n")
962 else:
963 print "ERROR: unknown format:",format
964 assert False
965
966 return
967
968 RepeatIndicatorEncodeLut = {
969 'default':'0',
970 'do not repeat any more':'3',
971 }
972
973 RepeatIndicatorDecodeLut = {
974 '0':'default',
975 '3':'do not repeat any more',
976 }
977
978 RetransmitFlagEncodeLut = {
979 'no retransmission':'0',
980 'restransmitted':'1',
981 }
982
983 RetransmitFlagDecodeLut = {
984 '0':'no retransmission',
985 '1':'restransmitted',
986 }
987
988
989
990
991
992 -def sqlCreateStr(outfile=sys.stdout, fields=None, extraFields=None
993 ,addCoastGuardFields=True
994 ,dbType='postgres'
995 ):
996 '''
997 Return the SQL CREATE command for this message type
998 @param outfile: file like object to print to.
999 @param fields: which fields to put in the create. Defaults to all.
1000 @param extraFields: A sequence of tuples containing (name,sql type) for additional fields
1001 @param addCoastGuardFields: Add the extra fields that come after the NMEA check some from the USCG N-AIS format
1002 @param dbType: Which flavor of database we are using so that the create is tailored ('sqlite' or 'postgres')
1003 @type addCoastGuardFields: bool
1004 @return: sql create string
1005 @rtype: str
1006
1007 @see: sqlCreate
1008 '''
1009
1010 outfile.write(str(sqlCreate(fields,extraFields,addCoastGuardFields,dbType=dbType)))
1011
1012 -def sqlCreate(fields=None, extraFields=None, addCoastGuardFields=True, dbType='postgres'):
1013 '''
1014 Return the sqlhelp object to create the table.
1015
1016 @param fields: which fields to put in the create. Defaults to all.
1017 @param extraFields: A sequence of tuples containing (name,sql type) for additional fields
1018 @param addCoastGuardFields: Add the extra fields that come after the NMEA check some from the USCG N-AIS format
1019 @type addCoastGuardFields: bool
1020 @param dbType: Which flavor of database we are using so that the create is tailored ('sqlite' or 'postgres')
1021 @return: An object that can be used to generate a return
1022 @rtype: sqlhelp.create
1023 '''
1024 if None == fields: fields = fieldList
1025 import sqlhelp
1026 c = sqlhelp.create('imo_tidal_window',dbType=dbType)
1027 c.addPrimaryKey()
1028 if 'MessageID' in fields: c.addInt ('MessageID')
1029 if 'RepeatIndicator' in fields: c.addInt ('RepeatIndicator')
1030 if 'UserID' in fields: c.addInt ('UserID')
1031 if 'SeqNum' in fields: c.addInt ('SeqNum')
1032 if 'DestinationID' in fields: c.addInt ('DestinationID')
1033 if 'RetransmitFlag' in fields: c.addBool('RetransmitFlag')
1034 if 'Spare' in fields: c.addInt ('Spare')
1035 if 'dac' in fields: c.addInt ('dac')
1036 if 'fid' in fields: c.addInt ('fid')
1037 if 'month' in fields: c.addInt ('month')
1038 if 'day' in fields: c.addInt ('day')
1039 if dbType != 'postgres':
1040 if 'window1_longitude' in fields: c.addDecimal('window1_longitude',8,5)
1041 if dbType != 'postgres':
1042 if 'window1_latitude' in fields: c.addDecimal('window1_latitude',8,5)
1043 if 'fromhour1' in fields: c.addInt ('fromhour1')
1044 if 'frommin1' in fields: c.addInt ('frommin1')
1045 if 'tohour1' in fields: c.addInt ('tohour1')
1046 if 'tomin1' in fields: c.addInt ('tomin1')
1047 if 'curdir1' in fields: c.addInt ('curdir1')
1048 if 'curspeed1' in fields: c.addDecimal('curspeed1',3,1)
1049 if dbType != 'postgres':
1050 if 'window2_longitude' in fields: c.addDecimal('window2_longitude',8,5)
1051 if dbType != 'postgres':
1052 if 'window2_latitude' in fields: c.addDecimal('window2_latitude',8,5)
1053 if 'fromhour2' in fields: c.addInt ('fromhour2')
1054 if 'frommin2' in fields: c.addInt ('frommin2')
1055 if 'tohour2' in fields: c.addInt ('tohour2')
1056 if 'tomin2' in fields: c.addInt ('tomin2')
1057 if 'curdir2' in fields: c.addInt ('curdir2')
1058 if 'curspeed2' in fields: c.addDecimal('curspeed2',3,1)
1059 if dbType != 'postgres':
1060 if 'window3_longitude' in fields: c.addDecimal('window3_longitude',8,5)
1061 if dbType != 'postgres':
1062 if 'window3_latitude' in fields: c.addDecimal('window3_latitude',8,5)
1063 if 'fromhour3' in fields: c.addInt ('fromhour3')
1064 if 'frommin3' in fields: c.addInt ('frommin3')
1065 if 'tohour3' in fields: c.addInt ('tohour3')
1066 if 'tomin3' in fields: c.addInt ('tomin3')
1067 if 'curdir3' in fields: c.addInt ('curdir3')
1068 if 'curspeed3' in fields: c.addDecimal('curspeed3',3,1)
1069
1070 if addCoastGuardFields:
1071
1072
1073
1074
1075
1076 c.addVarChar('cg_r',15)
1077 c.addInt('cg_sec')
1078
1079 c.addTimestamp('cg_timestamp')
1080
1081 if dbType == 'postgres':
1082
1083
1084 c.addPostGIS('window1','POINT',2,SRID=4326);
1085
1086
1087 c.addPostGIS('window2','POINT',2,SRID=4326);
1088
1089
1090 c.addPostGIS('window3','POINT',2,SRID=4326);
1091
1092 return c
1093
1094 -def sqlInsertStr(params, outfile=sys.stdout, extraParams=None, dbType='postgres'):
1095 '''
1096 Return the SQL INSERT command for this message type
1097 @param params: dictionary of values keyed by field name
1098 @param outfile: file like object to print to.
1099 @param extraParams: A sequence of tuples containing (name,sql type) for additional fields
1100 @return: sql create string
1101 @rtype: str
1102
1103 @see: sqlCreate
1104 '''
1105 outfile.write(str(sqlInsert(params,extraParams,dbType=dbType)))
1106
1107
1108 -def sqlInsert(params,extraParams=None,dbType='postgres'):
1109 '''
1110 Give the SQL INSERT statement
1111 @param params: dict keyed by field name of values
1112 @param extraParams: any extra fields that you have created beyond the normal ais message fields
1113 @rtype: sqlhelp.insert
1114 @return: insert class instance
1115 @todo: allow optional type checking of params?
1116 @warning: this will take invalid keys happily and do what???
1117 '''
1118 import sqlhelp
1119 i = sqlhelp.insert('imo_tidal_window',dbType=dbType)
1120
1121 if dbType=='postgres':
1122 finished = []
1123 for key in params:
1124 if key in finished:
1125 continue
1126
1127 if key not in toPgFields and key not in fromPgFields:
1128 if type(params[key])==Decimal: i.add(key,float(params[key]))
1129 else: i.add(key,params[key])
1130 else:
1131 if key in fromPgFields:
1132 val = params[key]
1133
1134 i.addPostGIS(key,val)
1135 finished.append(key)
1136 else:
1137
1138 pgName = toPgFields[key]
1139
1140 valStr=pgTypes[pgName]+'('
1141 vals = []
1142 for nonPgKey in fromPgFields[pgName]:
1143 vals.append(str(params[nonPgKey]))
1144 finished.append(nonPgKey)
1145 valStr+=' '.join(vals)+')'
1146 i.addPostGIS(pgName,valStr)
1147 else:
1148 for key in params:
1149 if type(params[key])==Decimal: i.add(key,float(params[key]))
1150 else: i.add(key,params[key])
1151
1152 if None != extraParams:
1153 for key in extraParams:
1154 i.add(key,extraParams[key])
1155
1156 return i
1157
1158
1159
1160
1161
1164 '''
1165 Return the LaTeX definition table for this message type
1166 @param outfile: file like object to print to.
1167 @type outfile: file obj
1168 @return: LaTeX table string via the outfile
1169 @rtype: str
1170
1171 '''
1172 o = outfile
1173
1174 o.write('''
1175 \\begin{table}%[htb]
1176 \\centering
1177 \\begin{tabular}{|l|c|l|}
1178 \\hline
1179 Parameter & Number of bits & Description
1180 \\\\ \\hline\\hline
1181 MessageID & 6 & AIS message number. Must be 6 \\\\ \hline
1182 RepeatIndicator & 2 & Indicated how many times a message has been repeated \\\\ \hline
1183 UserID & 30 & MMSI number of transmitter broadcasting the message \\\\ \hline
1184 SeqNum & 2 & Sequence number as described in 5.3.1. Assigned to each station \\\\ \hline
1185 DestinationID & 30 & Unique ship identification number (MMSI) \\\\ \hline
1186 RetransmitFlag & 1 & Should be set upon retransmission \\\\ \hline
1187 Spare & 1 & Must be 0 \\\\ \hline
1188 dac & 10 & Designated Area Code - part 1 of the IAI \\\\ \hline
1189 fid & 6 & Functional Identifier - part 2 of the IAI \\\\ \hline
1190 month & 4 & UTC month \\\\ \hline
1191 day & 5 & UTC day \\\\ \hline
1192 window1\_longitude & 28 & Not sure what this position is for? Center? East West location \\\\ \hline
1193 window1\_latitude & 27 & Not sure what this position is for? Center? North South location \\\\ \hline
1194 fromhour1 & 5 & From UTC hour \\\\ \hline
1195 frommin1 & 6 & From UTC minute \\\\ \hline
1196 tohour1 & 5 & To UTC hour \\\\ \hline
1197 tomin1 & 6 & To UTC minute \\\\ \hline
1198 curdir1 & 9 & Current direction \\\\ \hline
1199 curspeed1 & 7 & Current speed \\\\ \hline
1200 window2\_longitude & 28 & Not sure what this position is for? Center? East West location \\\\ \hline
1201 window2\_latitude & 27 & Not sure what this position is for? Center? North South location \\\\ \hline
1202 fromhour2 & 5 & From UTC hour \\\\ \hline
1203 frommin2 & 6 & From UTC minute \\\\ \hline
1204 tohour2 & 5 & To UTC hour \\\\ \hline
1205 tomin2 & 6 & To UTC minute \\\\ \hline
1206 curdir2 & 9 & Current direction \\\\ \hline
1207 curspeed2 & 7 & Current speed \\\\ \hline
1208 window3\_longitude & 28 & Not sure what this position is for? Center? East West location \\\\ \hline
1209 window3\_latitude & 27 & Not sure what this position is for? Center? North South location \\\\ \hline
1210 fromhour3 & 5 & From UTC hour \\\\ \hline
1211 frommin3 & 6 & From UTC minute \\\\ \hline
1212 tohour3 & 5 & To UTC hour \\\\ \hline
1213 tomin3 & 6 & To UTC minute \\\\ \hline
1214 curdir3 & 9 & Current direction \\\\ \hline
1215 curspeed3 & 7 & Current speed\\\\ \\hline \\hline
1216 Total bits & 376 & Appears to take 2 slots with 48 pad bits to fill the last slot \\\\ \\hline
1217 \\end{tabular}
1218 \\caption{AIS message number 6: IMO fairway closed. Specified in SN\\Circ.236 Annex 2, page 5, Application 3. Also defined in IALA Guidelines on AIS, Vol 1, Part 1, Ed. 1.3. Guildeline No 1028. This message should be used to inform vessels about tidal windows which allow a vessel the safe passage of a fairway. The message includes predictions of current speed and current direction. In this example, three points of tidal information are given. Attributes of message: addressed, shore station transmitting, acknowledgement required. }
1219 \\label{tab:imo_tidal_window}
1220 \\end{table}
1221 ''')
1222
1223
1224
1225
1226
1227 -def textDefinitionTable(outfile=sys.stdout
1228 ,delim='\t'
1229 ):
1230 '''
1231 Return the text definition table for this message type
1232 @param outfile: file like object to print to.
1233 @type outfile: file obj
1234 @return: text table string via the outfile
1235 @rtype: str
1236
1237 '''
1238 o = outfile
1239 o.write('''Parameter'''+delim+'Number of bits'''+delim+'''Description
1240 MessageID'''+delim+'''6'''+delim+'''AIS message number. Must be 6
1241 RepeatIndicator'''+delim+'''2'''+delim+'''Indicated how many times a message has been repeated
1242 UserID'''+delim+'''30'''+delim+'''MMSI number of transmitter broadcasting the message
1243 SeqNum'''+delim+'''2'''+delim+'''Sequence number as described in 5.3.1. Assigned to each station
1244 DestinationID'''+delim+'''30'''+delim+'''Unique ship identification number (MMSI)
1245 RetransmitFlag'''+delim+'''1'''+delim+'''Should be set upon retransmission
1246 Spare'''+delim+'''1'''+delim+'''Must be 0
1247 dac'''+delim+'''10'''+delim+'''Designated Area Code - part 1 of the IAI
1248 fid'''+delim+'''6'''+delim+'''Functional Identifier - part 2 of the IAI
1249 month'''+delim+'''4'''+delim+'''UTC month
1250 day'''+delim+'''5'''+delim+'''UTC day
1251 window1_longitude'''+delim+'''28'''+delim+'''Not sure what this position is for? Center? East West location
1252 window1_latitude'''+delim+'''27'''+delim+'''Not sure what this position is for? Center? North South location
1253 fromhour1'''+delim+'''5'''+delim+'''From UTC hour
1254 frommin1'''+delim+'''6'''+delim+'''From UTC minute
1255 tohour1'''+delim+'''5'''+delim+'''To UTC hour
1256 tomin1'''+delim+'''6'''+delim+'''To UTC minute
1257 curdir1'''+delim+'''9'''+delim+'''Current direction
1258 curspeed1'''+delim+'''7'''+delim+'''Current speed
1259 window2_longitude'''+delim+'''28'''+delim+'''Not sure what this position is for? Center? East West location
1260 window2_latitude'''+delim+'''27'''+delim+'''Not sure what this position is for? Center? North South location
1261 fromhour2'''+delim+'''5'''+delim+'''From UTC hour
1262 frommin2'''+delim+'''6'''+delim+'''From UTC minute
1263 tohour2'''+delim+'''5'''+delim+'''To UTC hour
1264 tomin2'''+delim+'''6'''+delim+'''To UTC minute
1265 curdir2'''+delim+'''9'''+delim+'''Current direction
1266 curspeed2'''+delim+'''7'''+delim+'''Current speed
1267 window3_longitude'''+delim+'''28'''+delim+'''Not sure what this position is for? Center? East West location
1268 window3_latitude'''+delim+'''27'''+delim+'''Not sure what this position is for? Center? North South location
1269 fromhour3'''+delim+'''5'''+delim+'''From UTC hour
1270 frommin3'''+delim+'''6'''+delim+'''From UTC minute
1271 tohour3'''+delim+'''5'''+delim+'''To UTC hour
1272 tomin3'''+delim+'''6'''+delim+'''To UTC minute
1273 curdir3'''+delim+'''9'''+delim+'''Current direction
1274 curspeed3'''+delim+'''7'''+delim+'''Current speed
1275 Total bits'''+delim+'''376'''+delim+'''Appears to take 2 slots with 48 pad bits to fill the last slot''')
1276
1277
1278
1279
1280
1281 import unittest
1283 '''Return a params file base on the testvalue tags.
1284 @rtype: dict
1285 @return: params based on testvalue tags
1286 '''
1287 params = {}
1288 params['MessageID'] = 6
1289 params['RepeatIndicator'] = 1
1290 params['UserID'] = 1193046
1291 params['SeqNum'] = 3
1292 params['DestinationID'] = 1193047
1293 params['RetransmitFlag'] = True
1294 params['Spare'] = 0
1295 params['dac'] = 1
1296 params['fid'] = 11
1297 params['month'] = 2
1298 params['day'] = 1
1299 params['window1_longitude'] = Decimal('-122.16328055555556')
1300 params['window1_latitude'] = Decimal('37.424458333333334')
1301 params['fromhour1'] = 1
1302 params['frommin1'] = 21
1303 params['tohour1'] = 23
1304 params['tomin1'] = 24
1305 params['curdir1'] = 300
1306 params['curspeed1'] = Decimal('12.1')
1307 params['window2_longitude'] = Decimal('-122.16328055555556')
1308 params['window2_latitude'] = Decimal('37.424458333333334')
1309 params['fromhour2'] = 1
1310 params['frommin2'] = 21
1311 params['tohour2'] = 23
1312 params['tomin2'] = 24
1313 params['curdir2'] = 300
1314 params['curspeed2'] = Decimal('12.1')
1315 params['window3_longitude'] = Decimal('-122.16328055555556')
1316 params['window3_latitude'] = Decimal('37.424458333333334')
1317 params['fromhour3'] = 1
1318 params['frommin3'] = 21
1319 params['tohour3'] = 23
1320 params['tomin3'] = 24
1321 params['curdir3'] = 300
1322 params['curspeed3'] = Decimal('12.1')
1323
1324 return params
1325
1327 '''Use testvalue tag text from each type to build test case the imo_tidal_window message'''
1329
1330 params = testParams()
1331 bits = encode(params)
1332 r = decode(bits)
1333
1334
1335 self.failUnlessEqual(r['MessageID'],params['MessageID'])
1336 self.failUnlessEqual(r['RepeatIndicator'],params['RepeatIndicator'])
1337 self.failUnlessEqual(r['UserID'],params['UserID'])
1338 self.failUnlessEqual(r['SeqNum'],params['SeqNum'])
1339 self.failUnlessEqual(r['DestinationID'],params['DestinationID'])
1340 self.failUnlessEqual(r['RetransmitFlag'],params['RetransmitFlag'])
1341 self.failUnlessEqual(r['Spare'],params['Spare'])
1342 self.failUnlessEqual(r['dac'],params['dac'])
1343 self.failUnlessEqual(r['fid'],params['fid'])
1344 self.failUnlessEqual(r['month'],params['month'])
1345 self.failUnlessEqual(r['day'],params['day'])
1346 self.failUnlessAlmostEqual(r['window1_longitude'],params['window1_longitude'],5)
1347 self.failUnlessAlmostEqual(r['window1_latitude'],params['window1_latitude'],5)
1348 self.failUnlessEqual(r['fromhour1'],params['fromhour1'])
1349 self.failUnlessEqual(r['frommin1'],params['frommin1'])
1350 self.failUnlessEqual(r['tohour1'],params['tohour1'])
1351 self.failUnlessEqual(r['tomin1'],params['tomin1'])
1352 self.failUnlessEqual(r['curdir1'],params['curdir1'])
1353 self.failUnlessAlmostEqual(r['curspeed1'],params['curspeed1'],1)
1354 self.failUnlessAlmostEqual(r['window2_longitude'],params['window2_longitude'],5)
1355 self.failUnlessAlmostEqual(r['window2_latitude'],params['window2_latitude'],5)
1356 self.failUnlessEqual(r['fromhour2'],params['fromhour2'])
1357 self.failUnlessEqual(r['frommin2'],params['frommin2'])
1358 self.failUnlessEqual(r['tohour2'],params['tohour2'])
1359 self.failUnlessEqual(r['tomin2'],params['tomin2'])
1360 self.failUnlessEqual(r['curdir2'],params['curdir2'])
1361 self.failUnlessAlmostEqual(r['curspeed2'],params['curspeed2'],1)
1362 self.failUnlessAlmostEqual(r['window3_longitude'],params['window3_longitude'],5)
1363 self.failUnlessAlmostEqual(r['window3_latitude'],params['window3_latitude'],5)
1364 self.failUnlessEqual(r['fromhour3'],params['fromhour3'])
1365 self.failUnlessEqual(r['frommin3'],params['frommin3'])
1366 self.failUnlessEqual(r['tohour3'],params['tohour3'])
1367 self.failUnlessEqual(r['tomin3'],params['tomin3'])
1368 self.failUnlessEqual(r['curdir3'],params['curdir3'])
1369 self.failUnlessAlmostEqual(r['curspeed3'],params['curspeed3'],1)
1370
1372 parser.add_option('-d','--decode',dest='doDecode',default=False,action='store_true',
1373 help='decode a "imo_tidal_window" AIS message')
1374 parser.add_option('-e','--encode',dest='doEncode',default=False,action='store_true',
1375 help='encode a "imo_tidal_window" AIS message')
1376 parser.add_option('--RepeatIndicator-field', dest='RepeatIndicatorField',default=0,metavar='uint',type='int'
1377 ,help='Field parameter value [default: %default]')
1378 parser.add_option('--UserID-field', dest='UserIDField',metavar='uint',type='int'
1379 ,help='Field parameter value [default: %default]')
1380 parser.add_option('--SeqNum-field', dest='SeqNumField',metavar='uint',type='int'
1381 ,help='Field parameter value [default: %default]')
1382 parser.add_option('--DestinationID-field', dest='DestinationIDField',metavar='uint',type='int'
1383 ,help='Field parameter value [default: %default]')
1384 parser.add_option('--RetransmitFlag-field', dest='RetransmitFlagField',metavar='bool',type='int'
1385 ,help='Field parameter value [default: %default]')
1386 parser.add_option('--month-field', dest='monthField',default=0,metavar='uint',type='int'
1387 ,help='Field parameter value [default: %default]')
1388 parser.add_option('--day-field', dest='dayField',default=0,metavar='uint',type='int'
1389 ,help='Field parameter value [default: %default]')
1390 parser.add_option('--window1_longitude-field', dest='window1_longitudeField',default=Decimal('181'),metavar='decimal',type='string'
1391 ,help='Field parameter value [default: %default]')
1392 parser.add_option('--window1_latitude-field', dest='window1_latitudeField',default=Decimal('91'),metavar='decimal',type='string'
1393 ,help='Field parameter value [default: %default]')
1394 parser.add_option('--fromhour1-field', dest='fromhour1Field',default=24,metavar='uint',type='int'
1395 ,help='Field parameter value [default: %default]')
1396 parser.add_option('--frommin1-field', dest='frommin1Field',default=60,metavar='uint',type='int'
1397 ,help='Field parameter value [default: %default]')
1398 parser.add_option('--tohour1-field', dest='tohour1Field',default=24,metavar='uint',type='int'
1399 ,help='Field parameter value [default: %default]')
1400 parser.add_option('--tomin1-field', dest='tomin1Field',default=60,metavar='uint',type='int'
1401 ,help='Field parameter value [default: %default]')
1402 parser.add_option('--curdir1-field', dest='curdir1Field',default=360,metavar='uint',type='int'
1403 ,help='Field parameter value [default: %default]')
1404 parser.add_option('--curspeed1-field', dest='curspeed1Field',default=Decimal('12.7'),metavar='udecimal',type='string'
1405 ,help='Field parameter value [default: %default]')
1406 parser.add_option('--window2_longitude-field', dest='window2_longitudeField',default=Decimal('181'),metavar='decimal',type='string'
1407 ,help='Field parameter value [default: %default]')
1408 parser.add_option('--window2_latitude-field', dest='window2_latitudeField',default=Decimal('91'),metavar='decimal',type='string'
1409 ,help='Field parameter value [default: %default]')
1410 parser.add_option('--fromhour2-field', dest='fromhour2Field',default=24,metavar='uint',type='int'
1411 ,help='Field parameter value [default: %default]')
1412 parser.add_option('--frommin2-field', dest='frommin2Field',default=60,metavar='uint',type='int'
1413 ,help='Field parameter value [default: %default]')
1414 parser.add_option('--tohour2-field', dest='tohour2Field',default=24,metavar='uint',type='int'
1415 ,help='Field parameter value [default: %default]')
1416 parser.add_option('--tomin2-field', dest='tomin2Field',default=60,metavar='uint',type='int'
1417 ,help='Field parameter value [default: %default]')
1418 parser.add_option('--curdir2-field', dest='curdir2Field',default=360,metavar='uint',type='int'
1419 ,help='Field parameter value [default: %default]')
1420 parser.add_option('--curspeed2-field', dest='curspeed2Field',default=Decimal('12.7'),metavar='udecimal',type='string'
1421 ,help='Field parameter value [default: %default]')
1422 parser.add_option('--window3_longitude-field', dest='window3_longitudeField',default=Decimal('181'),metavar='decimal',type='string'
1423 ,help='Field parameter value [default: %default]')
1424 parser.add_option('--window3_latitude-field', dest='window3_latitudeField',default=Decimal('91'),metavar='decimal',type='string'
1425 ,help='Field parameter value [default: %default]')
1426 parser.add_option('--fromhour3-field', dest='fromhour3Field',default=24,metavar='uint',type='int'
1427 ,help='Field parameter value [default: %default]')
1428 parser.add_option('--frommin3-field', dest='frommin3Field',default=60,metavar='uint',type='int'
1429 ,help='Field parameter value [default: %default]')
1430 parser.add_option('--tohour3-field', dest='tohour3Field',default=24,metavar='uint',type='int'
1431 ,help='Field parameter value [default: %default]')
1432 parser.add_option('--tomin3-field', dest='tomin3Field',default=60,metavar='uint',type='int'
1433 ,help='Field parameter value [default: %default]')
1434 parser.add_option('--curdir3-field', dest='curdir3Field',default=360,metavar='uint',type='int'
1435 ,help='Field parameter value [default: %default]')
1436 parser.add_option('--curspeed3-field', dest='curspeed3Field',default=Decimal('12.7'),metavar='udecimal',type='string'
1437 ,help='Field parameter value [default: %default]')
1438
1439
1440 if __name__=='__main__':
1441
1442 from optparse import OptionParser
1443 parser = OptionParser(usage="%prog [options]",
1444 version="%prog "+__version__)
1445
1446 parser.add_option('--doc-test',dest='doctest',default=False,action='store_true',
1447 help='run the documentation tests')
1448 parser.add_option('--unit-test',dest='unittest',default=False,action='store_true',
1449 help='run the unit tests')
1450 parser.add_option('-v','--verbose',dest='verbose',default=False,action='store_true',
1451 help='Make the test output verbose')
1452
1453
1454
1455 typeChoices = ('binary','nmeapayload','nmea')
1456 parser.add_option('-t','--type',choices=typeChoices,type='choice',dest='ioType'
1457 ,default='nmeapayload'
1458 ,help='What kind of string to write for encoding ('+', '.join(typeChoices)+') [default: %default]')
1459
1460
1461 outputChoices = ('std','html','csv','sql' , 'kml','kml-full')
1462 parser.add_option('-T','--output-type',choices=outputChoices,type='choice',dest='outputType'
1463 ,default='std'
1464 ,help='What kind of string to output ('+', '.join(outputChoices)+') [default: %default]')
1465
1466 parser.add_option('-o','--output',dest='outputFileName',default=None,
1467 help='Name of the python file to write [default: stdout]')
1468
1469 parser.add_option('-f','--fields',dest='fieldList',default=None, action='append',
1470 choices=fieldList,
1471 help='Which fields to include in the output. Currently only for csv output [default: all]')
1472
1473 parser.add_option('-p','--print-csv-field-list',dest='printCsvfieldList',default=False,action='store_true',
1474 help='Print the field name for csv')
1475
1476 parser.add_option('-c','--sql-create',dest='sqlCreate',default=False,action='store_true',
1477 help='Print out an sql create command for the table.')
1478
1479 parser.add_option('--latex-table',dest='latexDefinitionTable',default=False,action='store_true',
1480 help='Print a LaTeX table of the type')
1481
1482 parser.add_option('--text-table',dest='textDefinitionTable',default=False,action='store_true',
1483 help='Print delimited table of the type (for Word table importing)')
1484 parser.add_option('--delimt-text-table',dest='delimTextDefinitionTable',default='\t'
1485 ,help='Delimiter for text table [default: \'%default\'](for Word table importing)')
1486
1487
1488 dbChoices = ('sqlite','postgres')
1489 parser.add_option('-D','--db-type',dest='dbType',default='postgres'
1490 ,choices=dbChoices,type='choice'
1491 ,help='What kind of database ('+', '.join(dbChoices)+') [default: %default]')
1492
1493 addMsgOptions(parser)
1494
1495 (options,args) = parser.parse_args()
1496 success=True
1497
1498 if options.doctest:
1499 import os; print os.path.basename(sys.argv[0]), 'doctests ...',
1500 sys.argv= [sys.argv[0]]
1501 if options.verbose: sys.argv.append('-v')
1502 import doctest
1503 numfail,numtests=doctest.testmod()
1504 if numfail==0: print 'ok'
1505 else:
1506 print 'FAILED'
1507 success=False
1508
1509 if not success: sys.exit('Something Failed')
1510 del success
1511
1512 if options.unittest:
1513 sys.argv = [sys.argv[0]]
1514 if options.verbose: sys.argv.append('-v')
1515 unittest.main()
1516
1517 outfile = sys.stdout
1518 if None!=options.outputFileName:
1519 outfile = file(options.outputFileName,'w')
1520
1521
1522 if options.doEncode:
1523
1524 if None==options.RepeatIndicatorField: parser.error("missing value for RepeatIndicatorField")
1525 if None==options.UserIDField: parser.error("missing value for UserIDField")
1526 if None==options.SeqNumField: parser.error("missing value for SeqNumField")
1527 if None==options.DestinationIDField: parser.error("missing value for DestinationIDField")
1528 if None==options.RetransmitFlagField: parser.error("missing value for RetransmitFlagField")
1529 if None==options.monthField: parser.error("missing value for monthField")
1530 if None==options.dayField: parser.error("missing value for dayField")
1531 if None==options.window1_longitudeField: parser.error("missing value for window1_longitudeField")
1532 if None==options.window1_latitudeField: parser.error("missing value for window1_latitudeField")
1533 if None==options.fromhour1Field: parser.error("missing value for fromhour1Field")
1534 if None==options.frommin1Field: parser.error("missing value for frommin1Field")
1535 if None==options.tohour1Field: parser.error("missing value for tohour1Field")
1536 if None==options.tomin1Field: parser.error("missing value for tomin1Field")
1537 if None==options.curdir1Field: parser.error("missing value for curdir1Field")
1538 if None==options.curspeed1Field: parser.error("missing value for curspeed1Field")
1539 if None==options.window2_longitudeField: parser.error("missing value for window2_longitudeField")
1540 if None==options.window2_latitudeField: parser.error("missing value for window2_latitudeField")
1541 if None==options.fromhour2Field: parser.error("missing value for fromhour2Field")
1542 if None==options.frommin2Field: parser.error("missing value for frommin2Field")
1543 if None==options.tohour2Field: parser.error("missing value for tohour2Field")
1544 if None==options.tomin2Field: parser.error("missing value for tomin2Field")
1545 if None==options.curdir2Field: parser.error("missing value for curdir2Field")
1546 if None==options.curspeed2Field: parser.error("missing value for curspeed2Field")
1547 if None==options.window3_longitudeField: parser.error("missing value for window3_longitudeField")
1548 if None==options.window3_latitudeField: parser.error("missing value for window3_latitudeField")
1549 if None==options.fromhour3Field: parser.error("missing value for fromhour3Field")
1550 if None==options.frommin3Field: parser.error("missing value for frommin3Field")
1551 if None==options.tohour3Field: parser.error("missing value for tohour3Field")
1552 if None==options.tomin3Field: parser.error("missing value for tomin3Field")
1553 if None==options.curdir3Field: parser.error("missing value for curdir3Field")
1554 if None==options.curspeed3Field: parser.error("missing value for curspeed3Field")
1555 msgDict={
1556 'MessageID': '6',
1557 'RepeatIndicator': options.RepeatIndicatorField,
1558 'UserID': options.UserIDField,
1559 'SeqNum': options.SeqNumField,
1560 'DestinationID': options.DestinationIDField,
1561 'RetransmitFlag': options.RetransmitFlagField,
1562 'Spare': '0',
1563 'dac': '1',
1564 'fid': '11',
1565 'month': options.monthField,
1566 'day': options.dayField,
1567 'window1_longitude': options.window1_longitudeField,
1568 'window1_latitude': options.window1_latitudeField,
1569 'fromhour1': options.fromhour1Field,
1570 'frommin1': options.frommin1Field,
1571 'tohour1': options.tohour1Field,
1572 'tomin1': options.tomin1Field,
1573 'curdir1': options.curdir1Field,
1574 'curspeed1': options.curspeed1Field,
1575 'window2_longitude': options.window2_longitudeField,
1576 'window2_latitude': options.window2_latitudeField,
1577 'fromhour2': options.fromhour2Field,
1578 'frommin2': options.frommin2Field,
1579 'tohour2': options.tohour2Field,
1580 'tomin2': options.tomin2Field,
1581 'curdir2': options.curdir2Field,
1582 'curspeed2': options.curspeed2Field,
1583 'window3_longitude': options.window3_longitudeField,
1584 'window3_latitude': options.window3_latitudeField,
1585 'fromhour3': options.fromhour3Field,
1586 'frommin3': options.frommin3Field,
1587 'tohour3': options.tohour3Field,
1588 'tomin3': options.tomin3Field,
1589 'curdir3': options.curdir3Field,
1590 'curspeed3': options.curspeed3Field,
1591 }
1592
1593 bits = encode(msgDict)
1594 if 'binary'==options.ioType: print str(bits)
1595 elif 'nmeapayload'==options.ioType:
1596
1597 print "bitLen",len(bits)
1598 bitLen=len(bits)
1599 if bitLen%6!=0:
1600 bits = bits + BitVector(size=(6 - (bitLen%6)))
1601 print "result:",binary.bitvectoais6(bits)[0]
1602
1603
1604
1605 elif 'nmea'==options.ioType: sys.exit("FIX: need to implement this capability")
1606 else: sys.exit('ERROR: unknown ioType. Help!')
1607
1608
1609 if options.sqlCreate:
1610 sqlCreateStr(outfile,options.fieldList,dbType=options.dbType)
1611
1612 if options.latexDefinitionTable:
1613 latexDefinitionTable(outfile)
1614
1615
1616 if options.textDefinitionTable:
1617 textDefinitionTable(outfile,options.delimTextDefinitionTable)
1618
1619 if options.printCsvfieldList:
1620
1621 if None == options.fieldList: options.fieldList = fieldList
1622 import StringIO
1623 buf = StringIO.StringIO()
1624 for field in options.fieldList:
1625 buf.write(field+',')
1626 result = buf.getvalue()
1627 if result[-1] == ',': print result[:-1]
1628 else: print result
1629
1630 if options.doDecode:
1631 if len(args)==0: args = sys.stdin
1632 for msg in args:
1633 bv = None
1634
1635 if msg[0] in ('$','!') and msg[3:6] in ('VDM','VDO'):
1636
1637
1638 bv = binary.ais6tobitvec(msg.split(',')[5])
1639 else:
1640
1641 binaryMsg=True
1642 for c in msg:
1643 if c not in ('0','1'):
1644 binaryMsg=False
1645 break
1646 if binaryMsg:
1647 bv = BitVector(bitstring=msg)
1648 else:
1649 bv = binary.ais6tobitvec(msg)
1650
1651 printFields(decode(bv)
1652 ,out=outfile
1653 ,format=options.outputType
1654 ,fieldList=options.fieldList
1655 ,dbType=options.dbType
1656 )
1657