Reading and Writing Google Protocol Buffers with Files

By: Fernando de Sousa

One of my current tasks with the Serval Project is the redevelopment of the Serval Maps application, which was the focus of my honours thesis last year.

As part of the redevelopment I’ve implemented a new data interchange format that takes advantage of the Rhizome capabilities of the Serval Mesh software. I’ve decided to use Google Protocol Buffers as the basis for my binary file format.

To write the messages to the file it is necessary to use the writeDelimitedTo method of my Message class to write the messages to the file. By using this method each message is delimited in the file.

The code looks something like this:

try {
	FileOutputStream mOutput = new FileOutputStream(mOutputPath + mFileName, true);
	mMessageBuilder.build().writeDelimitedTo(mOutput);
	mOutput.close();
} catch (FileNotFoundException e) {
	Log.e(TAG, "unable to create the output file", e);
	return;
} catch (IOException e) {
	Log.e(TAG, "unable to write to the output file", e);
	return;
}

Reading back the messages from the file requires the use of the mergeDelimitedFrom method to read the messages out of the file and process them. The code looks like this:

try {
	while(mMessageBuilder.mergeDelimitedFrom(mInput) == true) {

		// process each message in turn
	}
} catch (IOException e) {
	Log.e(TAG, "unable to read from the input file", e);
	return;
} finally {
	try {
		mInput.close();
	} catch (IOException e) {
		Log.e(TAG, "unable to close input file", e);
	}
}

It took me some time this afternoon to work this out, including a large number of Google searches. I hope this post helps someone else who is working through similar issues.

The photo “Binary” was uploaded to Flickr by Fernando de Sousa and used under the terms of a Creative Commons License.

Software Developer Contracts Available!

Do you thrive on contributing to something that has the potential to positively impact millions, if not billions of people the world over?
Do you slay pointers in your sleep, dream about data-flow diagrams, or cross-compile kernel drivers for fun?
Can you think in C (or Java)?  Do you know how to use mmap() instead of malloc()?
Have you ever written your own compiler, interpretor or network stack for the fun of it (or all three)?

If you can answer yes to at least some of the above, the Serval Project Inc. has the following contract opportunities that it is seeking to engage, so that we are able to accelerate our software development programme:

1. Java/Android/C Software Developer (full-time NOW through to 31 August)
2. Java/Android/C Software Developer (two days per week NOW through to 31 August)
(or possibly some mix-and-match for the total 1.4 full-time-equivalent.)
The purpose of these roles is to get us to our 1.0 public release in August 2012.  Future opportunities may develop over time, dependent on successful software outputs.
For both of these roles we are looking for people who can quickly pick up Java and/or C code, and make rapid and sustained contributions to the Serval Project’s software base in preparation for major software releases during 2012.  
Being a Java/C polymath will definitely work in your favour, as will having some experience with Android software development.  General Linux/UNIX admin and scripting awareness and skills are also a plus, as is demonstrated experience contributing to FLOSS software projects.
But most of all, we need people who are passionate about what the Serval Project is doing, and who want to change the world for the better.  Prior engagement with the Serval Project is a great way to prove this to us, both for these and any future openings.
These openings are available immediately, are based in Adelaide, Australia (sorry, not negotiable for these openings due to the intensity of software development we have scheduled), and interested parties are strongly encouraged to put together:
1. A CV listing (providing links is great) any FLOSS, CJavaAndroid and humanitarian experience;
2. A covering letter; and
3. About 250 words explaining why you think it is vital that the Serval Project succeed.
Then send it all to jobs@servalproject.org.  ODT and PDF are our preferred formats.
If we like what we read we will get in touch, and get into more of the nitty-gritty.
If we find more great people that we can offer work to, we will keep you on file for when we next have openings.

A call for change – Telcos need to meet client needs better.

Here at Serval, we do not regard ourselves as competing with Telcos. However, we do wish to encourage them to do better by their customers. We are happy to augment the service they can provide. We will continue to work on making a viable community and emergency communications solution, while observing how industry giants operate.

 

We wait to see if the regulator can transform the industry from one that thinks it is simply selling devices to an industry that understands it is supplying people with essential services. After 15 years of the industry writing its own rules, it can’t come soon enough for customers.

via A call for change at our service-challenged telcos | Article | The Punch.

Wireframing and UI Development

I have been using Balsamiq to wireframe UI for our upcoming releases. (If anyone is interested, I have a template for our standard phone – the Huawei Ideos 8180 or 8150). I use iMockups on my iPad, and that can work well with Balsamiq, which is nice.

However, today I am changing to Wireframesketcher – just to see how it goes. There is a 14 day trial, after all. It integrates with Eclipse, and I am going to see if that streamlines the process at all.

Wireframing is relatively simple, at least as compared to this time last year, when tools were fewer –  and then good ones of those were far between. However, exporting mockups to usable phone app mockups (for demonstration purposes) remains problematic. Two solutions (based around Balsamiq), are Canappi & Mockups2Android.

