Tuesday, December 23, 2014

Installing libgroove and nodejs groove module in Raspbian

As we are working on small internal hobby project turning the Raspberry PI into a music box, I came across the need for building the nodejs groove module which requires a pretty big amount of effort. I'm going to provide you with the instruction for building from source.

UPDATE: If using testing/unstable repo is not a problem for you, an alternative method is available and is much faster by using binary packages. Jump to the "Install using testing/unstable binary packages"  section.

Install from source

This is the shorten version of the build script for Raspbian Wheezy that I think it may be useful for other ones struggling with a similar task.

Note: this is the simplified version of a great guide created by Andrew Kelly: Turn Your Raspberry Pi Into a Music Player Server

# install tools and libs
sudo apt-get install cmake git screen
sudo apt-get install libchromaprint-dev libspeexdsp-dev libasound2-dev libmp3lame-dev libvorbis-dev

# install libebur128 from source
cd
git clone https://github.com/jiixyj/libebur128
cd libebur128/
mkdir build
cd build/
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
sudo make install
sudo mv /usr/local/lib/arm-linux-gnueabihf/* /usr/local/lib/
sudo rmdir /usr/local/lib/arm-linux-gnueabihf
sudo ldconfig

# install SDL2 from source
cd
wget https://www.libsdl.org/release/SDL2-2.0.3.tar.gz
tar xvf SDL2-2.0.3.tar.gz
cd SDL2-2.0.3/
./configure --enable-audio --disable-video --disable-render --disable-events --disable-joystick --disable-haptic --disable-power --disable-file --disable-timers --disable-loadso --disable-cpuinfo
make
sudo make install

# install libav from source, will takes about 9hrs (!), consider using 'screen'
cd
wget http://www.libav.org/releases/libav-10.1.tar.gz
tar xvf libav-10.1.tar.gz
cd libav-10.1/
./configure --enable-shared --enable-debug --disable-static --enable-gpl --enable-libmp3lame --enable-libvorbis
make
sudo make install
sudo ldconfig

# install libgroove from source
cd
git clone https://github.com/andrewrk/libgroove
cd ~/libgroove/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
sudo make install
sudo ldconfig
ls /usr/local/lib/

#install newer nodejs ARM, this is optional
get https://github.com/needforspeed/Nodejs-ARM-builder/raw/master/v0.10.33/nodejs_0.10.33-armv6_armhf.deb
sudo dpkg -i nodejs_0.10.33-armv6_armhf.deb
which node


#install nodejs groove
npm install groove -g

Install from testing/unstable binary packages

At the time of writing, the testing repository of Raspbian contains a usable set of binary packages that are sufficient for installing node groove module.

Step 1: switch to testing

Edit the /etc/apt/sources.list to replace wheezy with testing, so that the first line of the file reads:

deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi

Step 2: update and install the libraries

sudo apt-get update
sudo apt-get install libgroove4 libgroove-dev libgroovefingerprinter4 libgroovefingerprinter-dev libgrooveloudness4 libgrooveloudness-dev libgrooveplayer-dev libgrooveplayer4

Step 3: install node groove module

npm install groove -g


Thursday, February 20, 2014

Make your camera DICOM-able with a Raspberry PI

As I'm working on a medical product which includes almost all aspects of medical services, working with DICOM is one of my primary items. I came accross a requirement for integrating standard photo cameras into the system so that photos taken from those cameras can be easily imported into medical results. This initially came from an international clinic where physicians use high resolution EOS cameras to take patient's skin photos.

Our medical solution has a built-in feature that accepts images sent from DICOM compliant devices like ultrasound machines so my primary path for the intergration is to make the cameras DICOM-able. There are however several constraints for the solution:
  • There will be a large set of camera models that we need to support, ranging from low-end ones like the Canon IXUS to something like the 7D series.
  • The solution needs to be independent from the user workstation operation system as the users of our medical product can use different types of OS including Windows, OS X or GNU/Linux.
  • User operation needs to be as simple as possible as we want to avoid any redundant step in manually selecting the files and sending them.
My solution for this was to use a Raspberry PI, loaded with Pidora and custom scripts to work with the camera and send captured photos via the network to the DICOM storage server.

To support different camera models, I used the gphoto2 command line tools to watch camera activities and download photos to the Rasperry PI. The connection between the Raspberry PI and the camera is a USB cable. Downloaded photos will be then converted into DICOM files and sent to the server using the dcmtk command line tools. The following steps provide you with the details on how to get it done:

Step #0:
Prepare your Raspberry PI with Pidora. Connect it to the camera using a USB cable and to the local network using an ethernet cable.

Step #1:
Install necessary tools:

# yum -y install gphoto2 dcmtk

Step #2:
Make a main script that invoke gphoto2 and watch for captured photos

$ nano capture.sh
#!/bin/sh

while :
do
    export CAMERA=`gphoto2 --summary --quiet 2>&1 | grep "Model: " | sed "s/Model: //"`
    if [ "x$CAMERA" = "x" ]; then
        sleep 1
        continue
    fi
    gphoto2 --quiet --capture-tethered --hook-script=camhook.sh
done


Step #3:
Make the script that handles the downloaded photo and send it via DICOM

$ nano camhook.sh
#!/bin/sh

if [ "x$ACTION" = "xdownload" ]; then
    echo "Converting to DICOM..."
    img2dcm -k "PatientName=$ARGUMENT" $ARGUMENT $ARGUMENT.dcm
    echo "Sending to storage..."
    storescu -aet "$CAMERA" --propose-jpeg8 192.168.100.51 9104 "$ARGUMENT.dcm"
    echo "Done."
    rm $ARGUMENT.dcm
fi



After having all the setup done, starting the capture.sh will make your camera now DICOM-able.



Thursday, October 11, 2012

Pencil on Fedora

An exciting news today is that Pencil has been officially approved and made available for Fedora users. Users of Fedora 16, 17 and also 18 (beta) can now easily install Pencil via yum.

Repository information for Pencil in Fedora 17:

# yum info pencil
Loaded plugins: downloadonly, langpacks, presto, refresh-
              : packagekit, versionlock
Available Packages
Name        : pencil
Arch        : noarch
Version     : 2.0.1
Release     : 1.fc17
Size        : 1.4 M
Repo        : updates
Summary     : A sketching and GUI prototyping tool
URL         : http://code.google.com/p/evoluspencil/
License     : GPLv2
Description : Pencil is an open source GUI prototyping and
            : sketching tools released under GPL.

Thursday, March 10, 2011

Top five reasons why I don't use Chrome

As an opensource enthusiast, I love the Chromium project but there are things that keep me away from using Chromium-based web browsers for everyday browsing needs.

Reason #0: Font rendering is ugly
Google Chrome and Chromium (or Chrome for short) do not respect the desktop environment settings for font rendering. They use their own wrapping of freetype to produce a bad kerning and anti-aliasing result. This is not a problem of Webkit since other browsers including Midori do a very good job while using the same core as Chrome.

Google, don't tell me that I do not need to read texts when browsing the web.

Reason #1: Stupid cropping of titles in the tab bar
Chrome failed to render itself as a browser with excellent usability as claimed. By default, Chrome shows the page titles only in the tab for each page. The page titles seem to be always cropped and it's getting really hard for me to read the page title.

Google as a search giant knows very well how important a page title is but with Chrome they imply that "It's not any important, dude. Trust me. You don't want to read it."

Reason #2: No built-in tree-based XML view
I'm a programmer and it's my everyday need to inspect XML resources. Chrome claimed to be a developer-friendly browser but viewing XML files with it is funny.

Reason #3: I hardly see to where a bottom-left link points
For many cases, hovering over a link located a the bottom-left corner of the browser window hides the status bar which is displaying the target URL. This forces me to make a scroll-up to see the link location.

Reason #4: It should be named Chrashium
Yes, it crashes frequently on my desktop regardless it is a Google official build or a Chromium build.

Monday, December 27, 2010

Đọc được trong tự truyện

của Giáo Sư Trần Văn Khê:

"Từ câu chuyện này, tôi muốn nêu ra một thí dụ cụ thể của một người nghệ sĩ lớn ngoài tài nghệ còn có những đức tánh mà bạn trẻ nên noi theo. Một là, khi gặp khó khăn, không bao giờ bó tay mà phải quyết tâm tùy cơ ứng biến để vượt qua. Hai là, phải biết thích nghi với hoàn cảnh. Ba là, nên có lương tâm nghề nghiệp không bao giờ tự mãn với kinh nghiệm của mình mà luôn luôn phải luyện tập nhiều và khi đến một sân khấu lạ cũng cố gắng diễn tập một lần để không bị bỡ ngỡ trước ngoại cảnh khác."

Friday, May 21, 2010

Viettel 3G USB Modem with Fedora

I got myself a Viettel 3G USB stick yesterday for the need of roaming access while I'm off the city. I tried it first with my colleague's Windows machine. The stick worked well with Windows but in ridiculous way. It shown up in a dedicated, silly designed window frame with the ISP heavily branded. That's still acceptable, anyway.

I booted up my laptop which has only Fedora 12 to see how the stick behaves in GNU/Linux. Plugging in the USB in with a really hopeless mind since I know clearly that Linux is not what they are willing to support. And that was clearly documented in the tiny user manual I got when purchasing the stick.

I was right. It did not work. To be honest, it actually worked as a storage device since I found a fake CD-ROM shown up with the name of D-COM.

And that was the interesting clue for me to solve the problem. I googled for the whole day, asked in the forum to have it finally solved in the sweetest way!

To save others' time, here follows a complete guide for Fedora users:

Background

Modems provided Viettel are produced by Huawei and the one I got is the Huawei E1750. Huawei and many other manufactures use a method (which they actually call 'technology') in which the device will behave as a fake CD-ROM when just plugged in. This is to allow the manufacture to ship the installation CD contents right within the device instead of having a real CD-ROM attached.

An autorun application for Windows is included in the fake CD-ROM to start the driver installation process.

After the installation is done the driver is up and to begin the use of the stick as a real modem, a special data sequence is sent by the driver to the device in order to ask it to switch the USB interface into the modem mode. From that on, the USB can be used as a 3G GSM modem. The USB will kept itself switched as long as the power to it is not cut.

This is really clever! A CD-ROM and GSM Modem within just a single USB stick.

Problem with GNU/Linux

The clever part of the device is also the problematic part of it in GNU/Linux. While Huawei GSM modem support is added into the kernel, the activation of the GSM modem mode is however not straightforward.

When the device is plugged in, the OS recognizes it as a storage device only. What we have to find out is how to switch the device into the GMS mode.

Fortunately, a dedicated project was created for just this purpose. The usb_modeswitch program! The latest version of this program is included in the Fedora 12 official repository.

Switching the mode with usb_modeswitch

usb_modeswitch is a helper application that integrates into udev to watch for USB devices. When a device is plugged in, usb_modeswitch lookups the just-plugged-in device vendor and product ID in its internal registry and carries out an appropriate operation in order to switch the device into the GMS modem mode. This perfectly fits our need for the Huawei device. The following steps help you install the switching:

Step 1: Installing usb_modeswitch

usb_modeswitch can be installed easily with yum:

#yum -y install usb_modeswitch

Step 2: Removing wrong udev entries

An important thing that you have to do is to resolve a conflicts in using the device. To do this, find the file at /lib/udev/-modem-modeswitch.rules and comment out the line that mentions the Huawei device (Huawei devices have the vendor:product id of 12d1:1446)

May thanks to Josh for guiding me in this section.

Step 3: Reboot

There may be other ways but this is the most simple one to get udev reloaded.

Configuring the connection

After rebooting and plugging in your device you can now configured the connection using NetworkManager. And this is what I found it is so sweet, the Linux way of configuring network connection. You have a single, united and well designed graphical user interface for all network connections of all types, all kind of devices.

Adding a new connection

Right-click the NetworkManager panel icon, select 'Edit Connections...', select the 'Mobile Broadband' and click 'Add'

The Huawei device should be listed in the device list, select it and click 'Forward'.

Since Vietnam may not be listed in this version of NetworkManager, just select 'My country is not listed' and then 'Forward'

Enter Viettel in the Provider box. This is not a configuration parameter, you can choose another name. However, this will be used in the default connection name so I suggest that you have the ISP name here.

Enter 'e-connect' as the Access Point Name. This is an important configuration parameter. I found it when inspecting the Windows application shipped with the modem. No information for this parameter is officially provided by the ISP.

Click 'Forward'.

Just click 'Apply' in this confirmation screen.

Modify the connection name if you want and click 'Apply'. The configuration is done you can now start using the connection.

Using the connection

Clicking the NetworkManager panel icon you will find that connection is now listed and ready for use:

Select the connection and wait for the modem to get connected, you can now start using the 3G connection!










Tuesday, July 28, 2009

Đối với những người

không nhận ra những gì mình mang cho họ thì đừng mong họ có thể cùng mình làm những việc gì lâu dài hay to lớn.

--Ranh ngôn - Luis De Monkey