sirf/nmea protocol switch

categories: blog

For my touchbook i recently bought a Navilock USB GPS-Modul NL-302U SIRF III containing a SiRF III chip that are known for their excellent quality.

This is how the baby looks on the inside:

navilock gps

And this is how it looks when attaching it to my linux box:

[40538.052593] pl2303 2-1.2.1:1.0: pl2303 converter detected
[40538.054396] usb 2-1.2.1: pl2303 converter now attached to ttyUSB0

Bus 002 Device 009: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

Unfortunately instead of the widely understood ASCII based NMEA 0183 protocol those chips are using the proprietary, binary SiRF protocol. Luckily the gpsd guys are hosting a pdf documentation of that protocol. Reading that documentation one can also find out that it is possible to switch between NMEA and SiRF modes.

Reading and displaying data from a serial port is most convenient with:

apt-get install python-serial
/usr/share/doc/python-serial/examples/miniterm.py /dev/ttyUSB0 9600

And writing to serial is quickest with:

from serial import Serial
tty = Serial("/dev/ttyUSB0", 9600)
tty.write(message)

or

python -c "from serial import Serial; Serial("/dev/ttyUSB0", 9600).write(message)"

According to section 1.2.3 of the documentation the following message needs to be written to switch from NMEA to SiRF binary mode at 9600 baud:

message = "$PSRF100,0,9600,8,1,0*0C\r\n"

Switching from the default SiRF binary mode to NMEA is more involved but described in section 2.2.2.

Numbers are 7 bit and in big endian notation:

pack = lambda x: chr(x>>8)+chr(x&0xff)

Every message has a start and end sequence

start = "\xa0\xa2"
end = "\xb0\xb3"

The payload is assembled with help from the documentation (only GGA, GSA and GSV messages enabled, 9600 baud)

payload = "\x81\x02\x01\x01\x00\x01\x05\x01\x05\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x25\x80"

Calculate 15 bit checksum:

checksum = sum(map(ord, list(payload))) & 0x7fff

Calculate the length of the payload

length = len(payload)

Assemble message:

message = start + pack(length) + payload + pack(checksum) + end

And after sending it as explained above the device will gladly output NMEA data.

View Comments

extlinux

categories: tutorial

i'm finally back to extlinux...

installation was perfectly painless:

apt-get install extlinux
mkdir -p /boot/extlinux
extlinux --install /boot/extlinux
cat > /boot/extlinux/extlinux.conf << END
PROMPT 0
DEFAULT debian
LABEL debian
    kernel /vmlinuz
    append root=/dev/mapper/volumegroup-root ro quiet
    initrd /initrd
END
dd bs=440 conv=notrunc count=1 if=/usr/lib/syslinux/mbr.bin of=/dev/sda
apt-get remove --purge grub-pc grub-common

checking that the boot flag is set to the correct partition with fdisk and reboot :)

the path to vmlinuz and initrd should probably made relative - something like: ../vmlinuz but /vmlinuz works in my case as i have a separate /boot partition.

View Comments

git colors!

categories: blog

wheeee! colors!

I was especially in the need of colors for git-diff.

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.ui auto
git config --global color.interactive auto
git config --global color.grep auto

one can certainly overdo it but I love colored output on my terminal :)

View Comments

physics simulation games

categories: blog, debian

As I own a Always Innovating Touchbook I wanted to make use of its touchscreen by having some physics simulation games on it. Unfortunately it's kinda hard to find such open source games as the really good ones, phun (now algodoo), zanydoodle and crayonphyiscs are proprietary. Noteable opensource games I found were numptyphysics and the powder toy

While phun and the powder toy come with their own simulation engine, the rest are using open source libraries. This got me to research a bit to what is available on open source 2D rigid body physics simulation libraries.

The one that numptyphysics and crayonphysics (and angrybirds!) rely upon is box2d. As it is also used by the torque 2d engine it is probably also used in amazing games like Insanely Twisted Shadow Planet. Starting of in 2007 it is the older library but doesnt seem to be further developed since 2010. It is implemented in C++, released under the zlib license, rendering agnostic and supports lot of features like hinges, motors, friction and springs. Its sort and prune based broadphase collision detection is supposed to work better with objects of varying size.

