I <3 libpcap

A few years ago, I wrote a small app showing the open network connections (announcement following shortly). I never figured out how to measure transfer rates over the connections since the kernel does not seem to provide this info through the /proc filesystem (only some data queue length which is related to kernel mem usage).

Today we all know and love iftop, but where does it get that info? Simple: pcap! Out of curiosity, I checked out the libpcap docs to see how hard it would be to get started. Turned out to be pretty simple! There are a few excellent tutorials which get you started real fast. In about half an hour I made this very simple sniffer which accumulates the received bytes and packets per second and prints it out when the second changes. Each line contains the timestamp (sec), KB/s and number of packets received in that second. Here you can see me watching a youtube vid 🙂

Opening device eth0
ts = 1285276934, load = 0.7 KB/s (4)
ts = 1285276935, load = 0.3 KB/s (1)
ts = 1285276939, load = 0.9 KB/s (4)
ts = 1285276940, load = 14.4 KB/s (44)
ts = 1285276941, load = 294.9 KB/s (764)
ts = 1285276942, load = 608.9 KB/s (1505)
ts = 1285276943, load = 1164.4 KB/s (2882)
ts = 1285276944, load = 1242.6 KB/s (3064)
ts = 1285276945, load = 1166.6 KB/s (2880)
ts = 1285276946, load = 69.9 KB/s (179)
ts = 1285276947, load = 140.1 KB/s (363)
ts = 1285276948, load = 139.9 KB/s (361)
ts = 1285276949, load = 139.7 KB/s (358)
ts = 1285276950, load = 139.7 KB/s (358)
ts = 1285276951, load = 139.3 KB/s (358)
....

It is a good test to see if the calculated payload is correct. The initial burst of ~1.2MB/s confirms that. 🙂

Project announcement: Win7 RC auto reset alarm

Okay, this is becoming a bit outdated since windows 7 has been released for quite some time now, but you never know there are some other poor lads like me out there still using the RC. =)

Why I am using the RC is quite a story actually.. About a year ago, I bought this really beefy game rig. I tried some games using wine and although in general I managed to play them, I found it a bit silly that I wasn’t enjoying my new box for a 100% since there was always some direct3d feature not implemented yet or subpar framerate. So I decided I’d buy a game console software, aka Windows. But XP was almost EOL, Vista was a mess and Seven wasn’t released yet. So I figured I’d install the release candidate and see how it went from there.

All went well! And for the first time in many years, I even felt Microsoft was back on track. All my games ran very well. Until the day of doom, March 1st 2010. 🙂 On that day, Microsoft started to reboot all windows 7 rc’s every 2 hours. And by reboot, they don’t mean clean shutdown, they mean hard reset! Fair enough, it’s not like I paid for it.

Anyway, since I use Wintendo only for games, I realised it was actually a good thing that windows made me take a brake every few hours. It’s a good time to reassess the situation and maybe conclude to stop and do something else. 😉 No matter how I tried, I would always lose track of time and end up with game progress not being saved, steam stats not updated/lost, etc. So that’s where my little “windows 7 rc auto power off alarm” comes in. =)

This little utility will give an audible warning every minute when 1h45min have passed by. 10 mins later it will warn you with an additional sound, every 2 secs, that now the time really has come to finish your current mission/save your progress and do a proper shutdown. It is advisable to put this program in your startup folder so that it automatically starts when you log in, although it does not really matter when you start it as it initializes the timers using the boot time and not the time the program is started.

When the program is started, it sits in the system tray. Clicking on it will show you how much time is left. If you have a second monitor you can also use the pie chart countdown widget to have a visual indication on when to shutdown. Activate it by right-clicking on the systray icon and click “Show timer”. It shows green and should turn red when 0-hour is approaching. Click and drag it to move it around, scroll on it to scale.
Win7RCAutoShutdownAlarm desktop widget Win7RCAutoShutdownAlarm systray icon

Source is on gitorious, binaries can be download from qt-apps.org.

