ITS
LongPositionVector.cpp
Go to the documentation of this file.
1 #include "LongPositionVector.h"
2 #include <apiData.h>
3 
5 {
6  m_gnAddr = GnAddr();
7  m_timestamp = 0;
8  m_latitude = 0;
9  m_longitude = 0;
10  m_pai_Speed = 0;
11  m_heading = 0;
12 }
13 
14 LongPositionVector::LongPositionVector(GnAddr gnA, quint32 tmstmp, qint32 lat, qint32 lon, quint16 paiSpeed, quint16 head)
15 {
16  m_gnAddr = gnA;
17  m_timestamp = tmstmp;
18  m_latitude = lat;
19  m_longitude = lon;
20  m_pai_Speed = paiSpeed;
21  m_heading = head;
22 }
23 
24 LongPositionVector::LongPositionVector(GnAddr gnA, quint32 tmstmp, qint32 lat, qint32 lon, quint8 pai, quint16 speed, quint16 head)
25 {
26  m_gnAddr = gnA;
27  m_timestamp = tmstmp;
28  m_latitude = lat;
29  m_longitude = lon;
30  m_pai_Speed = (pai & 1) << 15;
31  m_pai_Speed = (speed & 0x7FF);
32  m_heading = head;
33 }
34 
36 {
37  m_gnAddr = spv.gnAddr();
38  m_latitude = spv.latitude();
39  m_longitude = spv.longitude();
40  m_timestamp = spv.timestamp();
41 }
42 
44 {
45  m_gnAddr = GnAddr(QByteArray(data, *offset));
46  *offset += 8;
47  m_latitude = extractInt(data, 4, offset);
48  m_longitude = extractInt(data, 4, offset);
49  m_timestamp = extractUInt(data, 8, offset);
50 }
51 
53 {
54  this->m_gnAddr = other.gnAddr();
55  this->m_timestamp = other.timestamp();
56  this->m_latitude = other.latitude();
57  this->m_longitude = other.longitude();
58  this->m_pai_Speed = other.pai_Speed();
59  this->m_heading = other.heading();
60 }
61 
63 {
64  this->m_gnAddr = other.gnAddr();
65  this->m_timestamp = other.timestamp();
66  this->m_latitude = other.latitude();
67  this->m_longitude = other.longitude();
68  this->m_pai_Speed = other.pai_Speed();
69  this->m_heading = other.heading();
70  return *this;
71 }
72 
73 quint64 LongPositionVector::extract(uchar* packet)
74 {
75  quint64 offset = 0;
76 
77  offset += m_gnAddr.extract(packet + offset);
78  offset += get_UINT32(packet + offset, &m_timestamp);
79  offset += get_INT32(packet + offset, &m_latitude);
80  offset += get_INT32(packet + offset, &m_longitude);
81  offset += get_UINT16(packet + offset, &m_pai_Speed);
82  offset += get_UINT16(packet + offset, &m_heading);
83 
84  return offset;
85 }
86 
88 {
89  QByteArray hex;
90  QDataStream ds(&hex, QIODevice::WriteOnly);
91 
92  ds.writeRawData(m_gnAddr.toHex().data(), GnAddr::helper_size);
93  ds << m_timestamp;
94  ds << m_latitude;
95  ds << m_longitude;
96  ds << m_pai_Speed;
97  ds << m_heading;
98 
99  return hex;
100 }
LongPositionVector & operator=(const LongPositionVector &other)
operator = Overload of = operator
quint16 speed() const
speed Speed field getter (15 bits)
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
quint32 timestamp() const
timestamp Timestamp field getter
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
GnAddr gnAddr() const
gnAddr GnAddr field getter
quint16 heading() const
heading Heading field getter
quint64 extract(uchar *packet)
extract Fill the LongPositionVector with values contained in the packet
LongPositionVector()
LongPositionVector Default constructor.
quint64 extractUInt(char *data, int l, int *offset)
extractUInt Extract an unsigned integer from byte array.
Definition: apiData.cpp:3
quint64 extract(uchar *packet)
extract Fill the GnAddr with values contained in the packet.
Definition: GnAddr.cpp:55
quint16 pai_Speed() const
pai_Speed Pai_Speed field getter (16 bits)
qint32 latitude() const
latitude Latitude field getter
qint32 latitude() const
latitude Latitude field getter
quint32 timestamp() const
timestamp Timestamp field getter
qint64 extractInt(char *data, int l, int *offset)
extractInt Extract an signed integer from byte array.
Definition: apiData.cpp:22
QByteArray toHex()
toHex Create a QByteArray containing the hexadecimal format of the GnAddr.
Definition: GnAddr.cpp:69
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
QByteArray toHex()
toHex Create a QByteArray containing the hexadecimal format of the LongPositionVector.
LPV definition.
Definition: GnAddr.h:28
quint8 pai() const
pai Pai field getter (1 bit)
qint32 longitude() const
longitude Longitude field getter
qint32 longitude() const
longitude Longitude field getter
GnAddr gnAddr() const
gnAddr GnAddr field getter
API used for C++ style data.