Pages

23 December 2012

301. Building Mosquitto 1.0.5 on debian stable

Here's what I did in a chrooted Stable while writing up a reply for this post: http://forums.debian.net/viewtopic.php?f=10&t=90444

I've changed the commands a little bit from http://mosquitto.org/2012/11/making-mosquitto-packages-for-debian-yourself/ to be more faithful to my own style. Edit your /etc/apt/sources.list so that it has both stable and testing e.g.

deb http://ftp.au.debian.org/debian stable main
deb http://ftp.au.debian.org/debian testing main

and edit /etc/apt/preferences
Package: *
Pin: release a=stable
Pin-Priority: 990

Package: *
Pin: release a=testing
Pin-Priority: 800

Followed by

sudo apt-get update
sudo apt-get install build-essential python quilt libwrap0-dev libssl-dev devscripts python-setuptools
sudo apt-get install libssl-dev=1.0.1c-4 python3


Then

mkdir ~/tmp
cd ~/tmp
wget http://mosquitto.org/files/source/mosquitto-1.0.5.tar.gz -O mosquitto_1.0.5.orig.tar.gz
tar xvf mosquitto-1.0.5.orig.tar.gz
cd mosquitto-1.0.5/
wget http://mentors.debian.net/debian/pool/main/m/mosquitto/mosquitto_1.0.5-1.debian.tar.gz
tar xvf mosquitto_1.0.5-1.debian.tar.gz
debuild -us -uc
sudo dpgk -i ../*mosquitto*.deb


and you'll find the .debs in the parent folder.


Links to this page:
http://jtlog.wordpress.com/2013/01/04/raspberry-pi-mosquitto/

300. Briefly: Sharing a folder using SAMBA on Debian

I don't ever use samba, but it's not a bad thing to know how to set up in case you need to share files with someone using Windows in a pinch.

First install samba:
sudo apt-get install samba samba-common smbclient

To get a share up with samba, create an /etc/samba/smb.conf and stick the following in it:


[global]
workgroup=WORKGROUP
guest account=nobody
security=shared


[asharedfolder]
path=/home/lindqvist/shared
guest ok=yes
read only=no
writable=yes
browsable=yes
comment= SMB share

Restart samba:
sudo service samba restart

1. This is an insecure share i.e. <b>anyone can access it</> and edit everything.
2.. Also, by omitting "netbios name=  " you can use the IP address of the server as the hostname, but you could also specify e.g. "netbios name=niobium" and use that as the hostname in nautilus when you connect to the host server.

To set up a user- and password-based share, do



[global]
workgroup=WORKGROUP
security=user


[asharedfolder]
path=/home/lindqvist/shared
guest ok=no
read only=no
writable=yes
browsable=yes
comment= SMB share

You need to add and set the samba password, and enable the linux user you want to give access as well:
sudo smbpasswd -L -a -e lindqvist


There are a lot of other options that can be set. Two of the more interesting ones are probably

[asharedfolder]
createmask=0755
valid users=me myself irene

which means that any new files created in that share via samba gets chmod 755, and only the users me, myself and irene can connect.

But often a basic smb.conf is easier to manage and will do what you want it to.

22 December 2012

299. Briefly: Start autossh at boot on debian testing/wheezy

I have one of my work computers set up to create a reverse tunnel to my WRT54G router at home, so that by login in to my router at home and then connecting to localhost:19996 I can access my work network from home. The problem is that if I reboot my work computer remotely I need to make sure that it tries to recreate the reverse ssh tunnel.

The way to do that is by editing /etc/rc.local and putting the following in it:
su lindqvist -c 'autossh -N -f -M 29001 -R 19996:localhost:22 remoteuser@my.router.com' &

Make sure you put it before the line that says
exit 0

linqdvist is the user at on my work computer I want to be running the autossh, 19996 is the port I'll connect to on my home router to gain access to the ssh port on my work computer. Since I'm using WRT54G with Tomato the remoteuser is root, and I got my dns (remote hostname) as shown in this post: http://verahill.blogspot.com.au/2012/02/tomato-router-and-free-dns.html
It's that simple.

298. Hantek DSO 2250 USB with Openhantek on Debian Testing/Wheezy /Linux

Update 23 May 2013: Updated as per Peter Jeffris' suggestion (see below)/

UPDATE: this has been updated as per the developer's (Oliver Haag) recommendations (see first comment)

Original post:
I wanted to get Hantek DSO-2250 USB running on debian. I first tried openhantek 0.2.0 but it doesn't support the DSO-2250, so I ended up using the development version. I had to get the configure and Makefile.in files from another source though (see below).

I finally got the scope to work as shown below -- I primarily needed it for some work on NMR probes I did two years ago, but better late than never.

Probe set to X1

Probe set to X10


Before installing anything, on plugging in the oscilloscope we get:
dmesg
[10885.993061] usb 2-2: USB disconnect, device number 3
[10894.913984] usb 1-2: new high-speed USB device number 9 using ehci_hcd
[10895.046104] usb 1-2: New USB device found, idVendor=04b4, idProduct=2250
[10895.046117] usb 1-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[10895.398887] usb 1-2: USB disconnect, device number 9
[10895.668190] usb 1-2: new high-speed USB device number 10 using ehci_hcd
[10895.800317] usb 1-2: New USB device found, idVendor=04b4, idProduct=2250
[10895.800330] usb 1-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0

lsusb
Bus 001 Device 010: ID 04b4:2250 Cypress Semiconductor Corp.

Openhantek

sudo apt-get install subversion autoconf automake build-essential unrar
cd ~/tmp
svn checkout http://svn.code.sf.net/p/openhantek/code/trunk openhantek-code
cd openhantek-code/
sudo apt-get install libqt4-dev libfftw3-dev qt4-qmake fxload libusb-1.0-0-dev libbfd-dev
cd openhantek/
qmake
make
sudo make install
cd ../openhantek-extractfw/
aclocal && autoconf && automake
./configure
make
wget http://www.hantek.com.cn/Product/32Driver/2250/Driver.rar
unrar x Driver.rar
UNRAR 4.10 freeware Copyright (c) 1993-2012 Alexander Roshal Extracting from Driver.rar Creating Driver OK Extracting Driver/DSO22501.sys OK Extracting Driver/DSO22502.sys OK Extracting Driver/dso2250usb.inf OK All OK
./openhantek-extractfw Driver/DSO22501.sys
BFD: Driver/DSO22501.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .text BFD: Driver/DSO22501.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .data Section .data found (starting at 0x08a0, 9504 bytes) Symbol _firmware found (offset 0x0000, 8184 bytes) Symbol _loader found (offset 0x1ff8, 1320 bytes) Saving firmware as Driver/dso2250-firmware.hex Saving loader as Driver/dso2250-loader.hex
sudo mkdir -p /usr/local/share/hantek sudo cp Driver/*.hex /usr/local/share/hantek/

While tempting (the ID shows up as 04b4 above), do NOT change the part marked in red in 90-hantek.rules since changing it requires you to run as root. It works fine as user if you leave it alone.
 13 # Hantek DSO-2250
 14 SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="4b4/2250/*", RUN+="/sbin/fxload -t fx2 -I /usr/local/share/hantek/dso2250-firmware.hex -s /usr/local/share/hantek/dso2250-loader.hex -D $env{DEVNAME}"
 15 SYSFS{idVendor}=="04b5", SYSFS{idProduct}=="2250", MODE="0660", GROUP="plugdev"
sudo cp 90-hantek.rules /etc/udev/rules.d/
sudo service udev restart
sudo usermod -a -G plugdev $USER

Plug in your oscilloscope:
[ 4216.277235] udevd[23240]: starting version 175
[ 4246.532221] usb 2-2: new high-speed USB device number 5 using ehci_hcd
[ 4246.664559] usb 2-2: New USB device found, idVendor=04b4, idProduct=2250
[ 4246.664570] usb 2-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 4246.718694] usb 2-2: USB disconnect, device number 5
[ 4248.492214] usb 2-2: new high-speed USB device number 6 using ehci_hcd
[ 4248.625224] usb 2-2: New USB device found, idVendor=04b5, idProduct=2250
[ 4248.625238] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 4248.625246] usb 2-2: Product: DSO-2250 
[ 4248.625252] usb 2-2: Manufacturer: ODM

At this point the light on the oscilloscope was blinking red.
openhantek

Check the 'show spectrum' thingy (I'm running this with the probe on CH1 connected to the square wave cal at the back of the scope).

Done.

21 December 2012

297. WakeOnLan with etherwake, ethtool -- working with onboard NIC

I've looked at this on and off during the past two years and never managed to get it to work -- until today. I leaned heavily on https://wiki.debian.org/WakeOnLan to get it to work.

Not sure what made the difference -- probably the ethernet-wol g line -- but here's what I did:


First activate wake on lan in the bios on whatever computer you're using. In an ideal world that'd just be a matter of changing 'Wake On Lan' to enabled, but it's not always that easy. Typically, you'll be looking under power options.

On Optiplex 990, go to power options, and enable Wake On Lan.
On Gigabyte 990-fxa-d3 there's no such option. Just make sure that ErP support is NOT enabled.
On Biostar N68S3+, just enable Wake On Lan and you'll be fine.

On none of these could I boot using the PCI/PCIe NIC devices i.e. only the onboard NICs worked.


Next on each computer which you wish to boot, install ethtool.
Then edit /etc/network/interfaces and add ethernet-wol g for each IF that you want to boot with:

auto eth0
iface eth0 inet dhcp
ethernet-wol g

auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.1
ethernet-wol g

Finally, on the computer you wish to boot from, install etherwake from the repos. Then do
sudo etherwake -i eth3 78:2b:cb:b3:a4:a5
where eth3 is the interface on the local computer that is on the same LAN as the interface on the remote computer that you wish to boot, and 78:2b:cb:b3:a4:a5 is the MAC address of the remote computer's interface.

I've tried this successfully on:
* Optiplex 990 -- onboard NIC only
* gigabyte 990-fxa-d3 -- onboard NIC only
* Biostar N68S3+. Bios: American Megatrends 08/26/2010. On-board NIC only.


19 December 2012

296. Building Wine 1.5.19 on Debian (Wheezy/Testing) without errors

UPDATE 16 May 2013: See here for Wine 1.5.30: http://verahill.blogspot.com.au/2013/05/416-wine-1530-in-chroot.html

UPDATE (10th Jan 2013): See here for Wine 1.5.21 using the multiarch approach: http://verahill.blogspot.com.au/2013/01/308-compiling-wine-1521-on-debian.html

This time we'll be cheating and using the carbon-dev.org debian rules to build wine 1.5.19, which works amazingly well with a tiny bit of editing. In spite of what it looks like, this build is easy.



This is also my first encounter with multiarch since libgsm was causing issues (think it's moved out of ia32). Ultimately, multiarch will be the proper way to build 32-bit wine anyway, but I'll deal with that some other day.

Interesting fact: if you try to build with ... 1>build.log 2> build.err the build will fail since files are changing in the main directory during build. Make sure that you do e.g. .. 1> ../build.log 2> ../build.err if you want to track the build.

Finally, I've also built wine 1.5.18 this way, in addition to wine 1.5.19.

The build starts here:

Here's my current best guess at dependencies (Note that multiarch on ubuntu is a little bit different from Debian.):
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install ia32-libs ia32-libs-dev bison flex gcc libc6-dev libfontconfig-dev libfreetype6-dev libglu-dev libgsm1-dev libice-dev libjpeg-dev libldap-dev libmpg123-dev libncurses5-dev libopenal-dev libpng-dev libsm-dev libssl-dev libusb-dev libx11-dev libxcomposite-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxml2-dev libxrandr-dev libxrender-dev libxslt-dev libxt-dev libxxf86vm-dev make libcapi20-dev liblcms-dev libsane-dev libhal-dev libdbus-1-dev valgrind prelink libcups2-dev opencl-dev lib32opencl1 oss4-dev gettext lib32v4l-dev lib32ncurses5-dev lib32asound2-dev libtiff4-dev libgphoto2-2-dev libxkbfile-dev libxxf86dga-dev freeglut3-dev unixodbc-dev gcc-multilib
sudo apt-get install libgsm1:i386
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: gcc-4.7-base:i386 libc6:i386 libc6-i686:i386 libgcc1:i386 Suggested packages: glibc-doc:i386 locales:i386 The following NEW packages will be installed: gcc-4.7-base:i386 libc6:i386 libc6-i686:i386 libgcc1:i386 libgsm1:i386 0 upgraded, 5 newly installed, 0 to remove and 2 not upgraded. Need to get 5,412 kB of archives. After this operation, 11.9 MB of additional disk space will be used. [..]
Once you've got that sorted, it is time to download the sources:
mkdir -p ~/tmp/wine_1.5.19_carbon/
cd ~/tmp/wine_1.5.19_carbon/
wget http://mirrors.ibiblio.org/wine/source/1.5/wine-1.5.19.tar.bz2 -O wine-unstable_1.5.19.orig.tar.bz2
tar xvf wine-unstable_1.5.19.orig.tar.bz2
cd wine-1.5.19/
wget http://dev.carbon-project.org/debian/wine-unstable/wine-unstable_1.5.5-0.1.debian.tar.bz2
tar xvf wine-unstable_1.5.5-0.1.debian.tar.bz2
rm wine-unstable_1.5.5-0.1.debian.tar.bz2

We could do the editing the proper way, or the quick way. Since I'm not really that familiar with build debian packages the right way (I cheat using checkinstall) we're doing this the quick and dirty way:
sed -i 's/1.5.5/1.5.19/g' debian/changelog
sed -i 's/\-4.5//g' debian/rules
sed -i 's/\-4.5//g' debian/control
sed -i 's/\-4.5//g' debian/control.in

Next, edit debian/patches/series and change it from
  1 debian-changes-from-1.1.32-1.patch
  2 readd_xpm.patch
  3 function_grep.patch
  4 Bug#29669_proposed-fix.patch
  5 fix-winegcc-paths.patch
  6 Bug#28898_squashed-proposed-patches.patch
  7 Bug#28201_proposed-fix-modified.patch
to
  1 debian-changes-from-1.1.32-1.patch
  2 readd_xpm.patch
  3 function_grep.patch

And build:
time dpkg-buildpackage -uc -us

The entire build takes about 40 minutes and gives the following files:
../libwine-alsa-unstable_1.5.19-0.1_amd64.deb
../libwine-dbg-unstable_1.5.19-0.1_amd64.deb
../libwine-ldap-unstable_1.5.19-0.1_amd64.deb
../libwine-sane-unstable_1.5.19-0.1_amd64.deb
../libwine-bin-unstable_1.5.19-0.1_amd64.deb
../libwine-dev-unstable_1.5.19-0.1_amd64.deb
../libwine-openal-unstable_1.5.19-0.1_amd64.deb
../libwine-unstable_1.5.19-0.1_amd64.deb
../libwine-capi-unstable_1.5.19-0.1_amd64.deb
../libwine-gl-unstable_1.5.19-0.1_amd64.deb
../libwine-oss-unstable_1.5.19-0.1_amd64.deb
../wine-bin-unstable_1.5.19-0.1_amd64.deb
../libwine-cms-unstable_1.5.19-0.1_amd64.deb
../libwine-gphoto2-unstable_1.5.19-0.1_amd64.deb
../libwine-print-unstable_1.5.19-0.1_amd64.deb
../wine-unstable_1.5.19-0.1_amd64.deb

To install,
cd ../
sudo dpkg -i *.deb

And you're done.
To confirm what version you're using (and get a screenshot like above) do
winecfg
and click on 'about'.

Links to this post:
http://www.debian-srbija.iz.rs/p/kako-da.html

295. Patching kernel 3.7.1 to fix the azx_runtime_suspend bug

(For a general approach to compiling kernel 3.7,see http://verahill.blogspot.com.au/2012/12/compiling-kernel-37-on-debian.html )

Note that it is NOT necessary to patch version 3.7.2

If you're seeing the following error messages during boot of kernel 3.7.0:
azx_runtime_suspend
pci_pcm_runtime_suspend
snd_hda_intel returns -11
you will want to patch your kernel. Technically I should be patching 3.7, but we might as well go straight for kernel 3.7.1.

So, here's how to patch it:
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.7.1.tar.bz2
tar xvf linux-3.7.1.tar.bz2
cd linux-3.7.1/
cat /boot/config-`uname -r`>.config
make oldconfig
wget https://patchwork.kernel.org/patch/1865521/raw/
mv index.html hda_intel.patch
patch -i hda_intel.patch -p 1
patching file sound/pci/hda/hda_intel.c Hunk #1 succeeded at 2557 (offset -134 lines). Hunk #2 succeeded at 2571 (offset -134 lines).
make-kpkg clean time fakeroot make-kpkg -j3 --initrd --revision=3.7.1 --append-to-version=-amd64 kernel_image kernel_headers

Once building is complete
mv ../*3.7.1*.deb .
sudo dpkg -i *.deb
and reboot.

Tried it and it works.

294. Bruker 1D processing using octave/matlab

I wanted a set of scripts that behaved a little bit like the commands in bruker xwin-nmr/topspin, so that I could do some quick processing for visual inspection without having to do too much coding.

I also wanted some simple modules that I can plug into automated processing routines for large numbers of spectra (e.g. when doing kinetics).

So here are a few simple octave routines which should work in matlab as well. They won't change the world, but should be good enough for some basic 1D processing.

Because of the groupdelay (GRPDLY) used in by Bruker (see e.g. here (16th of June post) and here), you need to use the bruk2ana converter. There's little science behind the values which are applied since they are hardware specific.



Example workflow:

./bin2ascii experiment_1/1 fid
getpar experiment_1/1 my.par

octave:1> [fid,pars]=loadfid('fid.ascii','my.par');
octave:2> [zfid,pars]=zf(fid,pars);
octave:3> [test,phc1]=bruk2ana(zfid,pars);
octave:4> test=em(test,0.5);
octave:5> plot(test(:,1),test(:,3));
octave:6> spectrum=ft(test,pars);
octave:7> phased=apk(spectrum,phc1);
octave:8> final=absd(spectrum);
octave:9> pltspec(final)




Linux shell-scripts

bin2ascii
#!/bin/bash
#bin2ascii dir fid
cp $1/$2 $1/$2.bak
ls $1/$2.bak | cpio -o | cpio -i --swap -u
od -An -t dI -v -w8 $1/$2.bak| gawk '{print NR,$1,$2}' > $2.ascii

getpars
 #!/bin/bash
 #getpars $1 $2
 # $1 is the location (directory or .) and $2 is the root of the output file name
 SW=`cat $1/acqus | grep 'SW_h' | sed 's/\=/\t/g' | gawk '{print $2}'| tr -d '\n'`
 TD=`cat $1/acqus | grep 'TD=' | sed 's/\=/\t/g' | gawk '{print $2}'| tr -d '\n'`
 O=`cat $1/acqus | grep '$O1=' | sed 's/\=/\t/g' | gawk '{print $2}'`
 SFO=`cat $1/acqus | grep 'SFO1=' | sed 's/\=/\t/g' | gawk '{print $2}'`
 DECIM=`cat $1/acqus | grep 'DECIM=' | sed 's/\=/\t/g' | gawk '{print $2}'`
 DSPFVS=`cat $1/acqus | grep 'DSPFVS=' | sed 's/\=/\t/g' | gawk '{print $2}'`
 echo $SW > $2
 echo $TD >> $2
 echo $O >> $2
 echo $SFO >> $2
 echo $DECIM >> $2
 echo $DSPFVS >> $2

Octave scripts

loadfid.m
function [fid,pars]=loadfid(infile,parfile)
%%Usage: [fid,pars]=loadfile(infile,parfile)
%%reads a pts, re, im ascii array 
%%generated by bin2ascii
%%and a parfile generated with genpar
 fid=load(infile);
 pars=load(parfile);
 t=linspace(0,(1/(pars(1)/(pars(2)/2))),pars(2)/2);
 fid=[t' fid(:,2) fid(:,3)];
end

zf.m
function [newfid,pars]=zf(fid,pars)
%% Usage:[newfid,updatedpars]=zf(fid,pars)
%% Doubles the number of points by zerofilling
 dims=size(fid);
 newfid=[fid' zeros(3,dims(1))]';
 pars(2)=pars(2)*2;
end

bruk2ana
function [fid,phc1]=bruk2ana(fid,pars)
%% Usage: [fid,phc1]=bruk2ana(fid,pars)
%% where phc1 is the first-order phase correction
%% Using https,//nmrglue.googlecode.com/svn-history/r44/trunk/nmrglue/fileio/bruker.py
%% and https,//ucdb.googlecode.com/hg/application/ProSpectND/html/dmx_digital_filters.html
%% The short version is: bruker fid data needs pre-processing and it's hardware dependent

%%D contains the digital filter parameters
D=[[10,2, 44.75];
[10,3, 33.5];
[10,4, 66.625];
[10,6, 59.083333333333333];
[10,8, 68.5625];
[10,12, 60.375];
[10,16, 69.53125];
[10,24, 61.020833333333333];
[10,32, 70.015625];
[10,48, 61.34375];
[10,64, 70.2578125];
[10,96, 61.505208333333333];
[10,128, 70.37890625];
[10,192, 61.5859375];
[10,256, 70.439453125];
[10,384, 61.626302083333333];
[10,512, 70.4697265625];
[10,768, 61.646484375];
[10,1024, 70.48486328125];
[10,1536, 61.656575520833333];
[10,2048,70.492431640625];
[11,2, 46.];
[11,3, 36.5];
[11,4, 48.];
[11,6, 50.166666666666667];
[11,8, 53.25];
[11,12, 69.5];
[11,16, 72.25];
[11,24, 70.166666666666667];
[11,32, 72.75];
[11,48, 70.5];
[11,64, 73.];
[11,96, 70.666666666666667];
[11,128, 72.5];
[11,192, 71.333333333333333];
[11,256, 72.25];
[11,384, 71.666666666666667];
[11,512, 72.125];
[11,768, 71.833333333333333];
[11,1024, 72.0625];
[11,1536, 71.916666666666667];
[11,2048, 72.03125];
[12,2, 46. ];
[12,3, 36.5];
[12,4, 48.];
[12,6, 50.166666666666667];
[12,8, 53.25];
[12,12, 69.5];
[12,16, 71.625];
[12,24, 70.166666666666667];
[12,32, 72.125];
[12,48, 70.5];
[12,64, 72.375];
[12,96, 70.666666666666667];
[12,128, 72.5];
[12,192, 71.333333333333333];
[12,256, 72.25];
[12,384, 71.666666666666667];
[12,512, 72.125];
[12,768, 71.833333333333333];
[12,1024, 72.0625];
[12,1536, 71.916666666666667];
[12,2048, 72.03125];
[13,2, 2.75]; 
[13,3, 2.8333333333333333];
[13,4, 2.875];
[13,6, 2.9166666666666667];
[13,8, 2.9375];
[13,12, 2.9583333333333333];
[13,16, 2.96875];
[13,24, 2.9791666666666667];
[13,32, 2.984375];
[13,48, 2.9895833333333333];
[13,64, 2.9921875];
[13,96, 2.9947916666666667];];

 h=find(D(:,2)==pars(5));
 j=find(D(h,1)==pars(6));
 magickey=D(h(j),3);
 chop=floor(magickey);

 phc1=(magickey-chop)*2*pi; %the first-order phase correction gets mangled by bruker

 tmp=size(fid); %matlab workaround. rows/columns would be more elegant
 
 newfid=[fid(chop:tmp(1),2:3)' fid(1:chop-1,2:3)']';
 fid=[fid(:,1) newfid(:,1) newfid(:,2)];
 
end

em.m
function fid=em(fid,lb)
%%Usage: fid=em(fid,lb)
%%Exponential multiplication window function
%%Increases Signal-to-noise at the expense
%%of resolution
 fid(:,2)=fid(:,2).*exp(-lb.*fid(:,1));
 fid(:,3)=fid(:,3).*exp(-lb.*fid(:,1));
end

gm.m
function fid=gm(fid,lb)
%%Usage: fid=gm(fid,lb)
%%Gaussian multiplication window function
%%Increases Signal-to-noise at the expense
%%of resolution
 fid(:,2)=fid(:,2).*exp(-(lb.*fid(:,1)).^2);
 fid(:,3)=fid(:,3).*exp(-(lb.*fid(:,1)).^2);
end

de.m
function fid=de(fid,lb,gm)
%%Usage fid=de(fid,lb,gm)
%%Double-exponential window function
%%Increases resolution at the expense of
%%signal-to-noise
 at=max(fid(:,1));
 defun= @(lb,gm,t) (exp(-(t.*lb-gm*at))).^2;
 fid(:,2)=fid(:,2).*defun(lb,gm,fid(:,1));
 fid(:,3)=fid(:,3).*defun(lb,gm,fid(:,1));
end

traf.m
function fid=traf(fid,lb)
%%Usage: fid=traf(fid,lb)
%%TRAF window function
%%Increases resolution at the expense of
%%the signal-to-noise
 at=max(fid(:,1));
 traffun= @(lb,t) (exp(-t.*lb)).^2./((exp(-t.*lb)).^3+(exp(-at*lb)).^3);
 fid(:,2)=fid(:,2).*traffun(lb,fid(:,1));
 fid(:,3)=fid(:,3).*traffun(lb,fid(:,1));
end

ft.m
function spectrum=ft(fid,pars)
%%Usage: spectrum=ft(fid,pars)
%% Spectrum is a complex array with the frequency in
%%the first column and the real and imaginary parts
%%in the second column
%%pars(3)=centrefreq, pars(1)=SW
 spectrum=fftshift(fft(fid(:,3)+i*fid(:,2)));
 tmp=size(spectrum);%matlab workaround
 freq=linspace(pars(3)+pars(1)/2,pars(3)-pars(1)/2,tmp(1));
 spectrum=[freq' spectrum];
endfunction

apk.m
function spectrum=apk(spectrum,phc1)
%%Usage spectrum=apk(spectrum,phc1)
%%Spectrum is a complex matrix with
%%the frequency in the first column
%%and the complex spectrum in the 
%%second column. phc1 is the first order
%%phase correection

 tmp=size(spectrum);
 m=720;
 ph=linspace(-2*pi,2*pi,m);
 maxsig=0;k=1;
 minsig=-inf;
 for n=1:m;
  spex=real( (spectrum(:,2)).*exp(i*(ph(n)+phc1*i/tmp(1))) );
  localmin=min(spex);
        localmax=max(spex);
        if (localmin>minsig) 
                minsig=localmin;
                k=n;
        end
 end
 ph0=ph(k);
 spectrum(:,2)=spectrum(:,2).*exp(i*(ph0+phc1*i/tmp(1)));
end

altapk.m
function [spectrum,ph]=altapk(spectrum,phc0,phc1)
%%Usage -spectrum,ph]=altapk(spectrum,phc0,phc1)
%%Spectrum is a complex matrix with the frequency in the first column
%%and the complex spectrum in the second column. phc0 and phc1 are the first order
%%phase correction parameters, respectively, and are used as initial guesses.
%%This is an implementation of Chen, Weng, Goh and Garland, J. Mag. Res., 2002, 158, 164-168 and depends on entropy.m.

    ph=[phc0;phc1];
        ph=minimize("entropy",{ph,spectrum});

        %compute spectrum with optimal phase params
        pts=linspace(1,size(spectrum(:,2),1),size(spectrum(:,2),1));
        phi=(ph(1)+ph(2).*pts./max(pts))';
        spectrum(:,2)=spectrum(:,2).*exp(i*phi);
end

entropy.m
function E=entropy(ph,spectrum)
%%Used by altapk.m
    pts=linspace(1,size(spectrum(:,2),1),size(spectrum(:,2),1));
        penalty=5.53;

    phi=(ph(1)+ph(2).*pts./max(pts))';
        size(phi);
        spectrum(:,2)=spectrum(:,2).*exp(i*phi);
        R=real(spectrum(:,2));
        size(R);
    Rm=firstderiv(R);
        size(Rm);
    h=abs(Rm)/sum(abs(Rm));
        size(h);

        negs= imag((R).^(1/2));
        negs(find(negs>1))=1;
    P= @(R) penalty.*sum((negs).*R.^2);

    E=-sum(h.*log(h))+P(R);
end

absd.m
function spectrum=absd(spectrum)
%%Usage spectrum=absd(spectrum)
%%Simple (linear) baseline correction
        bsline=@(m) sum(abs(real(spectrum(:,2))-m));
        guess=0;
        p=0;
        newm=minimize(bsline,p);
        spectrum(:,2)=spectrum(:,2)-newm;
end

pltspec.m
function pltspec(spectrum)
%%Usage: pltspec(spectrum)
%%Where spectrum is a complex matrix
%%with the frequency in the first column
%%and the complex spectrum (a+i*b) in the
%%second column
 plot(spectrum(:,1),real(spectrum(:,2)))
end

16 December 2012

293. Running GIMP 2.8 in a chroot on debian stable/squeeze (ugly)

Update: because I had copied and pasted some of the instructions from one of my earlier attempts at building gimp under stable, there were some minor discrepancies. Those are fixed now.

Original post:
Here's the least elegant and functional way of running GIMP 2.8 on stable/squeeze other than running it in a virtual machine.
 I've previously tried
 * creating a statically linked binary of gimp 2.8 under testing, then using it under stable (didn't work --
 * compiling gimp + all dependencies from scratch -- ballooned out of control
 * compiling the bare minimum needed for gimp from scratch, but had issues with libglib2.0-dev -- the dev files are obviously taken care of when you compile glib, but the -dev package is required by a lot of libraries needed for graphics support, and I wanted to replace the libglib2.0-0 package.

Long story short, I gave up. If you don't mind the overhead in terms of space, you can run it in a chrooted environment. It's not pretty, but it works.


We first set up a chrooted environment

sudo apt-get install debootstrap coreutils
mkdir -p $HOME/tmp/architectures/testing
cd $HOME/tmp/architectures
sudo debootstrap --arch amd64 testing $HOME/tmp/architectures/testing/ http://ftp.au.debian.org/debian/
sudo chroot testing/

Cosmetic
Sort out locales to avoid annoying error messages
apt-get install locales
echo 'export LC_ALL="C"'>>/etc/bash.bashrc
echo 'export LANG="C"'>>/etc/bash.bashrc
source /etc/bash.bashrc

Also, add your hostname (=beryllium) to /etc/hosts by putting your hostname at the end of the 127.0.0.1 line:
127.0.0.1 localhost beryllium

to avoid constant warnings about unresolved hostname like the one below
sudo: unable to resolve host beryllium

Continue
I don't like working as root even in a chrooted environment, so create a new user, 'build' and give it superuser powers:
adduser gimp

And edit /etc/sudoers to add
gimp ALL=ALL:ALL
Defaults !tty_tickets

The reason we add the !tty_tickets is that otherwise you will have to type the password each time you use sudo i.e. it will time out instantaneously.

Run the echo command below and exit your chroot:
echo "export DISPLAY=:0.0">>/etc/bash.bashrc
exit
And put this in a file, e.g. gimp.sh
xhost + sudo mount -o bind /proc $HOME/tmp/architectures/testing/proc sudo cp /etc/resolv.conf $HOME/tmp/architectures/testing/etc/resolv.conf sudo chroot $HOME/tmp/architectures/testing
Run
sh gimp.sh

Now inside the chrooted shell that you just started, do
su gimp
cd ~

Time to install gimp
sudo apt-get install gimp

And you're done!

You can now run GIMP 2.8 in the chrooted environment. It is NOT elegant though.
Gimp running in a chrooted Wheezy on a Squeeze virtual machine (LXDE) on a Wheezy physical machine (gnome 3).
Moving files in and out of the jail:
There are a few options -- you can obviously always move files from your host system to the chroot jail. A major point of a chroot jail is that you can't access the host system though, but we've set up our gimp.sh so that we can connect via ssh or sftp as well

In your chroot, as the user gimp, do e.g.
sudo apt-get install openssh-client
sftp me@host:shared/

I warned you that it wasn't elegant...

15 December 2012

292. seahorse -- what happened?

There's been a lot of talk about how nautilus will be simplified/dumbed-down/crippled/improved -- but I didn't know seahorse was going to undergo such a radical makeover. Don't know if it's for better, worse or if it changes nothing, but at the moment I'm having trouble finding my way around.

seahorse 3.4.1-2

14 December 2012

291. Another nautilus-open-terminal related bug

We recently had issues with nautilus-open-terminal opening the terminal in $HOME no matter from which directory it was called: http://verahill.blogspot.com.au/2012/11/fix-for-nautilus-open-terminal-opens-in.html

In that post the fix was to do
gsettings set org.gnome.desktop.default-applications.terminal exec gnome-terminal

Which worked fine as long as the exec-arg remained '-x'. It seems to have changed to '-e' now, so during the past few days (since nautilus 3.4.2) 'open terminal here' doesn't open a terminal at all.

Diagnosis:
Looking at this: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=693894


gsettings get org.gnome.desktop.default-applications.terminal exec
'gnome-terminal'
gsettings get org.gnome.desktop.default-applications.terminal exec-arg
'-e'
Fix:
gsettings set org.gnome.desktop.default-applications.terminal exec x-terminal-emulator

It should now work normally.

12 December 2012

290. Compiling Kernel 3.7.* on Debian (Wheezy/testing)

Update 19/12/2012
On one of my seven boxes I'm having problems with the new kernel, receiving messages such as
pci_pcm_runtime_suspend()
azx_runtime_suspend
[snd_hda_intel] returns -11
This is a known bug (https://patchwork.kernel.org/patch/1865521/), but as can be seen in that message the patch might not be included until kernel 3.8 (although one of the authors call for a backport to kernel 3.6). Again, this happened only on one out of seven computers tested so far so it might not be a universal problem. See here for how to fix it yourself: http://verahill.blogspot.com.au/2012/12/patching-kernel-371-to-fix.html

Note
 vboxdrv 4.1.18 and nvidia 304.48-1 dkms packages do not seem to play well with 3.7. This is perhaps not that surprising given that wheezy is frozen since June 2012.

* The virtualbox-dkms/vboxdrv (4.1.18-dfsg-1.1) isn't playing ball on 3.7. See e.g. https://forums.virtualbox.org/viewtopic.php?f=7&t=53031 and http://www.kubuntuforums.net/showthread.php?61234-Kernel-update-video-drivers-and-virtualbox

I solved it by going to the virtualbox website and installing their .deb package:
wget http://download.virtualbox.org/virtualbox/4.2.4/virtualbox-4.2_4.2.4-81684~Debian~wheezy_amd64.deb
sudo apt-get autoremove virtualbox virtualbox-qt virtualbox-dkms
sudo dpkg -i virtualbox-4.2_4.2.4-81684~Debian~wheezy_amd64.deb
sudo /etc/init.d/vboxdrv setup

This works absolutely fine under 3.7 and 3.7.1

* I'm also having issues with building the nvidia dkms module on this kernel. It seems to be a bug which is resolved by upgrading to a newer nvidia driver. http://www.mail-archive.com/desktop-packages@lists.launchpad.net/msg184146.html

Given that Wheezy is frozen since the end of June I suspect that we won't be seeing any fix for this. Instead I ended up installing nvidia-current (310.19) using smxi (smxi.org) and it's working fine (the alt+prtscrn screenshot bug doesn't seem to be resolved though).



Original post:
Be aware that starting with kernel 3.6 you will need to explicitly include compilation of various drivers for multimedia and webcams -- see e.g.
http://verahill.blogspot.com.au/2012/10/compiling-kernel-36-on-debian.html
http://verahill.blogspot.com.au/2012/10/leadtek-dtv-1000s-in-kernel-36-debian.html

Other than that, compiling kernel 3.7.* is pretty straightforward. The ncurses packages are needed only for 'make menuconfig'

sudo apt-get install kernel-package fakeroot build-essential ncurses-bin ncurses-dev
mkdir ~/tmp
cd ~/tmp
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.7.1.tar.bz2
tar xvf linux-3.7.1.tar.bz2
cd linux-3.7.1/
cat /boot/config-`uname -r`>.config
make oldconfig

and answer the questions (see bottom of the post for a list of new features).

If you want to specifically include a driver, then the easiest thing to do is:

make menuconfig

and navigating through (or search -- hit / ). E.g. saa7134 is found under Device drivers/Multimedia support/Media PCI adapters/Philips SAA7134 support. Don't forget to compile in remote control support as well if needed.

Continue (replace 4 with whatever is suitable for the number of cores on your system):
make-kpkg clean
time fakeroot make-kpkg -j4 --initrd --revision=3.7.1 --append-to-version=-amd64 kernel_image kernel_headers

This took 20 minutes on a four-core i5-2400..

mv ../linux*3.7*.deb .
sudo dpkg -i *.deb

Building failed completely on an AMD 8150FX 8 core system (See bottom of the post). It built fine on first try on all other systems.



Changes (if in doubt, hit enter for the default option):

* CPU/Task time and stats accounting
*
Cputime accounting
> 1. Simple tick based cputime accounting (TICK_CPU_ACCOUNTING) (NEW)
  2. Fine granularity task level IRQ time accounting (IRQ_TIME_ACCOUNTING)
choice[1-2]: 1
Consider userspace as in RCU extended quiescent state (RCU_USER_QS) [N/y/?] (NEW)
Module signature verification (MODULE_SIG) [N/y/?] (NEW)
Legacy cpb sysfs knob support for AMD CPUs (X86_ACPI_CPUFREQ_CPB) [Y/n/?] (NEW)
Packet: sockets monitoring interface (PACKET_DIAG) [N/m/y/?] (NEW)
IPv6: GRE tunnel (IPV6_GRE) [N/m/y/?] (NEW) 
IPv4 NAT (NF_NAT_IPV4) [N/m/?] (NEW)
IPv6 NAT (NF_NAT_IPV6) [N/m/?] (NEW)
OMAP OCP2SCP DRIVER (OMAP_OCP2SCP) [N/m/y/?] (NEW) 
 Maximum expected bad eraseblock count per 1024 eraseblocks (MTD_UBI_BEB_LIMIT) [20] (NEW)
UBI Fastmap (Experimental feature) (MTD_UBI_FASTMAP) [N/y/?] (NEW)
Calxeda Highbank SATA support (SATA_HIGHBANK) [N/m/?] (NEW)
Virtual eXtensible Local Area Network (VXLAN) (VXLAN) [N/m/y/?] (NEW) 
PCH PTP clock support (PCH_PTP) [N/y/?] (NEW)
Solarflare SFC9000-family PTP support (SFC_PTP) [Y/n/?] (NEW)
Drivers for Atheros AT803X PHYs (AT803X_PHY) [N/m/?] (NEW)
MAX310X support (SERIAL_MAX310X) [N/y/?] (NEW)
SCCNXP serial port support (SERIAL_SCCNXP) [N/m/y/?] (NEW)
TPM HW Random Number Generator support (HW_RANDOM_TPM) [M/n/?] (NEW)
TPM Interface Specification 1.2 Interface (I2C - Infineon) (TCG_TIS_I2C_INFINEON) [N/m/?] (NEW)
NXP SC18IS602/602B/603 I2C to SPI bridge (SPI_SC18IS602) [N/m/?] (NEW)
OMAP HDQ driver (HDQ_MASTER_OMAP) [N/m/?] (NEW)
Analog Devices ADT7410 (SENSORS_ADT7410) [N/m/?] (NEW)
Maxim MAX197 and compatibles (SENSORS_MAX197) [N/m/y/?] (NEW)
generic cpu cooling support (CPU_THERMAL) [N/y/?] (NEW)
Fairchild FAN53555 Regulator (REGULATOR_FAN53555) [N/m/?] (NEW)
Media USB Adapters (MEDIA_USB_SUPPORT) [N/y/?] (NEW) 
STK1160 USB video capture support (VIDEO_STK1160) [N/m/?] (NEW)
STK1160 AC97 codec support (VIDEO_STK1160_AC97) [N/y/?] (NEW)   
Enable debug for the B2C2 FlexCop drivers (DVB_B2C2_FLEXCOP_USB_DEBUG) [N/y/?] (NEW)
Media PCI Adapters (MEDIA_PCI_SUPPORT) [N/y/?] (NEW)
Enable debug for the B2C2 FlexCop drivers (DVB_B2C2_FLEXCOP_PCI_DEBUG) [N/y/?] (NEW)
Media test drivers (V4L_TEST_DRIVERS) [N/y] (NEW)
ISA and parallel port devices (MEDIA_PARPORT_SUPPORT) [N/y/?] (NEW)
Autoselect tuners and i2c modules to build (MEDIA_SUBDRV_AUTOSELECT) [Y/n/?] (NEW)
Maximum debug level (NOUVEAU_DEBUG) [5] (NEW)
Default debug level (NOUVEAU_DEBUG_DEFAULT) [3] (NEW)
Backlight Driver for LM3630 (BACKLIGHT_LM3630) [N/m/?] (NEW)
Backlight Driver for LM3639 (BACKLIGHT_LM3639) [N/m/?] (NEW)
Sony PS3 BD Remote Control (HID_PS3REMOTE) [N/m/?] (NEW)
HID Sensors framework support (HID_SENSOR_HUB) [N/m/?] (NEW)
ZTE USB serial driver (USB_SERIAL_ZTE) [N/m/?] (NEW)
Functions for loading firmware on EZUSB chips (USB_EZUSB_FX2) [M/y/?] (NEW)
LED support for LM3642 Chip (LEDS_LM3642) [N/m/?] (NEW)
LED support for LM355x Chips, LM3554 and LM3556 (LEDS_LM355x) [N/m/?] (NEW)
LED CPU Trigger (LEDS_TRIGGER_CPU) [N/y/?] (NEW)
Dallas DS2404 (RTC_DRV_DS2404) [N/m/y/?] (NEW)
Silicom devices (NET_VENDOR_SILICOM) [Y/n/?] (NEW)
Silicom BypassCTL library support (SBYPASS) [N/m/?] (NEW)
Silicom BypassCTL net support (BPCTL) [N/m/?] (NEW)
Cambridge Electronic Design 1401 USB support (CED1401) [N/m/?] (NEW)
Digi Realport driver (DGRP) [N/m/y/?] (NEW) *
STE-Modem remoteproc support (STE_MODEM_RPROC) [N/m/y/?] (NEW)
SMB2 network file system support (EXPERIMENTAL) (CIFS_SMB2) [N/y/?] (NEW)
Red-Black tree test (RBTREE_TEST) [N/m/?] (NEW)
Interval tree test (INTERVAL_TREE_TEST) [N/m/?] (NEW)
CAST5 (CAST-128) cipher algorithm (x86_64/AVX) (CRYPTO_CAST5_AVX_X86_64) [N/m/y/?] (NEW)
CAST6 (CAST-256) cipher algorithm (x86_64/AVX) (CRYPTO_CAST6_AVX_X86_64) [N/m/y/?] (NEW)
Asymmetric (public-key cryptographic) key type (ASYMMETRIC_KEY_TYPE) [N/m/y/?] (NEW)
Asymmetric public-key crypto algorithm subtype (ASYMMETRIC_PUBLIC_KEY_SUBTYPE) [N/m/?] (NEW)
RSA public-key algorithm (PUBLIC_KEY_ALGO_RSA) [N/m/?] (NEW)
X.509 certificate parser (X509_CERTIFICATE_PARSER) [N/m/?] (NEW)


AMD FX 8150
My AMD FX8150 is causing no end of problems when it comes to compiling the kernel e.g.

In file included from include/linux/dynamic_debug.h:100:0,
                 from include/linux/kernel.h:14,
                 from include/linux/sched.h:15,
                 from include/linux/blkdev.h:4,
                 from drivers/scsi/lpfc/lpfc_sli.c:22:
include/linux/string.h:23:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See  /usr/share/doc/gcc-4.7/README.Bugs for instructions.
  CC [M]  drivers/scsi/lpfc/lpfc_ct.o
[..]
  LD [M]  drivers/scsi/osd/osd.o
  CC [M]  drivers/scsi/mpt2sas/mpt2sas_ctl.o
The bug is not reproducible, so it is likely a hardware or OS problem.
make[4]: *** [drivers/scsi/lpfc/lpfc_sli.o] Error 1
make[3]: *** [drivers/scsi/lpfc] Error 2
make[3]: *** Waiting for unfinished jobs....

289. /var/lib/dpkg/status error and fix

The problem:
e.g.
sudo apt-get install ncurses-bin -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ncurses-bin is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? 
dpkg: error: parsing file '/var/lib/dpkg/status' near line 16892 package 'smbclient':
 `Depends' field, reference to `libtdb1': version contains ` '
E: Sub-process /usr/bin/dpkg returned an error code (2)

The solution:
Open /var/lib/dpkg/status in e.g. vim and remove the extra space: change from

16892 Depends: samba-common (= 2:3.6.6-3), libc6 (>= 2.10), libcap2 (>= 2.10), libcomerr2 (>= 1.01), libgssapi-krb5-2 (>= 1.10+dfsg~), libk5crypto3 (>= 1.6.dfsg.2), libkrb5-3 (>= 1.10+dfsg~), libldap-2.4-2 (>= 2.4.7), libpopt0 (>= 1.14),       libreadline6 (>= 6.0), libtalloc2 (>= 2.0.4~git20101213), libtdb1 (>= 1.2.7+git201 1214), libtinfo5, libwbclient0 (>= 2:3.6.0~pre3), zlib1g (>= 1:1.1.4)
to
16892 Depends: samba-common (= 2:3.6.6-3), libc6 (>= 2.10), libcap2 (>= 2.10), libcomerr2 (>= 1.01), libgssapi-krb5-2 (>= 1.10+dfsg~), libk5crypto3 (>= 1.6.dfsg.2), libkrb5-3 (>= 1.10+dfsg~), libldap-2.4-2 (>= 2.4.7), libpopt0 (>= 1.14),       libreadline6 (>= 6.0), libtalloc2 (>= 2.0.4~git20101213), libtdb1 (>= 1.2.7+git2011214), libtinfo5, libwbclient0 (>= 2:3.6.0~pre3), zlib1g (>= 1:1.1.4)

You can now continue as normal.

What not to do:

sudo rm /var/lib/dpkg/status

because it gives (if you do touch /var/lib/dpkg/status)


sudo apt-get install ncurses-bin 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  gcc-4.7-base libc-bin libc6 libgcc1 libtinfo5 multiarch-support
Suggested packages:
  glibc-doc debconf debconf-2.0 locales

etc.
In other words, suddenly no packages are registered as being installed anymore.

To fix it
sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status

And then edit the file as shown above.

04 December 2012

288. KStar (Australia) 1500 VA UPS on Debian Wheezy with NUT

NOTE: long day and not quite familiar with this yet, so haven't proof-read this post. Your mileage may vary.

Being fed up with the recent frequency of power-outages in our department building I headed off to MSY and picked up a UPS, the KStar BM3150 1500 VA (link). Oddly enough this seems to be an Antipodean-only UPS, as the main Kstar website doesn't list it.

The UPS comes with a USB port, and if you connect it to a computer you'll find that the UPS is recognised as a Lakeview Research product:

lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0925:1234 Lakeview Research Bus 002 Device 003: ID 0b95:7720 ASIX Electronics Corp. AX88772 Bus 002 Device 004: ID 05e3:0606 Genesys Logic, Inc. USB 2.0 Hub / D-Link DUB-H4 USB 2.0 Hub Bus 002 Device 005: ID 04d9:1603 Holtek Semiconductor, Inc. Keyboard Bus 002 Device 006: ID 0461:4d81 Primax Electronics, Ltd
dmesg
[ 424.292130] usb 1-1.3: new low-speed USB device number 3 using ehci_hcd [ 424.389739] usb 1-1.3: New USB device found, idVendor=0925, idProduct=1234 [ 424.390648] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 424.391553] usb 1-1.3: Product: UPS USB MON V1.4 [ 424.392449] usb 1-1.3: Manufacturer: \xffffffd0\xffffff89\xffffff89 [ 424.397491] hid-generic 0003:0925:1234.0004: hiddev0,hidraw3: USB HID v1.00 Device [\xffffffd0\xffffff89\xffffff89 UPS USB MON V1.4] on usb-0000:00:1a.0-1.3/input0
The UPS comes with a CD which contains a full-fledged Windows collection of software, and a pre-compiled shell-only 32 bit binary (need ia32-libs) which is installed via a shell script which needs modification to run properly on Debian. In other words -- it seems to have linux 'support' as a selling point, but not much more. It's so bad that it's not realistically useful.

Googling 0925:124 leads to this post: http://ifireball.wordpress.com/2011/10/13/configuring-aviem-pro2100-ups-on-debian-6-0-stablesqueeze/

The solution below is not particularly elegant -- I compile nut from source to get the udev rules and the richcomm driver, then install the debian nut packages.

cd ~/tmp
sudo apt-get install libusb-dev
wget http://www.networkupstools.org/source/2.6/nut-2.6.4.tar.gz
tar xvf nut-2.6.4.tar.gz
cd nut-2.6.4/
./configure --with-usb --with-dev
Configuration summary: ====================== build serial drivers: yes build USB drivers: yes build SNMP drivers: no build neon based XML driver: no enable Avahi support: no build Powerman PDU client driver: no build IPMI driver: no enable SSL development code: yes enable libwrap (tcp-wrappers) support: no enable libltdl (Libtool dlopen abstraction) support: yes build CGI programs: no enable HAL support: no build and install documentation: no build and install the development files: yes
make sudo make install


Things are installed, but in an non-standard place.
/usr/local/ups/bin/nut-scanner
Scanning USB bus. No start IP, skipping NUT bus (old connect method) [nutdev1] driver = "richcomm_usb" port = "auto" vendorid = "0925" productid = "1234" bus = "001"
sudo ln -s /lib/udev/rules.d/52-nut-usbups.rules /etc/udev/rules.d/52-nut-usbups.rules sudo service udev restart sudo apt-get install nut nut-cgi
Edit /ect/nut/ups.conf
[kstar] driver=richcomm_usb port=auto desc='kstar'
Edit /etc/nut/nut.conf
MODE=standalone
Edit /etc/nut/upsmon.conf
MONITOR kstar@localhost 1 upsmon myups master
Edit /etc/nut/upsd.conf
[upsmon]
password=myups
upsmon master
Then restart the nut server
sudo service nut-server restart
ps aux|grep nut
nut 3594 0.0 0.0 16764 592 ? Ss 18:00 0:00 /lib/nut/richcomm_usb -a kstar nut 7179 0.0 0.0 16764 592 ? Ss 18:29 0:00 /lib/nut/richcomm_usb -a kstar nut 7182 0.0 0.0 16900 568 ? Ss 18:29 0:00 /sbin/upsd
upsc kstar
device.mfr: Richcomm dry-contact to USB solution device.model: UPS USB MON V1.4 device.serial: unknown device.type: ups driver.name: richcomm_usb driver.parameter.pollinterval: 2 driver.parameter.port: auto driver.version: 2.6.4 driver.version.internal: 0.04 ups.mfr: Richcomm dry-contact to USB solution ups.model: UPS USB MON V1.4 ups.productid: 1234 ups.serial: unknown ups.status: OL ups.vendorid: 0925


Errors:
I'm leaving the various errors here more or less as link-bait. I tried using the NUT in the debian repos, and it gave me nothing than pain.

It's not nicely formatted or anything. Basically, if you see any of the crap below, compile your own version.

./configure --with-drivers=richcomm_usb --with-statepath=/var/run/nut --with-pidpath=/var/run/nut --with-user=nut --with-group=nut
Configuration summary: ====================== build serial drivers: yes build USB drivers: yes build SNMP drivers: no build neon based XML driver: no enable Avahi support: no build Powerman PDU client driver: no build IPMI driver: no build Mac OS X meta-driver: no enable SSL development code: yes enable libwrap (tcp-wrappers) support: no enable libltdl (Libtool dlopen abstraction) support: yes build nut-scanner: yes build CGI programs: no enable HAL support: no build and install documentation: no build and install the development files: no only build specific drivers: richcomm_usb
make sudo make install

Now try to load the driver:
sudo upsdrvctl -u root -D start
Network UPS Tools - UPS driver controller 2.6.4 0.000000 Starting UPS: kstar Network UPS Tools - Richcomm dry-contact to USB driver 0.04 (2.6.4) Warning: This is an experimental driver. Some features may not function correctly.
and it didn't really work. Checking dmesg
[282263.171108] usb 1-1.3: usbfs: interface 0 claimed by usbhid while 'richcomm_usb' sets config #1

and looking at
ls /sys/bus/usb/drivers/usb/1-1.3/ -lah
lrwxrwxrwx 1 root root 0 Dec 1 10:09 driver -> ../../../../../../bus/usb/drivers/usb
means that the device already has a driver loaded, so
sudo su
echo -n "1-1.3" > /sys/bus/usb/drivers/usb/unbind
exit
ls /sys/bus/usb/drivers/usb/1-1.3/ -lah
ls: cannot access /sys/bus/usb/drivers/usb/1-1.3/: No such file or directory
sudo upsdrvctl -u root -D start
Network UPS Tools - UPS driver controller 2.6.4 0.000000 Starting UPS: kstar Network UPS Tools - Richcomm dry-contact to USB driver 0.04 (2.6.4) Warning: This is an experimental driver. Some features may not function correctly. Communications with UPS lost: Query to UPS failed
dmesg
[284116.758107] usb 1-1.3: usbfs: interface 0 claimed by usbfs while 'richcomm_usb' sets config #1 [..] [284155.661271] usb 1-1.3: usbfs: interface 0 claimed by usbfs while 'richcomm_usb' sets config #1 [284155.790409] usb 1-1.3: usbfs: process 17105 (richcomm_usb) did not claim interface 0 before use
sigh...
ls /sys/bus/usb/drivers/usbfs/ -lah
lrwxrwxrwx 1 root root 0 Dec 4 17:07 1-1.3:1.0 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/1-1.3:1.0
sudo su echo -n "1-1.3:1.0" > /sys/bus/usb/drivers/usbfs/unbind exit
Then try again
  sudo upsdrvctl -u root -D start
Network UPS Tools - UPS driver controller 2.6.4 0.000000 Starting UPS: kstar Network UPS Tools - Richcomm dry-contact to USB driver 0.04 (2.6.4) Warning: This is an experimental driver. Some features may not function correctly. Duplicate driver instance detected! Terminating other driver! Communications with UPS lost: Query to UPS failed
So I then did
sudo vim /etc/udev/rules.d/70-ignore-ups.rules
ATTRS{idVendor}=="0925", ATTRS{idProduct}=="1234", OPTIONS=="ignore_device"
sudo service udev restart
Stopping the hotplug events dispatcher: udevd. Starting the hotplug events dispatcher: udevd.
If you get this:
 sudo upsdrvctl -D start
Network UPS Tools - UPS driver controller 2.6.4 0.000000 Starting UPS: kstar Network UPS Tools - Richcomm dry-contact to USB driver 0.04 (2.6.4) Warning: This is an experimental driver. Some features may not function correctly. USB device [0925:1234] matches, but driver callback failed: could not detach kernel driver from interface 0: Operation not permitted 0.004077 Driver failed to start (exit status=1)
then you need to make sure to add -u root to upsdrvctl. Also, make sure that the driver versions match.