Monday, April 6, 2015

RCS Calculations - Puma-EM on Ubuntu Linux

If you need to calculate the Radar Cross Section of something, then this installation guide for Puma-EM may help.

You can get Puma-EM here:
http://sourceforge.net/projects/puma-em/

You may also need FreeCAD, to prepare the mesh files:
http://www.aeronetworks.ca/2014/12/freecad.html

Note that the mesh size typically needs to be about Lamda/10, which at 10 GHz amounts to about 3 mm.

Puma-EM on Ubuntu Linux

========================



To ensure that you have a fast system, do a minimal install of the Ubuntu server edition and then add LXDE to make it more usable.



Get Ubuntu Server 14.04.2 LTS version here:

http://www.ubuntu.com/download/server



Make a virtual machine:

Create a new Virtualbox VDI VM for Ubuntu 64 bit Linux and a 20 GB dynamic disk.

Select the LTS CD image in the Storage section of the VM settings and boot.

Press Enter a few times to accept the defaults

Make a user account: user / 5uper5ecret

Some more Enters

"Guided - use entire disk" will result in a ext4 system

Write changes: Yes

Yet more Enters

If you can figure out how, install 'ssh server' and 'build-essential', otherwise, do it after installing the desktop

Type more Enters

La voila!



Reboot, then update the package lists:

sudo apt-get update

Long wait...



Now install LXDE:

sudo apt-get install lxde



or

sudo apt-get install --no-install-recommends lubuntu-desktop

(about 900 MB)



or

sudo apt-get install lubuntu-desktop

(about 1.3 GB)



...depending on how much bloat you want with your desktop.



Install the development tools:

sudo apt-get install build-essential

udo apt-get install cvs subversion git-core mercurial

sudo chown $USER /usr/local/src

sudo chmod u+rwx /usr/local/src



Install Guest Additions

Click Devices insert Guest Additions

Open in file manager

Open a terminal in /media/user/VBOX...

sudo ./VBOXLinuxAddtions.run

Then reboot



Configure the VM :

Enable the copy and paste buffer sharing and screen resizing features

Go to Power Savings and turn it off

Go to Light Locker and turn it off



Download Puma-EM:

Get it from here http://puma-em.sourceforge.net/

Untar it in the user home directory

cd ~/Puma-EM/installScripts

./UBUNTU_14.04_INSTALL.sh

It asks for a password once or twice and downloads and builds a lot of stuff

Long wait...

...and you should eventually reach the end of the compilation without errors.



Resolving problems:

Which Ubuntu package a missing file is in:

apt-file search missingfilename.pc

Friday, March 6, 2015

Travel with Computers

I used to think that one is safe against search and seizure of computers and phones at Canadian borders, but no more: http://www.cbc.ca/news/alain-philippon-phone-password-case-powers-of-border-agents-and-police-differ-1.2983841

When I travel to the USA, I upload my encrypted data to a FTP server and take a Kindle with me.  The border guards can have fun with that all they like.   Now I'll have to do the same when I go home too - ridiculous.

I should be able to enter my own country without being harassed at the border!

I do think that sanity will prevail in the end, but until it does, rather mail/courier your computers and equipment to wherever you are going, or beg/buy/borrow something at your destination and travel light.

It is much the same as travel with medication - take the prescription with you and buy new medicine at your destination - and never, never, never take unidentifiable scary white powders with you.  Years ago, we had huge trouble in Paris because of a few tins of baby formula, so the stupidity is everywhere. Vive la difference....

Saturday, February 21, 2015

The Keys to the Kingdom

Apparently, the NSA stole the keys to the GSM kingdom.  It was already clear that GSM is not secure and two heads of state were annoyed by the Yanks listening in to their calls already, but this is ridiculous:  https://firstlook.org/theintercept/2015/02/19/great-sim-heist/

What is clear, is that the US government doesn't care how much damage the NSA causes to states and corporations the world over.  This is a Dutch/French company, NATO members and the NSA did them in to the tune of half a billion Dollars, with hardly a peep from any politician anywhere.  If your computer system is not secure, then you can lose your business thanks to the US military, whether you are an ally, at peace, at war or neutral.  With such friends, who needs enemies?

