QtFit  0.1
Internal library development documentation
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gyroscopedatamessage.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 GyroscopeDataMessage, and GyroscopeDataMessagePrivate classes.
28  */
29 
30 #include "gyroscopedatamessage.h"
31 #include "gyroscopedatamessage_p.h"
32 
33 #include <QDebug>
34 #include <QtEndian>
35 
37 
38 /*!
39  * \class GyroscopeDataMessage
40  *
41  * The GyroscopeDataMessage class represents a FIT GyroscopeDataMessage data message.
42  *
43  * \sa DataMessage
44  */
45 
46 /*!
47  * Constructs a GyroscopeDataMessage 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 GyroscopeDataMessage object with private implementation \a d.
61  *
62  * \param d Pointer to private implementation.
63  */
65 {
66 
67 }
68 
69 /*!
70  * Returns the GyroscopeDataMessage data message's \c timestamp field's current value.
71  *
72  * Whole second part of the timestamp
73  *
74  * \return the \c timestamp field value.
75  */
77 {
78  Q_D(const GyroscopeDataMessage);
79  return d->timestamp;
80 }
81 
82 /*!
83  * Returns the GyroscopeDataMessage data message's \c timestampMs field's current value.
84  *
85  * Millisecond part of the timestamp.
86  *
87  * \return the \c timestampMs field value.
88  */
90 {
91  Q_D(const GyroscopeDataMessage);
92  return d->timestampMs;
93 }
94 
95 /*!
96  * Returns the GyroscopeDataMessage data message's \c sampleTimeOffset field's current value.
97  *
98  * Each time in the array describes the time at which the gyro sample with the corrosponding
99  * index was taken. Limited to 30 samples in each message. The samples may span across seconds.
100  * Array size must match the number of samples in gyro_x and gyro_y and gyro_z
101  *
102  * \return the \c sampleTimeOffset field value.
103  */
105 {
106  Q_D(const GyroscopeDataMessage);
107  return d->sampleTimeOffset;
108 }
109 
110 /*!
111  * Returns the GyroscopeDataMessage data message's \c gyroX field's current value.
112  *
113  * These are the raw ADC reading. Maximum number of samples is 30 in each message. The samples
114  * may span across seconds. A conversion will need to be done on this data once read.
115  *
116  * \return the \c gyroX field value.
117  */
119 {
120  Q_D(const GyroscopeDataMessage);
121  return d->gyroX;
122 }
123 
124 /*!
125  * Returns the GyroscopeDataMessage data message's \c gyroY field's current value.
126  *
127  * These are the raw ADC reading. Maximum number of samples is 30 in each message. The samples
128  * may span across seconds. A conversion will need to be done on this data once read.
129  *
130  * \return the \c gyroY field value.
131  */
133 {
134  Q_D(const GyroscopeDataMessage);
135  return d->gyroY;
136 }
137 
138 /*!
139  * Returns the GyroscopeDataMessage data message's \c gyroZ field's current value.
140  *
141  * These are the raw ADC reading. Maximum number of samples is 30 in each message. The samples
142  * may span across seconds. A conversion will need to be done on this data once read.
143  *
144  * \return the \c gyroZ field value.
145  */
147 {
148  Q_D(const GyroscopeDataMessage);
149  return d->gyroZ;
150 }
151 
152 /*!
153  * Returns the GyroscopeDataMessage data message's \c calibratedGyroX field's current value.
154  *
155  * Calibrated gyro reading
156  *
157  * \return the \c calibratedGyroX field value.
158  */
160 {
161  Q_D(const GyroscopeDataMessage);
162  return d->calibratedGyroX;
163 }
164 
165 /*!
166  * Returns the GyroscopeDataMessage data message's \c calibratedGyroY field's current value.
167  *
168  * Calibrated gyro reading
169  *
170  * \return the \c calibratedGyroY field value.
171  */
173 {
174  Q_D(const GyroscopeDataMessage);
175  return d->calibratedGyroY;
176 }
177 
178 /*!
179  * Returns the GyroscopeDataMessage data message's \c calibratedGyroZ field's current value.
180  *
181  * Calibrated gyro reading
182  *
183  * \return the \c calibratedGyroZ field value.
184  */
186 {
187  Q_D(const GyroscopeDataMessage);
188  return d->calibratedGyroZ;
189 }
190 
191 /*!
192  * Sets the \c timestamp field to \a timestamp.
193  *
194  * \param timestamp The field value to set.
195  */
197 {
199  d->timestamp = timestamp;
200 }
201 /*!
202  * Sets the \c timestampMs field to \a timestampMs.
203  *
204  * \param timestampMs The field value to set.
205  */
206 void GyroscopeDataMessage::setTimestampMs(const quint16 timestampMs)
207 {
209  d->timestampMs = timestampMs;
210 }
211 /*!
212  * Sets the \c sampleTimeOffset field to \a sampleTimeOffset.
213  *
214  * \param sampleTimeOffset The field value to set.
215  */
216 void GyroscopeDataMessage::setSampleTimeOffset(const quint16 sampleTimeOffset)
217 {
219  d->sampleTimeOffset = sampleTimeOffset;
220 }
221 /*!
222  * Sets the \c gyroX field to \a gyroX.
223  *
224  * \param gyroX The field value to set.
225  */
226 void GyroscopeDataMessage::setGyroX(const quint16 gyroX)
227 {
229  d->gyroX = gyroX;
230 }
231 /*!
232  * Sets the \c gyroY field to \a gyroY.
233  *
234  * \param gyroY The field value to set.
235  */
236 void GyroscopeDataMessage::setGyroY(const quint16 gyroY)
237 {
239  d->gyroY = gyroY;
240 }
241 /*!
242  * Sets the \c gyroZ field to \a gyroZ.
243  *
244  * \param gyroZ The field value to set.
245  */
246 void GyroscopeDataMessage::setGyroZ(const quint16 gyroZ)
247 {
249  d->gyroZ = gyroZ;
250 }
251 /*!
252  * Sets the \c calibratedGyroX field to \a calibratedGyroX.
253  *
254  * \param calibratedGyroX The field value to set.
255  */
256 void GyroscopeDataMessage::setCalibratedGyroX(const float calibratedGyroX)
257 {
259  d->calibratedGyroX = calibratedGyroX;
260 }
261 /*!
262  * Sets the \c calibratedGyroY field to \a calibratedGyroY.
263  *
264  * \param calibratedGyroY The field value to set.
265  */
266 void GyroscopeDataMessage::setCalibratedGyroY(const float calibratedGyroY)
267 {
269  d->calibratedGyroY = calibratedGyroY;
270 }
271 /*!
272  * Sets the \c calibratedGyroZ field to \a calibratedGyroZ.
273  *
274  * \param calibratedGyroZ The field value to set.
275  */
276 void GyroscopeDataMessage::setCalibratedGyroZ(const float calibratedGyroZ)
277 {
279  d->calibratedGyroZ = calibratedGyroZ;
280 }
281 
282 /// \cond internal
283 
284 /*!
285  * \internal
286  *
287  * \class GyroscopeDataMessagePrivate
288  *
289  * The GyroscopeDataMessagePrivate class provides private implementation for the GyroscopeDataMessage.
290  *
291  * \sa GyroscopeDataMessage
292  */
293 
294 /*!
295  * \internal
296  *
297  * Constructs a GyroscopeDataMessagePrivate object with public implementation \a q.
298  *
299  * \param q Pointer to public implementaton.
300  */
301 GyroscopeDataMessagePrivate::GyroscopeDataMessagePrivate(GyroscopeDataMessage * const q)
303  , timestamp(static_cast<DateTime>(-1))
304  , timestampMs(0xFFFF)
305  , sampleTimeOffset(0xFFFF)
306  , gyroX(0xFFFF)
307  , gyroY(0xFFFF)
308  , gyroZ(0xFFFF)
309  , calibratedGyroX(static_cast<float>(-1))
310  , calibratedGyroY(static_cast<float>(-1))
311  , calibratedGyroZ(static_cast<float>(-1))
312 {
313  globalMessageNumber = MesgNum::GyroscopeData;
314 }
315 
316 /*!
317  * \internal
318  *
319  * Destroys the GyroscopeDataMessagePrivate object.
320  */
322 {
323 
324 }
325 
327  const int fieldId, const QByteArray &data, const FitBaseType baseType, const bool bigEndian)
328 {
329  switch (fieldId) {
330  case 253: // See Profile.xlsx::Messages:gyroscope_data.timestamp
331  if (!verify(data, baseType, 4, FitBaseType::Uint32, "gyroscope_data.timestamp")) return false;
332  this->timestamp = static_cast<DateTime>(bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data));
333  break;
334  case 0: // See Profile.xlsx::Messages:gyroscope_data.timestampMs
335  if (!verify(data, baseType, 2, FitBaseType::Uint16, "gyroscope_data.timestampMs")) return false;
336  this->timestampMs = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
337  break;
338  case 1: // See Profile.xlsx::Messages:gyroscope_data.sampleTimeOffset
339  if (!verify(data, baseType, 2, FitBaseType::Uint16, "gyroscope_data.sampleTimeOffset")) return false;
340  this->sampleTimeOffset = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
341  break;
342  case 2: // See Profile.xlsx::Messages:gyroscope_data.gyroX
343  if (!verify(data, baseType, 2, FitBaseType::Uint16, "gyroscope_data.gyroX")) return false;
344  this->gyroX = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
345  break;
346  case 3: // See Profile.xlsx::Messages:gyroscope_data.gyroY
347  if (!verify(data, baseType, 2, FitBaseType::Uint16, "gyroscope_data.gyroY")) return false;
348  this->gyroY = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
349  break;
350  case 4: // See Profile.xlsx::Messages:gyroscope_data.gyroZ
351  if (!verify(data, baseType, 2, FitBaseType::Uint16, "gyroscope_data.gyroZ")) return false;
352  this->gyroZ = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
353  break;
354  case 5: // See Profile.xlsx::Messages:gyroscope_data.calibratedGyroX
355  if (!verify(data, baseType, 4, FitBaseType::Float32, "gyroscope_data.calibratedGyroX")) return false;
356  #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
357  { // Qt's from-endian functions have no float/double specialisations prior to Qt 5.12.
358  const quint32 localEndian = bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data);
359  static_assert(sizeof(localEndian) == 4, "src not expected size");
360  static_assert(sizeof(this->calibratedGyroX) == 4, "src and dst not the same size");
361  memcpy(&this->calibratedGyroX, &localEndian, data.size());
362  }
363  #else
364  this->calibratedGyroX = static_cast<float>(bigEndian ? qFromBigEndian<float>(data) : qFromLittleEndian<float>(data));
365  #endif
366  break;
367  case 6: // See Profile.xlsx::Messages:gyroscope_data.calibratedGyroY
368  if (!verify(data, baseType, 4, FitBaseType::Float32, "gyroscope_data.calibratedGyroY")) return false;
369  #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
370  { // Qt's from-endian functions have no float/double specialisations prior to Qt 5.12.
371  const quint32 localEndian = bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data);
372  static_assert(sizeof(localEndian) == 4, "src not expected size");
373  static_assert(sizeof(this->calibratedGyroY) == 4, "src and dst not the same size");
374  memcpy(&this->calibratedGyroY, &localEndian, data.size());
375  }
376  #else
377  this->calibratedGyroY = static_cast<float>(bigEndian ? qFromBigEndian<float>(data) : qFromLittleEndian<float>(data));
378  #endif
379  break;
380  case 7: // See Profile.xlsx::Messages:gyroscope_data.calibratedGyroZ
381  if (!verify(data, baseType, 4, FitBaseType::Float32, "gyroscope_data.calibratedGyroZ")) return false;
382  #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
383  { // Qt's from-endian functions have no float/double specialisations prior to Qt 5.12.
384  const quint32 localEndian = bigEndian ? qFromBigEndian<quint32>(data) : qFromLittleEndian<quint32>(data);
385  static_assert(sizeof(localEndian) == 4, "src not expected size");
386  static_assert(sizeof(this->calibratedGyroZ) == 4, "src and dst not the same size");
387  memcpy(&this->calibratedGyroZ, &localEndian, data.size());
388  }
389  #else
390  this->calibratedGyroZ = static_cast<float>(bigEndian ? qFromBigEndian<float>(data) : qFromLittleEndian<float>(data));
391  #endif
392  break;
393  default:
394  qWarning() << "ignoring unknown gyroscope_data message field number" << fieldId << bigEndian;
395  // Fall through to return true, as its still 'safe' to continue parsing data messages.
396  }
397  return true;
398 }
399 
400 /// \endcond
401 
#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 gyroX
The GyroscopeDataMessage FIT message's gyroX field.
bool setField(const int fieldId, const QByteArray &data, const FitBaseType baseType, const bool bigEndian) override
quint16 gyroY
The GyroscopeDataMessage FIT message's gyroY field.
DateTime timestamp
The GyroscopeDataMessage FIT message's timestamp field.
float calibratedGyroX
The GyroscopeDataMessage FIT message's calibratedGyroX field.
float calibratedGyroY
The GyroscopeDataMessage FIT message's calibratedGyroY field.
quint16 sampleTimeOffset
The GyroscopeDataMessage FIT message's sampleTimeOffset field.
quint16 gyroZ
The GyroscopeDataMessage FIT message's gyroZ field.
quint16 timestampMs
The GyroscopeDataMessage FIT message's timestampMs field.
float calibratedGyroZ
The GyroscopeDataMessage FIT message's calibratedGyroZ field.
The GyroscopeDataMessage class represents a FIT GyroscopeDataMessage data message.
quint16 sampleTimeOffset() const
Returns the GyroscopeDataMessage data message's sampleTimeOffset field's current value.
void setTimestampMs(const quint16 timestampMs)
Sets the timestampMs field to timestampMs.
void setCalibratedGyroZ(const float calibratedGyroZ)
Sets the calibratedGyroZ field to calibratedGyroZ.
quint16 gyroX() const
Returns the GyroscopeDataMessage data message's gyroX field's current value.
void setGyroX(const quint16 gyroX)
Sets the gyroX field to gyroX.
void setCalibratedGyroY(const float calibratedGyroY)
Sets the calibratedGyroY field to calibratedGyroY.
void setGyroY(const quint16 gyroY)
Sets the gyroY field to gyroY.
void setGyroZ(const quint16 gyroZ)
Sets the gyroZ field to gyroZ.
void setSampleTimeOffset(const quint16 sampleTimeOffset)
Sets the sampleTimeOffset field to sampleTimeOffset.
DateTime timestamp() const
Returns the GyroscopeDataMessage data message's timestamp field's current value.
void setTimestamp(const DateTime timestamp)
Sets the timestamp field to timestamp.
float calibratedGyroY() const
Returns the GyroscopeDataMessage data message's calibratedGyroY field's current value.
void setCalibratedGyroX(const float calibratedGyroX)
Sets the calibratedGyroX field to calibratedGyroX.
float calibratedGyroZ() const
Returns the GyroscopeDataMessage data message's calibratedGyroZ field's current value.
GyroscopeDataMessage()
Constructs a GyroscopeDataMessage object.
float calibratedGyroX() const
Returns the GyroscopeDataMessage data message's calibratedGyroX field's current value.
quint16 gyroZ() const
Returns the GyroscopeDataMessage data message's gyroZ field's current value.
quint16 timestampMs() const
Returns the GyroscopeDataMessage data message's timestampMs field's current value.
quint16 gyroY() const
Returns the GyroscopeDataMessage data message's gyroY field's current value.
Declares the GyroscopeDataMessage class.
Declares the GyroscopeDataMessagePrivate class.
FitBaseType
Garmin FIT FitBaseType type.
Definition: types.h:3388
DateTime
Seconds since UTC 00:00 Dec 31 1989.
Definition: types.h:237