Archive for September, 2009

Supertux, cheating at the source code level

September 28, 2009

Who said that there are no games for Linux?

Other than running games for windows through Wine (as well as nearly any other .exe file), there are many games that run natively on Linux.

I don’t play much, but I’ve personally tried Sauerbraten and Supertux, both of which have been suggested to me by admiral0, a member of the POuL.

Supertux is a nice game, but I’ve found it a bit too difficult to play, especially some levels where there are these flying enemies, identified in this picture:

supertux_cheating

So, to finish this almost-impossible level, I decided to cheat :)

And since I’m a programmer, I thought that the easiest way to cheat was to alter the game’s source code :D It did not take much time to download the 0.3.1 beta release (which was the version I was playing) and find what to modify.

The code that makes these enemies attack from the sky is defined in

src/badguy/zeekling.cpp

and is the should_we_dive() member function of the Zeekling class.

Just replace the function’s body with a

return false;

and recompile. The game becomes a little bit easier, and I successfully completed the level :)

FPGA!

September 27, 2009

This is a quick post, more information will follow later. I’m entering the world of reconfigurable hardware :D

Here’s an image of the FPGA board I’ve designed:

fpga

It has an xc3s200 spartan 3 FPGA. It’s not one of the newest nor one of the biggest FPGAs around, but you can synthesize a Microblaze 32bit CPU in it and still have room for other logic.

And there are more good news: Xilinx provides a version of their IDE for Linux, and I even managed to program the FPGA using my JTAG cable and urJTAG.  Here’s an image of urJTAG correctly recognizing the two chips in the JTAG chain:

fpga_screenshot

Until now I’ve only written two simple VHDL programs, one that does an and gate, which is probably the equivalent of the “Hello world” for an FPGA, and one that divides the 50MHz clock on the board by 2^26, and uses the resulting ~1Hz frequency to blink a led. Both work as expected on the FPGA board.