The CTO of Lenovo has now proven himself to be just as clueless as a previous CTO of Sony: http://www.wired.com/2015/02/lenovo-superfish/

They all failed to understand that if you subvert thousands of computers, then the system is weakened and can be misused by anyone else too.  Even the much maligned DHS is on the ball on this one http://www.reuters.com/article/2015/02/20/us-lenovo-cybersecurity-dhs-idUSKBN0LO21U20150220

Where did these guys buy their university degree certificates - maybe here http://www.iwantadegree.co.uk/cyberdegree3.html?

The only way to combat the spying, is to buy all your computer and networking equipment in bits and pieces from random vendors and assemble it yourself, then load it with an obscure version of UNIX such as OpenBSD.


Whatever comes preinstalled on any machine, not only from the special class at Lenovo, cannot be trusted.

Monday, February 9, 2015

Thermionic Valve Amplifier

I stumbled upon a source for some cool old stuff called Magic Eye tubes.  The shop is in Chelyabinsk Russia, called Tubes Store.

Here is a nice VU meter video:
http://tubes-store.com/product_info.php?cPath=31_59&products_id=5

While browsing there, I decided to make a little audio amplifier to hook to my Mac, get a couple of Magic Eye tubes to use for a VU meter (blah) or robot eyes (yes!) and some Nixie tubes for a clock or digital read-out, or goodness knows what, so I ended up buying a handful of brand new old junk.

Now the problem is getting high voltage transformers and capacitors that can handle >200 Volts.  Everything in my junk box is low voltage and will go pop, just like the weasel of yore.

After a little bit of head scratching, I came up with this cool little audio amplifier design:


It is a pretty standard push-puller, using a miniature 6N21 dual triode at the front end and a pair of 6E6 tubes at the back end (It is a rough drawing, but it gives the idea.  I didn't want to create a special transformer part in Eagle.).

Bluetooth Audio

I'd like to have both a wired and wireless interface.  It may be an old fashioned amplifier, but it is the 21st century after all!

Sparkfun sells a Bluetooth Audio interface module https://www.sparkfun.com/products/11777

Improvising

Now where on earth can I get transformers for the 6V heaters and 200 V anodes?  One could use an automotive ignition coil for the audio output transformer and a couple of low voltage transformers back to back for the heater and high voltage power supply, but it turned out that there is a manufacturer of replica guitar amp transformers in Canada, Hammond Manufacturing, eh...

The Hammond classic audio output transformer should sound better than a car coil.  Well, I hope - at least it will look better:
http://www.hammondmfg.com/125a.htm
http://www.hammondmfg.com/300series.htm

and one can get high voltage electrolytic capacitors from Digikey:
http://www.digikey.com/product-detail/en/EKXG351ELL101MM25S/565-1457-ND/755973

Next time I walk past a Pakistani trinket store down town, I'll pick up an old fashioned little wooden box to put it in. I saw a replica His Master's Voice wind-up record player the other day - that store will have something.

So, it is no problem to build a new old toy today, but it ain't cheap.  Shipping transformers halfway around the world is expensive.  I guess my little amplifier will cost about $300 when it is all done.

Transformers

I finally ordered the transformers.  It turned out to be easiest to get them from Mouser and instead of getting a multi-winding tube amp power transformer, I got separate transformers for the heaters and anodes - easier that way. Mouser does stock a Hammond Fender replica power transformer, but it is 115 V only - while I live in UAE with 240 V mains supply.

Therefore I got a Hammond 185C230 for the anode voltage:

Primary 230 V:
Connect in series
.1, 6 = 230 V mains
2, .5 = Short

Secondary 115 V:
Connect in parallel
12, 8 = Short
.11, .7 = Short

and a VPS12-2000 for the heaters:

Primary:
Connect in series
.6, 1 = 230 V mains
5, .2 = Short

Secondary:
Connect in parallel
.12, .8 = short
11, 7 = short

The audio transformer I settled on is the Hammond 1750H:

Primary:
.Blue / Brown = 6600 Ohm
Red = Centre Tap

Secondary:
.Black, Brown = 8 Ohm

Note that you must never run a tube amp without a load - the output transformer will arc and destroy itself.  I'll get a 6 inch full range car speaker pair at Lulu or Carrefour and stick it in an old fashioned wooden box from my newfound Pakistani friend downtown.

Tube Sockets

One can still buy new octal sockets.  They are manufactured for relays.  However, all the tubes I got have 9 or more pins, so that is no help.  I'll have to make a plan with some D-sub connector sockets - they look like they will fit.

Terminal Strips and Turret Boards

These old fashioned high voltage solder tag strips are hard to find, but Digikey and Mouser do have them, if you know to search for 'turret boards'.


http://eu.mouser.com/_/?Keyword=turret+boards&FS=True




http://www.digikey.com/product-search/en/connectors-interconnects/terminal-strips-and-turret-boards/1442011?k=terminal&stock=1

For hooking the parts up, you need 22 AWG tinned coper wire, which is unhelpfully named 'bus bar wire' by the vendors.  It is available in little 100 foot rolls.  Don't use 'magnet wire' - well, you could if you are a masochist.  Magnet wire is insulated with epoxy or nylon which is very hard to strip.

Once all is working, clean with alcohol and spray the electronics (not the tubes!) with V-66 or similar conformal coating to keep it from corroding and it will keep working and look nice for years.

Friday, February 6, 2015

Windows 10 on Virtualbox

What? Herman uses Windows? Shock, horror...

My first desktop computer - if you could call it that - was a Commodore Vic 20 - ugh.  The second one, was an Apple IIe, which was probably the first desktop computer worthy of the name.  Since then, I have used many, many systems, including Sperry, UNIVAC, Varian, DEC and some that nobody ever heard of.

As far as Microsoft operating systems go - if you can call them that - I have used practically every version of everything O'l Billybob ever made.  I even once received a cheque from Microsoft for one of their infamous lawsuits that they lost.

If it is Free, Take Two!

You can download a Windows 10 ISO file for free here:
https://insider.windows.com/

Windows 10 Running in a Window on Fedora Linux KDE

You just have to give them your whole pedigree and create an online account, but if you are old enough to do this on your own, then MS already has your whole pedigree and you may even have an account too... 

The Magical Incantation

After downloading the thing (4.9 GB), run Virtualbox and create a "Windows 8.1, 64 bit" disk.  Select the ISO file in the Storage, CDROM widget and boot up.

That trick above is the sole reason I'm writing this, to save you from a Blue Screen of Death Error 5D.

Settings

Turn power management off, since your host already does that, install Guest Additions, enable file sharing and once everything is working right, disable the network, since that is the only way to keep a Windows machine secure.

Now please don't blame me for all the usual problems you may get with Windows...

La Voila!

Herman



Monday, January 12, 2015

Makefiles Made Easy

The bane of computer programming is the Makefile. As soon as there are more than one source file and a library, a Makefile becomes essential and generating one can be painful.  The Makefile syntax reminds me of a sendmail configuration file, which looks like someone banged his head on a keyboard.

# This rule ensures that all local mail is delivered using the 
# smtp transport, everything else will go via the smart host. 
R$* < @ $* .$m. > $* $#smtp $@ $2.$m. $: $1 < @ $2.$m. > $3 dnl

Obvious, yeah...

Same as with sendmail, you should never edit a Makefile manually.  It is a total waste of time.  There are nice and simple utilities to do it for you!

GCC -MM

If you have a very simple project, then gcc can generate the Makefile for you:
$ gcc -MM *.c > Makefile
$ make

Error: cc1plus

If you get the following or similar error regarding cc1plus, then the solution is not at all obvious:
gcc: error trying to exec 'cc1plus': execvp: No such file or directory

The problem is that while gcc is installed, g++ is missing:
# yum install gcc-c++

Also see the previous post for details on installing gcc.

CMake

If your project is more complex, then cmake can generate the Makefile for you, but you need to give it a few instructions in the file CMakeLists.txt.  First install cmake and related tools:
# yum install cmake*

Now create the file CMakeLists.txt and tell it which are the output, source and libraries:
project(FlashProject)
cmake_minimum_required(VERSION 2.8.12.2)
add_executable(flasher flasher.c)
find_library(FTDI ftdi)
target_link_libraries(flasher ${FTDI})

Note that gcc assumes that library file names start with lib and end with .so, therefore only specify the base ftdi or whatever, not libftdi.so.

The first time you run cmake, you need to specify the compiler:
$ CXX=gcc
$ export CXX

After that, run cmake to generate the makefile complete with all the obscure, head banging, gobbledygook lines:
$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/herman/sw/ftdi


Now you should have a very detailed almost 200 line Makefile and can compile your project with:
$ make

La voila!


Serial Port I/O

Until about 20 years ago, most desktop and portable computers had serial and parallel ports built in.  Those ports were great for controlling and testing home brew gadgets.  Modern machines are blessed/cursed with USB ports, which are just getting more and more complex.

The result is that if you want to do anything at all in your Underground Lab or Rooftop Radio Shack, you need an Arduino,  a Raspberry or a Beaglebone embedded computer.

However, every respectable engineer has two or three FTDI USB to RS232 serial adaptors lying in a drawer (to control his Raspberry or Beaglebone).  These adaptors are great, since they effectively insulate your target system from your expensive computer, therefore whatever goes wrong on the far end, is unlikely to fry your machine and they are delightfully hackable.

I prefer the dongles made by SerialComm.  They are cheap and both RS232 and RS422/485 are available.

You can also get ones from Sparkfun that are even more hackable, or you can crack the case and remove the line driver chip from a regular off the shelf one if you are desperate for TTL I/O lines.

The secret Open Sauce is the libftdi project, which is available for Linux and Mac systems. Documentation and examples are here.  The online files are the latest and greatest.  Therefore it may be best to work with the header file on your machine which is /usr/include/ftdi.h since your installed version of the library may be older and some functions may be deprecated or missing.

Simple Bitbanging with libftdi

Here is a tiny little C program for an older version of libftdi, that will toggle the Tx, DTR and CTS lines on a USB RS232 adaptor.  Note that you have to run it as root (or join some or other USB group), otherwise the USB device will not open.

/* File flasher.c */
/* libftdi API Example LED Flasher */

#include <stdio.h>
#include <ftdi.h>

/* RS232 DE9 pins */
#define DCD 0x40 /* 1 in */
#define RX  0x02 /* 2 in */
#define TX  0x01 /* 3 out */
#define DTR 0x10 /* 4 out */
#define DSR 0x20 /* 6 in */
#define RTS 0x04 /* 7 out */
#define CTS 0x08 /* 8 in */
#define RI  0x80 /* 9 in */
/* 5 GND */


int main()
{
    unsigned char data = 0;
    unsigned char pins = TX | DTR | RTS;
    struct ftdi_context context;

    /* Initialize libftdi */
    ftdi_init(&context);

    /* Open FTDI dongle using FT232RL vendor & product IDs */
    if(ftdi_usb_open(&context, 0x0403, 0x6001) < 0) 

    {
        puts("ERROR: ftdi_usb_open()");
        return 1;
    }

    /* Set bitbang mode on the RS232 output pins */
    ftdi_enable_bitbang(&context, pins);

    /* Forever */
    for(;;) 

    {
        data ^= pins;
        ftdi_write_data(&context, &data, 1);
        sleep(1);
    }
}


Improved Bitbanging with libftdi

Here is a more advanced program with proper error checking.  Note that you have to run it as root (or join some or other USB group), otherwise the USB device will not open.

/* File flasher.c */
/* libftdi.so API Example LED Flasher */
/* Copyright reserved Herman Oosthuysen, 2015 */
/* License: GPL version 2 or later */
/* Use at your own peril */

#include <stdio.h>
#include <stdlib.h>
#include <ftdi.h>

/* RS232 DE9 pins */
#define DCD 0x40 /* 1 in */
#define RX  0x02 /* 2 in */
#define TX  0x01 /* 3 out */
#define DTR 0x10 /* 4 out */
#define DSR 0x20 /* 6 in */
#define RTS 0x04 /* 7 out */
#define CTS 0x08 /* 8 in */
#define RI  0x80 /* 9 in */
/* 5 GND */


int main()
{
    int i;
    int ret;
    unsigned char data = 0;
    unsigned char outputs = TX | DTR | RTS;
    struct ftdi_context *ftdi;

    /* Initialize libftdi */
    printf("FTDI Initialize\n");
    ftdi = ftdi_new();
    if (ftdi == NULL)
    {
        fprintf(stderr, "ERROR: ftdi_new()\n");
        return EXIT_FAILURE;
    }

    ret = ftdi_init(ftdi);
    if (ret < 0)
    {
        fprintf(stderr, "ERROR: ftdi_init() = %d\n", ret);
        ftdi_free(ftdi);
        return EXIT_FAILURE;
    }

    /* Open FTDI dongle using FT232RL vendor & product IDs */
    /* Plug the device in and run 'dmesg' to see these codes */
    printf("FTDI USB Open\n");
    ret = ftdi_usb_open(ftdi, 0x0403, 0x6001);
    if (ret < 0)
    {
        fprintf(stderr, "ERROR: ftdi_usb_open() = %d\n", ret);
        ftdi_free(ftdi);
        return EXIT_FAILURE;
    }

    /* Set bitbang mode on the RS232 output pins */
    /* pins: Output = 1, Input = 0 */
    printf("FTDI set Bitbang Mode\n");
    ret = ftdi_set_bitmode(ftdi, outputs, BITMODE_BITBANG);
    if (ret < 0)
    {
        fprintf(stderr, "ERROR: ftdi_set_bitmode() = %d\n", ret);
        ftdi_free(ftdi);
        return EXIT_FAILURE;
    }

    /* Flash for a little while */

    /* Note: Use ftdi_read_pins() to read data directly */
    printf("FTDI Flashing...\n");
    for(i = 0; i < 10; i++)
    {
        printf("%d\r", i);
        data ^= outputs;
        ret = ftdi_write_data(ftdi, &data, sizeof(data));
        if (ret < 0)
        {
            ftdi_free(ftdi);
            fprintf(stderr, "ERROR: ftdi_write_data() = %d\n", ret);
            return EXIT_FAILURE;
        }
        usleep(500000);
    }

    /* Done */
    printf("\nDone\n");
    ret = ftdi_usb_close(ftdi);
    if (ret)
    {
        ftdi_free(ftdi);
        fprintf(stderr, "ERROR: ftdi_usb_close() = %d\n", ret);
        return EXIT_FAILURE;
    }

    ftdi_free(ftdi);
    return EXIT_SUCCESS;
}


CBUS Discretes

In addition to the 8 lines used for RS232, there are 4 more, which are used to control the LEDs and RS485 drivers.  These lines can be controlled in a similar fashion using BITMODE_CBUS.  It is not clear whether one can interleave the two bitbashing modes in order to control all 12 lines at the same time and whether the lines will glitch if one does. See this example.

I also read that one can use the CBUS bitbashing concurrently with the normal serial mode, to provide a UART plus 4 discretes, but I have not tried it.

Compile and Test

Assuming that your Linux machine is configured properly with GCC, compile it thus:
$ gcc -o flasher flasher.c -lftdi
$ chmod 754 flasher

Now stick a LED with a 1k resistor in series onto the RS232 adaptor Tx and Gnd pins to see how it works and run it:
$ ./flasher

Install and Configuration of libftdi

If you don't have a GCC and libftdi configured system yet, then assuming that you have Fedora Linux:
$ su -
# yum update

# yum install kernel-headers

# yum groupinstall "Development Tools" "Development Libraries"
# yum install libftdi libftdi-devel

Now you can control the world!

Cmake

Also see the next post on Makefiles.