The newer and more fancy one is chipmunk which builds on parts of box2d, is implemented in C99 and is more high level than box2d. It is used by zany doodle and xmoto and released under MIT license. The spatial hash broad phase collision detection is supposed to make it faster for lots of objects of the same size. This is also one of the reasons why chipmunk seems to be much faster with fluids which are quite problematic for box2d because of the huge number of small circles used to simulate it.

Box2d is ported to many languages, chipmunk as many bindings. They are both cross platform, running on Windows, Mac OS, GNU/Linux, Android and Apple iOS. Chipmunk has a more modern and thought out API but that might just be because of my C++ dislike. In the end, forum posts suggest that each of them has it's strengths and weaknesses and (as usual) in the end one has to go with the one than one is more comfortable in using.

Unfortunately the most impressive engine seems to be integrated in the propriety game phun, or algodoo as it was renamed. But this might just be an impression by the immensely complex and function rich program that phun/algodoo is. Most noteably is probably its smooth handling of water including simulation of buoyancy but it also simulates specular reflection, fraction and dispersion of light. Its other features like hinges, motors, springs, friction and mass are also handled by chipmunk and box2d but there is an editor missing that is as powerful as the one of phun/algodoo.

Now the two open source games I was checking out were numptyphysics and the powder toy. I wanted to have both on my touchbook and be able to control them with the touchscreen only.

Now numptyphysics is packaged in debian but development seems to have stopped in 2008. Fortunately it's quite useable and even supports touchscreen only operation by two slide-out menus on the left and right. It took me ages to find those and i only found them by accidentally clicking on the 5 pixel border of the window which slides out the menu. With this one it can be fully controlled with the left mouse button and is hence ready for touchscreens. Unfortunately it needs some tweaks to be nicely useable. Those changes were, to increase the window size to 1024x600 (there is no way to do that without recompiling), change the selection and click tolerance to bigger values for touchscreen use (also needs recompilation), increase the area on both sides for the slide-out menus (again needs to be recompiled) and disable drawing of the rotating joint symbol as it doesnt get scaled.

You can find my changes here maybe some time I will make a better patch that also includes command line options to change all of that at runtime.

Then there is the powder toy. It comes with a fixed resolution as well which is mainly due to the fact that it builds on an online community that shares their creation and those are of fixed size. If one doesnt care about that, changing the resolution is very easy but also only possible at compile time. It involves just changing XRES, YRES, XCNTR and YCNTR in includes/defines.h. Since I wanted to run it on the armel architecture I added a new target to the makefile that built powder without sse. Also to make it run faster I didnt choose 1024x600 but 512x300 as the resolution and combined that with the scale:2 commandline parameter. Sadly scale can be only 1 or 2.

While numptyphysics is perfectly useable on the touchbook performance wise, the powder toy runs at a mere 9 fps with an empty screen. Maybe this will improve with armhf but i didnt check out how much the powder toy uses floating point arithmetics.

In the end here are some videos that are worth watching:

View Comments

using apt-cacher

categories: debian

Since I debootstrap a lot, I download the same base packages from the debian server over and over again. This sucks as it eats up the bandwidth of the debian people and is slow for me. The solution is apt-cacher that acts as a local debian repository and totally automagically even works for foreign architectures or distributions.

After apt-getting it, the only things I did to make it run, was to edit /etc/apt-cacher/apt-cacher.conf and /etc/default/apt-cacher. In apt-cacher.conf I had to remove the asterisk from the allowed_hosts setting and also set generate_reports to 0. Then setting AUTOSTART to 1 in the default file and from that point on I just have to use the following repository mirror URL in my bootstrapping scripts:

http://localhost:3142/ftp.de.debian.org/debian

The beauty is, that I dont have to configure apt-cacher to source http://ftp.de.debian.org beforehand - it's all done by a request of the above style. Would I want apt-cacher to choose a different mirror, I would just request another url from it. This way I can transparently cache any debian mirror I want without any hassle.

View Comments
« Older Entries -- Newer Entries »