First release of GarminSync

I have been working on a program that can download data from my Garmin Edge 305 GPS in Linux, and now I’ve finally got something that’s work. The program is called GarminSync, and you can download it from Launchpad.

Please try it out, but don’t expect too much from it. My main focus has been to get something working, now I’m going to focus more on getting it somewhat stable. There are a tons of bugs, for example it sometimes doesn’t work to download the data, and you have to simply try to run it again, and/or reconnect the GPS. But at least it’s able to download the runs from my GPS and export them to TCX files. It should be possible to such files to MotionBased, but it seems like the format is slightly wrong. At the moment I can’t get the GPS to work in VMWare, so I haven’t been able to get a correct file to compare with.

GarminSync is written in Python, so it probably works on other platforms than Linux as well, but I haven’t tried yet.

USB support in pygarmin

While extending pygarmin to support my Garmin Edge 305, I ran into a problem; pygarmin uses the serial protocol, and some packets that the Edge sends are too big for the serial protocol to handle. So when you request some information from the GPS, you don’t get any response back. The solution to this was to add native USB support to pygarmin, making it possible to use the USB protocol to talk to the GPS.

This turned out to be a quite fun task, actually, pyusb makes it easy to communicate to USB devices using Python. Of course it wasn’t entirely trivial, since the Garmin protocol specification seems to be out of date, so not everything the Edge 305 does is documented. But last night I finally managed to get something working, I can now specify "usb:" as the device to use, so that the USB protocol will be used instead of the serial one. It actually seems to work quite well, although there are some bugs still.

For those of you brave enough, I’d love to get feedback whether it works for you, especially if you have some other Garmin GPS than the Edge 305. You can test it by getting my edge-305 branch of pygarmin and try the following (which should write out some information about your GPS):

./pygarmin -p "usb:"

Using Launchpad to contribute to projects

While modifying pygarmin to support my Edge 305, I was faced with the problem how to submit my patches to be included in pygarmin; I don’t have commit access, so I can’t commit the changes myself. One way of doing it is of course to generate a diff, and attach a patch to their patch tracker. That has some problems, though, especially since I want to submit a series of patches. The main problem is how to get people to try out the patches. They would have to apply each patch to their version of the source code, and some patches might not apply cleanly after a while.

So, instead of submitting patches to their patch tracker, I make use of Launchpad. It has a nice feature that you can import the project’s source code and make it available as a bazaar branch. By importing the code, I can subscribe to pygarmin’s main branch in Launchpad, and get an e-mail notification when someone commits to the branch. But more importantly, I can now easily create a new branch to add support for my Garmin Edge 305:

bettan:~> bzr branch lp:pygarmin edge-305 Branched 82 revision(s).

Now I can hack on pygarmin and keep my changes versioned in bazaar, making it easier to keep my patches up-to-date. If code get commited to the trunk branch, I can simply merge and resolve the conflicts:

bettan:~/edge-305> bzr merge lp:pygarmin

The next thing I want to do is to publish my changes, so that other people can look at them. I do this by pushing my branch to Launchpad:

bzr push bzr+ssh://bjornt@bazaar.launchpad.net/~bjornt/pygarmin/edge-305

After doing this, the first time, the branch gets registered in Launchpad automatically, and the branch shows up under “Latest code” on the pygarmin page. People can now look and subscribe to my branch to see what changes I make. They can also choose “Browse code” to see the code, and see the diff of each revision I commit.

If I want someone to try out my changes, I can tell them to get my branch from Launchpad:

bzr branch http://bazaar.launchpad.net/~bjornt/pygarmin/edge-305

Linux support for Garmin Edge 305

I recently bought a new gadget for my bike, a Garmin Edge 305. It’s a GPS-enabled bicycle computer, which tracks your position, speed, pulse, altitude, etc., and you can of course download the data to your computer and analyse it. You can also upload data to it, for example workout programs, courses, and more.

The sad thing is that its Linux support is currently limited. Tools such gpsbabel and gpsman claim to support the device, but I haven’t gotten it to work yet. Also, those tools are mainly for extracting GPS data, they don’t handle other data, such as pulse and laps that well.

But there is hope! I found a project called pygarmin which is a Python library for communicating with Garmin GPS devices. The library is based on Garmin’s Device Interface SDK, so it shouldn’t be too hard to make it support my GPS device. The protocol specification doesn’t seem to include all the commands that the Edge uses, but there’s an open source tool for Windows, MotionBased Agent, which should be able to download and upload data to a Garmin Edge 305, so it should be possible to find out what needs to be added to pygarmin.