From dfd024ec37dabcaa6146b70b2dd5ff1e3795181c Mon Sep 17 00:00:00 2001
From: amsga <49681949+amsga@users.noreply.github.com>
Date: Sat, 14 Dec 2024 19:07:05 +0800
Subject: [PATCH] Added UnitTestAISMessage for some of the more common unit
test. Changed implementation based on SonarCloud recommendation.
---
AIS/AIS.csproj | 4 +-
AIS/AISMessage.cs | 56 ++++++++++++--------
AIS/AISMessage01.cs | 12 ++---
AIS/AISMessage02.cs | 12 ++---
AIS/AISMessage03.cs | 12 ++---
AIS/AISMessage04.cs | 12 ++---
AIS/AISMessage05.cs | 34 ++++++-------
AIS/AISMessage09.cs | 10 ++--
AIS/AISMessage11.cs | 12 ++---
AIS/AISMessage18.cs | 10 ++--
AIS/AISMessage19.cs | 26 +++++-----
AIS/AISMessage24.cs | 30 +++++------
AIS/ITDMACommunicationState.cs | 2 +-
XUnitTestProjectAIS/UnitTestAISMessage.cs | 62 +++++++++++++++++++++++
14 files changed, 184 insertions(+), 110 deletions(-)
create mode 100644 XUnitTestProjectAIS/UnitTestAISMessage.cs
diff --git a/AIS/AIS.csproj b/AIS/AIS.csproj
index f74f6e7..0d41e11 100644
--- a/AIS/AIS.csproj
+++ b/AIS/AIS.csproj
@@ -7,7 +7,7 @@
true
true
TensionDev.Maritime.AIS
- 0.4.1
+ 0.4.2
TensionDev amsga
TensionDev
TensionDev.Maritime.AIS
@@ -21,7 +21,7 @@
Initial project release
en-SG
0.4.0.0
- 0.4.1.0
+ 0.4.2.0
true
snupkg
diff --git a/AIS/AISMessage.cs b/AIS/AISMessage.cs
index 6627eb9..d5a7fc1 100644
--- a/AIS/AISMessage.cs
+++ b/AIS/AISMessage.cs
@@ -6,7 +6,7 @@ namespace TensionDev.Maritime.AIS
{
public abstract class AISMessage
{
- private protected static UInt16 s_groupId = 0;
+ protected UInt16 s_groupId = 0;
protected UInt16 messageId6;
protected UInt16 repeatIndicator2;
@@ -55,7 +55,7 @@ public static AISMessage DecodeSentences(IList sentences)
throw new NotImplementedException("Sentence Identifier not recognised.");
}
- String[] vs = sentence.Split(new char[] { ',', '*' });
+ String[] vs = sentence.Split(',', '*' );
// Ensure sentences count is equal to sentence fragment count.
if (vs[1] != sentences.Count.ToString())
@@ -82,8 +82,31 @@ public static AISMessage DecodeSentences(IList sentences)
payloads.Add(vs[5]);
}
- AISMessage aisMessage;
+ AISMessage aisMessage = CreateAISMessage(messageId);
+
+ if (sentenceIdentifier == "VDM")
+ {
+ aisMessage.SentenceFormatter = SentenceFormatterEnum.VDM;
+ }
+ else if (sentenceIdentifier == "VDO")
+ {
+ aisMessage.SentenceFormatter = SentenceFormatterEnum.VDO;
+ }
+
+ aisMessage.DecodePayloads(payloads);
+ return aisMessage;
+ }
+
+ ///
+ /// Creates an AIS Message Object based on encoded message ID
+ ///
+ /// Encoded Message ID
+ ///
+ ///
+ private static AISMessage CreateAISMessage(string messageId)
+ {
+ AISMessage aisMessage;
switch (messageId)
{
case "1":
@@ -142,17 +165,6 @@ public static AISMessage DecodeSentences(IList sentences)
throw new NotImplementedException("Message Identifier not recognised.");
}
- if (sentenceIdentifier == "VDM")
- {
- aisMessage.SentenceFormatter = SentenceFormatterEnum.VDM;
- }
- else if (sentenceIdentifier == "VDO")
- {
- aisMessage.SentenceFormatter = SentenceFormatterEnum.VDO;
- }
-
- aisMessage.DecodePayloads(payloads);
-
return aisMessage;
}
@@ -162,7 +174,7 @@ public static AISMessage DecodeSentences(IList sentences)
/// The Value to get the bitvector from
/// The end index of the bits required
/// The bitvector containing the required number of bits
- public UInt64 GetBitVector(Int64 value, Int32 bitcount)
+ public static UInt64 GetBitVector(Int64 value, Int32 bitcount)
{
UInt64 bv = 0;
Int64 mask;
@@ -184,7 +196,7 @@ public UInt64 GetBitVector(Int64 value, Int32 bitcount)
/// The end index of the bits required
/// The start index of the bits required
/// The bitvector containing the required number of bits
- public UInt64 GetBitVector(Int64 value, Int32 bitcount, Int32 startindex)
+ public static UInt64 GetBitVector(Int64 value, Int32 bitcount, Int32 startindex)
{
UInt64 bv = 0;
Int64 mask;
@@ -204,7 +216,7 @@ public UInt64 GetBitVector(Int64 value, Int32 bitcount, Int32 startindex)
/// The Value to get the bitvector from
/// The end index of the bits required
/// The bitvector containing the required number of bits
- public UInt64 GetBitVector(UInt64 value, Int32 bitcount)
+ public static UInt64 GetBitVector(UInt64 value, Int32 bitcount)
{
UInt64 bv = 0;
UInt64 mask;
@@ -212,7 +224,7 @@ public UInt64 GetBitVector(UInt64 value, Int32 bitcount)
for (Int32 i = 0; i < bitcount; i++)
{
mask = (UInt64)Math.Pow(2, i);
- bv = (UInt64)(mask & value) | bv;
+ bv = (mask & value) | bv;
}
return bv;
@@ -226,7 +238,7 @@ public UInt64 GetBitVector(UInt64 value, Int32 bitcount)
/// The end index of the bits required
/// The start index of the bits required
/// The bitvector containing the required number of bits
- public UInt64 GetBitVector(UInt64 value, Int32 bitcount, Int32 startindex)
+ public static UInt64 GetBitVector(UInt64 value, Int32 bitcount, Int32 startindex)
{
UInt64 bv = 0;
UInt64 mask;
@@ -234,7 +246,7 @@ public UInt64 GetBitVector(UInt64 value, Int32 bitcount, Int32 startindex)
for (Int32 i = startindex; i < bitcount; i++)
{
mask = (UInt64)Math.Pow(2, i);
- bv = (UInt64)(mask & value) | bv;
+ bv = (mask & value) | bv;
}
bv >>= startindex;
@@ -273,7 +285,7 @@ public String EncodePayload(UInt64 bitvector, Int32 bitsleft)
return EncodePayload(bitvector / 64, bitsleft - 6) + symbol;
}
- public UInt64 DecodePayload(String payload, Int32 startIndex, Int32 length)
+ public static UInt64 DecodePayload(String payload, Int32 startIndex, Int32 length)
{
if (length > 10)
{
@@ -304,7 +316,7 @@ public UInt64 DecodePayload(String payload, Int32 startIndex, Int32 length)
///
/// The NMEA 0183 sentence to be computed, inclusive of the start delimiter "!" and just before the checksum delimiter "*"
/// The 8-bit XOR value.
- protected Byte CalculateChecksum(String sentence)
+ protected static Byte CalculateChecksum(String sentence)
{
Byte checksum = 0b0;
Byte[] data = Encoding.ASCII.GetBytes(sentence.Substring(1));
diff --git a/AIS/AISMessage01.cs b/AIS/AISMessage01.cs
index 21955ff..ead48bf 100644
--- a/AIS/AISMessage01.cs
+++ b/AIS/AISMessage01.cs
@@ -413,7 +413,7 @@ private void GetBitVector0_59()
if (rateOfTurn8 < 0)
{
- UInt64 tempRateOfTurn = (UInt64)(rateOfTurn8 + (Int32)0xFF);
+ UInt64 tempRateOfTurn = (UInt64)(rateOfTurn8 + 0xFF);
_bitVector0_59 <<= 8;
_bitVector0_59 |= tempRateOfTurn;
@@ -421,7 +421,7 @@ private void GetBitVector0_59()
else
{
_bitVector0_59 <<= 8;
- _bitVector0_59 |= (UInt64)((UInt16)rateOfTurn8);
+ _bitVector0_59 |= (UInt16)rateOfTurn8;
}
_bitVector0_59 <<= 10;
@@ -439,7 +439,7 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector60_119 <<= 28;
_bitVector60_119 |= tempLongitude;
@@ -447,12 +447,12 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 28;
- _bitVector60_119 |= (UInt64)((UInt32)longitude28);
+ _bitVector60_119 |= (UInt32)longitude28;
}
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 27;
_bitVector60_119 |= tempLatitude;
@@ -460,7 +460,7 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 27;
- _bitVector60_119 |= (UInt64)((UInt32)latitude27);
+ _bitVector60_119 |= (UInt32)latitude27;
}
_bitVector60_119 <<= 4;
diff --git a/AIS/AISMessage02.cs b/AIS/AISMessage02.cs
index ecc1893..d262c5d 100644
--- a/AIS/AISMessage02.cs
+++ b/AIS/AISMessage02.cs
@@ -413,7 +413,7 @@ private void GetBitVector0_59()
if (rateOfTurn8 < 0)
{
- UInt64 tempRateOfTurn = (UInt64)(rateOfTurn8 + (Int32)0xFF);
+ UInt64 tempRateOfTurn = (UInt64)(rateOfTurn8 + 0xFF);
_bitVector0_59 <<= 8;
_bitVector0_59 |= tempRateOfTurn;
@@ -421,7 +421,7 @@ private void GetBitVector0_59()
else
{
_bitVector0_59 <<= 8;
- _bitVector0_59 |= (UInt64)((UInt16)rateOfTurn8);
+ _bitVector0_59 |= (UInt16)rateOfTurn8;
}
_bitVector0_59 <<= 10;
@@ -439,7 +439,7 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector60_119 <<= 28;
_bitVector60_119 |= tempLongitude;
@@ -447,12 +447,12 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 28;
- _bitVector60_119 |= (UInt64)((UInt32)longitude28);
+ _bitVector60_119 |= (UInt32)longitude28;
}
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 27;
_bitVector60_119 |= tempLatitude;
@@ -460,7 +460,7 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 27;
- _bitVector60_119 |= (UInt64)((UInt32)latitude27);
+ _bitVector60_119 |= (UInt32)latitude27;
}
_bitVector60_119 <<= 4;
diff --git a/AIS/AISMessage03.cs b/AIS/AISMessage03.cs
index 5134e9d..15c855a 100644
--- a/AIS/AISMessage03.cs
+++ b/AIS/AISMessage03.cs
@@ -413,7 +413,7 @@ private void GetBitVector0_59()
if (rateOfTurn8 < 0)
{
- UInt64 tempRateOfTurn = (UInt64)(rateOfTurn8 + (Int32)0xFF);
+ UInt64 tempRateOfTurn = (UInt64)(rateOfTurn8 + 0xFF);
_bitVector0_59 <<= 8;
_bitVector0_59 |= tempRateOfTurn;
@@ -421,7 +421,7 @@ private void GetBitVector0_59()
else
{
_bitVector0_59 <<= 8;
- _bitVector0_59 |= (UInt64)((UInt16)rateOfTurn8);
+ _bitVector0_59 |= (UInt16)rateOfTurn8;
}
_bitVector0_59 <<= 10;
@@ -439,7 +439,7 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector60_119 <<= 28;
_bitVector60_119 |= tempLongitude;
@@ -447,12 +447,12 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 28;
- _bitVector60_119 |= (UInt64)((UInt32)longitude28);
+ _bitVector60_119 |= (UInt32)longitude28;
}
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 27;
_bitVector60_119 |= tempLatitude;
@@ -460,7 +460,7 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 27;
- _bitVector60_119 |= (UInt64)((UInt32)latitude27);
+ _bitVector60_119 |= (UInt32)latitude27;
}
_bitVector60_119 <<= 4;
diff --git a/AIS/AISMessage04.cs b/AIS/AISMessage04.cs
index 899031d..1869411 100644
--- a/AIS/AISMessage04.cs
+++ b/AIS/AISMessage04.cs
@@ -288,7 +288,7 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector60_119 <<= 28;
_bitVector60_119 |= tempLongitude;
@@ -296,15 +296,15 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 28;
- _bitVector60_119 |= (UInt64)((UInt32)longitude28);
+ _bitVector60_119 |= (UInt32)longitude28;
}
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 13;
- _bitVector60_119 |= GetBitVector((UInt64)tempLatitude, 27, 14);
+ _bitVector60_119 |= GetBitVector(tempLatitude, 27, 14);
}
else
{
@@ -319,10 +319,10 @@ private void GetBitVector120_167()
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector120_167 <<= 14;
- _bitVector120_167 |= GetBitVector((UInt64)tempLatitude, 14);
+ _bitVector120_167 |= GetBitVector(tempLatitude, 14);
}
else
{
diff --git a/AIS/AISMessage05.cs b/AIS/AISMessage05.cs
index 63fe923..aeeaceb 100644
--- a/AIS/AISMessage05.cs
+++ b/AIS/AISMessage05.cs
@@ -497,24 +497,24 @@ private void GetBitVector60_119()
_bitVector60_119 |= callSign42;
_bitVector60_119 <<= 8;
- _bitVector60_119 |= GetBitVector((UInt64)name0_59, 60, 52);
+ _bitVector60_119 |= GetBitVector(name0_59, 60, 52);
}
private void GetBitVector120_179()
{
_bitVector120_179 = 0;
- _bitVector120_179 = GetBitVector((UInt64)name0_59, 52);
+ _bitVector120_179 = GetBitVector(name0_59, 52);
_bitVector120_179 <<= 8;
- _bitVector120_179 |= GetBitVector((UInt64)name60_119, 60, 52);
+ _bitVector120_179 |= GetBitVector(name60_119, 60, 52);
}
private void GetBitVector180_239()
{
_bitVector180_239 = 0;
- _bitVector180_239 = GetBitVector((UInt64)name60_119, 52);
+ _bitVector180_239 = GetBitVector(name60_119, 52);
_bitVector180_239 <<= 8;
_bitVector180_239 |= shipAndCargoType8;
@@ -561,24 +561,24 @@ private void GetBitVector300_359()
_bitVector300_359 = GetBitVector((UInt64)maxPresentStaticDraught8, 2);
_bitVector300_359 <<= 58;
- _bitVector300_359 |= GetBitVector((UInt64)destination0_59, 60, 2);
+ _bitVector300_359 |= GetBitVector(destination0_59, 60, 2);
}
private void GetBitVector360_419()
{
_bitVector360_419 = 0;
- _bitVector360_419 = GetBitVector((UInt64)destination0_59, 2);
+ _bitVector360_419 = GetBitVector(destination0_59, 2);
_bitVector360_419 <<= 58;
- _bitVector360_419 |= GetBitVector((UInt64)destination60_119, 60, 2);
+ _bitVector360_419 |= GetBitVector(destination60_119, 60, 2);
}
private void GetBitVector420_423()
{
_bitVector420_423 = 0;
- _bitVector420_423 = GetBitVector((UInt64)destination60_119, 2);
+ _bitVector420_423 = GetBitVector(destination60_119, 2);
_bitVector420_423 <<= 1;
_bitVector420_423 |= dataTerminalEquipment1;
@@ -610,11 +610,11 @@ private void SetBitVector0_59()
private void SetBitVector60_119()
{
- name0_59 = (UInt64)(_bitVector60_119 & 0xFF);
+ name0_59 = _bitVector60_119 & 0xFF;
name0_59 <<= 52;
_bitVector60_119 >>= 8;
- callSign42 = (UInt64)(_bitVector60_119 & 0x3FFFFFFFFFF);
+ callSign42 = _bitVector60_119 & 0x3FFFFFFFFFF;
_bitVector60_119 >>= 42;
imoNumber30 |= (UInt32)(_bitVector60_119 & 0x3FF);
@@ -623,11 +623,11 @@ private void SetBitVector60_119()
private void SetBitVector120_179()
{
- name60_119 = (UInt64)(_bitVector120_179 & 0xFF);
+ name60_119 = _bitVector120_179 & 0xFF;
name60_119 <<= 52;
_bitVector120_179 >>= 8;
- name0_59 |= (UInt64)(_bitVector120_179 & 0xFFFFFFFFFFFFF);
+ name0_59 |= _bitVector120_179 & 0xFFFFFFFFFFFFF;
_bitVector120_179 >>= 52;
}
@@ -636,7 +636,7 @@ private void SetBitVector180_239()
shipAndCargoType8 = (UInt16)(_bitVector180_239 & 0xFF);
_bitVector180_239 >>= 8;
- name60_119 |= (UInt64)(_bitVector180_239 & 0xFFFFFFFFFFFFF);
+ name60_119 |= _bitVector180_239 & 0xFFFFFFFFFFFFF;
_bitVector180_239 >>= 52;
}
@@ -676,7 +676,7 @@ private void SetBitVector240_299()
private void SetBitVector300_359()
{
- destination0_59 = (UInt64)(_bitVector300_359 & 0x3FFFFFFFFFFFFFF);
+ destination0_59 = _bitVector300_359 & 0x3FFFFFFFFFFFFFF;
destination0_59 <<= 2;
_bitVector300_359 >>= 58;
@@ -686,11 +686,11 @@ private void SetBitVector300_359()
private void SetBitVector360_419()
{
- destination60_119 = (UInt64)(_bitVector360_419 & 0x3FFFFFFFFFFFFFF);
+ destination60_119 = _bitVector360_419 & 0x3FFFFFFFFFFFFFF;
destination60_119 <<= 2;
_bitVector360_419 >>= 58;
- destination0_59 |= (UInt64)(_bitVector360_419 & 0x3);
+ destination0_59 |= _bitVector360_419 & 0x3;
_bitVector360_419 >>= 2;
}
@@ -704,7 +704,7 @@ private void SetBitVector420_423()
dataTerminalEquipment1 = (UInt16)(_bitVector420_423 & 0x1);
_bitVector420_423 >>= 1;
- destination60_119 |= (UInt64)(_bitVector420_423 & 0x3);
+ destination60_119 |= _bitVector420_423 & 0x3;
_bitVector420_423 >>= 2;
}
diff --git a/AIS/AISMessage09.cs b/AIS/AISMessage09.cs
index bbaefe9..bf5dc82 100644
--- a/AIS/AISMessage09.cs
+++ b/AIS/AISMessage09.cs
@@ -38,7 +38,7 @@ public class AISMessage09 : AISMessage
/// Altitude (derived from GNSS or barometric (see altitude sensor parameter below)) (m) (0 - 4094 m)
/// 4095 = not available, 4094 = 4094 m or higher
///
- public UInt16 Altitude { get => altitude12; set => altitude12 = (UInt16)Math.Min((UInt16)4095, value); }
+ public UInt16 Altitude { get => altitude12; set => altitude12 = Math.Min((UInt16)4095, value); }
///
/// Is the Speed Over Ground Available?
@@ -320,7 +320,7 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector60_119 <<= 28;
_bitVector60_119 |= tempLongitude;
@@ -328,12 +328,12 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 28;
- _bitVector60_119 |= (UInt64)((UInt32)longitude28);
+ _bitVector60_119 |= (UInt32)longitude28;
}
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 27;
_bitVector60_119 |= tempLatitude;
@@ -341,7 +341,7 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 27;
- _bitVector60_119 |= (UInt64)((UInt32)latitude27);
+ _bitVector60_119 |= (UInt32)latitude27;
}
_bitVector60_119 <<= 4;
diff --git a/AIS/AISMessage11.cs b/AIS/AISMessage11.cs
index 45c7a6c..43aeabf 100644
--- a/AIS/AISMessage11.cs
+++ b/AIS/AISMessage11.cs
@@ -288,7 +288,7 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector60_119 <<= 28;
_bitVector60_119 |= tempLongitude;
@@ -296,15 +296,15 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 28;
- _bitVector60_119 |= (UInt64)((UInt32)longitude28);
+ _bitVector60_119 |= (UInt32)longitude28;
}
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 13;
- _bitVector60_119 |= GetBitVector((UInt64)tempLatitude, 27, 14);
+ _bitVector60_119 |= GetBitVector(tempLatitude, 27, 14);
}
else
{
@@ -319,10 +319,10 @@ private void GetBitVector120_167()
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector120_167 <<= 14;
- _bitVector120_167 |= GetBitVector((UInt64)tempLatitude, 14);
+ _bitVector120_167 |= GetBitVector(tempLatitude, 14);
}
else
{
diff --git a/AIS/AISMessage18.cs b/AIS/AISMessage18.cs
index dba8334..81b93f5 100644
--- a/AIS/AISMessage18.cs
+++ b/AIS/AISMessage18.cs
@@ -327,7 +327,7 @@ private void GetBitVector0_59()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector0_59 <<= 3;
_bitVector0_59 |= GetBitVector(tempLongitude, 28, 25);
@@ -345,9 +345,9 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
- _bitVector60_119 = GetBitVector((UInt64)tempLongitude, 25);
+ _bitVector60_119 = GetBitVector(tempLongitude, 25);
}
else
{
@@ -356,7 +356,7 @@ private void GetBitVector60_119()
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 27;
_bitVector60_119 |= tempLatitude;
@@ -364,7 +364,7 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 27;
- _bitVector60_119 |= (UInt64)((UInt32)latitude27);
+ _bitVector60_119 |= (UInt32)latitude27;
}
_bitVector60_119 <<= 8;
diff --git a/AIS/AISMessage19.cs b/AIS/AISMessage19.cs
index b76e3b3..2393e07 100644
--- a/AIS/AISMessage19.cs
+++ b/AIS/AISMessage19.cs
@@ -484,7 +484,7 @@ private void GetBitVector0_59()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
_bitVector0_59 <<= 3;
_bitVector0_59 |= GetBitVector(tempLongitude, 28, 25);
@@ -502,9 +502,9 @@ private void GetBitVector60_119()
if (longitude28 < 0)
{
- UInt64 tempLongitude = (UInt64)(longitude28 + (Int32)0xFFFFFFF);
+ UInt64 tempLongitude = (UInt64)(longitude28 + 0xFFFFFFF);
- _bitVector60_119 = GetBitVector((UInt64)tempLongitude, 25);
+ _bitVector60_119 = GetBitVector(tempLongitude, 25);
}
else
{
@@ -513,7 +513,7 @@ private void GetBitVector60_119()
if (latitude27 < 0)
{
- UInt64 tempLatitude = (UInt64)(latitude27 + (Int32)0x7FFFFFF);
+ UInt64 tempLatitude = (UInt64)(latitude27 + 0x7FFFFFF);
_bitVector60_119 <<= 27;
_bitVector60_119 |= tempLatitude;
@@ -521,7 +521,7 @@ private void GetBitVector60_119()
else
{
_bitVector60_119 <<= 27;
- _bitVector60_119 |= (UInt64)((UInt32)latitude27);
+ _bitVector60_119 |= (UInt32)latitude27;
}
_bitVector60_119 <<= 8;
@@ -544,24 +544,24 @@ private void GetBitVector120_179()
_bitVector120_179 |= spare2_4;
_bitVector120_179 <<= 37;
- _bitVector120_179 |= GetBitVector((UInt64)name0_59, 60, 23);
+ _bitVector120_179 |= GetBitVector(name0_59, 60, 23);
}
private void GetBitVector180_239()
{
_bitVector180_239 = 0;
- _bitVector180_239 = GetBitVector((UInt64)name0_59, 23);
+ _bitVector180_239 = GetBitVector(name0_59, 23);
_bitVector180_239 <<= 37;
- _bitVector180_239 |= GetBitVector((UInt64)name60_119, 60, 23);
+ _bitVector180_239 |= GetBitVector(name60_119, 60, 23);
}
private void GetBitVector240_299()
{
_bitVector240_299 = 0;
- _bitVector240_299 = GetBitVector((UInt64)name60_119, 23);
+ _bitVector240_299 = GetBitVector(name60_119, 23);
_bitVector240_299 <<= 8;
_bitVector240_299 |= shipAndCargoType8;
@@ -652,7 +652,7 @@ private void SetBitVector60_119()
private void SetBitVector120_179()
{
- name0_59 = (UInt64)(_bitVector120_179 & 0x1FFFFFFFFF);
+ name0_59 = _bitVector120_179 & 0x1FFFFFFFFF;
name0_59 <<= 23;
_bitVector120_179 >>= 37;
@@ -670,11 +670,11 @@ private void SetBitVector120_179()
private void SetBitVector180_239()
{
- name60_119 = (UInt64)(_bitVector180_239 & 0x1FFFFFFFFF);
+ name60_119 = _bitVector180_239 & 0x1FFFFFFFFF;
name60_119 <<= 23;
_bitVector180_239 >>= 37;
- name0_59 |= (UInt64)(_bitVector180_239 & 0x7FFFFF);
+ name0_59 |= _bitVector180_239 & 0x7FFFFF;
_bitVector180_239 >>= 23;
}
@@ -696,7 +696,7 @@ private void SetBitVector240_299()
shipAndCargoType8 = (UInt16)(_bitVector240_299 & 0xFF);
_bitVector240_299 >>= 8;
- name60_119 |= (UInt64)(_bitVector240_299 & 0x7FFFFF);
+ name60_119 |= _bitVector240_299 & 0x7FFFFF;
_bitVector240_299 >>= 23;
}
diff --git a/AIS/AISMessage24.cs b/AIS/AISMessage24.cs
index 093144f..3bc4c3a 100644
--- a/AIS/AISMessage24.cs
+++ b/AIS/AISMessage24.cs
@@ -477,7 +477,7 @@ private void GetBitVector0_59()
if (partNumber2 == 0)
{
_bitVector0_59 <<= 20;
- _bitVector0_59 |= GetBitVector((UInt64)name0_59, 60, 40);
+ _bitVector0_59 |= GetBitVector(name0_59, 60, 40);
}
else
{
@@ -485,7 +485,7 @@ private void GetBitVector0_59()
_bitVector0_59 |= shipAndCargoType8;
_bitVector0_59 <<= 12;
- _bitVector0_59 |= GetBitVector((UInt64)vendorId42, 42, 30);
+ _bitVector0_59 |= GetBitVector(vendorId42, 42, 30);
}
}
@@ -496,18 +496,18 @@ private void GetBitVector60_119()
if (partNumber2 == 0)
{
_bitVector60_119 <<= 40;
- _bitVector60_119 |= GetBitVector((UInt64)name0_59, 40);
+ _bitVector60_119 |= GetBitVector(name0_59, 40);
_bitVector60_119 <<= 20;
- _bitVector60_119 |= GetBitVector((UInt64)name60_119, 60, 40);
+ _bitVector60_119 |= GetBitVector(name60_119, 60, 40);
}
else
{
_bitVector60_119 <<= 30;
- _bitVector60_119 |= GetBitVector((UInt64)vendorId42, 30);
+ _bitVector60_119 |= GetBitVector(vendorId42, 30);
_bitVector60_119 <<= 30;
- _bitVector60_119 |= GetBitVector((UInt64)callSign42, 42, 12);
+ _bitVector60_119 |= GetBitVector(callSign42, 42, 12);
}
}
@@ -518,14 +518,14 @@ private void GetBitVector120_167()
if (partNumber2 == 0)
{
_bitVector120_167 <<= 40;
- _bitVector120_167 |= GetBitVector((UInt64)name60_119, 40);
+ _bitVector120_167 |= GetBitVector(name60_119, 40);
_bitVector120_167 <<= 2;
}
else
{
_bitVector120_167 <<= 12;
- _bitVector120_167 |= GetBitVector((UInt64)callSign42, 12);
+ _bitVector120_167 |= GetBitVector(callSign42, 12);
_bitVector120_167 <<= 9;
_bitVector120_167 |= dimensionToBow9;
@@ -549,7 +549,7 @@ private void GetBitVector120_167()
private void SetBitVector0_59()
{
- UInt64 temp = (UInt64)(_bitVector0_59 & 0xFFFFF);
+ UInt64 temp = _bitVector0_59 & 0xFFFFF;
_bitVector0_59 >>= 20;
partNumber2 = (UInt16)(_bitVector0_59 & 0x3);
@@ -583,20 +583,20 @@ private void SetBitVector60_119()
{
if (partNumber2 == 0)
{
- name60_119 = (UInt64)(_bitVector60_119 & 0xFFFFF);
+ name60_119 = _bitVector60_119 & 0xFFFFF;
name60_119 <<= 40;
_bitVector60_119 >>= 20;
- name0_59 |= (UInt64)(_bitVector60_119 & 0xFFFFFFFFFF);
+ name0_59 |= _bitVector60_119 & 0xFFFFFFFFFF;
_bitVector60_119 >>= 20;
}
else
{
- callSign42 = (UInt64)(_bitVector60_119 & 0x3FFFFFFF);
+ callSign42 = _bitVector60_119 & 0x3FFFFFFF;
callSign42 <<= 12;
_bitVector60_119 >>= 30;
- vendorId42 |= (UInt64)(_bitVector60_119 & 0x3FFFFFFF);
+ vendorId42 |= _bitVector60_119 & 0x3FFFFFFF;
_bitVector60_119 >>= 30;
}
}
@@ -607,7 +607,7 @@ private void SetBitVector120_167()
{
_bitVector120_167 >>= 2;
- name60_119 |= (UInt64)(_bitVector120_167 & 0xFFFFFFFFFF);
+ name60_119 |= _bitVector120_167 & 0xFFFFFFFFFF;
_bitVector120_167 >>= 40;
}
else
@@ -630,7 +630,7 @@ private void SetBitVector120_167()
dimensionToBow9 = (UInt16)(_bitVector120_167 & 0x1FF);
_bitVector120_167 >>= 9;
- callSign42 |= (UInt64)(_bitVector120_167 & 0xFFF);
+ callSign42 |= _bitVector120_167 & 0xFFF;
_bitVector120_167 >>= 12;
}
}
diff --git a/AIS/ITDMACommunicationState.cs b/AIS/ITDMACommunicationState.cs
index 29072e8..26c3445 100644
--- a/AIS/ITDMACommunicationState.cs
+++ b/AIS/ITDMACommunicationState.cs
@@ -14,7 +14,7 @@ public class ITDMACommunicationState : AISCommunicationState
///
/// Offset to next slot to be used, or zero (0) if no more transmissions
///
- public Int16 SlotIncrement { get => (Int16)communicationState19[_slotIncrement13]; set => communicationState19[_slotIncrement13] = (Int16)value; }
+ public Int16 SlotIncrement { get => (Int16)communicationState19[_slotIncrement13]; set => communicationState19[_slotIncrement13] = value; }
///
/// Number of consecutive slots to allocate.
diff --git a/XUnitTestProjectAIS/UnitTestAISMessage.cs b/XUnitTestProjectAIS/UnitTestAISMessage.cs
new file mode 100644
index 0000000..2bc64f2
--- /dev/null
+++ b/XUnitTestProjectAIS/UnitTestAISMessage.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using TensionDev.Maritime.AIS;
+using Xunit;
+
+namespace XUnitTestProjectAIS
+{
+ public class UnitTestAISMessage
+ {
+ [Fact]
+ public void AISDecodingNullList()
+ {
+ IList sentences = null;
+
+ Assert.Throws(() => { AISMessage.DecodeSentences(sentences); });
+ }
+
+ [Fact]
+ public void AISDecodingEmptyList()
+ {
+ IList sentences = new List()
+ {
+ };
+
+ Assert.Throws(() => { AISMessage.DecodeSentences(sentences); });
+ }
+
+ [Fact]
+ public void AISDecodingInvalidSentenceIdentifier()
+ {
+ IList sentences = new List()
+ {
+ "!AIHDT,1,1,,B,25Cjtd0Oj;Jp7ilG7=UkKBoB0<06,0*60"
+ };
+
+ Assert.Throws(() => { AISMessage.DecodeSentences(sentences); });
+ }
+
+ [Fact]
+ public void AISDecodingInvalidSentenceCount()
+ {
+ IList sentences = new List()
+ {
+ "!AIVDM,2,1,,A,14eG;o@034o8sd062D,0*7D"
+ };
+
+ Assert.Throws(() => { AISMessage.DecodeSentences(sentences); });
+ }
+
+ [Fact]
+ public void AISDecodingInvalidSquence()
+ {
+ IList sentences = new List()
+ {
+ "!AIVDM,2,1,7,A,58wt8Ui`g??r21`7S=:220588OA;0sk,0*7B",
+ "!AIVDM,2,2,3,A,eQ8823mDm3kP00000000000,2*5D"
+ };
+
+ Assert.Throws(() => { AISMessage.DecodeSentences(sentences); });
+ }
+ }
+}