Sunday, December 31, 2006

BlueTooth under Linux on a Sony Vaio VGN-S5VP/B

I finally took some time and tested bluetooth under GNU/Linux (Debian Testing) on my Sony Vaio VGN-S5VP/B. I had to say that everything went quite smooth, and everything seems to work fine (although I only tested file sending).

This post should be considered complementary to this page, where I described the installation of Debian GNU/Linux on this laptop.

First of all I installed all the necessary software:

apt-get install bluez-utils libbluetooth1 bluez-hcidump bluez-pin

and then I configured and recompiled the kernel (in this case a 2.6.18 installed from the Debian repository, i.e., it's not a vanilla kernel): under Networking enable Bluetooth Subsystem Support, and then, from there enable the options:

CONFIG_BT=m
CONFIG_BT_L2CAP=m
CONFIG_BT_SCO=m
CONFIG_BT_RFCOMM=m
CONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_BNEP=m
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
CONFIG_BT_HIDP=m
and then enable all the options in the bluetooth device drivers.

Once you boot with the new kernel you can check from dmesg the Bluetooth information:
dmesg | grep Bl
Bluetooth: Core ver 2.10
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: HCI USB driver ver 2.9
Bluetooth: L2CAP ver 2.8
Bluetooth: L2CAP socket layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM ver 1.8
Bluetooth: BNEP (Ethernet Emulation) ver 1.2
Bluetooth: BNEP filters: protocol multicast
and you should see the above information.

Now you can use the command hciconfig (which is basically the command that corresponds to ifconfig, but for bluetooth), and you should see something like:
hci0:   Type: USB
BD Address: mac address ACL MTU: 384:8 SCO MTU: 64:8
UP RUNNING PSCAN
RX bytes:602 acl:0 sco:0 events:60 errors:0
TX bytes:486 acl:0 sco:0 commands:40 errors:0
where mac address should report the mac address of your bluetooth device.

Moreover, you can scan for bluetooth devices with the following command:
hcitool scan
for instance, you should see your mobile phone mac address (if bluetooth is enabled on the mobile phone).

Now you can go on using your own software for accessing your bluetooth devices (probably described on a next post :-)

Wednesday, December 27, 2006

PhpBibliography 0.4 - web based bibliography system

I've released version 0.4 of PhpBibliography, http://phpbibliography.sourceforge.net, a web based bibliography system that allows you to publish your bibliography online (and to edit it via web). It is implemented in Php and uses MySql. This is free software, open source, released under GPL.

There are many new features in this release (I hope you find useful).

First of all, you can also modify a paper by using a bibtex (previously you could only insert a new paper by using a bibtex). For this reason, the bibtexkey field was added to the database (and w.t.r. I added also the function in the admin menu to automatically generate bibtex key for papers which do not have it yet). Furthermore, you can also upload an entire bib file; this will allow you to set up the bibliography site with only one action (of course you'll then be able to modify each inserted paper).

Papers can now be classified according to several criteria (called classifications), not only by using categories. You can add new classifications, and for each classification you'll be able to add values that can be associated to papers. For instance, you can have the classification "keyword", the classification "status" with values "submitted", "to appear", "published", etc. This is very useful also for (virtually) adding a new field to the paper table structure. Classifications can be related to a specific bibtex field, so that they can be retrieved from bibtexs (and also generated in the corresponding field, during the automatic bibtex generation).

A functionality was added (available from the admin menu) that allows you to "merge two authors" that, due to a mistake, represent the same author. (This usually happens when inserting a paper through a bibtex.) For instance you have two authors Foo Bar and Foo T. Bar that represent the same author. With this function, the system will replace the second author with the first author (i.e., the second author will be deleted and all the papers that were associated to the second author will be associated to the first author).

From the paper presentation point of view some customization features were added: you can pass additional parameters in the URL (you can also specify them in the config.php file, but the ones passed on the URL will take the precedence). Here we list these parameters (in the URL they must be passed without the $, using the GET passing method syntax) and their default values:

  • $printfilenames = "1"
    This tells the paper formatter whether to name the link to the paper source using the complete name of the file (e.g., my_paper.ps.gz). If set to "0", then only the extension of the file will be shown (e.g., ps.gz).
  • $linktodetails = "1"
    The title of the paper will link to a separate page with complete details about that paper. If set to "0", no link will be generated.
  • $noheader = "0"
    If set to "1" the generated page will contain no header information (i.e., it will not even contain the css definitions). This is useful when you want to include the output of phpbibliography into another web page and you want customize it with your own css definitions.
  • $paperorder
    Specify the sorting criteria of the shown papers. For the moment the only possible value for this parameter is title (meaning that papers will be ordered according to their title).
For instance, the following screenshot shows the output where printfilenames is set to "1"
while the next one shows the output where printfilenames is set to "0"
Finally, some bugs were fixed (in particular the authentication problem in php 5, due to the use of wrong variable names, see also this post on this blog).

Hope you enjoy this new version of PhpBibliography (yeah, I know, the logo is not that beauty, but that's just the beginning :-)

Saturday, December 23, 2006

Strpbrk in Php


In Php 5 the string function strpbrk was introduced (quoting from the manual):

string strpbrk ( string haystack, string char_list )

strpbrk() searches the haystack string for a char_list, and returns a string starting from the character found (or FALSE if it is not found).


This is quite useful in many cases, but unfortunately it's not available in Php 4. However, it should be quite straightforward to implement it. Here's how I did:

function my_strpbrk($haystack, $char_list) {
$pos = strcspn($haystack, $char_list);

if ($pos == strlen($haystack))
return FALSE;

return substr($haystack, $pos);
}

And this is its usage:

<?php

require_once("strpbrk.php");

$text = 'This is a Simple text.';

// this echoes "is is a Simple text." because 'i' is matched first
echo my_strpbrk($text, 'mi');

// this echoes "Simple text." because chars are case sensitive
echo my_strpbrk($text, 'S');

// returns FALSE
print (!my_strpbrk($text, 'W') ? "FALSE" : "TRUE");
?>

Just my two little cents :-)

Tuesday, December 19, 2006

C/C++ parameters at configure time

If you ever compiled an open source program from sources, you'll surely know the sequence:

./configure
make
make install

In particular, the first command will try to figure out the system you're using for compilation and to set some parameters accordingly (C and C++ compiler, missing features, etc.). This script is usually automatically built using the GNU Autotools, such as autoconf, automake, libtool.

The configure usually assume the following parameters for the C/C++ compiler:

-g -O2

That is, enable debugger information, and perform optimizations and for the end user this might be OK.

However, for the developer, who probably will have to debug the program, having the optimizations enabled might make debugging a nightmare (since some instructions might be rearranged by the optimizer). For this reason, I usually disable optimizations at configuration time simply by using the following configure command line:

./configure CXXFLAGS="-g" CFLAGS="-g"

So that debugging will be much easier!

Tuesday, December 12, 2006

Using Rsync for Remote Backup

I've been using Rsync for a while now for keeping a backup of my stuff on a remote server. Rsync is an open source program for fast incremental file transfer. It can be used to synchronize two remote directories and to synchronize a local folder with a remote folder (which is what I use it for). This also allows me to work on different machines on the same stuff: I download (or update) the stuff from the remote server, work on it, and the commit the changes back on the server.

Notice that rsync can only synchronize in one way (a source with a target, or the other way round, but not in both directions simulataneously); if you need a two way file synchronizer you might want to take a look at Unison.

Anyway, this is how I update my local version of a directory with the version on the server:

rsync -e ssh -avzu --delete -c -C \
--exclude-from=exclude-files \
USER@REMOTEMACHINE:REMOTEDIR LOCALDIR
where
  • -e ssh instructs rsync to use ssh as a remote shell (thus authentication and transfer will use ssh)
  • -a is archive mode (refer to documentation): basically recurs into directories and keeps permissions
  • -v increments verbosity
  • -z compresses the transferred data (very useful when using slow connections)
  • -u skips files that are newer on the receiver
  • --delete deletes files that are in the local folder but not in the remote folder
  • -c uses checksums to determine which files need to be synchronized
  • -C auto-ignores files in the same way CVS does
  • --exclude-from excludes all the files (using also regular expressions) specified in the file exclude-files.
  • USER is my user name on the REMOTEMACHINE
  • REMOTEDIR is the complete path of the folder on the remote machine and LOCALDIR is the path of the local folder (IMPORTANT: do not append the final slash on these paths otherwise the semantics changes, see the documentation)
Another useful option is -n or --dry-run that only simulates the transfer (so that you can see which files would be transferred).

And exclude files contains these regular expressions:
*~
*.dvi
*.aux
*.log
*.bbl
*.blg
*.toc
*.bak
*.idx
*.ilg
*.ind
*.class
*.out
core
But of course you can modify it as you see fit.

When I want to commit my local changes to the remote server I basically run the above command inverting source and destination:
rsync -e ssh -avzu --delete -c -C \
--exclude-from=exclude-files \
LOCALDIR USER@REMOTEMACHINE:REMOTEDIR
This is only one use of rsync. I refer to the documentation for more advanced usage. Hope you enjoy rsync as much as I do :-)