Friday, 23 November 2012

Usb Modem from Mono on the Raspberry Pi

or

How to Automatically Hang Up on Telesales Using .net, a Modem and Caller ID

or

Using Serial Ports from Mono on Raspbian

Since we seem to get a never-ending series of calls from telesales, market research and “your ISP”, I decided to start adding their caller IDs to our cordless phone book as “Scam n”.

The problem with this plan was that you still had to head to the phone to see that it wasn’t someone you wanted to bother with. If only there was something that could read a caller ID and automatically pick up the phone and hang up.

Like a modem.

Connected to a Raspberry Pi.

So I bought a cheap USB modem from Amazon, and wrote something in C# to check incoming CLID against a blacklist. I tested it on a Windows laptop, and then installed Mono on the Raspberry Pi. Watched it do nothing. Then I wrote it again. Twice.

1. Getting the modem to work

One important step was to tell the modem which country it was in, I did this via the properties page on the Windows laptop. Without this stage, it didn’t recognise the caller id information coming along with the calls.

The name of the port can be found on the device properties page in Windows, or on Raspbian / Debian / Ubuntu / whatever-linux by running

lsusb

And finding the entry for the modem

Bus 001 Device 007: ID 0572:1329 Conexant Systems (Rockwell), Inc.

And then finding the symlink to that device, of the form /dev/tty…

ls -l `find /dev -name '*Conexant*'`

(there’s backqoutes and single quotes in there, not smart quotes gone nuts)

2. Getting Mono on the Raspberry Pi

sudo apt-get install mono-complete

wait.

3. Using Serial Ports in Mono

Forget the DataReceived event. Spin up threads for the reading and writing from the serial ports.

4. TimeSpan in Mono 2.10.8.1 on Raspbian 3.2.27+ #250 PREEMPT

Forget it. Use an int for milliseconds. The following code

Console.WriteLine(TimeSpan.FromSeconds(1));

Produces

00:00:00

5. The source code

It’s quick and dirty, and it’s available on bitbucket.

6. Get your own

You can get a Raspberry Pi here, and there’s an Amazon ad for the modem I used below.

TRIXES USB 56K External Dial Up Voice Fax Data Modem Windows 7

Wednesday, 24 October 2012

A disk read error occurred Press Ctrl+Alt+Del to restart

After fitting an IDE SSD in my aging laptop, I found that although Windows 7 (and Windows 8 Preview) would install to it, they wouldn’t boot – instead claiming that there was a disk error.

After some experimentation, I found that the Super Grub2 Disk, booted from a CD, could start Windows via its “Detect any other operating system” option.

But booting from a CD every time sort of defeats the point of a faster drive, so I tried to get grub to boot into Windows from the hard drive. It worked – (almost every time), and here’s how.

  1. Get an Ubuntu Live disk.
  2. Boot into Ubuntu and repartition the disk using gparted. Create one ext2 partition of 256Mb (aligned to none) and set its flags to bootable. Create a second partition for NTFS that fills the rest of the disk.
  3. From the terminal, start a su shell and mount the ext2 partition as /boot, then install grub
    • sudo –i
    • mount /dev/sda1 /boot
    • grub-install /dev/sda
  4. Install windows to the second partition, you might need the Super Grub2 disk to help it through the reboots.
  5. Boot into Ubuntu again, mount the boot partition, and find the volume info for the NTFS partition using the blkid command.
  6. Create a /boot/grub/grub.cfg that looks like this

set default=0
set timeout=0

menuentry "Windows 7" --class windows --class os {
    insmod part_msdos
    insmod ntfs
    insmod ntldr
    set root='(hd0,msdos2)'
    search --no-floppy --fs-uuid --set=root BIGHEXNUMBERFROMBLKID
    ntldr ($root)/bootmgr
}

Saturday, 7 April 2012

Phone Charger Recommendation

If you’ve got a phone with a Micro USB power connector (say, for instance, an HTC Android model) and you occasionally find yourself running out of battery power, here’s something that I’ve found to work really well.

A 4xAA to Micro USB battery pack. I’ve stocked mine with Duracell ACCU / Stay charged NiMH batteries so they don’t self-discharge while they’re in waiting.

It’s not a fast charge, but if you can cope with having the phone connected to the charger in your bag / jacket pocket it will get your phone battery back into the green.

(Amazon associate) links:

Sunday, 4 March 2012

16-bit Grayscale in WPF Pixel Shader BitmapEffect

If you’re looking to use a 16-bit grayscale (Gray16) BitmapSource as an input to a Pixel Shader BitmapEffect – say for brightness / contrast adjustment, you’re likely to hit a problem.
It seems that the 16-bit values are knocked down to 8-bit precision by the time you get the float values in the pixel shader (so a range from 0 to 1, but only 256 distinct values).
But you can instead pack the 16 bits into two of the 8-bit colour channels of an RGB image (an approach suggested by ken_s in the msdn thread Debugging Pixel Shaders for WPF effects.
Create a Bgr32 format WriteableBitmap, and use WritePixels to copy the 16-bit values from a ushort array, with one blank ushort between each pixel. This way the high byte goes into the green channel, the low byte into the blue, and the red and unused channels get zeroed.
In your pixel shader code, you can reconstruct the 16-bit value from the float values passed for green and blue.
float4 main(float2 img : TEXCOORD) : COLOR
{
 float4 gb = tex2D(input, img);
  int high = gb.g * 65280; // Fix by Rick Burke (see comments)
 int low = gb.b * 255;
 int grayVal = high + low;

 // ... 
 // Calculate a 0-1 grayscale value ‘processed’ from grayVal 
 // ... 

 float4 result; 
 result.a = 1; 
 result.r = processed; 
 result.g = processed; 
 result.b = processed; 
 return result; 
}

Saturday, 28 January 2012

Multi-Channel LPCM on a DVD-ROM

(Or how to store 4.0 / 5.1 at 96khz 24-bit on a DVD-R, in a way that plays back properly over HDMI from a Sony BDP-S370)
Yes, another exciting audio howto :-) but if I don’t record it, I won’t be remember (or be willing to rediscover) how.
If starting from one-track-per-file, use foobar2000 to create a single wav file and a cue sheet. The key here is to multi-select the files, and do a convert to wav with the destination type set to “Generate multi-track files”. This will produce the cue sheet.
Next find the duration of the combined wav file, and use ffmpeg from the command prompt to create a still video file:
ffmpeg.exe -loop 1 –i somepicture.png -c:v libx264 -s hd720 -t hh:mm:ss.mmm video.mkv
Then use multiavchd, add video.mkv and click on the entry under “compilation”. Add the audio, then edit the chapters and fill in the values from the cue sheet. On the Author tab I also changed TV system to PAL.
Hit Start, and choose AVCHD (Strict) under the Optical Media section.
From the command prompt multiavchd folder, Use oscdimg to create a UDF disc image of the AVCHD folder
oscdimg -u2 AVCHD myaudiodisc.iso
Burn myaudiodisc.iso to DVD-R. If I let the disc play automatically on loading, the receiver claimed it was being sent 88.2Khz sound. I had to select “AVCHD disc” from the blu-ray player menus to get 96khz.