Author:


TEMPer1 temperature sensor in Linux

Posted by – 2012/01/15

Yey! Just got my PCSensor TEMPer1 USB thermometer logging in Linux. It automatically detects and does expose USB HID profiles, but there’s no way to access the data by holding down the CAPS key like it says in the docs.

Thankfully, a search for the device ID (0c45:7401 Microdia) finds ruby bindings for Temper.c by Michitaka Ohno, which conveniently includes the reverse-engineered USB protocol. So I’ve forked this on GitHub, removed the Ruby bits, edited the unit test wrapped it up in a little script that logs the time and temperature to a CSV file. It currently only supports one device, which will change if I ever get another one of these devices (spoiler: I probably will)

More…

Ubuntu printing and scanning

Posted by – 2012/01/15

I haven’t owned a printer since I had an Amiga all those years ago, but since I’ve started my homebrew mission I’ve decided I need something to print some labels. Kath got me a HP OfficeJet 4500 G510g printer/scanner/copier for my birthday, and I have to say it works wonderfully.

More…

Irrlicht website update

Posted by – 2012/01/06

The WordPress version of the Irrlicht website is now live, which means we can edit pages and post news articles using an online editor, users can post comments and we can even appoint community editors to post stuff without giving them rights to the filesystem.

Expect lots more activity there in the future :)

2011 in review

Posted by – 2012/01/05

Dear diary

Sorry for not writing to you of late, but this year has been a busy one.  I’ll make up for my lack of output with this mammoth post reviewing a small selection of interesting things I got up to this year…

More…

Anonypic and Microphone source drop

Posted by – 2011/01/03

Since I’ve not updated these two Android projects in a while, at risk of total future embarrassment (I’m still a Java newbie) I’ve decided to dump the source code on GitHub so others can make use of it. Details are on the Anonypic and Microphone project pages.

If you fix any bugs, please send a pull request and I’ll do my best to merge them in, but keep in mind this is also my first attempt at using git; expect schoolboy errors there too!

Import vmstat logs into LoadRunner

Posted by – 2010/11/15

Here’s a little script to format vmstat’s output into something you can import into LoadRunner’s analysis tool:

import sys, time
 
sys.stdout.write("Date,Time,"
                 "Proc Run,Proc sleep,"
                 "Mem swap use,Mem free,Mem buffered,Mem Cache,"
                 "Swap in,Swap out,Blocks in,Blocks out,"
                 "Interrupts,Context switches,"
                 "CPU %User,CPU %System,CPU %Idle,CPU %Wait,CPU %Stolen\n")
 
for line in iter(sys.stdin.readline, ""):
    if line[0] != 'p' and line[0:2] != ' r':
        t = time.strftime("%d/%m/%Y,%H:%M:%S", time.localtime(time.time()))
        line = ' '.join(line.split())
        line = line.replace(" ", ",")
        sys.stdout.write("%s,%s\n" % (t, line))
        sys.stdout.flush()

(Thanks to fabrizoM for the help!)

Run it from a shell script like so:

#!/bin/bash
vmstat 5 | python vmstat2csv.py >> servername-vmstat.log

Then start the job from the shell, press CTRL+Z and nohup it (so it doesn’t die if you disconnect) and tail it (so you can keep an eye on it) like so:

[1]+  Stopped                 ./log.sh
[gaz@box ~]$ bg
[1]+ ./log.sh &
[gaz@box ~]$ disown
[gaz@box ~]$ tail -f servername-vmstat.log
Date,Time,Proc Run,Proc sleep,Mem swap use,Mem free,Mem buffered,Mem Cache,Swap in,Swap out,Blocks in,Blocks out,Interrupts,Context switches,CPU %User,CPU %System,CPU %Idle,CPU %Wait,CPU %Stolen
23/11/2010,12:59:47,1,0,0,1266452,465576,2074012,0,0,2,15,0,36,0,0,99,0,0
23/11/2010,13:00:11,0,0,0,1264460,465584,2074024,0,0,0,168,581,577,1,1,94,4,0

When you’re done, import it into the Analysis tool via the Tools -> External Monitors menu. Make sure you set the correct date for the custom format and remember to keep a close eye on the timezones. If you make a mistake while importing there’s no going back, so save a backup of your analysis files before you attempt this.

Rainwatch featured on Android Market

Posted by – 2010/09/09

Sometime yesterday my app Rainwatch was added to the “top free” list on the Android Marketplace, showing in 5th position in the News and Weather section. This is strange because it’s only 32nd in the “top free” list on the market on Android devices, but hey, I’m not complaining!

I guess I’d better make a promotional image for Market and update the screenshots so they actually look like recent versions of the app!

Float.parseFloat is slow

Posted by – 2010/08/27

While profiling some loader code and expecting to see performance issues with my regular expressions, I found that ~60% of my time was actually spent converting String variables to floats. It turns out that the slow bit lives inside Float.parseFloat, where it calls String.toLowerCase every single time just in case this string is a hex float, a very rare type of float which I had never seen before. I logged this with Apache, but as I can’t ship a custom ROM with my SVG parser I decided to replace it.
Here’s the results from some tests of 3896 calls to parseFloat on my Nexus One:

  • a) Using Float.parseFloat(String): 1516.449ms
  • b) My own parseFloat(String): 654.882ms
  • c) …and my own isDigit(char): 449.622
  • d) …and isDigit written inline: 295.865ms
  • e) …copying the string into a char buffer and avoiding all string access and method calls: 254.527ms (112ms spent copying the characters!)

