Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 110 lines (89 sloc) 3.534 kb
42aa391 Removed deprecated code (append_to_xml); \n Added read_from_xml(); \n Ma...
Clovis Scotti authored
1 /*
2 * Copyright (c) 2011 Nokia Corporation
3 *
4 * This file is part of the Push Snowboarding Project, More info at:
5 * www.pushsnowboading.com
6 *
7 * Author: Clovis Scotti <scotti@ieee.org>
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 */
27
28 #include "npushacctick.h"
29
30 NPushAccTick::NPushAccTick(QAccelerometerReading * reading)
31 {
32 tick.copyValuesFrom(reading);
33
34 uint secs_to_epoch;
35 uint msecs;
36
37 secs_to_epoch = QDateTime::currentDateTime().toTime_t();
38 msecs = QTime::currentTime().msec();
39 uint aft = QDateTime::currentDateTime().toTime_t();
40
41 //ugly work around, will be fized with msecsToEpoc from Qt 4.7
42 if(aft != secs_to_epoch)//on a second slip
43 {
44 msecs = 0;
45 secs_to_epoch = aft;
46 }
47
48 msecsToEpoch = (double)secs_to_epoch*1000.0+(double)msecs;
49
50 pAccAbsMag = qSqrt(tick.x()*tick.x()+
51 tick.y()*tick.y()+
52 tick.z()*tick.z());
53 }
54
55 //Used to generate simulated ticks (tstamp comes directly from the xml file)
56 NPushAccTick::NPushAccTick(QAccelerometerReading * reading, quint64 a_msecsToEpoch)
57 {
58 tick.copyValuesFrom(reading);
59 msecsToEpoch = a_msecsToEpoch;
60
61 pAccAbsMag = qSqrt(tick.x()*tick.x()+
62 tick.y()*tick.y()+
63 tick.z()*tick.z());
64 }
65
66 NPushAccTick::~NPushAccTick()
67 {
68 }
69
70 void NPushAccTick::read_from_xml( QXmlStreamReader& xml)
71 {
72 // if(xml.attributes().hasAttribute("x"))
73 tick.setX(xml.attributes().value("x").toString().toFloat());
74
75 // if(xml.attributes().hasAttribute("y"))
76 tick.setY(xml.attributes().value("y").toString().toFloat());
77
78 // if(xml.attributes().hasAttribute("z"))
79 tick.setZ(xml.attributes().value("z").toString().toFloat());
80
81 pAccAbsMag = qSqrt(tick.x()*tick.x()+
82 tick.y()*tick.y()+
83 tick.z()*tick.z());
84
85 // if(xml.attributes().hasAttribute("tstamp"))
86 msecsToEpoch = (quint64)((double)xml.attributes().value("tstamp").toString().toDouble()*1000.0);
87 }
88
89 void NPushAccTick::dump_to_xml(QXmlStreamWriter& xml) const
90 {
91 xml.writeStartElement("acc_data");
92
93 xml.writeAttribute("tstamp", QString::number(((double)msecsToEpoch)/(double)1000.0, 'f', 3));
94
95 xml.writeAttribute("x", QString::number(tick.x()));
96 xml.writeAttribute("y", QString::number(tick.y()));
97 xml.writeAttribute("z", QString::number(tick.z()));
98 xml.writeAttribute("r", QString::number(pAccAbsMag));
99 xml.writeEndElement();//acc_data
100 }
101
102 QString NPushAccTick::get_pretty_print() const
103 {
104 return QString("P.Acc= %1;%2;%3")
105 .arg(QString::number(tick.x()))
106 .arg(QString::number(tick.y()))
107 .arg(QString::number(tick.z()));
108 }
109
Something went wrong with that request. Please try again.