ITS
CBFPacketBuffer.cpp
Go to the documentation of this file.
1 #include "CBFPacketBuffer.h"
2 
4 
6 {
7  m_mutex = new QMutex;
8  m_paramNetwork = 0;
9  m_locationTable = 0;
10  m_paramGPS = 0;
11  m_HPB = 0;
12  m_CBFPBCounter = 0;
13 }
14 
15 CBFPacketBuffer::CBFPacketBuffer(ParameterNetwork* paramNetwork, QHash<QByteArray, LocationTableEntry>* locT, GnAddr* gnAddr, FakeGPSProvider* paramGPS, HistoryPacketBuffer* HPB, quint16* SN, QHash<QByteArray, int> *CBFPBCounter)
16 {
17  m_mutex = new QMutex;
18  m_paramNetwork = paramNetwork;
19  m_locationTable = locT;
20  m_gnAddr = gnAddr;
21  m_paramGPS = paramGPS;
22  m_HPB = HPB;
23  sequenceNumber = SN;
24  m_CBFPBCounter = CBFPBCounter;
25 }
26 
28 {
29  this->m_mutex = other.m_mutex;
31  this->m_paramNetwork = other.m_paramNetwork;
32  this->m_locationTable = other.m_locationTable;
33  this->m_gnAddr = other.m_gnAddr;
34  this->m_paramGPS = other.m_paramGPS;
35  this->m_HPB = other.m_HPB;
36  this->sequenceNumber = other.sequenceNumber;
37  this->m_CBFPBCounter = other.m_CBFPBCounter;
38 }
39 
40 int CBFPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray payload, int timeToBuffer)
41 {
42  if(!isDuplicateTimestamp(packet))
43  {
44  CBFPacketEntry* cbfpe = new CBFPacketEntry(bh, ch, packet, payload, timeToBuffer, m_paramNetwork, m_gnAddr, m_paramGPS, m_HPB, sequenceNumber);
45 
46  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
48  {
49  m_CBFPacketBuffer.first()->kill();
50  m_CBFPacketBuffer.pop_front();
51  nbCBFPacketQueued -= 1;
52  }
53 
54  if(isDuplicateTimestamp(packet))
55  {
56  printf("\n\n\n\n\nDUPLICATE CBF GBC\n\n\n\n\n");
57  return nbCBFPacketQueued;
58  }
59 
60  QObject::connect(cbfpe, SIGNAL(packetSent(GBCPacket)), this, SLOT(sendPacket(GBCPacket)));
61  QObject::connect(cbfpe, SIGNAL(killMe(GBCPacket)), this, SLOT(stopPacket(GBCPacket)));
62  QObject::connect(this, SIGNAL(killAll()), cbfpe, SLOT(kill()));
63  m_CBFPacketBuffer.push_back(cbfpe);
64 
65  QThread* th = new QThread;
66  cbfpe->moveToThread(th);
67  QObject::connect(th, SIGNAL(started()), cbfpe, SLOT(execute()));
68  th->start();
69 
70  return ++nbCBFPacketQueued;
71  }
72  else
73  return -1;
74 }
75 
76 int CBFPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, GUCPacket packet, QByteArray payload, int timeToBuffer)
77 {
78  if(!isDuplicateTimestamp(packet))
79  {
80  CBFPacketEntry* cbfpe = new CBFPacketEntry(bh, ch, packet, payload, timeToBuffer, m_paramNetwork, m_gnAddr, m_paramGPS, m_HPB, sequenceNumber);
81 
82  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
84  {
85  m_CBFPacketBuffer.first()->kill();
86  m_CBFPacketBuffer.pop_front();
87  nbCBFPacketQueued -= 1;
88  }
89 
90  if(isDuplicateTimestamp(packet))
91  {
92  printf("\n\n\n\n\nDUPLICATE CBF GUC\n\n\n\n\n");
93  return nbCBFPacketQueued;
94  }
95 
96  QObject::connect(cbfpe, SIGNAL(packetSent(GUCPacket)), this, SLOT(sendPacket(GUCPacket)));
97  QObject::connect(cbfpe, SIGNAL(killMe(GUCPacket)), this, SLOT(stopPacket(GUCPacket)));
98  QObject::connect(this, SIGNAL(killAll()), cbfpe, SLOT(kill()));
99  m_CBFPacketBuffer.push_back(cbfpe);
100 
101  QThread* th = new QThread;
102  cbfpe->moveToThread(th);
103  QObject::connect(th, SIGNAL(started()), cbfpe, SLOT(execute()));
104  th->start();
105 
106  return ++nbCBFPacketQueued;
107  }
108  else
109  return -1;
110 }
111 
112 int CBFPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, LSReplyPacket packet, QByteArray payload, int timeToBuffer)
113 {
114  if(!isDuplicateTimestamp(packet))
115  {
116  CBFPacketEntry* cbfpe = new CBFPacketEntry(bh, ch, packet, payload, timeToBuffer, m_paramNetwork, m_gnAddr, m_paramGPS, m_HPB, sequenceNumber);
117 
118  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
120  {
121  m_CBFPacketBuffer.first()->kill();
122  m_CBFPacketBuffer.pop_front();
123  nbCBFPacketQueued -= 1;
124  }
125 
126  if(isDuplicateTimestamp(packet))
127  {
128  printf("\n\n\n\n\nDUPLICATE CBF LSREPLY\n\n\n\n\n");
129  return nbCBFPacketQueued;
130  }
131 
132  QObject::connect(cbfpe, SIGNAL(packetSent(LSReplyPacket)), this, SLOT(sendPacket(LSReplyPacket)));
133  QObject::connect(cbfpe, SIGNAL(killMe(LSReplyPacket)), this, SLOT(stopPacket(LSReplyPacket)));
134  QObject::connect(this, SIGNAL(killAll()), cbfpe, SLOT(kill()));
135  m_CBFPacketBuffer.push_back(cbfpe);
136 
137  QThread* th = new QThread;
138  cbfpe->moveToThread(th);
139  QObject::connect(th, SIGNAL(started()), cbfpe, SLOT(execute()));
140  th->start();
141 
142  return ++nbCBFPacketQueued;
143  }
144  else
145  return -1;
146 }
147 
148 bool CBFPacketBuffer::update(GBCPacket packet, int timeToBuffer)
149 {
150  bool b = false;
151  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();i != m_CBFPacketBuffer.end(); ++i)
152  if(((*i)->commonHeader().headerType() == CommonHeader::headerType_geoAnycast || (*i)->commonHeader().headerType() == CommonHeader::headerType_geoBroadcast) && isDuplicatePacketDetectionTimestampSN((*i)->gbcPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->gbcPacket().sequenceNumber(), packet.sequenceNumber()))
153  {
154  (*i)->restartTimer(timeToBuffer);
155  b = true;
156  }
157  return b;
158 }
159 
160 bool CBFPacketBuffer::update(GUCPacket packet, int timeToBuffer)
161 {
162  bool b = false;
163  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();i != m_CBFPacketBuffer.end(); ++i)
164  if((*i)->commonHeader().headerType() == CommonHeader::headerType_geoUnicast && isDuplicatePacketDetectionTimestampSN((*i)->gucPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->gucPacket().sequenceNumber(), packet.sequenceNumber()))
165  {
166  (*i)->restartTimer(timeToBuffer);
167  b = true;
168  }
169  return b;
170 }
171 
172 bool CBFPacketBuffer::update(LSReplyPacket packet, int timeToBuffer)
173 {
174  bool b = false;
175  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();i != m_CBFPacketBuffer.end(); ++i)
176  if((*i)->commonHeader().headerType() == CommonHeader::headerType_locationService && (*i)->commonHeader().headerSubType() == CommonHeader::headerSubTypeLocationService_Reply && isDuplicatePacketDetectionTimestampSN((*i)->lsReplyPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->lsReplyPacket().sequenceNumber(), packet.sequenceNumber()))
177  {
178  (*i)->restartTimer(timeToBuffer);
179  b = true;
180  }
181  return b;
182 }
183 
185 {
186  bool b = false;
187  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();i != m_CBFPacketBuffer.end(); ++i)
188  if(((*i)->commonHeader().headerType() == CommonHeader::headerType_geoAnycast || (*i)->commonHeader().headerType() == CommonHeader::headerType_geoBroadcast) && isDuplicatePacketDetectionTimestampSN((*i)->gbcPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->gbcPacket().sequenceNumber(), packet.sequenceNumber()))
189  b = true;
190  return b;
191 }
192 
194 {
195  bool b = false;
196  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();i != m_CBFPacketBuffer.end(); ++i)
197  if((*i)->commonHeader().headerType() == CommonHeader::headerType_geoUnicast && isDuplicatePacketDetectionTimestampSN((*i)->gucPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->gucPacket().sequenceNumber(), packet.sequenceNumber()))
198  b = true;
199  return b;
200 }
201 
203 {
204  bool b = false;
205  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();i != m_CBFPacketBuffer.end(); ++i)
206  if((*i)->commonHeader().headerType() == CommonHeader::headerType_locationService && (*i)->commonHeader().headerSubType() == CommonHeader::headerSubTypeLocationService_Reply && isDuplicatePacketDetectionTimestampSN((*i)->lsReplyPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->lsReplyPacket().sequenceNumber(), packet.sequenceNumber()))
207  b = true;
208  return b;
209 }
210 
212 {
213  bool b = false;
214  int j = 0;
215  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();j < m_CBFPacketBuffer.size(); ++i, j++)
216  if(isDuplicatePacketDetectionTimestampSN((*i)->gbcPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->gbcPacket().sequenceNumber(), packet.sequenceNumber()))
217  {
218  (*i)->kill();
219  nbCBFPacketQueued -= 1;
220  b = true;
221  m_CBFPacketBuffer.erase(i);
222  }
223  return b;
224 }
225 
227 {
228  bool b = false;
229  int j = 0;
230  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();j < m_CBFPacketBuffer.size(); ++i, j++)
231  if(isDuplicatePacketDetectionTimestampSN((*i)->gucPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->gucPacket().sequenceNumber(), packet.sequenceNumber()))
232  {
233  (*i)->kill();
234  m_CBFPacketBuffer.erase(i);
235  nbCBFPacketQueued -= 1;
236  b = true;
237  }
238  return b;
239 }
240 
242 {
243  bool b = false;
244  int j = 0;
245  for(QVector<CBFPacketEntry*>::Iterator i = m_CBFPacketBuffer.begin();j < m_CBFPacketBuffer.size(); ++i, j++)
246  if(isDuplicatePacketDetectionTimestampSN((*i)->lsReplyPacket().soPv().timestamp(), packet.soPv().timestamp(), (*i)->lsReplyPacket().sequenceNumber(), packet.sequenceNumber()))
247  {
248  (*i)->kill();
249  m_CBFPacketBuffer.erase(i);
250  nbCBFPacketQueued -= 1;
251  b = true;
252  }
253  return b;
254 }
255 
257 {
258  emit killAll();
259  m_CBFPacketBuffer.clear();
260  nbCBFPacketQueued = 0;
261 }
262 
264 {
265  erase(packet);
266  m_CBFPBCounter->erase(m_CBFPBCounter->find(QByteArray(QByteArray(packet.soPv().gnAddr().toHex(), GnAddr::helper_size)+QByteArray(packet.soPv().timestamp(), 32)+QByteArray(packet.sequenceNumber(), 16), GnAddr::helper_size+32+16)));
267  emit lpvSent();
268 }
269 
271 {
272  erase(packet);
273  m_CBFPBCounter->erase(m_CBFPBCounter->find(QByteArray(QByteArray(packet.soPv().gnAddr().toHex(), GnAddr::helper_size)+QByteArray(packet.soPv().timestamp(), 32)+QByteArray(packet.sequenceNumber(), 16), GnAddr::helper_size+32+16)));
274  emit lpvSent();
275 }
276 
278 {
279  erase(packet);
280  m_CBFPBCounter->erase(m_CBFPBCounter->find(QByteArray(QByteArray(packet.soPv().gnAddr().toHex(), GnAddr::helper_size)+QByteArray(packet.soPv().timestamp(), 32)+QByteArray(packet.sequenceNumber(), 16), GnAddr::helper_size+32+16)));
281  emit lpvSent();
282 }
283 
285 {
286  erase(packet);
287  m_CBFPBCounter->erase(m_CBFPBCounter->find(QByteArray(QByteArray(packet.soPv().gnAddr().toHex(), GnAddr::helper_size)+QByteArray(packet.soPv().timestamp(), 32)+QByteArray(packet.sequenceNumber(), 16), GnAddr::helper_size+32+16)));
288 }
289 
291 {
292  erase(packet);
293  m_CBFPBCounter->erase(m_CBFPBCounter->find(QByteArray(QByteArray(packet.soPv().gnAddr().toHex(), GnAddr::helper_size)+QByteArray(packet.soPv().timestamp(), 32)+QByteArray(packet.sequenceNumber(), 16), GnAddr::helper_size+32+16)));
294 }
295 
297 {
298  erase(packet);
299  m_CBFPBCounter->erase(m_CBFPBCounter->find(QByteArray(QByteArray(packet.soPv().gnAddr().toHex(), GnAddr::helper_size)+QByteArray(packet.soPv().timestamp(), 32)+QByteArray(packet.sequenceNumber(), 16), GnAddr::helper_size+32+16)));
300 }
Buffer used for CBF.
quint16 * sequenceNumber
void clear()
clear Clear the buffer.
HistoryPacketBuffer * m_HPB
void stopPacket(GBCPacket packet)
stopPacket Slot used to stop the packet (GBC case).
LongPositionVector soPv() const
soPv SO PV getter.
Definition: GBCPacket.h:95
quint32 timestamp() const
timestamp Timestamp field getter
quint16 sequenceNumber() const
sequenceNumber Sequence number getter.
Definition: GBCPacket.h:90
static int nbCBFPacketQueued
QVector< CBFPacketEntry * > m_CBFPacketBuffer
GnAddr gnAddr() const
gnAddr GnAddr field getter
bool isDuplicatePacketDetectionTimestampSN(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp, quint16 lastReceivedSN, quint16 nowReceivedSN)
isDuplicatePacketDetectionTimestamp Calculate if the packet is a duplicate using the timestamp and th...
Definition: apiNetwork.cpp:104
bool update(GBCPacket packet, int timeToBuffer)
update Update the packet of the buffer.
bool erase(GBCPacket packet)
erase Remove packet from the buffer.
FakeGPSProvider * m_paramGPS
void killAll()
killAll Signal used to kill all the buffer entries.
QByteArray toHex()
toHex Create a QByteArray containing the hexadecimal format of the GnAddr.
Definition: GnAddr.cpp:69
QHash< QByteArray, int > * m_CBFPBCounter
void sendPacket(GBCPacket packet)
sendPacket Slot used to send packet (GBC case).
int addPacket(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray payload, int timeToBuffer)
addPacket Add packet to the buffer.
bool isDuplicateTimestamp(GBCPacket packet)
isDuplicateTimestamp Check is the packet is duplicate.
#define itsGnCbfPacketbufferSize
Definition: constantes.h:127
Definition: GnAddr.h:28
QHash< QByteArray, LocationTableEntry > * m_locationTable
quint16 sequenceNumber() const
sequenceNumber GUC sequence number getter.
Definition: GUCPacket.h:72
ParameterNetwork * m_paramNetwork
LongPositionVector soPv() const
soPv GUC SO PV getter.
Definition: GUCPacket.h:77
CBFPacketBuffer()
CBFPacketBuffer Default constructor.
void lpvSent()
lpvSent Signal sent to advertised of an LPV sending.