-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAISData.py
1619 lines (1351 loc) · 50.4 KB
/
AISData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import struct
import logging
from AISDictionary import AISDictionaries
def Dissemble_encoded_string(encoded_string: str):
# takes an encoded string and breaks it up into its
# (hopefiully seven components
breakdown = encoded_string.split(',')
if len(breakdown) == 7:
talker = breakdown[0]
fragcount = breakdown[1]
fragno = breakdown[2]
messid = breakdown[3]
channel = breakdown[4]
payload = breakdown[5]
trailer = breakdown[6]
return breakdown
else:
return ('!AIVDM', '1', '1', '', 'A', 'N000000000000000', '0')
class AIS_Data:
'''
first the constructor stuff
because there are multiple forms need to use the **kwargs
(multiple keyword arguments) approach and iterate through the argument list
kwargs is a dictionary of keywod:value pairs
Within the AIS record there are a number of payloads
each has a set of attributes all of which are described in
http://www.catb.org/gpsd/AIVDM.html
CURRENTLY ONLY types 1, 2 3, 4, 5, 18 and 24 are processed in this script
Payload ids 1,2 and 3 (Position Reports) have attributes
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Nav Status
Rate of Turn ROT
Speed over Ground SOG
Position Accuracy
Longitude
Latitude
Course over Groung COG
True Heading
Time Stamp
Manouver Indicator
RAIM Flag
Radio Status
Payload id 4 (Base Station Report) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Year
Month
Day
Hour
Minute
Second
Fix Quality
Longitude
Latitude
Type of EPFD
RAIM Flag
SOTDMAState
Payload 5 (Static and Voyage RElated Data) has Parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
AIS Version
IMO Number
Callsign
Vessel Name
Ship Type
Dimension to Bow
Dimension to Stern
Dimension to Port
Dimension to Starboard
Position Fix Type
ETA Month
ETA Day
ETA Hour
ETA Minute
Draught
Destination
DTE
Payload Id 6 (Binary Addressed Message has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Sequence Number
Destination MMSI
Retransmit Flag
Designated Area Code
Functional Id
Data
Payload id 7 (Binary Acknowledge) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
MMSI No 1
MMSI No 2
MMSI No 3
MMSI No 4
Payload id 8 (Binary Broadcast Message) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Designated Area Code
Functional Id
Data
payload id 9 (SAR Aircraft Position Report) has attributes
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
payload id 10 (UTC/.Date Enquiry) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Altitude
SOG
Position Accuracy
Longitude
Latitude
COG
TimeStamp
DTE
Assigned
RAIM Flag
Radio Status
payload id 11 (UTC/Date Response) has sme parameters as id 4
payload id 12 (Addressed Safety Related Message) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Sequence Number
Destination MMSI
Retransmit Flag
Text
payload id 13 (Safety Related Acknowledgement) has same parameters as id 7
payload 14 (Safety Related Broadcast) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Text
payload 15 (Interrogation) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Interrogated MMSI
First msg Type
First Slot offset
Second Msg Type
Second Slot offset
Interrogated MMSI
First messge TYpe
First slot offset
payload id 16 (Assignment Mode Command) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Destination A MMSI
Offset A
Increment A
Destination B MMSI
Offset B
Increment B
payload 17 (DGNSS Broadcast Binary Message) has parameters
Message Type 1-3
Repeat Indicator
Source MMSI 9 digits
Longitude
Latitude
Payload
payload 18 (Class B Position Report) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Speed over Ground SOG
Position Accuracy
Longitude
Latitude
Course over Groung COG
True Heading
Time Stamp
CS Unit
Display Flag
DSC Flag
Band Flag
Message22 Flag
Manouver Indicator
RAIM Flag
Radio Status
payload 19 (Extended Class B Position Report) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Speed Over Ground SOG
Postion Accuracy
Latitude
Longitude
Course Over Ground COG
True Heading
Type of Ship and Cargo
Dimension to Bow
Dimension to Stern
Dimension to Port
Dimension to Starboard
Position Fix Type
RAIM Flag
DTE
Assigned Mode Flag
payload id 20 (Data LInk Mgt Message) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Offset no 1
Reserved Slots
Timeout
Increment
Offset no2
Timeout
Increment
Offset no3
Timeout
Increment
Offset no4
Timeout
Increment
payload id 21 (Aid to Navigation REport) has parameterrs
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Aid Type
Name
Position Accuracy
Longitude
Latitude
Dimension to Bow
Dimension to Stern
Dimension to Port
Dimension to Starboard
Type of EPFD
UTC Second
Off Position Indicator
RAIM Flag
Virtual Aid Flag
Assigned Mode Flag
Name Extension
payload 22 (Channel Mgt) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Channel A
Channel B
Tx/Rx mode
Power
NE Longitude
NE Latitude
SW Longitude
SW Latitude
MSSI1
MSSI2
Addressed
Channel A Band
Channel B Band
Zone Size
payload 23 (Group Assignment Command) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
NE Longitude
NE Latitude
SW Longitude
SW Latitude
Station Type
Ship Type
Tx/RX Mode
Report Interval
Quite Time
payload id 24 (Static Data Report) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Part Number
Vessel Name
Ship Type
Vendor Id
Unit Model Code
Serial Number
Callsaign
Dimension to Bow
Dimension to Stern
Dimension to Port
Dimension to Starboard
Mothership MMSI
payload id 25 (Single Slot Bianary MNessage) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Destination Indicator
Binary Data Flag
Destination MMSI
Application Id
Data
payload id 26 (Multiple Slot Binary Message) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Destination Indicator
Binary Data Flag
Destination MMSI
Application Id
Data
Radio Status
payload id 27 (Long Range AIS Broadcast) has parameters
Message Type 1-3
Repeat Indicator
MMSI 9 digits
Position Accuracy
RAIM Flag'Navigation Status
Longitude
Latitude
Speed over Ground SOG
Course over Ground COG
GNSS Position Status
'''
_rot = 128 # not available
_altitude = float(0) # special for Type 9 (SAR aircraft) records
_sog = 0
_long = 0 # longitude
_lat = 0 # latitude
_cog = 0
_truhead = 0
_raim: int # RAIM not in use
_rad_status = 0 # special radio status generally unused
_time = 0
_man = 0
_name = '' # string
_call = '' # string
_destination = '' # string
_nstatus = 15 # not defined
_pa: int # unaugmented GPS fix
_disp: int = 0 # Display flag derived from type 18
_dsc: int = 0 # DSC flag - unit attached to VHF radio with DSC capability
_band: int = 0
# base stations can command units to switch frequency
# if True unit can use any part of band
_m22: int = 0
# Unit can accept channel assignment via message type 22
_assigned: int = 0
# Assigned mode flag False = autonomous, true = assigned mode
_version = 0
_IMO = 0
_type = 0
_d2bow = 0
_d2stern = 0
_d2port = 0
_d2starboard = 0
_fix_type = 0
_ETA_month = 0
_ETA_day = 0
_ETA_hour = 0
_ETA_minute = 0
_draught = 0
_DTE = 0
_t14text = '' # Type 14 Safety Announcement text
_isavcga:int = 0
_trailer = ''
_flat = float(0)
_flong = float(0)
_talker = ''
_Frag = 0
_Fragno = 0
_Message_ID = -1
_channel = '' # string
_Payload_ID = 0
_payload = '' # string
_repeat = 3 # dont
_binary_length = 0
_mmsi = 0
_smmsi = '000000000'
_binary_payload = ''
# ########################## ######################### ###################
# for diagnostic purposes - may be deleted in production module
def print_AIS(self):
# prints out all internal parametersd of AIS Data
print('AIS Data')
print('altitude ', self._altitude)
# special for Type 9 (SAR aircraft) records
print('SOG ', self._sog)
print('long ', self._long)
print('lat ', self._lat)
print('COG ', self._cog)
print('TruHead ', self._truhead)
print('RAIM ', self._raim)
print('rad_status ', self._rad_status)
print('time ', self._time)
print('man ', self._man)
print('name ', self._name)
print('call ', self._call)
print('destination ', self._destination)
print('nstatus ', self._nstatus)
print('pa ', self._pa)
print('displacement ', self._disp)
print('dsc ', self._dsc)
print('band ', self._band)
print('m22 ', self._m22)
print('assigned ', self._assigned)
print('version ', self._version)
print('IMO ', self._IMO)
print('type ', self._type)
print('d2bow ', self._d2bow)
print('d2stern ', self._d2stern)
print('d2port ', self._d2port)
print('d2stb ', self._d2starboard)
print('fixtype ', self._fix_type)
print('ETAMonth ', self._ETA_month)
print('ETADay ', self._ETA_day)
print('ETAHour ', self._ETA_hour)
print('ETAMinute ', self._ETA_minute)
print('draught ', self._draught)
print('DTE ', self._DTE)
print('t14text ', self._t14text)
print('isavcga ', self._isavcga)
print('trailer ', self._trailer)
print('flat ', self._flat)
print('flong ', self._flong)
print('FragCount ', self._Frag)
print('FragNo ', self._Fragno)
print('Message_ID ', self._Message_ID)
print('channel ', self._channel)
print('Payload_ID ', self._Payload_ID)
print('Payload ', self._payload)
print('binarylength ', self._binary_length)
print('mmsi ', self._mmsi)
print('binaryPayLoad ', self._binary_payload)
# ########################## ######################## #################
def get_AIS_FragCount(self):
return self._Frag
# AIS_FragCount = property(get_AIS_FragCount)
def get_AIS_FragNo(self):
return self._Fragno
'''
def get_xx(self):
return self.yy
xx = property(get_xx)
'''
def get_Message_ID(self) -> str:
return self._Message_ID
def set_Message_ID(self, value: str) -> None:
if isinstance(value, str):
self._Message_ID = value
else:
raise RuntimeError(
"Incorrect type not string supplied to set Message_ID")
# AIS_Message_ID = property(get_Message_ID)
def get_AIS_Channel(self):
return self._channel
def set_ais_Channel(self, value: str):
if isinstance(value, str):
self._channel = value
else:
raise RuntimeError(
"Incorrect type not string supplied to set AIS_Channel")
# AIS_Channel = property(get_AIS_Channel)
def get_AIS_Payload(self) -> str:
return self._payload
def set_AIS_Payload(self, value: str) -> None:
if isinstance(value, str):
self._payload = value
else:
raise RuntimeError(
"Incorrect type not string supplied to set AIS_Payload")
# AIS_Payload = property(get_AIS_Payload)
def get_AIS_Binary_Payload(self):
# print("To be returned ",self._binary_payload)
return self._binary_payload
def set_AIS_Binary_Payload(self, value: str):
self._binary_payload = ''
if isinstance(value, str):
# print("setting ", value)
# print("current ", self._binary_payload)
self._binary_payload = value
# print("after ", self._binary_payload)
else:
raise RuntimeError(
"Incorrect type not string supplied to set AIS_Binary_Payload")
def get_AIS_Binary_Payload_length(self):
return self._binary_length
def set_AIS_Binary_Payload_length(self, value):
if isinstance(value, int):
self._binary_length = value
else:
raise RuntimeError(
"Error setting binary payload length - non integer presented")
# AIS_Binary_Payload_length = property(
# get_AIS_Binary_Payload_length,
# set_AIS_Binary_Payload_length
# )
def set_AIS_Payload_ID(self, value: int) -> None:
if not isinstance(value, int):
raise RuntimeError(
"Error setting binary payload ID - non integer presented")
if value in range(1, 27):
self._Payload_ID = value
else:
raise ValueError("Error setting binary payload ID - non valid ID type")
def get_AIS_Payload_ID(self) -> int:
return self._Payload_ID
def __init__(self, talker: str, fragcount: str, fragno: str,
messid: str, channel: str, payload: str, trailer: str):
# first predefine the known internals
# if no args then we may assume it's the AISSData(enconded_string) form
# and afterwards execute tne initialise_encoded function
# otherwise it contains the following
# talker,fragcount ,fragno ,_messid,channel ,payload,trailer variables
#
argcount = 0
_parameter = ''
_parameter = talker + ',' \
+ fragcount + ',' \
+ fragno + ',' \
+ messid + ',' \
+ channel + ',' \
+ payload + ',' \
+ trailer
try:
self.m_initialise()
except Exception as e:
print("Unexpected error:", sys.exc_info()[0])
raise RuntimeError("Unexpected error:", e) from e
try:
self.m_setup(_parameter)
except Exception as e:
print("Unexpected error:", sys.exc_info()[0])
raise RuntimeError("Unexpected error:", e) from e
# now predefine all the functions necessary to initialise the class
def m_initialise(self):
_Frag = -1
_Message_ID = 0
_channel = '' # String.Empty
_Payload_ID = 0
_payload = '' # String.Empty
def m_setup(self, Encoded_String: str):
diction = AISDictionaries()
nr_items = 0
# dictionary used to avoid a case statement in AIS_Data
# translates channel number
# if non standard 1 or 2 used
diagnostic3 = False
diagnostic4 = False
logging.debug('ïn AIS_Data.m_setup encoded string = {}'.format(Encoded_String))
try:
# under c# discrete_items would be a string array,
# using pythin its a list
discrete_items = Encoded_String.split(",")
nr_items = int(len(discrete_items))
except:
print("Error Splitting AIS_DATA string", sys.exc_info()[0])
# System.ArgumentException argEx =
# new System.ArgumentException("Error Splitting AIS_DATA string")
raise
# foreach (string Data in discrete_items)
for Data in discrete_items:
# Console.WriteLine(Data)
# now confirms its a valid AIVDM string
# throw an error if not
if discrete_items[0] == "!AIVDM":
if nr_items > 4:
logging.debug('in m_setup valid string')
# number of fragments to make complete message
self.set_fragment(int(int(discrete_items[1])))
self.set_fragnumber(value=int(discrete_items[2]))
# current fragment number
xx = discrete_items[3]
# message id for multifragment message
if (len(xx) > 0):
self.set_Message_ID(discrete_items[3])
if discrete_items[4] in diction.ch_numb_dict:
self.set_ais_Channel(diction.ch_numb_dict[discrete_items[4]]) # radio channel used
else:
raise RuntimeError(
"channel number not in range {A,B,1,2")
try:
self.set_AIS_Payload(discrete_items[5])
# actual payload of the message, may need to be
except:
print("Error in extracting payload", sys.exc_info()[0])
raise
logging.debug('in m_setup _Frag = {}\r\n_Frag_no = {}\r\n_channel = {}\r\n_payload = {}'
.format(
self._Frag,
self._Fragno,
self._channel,
self._payload
))
else:
print("Insufficient fields in string " + Encoded_String, sys.exc_info()[0])
raise
intid: int = self.m_to_int(self._payload[0]) # payload type
self.set_AIS_Payload_ID(intid) # payload type)
logging.debug('in m_setup_Payload_ID = {}'.format( self._Payload_ID))
self._binary_payload, self._binary_length = (
self.create_binary_payload(self._payload)) # binary form of payload
self.set_AIS_Binary_Payload(self._binary_payload)
self.set_AIS_Binary_Payload_length(self._binary_length)
# not currently used but available if converting to use bytearray instead of str for binary payload
# _byte_payload = AIS_Data.create_bytearray_payload(self._payload)
# self._binary_length = len(_byte_payload)
logging.debug('in m_setup_binary_Payload = {}'.format( self._binary_payload))
# if message type is 14 we need to create the safety message text
#
if self._Payload_ID == 14:
self.set_SafetyText(self.ExtractString(40, self._binary_length - 41))
else:
print("Invalid Talker ID", sys.exc_info()[0])
raise RuntimeError("Invalid Talker ID")
def set_Encoded_String(self, value: str) -> None:
if isinstance(value, str):
self._parameter = value
else:
raise (TypeError, "Value passed to set_Encoded_String not a string")
def get_Encoded_String(self) -> str:
return self._parameter
def set_fragment(self, value: int) -> None:
if 0 <= value <= 9:
self._Frag = value
else:
self._Frag = 0
raise ValueError("Number of fragments cannot exceed 9")
def get_fragment(self) -> int:
return self._Frag
def set_fragnumber(self, *, value: int = 0) -> None:
if 0 <= value <= 9:
self._Fragno = value
else:
self._Fragno = 0
raise ValueError("Number of fragments cannot exceed 9")
def get_fragno(self) -> int:
return self._Fragno
def set_channel(self, value: str) -> None:
diction = AISDictionaries()
if not isinstance(value, str):
raise (TypeError, "Value passed to set_channel not a string")
if value in diction.ch_numb_dict:
self._channel = diction.ch_numb_dict[value]
else:
raise ValueError
def get_channel(self) -> str:
return self._channel
def set_trailer(self, value):
if isinstance(value, str):
self._trailer = value
else:
raise (TypeError, "Value passed to set_trailer not a string")
def extract_random_mmsi(self, startpos: int, length: int) -> tuple:
immsi = self.Binary_Item(startpos, length)
smmsi = "{:09d}".format(immsi)
# string mmsi derived from immsi
logging.debug(" return string MMSI = {}".format( smmsi))
return immsi, smmsi
def set_mmsi(self, value: int):
# mmsi is nine digits which may start with any digit from 0 to 9.
# string MMSI will be zero filled MSC if not 9 chars long
immsi = value
if 0 <= value <= 999999999:
self._mmsi = value
self._smmsi = "{:09}".format(value)
else:
self._mmsi = 0
self._smmsi = '000000000"'
raise ValueError("attempted to set MMSI outside 0-999999999")
def get_mmsi(self):
return self._mmsi
def get_smmsi(self):
return self._smmsi
def get_String_MMSI(self) -> str:
s_mmsi = str(self._mmsi)
if len(s_mmsi) == 9:
return s_mmsi
else:
while (len(s_mmsi) < 9):
# zero fill on the left
s_mmsi = "0" + s_mmsi
# Console.WriteLine(" return string MMSI = " + s_mmsi)
return s_mmsi
def do_function(self, keyword, value):
# create a dictionary of functions related to keywords that might be being initialised
Funcdict = \
{
'Encoded_String': self.set_Encoded_String,
'fragcount': self.set_fragment,
'channel': self.set_channel,
'payload': self.set_AIS_Payload,
'trailer': self.set_trailer,
'RepeatIndicator': self.set_RepeatIndicator,
'SOG': self.set_SOG,
'int_HDG': self.set_int_HDG,
'Altitude': self.set_Altitude,
'int_ROT': self.set_int_ROT,
'NavStatus': self.set_NavStatus,
'int_latitude': self.set_int_latitude,
'int_longitude': self.set_int_longitude,
'Pos_Accuracy': self.set_Pos_Accuracy,
'int_COG': self.set_int_COG,
'Timestamp': self.set_Timestamp,
'MAN_Indicator': self.set_MAN_Indicator,
'RAIM': self.set_RAIM,
'Name': self.set_Name,
'Callsign': self.set_Callsign,
'IMO': self.set_IMO,
'Version': self.set_Version,
'Destination': self.set_Destination,
'Display': self.set_Display,
'DSC': self.set_DSC,
'BAND': self.set_BAND,
'Message22': self.set_Message22,
'Assigned': self.set_Assigned,
'ShipType': self.set_ShipType,
'Dim2Bow': self.set_Dim2Bow,
'Dim2Stern': self.set_Dim2Stern,
'Dim2Port': self.set_Dim2Port,
'Dim2Starboard': self.set_Dim2Starboard,
'FixType': self.set_FixType,
'ETA_Month': self.set_ETA_Month,
'ERA_Day': self.set_ETA_Day,
'ETA_Hour': self.set_ETA_Hour,
'ETA_Minute': self.set_ETA_Minute,
'Draught': self.set_Draught,
'DTE': self.set_DTE,
'SafetyText': self.set_SafetyText,
'isAVCGA': self.set_isAVCGA
}
if keyword in Funcdict:
return Funcdict[keyword](value)
else:
raise (ValueError, "parameter name unknown")
def get_SOG(self) -> float:
self._fsog = float(self._sog)
return self._fsog / 10
def set_SOG(self, value) -> None:
self._sog = int(value)
def get_int_HDG(self) -> int:
# print('getting int HDG')
return self._truhead
def set_int_HDG(self, value) -> None:
# print ('setting int HDG ', value)
self._truhead = value
# int_HDG = property(get_int_HDG, set_int_HDG)
def ROT(self) -> float:
# ROT is coded as 4.733 * SQRT(p_rot)
# to decode divide bcoded value by 4.733 then square.
# Returns rate in degrees per minute to three decimal places
self._frot = float(0)
# switch (_rot)
if (self._rot > 0) and (self._rot < 127):
self._frot = self._rot
self._frot = (self._frot / 4.733)
self._frot = round(self._frot * self._frot, 3)
elif self._rot < 0:
if self._rot == -127: # turning left at more than 5 deg/30sec
pass
else:
self._frot = self._frot # preserve sign of RO
elif self._rot == 127: # turning right at more than 5 deg/30 sec
pass
elif self._rot == 128: # not available
pass
# Console.WriteLine("Rate of turn = " + self._frot)
return float(self._frot)
def get_Altitude(self) -> int:
return self._altitude
def set_Altitude(self, value: int) -> None:
if value >= 0 and value <= 4095:
self._altitude = value
else:
raise ValueError
def get_int_ROT(self) -> int:
return self._rot
def set_int_ROT(self, value) -> None:
self._rot = value
int_ROT = property(get_int_ROT, set_int_ROT)
def get_NavStatus(self) -> int:
return self._nstatus
def set_NavStatus(self, value: int) -> None:
if value in range(1, 15):
self._nstatus = value
else:
raise ValueError
def set_int_latitude(self, value) -> None:
# print(' setting int latitude', value)
# in 1/10000 of a minute +/- 180 degrees
if not isinstance(value, int):
raise RuntimeError(
"incorrect type {} in set_ini_latitude should be int".format(type(value)))
if (value >= -108000000) and (value <= 108000000):
self._lat = value
self._flat = float(self._lat / 6000000)
else:
raise ValueError(
"Latitude range +/- 180 degrees")
def get_int_latitude(self) -> int: # unused
return self._lat
def set_int_longitude(self, value: int) -> None:
# print (' setting int longitude', value)
# in 1/10000 of a minute +/- 180 degrees
if not isinstance(value, int):
raise RuntimeError(
"incorrect type {} in set_ini_longitude should be int".format(type(value)))
if (value >= -108000000) and (value <= 108000000):
self._long = value
self._flong = float(self._long / 6000000)
else:
raise ValueError(
"Longitude range +/- 180 degrees")
def get_int_longitude(self) -> int: # unused
return self._long
def get_Latitude(self) -> float:
return self._flat
def get_Longitude(self) -> float:
return self._flong
def get_Pos_Accuracy(self) -> int:
return self._pa
def set_Pos_Accuracy(self, *, value: int = 0):
self._pa = value
Pos_Accuracy = property(get_Pos_Accuracy, set_Pos_Accuracy)
def get_COG(self) -> float:
return self._cog
def set_COG(self, value: int) -> None:
if 0 <= value <= 3600:
self._cog = float (value/10)
else:
print('in AISDATA setting COG got incorect value = ', value)
raise ValueError
def set_int_COG(self, value) -> None:
self.set_COG(value)
def get_int_COG(self) -> int: # not used
return int(self._cog)
def get_HDG(self) -> int:
return self._truhead
def set_HDG(self, value: int) -> None:
if value >= 0 and value <= 359:
self._truhead = value
else:
print('Error setting heading incorrect value got ', value)
# need to pass back the number of bits in the payload
# it looks as though type 5 static data packets may
# not conform to standard (destination truncated
def Binary_length(self) -> int:
return int(self._binary_length)
def get_Timestamp(self) -> int:
# seconds of UTC Timestamp
# 60 timestamp unavailable
# 61 positioning system in manual input mode
# 62 Position Fixing System operating in Dead Reckoning Mode
# 63 if positioning system inoperative
return int(self._time)
def set_Timestamp(self, value: int) -> None:
if value in range(0,63):
self._time = int(value)
else:
raise ValueError('UTC seconds timestamp outside 0-63')
def set_MAN_Indicator(self, value: int) -> None:
if value in range(0,2):
self._man = int(value)
else: