QtFit  0.1
Internal library development documentation
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
obdiidatamessage.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2021 Paul Colby
3 
4  This file is part of QtFit.
5 
6  QtFit is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  QtFit is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with QtFit. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*!
21  * \file
22  * \note This file is automatcially generated. Any changes here are likely to be overwritten.
23  */
24 
25 /*!
26  * \file
27  * Defines the ObdiiDataMessage, and ObdiiDataMessagePrivate classes.
28  */
29 
30 #include "obdiidatamessage.h"
31 #include "obdiidatamessage_p.h"
32 
33 #include <QDebug>
34 #include <QtEndian>
35 
37 
38 /*!
39  * \class ObdiiDataMessage
40  *
41  * The ObdiiDataMessage class represents a FIT ObdiiDataMessage data message.
42  *
43  * \sa DataMessage
44  */
45 
46 /*!
47  * Constructs a ObdiiDataMessage object.
48  *
49  * Typically, instances of this class will be returned by FitStreamReader::readNext, but this
50  * constructor may be used, along with the relevant setter methods, to create a valid message.
51  */
53 {
54 
55 }
56 
57 /*!
58  * \internal
59  *
60  * Constructs a ObdiiDataMessage object with private implementation \a d.
61  *
62  * \param d Pointer to private implementation.
63  */
65 {
66 
67 }
68 
69 /*!
70  * Returns the ObdiiDataMessage data message's \c timestamp field's current value.
71  *
72  * Timestamp message was output
73  *
74  * \return the \c timestamp field value.
75  */
77 {
78  Q_D(const ObdiiDataMessage);
79  return d->timestamp;
80 }
81 
82 /*!
83  * Returns the ObdiiDataMessage data message's \c timestampMs field's current value.
84  *
85  * Fractional part of timestamp, added to timestamp
86  *
87  * \return the \c timestampMs field value.
88  */
90 {
91  Q_D(const ObdiiDataMessage);
92  return d->timestampMs;
93 }
94 
95 /*!
96  * Returns the ObdiiDataMessage data message's \c timeOffset field's current value.
97  *
98  * Offset of PID reading [i] from start_timestamp+start_timestamp_ms. Readings may span accross
99  * seconds.
100  *
101  * \return the \c timeOffset field value.
102  */
104 {
105  Q_D(const ObdiiDataMessage);
106  return d->timeOffset;
107 }
108 
109 /*!
110  * Returns the ObdiiDataMessage data message's \c pid field's current value.
111  *
112  * Parameter ID
113  *
114  * \return the \c pid field value.
115  */
116 quint8 ObdiiDataMessage::pid() const
117 {
118  Q_D(const ObdiiDataMessage);
119  return d->pid;
120 }
121 
122 /*!
123  * Returns the ObdiiDataMessage data message's \c rawData field's current value.
124  *
125  * Raw parameter data
126  *
127  * \return the \c rawData field value.
128  */
130 {
131  Q_D(const ObdiiDataMessage);
132  return d->rawData;
133 }
134 
135 /*!
136  * Returns the ObdiiDataMessage data message's \c pidDataSize field's current value.
137  *
138  * Optional, data size of PID[i]. If not specified refer to SAE J1979.
139  *
140  * \return the \c pidDataSize field value.
141  */
143 {
144  Q_D(const ObdiiDataMessage);
145  return d->pidDataSize;
146 }
147 
148 /*!
149  * Returns the ObdiiDataMessage data message's \c systemTime field's current value.
150  *
151  * System time associated with sample expressed in ms, can be used instead of time_offset.
152  * There will be a system_time value for each raw_data element. For multibyte pids the
153  * system_time is repeated.
154  *
155  * \return the \c systemTime field value.
156  */
158 {
159  Q_D(const ObdiiDataMessage);
160  return d->systemTime;
161 }
162 
163 /*!
164  * Returns the ObdiiDataMessage data message's \c startTimestamp field's current value.
165  *
166  * Timestamp of first sample recorded in the message. Used with time_offset to generate time of
167  * each sample
168  *
169  * \return the \c startTimestamp field value.
170  */
172 {
173  Q_D(const ObdiiDataMessage);
174  return d->startTimestamp;
175 }
176 
177 /*!
178  * Returns the ObdiiDataMessage data message's \c startTimestampMs field's current value.
179  *
180  * Fractional part of start_timestamp
181  *
182  * \return the \c startTimestampMs field value.
183  */
185 {
186  Q_D(const ObdiiDataMessage);
187  return d->startTimestampMs;
188 }
189 
190 /*!
191  * Sets the \c timestamp field to \a timestamp.
192  *
193  * \param timestamp The field value to set.
194  */
196 {
197  Q_D(ObdiiDataMessage);
198  d->timestamp = timestamp;
199 }
200 /*!
201  * Sets the \c timestampMs field to \a timestampMs.
202  *
203  * \param timestampMs The field value to set.
204  */
205 void ObdiiDataMessage::setTimestampMs(const quint16 timestampMs)
206 {
207  Q_D(ObdiiDataMessage);
208  d->timestampMs = timestampMs;
209 }
210 /*!
211  * Sets the \c timeOffset field to \a timeOffset.
212  *
213  * \param timeOffset The field value to set.
214  */
215 void ObdiiDataMessage::setTimeOffset(const quint16 timeOffset)
216 {
217  Q_D(ObdiiDataMessage);
218  d->timeOffset = timeOffset;
219 }
220 /*!
221  * Sets the \c pid field to \a pid.
222  *
223  * \param pid The field value to set.
224  */
225 void ObdiiDataMessage::setPid(const quint8 pid)
226 {
227  Q_D(ObdiiDataMessage);
228  d->pid = pid;
229 }
230 /*!
231  * Sets the \c rawData field to \a rawData.
232  *
233  * \param rawData The field value to set.
234  */
235 void ObdiiDataMessage::setRawData(const quint8 rawData)
236 {
237  Q_D(ObdiiDataMessage);
238  d->rawData = rawData;
239 }
240 /*!
241  * Sets the \c pidDataSize field to \a pidDataSize.
242  *
243  * \param pidDataSize The field value to set.
244  */
245 void ObdiiDataMessage::setPidDataSize(const quint8 pidDataSize)
246 {
247  Q_D(ObdiiDataMessage);
248  d->pidDataSize = pidDataSize;
249 }
250 /*!
251  * Sets the \c systemTime field to \a systemTime.
252  *
253  * \param systemTime The field value to set.
254  */
255 void ObdiiDataMessage::setSystemTime(const quint32 systemTime)
256 {
257  Q_D(ObdiiDataMessage);
258  d->systemTime = systemTime;
259 }
260 /*!
261  * Sets the \c startTimestamp field to \a startTimestamp.
262  *
263  * \param startTimestamp The field value to set.
264  */
266 {
267  Q_D(ObdiiDataMessage);
268  d->startTimestamp = startTimestamp;
269 }
270 /*!
271  * Sets the \c startTimestampMs field to \a startTimestampMs.
272  *
273  * \param startTimestampMs The field value to set.
274  */
275 void ObdiiDataMessage::setStartTimestampMs(const quint16 startTimestampMs)
276 {
277  Q_D(ObdiiDataMessage);
278  d->startTimestampMs = startTimestampMs;
279 }
280 
281 /// \cond internal
282 
283 /*!
284  * \internal
285  *
286  * \class ObdiiDataMessagePrivate
287  *
288  * The ObdiiDataMessagePrivate class provides private implementation for the ObdiiDataMessage.
289  *
290  * \sa ObdiiDataMessage
291  */
292 
293 /*!
294  * \internal
295  *
296  * Constructs a ObdiiDataMessagePrivate object with public implementation \a q.
297  *
298  * \param q Pointer to public implementaton.
299  */
300 ObdiiDataMessagePrivate::ObdiiDataMessagePrivate(ObdiiDataMessage * const q)
302  , timestamp(static_cast<DateTime>(-1))
303  , timestampMs(0xFFFF)
304  , timeOffset(0xFFFF)
305  , pid(0xFF)
306  , rawData(0xFF)
307  , pidDataSize(0xFF)
308  , systemTime(0xFFFFFFFF)
309  , startTimestamp(static_cast<DateTime>(-1))
310  , startTimestampMs(0xFFFF)
311 {
312  globalMessageNumber = MesgNum::ObdiiData;
313 }
314 
315 /*!
316  * \internal
317  *
318  * Destroys the ObdiiDataMessagePrivate object.
319  */
321 {
322 
323 }
324 
326  const int fieldId, const QByteArray &data, const FitBaseType baseType, const bool bigEndian)
327 {
328  switch (fieldId) {
329  case 253: // See Profile.xlsx::Messages:obdii_data.timestamp
330  if (!verify(data, baseType, 4, FitBaseType::Uint32, "obdii_data.timestamp")) return false;
331  this->timestamp = static_cast<DateTime>(bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data));
332  break;
333  case 0: // See Profile.xlsx::Messages:obdii_data.timestampMs
334  if (!verify(data, baseType, 2, FitBaseType::Uint16, "obdii_data.timestampMs")) return false;
335  this->timestampMs = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
336  break;
337  case 1: // See Profile.xlsx::Messages:obdii_data.timeOffset
338  if (!verify(data, baseType, 2, FitBaseType::Uint16, "obdii_data.timeOffset")) return false;
339  this->timeOffset = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
340  break;
341  case 2: // See Profile.xlsx::Messages:obdii_data.pid
342  if (!verify(data, baseType, 1, FitBaseType::Byte, "obdii_data.pid")) return false;
343  this->pid = static_cast<quint8>(data.at(0));
344  break;
345  case 3: // See Profile.xlsx::Messages:obdii_data.rawData
346  if (!verify(data, baseType, 1, FitBaseType::Byte, "obdii_data.rawData")) return false;
347  this->rawData = static_cast<quint8>(data.at(0));
348  break;
349  case 4: // See Profile.xlsx::Messages:obdii_data.pidDataSize
350  if (!verify(data, baseType, 1, FitBaseType::Uint8, "obdii_data.pidDataSize")) return false;
351  this->pidDataSize = static_cast<quint8>(data.at(0));
352  break;
353  case 5: // See Profile.xlsx::Messages:obdii_data.systemTime
354  if (!verify(data, baseType, 4, FitBaseType::Uint32, "obdii_data.systemTime")) return false;
355  this->systemTime = static_cast<quint32>(bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data));
356  break;
357  case 6: // See Profile.xlsx::Messages:obdii_data.startTimestamp
358  if (!verify(data, baseType, 4, FitBaseType::Uint32, "obdii_data.startTimestamp")) return false;
359  this->startTimestamp = static_cast<DateTime>(bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data));
360  break;
361  case 7: // See Profile.xlsx::Messages:obdii_data.startTimestampMs
362  if (!verify(data, baseType, 2, FitBaseType::Uint16, "obdii_data.startTimestampMs")) return false;
363  this->startTimestampMs = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
364  break;
365  default:
366  qWarning() << "ignoring unknown obdii_data message field number" << fieldId << bigEndian;
367  // Fall through to return true, as its still 'safe' to continue parsing data messages.
368  }
369  return true;
370 }
371 
372 /// \endcond
373 
#define QTFIT_END_NAMESPACE
Macro for ending the QtFit library's top-most namespace (if one is defined).
Definition: QtFit_global.h:78
#define QTFIT_BEGIN_NAMESPACE
Macro for starting the QtFit library's top-most namespace (if one is defined).
Definition: QtFit_global.h:77
MesgNum globalMessageNumber
FIT Globla Message Number for this FIT Data Message.
bool verify(const QByteArray &data, const FitBaseType actualType, const int expectedSize, const FitBaseType expectedType, const char *messageFieldName)
The AbstractDataMessage class is the polymorphic base class for all FIT Data Message classes.
quint16 startTimestampMs
The ObdiiDataMessage FIT message's startTimestampMs field.
bool setField(const int fieldId, const QByteArray &data, const FitBaseType baseType, const bool bigEndian) override
DateTime timestamp
The ObdiiDataMessage FIT message's timestamp field.
quint8 rawData
The ObdiiDataMessage FIT message's rawData field.
quint8 pid
The ObdiiDataMessage FIT message's pid field.
quint32 systemTime
The ObdiiDataMessage FIT message's systemTime field.
quint8 pidDataSize
The ObdiiDataMessage FIT message's pidDataSize field.
quint16 timestampMs
The ObdiiDataMessage FIT message's timestampMs field.
quint16 timeOffset
The ObdiiDataMessage FIT message's timeOffset field.
DateTime startTimestamp
The ObdiiDataMessage FIT message's startTimestamp field.
The ObdiiDataMessage class represents a FIT ObdiiDataMessage data message.
void setPid(const quint8 pid)
Sets the pid field to pid.
void setRawData(const quint8 rawData)
Sets the rawData field to rawData.
quint8 rawData() const
Returns the ObdiiDataMessage data message's rawData field's current value.
quint32 systemTime() const
Returns the ObdiiDataMessage data message's systemTime field's current value.
void setStartTimestamp(const DateTime startTimestamp)
Sets the startTimestamp field to startTimestamp.
quint16 timestampMs() const
Returns the ObdiiDataMessage data message's timestampMs field's current value.
void setTimestamp(const DateTime timestamp)
Sets the timestamp field to timestamp.
DateTime startTimestamp() const
Returns the ObdiiDataMessage data message's startTimestamp field's current value.
DateTime timestamp() const
Returns the ObdiiDataMessage data message's timestamp field's current value.
quint8 pidDataSize() const
Returns the ObdiiDataMessage data message's pidDataSize field's current value.
void setPidDataSize(const quint8 pidDataSize)
Sets the pidDataSize field to pidDataSize.
quint16 timeOffset() const
Returns the ObdiiDataMessage data message's timeOffset field's current value.
void setStartTimestampMs(const quint16 startTimestampMs)
Sets the startTimestampMs field to startTimestampMs.
quint8 pid() const
Returns the ObdiiDataMessage data message's pid field's current value.
void setTimeOffset(const quint16 timeOffset)
Sets the timeOffset field to timeOffset.
void setSystemTime(const quint32 systemTime)
Sets the systemTime field to systemTime.
ObdiiDataMessage()
Constructs a ObdiiDataMessage object.
quint16 startTimestampMs() const
Returns the ObdiiDataMessage data message's startTimestampMs field's current value.
void setTimestampMs(const quint16 timestampMs)
Sets the timestampMs field to timestampMs.
Declares the ObdiiDataMessage class.
Declares the ObdiiDataMessagePrivate class.
FitBaseType
Garmin FIT FitBaseType type.
Definition: types.h:3388
DateTime
Seconds since UTC 00:00 Dec 31 1989.
Definition: types.h:237