That’s it!

Telemeter plasmoid update

This week I’ve been plasmafying my telemeter widget. I’m documenting the stuff I learn along the way in my personal page over at the kde community wiki.

Here’s a first screenshot of the plasmoid in action in its natural habitat:

Telemeter plasmoid

Notice the change in looks (ditched the qneedleindicator in favor of a native plasmoid widget Plasma::Meter). I’ll do a blog post later to detail the changes. It shows a fetch error as it accesses the webservice with invalid credentials.

Project announcement: Telemeter widget / plasmoid

Lately I’ve been running low on my internet download/upload quota. Although my ISP (Telenet) trippled my quota, a combination of new suse release, new steam games and my isp failing to reset my quota (bug in upgrade process I guess), I managed to reach its limit inadvertently at 200 MB left. Since a) my ISP offers a webservice to access your usage data, b) I always wanted to write a useful plasmoid and c) wanted to try out soap services using Qt, I contemplated to write a quota monitor widget / plasmoid. This evening I gave it a shot.

After comparing available c++ toolkits for web services, I stuck to gSOAP rather than QtSoap as gSOAP seems the de facto standard when it comes to soap and cpp. gSOAP has some handy JAXB-ish utils to convert your wsdl into proxy classes. For a moment, I was afraid I would have to give up the nice and easy Qt network support (proxy, ssl,..) but it seems gSOAP has abundant support. All in all, in a few hours I had it up and running. Actually, I lost most of the time finding the relevant webservice url (you have to subscribe to a private wiki although eventually someone mailed it to me through a fairly private mailinglist I found on a user forum). In the meantime I found that putting a #define in my main is not the same as adding it as a compiler flag even when you rebuild everything. 😉 Adding a compiler flag the right way using qmake, goes like this:

QMAKE_CXXFLAGS += -DWITH_OPENSSL

When I finally could connect to the webservice, I received bogus data, all 0 usage! Only to find out that this was a problem with my account only. Btw, I good and cross platform tool to try out / debug webservices is SoapUI.

To keep it a little sexy, I threw in the QNeedleIndicator I recently stumbled upon on qt-apps.org and adapted it a bit to my needs and voila, we have an alpha:

Telemeter widget

It is not a plasmoid yet and credentials are hardcoded so it’s not useful to anybody but I couldn’t wait to blog. 😉 Note that in the screenshot I seem to have plenty of quota left. That’s only because it shows my parent’s account usage. 🙂

It is currently developed as a Qt app but I definitely plan on wrapping it in a plasmoid. Maybe I’ll keep the Qt app alive for some poor windows users. After I clean it up a bit I will post the code on gitorious.

Project announcement: ClockCalendarWidget

Although you can hardly call this one a ‘project’, I still categorized it as such as it comes with a matching project on gitorious.

In corporate environments, administrators like to put users in jail, or with an euphemism: a sandbox. At our company, the day has come that we can’t double-click on the system clock to quickly look up a date, do a simple time measurement, etc.. Although I understand it is a bug in Windows XP, it is still annoying as **** since it’s quite handy and why wouldn’t I be allowed to do that when I am adminstrator of my own machine anyway.

A workaround is putting another tool in the system tray which yields the same functionality and why not improve it while we’re at it. Today I created a very basic first version: qt clock example enhanced with seconds hand and put a calendar aside. No configuration at the moment. I created the systray icon in Inkscape and it should scale nicely in larger systray environments.

I plan on making the colors configurable and a written time under the analog clock, with maybe a simple timing functionality as a side dish.

ClockCalendarWidget

Project announcement: Vocabulary trainer

This year I followed a course in Spanish. Ever since I was a kid, when I had to study, I invented ways to not have to study. When learning a new language, what better excuse could I find than to develop a vocabulary trainer? 🙂
This is how the voctrainer project got started on the eve of the first semestrial exams. It was very basic and non-functional for other people, but at least I felt I didn’t entirely waste my study time. 😉 After the exams, development stalled but at the end of the year, once again, I managed to program instead of study. I believe it is now in a usable state, at least, when you know how to use it. 😉