So many interesting things to do, and so little time to do them… it’s 27 September and on 30 September I’ll have to go back to university… This year I had to write my thesis, and that resulted in no spare time during summer… :(

Miosix kernel released

September 23, 2009

After one year of development in the spare time, I released the Miosix kernel under an open source license.

I published the kernel source code, the schematic of the Miosix board, the doxygen documentation, instructions for compiling the kernel, and my thesis.

Read about it here: http://www.webalice.it/fede.tft/miosix/index.html.

Which *wrt is best for you

September 17, 2009

In this post I’m talking about Linux-based alternative firmwares for wifi routers, like the Fonera. Since there is more than one, I’ll present the three most widely known, explaining their advantages and disadvantages.

First of all, why would somebody want to change the default firmware that comes with the router? The primary reason is: more features. Some advanced features like QoS might not be available in the original firmware. It is also possible tu run a small webserver on the router and, if it has an USB host port, a bittorrent client can be installed.

As I said, there is more than one firmware. This blog post will concentrate on DD-Wrt, OpenWrt and X-Wrt.

Let’s start with DD-Wrt. This is a firmware designed for end users, it has a good web-based user interface for managing settings, and is relatively feature-rich. The key point is that the set of features is decided for you by DD-Wrt. The filesystem of the router is not writeable, so you can’t install other applications, and you also can’t remove applications you don’t use to save some FLASH memory space.

Pros:

  • Simple to use, good web UI, good documentation
  • Adds many features to your router

Cons:

  • Limited room for customization, due to the read only filesystem
  • When installed, the router password is set to a default value, this might cause a security hole if the user is inexperienced/lazy and does not change it
  • Not good for developers. The read only filesystem does not allow to install custom application, the development tools for this firmware are not very developer friendly

Now let’s examine the second choice: OpenWrt. This firmware is the opposite of DD-Wrt. By default, it comes with a minimal set of packages, not even a web based UI (even if it can be installed later). All configuration is done through SSH and a shell Update: it looks like newer releases of OpenWRT come with a minimal web based configuration interface, called LuCI. It has a writeable JFFS2 filesystem, with transparent compression enabled, so that installed applications need a minimum FLASH space. To install applications, you use the opkg package manager. This combination allows to customize the firmware the way you want, by installing only what you need. The repository is incredibly full of packages, see it for yourself here. You can find anything from CTorrent to aircrack to asterisk and even php. From a developer point of view, things are even better. If you have a computer running Linux, you can install the buildroot-based development system. You can choose from the full development system that allows you to modify the kernel and build custom firmwares, or only the SDK for application development.

Pros:

  • Fully customizable, with a writeable filesystem and package manager
  • Really large number of packages
  • Good documentation on its website
  • The first time is installed, it asks you to set the root password. There is no default password
  • Developer friendly

Cons:

  • Not good for end users/noobs. Configuration is done through a shell.

Now, the last firmware, X-Wrt. This is just OpenWrt with a web based UI installed by default. It is not a fork, since the two projects proceed together. This means that all the advantages of OpenWrt are the same for X-Wrt. Developers can even use the OpenWrt development tools to target X-Wrt too.

Pros:

  • All the advantages of OpenWrt
  • A web based UI for configuration makes it good also for end users

Cons:

  • The web UI takes up some FLASH memory. If you have a router with very little FLASH, it will limit the number of applications you can install
  • The quality of the web UI is a bit behind the one of DD-Wrt, even if it is improving

Personally, I find X-Wrt to be the best compromise between features and simplicity, and that’s why I’m using it on my Fonera. Also, I’ve tried the development tools and they work well, but maybe I’ll talk about them in detail in another blog post…

First steps with CMake

September 16, 2009

When building something I usually either let an IDE handle the build process, or write makefiles manually. Both solution work, but have drawbacks. IDEs allow you to forget about how code is built, but create some sort of IDE lock-in, since switching to another IDE becomes difficult. Makefiles solve this problem, but are a bit too low level, and writing makefiles for complex projects is tedious.

So it’s a while I’ve been searching a better way. The most known alternative is autoconf and automake. If you’ve compiled some software on Linux you’ll be familiar with the

./configure <options>
make
make install

way of doing things. However, these tools have the main problems of being built mostly with shell scripts. If you plan to support only Linux this is not an issue, but it becomes a bigger trouble if your program needs to be compiled on windows too, where bash is not available by default.

Recently I’ve found CMake, and it looks interesting. First it’s the tool used to build KDE4, and this means it’s well suited even for large projects, second it claims to work equally well on Linux, Mac and Windows. And lastly, its syntax seems simple and high level.

I’ve started with the documentaton on its website, and in 15 minutes I’ve been able to compile an example program. The example program is made of three files, main.cpp, foo.cpp and foo.h.

The first step to create a CMake project is to write a file named CMakeLists.txt. Its content is this:

cmake_minimum_required (VERSION 2.6)
project (HELLO)

add_executable (hello main.cpp foo.cpp)

The first line is a requirement for a new version of CMake. The second specifies the name of the project, and the third tells CMake to create an executable named hello by compiling the files main.cpp and foo.cpp. Really simple.

Like autoconf and automake, CMake doesn’t compile the code directly, instead it generates a makefile. The steps to compile the example program are to open a shell in the directory where the source files and CMakeLists.txt are, and type:

mkdir build
cd build
cmake ../
make

This is because with CMake it is recomended to keep the build directory separated from the source directory. To remove the generated files it is either possible to type “make clean” or simply to delete the build directory.

It is still early to say if I’ll use CMake for my projects, after all I’ve just started using it for 15 minutes, but it surely looks interesting.

Serial ports and C++

September 14, 2009

Update Jun 22, 2011: Fixed a bug for compiling under visual studio 2010.

I’ve added a new article to my website. You can read it here. This article explains how to interface with serial ports from C++. Applications include communicating with an Arduino, the Fonera or any microcontroller. It presents four classes to access serial ports, starting from simple string read/write to advanced asyncronous I/O.

All the code is based on the Boost.asio library, so the code is portable across operating systems.

If you have comments, or find bugs, post them as comment to this blog post.

Measuring time durations

September 14, 2009

Today on the poul‘s mailing list someone asked: “How to measure the time spent in a function?”. I replied with the code that I use for that purpose, but later I thought that it was an interesting question, so I’m posting the solution here on the blog.

The solution is to use the boost date_time library. It is simple, portable (works on Linux, Win and Mac) and precise, since the time is printed in microseconds.

Here is an example code that shows how to profile a function:

#include <iostream>
#include <boost/date_time.hpp>

void f()
{
 for(volatile int i=0;i<100000;i++) ;
}

int main()
{
 using namespace std;
 using namespace boost::posix_time;

 ptime t1(microsec_clock::local_time());
 f();
 ptime t2(microsec_clock::local_time());

 cout<<t2-t1<<endl;
}

Just replace f() with the function you want to profile. Of course you can profile the time spent running your entire program by putting the whole program between the declaration of t1 and t2.

The time is printed in this format:

./test
00:00:00.000620

To be able to compile the program, you need to link with the boost_system library. With the g++ compiler you must add -lboost_system when linking.

Of course you need to have the boost libraries installed. On Linux type:

sudo apt-get install libboost-dev libboost-thread-dev

While on Windows, get this compiler that comes with boost precompiled.

The Fonera 2.0n is coming

September 5, 2009

People who read my website know that I like Foneras. I have a model 2100 since 2008, the first model produced by Fon, bought for just 6€ (at the time there was a promotion :)).