Canappi converts Balsamiq files (or wireframes from Apple’s Interface Builder) into an intermediate language that then can be converted to Android files (however, a simple mockup from Balsamiq failed for me at that second step).

Mockups2Android is an Android app that takes Balsamiq files and converts on the phone to a usable mockup. However, it is NOT compatible with the Huawei Ideos range – so pretty useless for us. There is  demo version if anyone wishes to try – and please, if so inclined, pass on feedback to me.

 

I will evaluate Wireframesketcher and post on that – and also continue to post on anything else we find in the way of tools for UI.

 

Enhanced by Zemanta

The cost of cellphone-based services is hurting huge swaths of the developing world.

What drives us? What keeps us passionate about our project? It is often hard work getting funding, or continuing as a start up when not in Silicon Valley. (We have been so lucky in with the support of Flinders University, the Shuttleworth Foundation, and other amazing supporters).

via M-PESA and other ICT4D projects are leaving behind the developing world’s poorest people. – Slate Magazine.

Extracting Textual Data from a Zip File in Java

One of my development tasks this past week was to extract the contents of a file that was compressed and stored in a zip file using Java for the Serval Maps Android application that I’m developing as part of my work for the Serval Project.

The file in question contains a list of coordinates that I use as a source of location data that I can provide to my application using mock locations. Using this class I can provide geo-coordinates to my application during testing that appear to come from the GPS hardware, from the perspective of the rest of the code. The coordinates are in fact sourced from the file. I’ll write about this improved class in a future post.

The code that I developed to extract the contents of the file looks something like this:

// declare helper constants
private final String LOCATION_FILE = "mock-locations.txt";
private final String LOCATION_ZIP_FILE = "mock-locations.zip";

// open the zip file and get the required file inside
ZipInputStream mZipInput = new ZipInputStream(context.getAssets().open(LOCATION_ZIP_FILE));
ZipEntry mZipEntry;

// look for the required file
while((mZipEntry = mZipInput.getNextEntry())!= null) {

  // read the bytes from the file and convert them to a string
  if(mZipEntry.getName().equals(LOCATION_FILE)) {

    // store the incoming data in a byte array stream
    ByteArrayOutputStream mByteStream = new ByteArrayOutputStream();
    byte[] mBuffer = new byte[1024];
    int mCount;

    // read in the data until it is all gone
    while((mCount = mZipInput.read(mBuffer)) != -1) {
      mByteStream.write(mBuffer, 0, mCount);
    }

    // store the data for later
    locations = new String(mByteStream.toByteArray(), "UTF-8");
  }

  // play nice and tidy up
  mZipInput.closeEntry();
}

// play nice and tidy up
mZipInput.close();

The basic process that this code undertakes is to:

  1. Open the zip file stored in the assets folder using the ZipInputStream class
  2. Loop through the contents of the zip file looking for the required file by examining the series ZipEntry objects
  3. Once found read the contents of the file into a ByteArrayOutputStream
  4. Convert the byte array into a string and store it for later use

 

Linux.conf.au Presentations

Earlier this month Linux.conf.au 2012 was held in Ballarat, Vic. The Serval Project was fortunate to be awarded two presentation slots at the conference. I was scheduled to present, but unfortunately had to pull out at the last moment due to illness.

My presentation was to focus on my work on the prototype Serval Maps application, which was the topic of my honours thesis last year.

Fortunately Dr Paul Gardner-Stephen, Serval Project Co-Founder and Shuttleworth Fellow, was able to attend and presented instead. You can read his notes on the conference here.

The presentation by Paul is now available on YouTube here.

The Serval Project also had another presentation at the conference which focused on our Rhizome technology. That presentation, by Jeremy Lakeman, is also available on YouTube here.

It is unfortunate that I was unable to attend and present, it was something that I was looking forward to. Hopefully I’ll be able to present next year on one of the many interesting things that the Serval Project is undertaking this year.

My Honours Thesis is Online

By: Sam Hames

This past year I’ve been studying part time for a Bachelor of Science (Honours) degree specialising in Computer Science at Flinders University. The focus of my studies has been my honours thesis. My thesis explored the following research question:

Is it possible to provide collaborative mapping services on mobile devices in an infrastructure independent manner?

To explore this question I developed an Android based application that could support four core objectives. They were:

  1. have the users own geographic location displayed on a map;
  2. add incidents, represented by a marker, onto a map;
  3. be able to see the geographic location of other users of the application on the map; and
  4. share details of incidents with other users of the application on the network.

The software that I developed uses the resilient Ad Hoc mesh network provided by the Serval Project to ensure that communication between instances of the application are infrastructure independent.

The thesis is available online on my Stuff by Techxplorer website.

The photo “Writing Thesis” was uploaded to Flickr by Sam Hames and used under the terms of a Creative Commons License.