Let me explain the purpose of this program and why I couldn’t just use existing soft.

First of all, it doesn’t replace existing soft (in my world: Parley and KWordQuiz) but rather supplements it. Parley is my preferred vocabulary trainer so I use it to enter my words and train in dedicated mode. Dedicated training takes time and requires you to focus and not do anything else. Wouldn’t it be cool if you could train your vocabulary during the day while working or eating or on your cell phone while watching tv? It’s what I like to call “passive learning”. =)

This is where voctrainer comes in. It is a small light-weight tool dedicated to training (no entry/grading) without requiring your dedicated time. 😉
Currently, its main features are:

  • Kvtml format: use the vocabularies you created in Parley/KWordquiz. Only the enabled (with a checkbox) ones are trained.
  • Automatic mode: cycles through your word list using configurable time delays, no interaction needed. Put it in a corner of your screen.
  • Popup option: useful when you want to be welcomed by a new word every hour/day, for example. Good to keep you in the game during holidays.
  • Manual mode: go through your word list at your own pace using mouse/keyboard, optionally skipping solutions.
  • Auto font size: useful when you put it full screen so you can still read it from a large distance while cooking/eating/doing the dishes..
  • Written in Qt: runs on all platforms without loads of dependencies (like KDE)
  • Lean and mean: you should be able to run it off your smartphone (didn’t try this scenario, since I don’t own a smartphone yet 😉 ) Uses QXmlStreamReader for fast yet memory conservative parsing.

Currently, configuration is done through the config file (located in $HOME/.config/Mattiesworld) but a gui dialog is coming. I also plan on supporting 2 configurable profiles: normal and fullscreen.

VocTrainer is open source and still fully in development over at gitorious.

VocTrainer

more wii plots

So after all today’s hard work, still some time for a bit wiimote fiddling 😉
I extended my test app to show the raw accelerometer data.


wiimote accelerometer data

A few words about what is which graph and the color coding:
The left graph shows the same as 2 days ago, except, I switched the colors to remember the meaning more easily. 😉 Red is for Roll =) and blue is the pitch. These data are calculated by the wiiuse library.
The right graph shows the raw accelerometer data. It is simply showing the x (red), y (green) and z (blue) component of the acceleration vector.

The experiment here shows 2 rolls to the left (and return), followed by 2 translations to the left. One could argue that a translation to the left, from the accelerometer’s viewpoint, is just the same as a roll, since both are changing the gravitation vector temporarily in a similar way. I’d say there still seems to be a difference.. 🙂

Paul, I’m open for discussion 😉

Wiimote experiment

Okay, so I finally got to it. A few months ago I bought a wiimote to play a bit with the api’s floating on the net. It was until yesterday that I actually tried a driver, and since that seemed to work okay, I decided to give it a try myself. My simple goal, being an app plotting the raw inputs. However, it took me a 2 hours more than expected (1 =)) and also a lot more blood, sweat and tears. 😉 particularly because I made a lot of mistakes due to me being too tired 😉 So I will keep it short for now as I want to go to sleep.

I choose the wiiuse library as it seemed adequate for the job and still active (and even cross platform!). I started from the included example and tried to wrap it into a Qt app (hence I named it example-qt ;)). The obvious choice for drawing is using QGraphicsView. However, for once ;), I took the effort to see if there are no existing Qt graph plotting libraries. And this just happens to be the case. 🙂 Meet the excellent QWT lib. It couldn’t be more fit for the job. The site is (almost) nothing but the api docs, but that seemed sufficient. One second I thought this lib would not be qt4 ready, but it has been ported!

Quite a few seconds and segfaults later 😉 I got this:
wii experiment

Nothing fancy, but it does show the roll and pitch!! =)

Note: the wiimote survived the experiment 😉