I particularly appreciated the ease of hackability of this little device, with its RedBoot bootloader and brick-proof serial port. I’ve tried many hacks with it, first installed dd-wrt, then openwrt, written simple C++ programs for it, experimented with the GPIO, added an heatsink… some of these hacks are described in my website, and maybe I’ll talk about the remaining ones in this blog.

Fon announced the Fonera 2.0 more than one year ago, however it was available only for developers, until recently. It is different from the original fonera, because it has an USB host port that can be used to connect an hard drive, or other USB device. In addition, the software is open source, therefore expandable. And even the default configuration has many nice features, like auto backup of the computer onto the hard drive connected to the Fonera (like Apple’s time machine+time capsule, but multi platform), automatic torrent download without the need to leave the computer powered, and automatic upload for example on Youtube.

However, the topic of this post is the Fonera 2.0n. This is a fresh news. Fon has recently released a new router, called Fonera 2.0n. It is currently not available on the Fon shop online, but there’s a “Coming soon” banner. Searching around the Net I found some images. Here’s how it looks:

fonera_2.0g_1

fonera_2.0g_2

It’s significantly different from the older models, and not only outside.

It has a Ralink chipset, while the other was an Atheros. The CPU now runs @ 300MHz (the Atheros ran @ 180MHz), and even the RAM is larger: 64MBytes, while the Fonera 2.0 had 32MBytes and the older ones (including mine) only 16MBytes.

Other than the usual Internet port, to be connected to an ADSL Modem, this one has 4 10/100MBit ports, so it can also act as a switch for a wired network. And the wifi was upgraded to the latests 802.11n standard, which is faster. The two antennas will probably allow a better wifi signal reception.

The only downside is that the internal FLASH memory remained 8MBytes. However, it is still better than many other routers that only have 4MBytes.

Personally, I also don’t particularly like its case. All previous models came in the distinctive white case that it could be defined “The MacBook of the routers” (even if MacBooks aren’t white anymore). Now it looks like a “standard” router.

Last note: I couldn’t find a picture of the circuit board, and there’s no info on the presence of the serial port connector. Still too early, I guess.

English or Italian?

September 4, 2009

This is the same problem I faced when I started my website: what language to choose…
With the website I’ve chosen Italian, but I couldn’t consistently enforce the choice, and some articles were also written in English.
Probably the same will happen with this blog, even if the chosen language is English, sooner or later posts in Italian will appear…

Blog online, site updated

September 3, 2009

Finally after a long time I decided to update my website’s homepage, and open a blog.
My website really needed an update. The problem wasn’t the lack of graphics, I don’t care about that, it was usability. The home page only had two links to a “projects” and an “articles” webpage. To see the content of the website one had to click those links. Now I pushed both projects and articles directly on the homepage, so that the content of the site can be viewed at a glance.
However it took some time to make a proper layout (even if simple) with CSS, and it wasn’t a fun experience. Definitely web development is not for me…


Follow

Get every new post delivered to your Inbox.

Join 30 other followers