Esempio n. 1
0
def export_tcx(device_sn, raw_file_name, output_dir):
    """
    Given a garmin raw packet dump, tcx to specified output directory.
    """
    with open(raw_file_name) as file:
        result = []
        host = garmin.MockHost(file.read())
        host.device_id = device_sn
        device = garmin.Device(host)
        run_pkts = device.get_runs()
        runs = garmin.extract_runs(device, run_pkts)
        for run in runs:
            tcx_name = time.strftime("%Y%m%d-%H%M%S.tcx", run.time.gmtime)
            tcx_full_path = os.path.sep.join([output_dir, tcx_name])
            _log.info("tcx: writing %s -> %s.",
                      os.path.basename(raw_file_name), tcx_full_path)
            with open(tcx_full_path, "w") as file:
                doc = create_document(device, [run])
                file.write(
                    etree.tostring(doc,
                                   pretty_print=True,
                                   xml_declaration=True,
                                   encoding="UTF-8"))
            result.append(tcx_full_path)
        return result
Esempio n. 2
0
# 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.


import sys
import logging
import lxml.etree as etree

import antd.garmin as garmin
import antd.tcx as tcx
import antd.cfg as cfg

cfg.init_loggers(logging.DEBUG, out=sys.stderr)

if len(sys.argv) != 2:
	print "usage: %s <file>" % sys.argv[0]
	sys.exit(1)

with open(sys.argv[1]) as file:
	host = garmin.MockHost(file.read())
	#device = garmin.Device(host)
	for idx, pkt in enumerate(host.reader):
		if pkt:
			pid, length, data = garmin.unpack(pkt)
			data = "\n".join([(d if not idx else (" " * 23) + d) for idx, d in enumerate(garmin.chunk(data.encode("hex"), 32))])
			print "%04d pid=%04x len=%04x %s" % (idx, pid, length, data)
		else:
			print "%04d EOF" % idx