1 /*********************************************************************
2 Copyright 2013 Karl Jones
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "./Link16_Signal_PDU.h"
32 //////////////////////////////////////////////////////////////////////////
37 using namespace LINK16
;
38 using namespace DATA_TYPE
;
39 using namespace ENUMS
;
40 using namespace ENUMS::LINK16
;
42 //////////////////////////////////////////////////////////////////////////
44 //////////////////////////////////////////////////////////////////////////
46 Link16_Signal_PDU::Link16_Signal_PDU() :
53 m_ui32PTTInteger( 0 ),
54 m_ui32PTTFraction( 0 )
56 m_TimeSlotIDUnion
.m_ui16TimeSlotID
= 0;
57 m_ui16PDULength
= LINK16_SIGNAL_PDU_SIZE
;
58 m_EncodingScheme
.SetEncodingClass( RawBinaryData
);
59 m_EncodingScheme
.SetTDLType( Link16StandardizedFormat_JTIDS_MIDS_TADILJ_
);
62 //////////////////////////////////////////////////////////////////////////
64 Link16_Signal_PDU::Link16_Signal_PDU( KDataStream
& stream
)
69 //////////////////////////////////////////////////////////////////////////
71 Link16_Signal_PDU::Link16_Signal_PDU( const Header
& H
, KDataStream
& stream
) :
74 Decode( stream
, true );
77 //////////////////////////////////////////////////////////////////////////
79 Link16_Signal_PDU::Link16_Signal_PDU( const EntityIdentifier
& ID
, KUINT16 RadioID
, const EncodingScheme
& ES
,
80 KUINT32 SampleRate
, KUINT16 Samples
, const KOCTET
* Data
, KUINT16 DataLength
,
81 KUINT16 NPG
, KUINT8 NN
, KUINT8 TSEC
, KUINT8 MSEC
, Link16MessageType MT
,
82 KUINT32 TSN
, KUINT32 Epoch
, KUINT32 TTInteger
, KUINT32 TTFraction
) :
83 Signal_PDU( ID
, RadioID
, ES
, SampleRate
, Samples
, Data
, DataLength
),
90 m_ui32PTTInteger( TTInteger
),
91 m_ui32PTTFraction( TTFraction
)
93 m_TimeSlotIDUnion
.m_ui32TimeSlotNumber
= TSN
;
94 m_TimeSlotIDUnion
.m_ui32Padding1
= 0;
95 m_TimeSlotIDUnion
.m_ui32Epoch
= Epoch
;
96 m_ui16PDULength
= LINK16_SIGNAL_PDU_SIZE
;
99 //////////////////////////////////////////////////////////////////////////
101 Link16_Signal_PDU::~Link16_Signal_PDU()
105 //////////////////////////////////////////////////////////////////////////
107 void Link16_Signal_PDU::SetNetworkParticipationGroup( KUINT16 NPG
)
109 if( NPG
> 511 )m_ui16NPG
= 511;
110 else m_ui16NPG
= NPG
;
113 //////////////////////////////////////////////////////////////////////////
115 KUINT16
Link16_Signal_PDU::GetNetworkParticipationGroup() const
120 //////////////////////////////////////////////////////////////////////////
122 void Link16_Signal_PDU::SetNetNumber( KUINT8 NN
)
124 if( NN
> 127 )m_ui8NetNumber
= 127;
125 else m_ui8NetNumber
= NN
;
128 //////////////////////////////////////////////////////////////////////////
130 KUINT8
Link16_Signal_PDU::GetNetNumber() const
132 return m_ui8NetNumber
;
135 //////////////////////////////////////////////////////////////////////////
137 void Link16_Signal_PDU::SetTransmissionSecurity( KUINT8 TSEC
)
139 if( TSEC
> 127 )m_ui8TSEC
= 255;
140 else m_ui8TSEC
= TSEC
;
143 //////////////////////////////////////////////////////////////////////////
145 KUINT8
Link16_Signal_PDU::GetTransmissionSecurity() const
150 //////////////////////////////////////////////////////////////////////////
152 void Link16_Signal_PDU::SetMessageSecurity( KUINT8 MSEC
)
154 if( MSEC
> 127 )m_ui8MSEC
= 255;
155 else m_ui8MSEC
= MSEC
;
158 //////////////////////////////////////////////////////////////////////////
160 KUINT8
Link16_Signal_PDU::GetMessageSecurity() const
165 //////////////////////////////////////////////////////////////////////////
167 void Link16_Signal_PDU::SetMessageType( Link16MessageType MT
)
172 //////////////////////////////////////////////////////////////////////////
174 Link16MessageType
Link16_Signal_PDU::GetMessageType() const
176 return ( Link16MessageType
)m_ui8MsgType
;
179 //////////////////////////////////////////////////////////////////////////
181 void Link16_Signal_PDU::SetTimeSlotNumber( KUINT32 TSN
)
183 m_TimeSlotIDUnion
.m_ui32TimeSlotNumber
= TSN
;
186 //////////////////////////////////////////////////////////////////////////
188 KUINT32
Link16_Signal_PDU::GetTimeSlotNumber() const
190 return m_TimeSlotIDUnion
.m_ui32TimeSlotNumber
;
193 //////////////////////////////////////////////////////////////////////////
195 void Link16_Signal_PDU::SetEpoch( KUINT32 E
)
197 m_TimeSlotIDUnion
.m_ui32Epoch
= E
;
200 //////////////////////////////////////////////////////////////////////////
202 KUINT32
Link16_Signal_PDU::GetEpoch() const
204 return m_TimeSlotIDUnion
.m_ui32Epoch
;
207 //////////////////////////////////////////////////////////////////////////
209 void Link16_Signal_PDU::SetPerceivedTransmitTimeInteger( KUINT32 PTTI
)
211 m_ui32PTTInteger
= PTTI
;
214 //////////////////////////////////////////////////////////////////////////
216 KUINT32
Link16_Signal_PDU::GetPerceivedTransmitTimeInteger() const
218 return m_ui32PTTInteger
;
221 //////////////////////////////////////////////////////////////////////////
223 void Link16_Signal_PDU::SetPerceivedTransmitTimeFraction( KUINT32 PTTF
)
225 m_ui32PTTFraction
= PTTF
;
228 //////////////////////////////////////////////////////////////////////////
230 KUINT32
Link16_Signal_PDU::GetPerceivedTransmitTimeFraction() const
232 return m_ui32PTTFraction
;
235 //////////////////////////////////////////////////////////////////////////
237 void Link16_Signal_PDU::SetPerceivedTransmitTime( KUINT32 Integer
, KUINT32 Fraction
)
239 m_ui32PTTInteger
= Integer
;
240 m_ui32PTTFraction
= Fraction
;
243 //////////////////////////////////////////////////////////////////////////
245 KString
Link16_Signal_PDU::GetAsString() const
249 ss
<< Header::GetAsString()
250 << "-Link16 Signal PDU-\n"
251 << Radio_Communications_Header::GetAsString()
252 << m_EncodingScheme
.GetAsString()
253 << "Sample Rate: " << m_ui32SampleRate
<< "\n"
254 << "Data Length: " << m_ui16DataLength
<< "\n"
255 << "Samples: " << m_ui16Samples
<< "\n"
256 << "Network Participation Group: " << m_ui16NPG
<< "\n"
257 << "Network Number: " << ( KUINT16
)m_ui8NetNumber
<< "\n"
258 << "Transmission Security: " << ( KUINT16
)m_ui8TSEC
<< "\n"
259 << "Message Security: " << ( KUINT16
)m_ui8MSEC
<< "\n"
260 << "Message Type: " << GetEnumAsStringLink16MessageType( m_ui8MsgType
) << "\n"
261 << "Time Slot ID: " << m_TimeSlotIDUnion
.m_ui16TimeSlotID
<< "\n"
262 << "Perceived Transmit Time: " << m_ui32PTTInteger
<< " : " << m_ui32PTTFraction
<< "\n";
264 // Data is not printed as we dont know what the data is.
269 //////////////////////////////////////////////////////////////////////////
271 void Link16_Signal_PDU::Decode( KDataStream
& stream
, bool ignoreHeader
/*= true*/ )
273 if( stream
.GetBufferSize() < LINK16_SIGNAL_PDU_SIZE
)throw KException( __FUNCTION__
, NOT_ENOUGH_DATA_IN_BUFFER
);
275 Radio_Communications_Header::Decode( stream
, ignoreHeader
);
277 stream
>> KDIS_STREAM m_EncodingScheme
287 >> m_TimeSlotIDUnion
.m_ui16TimeSlotID
289 >> m_ui32PTTFraction
;
291 for( KUINT16 i
= 0; i
< ( m_ui16DataLength
/ 8 ); ++i
)
295 m_vData
.push_back( o
);
299 //////////////////////////////////////////////////////////////////////////
301 KDataStream
Link16_Signal_PDU::Encode() const
305 Radio_Communications_Header::Encode( stream
);
310 //////////////////////////////////////////////////////////////////////////
312 void Link16_Signal_PDU::Encode( KDataStream
& stream
) const
314 Radio_Communications_Header::Encode( stream
);
316 stream
<< KDIS_STREAM m_EncodingScheme
326 << m_TimeSlotIDUnion
.m_ui16TimeSlotID
328 << m_ui32PTTFraction
;
330 vector
<KOCTET
>::const_iterator citr
= m_vData
.begin();
332 for( ; citr
!= m_vData
.end(); ++citr
)
338 //////////////////////////////////////////////////////////////////////////
340 KBOOL
Link16_Signal_PDU::operator == ( const Link16_Signal_PDU
& Value
) const
342 if( Signal_PDU::operator != ( Value
) ) return false;
343 if( m_ui16NPG
!= Value
.m_ui16NPG
) return false;
344 if( m_ui8NetNumber
!= Value
.m_ui8NetNumber
) return false;
345 if( m_ui8TSEC
!= Value
.m_ui8TSEC
) return false;
346 if( m_ui8MSEC
!= Value
.m_ui8MSEC
) return false;
347 if( m_ui8MsgType
!= Value
.m_ui8MsgType
) return false;
348 if( m_TimeSlotIDUnion
.m_ui16TimeSlotID
!= Value
.m_TimeSlotIDUnion
.m_ui16TimeSlotID
) return false;
349 if( m_ui32PTTInteger
!= Value
.m_ui32PTTInteger
) return false;
350 if( m_ui32PTTFraction
!= Value
.m_ui32PTTFraction
) return false;
354 //////////////////////////////////////////////////////////////////////////
356 KBOOL
Link16_Signal_PDU::operator != ( const Link16_Signal_PDU
& Value
) const
358 return !( *this == Value
);
361 //////////////////////////////////////////////////////////////////////////