-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAISProto.cs
1669 lines (1488 loc) · 70.1 KB
/
AISProto.cs
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
//
// dkxce Marine AIS Packet Constructor and Parser
// AIS Implementation for C#
// https://github.com/dkxce/Marine_AIS_Packet
//
using System;
using System.Collections.Generic;
using System.Text;
namespace dkxce.AIS
{
#region Enums
/// <summary>
/// AIS Ship Type, TABLE 18 Rec. ITU-R M.13171-1,
/// https://api.vtexplorer.com/docs/ref-aistypes.html
/// </summary>
public enum AisShipType : uint
{
Default = 0,
// 1..19 Reserved
WIG_AllShips = 20, // Wing in ground
WIG_HazardousCategoryA = 21,
WIG_HazardousCategoryB = 22,
WIG_HazardousCategoryC = 23,
WIG_HazardousCategoryD = 24,
// 25..29 Wing in ground (WIG), Reserved for future use
Fishing = 30,
Towing = 31,
TowingBig = 32, // Towing: length exceeds 200m or breadth exceeds 25m
DredgingOrUnderwater = 33, // Dredging or underwater ops
Diving = 34,
Military = 35,
Sailing = 36,
PleasureCraft = 37,
// 38..39 Reserved
HighSpeedCraft_All = 40, // HSC
HighSpeedCraft_A = 41,
HighSpeedCraft_B = 42,
HighSpeedCraft_C = 43,
HighSpeedCraft_D = 44,
// 45..48 Reserved
HighSpeedCraft_NoInfo = 49,
PilotVessel = 50,
SearchRescue = 51,
Tug = 52,
PortTender = 53,
AntiPollutionEquipment = 54,
LawEnforcement = 55,
SpareLocalVessel = 56,
SpareLocalVessel2 = 57,
MedicalTransport = 58,
NoncombatantShipAccording2RRResolutionNo_18 = 59,
Passenger_All = 60,
Passenger_A = 61,
Passenger_B = 62,
Passenger_C = 63,
Passenger_D = 64,
// 65..68 Reserved
Passenger_NoInfo = 69,
Cargo_All = 70,
Cargo_A = 71,
Cargo_B = 72,
Cargo_C = 73,
Cargo_D = 74,
// 75..78 Reserved
Cargo_NoInfo = 79,
Tanker_All = 80,
Tanker_A = 81,
Tanker_B = 82,
Tanker_C = 83,
Tanker_D = 84,
// 85..88 Reserved
Tanker_NoInfo = 89,
OtherType_All = 90,
OtherType_HazardousCategory_A = 91,
OtherType_HazardousCategory_B = 92,
OtherType_HazardousCategory_C = 93,
OtherType_HazardousCategory_D = 94,
// 95..98 Reserved
OtherType_NoInfo = 99
}
/// <summary>
/// AIS Navigation Status, TABLE 15a Rec. ITU-R M.13171-1,
/// https://api.vtexplorer.com/docs/ref-navstat.html
/// </summary>
public enum AisNavigationStatus: uint
{
UnderWayUsingEngine = 0,
AtAnchor = 1,
NotUnderCommand = 2,
RestrictedManoeuverability = 3,
ConstrainedByHerDraught = 4,
Moored = 5,
Aground = 6,
EngagedInFishing = 7,
UnderWaySailing = 8,
ReservedHSC = 9,
ReservedWIG = 10, // Wing in ground
Reserved11 = 11,
Reserved12 = 12,
Reserved13 = 13,
AISSARTisActive = 14,
NotDefined = 15
}
/// <summary>
/// AIS Maneuver Indicator, TABLE 15a Rec. ITU-R M.13171-1
/// </summary>
public enum AisManeuverIndicator: uint
{
NotAvailable = 0,
NoSpecialManeuver = 1,
SpecialManeuver = 2
}
/// <summary>
/// AIS Communication Status, TABLE 15b Rec. ITU-R M.13171-1
/// </summary>
public enum AisCommunicationStatus: uint
{
DirectUTC = 0,
UndirectUTC = 1,
BaseStationSync = 2,
AnotherStationSync = 3
}
/// <summary>
/// AIS Position Fix Status, TABLE 16 Rec. ITU-R M.13171-1
/// </summary>
public enum AisPosFix : uint
{
Undefined = 0,
GPS = 1,
Glonass = 2,
GPS_Glonass = 3,
LoranC = 4,
Chayka = 5,
IntergatedNavSys = 6,
Surveyed = 7
}
/// <summary>
/// AIS Version Indicator, TABLE 17 Rec. ITU-R M.13171-1
/// </summary>
public enum AisVersion
{
AIS_0 = 0,
AIS_1 = 1,
AIS_2 = 2,
AIS_3 = 3
}
#endregion Enums
public interface AisISentense
{
byte[] ToAisUnpacked();
string ToAisSentense();
byte[] ToAisEnpacked();
string ToAisFullPacket();
byte[] ToAisFullDataMsg();
}
public interface AisIPositionReport
{
string ToAisPositionPacket();
byte[] ToAisPositionDataMsg();
}
public abstract class AisSentense: AisISentense
{
/// <summary>
/// Packet Message Identifier, 6 bits (offset 0)
/// </summary>
public byte MessageID { get; protected set; } = 0;
/// <summary>
/// Packet Repeat Indicator, 2 bits (offset 6)
/// </summary>
public byte Repeat = 0;
/// <summary>
/// Maritime Mobile Service Identity, 30 Bits (offset 8)
/// </summary>
public uint MMSI;
public virtual string ToString()
{
if (this.MessageID == 0)
return "Empty_AisSentense";
else
return $"{this.MessageID}_AisSentense";
}
public virtual string ToAisSentense()
{
return this.ToString();
}
public virtual byte[] ToAisUnpacked()
{
return new byte[0];
}
public virtual byte[] ToAisEnpacked()
{
return AISTransCoder.EnpackAISBytes(this.ToAisUnpacked());
}
public virtual string ToAisFullPacket()
{
if (this.MessageID == 0) return String.Empty;
string res = "!AIVDM,1,1,,A," + this.ToString() + ",0";
res += "*" + AISTransCoder.Checksum(res);
res = res + "\r\n";
return res;
}
public virtual byte[] ToAisFullDataMsg()
{
if (this.MessageID == 0) return new byte[0];
return Encoding.ASCII.GetBytes(ToAisFullPacket());
}
}
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 1, TABLE 15a (p.43 Rec. ITU-R M.13171-1)
// * PACKET 2, TABLE 15a (p.43 Rec. ITU-R M.13171-1)
// * PACKET 3, TABLE 15a (p.43 Rec. ITU-R M.13171-1)
/// <summary>
/// 1 - Position Report Class A (Scheduled Position Report),
/// 2 - Position Report Class A (Assigned Scheduled Position Report),
/// 3 - Position Report Class A (Special Position Report);
/// </summary>
public class PositionReport123 : AisSentense, AisISentense, AisIPositionReport
{
private const ushort TotalNumberOfBits = 168;
private static ushort TotalNumberOfBytes = TotalNumberOfBits / 8;
public PositionReport123() { MessageID = 3; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// AIS Navigation Status, 4 Bits (offset 38)
/// </summary>
private AisNavigationStatus NavigationStatus = AisNavigationStatus.NotDefined;
/// <summary>
/// Rate-of-Turn, 8 Bits (offset 42)
/// </summary>
private int ROT = 0;
/// <summary>
/// Speed-over-Ground, kmph, 10 Bits (offset 50)
/// </summary>
public uint SOG = 0;
/// <summary>
/// Position Accuracy, 1 Bits (offset 60)
/// </summary>
public bool Accuracy = false;
/// <summary>
/// Longitude, degrees, 28 Bits (offset 61)
/// </summary>
public double Longitude = 0;
/// <summary>
/// Latitude, degrees, 27 Bits (offset 89)
/// </summary>
public double Latitude = 0;
/// <summary>
/// Course-Over-Ground, degrees, 12 Bits (offset 116)
/// </summary>
public double COG = 0;
/// <summary>
/// True Heading, degrees, 9 Bits (offset 128)
/// </summary>
public ushort HDG = 0;
/// <summary>
/// UTC timestamp, 6 Bits (offset 137)
/// 0..60 - Not Available, 61 - Manual Mode, 62 - Dead Reckoning, 63 - Inoperative
/// </summary>
public uint TimeStamp = 60;
/// <summary>
/// Maneuver Indicator, 2 Bits (offset 143)
/// </summary>
public AisManeuverIndicator ManeuverIndicator = AisManeuverIndicator.NoSpecialManeuver;
/// <summary>
/// Radio status, 19 Bits (offset 149)
/// </summary>
public AisCommunicationStatus RadioStatus = AisCommunicationStatus.DirectUTC;
public static PositionReport123 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length < TotalNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if ((stype < 1) || (stype > 3)) return null;
PositionReport123 res = new PositionReport123();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
res.NavigationStatus = (AisNavigationStatus)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 38, 4);
res.ROT = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 42, 8);
res.SOG = (uint)(AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 50, 10) / 10 * 1.852);
res.Accuracy = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 60, 1) == 1 ? true : false;
res.Longitude = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 61, 28) / 600000.0;
res.Latitude = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 89, 27) / 600000.0;
res.COG = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 116, 12) / 10.0;
res.HDG = (ushort)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 128, 9);
res.TimeStamp = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 137, 6);
res.ManeuverIndicator = (AisManeuverIndicator)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 143, 2);
res.RadioStatus = (AisCommunicationStatus)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 149, 19);
return res;
}
public static PositionReport123 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
int acc = Accuracy ? 1 : 0;
byte[] unpackedBytes = new byte[TotalNumberOfBytes];
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 004, (int)NavigationStatus);
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 042, 008, (int)ROT);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 050, 010, (int)(SOG / 1.852 * 10));
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 060, 001, (int)acc);
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 061, 028, (int)(Longitude * 600000));
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 089, 027, (int)(Latitude * 600000));
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 116, 012, (int)(COG * 10));
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 128, 009, (int)HDG);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 137, 006, (int)TimeStamp);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 143, 002, (int)ManeuverIndicator);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 145, 002, (int)0); // Reserved
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 147, 001, (int)0); // Spare
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 148, 001, (int)0); // RAIM
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 149, 019, (int)RadioStatus);
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}
public string ToAisPositionPacket()
{
string ln1 = "!AIVDM,1,1,,A," + this.ToString() + ",0";
ln1 += "*" + AISTransCoder.Checksum(ln1);
string res = ln1 + "\r\n";
return res;
}
public byte[] ToAisPositionDataMsg()
{
return Encoding.ASCII.GetBytes(ToAisPositionPacket());
}
public string ToAisPositionPacket(ShipStaticAndVoyageRelatedReport5 ai)
{
string ln1 = "!AIVDM,1,1,,A," + this.ToString() + ",0";
ln1 += "*" + AISTransCoder.Checksum(ln1);
string ln2 = "!AIVDM,1,1,,A," + ai.ToString() + ",0";
ln2 += "*" + AISTransCoder.Checksum(ln2);
string res = ln1 + "\r\n" + ln2 + "\r\n";
return res;
}
public byte[] ToAisPositionPacketAsBytes(ShipStaticAndVoyageRelatedReport5 ai)
{
return Encoding.ASCII.GetBytes(ToAisPositionPacket(ai));
}
}
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 4, TABLE 16 (p.44 Rec. ITU-R M.13171-1)
// * PACKET 11, TABLE 16 (p.44 Rec. ITU-R M.13171-1)
/// <summary>
/// 4 - Base station report,
/// 11 - UTC/date response;
/// </summary>
public class BaseStationReport4: AisSentense, AisISentense, AisIPositionReport
{
private const ushort TotalNumberOfBits = 168;
private static ushort TotalNumberOfBytes = TotalNumberOfBits / 8;
public BaseStationReport4() { MessageID = 4; }
public BaseStationReport4(bool utcResponse) { MessageID = utcResponse ? (byte)11 : (byte)4; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// DateTime UTC, 40 Bits (offset 38)
/// </summary>
public DateTime? UTC;
/// <summary>
/// Position Accuracy, 1 Bits (offset 78)
/// </summary>
public bool Accuracy = false;
/// <summary>
/// Longitude, degrees, 28 Bits (offset 79)
/// </summary>
public double Longitude = 0;
/// <summary>
/// Latitude, degrees, 27 Bits (offset 107)
/// </summary>
public double Latitude = 0;
/// <summary>
/// GPS Position Fix, 4 Bits (offset 134)
/// </summary>
public AisPosFix PosFix = AisPosFix.Undefined;
/// <summary>
/// Radio status, 19 Bits (offset 149)
/// </summary>
private AisCommunicationStatus RadioStatus = AisCommunicationStatus.DirectUTC;
public static BaseStationReport4 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length < TotalNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if ((stype != 4) && (stype != 11)) return null;
BaseStationReport4 res = new BaseStationReport4();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
int yy = (int)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 14, 38);
int MM = (int)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 4, 52);
int dd = (int)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 5, 56);
int hh = (int)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 5, 61);
int mm = (int)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 66);
int ss = (int)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 72);
if ((yy != 0) || (MM != 0) || (dd != 0) || (hh != 24) || (mm != 60) || (ss != 60))
{
if (yy == 0) yy = DateTime.UtcNow.Year;
if (MM == 0) MM = DateTime.UtcNow.Month;
if (dd == 0) dd = DateTime.UtcNow.Day;
if (hh == 24) hh = DateTime.UtcNow.Hour;
if (hh == 60) mm = DateTime.UtcNow.Minute;
if (hh == 60) ss = DateTime.UtcNow.Second;
res.UTC = new DateTime(yy, MM, dd, hh, mm, ss, DateTimeKind.Utc);
};
res.Accuracy = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 78, 1) == 1 ? true : false;
res.Longitude = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 79, 28) / 600000.0;
res.Latitude = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 107, 27) / 600000.0;
res.PosFix = (AisPosFix)AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 134, 4);
res.RadioStatus = (AisCommunicationStatus)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 149, 19);
return res;
}
public static BaseStationReport4 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
int acc = Accuracy ? 1 : 0;
byte[] unpackedBytes = new byte[TotalNumberOfBytes];
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 014, UTC == null ? (int)00 : (int)UTC.Value.Year);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 052, 004, UTC == null ? (int)00 : (int)UTC.Value.Month);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 056, 005, UTC == null ? (int)00 : (int)UTC.Value.Day);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 061, 005, UTC == null ? (int)24 : (int)UTC.Value.Hour);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 066, 006, UTC == null ? (int)60 : (int)UTC.Value.Minute);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 072, 006, UTC == null ? (int)60 : (int)UTC.Value.Second);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 078, 001, (int)acc);
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 079, 028, (int)(Longitude * 600000));
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 107, 027, (int)(Latitude * 600000));
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 134, 004, (int)PosFix);
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 138, 010, (int)0); // Spare
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 148, 001, (int)0); // RAIM
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 149, 019, (int)RadioStatus);
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}
public string ToAisPositionPacket()
{
string ln1 = "!AIVDM,1,1,,A," + this.ToString() + ",0";
ln1 += "*" + AISTransCoder.Checksum(ln1);
string res = ln1 + "\r\n";
return res;
}
public byte[] ToAisPositionDataMsg()
{
return Encoding.ASCII.GetBytes(ToAisPositionPacket());
}
}
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 5, TABLE 17 (p.45 Rec. ITU-R M.13171-1)
/// <summary>
/// 5 - Static and voyage related data;
/// </summary>
public class ShipStaticAndVoyageRelatedReport5 : AisSentense
{
private const short TotalNumberOfBits = 424;
private static ushort TotalNumberOfBytes = TotalNumberOfBits / 8;
public ShipStaticAndVoyageRelatedReport5 () { MessageID = 5; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// AIS Version, 2 Bits (offset 38)
/// </summary>
public AisVersion AisVer { get; private set; } = AisVersion.AIS_0;
/// <summary>
/// IMO Number, 30 Bits (offset 40)
/// </summary>
public uint IMOShipID;
/// <summary>
/// 7-symbols Callsign, 42 Bits (offset 70)
/// </summary>
public string CallSign;
/// <summary>
/// 20-symbols Vessel, 120 Bits (offset 112)
/// </summary>
public string VesselName;
/// <summary>
/// Type of Ship/Cargo, 8 Bits (offset 232)
/// </summary>
public AisShipType ShipType = AisShipType.Default;
/// <summary>
/// Ship Dimentions A-B-C-D, 30 Bits (offset 240)
/// FIGURE 17 (p.48 Rec. ITU-R M.13171-1)
/// </summary>
public int[] Dimensions = new int[4];
/// <summary>
/// GPS Position Fix, 4 Bits (offset 270)
/// </summary>
public AisPosFix PosFix = AisPosFix.Undefined;
/// <summary>
/// Estimated time of arrival, UTC, 20 Bits (offset 274)
/// </summary>
public DateTime? ETA = null;
/// <summary>
/// Maximum present static draught, m, 8 Bits (offset 294)
/// </summary>
public double Draught = 0;
/// <summary>
/// 20-symbols Destination, 120 Bits (offset 302)
/// </summary>
public string Destination = "";
/// <summary>
/// Data Terminal Ready, 1 Bit (offset 422)
/// </summary>
public bool DataTerminalReady = false;
public static ShipStaticAndVoyageRelatedReport5 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length < TotalNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if (stype != 5) return null;
ShipStaticAndVoyageRelatedReport5 res = new ShipStaticAndVoyageRelatedReport5 ();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
res.AisVer = (AisVersion)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 2, 38);
res.IMOShipID = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 40, 30);
res.CallSign = AISTransCoder.GetAisString(unpackedBytes, 70, 42);
res.VesselName = AISTransCoder.GetAisString(unpackedBytes, 112, 120);
res.ShipType = (AisShipType)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 232, 8);
res.Dimensions[0] = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 240, 9);
res.Dimensions[1] = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 249, 9);
res.Dimensions[2] = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 258, 6);
res.Dimensions[3] = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 264, 6);
res.PosFix = (AisPosFix)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 270, 4);
int MM = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 274, 4);
int dd = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 278, 4);
int hh = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 282, 6);
int mm = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 288, 6);
if((MM != 0) || (dd != 0) || (hh != 24) || (mm != 60))
{
if (MM == 0) MM = DateTime.UtcNow.Month;
if (dd == 0) dd = DateTime.UtcNow.Day;
if (hh == 0) hh = DateTime.UtcNow.Hour;
if (mm == 0) mm = DateTime.UtcNow.Minute;
res.ETA = new DateTime(MM < DateTime.UtcNow.Month ? DateTime.UtcNow.Year + DateTime.UtcNow.Year : DateTime.UtcNow.Year, MM, dd, hh, mm, 00, DateTimeKind.Utc);
};
res.Draught = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 294, 8) * 10.0;
res.Destination = AISTransCoder.GetAisString(unpackedBytes, 302, 120);
res.DataTerminalReady = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 422, 1) == 0;
return res;
}
public static ShipStaticAndVoyageRelatedReport5 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
string callsign = string.IsNullOrEmpty(CallSign) ? "UNKNOWN" : CallSign.ToUpper();
if (callsign.Length > 7) callsign = callsign.Substring(0, 7);
string vessel = string.IsNullOrEmpty(VesselName) ? "UNKNOWN" : VesselName.ToUpper();
if (vessel.Length > 20) vessel = vessel.Substring(0, 20);
string dest = string.IsNullOrEmpty(Destination) ? "UNKNOWN" : Destination.ToUpper();
if (dest.Length > 20) dest = dest.Substring(0, 20);
byte[] unpackedBytes = new byte[TotalNumberOfBytes]; // 54?
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 002, (int)AisVer); // AIS Version
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 040, 030, (int)IMOShipID);
AISTransCoder.SetAisString(unpackedBytes, 070, 042, callsign);
AISTransCoder.SetAisString(unpackedBytes, 112, 120, vessel);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 232, 008, (int)ShipType);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 240, 009, Dimensions == null || Dimensions.Length != 4 ? (int)0 : (int)Dimensions[0]); //A DIMENTIONS
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 249, 009, Dimensions == null || Dimensions.Length != 4 ? (int)0 : (int)Dimensions[1]); //B DIMENTIONS
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 258, 006, Dimensions == null || Dimensions.Length != 4 ? (int)0 : (int)Dimensions[2]); //C DIMENTIONS
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 264, 006, Dimensions == null || Dimensions.Length != 4 ? (int)0 : (int)Dimensions[3]); //D DIMENTIONS
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 270, 004, (int)PosFix);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 274, 004, ETA == null ? 00 : ETA.Value.Month);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 278, 005, ETA == null ? 00 : ETA.Value.Day);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 283, 005, ETA == null ? 24 : ETA.Value.Hour);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 288, 006, ETA == null ? 60 : ETA.Value.Minute);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 294, 008, (int)Draught); // Maximum present static draught
AISTransCoder.SetAisString(unpackedBytes, 302, 120, dest);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 422, 001, DataTerminalReady ? 0 : 1); // DTE
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 423, 001, (int)0); // Spare
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}
}
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 6, TABLE 19 (p.49 Rec. ITU-R M.13171-1)
/// <summary>
/// 6 - Addressed Binary Message;
/// </summary>
public class AddressedBinaryMessage6: AisSentense
{
private const short MaxNumberOfBits = 1008;
private static ushort MaxNumberOfBytes = MaxNumberOfBits / 8;
public AddressedBinaryMessage6() { MessageID = 6; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// Sequence Number, 2 Bits (offset 38)
/// </summary>
public uint SeqNum = 0;
/// <summary>
/// Maritime Mobile Service Identity, 30 Bits (offset 40)
/// </summary>
public uint DestMMSI;
/// <summary>
/// Retransmit flag, 1 Bit (offset 70)
/// </summary>
public bool Retransmit = false;
/// <summary>
/// Binary Data, Max 117 Bytes or 936 Bits (offset 72)
/// </summary>
public byte[] Data = new byte[0];
public static AddressedBinaryMessage6 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length > MaxNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if (stype != 6) return null;
AddressedBinaryMessage6 res = new AddressedBinaryMessage6();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
res.SeqNum = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 38, 2);
res.DestMMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 40, 30);
res.Retransmit = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 70, 1) == 1;
List<byte> bytes = new List<byte>();
for (int i = 9; i < unpackedBytes.Length; i++) bytes.Add(unpackedBytes[i]);
res.Data = bytes.ToArray();
return res;
}
public static AddressedBinaryMessage6 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
int dLen = Math.Min(Data.Length, 117);
byte[] unpackedBytes = new byte[9 + dLen];
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 002, (int)SeqNum);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 040, 030, (int)DestMMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 070, 001, Retransmit ? 1 : 0);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 071, 001, 0); // Spare
for (int i = 0; i < dLen; i++) unpackedBytes[9 + i] = Data[i];
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}
}
// NO MESSAGE Acknowledgement 7, 13
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 8, TABLE 22 (p.52 Rec. ITU-R M.13171-1)
/// <summary>
/// 8 - Binary Broadcast Message;
/// </summary>
public class BinaryBroadcastMessage8: AisSentense
{
private const short MaxNumberOfBits = 1008;
private static ushort MaxNumberOfBytes = MaxNumberOfBits / 8;
public BinaryBroadcastMessage8() { MessageID = 8; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// Binary Data, Max 121 Bytes or 968 Bits (offset 40)
/// </summary>
public byte[] Data = new byte[0];
public static BinaryBroadcastMessage8 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length > MaxNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if (stype != 8) return null;
BinaryBroadcastMessage8 res = new BinaryBroadcastMessage8();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
List<byte> bytes = new List<byte>();
for (int i = 5; i < unpackedBytes.Length; i++) bytes.Add(unpackedBytes[i]);
res.Data = bytes.ToArray();
return res;
}
public static BinaryBroadcastMessage8 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
int dLen = Math.Min(Data.Length, 121);
byte[] unpackedBytes = new byte[5 + dLen];
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 002, (int)0); // Spare
for (int i = 0; i < dLen; i++) unpackedBytes[5 + i] = Data[i];
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}
}
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 9, TABLE 23 (p.53 Rec. ITU-R M.13171-1)
/// <summary>
/// 9 - Aircraft Position Report;
/// </summary>
public class AircraftPositionReport9 : AisSentense, AisISentense, AisIPositionReport
{
private const ushort TotalNumberOfBits = 168;
private static ushort TotalNumberOfBytes = TotalNumberOfBits / 8;
public AircraftPositionReport9() { MessageID = 9; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// Altitude, m, 12 Bits (offset 38)
/// </summary>
public uint Altitude = 4095;
/// <summary>
/// Speed-over-Ground, kmph, 10 Bits (offset 50)
/// </summary>
public uint SOG = 0;
/// <summary>
/// Position Accuracy, 1 Bits (offset 60)
/// </summary>
public bool Accuracy = false;
/// <summary>
/// Longitude, degrees, 28 Bits (offset 61)
/// </summary>
public double Longitude = 0;
/// <summary>
/// Latitude, degrees, 27 Bits (offset 89)
/// </summary>
public double Latitude = 0;
/// <summary>
/// Course-Over-Ground, degrees, 12 Bits (offset 116)
/// </summary>
public double COG = 0;
/// <summary>
/// UTC timestamp, 6 Bits (offset 128)
/// 0..60 - Not Available, 61 - Manual Mode, 62 - Dead Reckoning, 63 - Inoperative
/// </summary>
public uint TimeStamp = 60;
/// <summary>
/// Data Terminal Ready, 1 Bit (offset 142)
/// </summary>
public bool DataTerminalReady = false;
/// <summary>
/// Radio status, 19 Bits (offset 149)
/// </summary>
private AisCommunicationStatus RadioStatus = AisCommunicationStatus.DirectUTC;
public static AircraftPositionReport9 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length < TotalNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if ((stype != 13)) return null;
AircraftPositionReport9 res = new AircraftPositionReport9();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
res.Altitude = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 38, 12);
res.SOG = (uint)(AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 50, 10) / 10 * 1.852);
res.Accuracy = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 60, 1) == 1 ? true : false;
res.Longitude = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 61, 28) / 600000.0;
res.Latitude = AISTransCoder.GetBitsAsSignedInt(unpackedBytes, 89, 27) / 600000.0;
res.COG = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 116, 12) / 10.0;
res.TimeStamp = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 128, 6);
res.DataTerminalReady = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 142, 2) == 0;
res.RadioStatus = (AisCommunicationStatus)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 149, 19);
return res;
}
public static AircraftPositionReport9 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
int acc = Accuracy ? 1 : 0;
byte[] unpackedBytes = new byte[TotalNumberOfBytes];
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 012, (int)Altitude);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 050, 010, (int)(SOG / 1.852 * 10));
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 060, 001, (int)acc);
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 061, 028, (int)(Longitude * 600000));
AISTransCoder.SetBitsAsSignedInt(unpackedBytes, 089, 027, (int)(Latitude * 600000));
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 116, 012, (int)(COG * 10));
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 128, 006, (int)TimeStamp);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 142, 001, DataTerminalReady ? 0 : 1);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 143, 005, (int)0); // Spare
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 147, 001, (int)0); // Spare
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 148, 001, (int)0); // RAIM
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 149, 019, (int)RadioStatus);
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}
public string ToAisPositionPacket()
{
string ln1 = "!AIVDM,1,1,,A," + this.ToString() + ",0";
ln1 += "*" + AISTransCoder.Checksum(ln1);
string res = ln1 + "\r\n";
return res;
}
public byte[] ToAisPositionDataMsg()
{
return Encoding.ASCII.GetBytes(ToAisPositionPacket());
}
}
// TABLE 13 (p.40 Rec. ITU-R M.13171-1):
// * PACKET 10, TABLE 24 (p.54 Rec. ITU-R M.13171-1)
/// <summary>
/// 10 - UTC and date inquiry;
/// </summary>
public class UTCandDateInquiryMessage10 : AisSentense
{
private const ushort TotalNumberOfBits = 72;
private static ushort TotalNumberOfBytes = TotalNumberOfBits / 8;
public UTCandDateInquiryMessage10() { MessageID = 10; }
// MessageID, 6 Bits (offset 0)
// Repeat, 2 Bits (offset 6)
// MMSI, 30 Bits (offset 8)
/// <summary>
/// Maritime Mobile Service Identity, 30 Bits (offset 40)
/// </summary>
public uint DestMMSI;
public static UTCandDateInquiryMessage10 FromAIS(byte[] unpackedBytes)
{
if (unpackedBytes == null) return null;
if (unpackedBytes.Length < TotalNumberOfBytes) return null;
int stype = AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 0, 6);
if (stype != 10) return null;
UTCandDateInquiryMessage10 res = new UTCandDateInquiryMessage10();
res.MessageID = (byte)stype;
res.Repeat = (byte)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 6, 2);
res.MMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 8, 30);
res.DestMMSI = (uint)AISTransCoder.GetBitsAsUnsignedInt(unpackedBytes, 40, 30);
List<byte> bytes = new List<byte>();
return res;
}
public static UTCandDateInquiryMessage10 FromAIS(string ais)
{
byte[] unp = AISTransCoder.UnpackAISString(ais);
return FromAIS(unp);
}
public override byte[] ToAisUnpacked()
{
byte[] unpackedBytes = new byte[TotalNumberOfBytes];
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 000, 006, (int)MessageID);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 006, 002, (int)Repeat);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 008, 030, (int)MMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 038, 002, (int)0); // Spare
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 040, 030, (int)DestMMSI);
AISTransCoder.SetBitsAsUnsignedInt(unpackedBytes, 070, 002, (int)0); // Spare
return unpackedBytes;
}
public override string ToString()
{
return AISTransCoder.EnpackAISString(ToAisUnpacked());
}