So in theory, if the method took a character buffer and length it could be as short as 135ms, over ten times faster than Float.parseFloat. I’m currently using option d as gives a nice performance gain without breaking my design, but when performance tuning the entire API later this may see some huge changes. Here’s the function I cooked up:

public static float parseFloat(String f) {
	final int len   = f.length();
	float     ret   = 0f;         // return value
	int       pos   = 0;          // read pointer position
	int       part  = 0;          // the current part (int, float and sci parts of the number)
	boolean   neg   = false;      // true if part is a negative number
 
	// find start
	while (pos < len && (f.charAt(pos) < '0' || f.charAt(pos) > '9') && f.charAt(pos) != '-' && f.charAt(pos) != '.')
		pos++;
 
	// sign
	if (f.charAt(pos) == '-') { 
		neg = true; 
		pos++; 
	}
 
	// integer part
	while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0'))
		part = part*10 + (f.charAt(pos++) - '0');
	ret = neg ? (float)(part*-1) : (float)part;
 
	// float part
	if (pos < len && f.charAt(pos) == '.') {
		pos++;
		int mul = 1;
		part = 0;
		while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0')) {
			part = part*10 + (f.charAt(pos) - '0'); 
			mul*=10; pos++;
		}
		ret = neg ? ret - (float)part / (float)mul : ret + (float)part / (float)mul;
	}
 
	// scientific part
	if (pos < len && (f.charAt(pos) == 'e' || f.charAt(pos) == 'E')) {
		pos++;
		neg = (f.charAt(pos) == '-'); pos++;
		part = 0;
		while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0')) {
			part = part*10 + (f.charAt(pos++) - '0'); 
		}
		if (neg)
			ret = ret / (float)Math.pow(10, part);
		else
			ret = ret * (float)Math.pow(10, part);
	}	
	return ret;
}

This is of course a very crude method, it requires a well-formed number and will return 0 or partial numbers instead of raising exceptions, it doesn’t work with hex floats or parse NaNs or Infinity and it doesn’t use doubles internally so the accuracy is not perfect. It does however work for my purposes, so I thought I’d share it with the Internet.

Microphone for Android

Posted by – 2010/08/22

So, my 4th Android app is out, a simple mic which you can plug into your computer. It’s got quite a slating on the Android Market because of its latency, the problem is that there’s quite large minimum values on the buffer size for accessing input and output buffers, there’s no way to reduce this latency below the ~300ms which it currently has. Hopefully AOSP will address this eventually, paving way for realtime audio applications.

Adventures in Android

Posted by – 2010/08/17

Since getting myself a Google Nexus One I’ve decided to do a bit of Android development. My first impressions with the platform weren’t really that good, but I’m beginning to get the hang of it now.

My main problem is that Java is a horribly verbose and restrictive language. To do the simplest things you need to implement at least three interfaces and extend a couple of abstract classes (after reading the documentation for each of them and their alternatives of course). Something which could be written in Python in three lines of code and two minutes takes fifty lines and twenty minutes in Java. Perhaps that’s just me, maybe I’ve been spoiled by dynamic languages and expect to be able to do things a hundred different ways by just typing whatever comes to mind, rather than carefully considering the available options and planning every step of my app. In my short journey through Java development I’ve suffered a lot of pain because I make assumptions and choose a design pattern which is incompatible some point later down the line, so I end up refactoring everything ten times before I even get a working prototype. I’m slowly learning not to fly by the seat of my pants (even if it is the most fun way to fly) and perhaps that’s a good thing.

My other gripe is the UI editor and XML format, their steep learning curve makes the design stage a huge time sink. I’ve now spent a fair bit of time banging my head off my keyboard while attempting to make the simplest of interface, which still don’t look like they do on paper, but I think I’m getting the hang of it.

Anyhow, so far I’ve managed to knock out 3 applications which are available in the Android marketplace:

Anonypic

This little app just adds an extra option to your share menu, and will upload an image to bayimg.com, the anonymous image sharing service by the creators of The Pirate Bay. Images have their EXIF data removed, so you can share images without leaving a trail of metadata leading back to your phone.

Rainwatch

Rainwatch is an alternative viewer for the BBC’s Maps Presenter, the Flash application available on their weather site. It’s far from complete but is good enough to predict the weather, so I’m quite happy with it (as are my 1500 active users)

MC Mail

MC Mail, or Missed Call Mailer is a little app which sends you an email when you get a missed call. The back-end is written in PHP and MySQL, the front-end is mostly just a service which monitors your call log. Useful if you’re a hospital or call centre worker who has access to email but can’t use a phone in work, or if you always forget your phone. It usually only works while the phone is in silent mode.

Next steps?

I’ll make a couple more apps and maybe a game, then learn the Native Development Kit and port Irrlicht using Christian’s OpenGL ES driver. I haven’t done any Irrlicht code in ages, so that’s certainly on the agenda.