ITS
apiNetwork.cpp
Go to the documentation of this file.
1 #include "apiNetwork.h"
2 
3 quint64 get_INT64(u_char *field, qint64 *int64)
4 {
5  quint64 tmp = 0;
6 
7  for(int i = 0 ; i < 8 ; i++)
8  {
9  tmp <<= 8;
10  tmp += *(field + i);
11  }
12  *int64 = (long long int)tmp;
13 
14  return 8;
15 }
16 
17 quint64 get_UINT64(u_char *field, quint64 *uint64)
18 {
19  *uint64 = 0;
20  for(int i = 0 ; i < 8 ; i++)
21  {
22  *uint64 <<= 8;
23  *uint64 += *(field + i);
24  }
25 
26  return 8;
27 }
28 
29 quint64 get_INT32(u_char *field, qint32 *int32)
30 {
31  quint64 tmp = 0;
32 
33  for(int i = 0 ; i < 4 ; i++)
34  {
35  tmp <<= 8;
36  tmp += *(field + i);
37  }
38  *int32 = (long long int)tmp;
39 
40  return 4;
41 }
42 
43 quint64 get_UINT32(u_char *field, quint32 *uint32)
44 {
45  *uint32 = 0;
46  for(int i = 0 ; i < 4 ; i++)
47  {
48  *uint32 <<= 8;
49  *uint32 += *(field + i);
50  }
51 
52  return 4;
53 }
54 
55 quint64 get_INT16(u_char *field, qint16 *int16)
56 {
57  quint64 tmp = 0;
58 
59  for(int i = 0; i < 2; i++)
60  {
61  tmp <<= 8;
62  tmp += *(field+i);
63  }
64  *int16 = (long int)tmp;
65 
66  return 2;
67 }
68 
69 quint64 get_UINT16(u_char *field, quint16 *uint16)
70 {
71  *uint16 = 0;
72  for(int i = 0 ; i < 2 ; i++)
73  {
74  *uint16 <<= 8;
75  *uint16 += *(field + i);
76  }
77 
78  return 2;
79 }
80 
81 quint64 get_INT8(u_char *field, qint8 *int8)
82 {
83  *int8 = 0;
84  *int8 = *field;
85  return 1;
86 }
87 
88 quint64 get_UINT8(u_char *field, quint8 *uint8)
89 {
90  *uint8 = 0;
91  *uint8 += *field;
92  return 1;
93 }
94 
95 bool isDuplicatePacketDetectionTimestamp(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp)
96 {
97  if(((nowReceivedTimestamp >= lastReceivedTimestamp) && ((nowReceivedTimestamp - lastReceivedTimestamp) <= TST_MAX/2))
98  || ((lastReceivedTimestamp > nowReceivedTimestamp) && ((lastReceivedTimestamp - nowReceivedTimestamp) > TST_MAX/2)))
99  return false;
100  else
101  return true;
102 }
103 
104 bool isDuplicatePacketDetectionTimestampSN(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp, quint16 lastReceivedSN, quint16 nowReceivedSN)
105 {
106  if(((nowReceivedTimestamp > lastReceivedTimestamp) && ((nowReceivedTimestamp - lastReceivedTimestamp) <= TST_MAX/2))
107  || ((lastReceivedTimestamp > nowReceivedTimestamp) && ((lastReceivedTimestamp - nowReceivedTimestamp) > TST_MAX/2)))
108  return false;
109  else if(nowReceivedTimestamp == lastReceivedTimestamp)
110  if(((nowReceivedSN > lastReceivedSN) && ((nowReceivedSN - lastReceivedSN) <= SN_MAX/2))
111  || ((lastReceivedSN > nowReceivedSN) && ((lastReceivedSN - nowReceivedSN) > SN_MAX/2)))
112  return false;
113  else
114  return true;
115  else
116  return true;
117 }
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
quint64 get_INT64(u_char *field, qint64 *int64)
get_INT64 Extract an integer encoded in 64 bits from a byte array.
Definition: apiNetwork.cpp:3
quint64 get_INT8(u_char *field, qint8 *int8)
get_INT8 Extract an integer encoded in 8 bits from a byte array.
Definition: apiNetwork.cpp:81
quint64 get_INT16(u_char *field, qint16 *int16)
get_INT16 Extract an integer encoded in 16 bits from a byte array.
Definition: apiNetwork.cpp:55
bool isDuplicatePacketDetectionTimestamp(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp)
isDuplicatePacketDetectionTimestamp Calculate if the packet is a duplicate using the timestamp of the...
Definition: apiNetwork.cpp:95
quint64 get_UINT64(u_char *field, quint64 *uint64)
get_UINT64 Extract an unsigned integer encoded in 64 bits from a byte array.
Definition: apiNetwork.cpp:17
quint64 get_INT32(u_char *field, qint32 *int32)
get_INT32 Extract an integer encoded in 32 bits from a byte array.
Definition: apiNetwork.cpp:29
quint64 get_UINT8(u_char *field, quint8 *uint8)
get_UINT8 Extract an unsigned integer encoded in 64 bits from a byte array.
Definition: apiNetwork.cpp:88
#define SN_MAX
Definition: apiNetwork.h:10
quint64 get_UINT32(u_char *field, quint32 *uint32)
get_UINT32 Extract an unsigned integer encoded in 32 bits from a byte array.
Definition: apiNetwork.cpp:43
quint64 get_UINT16(u_char *field, quint16 *uint16)
get_INT64 Extract an integer encoded in 64 bits from a byte array.
Definition: apiNetwork.cpp:69
#define TST_MAX
Network library.
Definition: apiNetwork.h:9