@@ -6,7 +6,7 @@ namespace TensionDev.Maritime.AIS
66{
77 public abstract class AISMessage
88 {
9- private protected static UInt16 s_groupId = 0 ;
9+ protected UInt16 s_groupId = 0 ;
1010
1111 protected UInt16 messageId6 ;
1212 protected UInt16 repeatIndicator2 ;
@@ -55,7 +55,7 @@ public static AISMessage DecodeSentences(IList<String> sentences)
5555 throw new NotImplementedException ( "Sentence Identifier not recognised." ) ;
5656 }
5757
58- String [ ] vs = sentence . Split ( new char [ ] { ',' , '*' } ) ;
58+ String [ ] vs = sentence . Split ( ',' , '*' ) ;
5959
6060 // Ensure sentences count is equal to sentence fragment count.
6161 if ( vs [ 1 ] != sentences . Count . ToString ( ) )
@@ -82,8 +82,31 @@ public static AISMessage DecodeSentences(IList<String> sentences)
8282 payloads . Add ( vs [ 5 ] ) ;
8383 }
8484
85- AISMessage aisMessage ;
85+ AISMessage aisMessage = CreateAISMessage ( messageId ) ;
86+
87+ if ( sentenceIdentifier == "VDM" )
88+ {
89+ aisMessage . SentenceFormatter = SentenceFormatterEnum . VDM ;
90+ }
91+ else if ( sentenceIdentifier == "VDO" )
92+ {
93+ aisMessage . SentenceFormatter = SentenceFormatterEnum . VDO ;
94+ }
95+
96+ aisMessage . DecodePayloads ( payloads ) ;
8697
98+ return aisMessage ;
99+ }
100+
101+ /// <summary>
102+ /// Creates an AIS Message Object based on encoded message ID
103+ /// </summary>
104+ /// <param name="messageId">Encoded Message ID</param>
105+ /// <returns></returns>
106+ /// <exception cref="NotImplementedException"></exception>
107+ private static AISMessage CreateAISMessage ( string messageId )
108+ {
109+ AISMessage aisMessage ;
87110 switch ( messageId )
88111 {
89112 case "1" :
@@ -142,17 +165,6 @@ public static AISMessage DecodeSentences(IList<String> sentences)
142165 throw new NotImplementedException ( "Message Identifier not recognised." ) ;
143166 }
144167
145- if ( sentenceIdentifier == "VDM" )
146- {
147- aisMessage . SentenceFormatter = SentenceFormatterEnum . VDM ;
148- }
149- else if ( sentenceIdentifier == "VDO" )
150- {
151- aisMessage . SentenceFormatter = SentenceFormatterEnum . VDO ;
152- }
153-
154- aisMessage . DecodePayloads ( payloads ) ;
155-
156168 return aisMessage ;
157169 }
158170
@@ -162,7 +174,7 @@ public static AISMessage DecodeSentences(IList<String> sentences)
162174 /// <param name="value">The Value to get the bitvector from</param>
163175 /// <param name="bitcount">The end index of the bits required</param>
164176 /// <returns>The bitvector containing the required number of bits</returns>
165- public UInt64 GetBitVector ( Int64 value , Int32 bitcount )
177+ public static UInt64 GetBitVector ( Int64 value , Int32 bitcount )
166178 {
167179 UInt64 bv = 0 ;
168180 Int64 mask ;
@@ -184,7 +196,7 @@ public UInt64 GetBitVector(Int64 value, Int32 bitcount)
184196 /// <param name="bitcount">The end index of the bits required</param>
185197 /// <param name="startindex">The start index of the bits required</param>
186198 /// <returns>The bitvector containing the required number of bits</returns>
187- public UInt64 GetBitVector ( Int64 value , Int32 bitcount , Int32 startindex )
199+ public static UInt64 GetBitVector ( Int64 value , Int32 bitcount , Int32 startindex )
188200 {
189201 UInt64 bv = 0 ;
190202 Int64 mask ;
@@ -204,15 +216,15 @@ public UInt64 GetBitVector(Int64 value, Int32 bitcount, Int32 startindex)
204216 /// <param name="value">The Value to get the bitvector from</param>
205217 /// <param name="bitcount">The end index of the bits required</param>
206218 /// <returns>The bitvector containing the required number of bits</returns>
207- public UInt64 GetBitVector ( UInt64 value , Int32 bitcount )
219+ public static UInt64 GetBitVector ( UInt64 value , Int32 bitcount )
208220 {
209221 UInt64 bv = 0 ;
210222 UInt64 mask ;
211223
212224 for ( Int32 i = 0 ; i < bitcount ; i ++ )
213225 {
214226 mask = ( UInt64 ) Math . Pow ( 2 , i ) ;
215- bv = ( UInt64 ) ( mask & value ) | bv ;
227+ bv = ( mask & value ) | bv ;
216228 }
217229
218230 return bv ;
@@ -226,15 +238,15 @@ public UInt64 GetBitVector(UInt64 value, Int32 bitcount)
226238 /// <param name="bitcount">The end index of the bits required</param>
227239 /// <param name="startindex">The start index of the bits required</param>
228240 /// <returns>The bitvector containing the required number of bits</returns>
229- public UInt64 GetBitVector ( UInt64 value , Int32 bitcount , Int32 startindex )
241+ public static UInt64 GetBitVector ( UInt64 value , Int32 bitcount , Int32 startindex )
230242 {
231243 UInt64 bv = 0 ;
232244 UInt64 mask ;
233245
234246 for ( Int32 i = startindex ; i < bitcount ; i ++ )
235247 {
236248 mask = ( UInt64 ) Math . Pow ( 2 , i ) ;
237- bv = ( UInt64 ) ( mask & value ) | bv ;
249+ bv = ( mask & value ) | bv ;
238250 }
239251
240252 bv >>= startindex ;
@@ -273,7 +285,7 @@ public String EncodePayload(UInt64 bitvector, Int32 bitsleft)
273285 return EncodePayload ( bitvector / 64 , bitsleft - 6 ) + symbol ;
274286 }
275287
276- public UInt64 DecodePayload ( String payload , Int32 startIndex , Int32 length )
288+ public static UInt64 DecodePayload ( String payload , Int32 startIndex , Int32 length )
277289 {
278290 if ( length > 10 )
279291 {
@@ -304,7 +316,7 @@ public UInt64 DecodePayload(String payload, Int32 startIndex, Int32 length)
304316 /// </summary>
305317 /// <param name="sentence">The NMEA 0183 sentence to be computed, inclusive of the start delimiter "!" and just before the checksum delimiter "*"</param>
306318 /// <returns>The 8-bit XOR value.</returns>
307- protected Byte CalculateChecksum ( String sentence )
319+ protected static Byte CalculateChecksum ( String sentence )
308320 {
309321 Byte checksum = 0b0 ;
310322 Byte [ ] data = Encoding . ASCII . GetBytes ( sentence . Substring ( 1 ) ) ;
0 commit comments