summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRALOVICH, Kristof <tade60@freemail.hu>2014-03-02 11:19:27 +0100
committerRALOVICH, Kristof <tade60@freemail.hu>2014-03-02 11:19:27 +0100
commit17492b65ea3789bf4ac7ea65a596e5543e114d12 (patch)
tree11120672bbb0f9b5242c1d663521ac5e3c0e0bc9
parent435805b14559dbfbfa1a7e415e0fd7169d216d18 (diff)
parentd86fbcd7b8333972874670ab299b724f1995035a (diff)
Merge tag 'upstream/20140302'
-rw-r--r--README.rst21
-rw-r--r--scripts/archlinux/PKGBUILD25
-rw-r--r--scripts/debian/changelog76
-rw-r--r--scripts/debian/control40
-rw-r--r--scripts/debian/copyright34
-rwxr-xr-xscripts/debian/rules10
-rw-r--r--scripts/origsrc-file-list5
-rwxr-xr-xscripts/snaphot-deb51
-rw-r--r--src/AntChannel.cpp55
-rw-r--r--src/AntChannel.hpp2
-rw-r--r--src/AntFr310XT.cpp163
-rw-r--r--src/AntFr310XT.hpp3
-rw-r--r--src/AntMessage.cpp313
-rw-r--r--src/AntMessage.hpp276
-rw-r--r--src/AntMessenger.cpp74
-rw-r--r--src/AntMessenger.hpp1
-rw-r--r--src/CMakeLists.txt62
-rw-r--r--src/DeviceSettings.cpp9
-rw-r--r--src/FIT.cpp4
-rw-r--r--src/Log.hpp2
-rw-r--r--src/Serial.cpp102
-rw-r--r--src/Serial.hpp3
-rw-r--r--src/SerialTty.cpp11
-rw-r--r--src/SerialUsb.cpp410
-rw-r--r--src/VERSION2
-rw-r--r--src/antdefs.cpp107
-rw-r--r--src/antdefs.hpp3
-rw-r--r--src/antpm-downloader.cpp27
-rw-r--r--src/common.cpp96
-rw-r--r--src/common.hpp4
-rw-r--r--src/gant/antdefs.h4
-rw-r--r--src/gant/antlib.c12
-rw-r--r--src/gant/gant.c10
-rw-r--r--src/lqueue.hpp3
34 files changed, 1265 insertions, 755 deletions
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..c0c61c6
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,21 @@
+=========
+ANT+minus
+=========
+
+Userspace implementation of a wire protocol similar to the
+ANT/ANT+/ANT-FS protocols. The goal is to be able to communicate with
+the Forerunner 310XT (or any other ANT/ANT+/ANT-FS capable device)
+watch in order to retrieve sports tracks.
+
+The C++ implementation is currently available under both Linux and
+win. Communication with watches other than the 310XT might (610XT and
+910XT are likely) work, but are untested. This project currently does
+not yet support Forerunner 405, but work is underway for 405
+support. Please report your experience to help improving the software.
+
+.. image:: https://secure.travis-ci.org/ralovich/antpm.png
+ :alt: Build Status
+ :target: http://travis-ci.org/ralovich/antpm
+ :width: 77px
+ :height: 19px
+
diff --git a/scripts/archlinux/PKGBUILD b/scripts/archlinux/PKGBUILD
new file mode 100644
index 0000000..5a7599a
--- /dev/null
+++ b/scripts/archlinux/PKGBUILD
@@ -0,0 +1,25 @@
+# Maintainer: kusakata <shohei atmark kusakata period com>
+
+pkgname=antpm
+pkgver=1.15
+pkgrel=1
+pkgdesc='Userspace implementation of a wire protocol similar to the ANT/ANT+/ANT-FS protocols'
+arch=('i686' 'x86_64')
+url="http://code.google.com/p/antpm/"
+license=('GPL3')
+depends=('libxml2' 'boost-libs')
+makedepends=('boost' 'cmake')
+source=("http://antpm.googlecode.com/files/antpm_${pkgver}.orig.tar.gz")
+
+build() {
+ cd "${srcdir}/src"
+ cmake -D CMAKE_INSTALL_PREFIX=/usr -D USE_BOOST_STATIC_LINK=OFF .
+ make
+}
+
+package() {
+ cd "${srcdir}/src"
+ make DESTDIR="$pkgdir" install
+}
+
+md5sums=('8482a4f846d3647ad408588bd940e0ab')
diff --git a/scripts/debian/changelog b/scripts/debian/changelog
index e8162f1..47ec07b 100644
--- a/scripts/debian/changelog
+++ b/scripts/debian/changelog
@@ -1,3 +1,79 @@
+antpm (1.16-1) experimental; urgency=low
+
+ * open for new development
+ * ant: try logging MESG_STARTUP_MSG_ID
+ * more verbose debug
+ * more verbose debug
+ * SerialUsb.cpp: more VID/PID pairs to be recognised
+ * Serial: implement central factory method
+ * use central factory to create serial interface
+ * tell apart 32/64 bit linux
+ * scripts: create snapshot .deb package
+ * output formatting fixes
+ * decode: MESG_STARTUP_MSG_ID
+ * SerialUsb: print only on error path
+ * remove stale comment
+ * do skip already downloaded files
+ * let us not consider EVENT_TRANSFER_TX_START events
+ * log sent messages too
+ * create antpm-dbg package too
+ * Log: make sure current log level threshold is logged
+ * fix comments
+ * usb: win and linux have different errno values
+ * ANT_CloseChannel: accept more responses are success
+ * catch spurious wakeups of condition variables
+ * infrastructure to interrupt waiting message listeners
+ * extra statement
+ * disable device guessing
+ * give up restarting sooner
+ * Quit quicker.
+ * SerialUsb: reduce verbosity
+ * AntChannel: bugfix
+ * build packages with RelWithDebInfo
+ * cmake: default to Debug build
+ * move method from header to .cpp
+ * fix warning about unused variable
+ * move methods from header to .cpp
+ * add comment
+ * log the dtors
+ * include timstamp in version string
+ * FIT: omit extra printing
+ * debug macros
+ * reduce chattiness in release
+ * make ANTFS_Disconnect not wait for reply
+ * SerialUsb: overhaul
+ * reduce chattiness in release
+ * reduce chattiness in release
+ * reduce chattiness in release
+ * move messy definitions
+ * AntMessage::str2(): decode MESG_STARTUP_MSG_ID
+ * log when state machine destructs
+ * AntFr310XT: stop() is not thread safe, or reentrant
+ * state machine for GarminIntf
+ * provide some end user messages
+ * fold in the GarminIntf states
+ * cmake: inherit compiler flags
+ * check return value of strerror_r
+ * Serial: list linux kernel modules
+ * downloader: more debugging info
+ * UNUSED() macro
+ * gant: fix a bunch of warnings
+ * SerialUsb: bugfix, what a typo
+ * fix warnings about unused variables
+ * use gnu variant of strerror_r
+ * serial: unify unblocking readBlocking()
+ * serial: more info to help remote debugging
+ * add readme file
+ * usb: remove GPLv2 code
+ * update copyright info
+ * serial: try to actually open a device under win too
+ * scripts: arch build file
+ * make lintian happier
+ * tar README.rst too
+ * make lintian happier 2
+
+ -- RALOVICH, Kristof <tade60@freemail.hu> Sun, 02 Mar 2014 10:42:06 +0100
+
antpm (1.15-1) experimental; urgency=low
* open for new development
diff --git a/scripts/debian/control b/scripts/debian/control
index 3d6081a..24929a7 100644
--- a/scripts/debian/control
+++ b/scripts/debian/control
@@ -2,7 +2,7 @@ Source: antpm
Maintainer: Kristof Ralovich <tade60@freemail.hu>
Section: misc
Priority: optional
-Standards-Version: 3.9.2
+Standards-Version: 3.9.4
Build-Depends: debhelper (>= 8), devscripts (>= 2.10), g++ (>= 4.4) | clang (>= 3.0), libboost-dev (>= 1.41) | libboost1.41-dev, cmake (>= 2.8), libusb-dev, libxml2-dev, pkg-config (>= 0.25), libboost-thread-dev,libboost-filesystem-dev,libboost-system-dev,libboost-date-time-dev,libboost-program-options-dev,libboost-test-dev
Homepage: https://code.google.com/p/antpm/
Vcs-Git: https://code.google.com/p/antpm/
@@ -10,10 +10,36 @@ Vcs-Browser: https://code.google.com/p/antpm/source/browse/
Package: antpm
Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, libstdc++6 (>=4.4.0)
+Depends:
+ ${shlibs:Depends},
+ ${misc:Depends},
+ libstdc++6 (>=4.4.0),
Description: ANT+minus implements the ANT/ANT+/ANT-FS protocols and provides tools.
- Userspace implementation of a wire protocol similar to the ANT/ANT+/ANT-FS protocols. The
- goal is to be able to communicate with the Forerunner 310XT watch in order to retrieve
- sports tracks. The c++ implementation is currently available under both linux and win.
- Communication with watches other than the 310XT might work, but are untested. Please report
- your experience to help improving the software.
+ Userspace implementation of a wire protocol similar to the
+ ANT/ANT+/ANT-FS protocols. The goal is to be able to communicate with
+ the Forerunner 310XT (or any other ANT/ANT+/ANT-FS capable device)
+ watch in order to retrieve sports tracks.
+ The C++ implementation is currently available under both Linux and
+ win. Communication with watches other than the 310XT might (610XT and
+ 910XT are likely) work, but are untested. This project currently does
+ not yet support Forerunner 405, but work is underway for 405
+ support. Please report your experience to help improving the software.
+
+Package: antpm-dbg
+Section: debug
+Priority: extra
+Architecture: any
+Depends:
+ antpm (= ${binary:Version}),
+ ${misc:Depends},
+Description: ANT+minus implements the ANT/ANT+/ANT-FS protocols and provides tools.
+ Userspace implementation of a wire protocol similar to the
+ ANT/ANT+/ANT-FS protocols. The goal is to be able to communicate with
+ the Forerunner 310XT (or any other ANT/ANT+/ANT-FS capable device)
+ watch in order to retrieve sports tracks.
+ The C++ implementation is currently available under both Linux and
+ win. Communication with watches other than the 310XT might (610XT and
+ 910XT are likely) work, but are untested. This project currently does
+ not yet support Forerunner 405, but work is underway for 405
+ support. Please report your experience to help improving the software.
+ This package provides debugging symbols for the antpm package.
diff --git a/scripts/debian/copyright b/scripts/debian/copyright
index 42b7d3f..d098a9f 100644
--- a/scripts/debian/copyright
+++ b/scripts/debian/copyright
@@ -14,9 +14,10 @@ Software copyright information:
© 2010 Klaus@Ethgen.de. released under GPLv3
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 3 dated June, 2007.
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,10 +25,33 @@ Software copyright information:
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- MA 02110-1301, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in `/usr/share/common-licenses/GPL-3'.
+
+w_inttypes.h, w_stdint.h Copyright (c) 2006-2008 Alexander Chemeris
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. The name of the author may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/scripts/debian/rules b/scripts/debian/rules
index 613752d..9b39eb5 100755
--- a/scripts/debian/rules
+++ b/scripts/debian/rules
@@ -21,11 +21,19 @@ override_dh_auto_configure:
# echo -e "\n\n\nCMAKE\n\n\n"
# echo $(NUMCPUS)
mkdir cmake-build
- cd cmake-build && cmake ../src -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} $(CFLAGS)" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} $(CXXFLAGS)"
+ cd cmake-build && cmake ../src -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} $(CFLAGS)" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} $(CXXFLAGS)"
override_dh_auto_build:
cd cmake-build && $(MAKE) -j$(NUMCPUS)
+override_dh_strip:
+ #dh_strip -pantpm-downloader --dbg-package=antpm-dbg
+ #dh_strip -pantpm-fit2gpx --dbg-package=antpm-dbg
+ #dh_strip -pantpm-usbmon2ant --dbg-package=antpm-dbg
+ #dh_strip -pgant --dbg-package=antpm-dbg
+ dh_strip --dbg-package=antpm-dbg
+ dh_strip -s --remaining-packages
+
DESTDIR=../debian/antpm/
override_dh_install:
cd cmake-build && $(MAKE) install DESTDIR=$(DESTDIR)
diff --git a/scripts/origsrc-file-list b/scripts/origsrc-file-list
index e5fa538..27e2bb8 100644
--- a/scripts/origsrc-file-list
+++ b/scripts/origsrc-file-list
@@ -50,8 +50,8 @@ src/AntFr310XT.hpp
src/AntFr310XT.cpp
src/AntFr405.hpp
src/AntFr405.cpp
-src/common.cpp
src/antdefs.hpp
+src/antdefs.cpp
src/SerialUsb.hpp
src/SerialUsb.cpp
src/GarminConvert.cpp
@@ -66,7 +66,9 @@ src/FIT.cpp
src/GPX.hpp
src/SmartPtrFwd.hpp
src/Serial.hpp
+src/Serial.cpp
src/common.hpp
+src/common.cpp
src/AntMessenger.cpp
src/DeviceSettings.hpp
src/DeviceSettings.cpp
@@ -81,3 +83,4 @@ src/gant/GantMonitor.py
src/gant/resources/gant.png
LICENSE
gpl-3.0.txt
+README.rst \ No newline at end of file
diff --git a/scripts/snaphot-deb b/scripts/snaphot-deb
new file mode 100755
index 0000000..d4ee6ee
--- /dev/null
+++ b/scripts/snaphot-deb
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+
+VER=`cat src/VERSION | head -n 1`
+
+echo 'VER='$VER
+
+(
+ cp -r scripts/debian .
+
+cp debian/changelog.2 debian/changelog.3
+cp debian/changelog.1 debian/changelog.2
+cp debian/changelog debian/changelog.1
+#git-dch --git-author -vaN $VER-$DEB_VER_MINOR --distribution=experimental --debian-tag=experimental/%\(version\)s
+git-dch --git-author -vaSN $VER --distribution=experimental --debian-tag=experimental/%\(version\)s
+
+ cp debian/changelog* scripts/debian
+ rm -rv ./debian
+)
+
+
+
+
+CHGLOG_VER=`head -1 scripts/debian/changelog | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }'`
+OUTNAME=antpm_${CHGLOG_VER}.orig.tar
+#OUTNAME=antpm_${VER}.orig.tar
+
+
+rm -fv ${OUTNAME}.gz
+tar -czvf ${OUTNAME}.gz -T scripts/origsrc-file-list
+#tar --xz -cf ${OUTNAME}.xz -T scripts/origsrc-file-list
+
+echo 'OK: ' ${OUTNAME}.gz
+
+
+ROOT=`mktemp -d --tmp=.`
+eval ROOT=$ROOT
+
+echo $ROOT
+echo
+mv ${OUTNAME}.gz $ROOT/
+
+( cd $ROOT;
+ mkdir build;
+ cd build
+ tar -xzf ../${OUTNAME}.gz
+ mv scripts/debian .
+ echo -e "\nStarting to build...\n"
+ debuild -us -uc && echo -e "\nBuild OK\ndeb package in '${ROOT}' \n";
+)
+
diff --git a/src/AntChannel.cpp b/src/AntChannel.cpp
index bca5033..5bd5b2a 100644
--- a/src/AntChannel.cpp
+++ b/src/AntChannel.cpp
@@ -48,6 +48,16 @@ AntChannel::onMsg(AntMessage &m)
}
}
+void
+AntChannel::interruptWait()
+{
+ boost::unique_lock<boost::mutex> lock(m_mtxListeners);
+ for(std::list<AntListenerBase*>::iterator i = listeners.begin(); i != listeners.end(); i++)
+ {
+ (*i)->interruptWait();
+ }
+}
+
@@ -78,24 +88,38 @@ AntListenerBase::onMsg(AntMessage& m)
}
}
+void
+AntListenerBase::interruptWait()
+{
+ boost::unique_lock<boost::mutex> lock(m_mtxResp);
+ m_msgResp.reset();
+ m_cndResp.notify_all(); // intentionally generate a "spurious" wakeup
+}
+
bool
AntListenerBase::waitForMsg(AntMessage* m, const size_t timeout_ms)
{
boost::unique_lock<boost::mutex> lock(m_mtxResp);
- if(m_msgResp)
+ if(m_msgResp) // it had already arrived
{
- if(m) *m = *m_msgResp; // it had already arrived
+ if(m) *m = *m_msgResp;
m_msgResp.reset();
return true;
}
if(!m_cndResp.timed_wait(lock, boost::posix_time::milliseconds(timeout_ms)))
{
+ // false means, timeout was reached
return false;
}
- assert(m_msgResp);
- if(m) *m=*m_msgResp;//copy
- m_msgResp.reset();
- return true;
+ // true means, either notification OR spurious wakeup!!
+ //assert(m_msgResp); // this might fail for spurious wakeups!!
+ if(m_msgResp)
+ {
+ if(m) *m=*m_msgResp;//copy
+ m_msgResp.reset();
+ return true;
+ }
+ return false;
}
@@ -110,7 +134,8 @@ AntEvListener::match(AntMessage& other) const
{
return other.getMsgId()==MESG_RESPONSE_EVENT_ID
&& owner.chan == other.getPayloadRef()[0]
- && other.getPayloadRef()[1]==MESG_EVENT_ID;
+ && other.getPayloadRef()[1]==MESG_EVENT_ID
+ && other.getPayloadRef()[2]!=EVENT_TRANSFER_TX_START; // let us not consider EVENT_TRANSFER_TX_START events
}
// whether there was a response before timeout
bool
@@ -231,10 +256,18 @@ AntBurstListener::waitForBursts(std::list<AntMessage>& bs, const size_t timeout_
}
// TODO: handle arrival of event:EVENT_RX_FAIL
if(!m_cndResp.timed_wait(lock, boost::posix_time::milliseconds(timeout_ms)))
+ {
+ // // false means, timeout was reached
return false;
- assert(!bursts.empty());
- std::swap(bs, bursts);
- return true;
+ }
+ // true means, either notification OR spurious wakeup!!
+ //assert(!bursts.empty()); // this might fail for spurious wakeups!!
+ if(!bursts.empty())
+ {
+ std::swap(bs, bursts);
+ return true;
+ }
+ return false;
}
@@ -298,7 +331,7 @@ AntBurstListener::collectBurst(std::vector<uint8_t>& burstData, const size_t tim
lprintf(LOG_ERR, "couldn't reconstruct burst data transmission before timeout\n"); fflush(stdout);
return false;
}
- lprintf(LOG_INF, "collectBurst: %d bytes\n", int(burstData.size()));
+ lprintf(LOG_DBG, "collectBurst: %d bytes\n", int(burstData.size()));
return true;
}
diff --git a/src/AntChannel.hpp b/src/AntChannel.hpp
index 0549267..3165793 100644
--- a/src/AntChannel.hpp
+++ b/src/AntChannel.hpp
@@ -38,6 +38,7 @@ public:
AntListenerBase(AntChannel& o);
virtual ~AntListenerBase();
virtual void onMsg(AntMessage& m);
+ virtual void interruptWait();
protected:
virtual bool match(AntMessage& other) const = 0;
public:
@@ -55,6 +56,7 @@ public:
void addMsgListener2(AntListenerBase* lb);
void rmMsgListener2(AntListenerBase* lb);
void onMsg(AntMessage &m);
+ void interruptWait();
};
diff --git a/src/AntFr310XT.cpp b/src/AntFr310XT.cpp
index ceb7605..566f224 100644
--- a/src/AntFr310XT.cpp
+++ b/src/AntFr310XT.cpp
@@ -77,8 +77,12 @@ struct AntFr310XT_EventLoop
};
AntFr310XT::AntFr310XT(bool eventLoopInBgTh)
- : m_serial(new ANTPM_SERIAL_IMPL())
+ //: m_serial(new ANTPM_SERIAL_IMPL())
+ : m_serial(Serial::instantiate())
, m_antMessenger(new AntMessenger(eventLoopInBgTh))
+ , state(ST_ANTFS_0)
+ , m_eventThKill(0)
+ , m_restartCount(0)
, aplc(getConfigFolder()+std::string("antparse_")+getDateString()+".txt")
, clientSN(0)
, pairedKey(0)
@@ -86,10 +90,9 @@ AntFr310XT::AntFr310XT(bool eventLoopInBgTh)
, doPairing(false)
, mode(MD_DOWNLOAD_ALL)
{
+ if(!m_serial) return;
m_antMessenger->setHandler(m_serial.get());
m_antMessenger->setCallback(this);
- state = ST_ANTFS_0;
- m_eventThKill=0;
AntFr310XT_EventLoop eventTh;
eventTh.rv=0;
@@ -100,7 +103,7 @@ AntFr310XT::AntFr310XT(bool eventLoopInBgTh)
AntFr310XT::~AntFr310XT()
{
- m_antMessenger->setCallback(0);
+ if(m_antMessenger) m_antMessenger->setCallback(0);
//m_antMessenger->setHandler(0);
m_eventThKill=1;
@@ -109,7 +112,7 @@ AntFr310XT::~AntFr310XT()
m_antMessenger.reset();
m_serial.reset();
- lprintf(LOG_DBG, "%s\n", __FUNCTION__);
+ lprintf(LOG_DBG2, "%s\n", __FUNCTION__);
}
@@ -161,6 +164,7 @@ AntFr310XT::onAntReceived(const AntMessage m)
void
AntFr310XT::onAntSent(const AntMessage m)
{
+ lprintf(antpm::LOG_DBG3, "%s\n", m.str().c_str());
}
@@ -168,7 +172,8 @@ AntFr310XT::onAntSent(const AntMessage m)
void
AntFr310XT::start()
{
- CHECK_RETURN(m_serial->open());
+ CHECK_RETURN(m_serial);
+ CHECK_RETURN(m_serial->isOpen());
//createDownloadFolder();
@@ -185,24 +190,34 @@ AntFr310XT::start()
void AntFr310XT::stop()
{
m_eventThKill = 1;
+ // stop() might be called from the event thread
+ // terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >'
+ // what(): boost thread: trying joining itself: Resource deadlock avoided
//m_eventTh.join();
m_antMessenger->kill();
- if(m_serial->isOpen())
+ if(m_serial && m_serial->isOpen())
{
if(state>ST_ANTFS_LINKING)
m_antMessenger->ANTFS_Disconnect(chan);
m_antMessenger->ANT_CloseChannel(chan);
m_antMessenger->ANT_ResetSystem();
}
- m_serial->close();
+ if(m_antMessenger) m_antMessenger->setCallback(0);
+ //m_antMessenger->setHandler(0);
+ m_antMessenger.reset();
+ if(m_serial) m_serial->close();
changeState(ST_ANTFS_START0, true);
}
-void AntFr310XT::stopAsync()
+
+void
+AntFr310XT::stopAsync()
{
+ LOG(LOG_WARN) << "stopAsync called!\n\n";
// FIXME: setting ST_ANTFS_LAST might not be enough for stopping immediately,
// as other thread might be
// sleeping in a listener, and we stop only when that returns.
+ if(m_antMessenger) m_antMessenger->interruptWait(); // FIXME locking needed to access m_antMessenger!!!
changeState(ST_ANTFS_LAST);
}
@@ -296,17 +311,37 @@ AntFr310XT::handleEvents()
changeState(ST_ANTFS_BAD);
}
}
+// else if(msgId==MESG_CLOSE_CHANNEL_ID)
+// {
+// uint8_t msgCode = m.getPayloadRef()[2]; // e.g. CHANNEL_IN_WRONG_STATE
+// if(msgCode==CHANNEL_IN_WRONG_STATE)
+// {
+// changeState(ST_ANTFS_BAD);
+// }
+// }
}
}
// new state machine
if(state==ST_ANTFS_RESTART)
{
- m_evQue.clear();
- //m_antMessenger->clearRxQueue();
- m_antMessenger->ANT_ResetSystem();
- m_antMessenger->ANT_ResetSystem();
- changeStateSafe(ST_ANTFS_START0);
+ if(++m_restartCount==10)
+ {
+ LOG(LOG_RAW) << "\n\nTried " << m_restartCount << " times, and couldn't communicate with ANT device!\n"
+ << "Please try again running the downloader.\n"
+ << "Sometimes re-plugging the USB ANT stick, and rarely power cycling (turn-off, turn-on)\n"
+ << "the ANT device (watch/GPS) might help.\n\n\n";
+ stop();
+ return true;
+ }
+ else
+ {
+ m_evQue.clear();
+ //m_antMessenger->clearRxQueue();
+ m_antMessenger->ANT_ResetSystem();
+ m_antMessenger->ANT_ResetSystem();
+ changeStateSafe(ST_ANTFS_START0);
+ }
}
if(state==ST_ANTFS_START0)
{
@@ -333,7 +368,12 @@ AntFr310XT::handleEvents()
{
AntMessage m;
//CHECK_RETURN_FALSE(m_antMessenger->waitForBroadcastDataAvail(chan, &m, 20000));//link beacon
- CHECK_RETURN_FALSE(m_antMessenger->waitForBroadcast(chan, &m, 20000));//link beacon
+ if(!m_antMessenger->waitForBroadcast(chan, &m, 20000)) //link beacon
+ {
+ LOG(LOG_RAW) << "\n\nNo device available for linking!\n\n\n";
+ return false;
+ }
+
M_ANTFS_Beacon* beacon(reinterpret_cast<M_ANTFS_Beacon*>(&m.getPayloadRef()[1]));
// TODO:handle case of no available data
if(!beacon->dataAvail)
@@ -349,13 +389,13 @@ AntFr310XT::handleEvents()
uchar transType=0;
CHECK_RETURN_FALSE(m_antMessenger->ANT_GetChannelId(chan, &devNum, &devId, &transType, 1000));
LOG(LOG_RAW) << "\n\nFound device devNum=0x" << toString<ushort>(devNum) << " devId=0x" << toString<uint>(devId,2,'0') << " transType=0x" << toString<uint>(transType,2,'0') << "\n\n\n";
- GarminProducts prod;
- if(guessDeviceType(devNum, devId, transType, &prod))
- {
- if(prod==GarminFR310XT) { LOG(LOG_INF) << "guessed: GarminFR310XT\n\n\n"; }
- if(prod==GarminFR405) { LOG(LOG_INF) << "guessed: GarminFR405\n\n\n"; }
- }
- else { LOG(LOG_WARN) << "guessing failed!\n"; }
+ //GarminProducts prod;
+ //if(guessDeviceType(devNum, devId, transType, &prod))
+ //{
+ // if(prod==GarminFR310XT) { LOG(LOG_INF) << "guessed: GarminFR310XT\n\n\n"; }
+ // if(prod==GarminFR405) { LOG(LOG_INF) << "guessed: GarminFR405\n\n\n"; }
+ //}
+ //else { LOG(LOG_WARN) << "guessing failed!\n"; }
CHECK_RETURN_FALSE(m_antMessenger->ANTFS_Link(chan, fsFreq, beaconPer, hostSN));
@@ -367,7 +407,6 @@ AntFr310XT::handleEvents()
m_antMessenger->ANT_CloseChannel(chan);
sleepms(800);
changeStateSafe(ST_ANTFS_RESTART);
- return true;
}
else if(state == ST_ANTFS_AUTH0_SN)
{
@@ -382,13 +421,14 @@ AntFr310XT::handleEvents()
//CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->waitForBroadcast(chan));
- CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANTFS_RequestClientDeviceSerialNumber(chan, hostSN, clientSN, clientDevName));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(m_antMessenger->ANTFS_RequestClientDeviceSerialNumber(chan, hostSN, clientSN, clientDevName));
LOG(LOG_RAW) << "\n\nFound client \"" << clientDevName << "\" SN=0x" << toString<uint>(clientSN,8,'0') << " SN=" << clientSN << "\n\n\n";
m_ds.reset(new DeviceSettings(toStringDec<uint>(clientSN).c_str()));
assert(m_ds.get());
m_ds->loadDefaultValues();
+ LOG_VAR(m_ds->getConfigFileName());
m_ds->loadFromFile(m_ds->getConfigFileName());
m_ds->saveToFile(m_ds->getConfigFileName());
m_serial->setWriteDelay(m_ds->SerialWriteDelayMs);
@@ -412,19 +452,14 @@ AntFr310XT::handleEvents()
}
writeUInt64(clientSN, pairedKey);
- CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(m_antMessenger->ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
//changeStateSafe(ST_ANTFS_LAST);
changeStateSafe(ST_ANTFS_AUTH1_PASS);
}
- else if(state == ST_ANTFS_AUTH1_PAIR)
- {
- //FIXME:
- //m_antMessenger->ANTFS_Pairing(chan, hostSN, );
- }
else if(state == ST_ANTFS_AUTH1_PASS)
{
- CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(m_antMessenger->ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
if(!m_antMessenger->ANTFS_Authenticate(chan, hostSN, pairedKey))
{
@@ -435,9 +470,11 @@ AntFr310XT::handleEvents()
LOG(LOG_RAW) << "\n\nClient authenticated successfully!\n\n\n";
// channel status <>
- CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(m_antMessenger->ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
- if(mode==MD_DOWNLOAD_ALL || mode==MD_DIRECTORY_LISTING)
+ if(clientDevName=="Forerunner 405")
+ changeStateSafe(ST_ANTFS_GINTF_DL_CAPS);
+ else if(mode==MD_DOWNLOAD_ALL || mode==MD_DIRECTORY_LISTING)
changeStateSafe(ST_ANTFS_DL_DIRECTORY);
else if(mode==MD_DOWNLOAD_SINGLE_FILE)
changeStateSafe(ST_ANTFS_DL_SINGLE_FILE);
@@ -492,17 +529,20 @@ AntFr310XT::handleEvents()
for(size_t i=0; i<zfc.waypointsFiles.size() && fileCnt<m_ds->MaxFileDownloads; i++)
{
checkForExit();
- LOG_VAR3(fileCnt, m_ds->MaxFileDownloads, zfc.waypointsFiles.size());
+ //LOG_VAR3(fileCnt, m_ds->MaxFileDownloads, zfc.waypointsFiles.size());
ushort fileIdx = zfc.waypointsFiles[i];
time_t t = GarminConvert::gOffsetTime(zfc.getFitFileTime(fileIdx));
- if(t < m_ds->LastUserProfileTime)
+ //LOG_VAR2(DeviceSettings::time2str(t), DeviceSettings::time2str(zfc.getFitFileTime(fileIdx)));
+ if(t < m_ds->LastTransferredTime)
{
logger() << "Skipping waypoints file 0x" << toString<ushort>(fileIdx,4,'0')
<< "@" << DeviceSettings::time2str(t) << " older than "
- << DeviceSettings::time2str(m_ds->LastUserProfileTime) << "\n";
+ << DeviceSettings::time2str(m_ds->LastTransferredTime) << "\n";
continue;
}
- logger() << "Transfer waypoints file 0x" << hex << fileIdx << "\n";
+ logger() << "Transfer waypoints file 0x" << toString<ushort>(fileIdx,4,'0')
+ << "@" << DeviceSettings::time2str(t) << " newer than "
+ << DeviceSettings::time2str(m_ds->LastTransferredTime) << "\n";
std::vector<uchar> data;
if(!m_antMessenger->ANTFS_Download(chan, fileIdx, data))
@@ -512,7 +552,7 @@ AntFr310XT::handleEvents()
}
LOG(LOG_RAW) << "\n\nDownloaded file idx=" << toString<ushort>(fileIdx,4,'0') << "\n\n\n";
AntFsFile file0; file0.bytes=data; file0.saveToFile((folder+toString(fileIdx, 4, '0')+".fit").c_str());
- LOG_VAR(file0.checkCrc());
+ //LOG_VAR(file0.checkCrc());
fit.parse(data, gpx);
@@ -527,17 +567,20 @@ AntFr310XT::handleEvents()
for (size_t i=0; i<zfc.activityFiles.size() && fileCnt<m_ds->MaxFileDownloads; i++)
{
checkForExit();
- LOG_VAR3(fileCnt, m_ds->MaxFileDownloads, zfc.activityFiles.size());
+ //LOG_VAR3(fileCnt, m_ds->MaxFileDownloads, zfc.activityFiles.size());
ushort fileIdx = zfc.activityFiles[i];
time_t t = GarminConvert::gOffsetTime(zfc.getFitFileTime(fileIdx));
- if(t < m_ds->LastUserProfileTime)
+ //LOG_VAR2(DeviceSettings::time2str(t), DeviceSettings::time2str(zfc.getFitFileTime(fileIdx)));
+ if(t < m_ds->LastTransferredTime)
{
logger() << "Skipping activity file 0x" << toString<ushort>(fileIdx,4,'0')
<< "@" << DeviceSettings::time2str(t) << " older than "
- << DeviceSettings::time2str(m_ds->LastUserProfileTime) << "\n";
+ << DeviceSettings::time2str(m_ds->LastTransferredTime) << "\n";
continue;
}
- logger() << "# Transfer activity file 0x" << hex << fileIdx << "\n";
+ logger() << "# Transfer activity file 0x" << toString<ushort>(fileIdx,4,'0')
+ << "@" << DeviceSettings::time2str(t) << " newer than "
+ << DeviceSettings::time2str(m_ds->LastTransferredTime) << "\n";
std::vector<uchar> data;
if(!m_antMessenger->ANTFS_Download(chan, fileIdx, data))
@@ -553,13 +596,13 @@ AntFr310XT::handleEvents()
time_t fitDate=0;
if(!FIT::getCreationDate(data, fitDate))
{
- LOG_VAR3(fitDate, t, m_ds->LastUserProfileTime);
+ //LOG_VAR3(fitDate, t, m_ds->LastUserProfileTime);
fitDate = t;
}
else
{
fitDate = GarminConvert::gOffsetTime(fitDate);
- LOG_VAR3(DeviceSettings::time2str(fitDate), DeviceSettings::time2str(t), DeviceSettings::time2str(m_ds->LastUserProfileTime));
+ //LOG_VAR3(DeviceSettings::time2str(fitDate), DeviceSettings::time2str(t), DeviceSettings::time2str(m_ds->LastUserProfileTime));
}
//m_ds->mergeLastUserProfileTime(fitDate); // can't update it in the middle of the loop
@@ -569,17 +612,20 @@ AntFr310XT::handleEvents()
for (size_t i=0; i<zfc.courseFiles.size() && fileCnt<m_ds->MaxFileDownloads; i++)
{
checkForExit();
- LOG_VAR3(fileCnt, m_ds->MaxFileDownloads, zfc.courseFiles.size());
+ //LOG_VAR3(fileCnt, m_ds->MaxFileDownloads, zfc.courseFiles.size());
ushort fileIdx = zfc.courseFiles[i];
time_t t = GarminConvert::gOffsetTime(zfc.getFitFileTime(fileIdx));
- if(t < m_ds->LastUserProfileTime)
+ //LOG_VAR2(DeviceSettings::time2str(t), DeviceSettings::time2str(zfc.getFitFileTime(fileIdx)));
+ if(t < m_ds->LastTransferredTime)
{
logger() << "Skipping course file 0x" << toString<ushort>(fileIdx,4,'0')
<< "@" << DeviceSettings::time2str(t) << " older than "
- << DeviceSettings::time2str(m_ds->LastUserProfileTime) << "\n";
+ << DeviceSettings::time2str(m_ds->LastTransferredTime) << "\n";
continue;
}
- logger() << "Transfer course file 0x" << hex << fileIdx << "\n";
+ logger() << "Transfer course file 0x" << toString<ushort>(fileIdx,4,'0')
+ << "@" << DeviceSettings::time2str(t) << " older than "
+ << DeviceSettings::time2str(m_ds->LastTransferredTime) << "\n";
std::vector<uchar> data;
if(!m_antMessenger->ANTFS_Download(chan, fileIdx, data))
@@ -640,6 +686,27 @@ AntFr310XT::handleEvents()
changeStateSafe(ST_ANTFS_LAST);
}
+ else if(state==ST_ANTFS_GINTF_DL_CAPS)
+ {
+ // when authentication succeeds, State=Transport beacon arrives
+ //R 96.026 MESG_BROADCAST_DATA_ID chan=0x00 ANTFS_BEACON(0x43) Beacon=1Hz, pairing=disabled, upload=disabled, dataAvail=no, State=Transport, Auth=PasskeyAndPairingOnly
+ //R 124.999 MESG_BROADCAST_DATA_ID chan=0x00 ANTFS_BEACON(0x43) Beacon=1Hz, pairing=disabled, upload=disabled, dataAvail=no, State=Transport, Auth=PasskeyAndPairingOnly
+ //S 114.743 MESG_REQUEST_ID chan=0x00 reqMsgId=MESG_CHANNEL_STATUS_ID
+ //R 3.247 MESG_CHANNEL_STATUS_ID chan=00 chanSt=Tracking
+ //S 12.451 MESG_BURST_DATA_ID chan=0x00, seq=0, last=no ANTFS_CMD(0x44) ANTFS_CmdDirect fd=0xffff, offset=0x0000, data=0x0000
+ //R 1.546 MESG_BROADCAST_DATA_ID chan=0x00 ANTFS_BEACON(0x43) Beacon=1Hz, pairing=disabled, upload=disabled, dataAvail=no, State=Transport, Auth=PasskeyAndPairingOnly
+ //S 2.477 MESG_BURST_DATA_ID chan=0x00, seq=1, last=yes fe00000000000000 ........
+
+ CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANTFS_Direct(chan, SwapDWord(0xfe00000000000000)));
+
+ CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANTFS_Direct(chan, SwapDWord(0x06000200ff000000)));
+
+ // 06000200f8000000
+ CHECK_RETURN_FALSE_LOG_OK(m_antMessenger->ANTFS_Direct(chan, SwapDWord(0x06000200f8000000)));
+
+ // just exit
+ changeStateSafe(ST_ANTFS_LAST);
+ }
else if(state==ST_ANTFS_NODATA)
{
changeStateSafe(ST_ANTFS_LAST);
diff --git a/src/AntFr310XT.hpp b/src/AntFr310XT.hpp
index 3fb0b2c..308d3e6 100644
--- a/src/AntFr310XT.hpp
+++ b/src/AntFr310XT.hpp
@@ -47,7 +47,9 @@ public:
virtual void onAntSent(const AntMessage m);
void start();
+protected:
void stop();
+public:
void stopAsync();
const int getSMState() const;
@@ -64,6 +66,7 @@ protected:
int state;
boost::mutex stateMtx;
volatile int m_eventThKill;
+ int m_restartCount;
boost::thread m_eventTh;
lqueue4<AntMessage> m_evQue;
AntParsedLoggerCallback aplc;
diff --git a/src/AntMessage.cpp b/src/AntMessage.cpp
index 8cbeea7..863948f 100644
--- a/src/AntMessage.cpp
+++ b/src/AntMessage.cpp
@@ -38,6 +38,7 @@ using namespace std;
namespace antpm{
+
std::string
antFSCommand2Str(uchar cmd)
{
@@ -109,6 +110,15 @@ isAntFSCommandOrResponse(const uchar command, bool& isCommand)
}
+const string M_ANT_Channel_Id::toString() const
+{
+ std::stringstream sstr;
+ sstr
+ << " chan=0x" << antpm::toString<int>(chan,2,'0') << ", devNum=0x" << antpm::toString<int>(devNum,4,'0')
+ << ", devId=0x" << antpm::toString<int>(devId,2,'0') << ", transType=0x" << antpm::toString<int>(transType,2,'0');
+ return sstr.str();
+}
+
bool AntMessage::vrfChkSum() const
{
@@ -284,6 +294,7 @@ AntMessage::str2() const
vector<uchar> payl=getPayload();
const uchar* p=getPayloadRef();
assert(payl[i]==p[i]);
+ UNUSED(p);
}
const M_ANT_Burst* burst(reinterpret_cast<const M_ANT_Burst*>(getPayloadRef()));
//sstr << " chan=0x" << toString<int>(burst->chan,2,'0') << ", seq=" << toStringDec<int>(burst->seq,1,' ') << ", last=" << (burst->last?"yes":"no ");
@@ -317,6 +328,40 @@ AntMessage::str2() const
} } CHST;
sstr << " " << CHST.szChanSt(chanSt);
}
+ else if(getMsgId()==MESG_STARTUP_MSG_ID)
+ {
+ enum {
+ PowerOnReset = 0,
+ HwResetLine = 1,
+ UnkReset1 = 2,
+ UnkReset2 = 4,
+ UnkReset3 = 8,
+ UnkReset4 = 16,
+ CommandReset = 32,
+ SyncReset = 64,
+ SuspendReset = 128
+ };
+ if(getLenPayload()>=1)
+ {
+ uint8_t startup=getPayloadRef()[0];
+ //lprintf(antpm::LOG_DBG2, "startup 0x%02x\n", startup);
+ sstr << " startup=";
+ if(startup==0) sstr << "PowerOnReset,";
+ if(startup & HwResetLine) sstr << "HwResetLine,";
+ if(startup & UnkReset1) sstr << "UnkReset1,";
+ if(startup & UnkReset2) sstr << "UnkReset2,";
+ if(startup & UnkReset3) sstr << "UnkReset3,";
+ if(startup & UnkReset4) sstr << "UnkReset4,";
+ if(startup & CommandReset) sstr << "CommandReset,";
+ if(startup & SyncReset) sstr << "SyncReset,";
+ if(startup & SuspendReset) sstr << "SuspendReset,";
+ }
+ if(getLenPayload()>1)
+ {
+ // print extra bytes if any?
+ }
+
+ }
return sstr.str();
}
@@ -780,4 +825,272 @@ template bool AntMessage::saveAsAntParse<std::list<AntMessage> >(std::ostream& o
//template bool AntMessage::saveAsAntParse<std::queue<AntMessage> >(std::ostream& os, const std::queue<AntMessage>& messages);
template bool AntMessage::saveAsAntParse<std::vector<AntMessage> >(std::ostream& os, const std::vector<AntMessage>& messages);
+const char *M_ANTFS_Beacon::szBeaconChannelPeriod() const
+{
+ if(beaconChannelPeriod==0x0) return "Beacon=0.5Hz";
+ else if(beaconChannelPeriod==0x1) return "Beacon=1Hz";
+ else if(beaconChannelPeriod==0x2) return "Beacon=2Hz";
+ else if(beaconChannelPeriod==0x3) return "Beacon=4Hz";
+ else if(beaconChannelPeriod==0x4) return "Beacon=8Hz";
+ else if(beaconChannelPeriod==0x7) return "Beacon=MatchEstablishedChannelPeriod";
+ else return "Beacon=??";
+}
+
+const char *M_ANTFS_Beacon::szPairingEnabled() const
+{
+ return pairingEnabled ? "pairing=enabled" : "pairing=disabled";
+}
+
+const char *M_ANTFS_Beacon::szUploadEnabled() const
+{
+ return uploadEnabled ? "upload=enabled" : "upload=disabled";
+}
+
+const char *M_ANTFS_Beacon::szClientDeviceState() const
+{
+ if(clientDeviceState==0x00) return "State=Link";
+ else if(clientDeviceState==0x01) return "State=Authentication";
+ else if(clientDeviceState==0x02) return "State=Transport";
+ else if(clientDeviceState==0x03) return "State=Busy";
+ else return "State=??";
+}
+
+const char *M_ANTFS_Beacon::szDataAvail() const
+{
+ return dataAvail ? "dataAvail=yes" : "dataAvail=no";
+}
+
+const char *M_ANTFS_Beacon::szAuthType() const
+{
+ if(authType==0x0) return "Auth=Passthrough";
+ else if(authType==0x1) return "Auth=NA";
+ else if(authType==0x2) return "Auth=PairingOnly";
+ else if(authType==0x3) return "Auth=PasskeyAndPairingOnly";
+ else return "Auth=??";
+}
+
+const string M_ANTFS_Beacon::strDeviceDescriptor() const
+{
+ return std::string("dev=0x") + antpm::toString(this->dev, 4, '0') + std::string("manuf=0x") + antpm::toString(this->manuf, 4, '0');
+}
+
+const string M_ANTFS_Beacon::strDeviceSerial() const
+{
+ return std::string("SN=0x") + antpm::toString(this->sn, 8, '0');
+}
+
+void M_ANTFS_Beacon::getDeviceDescriptor(ushort &dev, ushort &manuf) const
+{
+ dev=this->dev;
+ manuf=this->manuf;
+}
+
+uint M_ANTFS_Beacon::getDeviceSerial() const
+{
+ return this->sn;
+}
+
+const string M_ANTFS_Beacon::toString() const
+{
+ assert(beaconId==ANTFS_BeaconId);
+ std::stringstream sstr;
+ sstr << " ANTFS_BEACON(0x" << antpm::toString(unsigned(beaconId), 2, '0') << ") "
+ << this->szBeaconChannelPeriod()
+ << ", " << this->szPairingEnabled()
+ << ", " << this->szUploadEnabled()
+ << ", " << this->szDataAvail()
+ << ", " << this->szClientDeviceState()
+ << ", " << this->szAuthType();
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::Detail1::Link::toString() const
+{
+ std::stringstream sstr;
+ sstr << "freq=0x" << antpm::toString(unsigned(chanFreq), 2, '0') << ", period=0x" << antpm::toString(unsigned(chanPeriod), 2, '0') << ", SNhost=0x" << antpm::toString(sn, 8, '0');
+ return sstr.str();
+}
+
+const char *M_ANTFS_Command::Detail1::Disconnect::szCmdType() const
+{
+ if(cmdType==ReturnToLinkLayer) return "type=ReturnToLinkLayer";
+ else if(cmdType==ReturnToBroadcastMode) return "type=ReturnToBroadcastMode";
+ else return "type=??";
+}
+
+const char *M_ANTFS_Command::Detail1::Authenticate::szCmdType() const
+{
+ if(cmdType==ProceedToTransport) return "type=ProceedToTransport(pass-through)";
+ else if(cmdType==RequestClientDeviceSerialNumber) return "type=RequestClientDeviceSerialNumber";
+ else if(cmdType==RequestPairing) return "type=RequestPairing";
+ else if(cmdType==RequestPasskeyExchange) return "type=RequestPasskeyExchange";
+ else return "type=??";
+}
+
+const string M_ANTFS_Command::Detail1::Authenticate::toString() const
+{
+ std::stringstream sstr;
+ sstr << szCmdType() << ", authStrLen=" << int(authStrLen) << ", SNhost=0x" << antpm::toString(sn, 8, '0');
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::Detail1::DownloadRequest::toString() const
+{
+ std::stringstream sstr;
+ sstr << "file=0x" << antpm::toString(dataFileIdx, 4, '0') << ", dataOffset=0x" << antpm::toString(dataOffset, 8, '0');
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::Detail1::UploadRequest::toString() const
+{
+ std::stringstream sstr;
+ sstr << "file=0x" << antpm::toString(dataFileIdx, 4, '0') << ", maxSize=0x" << antpm::toString(maxSize, 8, '0');
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::Detail1::EraseRequest::toString() const
+{
+ std::stringstream sstr;
+ sstr << "dataFileIdx=0x" << antpm::toString(dataFileIdx, 4, '0');
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::Detail1::UploadData::toString() const
+{
+ std::stringstream sstr;
+ sstr << "crcSeed=0x" << antpm::toString(crcSeed, 4, '0') << ", dataOffset=0x" << antpm::toString(dataOffset, 8, '0');
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::Detail1::DirectCmd::toString() const
+{
+ std::stringstream sstr;
+ sstr << "fd=0x" << antpm::toString(fd, 4, '0')
+ << ", offset=0x" << antpm::toString(offset, 4, '0')
+ << ", data=0x" << antpm::toString(data, 4, '0') ;
+ return sstr.str();
+}
+
+const string M_ANTFS_Command::toString() const
+{
+ assert(commandId==ANTFS_CommandResponseId);
+ std::stringstream sstr;
+ sstr << " ANTFS_CMD(0x" << antpm::toString(unsigned(commandId),2,'0') << ") "
+ << antFSCommand2Str(command);
+ if(command==ANTFS_CmdLink) sstr << " " << detail.link.toString();
+ else if(command==ANTFS_CmdDisconnect) sstr << " " << detail.disconnect.toString();
+ else if(command==ANTFS_CmdAuthenticate) sstr << " " << detail.authenticate.toString();
+ else if(command==ANTFS_ReqDownload) sstr << " " << detail.downloadRequest.toString();
+ else if(command==ANTFS_ReqUpload) sstr << " " << detail.uploadRequest.toString();
+ else if(command==ANTFS_ReqErase) sstr << " " << detail.eraseRequest.toString();
+ else if(command==ANTFS_UploadData) sstr << " " << detail.uploadData.toString();
+ else if(command==ANTFS_CmdDirect) sstr << " " << detail.direct.toString();
+ return sstr.str();
+}
+
+const char *M_ANTFS_Response::Detail::AuthenticateResponse::szRespType() const
+{
+ if(respType==0) return "resp=SN";
+ else if(respType==1) return "resp=accept";
+ else if (respType==2) return "resp=reject";
+ else return "resp=??";
+}
+
+const string M_ANTFS_Response::Detail::AuthenticateResponse::toString() const
+{
+ std::stringstream sstr;
+ sstr << szRespType() << ", authStrLen=" << int(authStrLen) << ", SNclient=0x" << antpm::toString(sn, 8, '0');
+ return sstr.str();
+}
+
+const char *M_ANTFS_Response::Detail::DownloadRequestResponse::szResponseVal() const
+{
+ if(responseVal==DownloadRequestOK) return "resp=DownloadRequestOK";
+ else if(responseVal==DataDoesNotExist) return "resp=DataDoesNotExist";
+ else if(responseVal==DataExistsButIsNotDownloadable) return "resp=DataExistsButIsNotDownloadable";
+ else if(responseVal==NotReadyToDownload) return "resp=NotReadyToDownload";
+ else if(responseVal==DownloadRequestInvalid) return "resp=DownloadRequestInvalid";
+ else if(responseVal==CRCIncorrect) return "resp=CRCIncorrect";
+ return "resp=??";
+}
+
+const string M_ANTFS_Response::Detail::DownloadRequestResponse::toString() const
+{
+ std::stringstream sstr;
+ sstr << szResponseVal() << ", remainingBytes=0x" << antpm::toString(remainingBytes, 8, '0');
+ return sstr.str();
+}
+
+const char *M_ANTFS_Response::Detail::UploadRequestResponse::szResponseVal() const
+{
+ if(responseVal==UploadRequestOK) return "resp=UploadRequestOK";
+ else if(responseVal==DataFileIndexDoesNotExist) return "resp=DataFileIndexDoesNotExist";
+ else if(responseVal==DataFileIndexExistsButIsNotWriteable) return "resp=DataFileIndexExistsButIsNotWriteable";
+ else if(responseVal==NotEnoughSpaceToCompleteWrite) return "resp=NotEnoughSpaceToCompleteWrite";
+ else if(responseVal==UploadRequestInvalid) return "resp=UploadRequestInvalid";
+ else if(responseVal==NotReadyToUpload) return "resp=NotReadyToUpload";
+ return "resp=??";
+}
+
+const string M_ANTFS_Response::Detail::UploadRequestResponse::toString() const
+{
+ std::stringstream sstr;
+ sstr << szResponseVal() << ", lastDataOffset=0x" << antpm::toString(lastDataOffset, 8, '0');
+ return sstr.str();
+}
+
+const char *M_ANTFS_Response::Detail::EraseRequestResponse::szResponseVal() const
+{
+ if(responseVal==0) return "resp=EraseSuccessful";
+ else if(responseVal==1) return "resp=EraseFailed";
+ else if(responseVal==2) return "resp=NotReady";
+ return "resp=??";
+}
+
+const string M_ANTFS_Response::Detail::EraseRequestResponse::toString() const
+{
+ std::stringstream sstr;
+ sstr << szResponseVal() << " 0x" << antpm::toString<int>(int(responseVal),2,'0');
+ return sstr.str();
+}
+
+const char *M_ANTFS_Response::Detail::UploadDataResponse::szResponseVal() const
+{
+ if(responseVal==DataUploadSuccessfulOK) return "resp=DataUploadSuccessfulOK";
+ else if(responseVal==DataUploadFailed) return "resp=DataUploadFailed";
+ return "resp=??";
+}
+
+const string M_ANTFS_Response::Detail::DirectResponse::toString() const
+{
+ std::stringstream sstr;
+ sstr << "fd=0x" << antpm::toString(fd, 4, '0')
+ << ", offset=0x" << antpm::toString(offset, 4, '0')
+ << ", data=0x" << antpm::toString(data, 4, '0') ;
+ return sstr.str();
+}
+
+const string M_ANTFS_Response::toString() const
+{
+ assert(responseId==ANTFS_CommandResponseId);
+ std::stringstream sstr;
+ sstr << " ANTFS_RESP(0x" << antpm::toString(unsigned(responseId),2,'0') << ") "
+ << antFSResponse2Str(response);
+ if(response==ANTFS_RespAuthenticate) sstr << " " << detail.authenticateResponse.toString();
+ else if(response==ANTFS_RespDownload) sstr << " " << detail.downloadRequestResponse.toString();
+ else if(response==ANTFS_RespUpload) sstr << " " << detail.uploadRequestResponse.toString();
+ else if(response==ANTFS_RespErase) sstr << " " << detail.eraseRequestResponse.toString();
+ else if(response==ANTFS_RespUploadData) sstr << " " << detail.uploadDataResponse.toString();
+ else if(response==ANTFS_RespDirect) sstr << " " << detail.directResponse.toString();
+ return sstr.str();
+}
+
+const string M_ANT_Burst::toString() const
+{
+ std::stringstream sstr;
+ sstr << " chan=0x" << antpm::toString<int>(chan,2,'0') << ", seq=" << antpm::toStringDec<int>(seq,1,' ') << ", last=" << (isLast()?"yes":"no ");
+ return sstr.str();
+}
+
+
}
diff --git a/src/AntMessage.hpp b/src/AntMessage.hpp
index b9e5f36..8ff7cec 100644
--- a/src/AntMessage.hpp
+++ b/src/AntMessage.hpp
@@ -44,14 +44,7 @@ struct M_ANT_Channel_Id : public AntMessageContentBase
ushort devNum;
uchar devId;
uchar transType;
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr
- << " chan=0x" << antpm::toString<int>(chan,2,'0') << ", devNum=0x" << antpm::toString<int>(devNum,4,'0')
- << ", devId=0x" << antpm::toString<int>(devId,2,'0') << ", transType=0x" << antpm::toString<int>(transType,2,'0');
- return sstr.str();
- }
+ const std::string toString() const;
};
struct M_ANTFS_Beacon : public AntMessageContentBase
{
@@ -93,74 +86,17 @@ struct M_ANTFS_Beacon : public AntMessageContentBase
};
- const char* szBeaconChannelPeriod() const
- {
- if(beaconChannelPeriod==0x0) return "Beacon=0.5Hz";
- else if(beaconChannelPeriod==0x1) return "Beacon=1Hz";
- else if(beaconChannelPeriod==0x2) return "Beacon=2Hz";
- else if(beaconChannelPeriod==0x3) return "Beacon=4Hz";
- else if(beaconChannelPeriod==0x4) return "Beacon=8Hz";
- else if(beaconChannelPeriod==0x7) return "Beacon=MatchEstablishedChannelPeriod";
- else return "Beacon=??";
- }
- const char* szPairingEnabled() const
- {
- return pairingEnabled ? "pairing=enabled" : "pairing=disabled";
- }
- const char* szUploadEnabled() const
- {
- return uploadEnabled ? "upload=enabled" : "upload=disabled";
- }
- const char* szClientDeviceState() const
- {
- if(clientDeviceState==0x00) return "State=Link";
- else if(clientDeviceState==0x01) return "State=Authentication";
- else if(clientDeviceState==0x02) return "State=Transport";
- else if(clientDeviceState==0x03) return "State=Busy";
- else return "State=??";
- }
- const char* szDataAvail() const
- {
- return dataAvail ? "dataAvail=yes" : "dataAvail=no";
- }
- const char* szAuthType() const
- {
- if(authType==0x0) return "Auth=Passthrough";
- else if(authType==0x1) return "Auth=NA";
- else if(authType==0x2) return "Auth=PairingOnly";
- else if(authType==0x3) return "Auth=PasskeyAndPairingOnly";
- else return "Auth=??";
- }
- const std::string strDeviceDescriptor() const
- {
- return std::string("dev=0x") + antpm::toString(this->dev, 4, '0') + std::string("manuf=0x") + antpm::toString(this->manuf, 4, '0');
- }
- const std::string strDeviceSerial() const
- {
- return std::string("SN=0x") + antpm::toString(this->sn, 8, '0');
- }
- void getDeviceDescriptor(ushort& dev, ushort& manuf) const
- {
- dev=this->dev;
- manuf=this->manuf;
- }
- uint getDeviceSerial() const
- {
- return this->sn;
- }
- const std::string toString() const
- {
- assert(beaconId==ANTFS_BeaconId);
- std::stringstream sstr;
- sstr << " ANTFS_BEACON(0x" << antpm::toString(unsigned(beaconId), 2, '0') << ") "
- << this->szBeaconChannelPeriod()
- << ", " << this->szPairingEnabled()
- << ", " << this->szUploadEnabled()
- << ", " << this->szDataAvail()
- << ", " << this->szClientDeviceState()
- << ", " << this->szAuthType();
- return sstr.str();
- }
+ const char* szBeaconChannelPeriod() const;
+ const char* szPairingEnabled() const;
+ const char* szUploadEnabled() const;
+ const char* szClientDeviceState() const;
+ const char* szDataAvail() const;
+ const char* szAuthType() const;
+ const std::string strDeviceDescriptor() const;
+ const std::string strDeviceSerial() const;
+ void getDeviceDescriptor(ushort& dev, ushort& manuf) const;
+ uint getDeviceSerial() const;
+ const std::string toString() const;
};
#pragma pack(pop)
BOOST_STATIC_ASSERT(sizeof(M_ANTFS_Beacon)==8);
@@ -198,22 +134,12 @@ struct M_ANTFS_Command : public AntMessageContentBase
};
uchar sn4[4];
};
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "freq=0x" << antpm::toString(unsigned(chanFreq), 2, '0') << ", period=0x" << antpm::toString(unsigned(chanPeriod), 2, '0') << ", SNhost=0x" << antpm::toString(sn, 8, '0');
- return sstr.str();
- }
+ const std::string toString() const;
} link;
struct Disconnect
{
uchar cmdType;
- const char* szCmdType() const
- {
- if(cmdType==ReturnToLinkLayer) return "type=ReturnToLinkLayer";
- else if(cmdType==ReturnToBroadcastMode) return "type=ReturnToBroadcastMode";
- else return "type=??";
- }
+ const char* szCmdType() const;
const std::string toString() const
{
std::stringstream sstr;
@@ -234,20 +160,8 @@ struct M_ANTFS_Command : public AntMessageContentBase
uchar sn4[4];
};
// TODO:extra bytes ....
- const char* szCmdType() const
- {
- if(cmdType==ProceedToTransport) return "type=ProceedToTransport(pass-through)";
- else if(cmdType==RequestClientDeviceSerialNumber) return "type=RequestClientDeviceSerialNumber";
- else if(cmdType==RequestPairing) return "type=RequestPairing";
- else if(cmdType==RequestPasskeyExchange) return "type=RequestPasskeyExchange";
- else return "type=??";
- }
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << szCmdType() << ", authStrLen=" << int(authStrLen) << ", SNhost=0x" << antpm::toString(sn, 8, '0');
- return sstr.str();
- }
+ const char *szCmdType() const;
+ const std::string toString() const;
} authenticate;
// ping
struct DownloadRequest
@@ -255,35 +169,20 @@ struct M_ANTFS_Command : public AntMessageContentBase
ushort dataFileIdx;
uint dataOffset;
// ...
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "file=0x" << antpm::toString(dataFileIdx, 4, '0') << ", dataOffset=0x" << antpm::toString(dataOffset, 8, '0');
- return sstr.str();
- }
+ const std::string toString() const;
} downloadRequest;
struct UploadRequest
{
ushort dataFileIdx;
uint maxSize;
//uint dataOffset; //TODO: in next burst packet
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "file=0x" << antpm::toString(dataFileIdx, 4, '0') << ", maxSize=0x" << antpm::toString(maxSize, 8, '0');
- return sstr.str();
- }
+ const std::string toString() const;
} uploadRequest;
struct EraseRequest
{
ushort dataFileIdx;
// ...
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "dataFileIdx=0x" << antpm::toString(dataFileIdx, 4, '0');
- return sstr.str();
- }
+ const std::string toString() const;
} eraseRequest;
struct UploadData
{
@@ -292,12 +191,7 @@ struct M_ANTFS_Command : public AntMessageContentBase
// TODO: more burst packets
// uchar unused6[6];
// ushort crc;
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "crcSeed=0x" << antpm::toString(crcSeed, 4, '0') << ", dataOffset=0x" << antpm::toString(dataOffset, 8, '0');
- return sstr.str();
- }
+ const std::string toString() const;
} uploadData;
struct DirectCmd
@@ -305,32 +199,10 @@ struct M_ANTFS_Command : public AntMessageContentBase
ushort fd;
ushort offset;
ushort data;
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "fd=0x" << antpm::toString(fd, 4, '0')
- << ", offset=0x" << antpm::toString(offset, 4, '0')
- << ", data=0x" << antpm::toString(data, 4, '0') ;
- return sstr.str();
- }
+ const std::string toString() const;
} direct;
} detail;
- const std::string toString() const
- {
- assert(commandId==ANTFS_CommandResponseId);
- std::stringstream sstr;
- sstr << " ANTFS_CMD(0x" << antpm::toString(unsigned(commandId),2,'0') << ") "
- << antFSCommand2Str(command);
- if(command==ANTFS_CmdLink) sstr << " " << detail.link.toString();
- else if(command==ANTFS_CmdDisconnect) sstr << " " << detail.disconnect.toString();
- else if(command==ANTFS_CmdAuthenticate) sstr << " " << detail.authenticate.toString();
- else if(command==ANTFS_ReqDownload) sstr << " " << detail.downloadRequest.toString();
- else if(command==ANTFS_ReqUpload) sstr << " " << detail.uploadRequest.toString();
- else if(command==ANTFS_ReqErase) sstr << " " << detail.eraseRequest.toString();
- else if(command==ANTFS_UploadData) sstr << " " << detail.uploadData.toString();
- else if(command==ANTFS_CmdDirect) sstr << " " << detail.direct.toString();
- return sstr.str();
- }
+ const std::string toString() const;
};
struct M_ANTFS_Command_Authenticate : public M_ANTFS_Command
{
@@ -399,19 +271,8 @@ struct M_ANTFS_Response : public AntMessageContentBase
uchar sn4[4];
};
// TODO:extra bytes in following burst message
- const char* szRespType() const
- {
- if(respType==0) return "resp=SN";
- else if(respType==1) return "resp=accept";
- else if (respType==2) return "resp=reject";
- else return "resp=??";
- }
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << szRespType() << ", authStrLen=" << int(authStrLen) << ", SNclient=0x" << antpm::toString(sn, 8, '0');
- return sstr.str();
- }
+ const char* szRespType() const;
+ const std::string toString() const;
} authenticateResponse;
// ping
struct DownloadRequestResponse
@@ -420,22 +281,8 @@ struct M_ANTFS_Response : public AntMessageContentBase
uchar reserved;
uint remainingBytes;
// ...
- const char* szResponseVal() const
- {
- if(responseVal==DownloadRequestOK) return "resp=DownloadRequestOK";
- else if(responseVal==DataDoesNotExist) return "resp=DataDoesNotExist";
- else if(responseVal==DataExistsButIsNotDownloadable) return "resp=DataExistsButIsNotDownloadable";
- else if(responseVal==NotReadyToDownload) return "resp=NotReadyToDownload";
- else if(responseVal==DownloadRequestInvalid) return "resp=DownloadRequestInvalid";
- else if(responseVal==CRCIncorrect) return "resp=CRCIncorrect";
- return "resp=??";
- }
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << szResponseVal() << ", remainingBytes=0x" << antpm::toString(remainingBytes, 8, '0');
- return sstr.str();
- }
+ const char* szResponseVal() const;
+ const std::string toString() const;
} downloadRequestResponse;
struct UploadRequestResponse
{
@@ -443,50 +290,20 @@ struct M_ANTFS_Response : public AntMessageContentBase
uchar unused1;
uint lastDataOffset;
// TODO: 4 packets in total
- const char* szResponseVal() const
- {
- if(responseVal==UploadRequestOK) return "resp=UploadRequestOK";
- else if(responseVal==DataFileIndexDoesNotExist) return "resp=DataFileIndexDoesNotExist";
- else if(responseVal==DataFileIndexExistsButIsNotWriteable) return "resp=DataFileIndexExistsButIsNotWriteable";
- else if(responseVal==NotEnoughSpaceToCompleteWrite) return "resp=NotEnoughSpaceToCompleteWrite";
- else if(responseVal==UploadRequestInvalid) return "resp=UploadRequestInvalid";
- else if(responseVal==NotReadyToUpload) return "resp=NotReadyToUpload";
- return "resp=??";
- }
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << szResponseVal() << ", lastDataOffset=0x" << antpm::toString(lastDataOffset, 8, '0');
- return sstr.str();
- }
+ const char* szResponseVal() const;
+ const std::string toString() const;
} uploadRequestResponse;
struct EraseRequestResponse
{
uchar responseVal;
- const char* szResponseVal() const
- {
- if(responseVal==0) return "resp=EraseSuccessful";
- else if(responseVal==1) return "resp=EraseFailed";
- else if(responseVal==2) return "resp=NotReady";
- return "resp=??";
- }
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << szResponseVal() << " 0x" << antpm::toString<int>(int(responseVal),2,'0');
- return sstr.str();
- }
+ const char* szResponseVal() const;
+ const std::string toString() const;
} eraseRequestResponse;
struct UploadDataResponse
{
// TODO: first is a beacon
uchar responseVal;
- const char* szResponseVal() const
- {
- if(responseVal==DataUploadSuccessfulOK) return "resp=DataUploadSuccessfulOK";
- else if(responseVal==DataUploadFailed) return "resp=DataUploadFailed";
- return "resp=??";
- }
+ const char* szResponseVal() const;
const std::string toString() const
{
std::stringstream sstr;
@@ -499,30 +316,10 @@ struct M_ANTFS_Response : public AntMessageContentBase
ushort fd;
ushort offset;
ushort data;
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << "fd=0x" << antpm::toString(fd, 4, '0')
- << ", offset=0x" << antpm::toString(offset, 4, '0')
- << ", data=0x" << antpm::toString(data, 4, '0') ;
- return sstr.str();
- }
+ const std::string toString() const;
} directResponse;
} detail;
- const std::string toString() const
- {
- assert(responseId==ANTFS_CommandResponseId);
- std::stringstream sstr;
- sstr << " ANTFS_RESP(0x" << antpm::toString(unsigned(responseId),2,'0') << ") "
- << antFSResponse2Str(response);
- if(response==ANTFS_RespAuthenticate) sstr << " " << detail.authenticateResponse.toString();
- else if(response==ANTFS_RespDownload) sstr << " " << detail.downloadRequestResponse.toString();
- else if(response==ANTFS_RespUpload) sstr << " " << detail.uploadRequestResponse.toString();
- else if(response==ANTFS_RespErase) sstr << " " << detail.eraseRequestResponse.toString();
- else if(response==ANTFS_RespUploadData) sstr << " " << detail.uploadDataResponse.toString();
- else if(response==ANTFS_RespDirect) sstr << " " << detail.directResponse.toString();
- return sstr.str();
- }
+ const std::string toString() const;
};
struct M_ANTFS_Response_Download : public M_ANTFS_Response
{
@@ -556,12 +353,7 @@ struct M_ANT_Burst : public AntMessageContentBase
uchar seqchan;
};
uchar data8[8];
- const std::string toString() const
- {
- std::stringstream sstr;
- sstr << " chan=0x" << antpm::toString<int>(chan,2,'0') << ", seq=" << antpm::toStringDec<int>(seq,1,' ') << ", last=" << (isLast()?"yes":"no ");
- return sstr.str();
- }
+ const std::string toString() const;
bool isLast() const
{
bool isLast = ((last!=0x00)?true:false);
diff --git a/src/AntMessenger.cpp b/src/AntMessenger.cpp
index cb6ce47..c6dc20e 100644
--- a/src/AntMessenger.cpp
+++ b/src/AntMessenger.cpp
@@ -81,6 +81,7 @@ AntMessenger::~AntMessenger()
m_packerTh.join();
m_io=0;
m_cb=0;
+ lprintf(LOG_DBG2, "%s\n", __FUNCTION__);
}
size_t AntMessenger::getQueueLength() const
@@ -180,7 +181,9 @@ AntMessenger::ANT_CloseChannel(uchar chan, const size_t timeout_ms)
uint8_t msgCode;
rv = rv && el.waitForEvent(msgCode, timeout_ms/2);
- rv = rv && (msgCode==EVENT_CHANNEL_CLOSED);
+ rv = rv && (msgCode==EVENT_CHANNEL_CLOSED
+ || msgCode==CHANNEL_IN_WRONG_STATE
+ || msgCode==CHANNEL_NOT_OPENED);
//pc.rmEvListener(&el);
@@ -320,7 +323,7 @@ AntMessenger::ANTFS_Disconnect(const uchar chan)
cmd.command = ANTFS_CmdDisconnect;
cmd.detail.disconnect.cmdType = M_ANTFS_Command::ReturnToLinkLayer;
- /*CHECK_RETURN_FALSE_LOG_OK(*/ANT_SendAcknowledgedData(chan, reinterpret_cast<uchar*>(&cmd), 400)/*)*/;
+ /*CHECK_RETURN_FALSE_LOG_OK(*/ANT_SendAcknowledgedData(chan, reinterpret_cast<uchar*>(&cmd), 0)/*)*/;
return true;
}
@@ -349,7 +352,7 @@ AntMessenger::ANTFS_Pairing(const uchar chan, const uint hostSN, const std::stri
{
sentPairing = false;
- LOG_VAR(waitForBroadcast(chan));
+ LOG_VAR_DBG2(waitForBroadcast(chan));
//CHECK_RETURN_FALSE_LOG_OK(collectBroadcasts(chan));
sentPairing = ANT_SendBurstData2(chan, reinterpret_cast<uchar*>(&cmd), sizeof(cmd));
@@ -372,7 +375,7 @@ AntMessenger::ANTFS_Pairing(const uchar chan, const uint hostSN, const std::stri
else
sleepms(ANTPM_RETRY_MS);
}
- CHECK_RETURN_FALSE_LOG_OK(sentPairing);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(sentPairing);
// FIXME: look for, and handle event:EVENT_RX_FAIL; event:EVENT_TRANSFER_RX_FAILED
@@ -381,13 +384,13 @@ AntMessenger::ANTFS_Pairing(const uchar chan, const uint hostSN, const std::stri
/*bool rv =*/ bl.collectBurst(burstData, 30*1000); // 30s to allow user confirmation
//pc.rmMsgListener(&bl);
- CHECK_RETURN_FALSE_LOG_OK(burstData.size()==3*8);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(burstData.size()==3*8);
const M_ANTFS_Response_Pairing* resp(reinterpret_cast<const M_ANTFS_Response_Pairing*>(&burstData[8]));
- CHECK_RETURN_FALSE_LOG_OK(resp->responseId==ANTFS_CommandResponseId);
- CHECK_RETURN_FALSE_LOG_OK(resp->response==ANTFS_RespAuthenticate);
- CHECK_RETURN_FALSE_LOG_OK(resp->detail.authenticateResponse.respType==1); // accept
- LOG_VAR((int)resp->detail.authenticateResponse.authStrLen);
- CHECK_RETURN_FALSE(resp->detail.authenticateResponse.authStrLen==8);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->responseId==ANTFS_CommandResponseId);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->response==ANTFS_RespAuthenticate);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->detail.authenticateResponse.respType==1); // accept
+ LOG_VAR_DBG2((int)resp->detail.authenticateResponse.authStrLen);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->detail.authenticateResponse.authStrLen==8);
unitId = resp->detail.authenticateResponse.sn;
key = resp->pairedKey;
@@ -432,7 +435,7 @@ AntMessenger::ANTFS_Authenticate(const uchar chan, const uint hostSN, const uint
{
sentReqAuth = false;
- LOG_VAR(waitForBroadcast(chan));
+ LOG_VAR_DBG2(waitForBroadcast(chan));
//CHECK_RETURN_FALSE_LOG_OK(collectBroadcasts(chan));
sentReqAuth = ANT_SendBurstData2(chan, reinterpret_cast<uchar*>(&cmd), sizeof(cmd));
@@ -455,18 +458,18 @@ AntMessenger::ANTFS_Authenticate(const uchar chan, const uint hostSN, const uint
else
sleepms(ANTPM_RETRY_MS);
}
- CHECK_RETURN_FALSE_LOG_OK(sentReqAuth);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(sentReqAuth);
// ANTFS_RespAuthenticate
std::vector<uchar> burstData;
- CHECK_RETURN_FALSE_LOG_OK(waitForBurst(chan, burstData, 10*1000));
- CHECK_RETURN_FALSE_LOG_OK(burstData.size()==2*8);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(waitForBurst(chan, burstData, 10*1000));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(burstData.size()==2*8);
const M_ANTFS_Response* resp(reinterpret_cast<const M_ANTFS_Response*>(&burstData[8]));
- CHECK_RETURN_FALSE_LOG_OK(resp->responseId==ANTFS_CommandResponseId);
- CHECK_RETURN_FALSE_LOG_OK(resp->response==ANTFS_RespAuthenticate);
- CHECK_RETURN_FALSE_LOG_OK(resp->detail.authenticateResponse.respType==1); // accept
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->responseId==ANTFS_CommandResponseId);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->response==ANTFS_RespAuthenticate);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(resp->detail.authenticateResponse.respType==1); // accept
// TODO: read bcast here?
@@ -481,6 +484,9 @@ AntMessenger::ANTFS_Download( const uchar chan, const ushort file, std::vector<u
//S 1.221 50 MESG_BURST_DATA_ID chan=0x00, seq=0, last=no ANTFS_CMD(0x44) ANTFS_ReqDownload file=0x0000, dataOffset=0x00000000
//R 118.782 4e MESG_BROADCAST_DATA_ID chan=0x00 ANTFS_BEACON(0x43) Beacon=8Hz, pairing=enabled, upload=disabled, dataAvail=yes, State=Transport, Auth=PasskeyAndPairingOnly
//S 1.258 50 MESG_BURST_DATA_ID chan=0x00, seq=1, last=yes 0001000000000000 ........
+
+ // 310XT 4.50 sends EVENT_TRANSFER_TX_START here too
+
//R 10.728 40 MESG_RESPONSE_EVENT_ID chan=0x00 mId=MESG_EVENT_ID mCode=EVENT_TRANSFER_TX_COMPLETED
//R 112.995 4e MESG_BROADCAST_DATA_ID chan=0x00 ANTFS_BEACON(0x43) Beacon=8Hz, pairing=enabled, upload=disabled, dataAvail=yes, State=Busy, Auth=PasskeyAndPairingOnly
//R 125.019 50 MESG_BURST_DATA_ID chan=0x00, seq=0, last=no ANTFS_BEACON(0x43) Beacon=8Hz, pairing=enabled, upload=disabled, dataAvail=yes, State=Busy, Auth=PasskeyAndPairingOnly
@@ -578,10 +584,8 @@ AntMessenger::ANTFS_Download( const uchar chan, const ushort file, std::vector<u
AntChannel& pc(chs[chan]);
AntBurstListener bl(pc);
- //pc.addMsgListener(&bl); // FIXME: remove this on return paths, IN DTOR!!!
AntEvListener el(pc);
- //pc.addEvListener(&el); // FIXME: remove this on return paths, IN DTOR!!!
bool sentReqDl = false;
sentReqDl = false;
@@ -670,7 +674,7 @@ AntMessenger::ANTFS_Download( const uchar chan, const ushort file, std::vector<u
ushort crcCalculated=crcData.crc16Calc(crc);
//LOG_VAR(toString(crcCalculated,4,'0'));
bool crcCheckOk=(footer->crc==crcCalculated);
- CHECK_RETURN_FALSE_LOG_OK(crcCheckOk);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(crcCheckOk);
crc = footer->crc; //TODO: crc check
CHECK_RETURN_FALSE(waitForBroadcast(chan, NULL, 1000));
@@ -748,7 +752,7 @@ AntMessenger::ANTFS_RequestClientDeviceSerialNumber(const uchar chan, const uint
//pc.addMsgListener(&bl);
- CHECK_RETURN_FALSE_LOG_OK(ANT_SendAcknowledgedData(chan, reinterpret_cast<uchar*>(&cmd), 2000));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(ANT_SendAcknowledgedData(chan, reinterpret_cast<uchar*>(&cmd), 2000));
std::vector<uchar> burstData;
/*bool rv =*/ bl.collectBurst(burstData, 5000);
@@ -760,19 +764,19 @@ AntMessenger::ANTFS_RequestClientDeviceSerialNumber(const uchar chan, const uint
//CHECK_RETURN_FALSE_LOG_OK(waitForBroadcast(chan));
//
//CHECK_RETURN_FALSE_LOG_OK(waitForBurst(chan, burstData, 30000));
- LOG_VAR(burstData.size());
- CHECK_RETURN_FALSE_LOG_OK(burstData.size()==4*8);
+ LOG_VAR_DBG2(burstData.size());
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(burstData.size()==4*8);
const M_ANTFS_Response* cmdResp(reinterpret_cast<const M_ANTFS_Response*>(&burstData[8]));
sn = cmdResp->detail.authenticateResponse.sn;
uchar lenDevName=cmdResp->detail.authenticateResponse.authStrLen;
- CHECK_RETURN_FALSE_LOG_OK(lenDevName==16);
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(lenDevName==16);
devName = std::string(reinterpret_cast<const char*>(&burstData[16]), lenDevName);
logger() << "devName = \"" << devName << "\"\n";
- CHECK_RETURN_FALSE_LOG_OK(ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
+ CHECK_RETURN_FALSE_LOG_OK_DBG2(ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID));
return true;
}
@@ -826,7 +830,7 @@ AntMessenger::ANTFS_Direct(const uchar chan, const uint64_t code)
CHECK_RETURN_FALSE_LOG_OK(waitForBurst(chan, burstData, 10*1000));
CHECK_RETURN_FALSE_LOG_OK(burstData.size()>=2*8);
- const M_ANTFS_Beacon* beac(reinterpret_cast<const M_ANTFS_Beacon*>(&burstData[0]));
+ //const M_ANTFS_Beacon* beac(reinterpret_cast<const M_ANTFS_Beacon*>(&burstData[0]));
const M_ANTFS_Response* resp(reinterpret_cast<const M_ANTFS_Response*>(&burstData[8]));
CHECK_RETURN_FALSE_LOG_OK(resp->responseId==ANTFS_CommandResponseId);
CHECK_RETURN_FALSE_LOG_OK(resp->response==ANTFS_RespDirect);
@@ -1069,6 +1073,14 @@ bool AntMessenger::onMessage(std::vector<AntMessage> v)
AntChannel& pc=chs[chan];
pc.onMsg(m);
}
+ else if(m.getMsgId()==MESG_STARTUP_MSG_ID)
+ {
+ if(m.getLenPayload()>=1)
+ {
+ uint8_t startup=m.getPayloadRef()[0];
+ lprintf(antpm::LOG_DBG2, "startup 0x%02x\n", startup);
+ }
+ }
else
{
lprintf(antpm::LOG_WARN, "unhandled 0x%0x\n", (int)m.getMsgId());
@@ -1130,6 +1142,16 @@ AntMessenger::waitForBroadcast(const uchar chan, AntMessage* reply, const size_t
}
+void
+AntMessenger::interruptWait()
+{
+ for(size_t i = 0; i < ANTPM_MAX_CHANNELS; i++)
+ {
+ chs[i].interruptWait();
+ }
+}
+
+
// receive bytes from the serial interface
void*
AntMessenger::th_messageHandler()
diff --git a/src/AntMessenger.hpp b/src/AntMessenger.hpp
index 52a4c10..d315e39 100644
--- a/src/AntMessenger.hpp
+++ b/src/AntMessenger.hpp
@@ -162,6 +162,7 @@ private:
public:
bool waitForBurst(const uchar chan, std::vector<uchar>& burstData, const size_t timeout_ms = 30000);
bool waitForBroadcast(const uchar chan, AntMessage* reply = NULL, const size_t timeout_ms = 2000);
+ void interruptWait();
//public:
private:
Serial* m_io;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f2257d6..50842e8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,13 +11,19 @@ OPTION(USE_COVERAGE "use gcov" FALSE)
OPTION(USE_BOOST_TEST "use boost::test" FALSE)
OPTION(USE_BOOST_STATIC_LINK "link statically against boost" TRUE)
+
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
-set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
-#set(CMAKE_CXX_FLAGS_DEBUGFULL "-g -Ob0 -noalign")
-#set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
-#set(CMAKE_C_FLAGS_RELEASE "-O2")
-set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
+# Set a default build type for single-configuration
+# CMake generators if no build type is set.
+IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
+ SET(CMAKE_BUILD_TYPE Debug)
+ENDIF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
+MESSAGE(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
+MESSAGE(STATUS "CMAKE_CONFIGURATION_TYPES=${CMAKE_CONFIGURATION_TYPES}")
+
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG=1")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG=1")
IF(MSVC)
IF(NOT DEP_ROOT)
@@ -32,10 +38,12 @@ IF(MSVC)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fms-extensions -std=c++0x -Wall")
- set(CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wextra -Wall")
- set(CMAKE_C_FLAGS_DEBUG "-g3 -ggdb3")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fms-extensions -std=c++0x -Wall")
+ SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g")
+ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -ggdb3")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wextra -Wall")
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -ggdb3")
IF(USE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
@@ -78,7 +86,7 @@ MESSAGE(STATUS "ANTPM_VERSION=\\\"${ANTPM_VERSION}\\\"")
ADD_DEFINITIONS(-DANTPM_VERSION=${ANTPM_VERSION})
SET(SRCS
- antdefs.hpp
+ antdefs.hpp antdefs.cpp
SmartPtrFwd.hpp w_inttypes.h w_stdint.h stdintfwd.hpp
common.hpp common.cpp
AntMessage.hpp AntMessage.cpp
@@ -88,7 +96,7 @@ SET(SRCS
AntFr310XT.hpp AntFr310XT.cpp
AntFr405.hpp AntFr405.cpp
lqueue.hpp
- Serial.hpp
+ Serial.hpp Serial.cpp
FIT.hpp FIT.cpp
GPX.hpp GPX.cpp
@@ -156,22 +164,22 @@ add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
ADD_SUBDIRECTORY(gant)
-set(CPACK_PACKAGE_VERSION_MAJOR "1")
-set(CPACK_PACKAGE_VERSION_MINOR "0")
-set(CPACK_SOURCE_GENERATOR "TGZ")
-set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-src")
-MESSAGE(STATUS "${CPACK_SOURCE_IGNORE_FILES}")
-set(CPACK_SOURCE_IGNORE_FILES
- "/build/;/.bzr/;~$;${CPACK_SOURCE_IGNORE_FILES};/CMakeLists.txt.user;/gpsbabel/;/gtest-1.6.0/")
-set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Kristof Ralovich <tade60@freemail.hu>")
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ANT+minus")
-set(CPACK_PACKAGE_DESCRIPTION "Userspace implementation of a wire protocol similar to the ANT/ANT+ protocols. The goal is to be able to communicate with the Forerunner 310XT watch, in order to retrieve sports tracks. Communication with other watches might work, please report your experiences to improve the software.")
-set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>=4.6.0)")
-#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>=4.6.0), cmake, debhelper (>= 7), libboost-filesystem, libboost-system")
-#set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive) ${CMAKE_CURRENT_SOURCE_DIR}/postinst
-#set(CPACK_DEBIAN_PACKAGE_SECTION Package section (see http://packages.debian.org/stable/) Network
-#set(CPACK_DEBIAN_PACKAGE_VERSION Package version ${CPACK_PACKAGE_VERSION}+lenny1
-INCLUDE(CPack)
+# set(CPACK_PACKAGE_VERSION_MAJOR "1")
+# set(CPACK_PACKAGE_VERSION_MINOR "0")
+# set(CPACK_SOURCE_GENERATOR "TGZ")
+# set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-src")
+# MESSAGE(STATUS "${CPACK_SOURCE_IGNORE_FILES}")
+# set(CPACK_SOURCE_IGNORE_FILES
+# "/build/;/.bzr/;~$;${CPACK_SOURCE_IGNORE_FILES};/CMakeLists.txt.user;/gpsbabel/;/gtest-1.6.0/")
+# set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Kristof Ralovich <tade60@freemail.hu>")
+# set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ANT+minus")
+# set(CPACK_PACKAGE_DESCRIPTION "Userspace implementation of a wire protocol similar to the ANT/ANT+ protocols. The goal is to be able to communicate with the Forerunner 310XT watch, in order to retrieve sports tracks. Communication with other watches might work, please report your experiences to improve the software.")
+# set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>=4.6.0)")
+# #set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>=4.6.0), cmake, debhelper (>= 7), libboost-filesystem, libboost-system")
+# #set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive) ${CMAKE_CURRENT_SOURCE_DIR}/postinst
+# #set(CPACK_DEBIAN_PACKAGE_SECTION Package section (see http://packages.debian.org/stable/) Network
+# #set(CPACK_DEBIAN_PACKAGE_VERSION Package version ${CPACK_PACKAGE_VERSION}+lenny1
+# INCLUDE(CPack)
IF(USE_BOOST_TEST)
diff --git a/src/DeviceSettings.cpp b/src/DeviceSettings.cpp
index cb8fe74..2b6f68b 100644
--- a/src/DeviceSettings.cpp
+++ b/src/DeviceSettings.cpp
@@ -119,7 +119,7 @@ DeviceSettings::saveToFile(const char *fname)
}
catch(boost::property_tree::ini_parser_error& ipe)
{
- LOG(LOG_WARN) << ipe.message() << std::endl;
+ LOG(LOG_WARN) << "DeviceSettings::saveToFile: " << ipe.message() << std::endl;
return false;
}
return true;
@@ -134,7 +134,7 @@ bool DeviceSettings::loadFromFile(const char *fname)
}
catch(boost::property_tree::ini_parser_error& ipe)
{
- LOG(LOG_WARN) << ipe.message() << std::endl;
+ LOG(LOG_WARN) << "DeviceSettings::loadFromFile: " << ipe.message() << std::endl;
return false;
}
@@ -154,7 +154,8 @@ bool DeviceSettings::loadFromFile(const char *fname)
void DeviceSettings::mergeLastUserProfileTime(const std::time_t gmt)
{
//std::time_t gmt = t + timezone;
- LOG(LOG_DBG) << "LastUserProfileTime: " << time2str(LastUserProfileTime) << " => " << time2str(gmt) << "\n";
+ LOG(LOG_DBG2) << "LastUserProfileTime: " << time2str(LastUserProfileTime) << " => " << time2str(gmt) << "\n";
+ LOG(LOG_DBG2) << "LastUserProfileTime: " << LastUserProfileTime << " => " << gmt << "\n";
if(gmt > LastUserProfileTime)
{
LastUserProfileTime = gmt;
@@ -165,7 +166,7 @@ void DeviceSettings::mergeLastUserProfileTime(const std::time_t gmt)
/// \param t expected to be represented as local time
void DeviceSettings::mergeLastTransferredTime(const std::time_t gmt)
{
- LOG(LOG_DBG) << "LastTransferredTime: " << time2str(LastTransferredTime) << " => " << time2str(gmt) << "\n";
+ LOG(LOG_DBG2) << "LastTransferredTime: " << time2str(LastTransferredTime) << " => " << time2str(gmt) << "\n";
//std::time_t gmt = t + timezone;
LastTransferredTime = std::max(LastTransferredTime, gmt);
}
diff --git a/src/FIT.cpp b/src/FIT.cpp
index 4a7fa90..ce49998 100644
--- a/src/FIT.cpp
+++ b/src/FIT.cpp
@@ -1206,7 +1206,7 @@ bool FIT::parseZeroFile(vector<uint8_t> &data, ZeroFileContent &zeroFileContent)
return false;
}
- logger() << uppercase;
+ //logger() << uppercase;
logger() << "_idx" << "|d" << "ata" << "type|" << "recordType|" << "_rt_" << "++ID++" << "__fileSize|" << "+++++++++++++++++++|" << "flags" << "\n";
uint8_t *ptr = &data.front();
@@ -1239,7 +1239,7 @@ bool FIT::parseZeroFile(vector<uint8_t> &data, ZeroFileContent &zeroFileContent)
for(size_t i = 0; i < zeroFileContent.zfRecords.size(); i++)
{
ZeroFileRecord& zfRecord(zeroFileContent.zfRecords[i]);
- logger() << hex << setw(4) << setfill('0') << (unsigned)zfRecord.index << ": " <<
+ LOG(LOG_DBG2) << hex << setw(4) << setfill('0') << (unsigned)zfRecord.index << ": " <<
GarminConvert::localTime(zfRecord.timeStamp) << "\n";
switch(zfRecord.recordType)
{
diff --git a/src/Log.hpp b/src/Log.hpp
index 6ac3b29..066b758 100644
--- a/src/Log.hpp
+++ b/src/Log.hpp
@@ -200,6 +200,7 @@ namespace antpm
this->lprintf2(LOG_INF,
"%s\n",
v.c_str());
+ this->lprintf2(LOG_RAW, "logging level: %d\n", this->_logReportingLevel);
}
}
@@ -285,6 +286,7 @@ namespace antpm
Log::setLogReportingLevel(const LogLevel& logReportingLevel)
{
_logReportingLevel = logReportingLevel;
+ this->lprintf2(LOG_RAW, "logging level: %d\n", this->_logReportingLevel);
}
int
diff --git a/src/Serial.cpp b/src/Serial.cpp
new file mode 100644
index 0000000..07de0bb
--- /dev/null
+++ b/src/Serial.cpp
@@ -0,0 +1,102 @@
+// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*-
+// ***** BEGIN LICENSE BLOCK *****
+//////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2014 RALOVICH, Kristóf //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+//////////////////////////////////////////////////////////////////////////
+// ***** END LICENSE BLOCK *****
+
+
+#include "Serial.hpp"
+#include "SerialUsb.hpp"
+#include "SerialTty.hpp"
+#include <fstream>
+#include "Log.hpp"
+
+#ifdef __linux__
+# include <sys/utsname.h>
+#endif
+
+namespace antpm {
+
+
+
+Serial*
+Serial::instantiate(void*)
+{
+#ifdef __linux__
+ utsname u;
+ int urv = uname(&u);
+ if(urv==0)
+ {
+ LOG(LOG_DBG) << "Running under: " << u.sysname << ", " << u.release << ", " << u.version << ", " << u.machine << "\n";
+ }
+
+ // check for cp210x kernel module
+ std::string line;
+ std::ifstream mods("/proc/modules");
+ bool cp210x_found=false;
+ bool usbserial_found=false;
+ if(!mods.is_open())
+ LOG(LOG_WARN) << "Could not open /proc/modules!\n";
+ else
+ {
+ while (mods.good())
+ {
+ getline(mods,line);
+ if(line.find("cp210x ")==0)
+ cp210x_found = true;
+ if(line.find("usbserial ")==0)
+ usbserial_found = true;
+ }
+ mods.close();
+ if(cp210x_found)
+ LOG(LOG_DBG) << "Found loaded cp210x kernel module.\n";
+ else
+ LOG(LOG_DBG) << "cp210x is not listed among loaded kernel modules.\n";
+ if(usbserial_found)
+ LOG(LOG_DBG) << "Found loaded usbserial kernel module.\n";
+ else
+ LOG(LOG_DBG) << "usbserial is not listed among loaded kernel modules.\n";
+ }
+#endif
+
+ Serial* s = new SerialUsb();
+ if(!s)
+ return NULL;
+#ifdef _WIN32
+ if(!s->open())
+ {
+ delete s;
+ return NULL;
+ }
+#else
+ if(!s->open())
+ {
+ delete s;
+ s = new SerialTty();
+ if(!s)
+ return NULL;
+ if(!s->open())
+ {
+ delete s;
+ return NULL;
+ }
+ }
+#endif
+ return s;
+}
+
+
+}
+
diff --git a/src/Serial.hpp b/src/Serial.hpp
index 46b2e0f..452b52f 100644
--- a/src/Serial.hpp
+++ b/src/Serial.hpp
@@ -15,7 +15,9 @@
// //
//////////////////////////////////////////////////////////////////////////
// ***** END LICENSE BLOCK *****
+
#pragma once
+#include "stdintfwd.hpp"
namespace antpm{
@@ -36,6 +38,7 @@ public:
virtual const char* getImplName() = 0;
virtual bool isOpen() const = 0;
virtual bool setWriteDelay(const size_t ms) = 0;
+ static Serial* instantiate(void* p = NULL);
};
}
diff --git a/src/SerialTty.cpp b/src/SerialTty.cpp
index c096028..5fe98b9 100644
--- a/src/SerialTty.cpp
+++ b/src/SerialTty.cpp
@@ -227,7 +227,7 @@ SerialTty::SerialTty()
SerialTty::~SerialTty()
{
- //printf("%s\n", __FUNCTION__);
+ lprintf(LOG_DBG2, "%s\n", __FUNCTION__);
}
#define ENSURE_OR_RETURN_FALSE(e) \
@@ -280,10 +280,10 @@ SerialTty::open()
if(m_p->m_fd<0)
{
char se[256];
- strerror_r(m_p->m_fd, se, sizeof(se));
+ char* ss = strerror_r(m_p->m_fd, se, sizeof(se));
LOG(antpm::LOG_ERR) << "Opening serial port failed! Make sure cp210x kernel module is loaded, and /dev/ttyUSBxxx was created by cp210x!\n"
<< "\tAlso make sure that /dev/ttyUSBxxx is R+W accessible by your user (usually enabled through udev.rules)!\n";
- LOG(antpm::LOG_ERR) << "error=" << m_p->m_fd << ", strerror=" << se << "\n";
+ LOG(antpm::LOG_ERR) << "error=" << m_p->m_fd << ", strerror=" << ss << "\n";
return rv;
}
@@ -318,7 +318,10 @@ SerialTty::close()
{
m_p->m_recvThKill = 1;
- m_p->m_condQueue.notify_all();
+ {
+ boost::unique_lock<boost::mutex> lock(m_p->m_queueMtx);
+ m_p->m_condQueue.notify_all();
+ }
m_p->m_recvTh.join();
diff --git a/src/SerialUsb.cpp b/src/SerialUsb.cpp
index 29f3ef2..42a76a6 100644
--- a/src/SerialUsb.cpp
+++ b/src/SerialUsb.cpp
@@ -1,30 +1,20 @@
// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*-
-/*
- * Portions copyright as:
- * Silicon Laboratories CP2101/CP2102/CP2103 USB to RS232 serial adaptor driver
- *
- * Copyright (C) 2010 Craig Shelley (craig@microtron.org.uk)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * Support to set flow control line levels using TIOCMGET and TIOCMSET
- * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow
- * control thanks to Munir Nassar nassarmu@real-time.com
- * Original backport to 2.4 by andreas 'randy' weinberger randy@ebv.com
- * Several fixes and enhancements by Bill Pfutzenreuter BPfutzenreuter@itsgames.com
- * Ported to userspace by Kristof Ralovich
- *
- */
-////////////////////////////////////////////////////////////////////
-// Copyright (c) 2011-2014 RALOVICH, Kristóf //
-// //
-// This program is free software; you can redistribute it and/or //
-// modify it under the terms of the GNU General Public License //
-// version 2 as published by the Free Software Foundation. //
-// //
-////////////////////////////////////////////////////////////////////
+// ***** BEGIN LICENSE BLOCK *****
+//////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2014 RALOVICH, Kristóf //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+//////////////////////////////////////////////////////////////////////////
+// ***** END LICENSE BLOCK *****
@@ -54,7 +44,9 @@
#define NOMINMAX 1
#include "lusb0_usb.h"
#else
-#include "usb.h"
+#include <errno.h>
+#include <usb.h>
+#include "SerialTty.hpp"
#endif
@@ -67,6 +59,8 @@ const uchar USB_ANT_EP_OUT = 0x01;
+#define LOG_USB_WARN(func, rv) \
+ do { LOG(LOG_WARN) << func << ": " << rv << ": \"" << usb_strerror() << "\"\n"; } while(0)
@@ -81,6 +75,8 @@ struct SerialUsbPrivate
volatile int m_recvThKill;
//AntCallback* m_callback;
usb_dev_handle* dev;
+ unsigned short dev_vid;
+ unsigned short dev_pid;
size_t m_writeDelay;
#define REQTYPE_HOST_TO_INTERFACE 0x41
@@ -91,226 +87,93 @@ struct SerialUsbPrivate
#define USB_CTRL_GET_TIMEOUT 5000
#define USB_CTRL_SET_TIMEOUT 5000
- /* Config request codes */
- #define CP210X_IFC_ENABLE 0x00
- #define CP210X_SET_BAUDDIV 0x01
- #define CP210X_GET_BAUDDIV 0x02
- #define CP210X_SET_LINE_CTL 0x03
- #define CP210X_GET_LINE_CTL 0x04
- #define CP210X_SET_BREAK 0x05
- #define CP210X_IMM_CHAR 0x06
- #define CP210X_SET_MHS 0x07
- #define CP210X_GET_MDMSTS 0x08
- #define CP210X_SET_XON 0x09
- #define CP210X_SET_XOFF 0x0A
- #define CP210X_SET_EVENTMASK 0x0B
- #define CP210X_GET_EVENTMASK 0x0C
- #define CP210X_SET_CHAR 0x0D
- #define CP210X_GET_CHARS 0x0E
- #define CP210X_GET_PROPS 0x0F
- #define CP210X_GET_COMM_STATUS 0x10
- #define CP210X_RESET 0x11
- #define CP210X_PURGE 0x12
- #define CP210X_SET_FLOW 0x13
- #define CP210X_GET_FLOW 0x14
- #define CP210X_EMBED_EVENTS 0x15
- #define CP210X_GET_EVENTSTATE 0x16
- #define CP210X_SET_CHARS 0x19
- #define CP210X_GET_BAUDRATE 0x1D
- #define CP210X_SET_BAUDRATE 0x1E
-
- /* CP210X_IFC_ENABLE */
- #define UART_ENABLE 0x0001
- #define UART_DISABLE 0x0000
-
- /* CP210X_(SET|GET)_BAUDDIV */
- #define BAUD_RATE_GEN_FREQ 0x384000
-
- /* CP210X_(SET|GET)_LINE_CTL */
- #define BITS_DATA_MASK 0X0f00
- #define BITS_DATA_5 0X0500
- #define BITS_DATA_6 0X0600
- #define BITS_DATA_7 0X0700
- #define BITS_DATA_8 0X0800
- #define BITS_DATA_9 0X0900
-
- #define BITS_PARITY_MASK 0x00f0
- #define BITS_PARITY_NONE 0x0000
- #define BITS_PARITY_ODD 0x0010
- #define BITS_PARITY_EVEN 0x0020
- #define BITS_PARITY_MARK 0x0030
- #define BITS_PARITY_SPACE 0x0040
-
- #define BITS_STOP_MASK 0x000f
- #define BITS_STOP_1 0x0000
- #define BITS_STOP_1_5 0x0001
- #define BITS_STOP_2 0x0002
-
- /* CP210X_SET_BREAK */
- #define BREAK_ON 0x0001
- #define BREAK_OFF 0x0000
-
- /* CP210X_(SET_MHS|GET_MDMSTS) */
- #define CONTROL_DTR 0x0001
- #define CONTROL_RTS 0x0002
- #define CONTROL_CTS 0x0010
- #define CONTROL_DSR 0x0020
- #define CONTROL_RING 0x0040
- #define CONTROL_DCD 0x0080
- #define CONTROL_WRITE_DTR 0x0100
- #define CONTROL_WRITE_RTS 0x0200
-
-
-#define TIOCM_DTR 0x002
-#define TIOCM_RTS 0x004
-
- int get_config(int request, char* data, int size)
- {
- if(!dev)
- return -1111;
-
- int index = 0; // bInterfaceNumber ==? USB_ANT_INTERFACE
-
- int irv;
- irv = usb_control_msg(dev, REQTYPE_INTERFACE_TO_HOST, request, 0,
- index, data, size, USB_CTRL_GET_TIMEOUT);
- LOG_VAR(irv);
+#define CP210X_IFC_ENABLE 0x00
+#define CP210X_SET_MHS 0x07
+#define CP210X_SET_BAUDRATE 0x1E
+#define UART_ENABLE 0x0001
- return irv;
- }
+#define CONTROL_DTR 0x0001
+#define CONTROL_RTS 0x0002
+#define CONTROL_WRITE_DTR 0x0100
+#define CONTROL_WRITE_RTS 0x0200
// size in bytes
- int set_config(int request, char* data, int size)
+ bool
+ setConfig(int request, char* data, int size)
{
- if(!dev)
- return -1111;
+ if(!dev || size<0)
+ return false;
int index = 0; // bInterfaceNumber ==? USB_ANT_INTERFACE
- int irv;
+ int irv = -1;
+ int sz = 0;
if(size>2)
{
- irv = usb_control_msg(dev, REQTYPE_HOST_TO_INTERFACE, request, 0,
- index, data, size, USB_CTRL_SET_TIMEOUT);
+ sz = size;
+ irv = usb_control_msg(dev, REQTYPE_HOST_TO_INTERFACE, request, 0, index, data, sz, USB_CTRL_SET_TIMEOUT);
}
else
{
- irv = usb_control_msg(dev, REQTYPE_HOST_TO_INTERFACE, request, data[0],
- index, NULL, 0, USB_CTRL_SET_TIMEOUT);
+ sz = 0;
+ irv = usb_control_msg(dev, REQTYPE_HOST_TO_INTERFACE, request, data[0], index, NULL, sz, USB_CTRL_SET_TIMEOUT);
}
- LOG_VAR(irv);
+ if(irv<0) { LOG_VAR(irv); }
- return irv;
+ return irv==sz;
}
- int set_config_single(int request, unsigned short data)
+ bool
+ cp210xInit()
{
- return set_config(request, reinterpret_cast<char*>(&data), 2);
- }
+ if((dev_vid==0x0fcf) && (dev_pid==0x1008 || dev_pid==0x1009))
+ return true;
- int change_speed(unsigned int baud)
- {
- return set_config(CP210X_SET_BAUDRATE, reinterpret_cast<char*>(&baud), sizeof(baud));
- }
-
- int tiocmset(unsigned int set, unsigned int clear)
- {
- unsigned int control = 0;
-
- if (set & TIOCM_RTS) {
- control |= CONTROL_RTS;
- control |= CONTROL_WRITE_RTS;
- }
- if (set & TIOCM_DTR) {
- control |= CONTROL_DTR;
- control |= CONTROL_WRITE_DTR;
- }
- if (clear & TIOCM_RTS) {
- control &= ~CONTROL_RTS;
- control |= CONTROL_WRITE_RTS;
- }
- if (clear & TIOCM_DTR) {
- control &= ~CONTROL_DTR;
- control |= CONTROL_WRITE_DTR;
- }
-
- lprintf(LOG_INF, "%s - control = 0x%.4x\n", __FUNCTION__, control);
-
- return set_config(CP210X_SET_MHS, reinterpret_cast<char*>(&control), 2);
- }
+ CHECK_RETURN_FALSE(dev);
+ unsigned short word = UART_ENABLE;
+ CHECK_RETURN_FALSE(setConfig(CP210X_IFC_ENABLE, reinterpret_cast<char*>(&word), sizeof(word)));
+ unsigned int baud = 115200;
+ CHECK_RETURN_FALSE(setConfig(CP210X_SET_BAUDRATE, reinterpret_cast<char*>(&baud), sizeof(baud)));
- void
- modprobe()
- {
-// ffff8800364a8300 962108826 S Co:3:001:0 s 23 03 0004 0001 0000 0
-// ffff8800364a8300 962108840 C Co:3:001:0 0 0
-// ffff8800b225b780 962162649 S Ci:3:001:0 s a3 00 0000 0001 0004 4 <
-// ffff8800b225b780 962162697 C Ci:3:001:0 0 4 = 03010000
-// ffff8800b225b780 962218579 S Co:3:001:0 s 23 01 0014 0001 0000 0
-// ffff8800b225b780 962218591 C Co:3:001:0 0 0
-// ffff8800b225b780 962218620 S Ci:3:000:0 s 80 06 0100 0000 0040 64 <
-// ffff8800b225b780 962222272 C Ci:3:000:0 0 18 = 12011001 00000040 cf0f0410 00030102 0301
-// ffff8800364a8300 962222320 S Co:3:001:0 s 23 03 0004 0001 0000 0
-// ffff8800364a8300 962222330 C Co:3:001:0 0 0
-// ffff8800b225b3c0 962274639 S Ci:3:001:0 s a3 00 0000 0001 0004 4 <
-// ffff8800b225b3c0 962274675 C Ci:3:001:0 0 4 = 03010000
-// ffff8800364a8300 962330667 S Co:3:001:0 s 23 01 0014 0001 0000 0
-// ffff8800364a8300 962330676 C Co:3:001:0 0 0
-// ffff8800364a8300 962330685 S Co:3:000:0 s 00 05 0002 0000 0000 0
-// ffff8800364a8300 962333269 C Co:3:000:0 0 0
-// ffff8800b225b3c0 962350649 S Ci:3:002:0 s 80 06 0100 0000 0012 18 <
-// ffff8800b225b3c0 962354268 C Ci:3:002:0 0 18 = 12011001 00000040 cf0f0410 00030102 0301
-// ffff8800b225b3c0 962354312 S Ci:3:002:0 s 80 06 0200 0000 0020 32 <
-// ffff8800b225b3c0 962357263 C Ci:3:002:0 0 32 = 09022000 01010080 32090400 0002ff00 00020705 81024000 00070501 02400000
-// ffff8800364a8300 962357309 S Ci:3:002:0 s 80 06 0303 0409 00ff 255 <
-// ffff8800364a8300 962364268 C Ci:3:002:0 0 128 = 80033100 30003000 36003200 00001400 28002f00 f300a700 18003a00 80004700
-// ffff8800b225ba80 962364316 S Co:3:002:0 s 00 09 0001 0000 0000 0
-// ffff8800b225ba80 962366264 C Co:3:002:0 0 0
- if(!dev)
- return;
-
- //cp210x_startup: usb_reset_device
-
- set_config_single(CP210X_IFC_ENABLE, UART_ENABLE);
- //cp2101_set_config_single(port, CP210X_IFC_ENABLE, UART_ENABLE);
- /* Configure the termios structure */
- //cp2101_get_termios(port);
- change_speed(115200);
- /* Set the DTR and RTS pins low */
- //cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0);
- tiocmset(TIOCM_DTR | TIOCM_RTS, 0);
+ unsigned int control = 0;
+ control |= CONTROL_RTS;
+ control |= CONTROL_WRITE_RTS;
+ control |= CONTROL_DTR;
+ control |= CONTROL_WRITE_DTR;
+ CHECK_RETURN_FALSE(setConfig(CP210X_SET_MHS, reinterpret_cast<char*>(&control), 2));
+ return true;
}
- void
- open_tty()
- {}
-
usb_dev_handle*
- libUSBGetDevice (unsigned short vid, unsigned short pid)
+ libUSBGetDevice (const unsigned short vid, const unsigned short pid)
{
struct usb_bus *UsbBus = NULL;
struct usb_device *UsbDevice = NULL;
- usb_dev_handle *ret;
+ usb_dev_handle *udev;
int dBuses, dDevices;
dBuses = usb_find_busses ();
dDevices = usb_find_devices ();
- LOG_VAR2(dBuses, dDevices);
- lprintf(LOG_INF, "bus: %s, dev: %s, vid: 0x%04hx, pid: 0x%04hx\n", "", "", vid, pid);
+ //LOG_VAR2(dBuses, dDevices);
+ //lprintf(LOG_INF, "bus: %s, dev: %s, vid: 0x%04hx, pid: 0x%04hx\n", "", "", vid, pid);
+ UNUSED(dBuses);
+ UNUSED(dDevices);
for (UsbBus = usb_get_busses(); UsbBus; UsbBus = UsbBus->next)
{
bool found = false;
for (UsbDevice = UsbBus->devices; UsbDevice; UsbDevice = UsbDevice->next)
{
- lprintf(LOG_INF, "bus: %s, dev: %s, vid: 0x%04hx, pid: 0x%04hx\n", UsbBus->dirname, UsbDevice->filename, UsbDevice->descriptor.idVendor, UsbDevice->descriptor.idProduct);
+ //lprintf(LOG_INF, "bus: %s, dev: %s, vid: 0x%04hx, pid: 0x%04hx\n", UsbBus->dirname, UsbDevice->filename, UsbDevice->descriptor.idVendor, UsbDevice->descriptor.idProduct);
if (UsbDevice->descriptor.idVendor == vid && UsbDevice->descriptor.idProduct== pid)
{
- lprintf(LOG_INF, "found!\n");
+ //lprintf(LOG_INF, "found!\n");
found = true;
+ dev_vid = vid;
+ dev_pid = pid;
break;
}
}
@@ -319,26 +182,47 @@ struct SerialUsbPrivate
}
if (!UsbDevice) return NULL;
- ret = usb_open (UsbDevice);
+ udev = usb_open (UsbDevice);
+ if(!udev)
+ {
+ LOG_USB_WARN("usb_open", (void*)udev);
+ return NULL;
+ }
+ int rv = 0;
+ char string[256];
+ if(0 < usb_get_string_simple(udev, UsbDevice->descriptor.iProduct, string, sizeof(string)))
+ {
+ LOG(LOG_INF) << string << "\n";
+ }
+ if(0 < usb_get_string_simple(udev, UsbDevice->descriptor.iManufacturer, string, sizeof(string)))
+ {
+ LOG(LOG_INF) << string << "\n";
+ }
+ if(0 < usb_get_string_simple(udev, UsbDevice->descriptor.iSerialNumber, string, sizeof(string)))
+ {
+ LOG(LOG_INF) << string << "\n";
+ }
//int cfg = usb_get_configuration(UsbDevice);
- int rv=usb_set_configuration (ret, USB_ANT_CONFIGURATION);
- LOG_VAR(rv);
- if (rv < 0) {
- usb_close (ret);
+ rv=usb_set_configuration (udev, USB_ANT_CONFIGURATION);
+ if(rv < 0)
+ {
+ LOG_USB_WARN("USB_ANT_CONFIGURATION", rv);
+ usb_close (udev);
return NULL;
}
- rv=usb_claim_interface (ret, USB_ANT_INTERFACE);
- LOG_VAR(rv);
- if (rv < 0) {
- usb_close (ret);
+ rv=usb_claim_interface (udev, USB_ANT_INTERFACE);
+ if(rv < 0)
+ {
+ LOG_USB_WARN("USB_ANT_INTERFACE", rv);
+ usb_close (udev);
return NULL;
}
- return ret;
+ return udev;
}
};
@@ -351,6 +235,8 @@ SerialUsb::SerialUsb()
m_p.reset(new SerialUsbPrivate());
m_p->m_recvThKill = 0;
m_p->dev = 0;
+ m_p->dev_vid = 0;
+ m_p->dev_pid = 0;
m_p->m_writeDelay = 0;
usb_init();
@@ -360,7 +246,7 @@ SerialUsb::SerialUsb()
SerialUsb::~SerialUsb()
{
close();
- m_p.reset();
+ lprintf(LOG_DBG2, "%s\n", __FUNCTION__);
}
//#define ENSURE_OR_RETURN_FALSE(e) do { if(-1 == (e)) {perror(#e); return false;} } while(false)
@@ -387,43 +273,47 @@ struct AntUsbHandler2_Recevier
bool
SerialUsb::open()
{
- close();
+ assert(!isOpen());
+ if(isOpen())
+ return false;
+
+ enum {NUM_DEVS=5};
+ uint16_t known[NUM_DEVS][2] =
+ {
+ {0x0fcf, 0x1003},
+ {0x0fcf, 0x1004},
+ {0x0fcf, 0x1006},
+ {0x0fcf, 0x1008},
+ {0x0fcf, 0x1009},
+ };
//bool rv = false;
// ffff8800b1c470c0 1328871577 S Co:3:002:0 s 00 09 0001 0000 0000 0
// ffff8800b1c470c0 1328873340 C Co:3:002:0 0 0
- m_p->dev = m_p->libUSBGetDevice(0x0fcf, 0x1004);
- if(!m_p->dev)
+ for(size_t i = 0; i < NUM_DEVS; i++)
{
- m_p->dev = m_p->libUSBGetDevice(0x0fcf, 0x1008);
- if(!m_p->dev)
+ uint16_t vid = known[i][0];
+ uint16_t pid = known[i][1];
+ LOG(LOG_INF) << "Trying to open vid=0x" << toString(vid,4,'0') << ", pid=0x" << toString(pid,4,'0') << " ...\n";
+ m_p->dev = m_p->libUSBGetDevice(vid, pid);
+ if(m_p->dev)
{
- return false;
+ LOG(LOG_INF) << "Opened vid=0x" << toString(vid,4,'0') << ", pid=0x" << toString(pid,4,'0') << " OK.\n";
+ break;
}
+ //LOG(LOG_RAW) << " failed.\n";
+ }
+ if(!m_p->dev)
+ {
+ LOG(antpm::LOG_ERR) << "Opening any known usb VID/PID failed!\n";
+ return false;
}
- m_p->modprobe();
-
- m_p->open_tty();
-
- //cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)
- /* Configure the termios structure */
- //cp2101_get_termios(port);
- /* Set the DTR and RTS pins low */
- //cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0);
-
- // ffff8800b1c470c0 1328873580 S Co:3:002:0 s 02 01 0000 0001 0000 0
- // ffff8800b1c470c0 1328874338 C Co:3:002:0 0 0
- //int irv = usb_clear_halt(m_p->dev, USB_ANT_EP_OUT);
- //LOG_VAR(irv);
+ assert(m_p->dev_vid!=0);
+ assert(m_p->dev_pid!=0);
- // usb_clear_halt()
- // usb_get_string_simple()
- // usb_reset()
- // usb_device()
- // usb_set_configuration()
- // usb_set_debug()
+ CHECK_RETURN_FALSE(m_p->cp210xInit());
m_p->m_recvThKill = 0;
AntUsbHandler2_Recevier recTh;
@@ -438,11 +328,15 @@ SerialUsb::open()
void
SerialUsb::close()
{
- m_p->m_recvThKill = 1;
- m_p->m_recvTh.join();
-
if(m_p.get())
{
+ m_p->m_recvThKill = 1;
+ {
+ boost::unique_lock<boost::mutex> lock(m_p->m_queueMtx);
+ m_p->m_condQueue.notify_all(); // make sure an other thread calling readBlocking() moves on too
+ }
+ m_p->m_recvTh.join();
+
if(m_p->dev)
{
//usb_reset(m_p->dev);
@@ -450,8 +344,9 @@ SerialUsb::close()
usb_close(m_p->dev);
}
m_p->dev = 0;
+ m_p->m_writeDelay = 0;
+ m_p.reset();
}
- m_p->m_writeDelay = 0;
}
@@ -536,8 +431,7 @@ SerialUsb::write(const char* src, const size_t sizeBytes, size_t& bytesWritten)
int written = usb_bulk_write(m_p->dev, USB_ANT_EP_OUT, const_cast<char*>(src), size, 3000);
if(written < 0)
{
- char* usberr=usb_strerror();
- LOG_VAR(usberr);
+ LOG_USB_WARN("SerialUsb::write", written);
return false;
}
@@ -573,12 +467,16 @@ SerialUsb::receiveHandler()
}
else if(rv==0)
{}
+#ifdef _WIN32
else if(rv==-116) // timeout
{}
+#else
+ else if(rv==-ETIMEDOUT)
+ {}
+#endif
else
{
- char* usberr=usb_strerror();
- LOG_VAR2(rv, usberr);
+ LOG_USB_WARN("SerialUsb::receiveHandler", rv);
}
}
@@ -594,15 +492,6 @@ const size_t SerialUsb::getQueueLength() const
}
-//// called from other thread
-//void
-//AntUsbHandler::queueData()
-//{
-//}
-
-
-
-
bool
SerialUsb::isOpen() const
{
@@ -620,4 +509,5 @@ SerialUsb::setWriteDelay(const size_t ms)
+
}
diff --git a/src/VERSION b/src/VERSION
index 07fe6f6..03ff897 100644
--- a/src/VERSION
+++ b/src/VERSION
@@ -1 +1 @@
-1.15 \ No newline at end of file
+1.16 \ No newline at end of file
diff --git a/src/antdefs.cpp b/src/antdefs.cpp
new file mode 100644
index 0000000..62ef2d3
--- /dev/null
+++ b/src/antdefs.cpp
@@ -0,0 +1,107 @@
+// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*-
+// ***** BEGIN LICENSE BLOCK *****
+//////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2014 RALOVICH, Kristóf //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+//////////////////////////////////////////////////////////////////////////
+// ***** END LICENSE BLOCK *****
+
+#include "antdefs.hpp"
+
+namespace antpm {
+
+#define ANTP_PAIR(x) {x,#x}
+
+MsgNames msgNames[]={
+ ANTP_PAIR(MESG_EVENT_ID),
+ ANTP_PAIR(MESG_ACKNOWLEDGED_DATA_ID),
+ ANTP_PAIR(MESG_ASSIGN_CHANNEL_ID),
+ ANTP_PAIR(MESG_BROADCAST_DATA_ID),
+ ANTP_PAIR(MESG_BURST_DATA_ID),
+ ANTP_PAIR(MESG_CAPABILITIES_ID),
+ ANTP_PAIR(MESG_CHANNEL_ID_ID),
+ ANTP_PAIR(MESG_CHANNEL_MESG_PERIOD_ID),
+ ANTP_PAIR(MESG_CHANNEL_RADIO_FREQ_ID),
+ ANTP_PAIR(MESG_CHANNEL_SEARCH_TIMEOUT_ID),
+ ANTP_PAIR(MESG_CHANNEL_STATUS_ID),
+ ANTP_PAIR(MESG_VERSION_ID),
+ ANTP_PAIR(MESG_CLOSE_CHANNEL_ID),
+ ANTP_PAIR(MESG_EXT_ACKNOWLEDGED_DATA_ID),
+ ANTP_PAIR(MESG_EXT_BROADCAST_DATA_ID),
+ ANTP_PAIR(MESG_EXT_BURST_DATA_ID),
+ ANTP_PAIR(MESG_NETWORK_KEY_ID),
+ ANTP_PAIR(MESG_OPEN_CHANNEL_ID),
+ ANTP_PAIR(MESG_OPEN_RX_SCAN_ID),
+ ANTP_PAIR(MESG_REQUEST_ID),
+ ANTP_PAIR(MESG_RESPONSE_EVENT_ID),
+ ANTP_PAIR(MESG_SEARCH_WAVEFORM_ID),
+ ANTP_PAIR(MESG_SYSTEM_RESET_ID),
+ ANTP_PAIR(MESG_UNASSIGN_CHANNEL_ID),
+ ANTP_PAIR(MESG_GET_SERIAL_NUM_ID),
+ ANTP_PAIR(MESG_STARTUP_MSG_ID),
+ {-1,"UNKNOWN"}
+};
+
+
+ResponseNames responseNames[]={
+ ANTP_PAIR(RESPONSE_NO_ERROR),
+ ANTP_PAIR(EVENT_RX_SEARCH_TIMEOUT),
+ ANTP_PAIR(EVENT_RX_FAIL),
+ ANTP_PAIR(EVENT_TX),
+ ANTP_PAIR(EVENT_TRANSFER_RX_FAILED),
+ ANTP_PAIR(EVENT_TRANSFER_TX_COMPLETED),
+ ANTP_PAIR(EVENT_TRANSFER_TX_FAILED),
+ ANTP_PAIR(EVENT_CHANNEL_CLOSED),
+ ANTP_PAIR(EVENT_RX_FAIL_GO_TO_SEARCH),
+ ANTP_PAIR(EVENT_CHANNEL_COLLISION),
+ ANTP_PAIR(EVENT_TRANSFER_TX_START),
+ ANTP_PAIR(CHANNEL_IN_WRONG_STATE),
+ ANTP_PAIR(CHANNEL_NOT_OPENED),
+ ANTP_PAIR(CHANNEL_ID_NOT_SET),
+ ANTP_PAIR(CLOSE_ALL_CHANNELS),
+ ANTP_PAIR(TRANSFER_IN_PROGRESS),
+ ANTP_PAIR(TRANSFER_SEQUENCE_NUMBER_ERROR),
+ ANTP_PAIR(TRANSFER_IN_ERROR),
+ {-1,"UNKNOWN"}
+};
+
+AntFSCommandNames antFSCommandNames[]={
+ ANTP_PAIR(ANTFS_CmdLink),
+ ANTP_PAIR(ANTFS_CmdDisconnect),
+ ANTP_PAIR(ANTFS_CmdAuthenticate),
+ ANTP_PAIR(ANTFS_CmdPing),
+ ANTP_PAIR(ANTFS_ReqDownload),
+ ANTP_PAIR(ANTFS_ReqUpload),
+ ANTP_PAIR(ANTFS_ReqErase),
+ ANTP_PAIR(ANTFS_UploadData),
+ ANTP_PAIR(ANTFS_CmdDirect),
+ {-1,"UNKNOWN"}
+};
+
+AntFSResponseNames antFSResponseNames[]={
+ ANTP_PAIR(ANTFS_RespAuthenticate),
+ ANTP_PAIR(ANTFS_RespDownload),
+ ANTP_PAIR(ANTFS_RespUpload),
+ ANTP_PAIR(ANTFS_RespErase),
+ ANTP_PAIR(ANTFS_RespUploadData),
+ ANTP_PAIR(ANTFS_RespDirect),
+ {-1,"UNKNOWN"}
+};
+
+
+#undef ANTP_PAIR
+
+
+
+}
+
diff --git a/src/antdefs.hpp b/src/antdefs.hpp
index 52b1223..9541d94 100644
--- a/src/antdefs.hpp
+++ b/src/antdefs.hpp
@@ -75,7 +75,7 @@ typedef uint32_t uint;
#define MESG_GET_SERIAL_NUM_ID 0x61
-
+#define MESG_STARTUP_MSG_ID 0x6f
#define MESG_DATA_SIZE 30
@@ -162,6 +162,7 @@ extern struct AntFSResponseNames {int i; const char* s; } antFSResponseNames[];
ENUMERATE1(ST_ANTFS_DL_DIRECTORY, 1024) \
ENUMERATE1(ST_ANTFS_DL_FILES, 1025) \
ENUMERATE1(ST_ANTFS_DL_SINGLE_FILE, 1027) \
+ ENUMERATE1(ST_ANTFS_GINTF_DL_CAPS, 1034) \
ENUMERATE1(ST_ANTFS_ERASE_SINGLE_FILE, 500) \
ENUMERATE1(ST_ANTFS_BAD, 1006) \
ENUMERATE1(ST_ANTFS_LAST, 1007)
diff --git a/src/antpm-downloader.cpp b/src/antpm-downloader.cpp
index ff8fcd3..2d1b1dd 100644
--- a/src/antpm-downloader.cpp
+++ b/src/antpm-downloader.cpp
@@ -133,19 +133,19 @@ main(int argc, char** argv)
signal(SIGINT, my_handler);
#endif
-#ifndef NDEBUG
- antpm::Log::instance()->setLogReportingLevel(antpm::LOG_DBG);
-#else
+ antpm::Log::instance()->addSink(std::cout);
+#ifdef NDEBUG
antpm::Log::instance()->setLogReportingLevel(antpm::LOG_INF);
+#else
+ antpm::Log::instance()->setLogReportingLevel(antpm::LOG_DBG);
#endif
- antpm::Log::instance()->addSink(std::cout);
// Declare the supported options.
- bool pairing =false;
- bool dirOnly =false;
- uint16_t dlFileIdx =0x0000;
- uint16_t eraseFileIdx=0x0000;
- int verbosityLevel = antpm::Log::instance()->getLogReportingLevel();
+ bool pairing = false;
+ bool dirOnly = false;
+ uint16_t dlFileIdx = 0x0000;
+ uint16_t eraseFileIdx = 0x0000;
+ int verbosityLevel = antpm::Log::instance()->getLogReportingLevel();
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
@@ -206,8 +206,13 @@ main(int argc, char** argv)
logger() << desc << "\n";
return EXIT_SUCCESS;
}
- LOG_VAR4(pairing, dirOnly, int(dlFileIdx), int(eraseFileIdx));
+ LOG_VAR5(pairing, dirOnly, dlFileIdx, eraseFileIdx, verbosityLevel);
+ LOG(antpm::LOG_DBG) << argv[0] << " " << antpm::getVersionString() << "\n";
+ for(int i = 0; i < argc; i++)
+ {
+ LOG(antpm::LOG_DBG2) << "\targv[" << i << "]\t\"" << argv[i] << "\"" << endl;
+ }
char* ANTPM_405 = getenv("ANTPM_405");
if(ANTPM_405!=NULL && strncmp("1",ANTPM_405,1)==0)
@@ -242,7 +247,7 @@ main(int argc, char** argv)
watch2.start();
- watch2.stop();
+ //watch2.stop();
}
}
diff --git a/src/common.cpp b/src/common.cpp
index 2babc48..d72636d 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -28,7 +28,6 @@
#include <boost/date_time.hpp>
#include <boost/filesystem.hpp>
#include "Log.hpp"
-#include "antdefs.hpp"
namespace antpm {
@@ -185,7 +184,7 @@ readUInt64(const uint clientSN, uint64_t& pairedKey)
std::stringstream ss;
ss << getConfigFolder() << "libantpmauth_" << clientSN;
FILE* f=fopen(ss.str().c_str(), "r");
- LOG_VAR2(ss.str(), f);
+ LOG_VAR3(ss.str(), f, pairedKey);
if(f)
{
if(1 != fread(&pairedKey, sizeof(pairedKey), 1, f))
@@ -200,7 +199,7 @@ writeUInt64(const uint clientSN, const uint64_t& pairedKey)
std::stringstream ss;
ss << getConfigFolder() << "libantpmauth_" << clientSN;
FILE* f=fopen(ss.str().c_str(), "w+");
- LOG_VAR2(ss.str(), f);
+ LOG_VAR3(ss.str(), f, pairedKey);
if(f)
{
fwrite(&pairedKey, sizeof(pairedKey), 1, f);
@@ -297,10 +296,14 @@ getVersionString()
{
return std::string("") + APP_NAME
+ " v" + std::string(BOOST_STRINGIZE(ANTPM_VERSION))
- + " built " __DATE__ "" //+#ANTPM_SERIAL_IMPL
+ + " built " __DATE__ " " + __TIME__ + "" //+#ANTPM_SERIAL_IMPL
+ " under "
#ifdef __linux__
- "linux"
+# ifdef __LP64__
+ "linux64"
+# else
+ "linux32"
+# endif
#elif defined(_WIN64)
"win64"
#elif defined(_WIN32)
@@ -339,89 +342,6 @@ getVersionString()
-#define ANTP_PAIR(x) {x,#x}
-
-MsgNames msgNames[]={
- ANTP_PAIR(MESG_EVENT_ID),
- ANTP_PAIR(MESG_ACKNOWLEDGED_DATA_ID),
- ANTP_PAIR(MESG_ASSIGN_CHANNEL_ID),
- ANTP_PAIR(MESG_BROADCAST_DATA_ID),
- ANTP_PAIR(MESG_BURST_DATA_ID),
- ANTP_PAIR(MESG_CAPABILITIES_ID),
- ANTP_PAIR(MESG_CHANNEL_ID_ID),
- ANTP_PAIR(MESG_CHANNEL_MESG_PERIOD_ID),
- ANTP_PAIR(MESG_CHANNEL_RADIO_FREQ_ID),
- ANTP_PAIR(MESG_CHANNEL_SEARCH_TIMEOUT_ID),
- ANTP_PAIR(MESG_CHANNEL_STATUS_ID),
- ANTP_PAIR(MESG_VERSION_ID),
- ANTP_PAIR(MESG_GET_SERIAL_NUM_ID),
- ANTP_PAIR(MESG_CLOSE_CHANNEL_ID),
- ANTP_PAIR(MESG_EXT_ACKNOWLEDGED_DATA_ID),
- ANTP_PAIR(MESG_EXT_BROADCAST_DATA_ID),
- ANTP_PAIR(MESG_EXT_BURST_DATA_ID),
- ANTP_PAIR(MESG_NETWORK_KEY_ID),
- ANTP_PAIR(MESG_OPEN_CHANNEL_ID),
- ANTP_PAIR(MESG_OPEN_RX_SCAN_ID),
- ANTP_PAIR(MESG_REQUEST_ID),
- ANTP_PAIR(MESG_RESPONSE_EVENT_ID),
- ANTP_PAIR(MESG_SEARCH_WAVEFORM_ID),
- ANTP_PAIR(MESG_SYSTEM_RESET_ID),
- ANTP_PAIR(MESG_UNASSIGN_CHANNEL_ID),
- {-1,"UNKNOWN"}
-};
-
-
-ResponseNames responseNames[]={
- ANTP_PAIR(RESPONSE_NO_ERROR),
- ANTP_PAIR(EVENT_RX_SEARCH_TIMEOUT),
- ANTP_PAIR(EVENT_RX_FAIL),
- ANTP_PAIR(EVENT_TX),
- ANTP_PAIR(EVENT_TRANSFER_RX_FAILED),
- ANTP_PAIR(EVENT_TRANSFER_TX_COMPLETED),
- ANTP_PAIR(EVENT_TRANSFER_TX_FAILED),
- ANTP_PAIR(EVENT_CHANNEL_CLOSED),
- ANTP_PAIR(EVENT_RX_FAIL_GO_TO_SEARCH),
- ANTP_PAIR(EVENT_CHANNEL_COLLISION),
- ANTP_PAIR(EVENT_TRANSFER_TX_START),
- ANTP_PAIR(CHANNEL_IN_WRONG_STATE),
- ANTP_PAIR(CHANNEL_NOT_OPENED),
- ANTP_PAIR(CHANNEL_ID_NOT_SET),
- ANTP_PAIR(CLOSE_ALL_CHANNELS),
- ANTP_PAIR(TRANSFER_IN_PROGRESS),
- ANTP_PAIR(TRANSFER_SEQUENCE_NUMBER_ERROR),
- ANTP_PAIR(TRANSFER_IN_ERROR),
- {-1,"UNKNOWN"}
-};
-
-AntFSCommandNames antFSCommandNames[]={
- ANTP_PAIR(ANTFS_CmdLink),
- ANTP_PAIR(ANTFS_CmdDisconnect),
- ANTP_PAIR(ANTFS_CmdAuthenticate),
- ANTP_PAIR(ANTFS_CmdPing),
- ANTP_PAIR(ANTFS_ReqDownload),
- ANTP_PAIR(ANTFS_ReqUpload),
- ANTP_PAIR(ANTFS_ReqErase),
- ANTP_PAIR(ANTFS_UploadData),
- ANTP_PAIR(ANTFS_CmdDirect),
- {-1,"UNKNOWN"}
-};
-
-AntFSResponseNames antFSResponseNames[]={
- ANTP_PAIR(ANTFS_RespAuthenticate),
- ANTP_PAIR(ANTFS_RespDownload),
- ANTP_PAIR(ANTFS_RespUpload),
- ANTP_PAIR(ANTFS_RespErase),
- ANTP_PAIR(ANTFS_RespUploadData),
- ANTP_PAIR(ANTFS_RespDirect),
- {-1,"UNKNOWN"}
-};
-
-
-#undef ANTP_PAIR
-
-
-
-
diff --git a/src/common.hpp b/src/common.hpp
index c5e5868..48912dc 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -28,13 +28,17 @@ namespace antpm {
#define CHECK_RETURN_FALSE(x) do { if(!(x)) { lprintf(antpm::LOG_ERR, "%s\n", #x); return false; } /*else { printf("ok: %s\n", #x); }*/ } while(0)
#define CHECK_RETURN_FALSE_LOG_OK(x) do { if(!(x)) { lprintf(antpm::LOG_ERR, "%s\n", #x); return false; } else { printf("ok: %s\n", #x); } } while(0)
+#define CHECK_RETURN_FALSE_LOG_OK_DBG2(x) do { if(!(x)) { lprintf(antpm::LOG_ERR, "%s\n", #x); return false; } else { lprintf(antpm::LOG_DBG2, "ok: %s\n", #x); } } while(0)
#define CHECK_RETURN_RV(x, rv) do { if(!(x)) { lprintf(antpm::LOG_ERR, "%s\n", #x); return rv; } /*else { printf("ok: %s\n", #x); }*/ } while(0)
#define CHECK_RETURN_RV_LOG_OK(x, rv) do { if(!(x)) { lprintf(antpm::LOG_ERR, "%s\n", #x); return rv; } else { printf("ok: %s\n", #x); } } while(0)
#define CHECK_RETURN(x) do { if(!(x)) { lprintf(antpm::LOG_ERR, "%s\n", #x); return; } else { printf("ok: %s\n", #x); } fflush(stdout); } while(0)
#define LOG_VAR(x) do { LOG(antpm::LOG_INF) << #x << "= " << x << std::endl; } while(0)
+#define LOG_VAR_DBG2(x) do { LOG(antpm::LOG_DBG2) << #x << "= " << x << std::endl; } while(0)
#define LOG_VAR2(x,y) do { LOG(antpm::LOG_INF) << #x << "= " << x << ", " #y << "= " << y << std::endl; } while(0)
#define LOG_VAR3(x,y, z) do { LOG(antpm::LOG_INF) << #x "= " << x << ", " #y "= " << y << ", " #z "= " << z << std::endl; } while(0)
#define LOG_VAR4(x,y, z, w) do { LOG(antpm::LOG_INF) << #x "= " << x << ", " #y "= " << y << ", " #z "= " << z << ", " #w "= " << w << std::endl; } while(0)
+#define LOG_VAR5(x,y, z, w,v) do { LOG(antpm::LOG_INF) << #x "= " << x << ", " #y "= " << y << ", " #z "= " << z << ", " #w "= " << w << ", " #v "= " << v << std::endl; } while(0)
+#define UNUSED(x) (void)(x)
//std::ostream& logger();
#define logger() LOG(antpm::LOG_INF)
diff --git a/src/gant/antdefs.h b/src/gant/antdefs.h
index 1112012..0b83447 100644
--- a/src/gant/antdefs.h
+++ b/src/gant/antdefs.h
@@ -1,5 +1,5 @@
-// copyright 2008-2009 paul@ant.sbrk.co.uk. released under GPLv3
-// vers 0.6t
+/* copyright 2008-2009 paul@ant.sbrk.co.uk. released under GPLv3 */
+/* vers 0.6t */
#ifndef __ANTDEFS_H__
#define __ANTDEFS_H__
diff --git a/src/gant/antlib.c b/src/gant/antlib.c
index 7d5b77a..26e880f 100644
--- a/src/gant/antlib.c
+++ b/src/gant/antlib.c
@@ -1,5 +1,5 @@
-// copyright 2008 paul@ant.sbrk.co.uk. released under GPLv3
-// vers 0.6t
+/* copyright 2008 paul@ant.sbrk.co.uk. released under GPLv3 */
+/* vers 0.6t */
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -13,14 +13,10 @@
#define __declspec(X)
#include "antdefs.h"
-//#include "antdefines.h"
-//#include "ANT_Interface.h"
-//#include "antmessage.h"
-//#include "anttypes.h"
#define S(e) do { if (-1 == (e)) {perror(#e); return 0;} } while(0)
-#define MAXMSG 30 // SYNC,LEN,MSG,data[9+],CHKSUM
+#define MAXMSG 30 /* SYNC,LEN,MSG,data[9+],CHKSUM */
#define MAXCHAN 32
#define BSIZE 8*10000
@@ -45,7 +41,7 @@ struct msg_queue {
uchar len;
};
-// send message over serial port
+/* send message over serial port */
uchar
msg_send(uchar mesg, uchar *inbuf, uchar len)
{
diff --git a/src/gant/gant.c b/src/gant/gant.c
index ed5e542..585be4d 100644
--- a/src/gant/gant.c
+++ b/src/gant/gant.c
@@ -1,6 +1,6 @@
-// copyright 2010 Klaus@Ethgen.de. released under GPLv3
-// copyright 2008-2009 paul@ant.sbrk.co.uk
-// copyright 2009-2009 Wali
+/* copyright 2010 Klaus@Ethgen.de. released under GPLv3 */
+/* copyright 2008-2009 paul@ant.sbrk.co.uk */
+/* copyright 2009-2009 Wali */
#include <stdio.h>
#include <sys/select.h>
#include <sys/time.h>
@@ -56,7 +56,7 @@ struct _lap {
int trigger;
};
-// all version numbering according ant agent for windows 2.2.1
+/* all version numbering according ant agent for windows 2.2.1 */
char *releasetime = "Apr 25 2010, 10:00:00";
uint majorrelease = 2;
uint minorrelease = 2;
@@ -76,7 +76,7 @@ int seenphase0 = 0;
int lastphase;
int sentack2;
int newfreq = 0;
-int period = 0x1000; // garmin specific broadcast period
+int period = 0x1000; /* garmin specific broadcast period */
int donebind = 0;
int sentgetv;
char *fname = "garmin";
diff --git a/src/lqueue.hpp b/src/lqueue.hpp
index 02fdc44..1b52c07 100644
--- a/src/lqueue.hpp
+++ b/src/lqueue.hpp
@@ -143,7 +143,8 @@ public:
continue;
}
- assert(!Super::m_q.empty());
+ if(Super::m_q.empty())
+ continue; // spurious wakeup
size_t s = Super::m_q.size();
std::vector<DataType> v(s);
for(size_t i = 0; i < s; i++)