QtFit  0.1
Internal library development documentation
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
magnetometerdatamessage.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 MagnetometerDataMessage, and MagnetometerDataMessagePrivate classes.
28  */
29 
32 
33 #include <QDebug>
34 #include <QtEndian>
35 
37 
38 /*!
39  * \class MagnetometerDataMessage
40  *
41  * The MagnetometerDataMessage class represents a FIT MagnetometerDataMessage data message.
42  *
43  * \sa DataMessage
44  */
45 
46 /*!
47  * Constructs a MagnetometerDataMessage 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 MagnetometerDataMessage object with private implementation \a d.
61  *
62  * \param d Pointer to private implementation.
63  */
65 {
66 
67 }
68 
69 /*!
70  * Returns the MagnetometerDataMessage 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 MagnetometerDataMessage);
79  return d->timestamp;
80 }
81 
82 /*!
83  * Returns the MagnetometerDataMessage 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 MagnetometerDataMessage);
92  return d->timestampMs;
93 }
94 
95 /*!
96  * Returns the MagnetometerDataMessage data message's \c sampleTimeOffset field's current value.
97  *
98  * Each time in the array describes the time at which the compass 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 cmps_x and cmps_y and cmps_z
101  *
102  * \return the \c sampleTimeOffset field value.
103  */
105 {
106  Q_D(const MagnetometerDataMessage);
107  return d->sampleTimeOffset;
108 }
109 
110 /*!
111  * Returns the MagnetometerDataMessage data message's \c magX 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 magX field value.
117  */
119 {
120  Q_D(const MagnetometerDataMessage);
121  return d->magX;
122 }
123 
124 /*!
125  * Returns the MagnetometerDataMessage data message's \c magY 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 magY field value.
131  */
133 {
134  Q_D(const MagnetometerDataMessage);
135  return d->magY;
136 }
137 
138 /*!
139  * Returns the MagnetometerDataMessage data message's \c magZ 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 magZ field value.
145  */
147 {
148  Q_D(const MagnetometerDataMessage);
149  return d->magZ;
150 }
151 
152 /*!
153  * Returns the MagnetometerDataMessage data message's \c calibratedMagX field's current value.
154  *
155  * Calibrated Magnetometer reading
156  *
157  * \return the \c calibratedMagX field value.
158  */
160 {
161  Q_D(const MagnetometerDataMessage);
162  return d->calibratedMagX;
163 }
164 
165 /*!
166  * Returns the MagnetometerDataMessage data message's \c calibratedMagY field's current value.
167  *
168  * Calibrated Magnetometer reading
169  *
170  * \return the \c calibratedMagY field value.
171  */
173 {
174  Q_D(const MagnetometerDataMessage);
175  return d->calibratedMagY;
176 }
177 
178 /*!
179  * Returns the MagnetometerDataMessage data message's \c calibratedMagZ field's current value.
180  *
181  * Calibrated Magnetometer reading
182  *
183  * \return the \c calibratedMagZ field value.
184  */
186 {
187  Q_D(const MagnetometerDataMessage);
188  return d->calibratedMagZ;
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 MagnetometerDataMessage::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 MagnetometerDataMessage::setSampleTimeOffset(const quint16 sampleTimeOffset)
217 {
219  d->sampleTimeOffset = sampleTimeOffset;
220 }
221 /*!
222  * Sets the \c magX field to \a magX.
223  *
224  * \param magX The field value to set.
225  */
226 void MagnetometerDataMessage::setMagX(const quint16 magX)
227 {
229  d->magX = magX;
230 }
231 /*!
232  * Sets the \c magY field to \a magY.
233  *
234  * \param magY The field value to set.
235  */
236 void MagnetometerDataMessage::setMagY(const quint16 magY)
237 {
239  d->magY = magY;
240 }
241 /*!
242  * Sets the \c magZ field to \a magZ.
243  *
244  * \param magZ The field value to set.
245  */
246 void MagnetometerDataMessage::setMagZ(const quint16 magZ)
247 {
249  d->magZ = magZ;
250 }
251 /*!
252  * Sets the \c calibratedMagX field to \a calibratedMagX.
253  *
254  * \param calibratedMagX The field value to set.
255  */
256 void MagnetometerDataMessage::setCalibratedMagX(const float calibratedMagX)
257 {
259  d->calibratedMagX = calibratedMagX;
260 }
261 /*!
262  * Sets the \c calibratedMagY field to \a calibratedMagY.
263  *
264  * \param calibratedMagY The field value to set.
265  */
266 void MagnetometerDataMessage::setCalibratedMagY(const float calibratedMagY)
267 {
269  d->calibratedMagY = calibratedMagY;
270 }
271 /*!
272  * Sets the \c calibratedMagZ field to \a calibratedMagZ.
273  *
274  * \param calibratedMagZ The field value to set.
275  */
276 void MagnetometerDataMessage::setCalibratedMagZ(const float calibratedMagZ)
277 {
279  d->calibratedMagZ = calibratedMagZ;
280 }
281 
282 /// \cond internal
283 
284 /*!
285  * \internal
286  *
287  * \class MagnetometerDataMessagePrivate
288  *
289  * The MagnetometerDataMessagePrivate class provides private implementation for the MagnetometerDataMessage.
290  *
291  * \sa MagnetometerDataMessage
292  */
293 
294 /*!
295  * \internal
296  *
297  * Constructs a MagnetometerDataMessagePrivate object with public implementation \a q.
298  *
299  * \param q Pointer to public implementaton.
300  */
301 MagnetometerDataMessagePrivate::MagnetometerDataMessagePrivate(MagnetometerDataMessage * const q)
303  , timestamp(static_cast<DateTime>(-1))
304  , timestampMs(0xFFFF)
305  , sampleTimeOffset(0xFFFF)
306  , magX(0xFFFF)
307  , magY(0xFFFF)
308  , magZ(0xFFFF)
309  , calibratedMagX(static_cast<float>(-1))
310  , calibratedMagY(static_cast<float>(-1))
311  , calibratedMagZ(static_cast<float>(-1))
312 {
313  globalMessageNumber = MesgNum::MagnetometerData;
314 }
315 
316 /*!
317  * \internal
318  *
319  * Destroys the MagnetometerDataMessagePrivate 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:magnetometer_data.timestamp
331  if (!verify(data, baseType, 4, FitBaseType::Uint32, "magnetometer_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:magnetometer_data.timestampMs
335  if (!verify(data, baseType, 2, FitBaseType::Uint16, "magnetometer_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:magnetometer_data.sampleTimeOffset
339  if (!verify(data, baseType, 2, FitBaseType::Uint16, "magnetometer_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:magnetometer_data.magX
343  if (!verify(data, baseType, 2, FitBaseType::Uint16, "magnetometer_data.magX")) return false;
344  this->magX = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
345  break;
346  case 3: // See Profile.xlsx::Messages:magnetometer_data.magY
347  if (!verify(data, baseType, 2, FitBaseType::Uint16, "magnetometer_data.magY")) return false;
348  this->magY = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
349  break;
350  case 4: // See Profile.xlsx::Messages:magnetometer_data.magZ
351  if (!verify(data, baseType, 2, FitBaseType::Uint16, "magnetometer_data.magZ")) return false;
352  this->magZ = static_cast<quint16>(bigEndian ? qFromBigEndian<quint16>(data) : qFromLittleEndian<quint16>(data));
353  break;
354  case 5: // See Profile.xlsx::Messages:magnetometer_data.calibratedMagX
355  if (!verify(data, baseType, 4, FitBaseType::Float32, "magnetometer_data.calibratedMagX")) 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->calibratedMagX) == 4, "src and dst not the same size");
361  memcpy(&this->calibratedMagX, &localEndian, data.size());
362  }
363  #else
364  this->calibratedMagX = static_cast<float>(bigEndian ? qFromBigEndian<float>(data) : qFromLittleEndian<float>(data));
365  #endif
366  break;
367  case 6: // See Profile.xlsx::Messages:magnetometer_data.calibratedMagY
368  if (!verify(data, baseType, 4, FitBaseType::Float32, "magnetometer_data.calibratedMagY")) 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->calibratedMagY) == 4, "src and dst not the same size");
374  memcpy(&this->calibratedMagY, &localEndian, data.size());
375  }
376  #else
377  this->calibratedMagY = static_cast<float>(bigEndian ? qFromBigEndian<float>(data) : qFromLittleEndian<float>(data));
378  #endif
379  break;
380  case 7: // See Profile.xlsx::Messages:magnetometer_data.calibratedMagZ
381  if (!verify(data, baseType, 4, FitBaseType::Float32, "magnetometer_data.calibratedMagZ")) 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->calibratedMagZ) == 4, "src and dst not the same size");
387  memcpy(&this->calibratedMagZ, &localEndian, data.size());
388  }
389  #else
390  this->calibratedMagZ = static_cast<float>(bigEndian ? qFromBigEndian<float>(data) : qFromLittleEndian<float>(data));
391  #endif
392  break;
393  default:
394  qWarning() << "ignoring unknown magnetometer_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.
float calibratedMagY
The MagnetometerDataMessage FIT message's calibratedMagY field.
DateTime timestamp
The MagnetometerDataMessage FIT message's timestamp field.
quint16 timestampMs
The MagnetometerDataMessage FIT message's timestampMs field.
quint16 magY
The MagnetometerDataMessage FIT message's magY field.
quint16 magX
The MagnetometerDataMessage FIT message's magX field.
quint16 magZ
The MagnetometerDataMessage FIT message's magZ field.
quint16 sampleTimeOffset
The MagnetometerDataMessage FIT message's sampleTimeOffset field.
float calibratedMagZ
The MagnetometerDataMessage FIT message's calibratedMagZ field.
float calibratedMagX
The MagnetometerDataMessage FIT message's calibratedMagX field.
bool setField(const int fieldId, const QByteArray &data, const FitBaseType baseType, const bool bigEndian) override
The MagnetometerDataMessage class represents a FIT MagnetometerDataMessage data message.
quint16 sampleTimeOffset() const
Returns the MagnetometerDataMessage data message's sampleTimeOffset field's current value.
quint16 magY() const
Returns the MagnetometerDataMessage data message's magY field's current value.
float calibratedMagY() const
Returns the MagnetometerDataMessage data message's calibratedMagY field's current value.
float calibratedMagZ() const
Returns the MagnetometerDataMessage data message's calibratedMagZ field's current value.
void setSampleTimeOffset(const quint16 sampleTimeOffset)
Sets the sampleTimeOffset field to sampleTimeOffset.
void setCalibratedMagZ(const float calibratedMagZ)
Sets the calibratedMagZ field to calibratedMagZ.
quint16 timestampMs() const
Returns the MagnetometerDataMessage data message's timestampMs field's current value.
void setTimestampMs(const quint16 timestampMs)
Sets the timestampMs field to timestampMs.
void setCalibratedMagX(const float calibratedMagX)
Sets the calibratedMagX field to calibratedMagX.
void setMagX(const quint16 magX)
Sets the magX field to magX.
float calibratedMagX() const
Returns the MagnetometerDataMessage data message's calibratedMagX field's current value.
MagnetometerDataMessage()
Constructs a MagnetometerDataMessage object.
void setMagZ(const quint16 magZ)
Sets the magZ field to magZ.
void setTimestamp(const DateTime timestamp)
Sets the timestamp field to timestamp.
void setMagY(const quint16 magY)
Sets the magY field to magY.
quint16 magX() const
Returns the MagnetometerDataMessage data message's magX field's current value.
quint16 magZ() const
Returns the MagnetometerDataMessage data message's magZ field's current value.
void setCalibratedMagY(const float calibratedMagY)
Sets the calibratedMagY field to calibratedMagY.
DateTime timestamp() const
Returns the MagnetometerDataMessage data message's timestamp field's current value.
Declares the MagnetometerDataMessage class.
Declares the MagnetometerDataMessagePrivate class.
FitBaseType
Garmin FIT FitBaseType type.
Definition: types.h:3388
DateTime
Seconds since UTC 00:00 Dec 31 1989.
Definition: types.h:237