Showing posts with label GNU/Linux. Show all posts
Showing posts with label GNU/Linux. Show all posts

4 Jul 2014

checking system requirements for owncloud installation

Here a short bash script which checks for all php features required to install owncloud:

#!/usr/bin/env bash

# (>= 5.3.8 minimum, 5.4 or higher recommended)
version=$(php -v | head -n 1 | sed 's/PHP \([0-9.]\+\).*/\1/')
echo "PHP Version $version installed."

# check for the following features:
features="ctype dom GD iconv JSON libxml mbstring SimpleXML zip zlib"

for f in $features; do
 echo -en "Checking: $f";
 r=$(php -i | egrep -i '^'$f'$')
 if [[ "$r" != "" ]]; then 
  echo " ... Found"; 
 else
  echo "";
 fi
done

5 Jul 2013

XFLR5 - airfoil analysis at low Reynolds Numbers


Click on the image for a larger resolution.

I am currently working on a new flying wing design. I was extremely amazed that there is open source software for doing software based wind tunnel simulation. The software package is called XFLR5 and is available as source package and binary package for windows (the debian repo includes a binary as well: apt-get install xflr5).

The animation above shows a flying wing design I am working on. The wing uses an MH-64 airfoil. In the animation you can see the induced drag, the lift and wake turbulence created by an Angle of Attack between -3 up to 12°.

22 Mar 2013

C shared objects exported to python (ctypes)

Some C Projects need a quick extension which is not performance relevant. Sometimes I wish to use python because it is available on all modern *nix systems. Also, programming in python is very efficient.

To solve this I have created a small example project which puts the functionality into a shared object (dll in windows-speak) which can be used from python.

The library:

lib.c
This library contains a simple function which appends the string "->aaa" to an existing string. This is an interesting example since it involves dynamic memory allocation and pointers.


#include <stdlib.h>
#include <string.h>
#include "lib.h"

//int main() {return 0;}

char *append(char* str) {
 //char *n = "";
 char *b = "->aaa";
 char *n = malloc(strlen(str) + strlen(b) + 1);
 n[0] = '\0';
 strcat(n, str);
 strcat(n, b);
 return n;
}


lib.h
char *append(char* str);


test.c
used for testing the the library from C.

#include <stdio.h>
#include "lib.h"

int main(int argc, char* argv[]) {
 printf("%s\n", append(argv[1]));
 return 0;
}

Compiling
#!/usr/bin/env bash
gcc -std=c99 -Wall -c -fPIC lib.c -o lib.o
gcc -std=c99 -Wall -shared -Wl,-soname,libt.so -o libt.so lib.o
gcc -std=c99 -Wall -o test test.c -L. -lt
rm lib.o


pylibt.py
Because python uses dynamic data types we need to give some hints about data types. Also pointers need to be declared.
#!/usr/bin/env python

from ctypes import *

cdll.LoadLibrary("./libt.so")
_libt = CDLL("libt.so")

#def initpylibt():
# pass

def append(s):
 _append = _libt.append
 _append.argtypes = [c_char_p]
 _append.restype = c_char_p
 return _append(s)


test.py
let's use the python module from a script.

#!/usr/bin/env python

import pylibt

ret = pylibt.append("0123456789as dfasdf asdf asdf asdf asf asdf")
print ret


7 Mar 2013

gcc - compile shared library

the Program to compile as shared library

string.h

/** string.h
 *
 * $Id$
 */

#ifndef STINRG_H_
#define STINRG_H_

#ifndef DEFAULT_BLOCKSIZE
 // num. bytes of junks of memory to allocate from the heap
 #define DEFAULT_BLOCKSIZE 128
#endif

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

/** datatype to hold the character data */
struct string_t {
 int memsize;
 int length;
 char *text;
 int error;
};
typedef struct string_t string;

// function declarations
string str_redfile(FILE *file, int bs);
void str_dump(string *s);
unsigned long str_memsize(string *s);

#endif /* STINRG_H_ */

string.c

/** C example for reading file and allocating memory dynamically.
 *
 * Will read a file from disk while dynamically allocating memory.
 *
 * Example usage: ./exe [file-name]
 *
 * $Id$
 */

#include "string.h"

/** Read file from FILE pointer
 *
 * Reads data from FILE *file and dynamically allocates memory from the heap
 * to store the read data. If memory allocation fails, the returned string
 * struct's member error will equal to 1.
 *
 * If reading the file works, string.error will be 0.
 */
string str_redfile(FILE *file, int bs) {
 int charsize = sizeof(char);
 int charcount = 0;
 int blocksize;
 if (!bs)
  blocksize = DEFAULT_BLOCKSIZE;
 else
  blocksize = bs;
 int memsize = blocksize;
 char *line = (char*) malloc(charsize * (memsize+1));
 char *linep = line;

 string l;
 l.error = 0;
 l.length = 0;
 l.memsize = memsize;
 l.length = charcount;
 l.text = linep;

 while (1) {

  if(charcount > memsize) {
   // reallocate memmory
   memsize = memsize+blocksize;
   char *al = (char*) realloc(linep, charsize * (memsize+1));

   if (al == NULL) {
    fprintf(stderr, "Error, out of memory.\n");
    *line = '\0';
    l.text = linep;
    l.error = 1;
    return l;
   }
  }

  char c = fgetc(file);

  //if (c == '\n' || c == '\r' || c == EOF) {
  if (c == EOF) {
   charcount--;
   break;
  }

  // remember input char
  *line = c;
  *(line++);
  charcount++;
 }

 *line = '\0';
 l.text = linep;
 l.memsize = memsize;
 l.length = charcount;

 return l;
}

/** return allocated memory of a string struct
 */
unsigned long str_memsize(string *s) {
 return sizeof(string) + (s->memsize) + 1;
}

/** print struct string info
 */
void str_dump(string *s) {
 if (s->error == 0) {
  printf("memsize: %d\n", s->memsize);
  printf("length:  %d\n", s->length);
  printf("error:   %d\n", s->error);
  printf("text:    %.*s\n", 10, s->text);
  printf("total:   %lu\n", str_memsize(s));
 } else
  printf("Error: %d.\n", s->error);
}

test.c

/** test shared library
 *
 * an example how to use a shared library in a C program.
 *
 * $Id$
 */

#include "string.h"

/** main entry point
 */
int main(int argc, char **argv) {

 // we need 1 argument, the file name
 if(argc < 2) {
  fprintf(stderr, "Usage: %s [file]\n", argv[0]);
  exit(1);
 }

 // try to open the file
 FILE *f = fopen(argv[1], "r");
 if (f == NULL) {
  fprintf(stderr, "Error: failed to open file: %s\n", argv[1]);
  exit(2);
 }

 // allocate memory for storing the string and read contents
 string l = str_redfile(f, 0);

 // close file
 fclose(f);

 // check if reading worked
 if (l.error != 0) {
  fprintf(stderr, "Error: str_redfile() error: '%d'\n", l.error);
  fclose(f);
  exit(l.error);
 }

 // dump file infos
 str_dump(&l);

 // TODO: deallocate the memory
 // free memory
 //free(l.text);

 exit(EXIT_SUCCESS);
}

compiling the shared library and the test program from a bash:

#!/usr/bin/env bash
#
# gcc, compile a shared object file
#
# This example shows how to compile a shared object for C with gcc on linux. 
# required files: string.c, string.h test.
#
# $Id$

# configuration
bin=test
libname=string
v[0]=1; v[1]=0; v[2]=1;

# dynamic library
rm lib$libname* $bin
gcc -c -fPIC $libname.c -o $libname.o
gcc -shared -Wl,-soname,lib$libname.so -o lib$libname.so $libname.o
# create links for ld
#ln -s lib$libname.so lib$libname.so.${v[0]}
#ln -s lib$libname.so.${v[0]} lib$libname.so.${v[0]}.${v[1]}
#ln -s lib$libname.so.${v[0]}.${v[1]} lib$libname.so.${v[0]}.${v[1]}.${v[2]}

# compile executable
gcc $bin.c -o $bin -L. -l$libname

# run with proper LD_LIBRARY env variable, example:
# $ LD_LIBRARY_PATH=. ./test [path-to-file]

Running the executable. Make the newly compiled library available to ld through an environment variable.

$ LD_LIBRARY_PATH=. ./test [path-to-file]

6 Mar 2013

Reading file with dynamic memmory allocation in C

/*
 Will read a file from disk while dynamically allocating memory.

 Example usage: ./exe [file-name]
 */

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

typedef struct string_t {
 int memsize;
 int length;
 char *text;
 int error;
};
typedef struct string_t string;

string redfile(FILE *file);
void str_dump(string *s);

string redfile(FILE *file) {
 int charsize = sizeof(char);
 int charcount = 0;
 int blocksize = 10;
 int memsize = blocksize;
 char *line = (char*) malloc(charsize * (memsize+1));
 char *linep = line;

 string l;
 l.error = 0;
 l.length = 0;
 l.memsize = memsize;
 l.length = charcount;
 l.text = linep;

 while (1) {

  if(charcount > memsize) {
   // reallocate memmory
   memsize = memsize+blocksize;
   char *al = realloc(linep, charsize * (memsize+1));

   if (al == NULL) {
    fprintf(stderr, "Error, out of memory.\n");
    *line = '\0';
    l.text = linep;
    l.error = 1;
    return l;
   }
  }

  char c = fgetc(file);

  //if (c == '\n' || c == '\r' || c == EOF) {
  if (c == EOF) {
   charcount--;
   break;
  }

  // remember input char
  *line = c;
  *(line++);
  charcount++;
 }

 *line = '\0';
 l.text = linep;
 l.memsize = memsize;
 l.length = charcount;

 return l;
}

void str_dump(string *s) {
 if (s->error == 0) {
  printf("memsize: %d\n", s->memsize);
  printf("length:  %d\n", s->length);
  printf("error:   %d\n", s->error);
  printf("text:    %s\n", s->text);
  printf("total:   %lu\n", sizeof(*s)+1);
 } else
  printf("Error: %d.\n", s->error);
}

int main(int argc, char **argv) {
 // string l = redfile(stdin);

 if(argc < 2) {
  fprintf(stderr, "Usage: %s [file]\n", argv[0]);
  exit(1);
 }

 FILE *f = fopen(argv[1], "r");
 if (f == NULL) {
  fprintf(stderr, "Error: failed to open file: %s\n", argv[1]);
  exit(2);
 }

 string l = redfile(f);

 if (l.error != 0) {
  fprintf(stderr, "Error: redfile() error: '%d'\n", l.error);
  fclose(f);
  exit(l.error);
 }

 str_dump(&l);

 fclose(f);

 exit(0);
}

24 Feb 2013

Example using getopt from C


// $Id$

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>

struct opt_t {
 char* opt;
 char* arg;
};

int opt_parse(int argc, char *argv[], const char * optstring) {

 //Specifying the expected options
 //The two options l and b expect numbers as argument
 while ((option = getopt(argc, argv, optstring /*"apl:b:"*/)) != -1) {
  switch (option) {
   case 'd':
    printf("Database: %s\n", optarg);
    break;
   default: 
     printf("Huh?"); 
    return EXIT_FAILURE;
  }
 }
 
 return 0;
}

int main(int argc, char** argv) {
 const char* opts = "d:";
 
 int r = opt_parse(argc, argv, opts);
 
 return r;
}

13 Feb 2013

Problems programming ATtiny85 from Arduino IDE

After several successful firmware uploads from the Arduino IDE via Arduino Uno as ISP programmer to an ATtiny85 it suddenly stopped to work.

I have not figured out why this happens, a friend of mine has the same problem and couldn't find what caused it neither.

Long story short, the work around is to use Arduino IDE to compile the sketch and avrdude directly to do the uploading.

Compiling

Compiling code for ATtiny85/45 in Arduino IDE requires that the hardware definitions of these chips are installed in Arduino IDE:

Once the code is compiled it can be found in /tmp/build[0-9]*.tmp/*.hex on a *nix platform (C:\Windows\temp\... probably on windows, check the Arduino IDE manual).

Once the location of the hex file is known, I copy it to a safe place (data in the temp folder are purged occasionally).

Arduino as ISP

I am using Arduino Uno as programmer. For this wot work the arduino must be flashed with an already available sketch called: ArduinoISP (found under Examples).

Once this sketch is uploaded, the Arduino Uno works as In System Programmer and can be hooked up to your ATtiny device. The Arduino Uno is the used as "bridge" between your USB port on the computer and the tiny, as well as power supply.


Uploading

Using avrdude with the following parameters worked out of the box for me on a virgin ATTiny85 from linux:
$ avrdude -P /dev/ttyACM0 -p t85 -c avrisp -b 19200 \
          -v -F -U flash:w:pulse_in.cpp.hex



4 Feb 2013

nag-o-meter



This is our new status display of the Service Monitoring System I have built up during the last years. My cow-orkers keep forgetting to act upon warnings. I thought I could add some extra motivation for fixing errors in a timely manner (note the nice sound it makes :) ).

A little bit of python, a little bit of *nix voodoo glued together with a bash script - done.



28 Jan 2013

/dev/null

i just figured where all the stuff that is piped to /dev/null goes to.


5 Jul 2012

BlueSMiRF Gold setup HOWTO

a short HOWTO on BlueSMiRF Setup from linux.




The default baud rate of the BlueSMiRF Gold is 115'200 baud. Using an FTDI cable from sparkfun, 3V or 5V will do), the following pins must be connected:

FTDI connector:
BlueSMiRF Gold connector:
 
Wiring it up to the FTDI connector:
  • VCC to VCC (3.3-6V)
  • GND to GND 
  • TX-O to RX-I 
  • RX-I to TX-O 
The BlueSMiRF is now power via the FTDI's VCC. So, it's time to connect it to an USB port. Via /var/log/messages (on some linux systems it's in /var/log/syslog?) you ca check the name of the device

$ grep tty /var/log/messages | tail -n1
Jul  4 20:31:58 shell1 kernel: [4027300.342679] usb 8-1: FTDI USB Serial Device converter now attached to ttyUSB0


This means it is connected to /dev/ttyUSB0 in m case.

Now it's time to use a serial terminal such as minicom, screen or in my case PuTTY:
































Serial line: /dev/ttyUSB0
Speed: 115200
Connection type: Serial

That's it. You will be greeted with an empty prompt. At the prompt, enter '$$$' and hit the key. You should get an CMD as response. Otherwise you most probably have chosen the wrong tty port or baud rate. Also, you need to enter '$$$' in the first 60 seconds after power up or the command won't be recognized.

Entering help will bring up the ist of available commands:



*** SET COMMANDS ***
SA,<1,0>   - Authentication
SB,   - Send Break
SC,   - Service Class
SD,   - Device Class
SE,<1,0>   - Encryption
SF,1       - Factory Defaults
SI,   - Inquiry Scan Window
SJ,   - Page Scan Window
SL, - Parity
SM,<0-5>   - Mode (0=slav,1=mstr,2=trig,3=auto,4=DTR,5=Any)
SN,  - Name
SO,  - conn/discon Status
SP,  - Pin Code
SR,   - Remote Address
SS,  - Service Name
ST,   - Config Timer
SU,  - Baudrate
SW,   - Sniff Rate
SX,<1,0>   - Bonding
SY,   - TX power
SZ,   - Raw Baudrate
S7,<0-1>   - 7bit data
S~,<0-3>   - Profile (0=SPP,1=DCE,2=DTE,3=MDM,4=D&S
S?,<0-1>   - role switch
S$,  - CMD mode char
S@,   - io port dir
S&,   - io port val
S%,   - io boot dir
S^,   - io boot val
S*,   - pio(8-11) set
S|,   - low power timers
*** DISPLAY      ***
D     - Basic Settings
E     - Extended Settings
G  - Stored setting
GB    - BT Address
GK    - Connect Status
G&    - I/O Ports
V     - Firmare version
*** OTHER        ***
C,    - Connect
F,1        - Fast Mode
I,

Full documentation: RN-41 AT Command Set

All I needed to do was changing the name to something more specific to the device I was building (and wile I was at it, I changed the pin code needed for pairing):

SN,Fireworks-1
SP,5678 
R,1
D
***Settings***
BTA=000666069B51
BTName=Fireworks-1
Baudrt(SW4)=115K
Parity=None
Mode  =Slav
Authen=0
Encryp=0
PinCod=
5678Bonded=0
Rem=NONE SET




6 Mar 2012

gEDA pcb command line arguments

These are the command line arguments for pcb version 20110918:

PCB Printed Circuit Board editing program, http://pcb.gpleda.org
pcb [-h|-V|--copyright]   Help, version, copyright
pcb [gui options]   to edit
Available GUI hid:
 gtk      Gtk - The Gimp Toolkit
pcb -p [printing options]  to print
Available printing hid:
 lpr      Postscript print
pcb -x hid [export options]  to export
Available export hids:
 bom      Exports a Bill of Materials
 gcode    G-CODE export
 gerber   RS-274X (Gerber) export
 nelma    Numerical analysis package export
 png      GIF/JPEG/PNG export
 ps       Postscript export
 eps      Encapsulated Postscript

gtk gui options:
 --listen                       Listen for actions on stdin
 --bg-image             Background Image
 --pcb-menu             Location of gpcb-menu.res file

lpr options:
 --lprcommand           Command to use for printing
 --drill-helper                 Print a centering target in large drill holes
 --align-marks                  Print alignment marks on each sheet
 --outline                      Print outline on each sheet
 --mirror                       Print mirror image of every page
 --fill-page                    Scale board to fill page
 --auto-mirror                  Print mirror image of appropriate layers
 --ps-color                     Prints in color
 --ps-bloat            Amount to add to trace/pad/pin edges
 --ps-invert                    Draw objects as white-on-black
 --media 

   media type
 --psfade                  Fade amount for assembly drawings (0.0=missing, 
1.0=solid)
 --scale                   Scale value to compensate for printer sizing 
errors (1.0 = full scale)
 --multi-file                   Produce multiple files, one per page, instead 
of a single file
 --xcalib                  Paper width. Used for x-Axis calibration
 --ycalib                  Paper height. Used for y-Axis calibration
 --drill-copper                 Draw drill holes in pins / vias, instead of 
leaving solid copper
 --show-legend                  Print file name and scale on printout

bom options:
 --bomfile              Name of the BOM output file
 --xyfile               Name of the XY output file
 --xy-unit  XY units

gcode options:
 --basename             File name prefix
 --dpi                     Resolution of intermediate image (pixels/inch)
 --mill-depth              Milling depth
 --safe-Z                  Safe Z for traverse move
 --tool-radius             Milling tool radius compensation
 --drill-depth             Drilling depth
 --measurement-unit  Measurement unit

gerber options:
 --gerberfile           Gerber output file base
 --all-layers                   Output all layers, even empty ones
 --verbose                      Print file names and aperture counts on stdout
 --copy-outline  Copy outline onto other layers
 --name-style 
   Naming style for individual gerber files

nelma options:
 --basename             File name prefix
 --dpi                     Horizontal scale factor (grid points/inch)
 --copper-height           Copper layer height (um)
 --substrate-height        Substrate layer height (um)
 --substrate-epsilon       Substrate relative epsilon

png options:
 --outfile              Graphics output file
 --dpi                     Scale factor (pixels/inch). 0 to scale to 
specified size
 --x-max                   Maximum width (pixels).  0 to not constrain
 --y-max                   Maximum height (pixels).  0 to not constrain
 --xy-max                  Maximum width and height (pixels).  0 to not 
constrain
 --as-shown                     Export layers as shown on screen
 --monochrome                   Convert to monochrome
 --only-visible                 Limit the bounds of the PNG image to the 
visible items
 --use-alpha                    Make the background and any holes transparent
 --format         Export file format
 --png-bloat            Amount (in/mm/mil/pix) to add to trace/pad/pin 
edges (1 = 1/100 mil)
 --photo-mode                   Photo-realistic export mode
 --photo-flip-x                 Show reverse side of the board, left-right flip
 --photo-flip-y                 Show reverse side of the board, up-down flip

ps options:
 --psfile               Postscript output file
 --drill-helper                 Print a centering target in large drill holes
 --align-marks                  Print alignment marks on each sheet
 --outline                      Print outline on each sheet
 --mirror                       Print mirror image of every page
 --fill-page                    Scale board to fill page
 --auto-mirror                  Print mirror image of appropriate layers
 --ps-color                     Prints in color
 --ps-bloat            Amount to add to trace/pad/pin edges
 --ps-invert                    Draw objects as white-on-black
 --media 

   media type
 --psfade                  Fade amount for assembly drawings (0.0=missing, 
1.0=solid)
 --scale                   Scale value to compensate for printer sizing 
errors (1.0 = full scale)
 --multi-file                   Produce multiple files, one per page, instead 
of a single file
 --xcalib                  Paper width. Used for x-Axis calibration
 --ycalib                  Paper height. Used for y-Axis calibration
 --drill-copper                 Draw drill holes in pins / vias, instead of 
leaving solid copper
 --show-legend                  Print file name and scale on printout

eps options:
 --eps-file             Encapsulated Postscript output file
 --eps-scale               EPS scale
 --as-shown                     Export layers as shown on screen
 --monochrome                   Convert to monochrome
 --only-visible                 Limit the bounds of the EPS file to the visible 
items

Common options:
 --help                         Show help on command line options
 --version                      Show version
 --verbose                      Be verbose on stdout
 --copyright                    Show Copyright
 --show-defaults                Show option defaults
 --show-actions                 Show available actions
 --dump-actions                 Dump actions (for documentation)
 --grid-units           Default grid units (mm|mil)
 --black-color          color value of 'black'
 --white-color          color value of 'white'
 --background-color     color for background
 --crosshair-color      color for the crosshair
 --cross-color          color of the cross
 --via-color            color of vias
 --via-selected-color   color for selected vias
 --pin-color            color of pins
 --pin-selected-color   color of selected pins
 --pin-name-color       color for pin names and pin numbers
 --element-color        color of components
 --rat-color            color of ratlines
 --invisible-objects-color  color of invisible objects
 --invisible-mark-color  color of invisible marks
 --element-selected-color  color of selected components
 --rat-selected-color   color of selected rats
 --connected-color      color to indicate connections
 --off-limit-color      color of off-canvas area
 --grid-color           color of the grid
 --layer-color-1        Color for layer 1
 --layer-color-2        Color for layer 2
 --layer-color-3        Color for layer 3
 --layer-color-4        Color for layer 4
 --layer-color-5        Color for layer 5
 --layer-color-6        Color for layer 6
 --layer-color-7        Color for layer 7
 --layer-color-8        Color for layer 8
 --layer-color-9        Color for layer 9
 --layer-color-10       Color for layer 10
 --layer-color-11       Color for layer 11
 --layer-color-12       Color for layer 12
 --layer-color-13       Color for layer 13
 --layer-color-14       Color for layer 14
 --layer-color-15       Color for layer 15
 --layer-color-16       Color for layer 16
 --layer-selected-color-1  Color for layer 1 when selected
 --layer-selected-color-2  Color for layer 2 when selected
 --layer-selected-color-3  Color for layer 3 when selected
 --layer-selected-color-4  Color for layer 4 when selected
 --layer-selected-color-5  Color for layer 5 when selected
 --layer-selected-color-6  Color for layer 6 when selected
 --layer-selected-color-7  Color for layer 7 when selected
 --layer-selected-color-8  Color for layer 8 when selected
 --layer-selected-color-9  Color for layer 9 when selected
 --layer-selected-color-10  Color for layer 10 when selected
 --layer-selected-color-11  Color for layer 11 when selected
 --layer-selected-color-12  Color for layer 12 when selected
 --layer-selected-color-13  Color for layer 13 when selected
 --layer-selected-color-14  Color for layer 14 when selected
 --layer-selected-color-15  Color for layer 15 when selected
 --layer-selected-color-16  Color for layer 16 when selected
 --warn-color           color of offending objects during DRC
 --mask-color           color for solder mask
 --via-thickness       default diameter of vias in 1/100 mil
 --via-drilling-hole   default diameter of holes
 --line-thickness      initial thickness of new lines
 --rat-thickness       thickness of rat lines
 --keepaway            minimum distance between adjacent copper
 --default-PCB-width   default width of the canvas
 --default-PCB-height  default height of the canvas
 --text-scale              default text scale in percent
 --alignment-distance  distance between the boards outline and 
alignment targets
 --bloat               DRC minimum spacing in 1/100 mil
 --shrink              DRC minimum overlap in 1/100 mils
 --min-width           DRC minimum copper spacing
 --min-silk            DRC minimum silk width
 --min-drill           DRC minimum drill diameter
 --min-ring            DRC minimum annular ring
 --grid                Initial grid size in 1/100 mil
 --minimum polygon area   
 --backup-interval         Time between automatic backups in seconds. Set 
to 0 to disable
 --layer-name-1         Name for layer 1
 --layer-name-2         Name for layer 2
 --layer-name-3         Name for layer 3
 --layer-name-4         Name for layer 4
 --layer-name-5         Name for layer 5
 --layer-name-6         Name for layer 6
 --layer-name-7         Name for layer 7
 --layer-name-8         Name for layer 8
 --groups               Layer group string
 --font-command         Command to load a font
 --file-command         Command to read a file
 --element-command      Command to read a footprint
 --print-file           Command to print to a file
 --lib-command-dir      Path to the command that queries the library
 --lib-command          Command to query the library
 --lib-contents-command 
   Command to query the contents of the library
 --lib-newlib           Top level directory for the newlib style library
 --save-command         Command to save to a file
 --lib-name             The default filename for the library
 --default-font         File name of default font
 --route-styles         A string that defines the route styles
 --file-path           
 --rat-command          Command for reading a netlist
 --font-path            Colon separated list of directories to search 
the default font
 --element-path         A colon separated list of directories or 
commands (starts with '|')
 --lib-path             A colon separated list of directories
 --action-script        If set, this file is executed at startup
 --action-string        If set, this is executed at startup
 --fab-author           Name of author to be put in the Gerber files
 --layer-stack          Initial layer stackup, for setting up an export.
 --make-program         Sets the name and optionally full path to a 
make(3) program
 --gnetlist             Sets the name and optionally full path to the 
gnetlist(3) program
 --pinout-offset-x     Horizontal offset of the pin number display in 
mil
 --pinout-offset-y     Vertical offset of the pin number display in mil
 --pinout-text-offset-x 
   Horizontal offset of the pin name display in mil
 --pinout-text-offset-y 
   Vertical offset of the pin name display in mil
 --draw-grid                    If set, draw the grid at start-up
 --clear-line                   If set, new lines clear polygons
 --full-poly                   
 --unique-names                 Prevents identical component names
 --snap-pin                     If set, the cursor snaps to pads and pin centers
 --save-last-command           
 --save-in-tmp                  When set, all data which would otherwise be 
lost are saved in /tmp
 --all-direction-lines          Allow all directions, when drawing new lines
 --show-number                  Pinout shows number
 --reset-after-element          If set, all found connections are reset before 
a new component is scanned
 --ring-bell-finished           Execute the bell command when all rats are 
routed

.

14 Feb 2012

Mmmmh, Raspberry Pi

It looks like we can soon play with the Raspberry Pi.

Their slogan: «An ARM GNU/Linux box for $25. Take a byte!»

The RasPi is an ARM based is a cheap education computer running various Operating Systems (Linux, Android, Risc OS, Risc iX and probably more). The board comes in two flavours; $25 without and $35 with ethernet (and 256MB instead of 128MB ram). This is great hardware for tinkering. It has a hand full of GPIO ports, SPI, I2C, UART, USB, Ethernet on board as well as a HDMI/Composite output.

 



 Spcifications


Model A Model B
Target price:[1] US$25 (GBP £16) US$35 (GBP £22)
System-on-a-chip (SoC):[1] Broadcom BCM2835 (CPU + GPU + SDRAM)
CPU: 700 MHz ARM11 ARM1176JZF-S core
GPU: Broadcom VideoCore IV,OpenGL ES 2.0,OpenVG 1080p30 H.264 high-profile encode/decode
Memory (SDRAM): 128 MiB 256 MiB
USB 2.0 ports: 1(provided by the BCM2835) 2 (via integrated USB hub)
Video outputs:[1] Composite video|Composite RCA, HDMI (not at the same time)
Audio outputs:[1] TRS connector|3.5 mm jack, HDMI
Audio inputs: none, but a USB mic or sound-card could be added
Onboard Storage: Secure Digital|SD / MMC / SDIO card slot
Onboard Network:[1] None 10/100 wired Ethernet RJ45
Low-level peripherals: General Purpose Input/Output (GPIO) pins, Serial Peripheral Interface Bus (SPI), I²C, I²S[2], Universal asynchronous receiver/transmitter (UART)
Real-time clock:[1] None
Power ratings (provisional, from alpha board): 500mA, (2.5 Watt) [1] 700mA, (3.5 Watt)
Power source:[1] 5V via Micro USB or GPIO header
Size: 85.60mm x 53.98mm[3] (3.370 × 2.125 inch)

(Provisional - some of the expansion interfaces won't be available on production boards) (PCB IDs are those of the Model B Beta board)
  • SoC: Broadcom BCM2835 media processor (partial datasheet, BCM2835 datasheet errata) system-on-chip featuring:
    • CPU core: ARM1176JZF-S ARM11 core clocked at 700MHz; ARM VFP. The ARM11 core implements the ARMv6 Architecture. For details on ARM instruction sets and naming conventions, see ARM architecrture and List of ARM microprocessor cores.
    • GPU core: a Broadcom VideoCore IV GPU providing OpenGL ES 1.1, OpenGL ES 2.0, hardware-accelerated OpenVG 1.1, Open EGL, OpenMAX and 1080p30 H.264 high-profile decode. There are 24 GFLOPS of general purpose compute and a bunch of texture filtering and DMA infrastructure. Eben worked on the architecture team for this and the Raspberry Pi team are looking at how they can make some of the proprietary features available to application programmers
    • DSP core: There is a DSP, but there isn't currently a public API (Liz thinks the BC team are keen to make one available at some point)
    • RAM: 128MiB (Model A) or 256MiB (Model B) of SDRAM. The RAM is physically stacked on top of the Broadcom media processor (package-on-package technology)
  • LAN9512 (Data Brief | Data Sheet)(Model B) providing:
    • 10/100Mb Ethernet (Auto-MDIX)[4]
    • 2x USB 2.0
  • S1: Micro USB power jack (5v - Power Only)
  • S2: DSI interface. 15-pin surface mounted flat flex connector (possibly no-fit).
  • S3: HDMI connector providing HDMI 1.3a out
  • S4: Composite Video connector: RCA
  • S5: MIPI CSI-2 interface. 15-pin surface mounted flat flex connector (possibly no-fit).
  • S6: Audio connector: 3.5mm stereo jack (output only)
  • S8: SD/MMC/SDIO memory card slot (underside)
  • S7: Either 1x USB 2.0 (Model A) 2x USB 2.0 (Model B)
  • P1: 26-pin 2.54mm header expansion (header not fitted), providing: see Low-level peripherals
    • 8 GPIOs at 3v3
    • 2-pin UART serial console, 3v3 TTL (debug); or 2 GPIOs at 3v3
    • I2C interface (3v3); or 2 GPIOs at 3v3
    • SPI interface (3v3); or 5 GPIOs at 3v3
    • 3v3, 5v and GND supply pins
    • ARM JTAG (if pins are reconfigured in software)
    • Second I2C interface (3v3) (if pins are reconfigured in software)
    • I2S interface (if pins are reconfigured in software, hardware hack may be required[2])
    • 6 pins reserved for future use
  • P2 and P3: 8-pin and 7-pin 2.54mm header expansion (header not fitted), providing:
    • 6-pin GPU JTAG (ARM11 pinout)
  • P4: 10/100Mb RJ45 Ethernet jack (Model B)
  • 5 Status LEDs[5][6][7]:
    • D5(Yellow) - OK - SDCard Access (via GPIO16)
    • D6(Red) - PWR - 3.3V Power
    • D7(Green) - FDX - Full Duplex (LAN) (Model B)
    • D8(Green) - LNK - Link/Activity (LAN) (Model B)
    • D9(Yellow) - 10M - 10/100Mbit (LAN) (Model B)


  • Board size: 85.60mm x 53.98mm. Overall height expected to be less than 25mm. [8]
  • Weight: <40g? (Alpha board weighs ~55g [9])
  • 6 layer PCB [8]





26 Oct 2011

Export SVG vector graphic to different sizes of PNG

#!/usr/bin/env bash

function export() {
 width=$1
 height=$2
 
 inkscape -w $width -h $height \
  -e app_icon_${width}x${height}.png app_icon.svg
}

export 72 72
export 48 48
export 36 36

5 May 2011

subversion and xxdiff

xxdiff is an X11 application for displaying differences of two files.

Installation on Debian:
$ sudo apt-get install xxdiff-scripts

Example usage with subversion (if you run the above command and are on X11 with xxdiff installed and in your $PATH, xxdiff should start, else console output should appear):

#!/usr/bin/env bash
# $Id: svndiff_gui.sh 174 2011-05-05 19:13:55Z wus $

# use xxdiff when available and on X11

if [[ -n "$DISPLAY" && -x `which xxdiff` ]]; then
 svn stat
 read -p "Graphical diff? [Y/n]: " proceed
 if [[ "$proceed" == "" || "$proceed" == "y" || "$proceed" == "Y" ]]; then
  xx-svn-diff $@
  exit $?
 fi
fi

svn diff $@

3 Dec 2010

plone 4 on debian 5 lenny

# apt-get install g++ make libssl-dev bzip2 exim4-daemon-light

Download latest version of Plone (Unified Installer)

tar zxvf Plone-YOURVERSION-UnifiedInstaller.tgz
cd Plone-YOURVERSION-UnifiedInstaller
./install.sh standalone

w3m /usr/local/Plone/zinstance/README.html
less /usr/local/Plone/zinstance/buildout.cfg

Find start script at:
/usr/local/Plone/zinstance/bin/plonectl

Change Admin password:
  • http://localhost:8080/manage (check zinstance/buildout.cfg for port)
  • Enter the ZMI root
  • Change the password for the admin user in the acl_users folder in the root
  • Log in with the new password
Run plone 4 from init.d on Debian:
For this, you need to copy the init script from below to /etc/init.d/plone and make it executable (chmod 755), then run update-rc.d
# update-rc.d plone defaults

Debian init script:
#! /bin/sh -e
# /etc/init.d/plone
### BEGIN INIT INFO
# Provides:          plone
# Required-Start:    $syslog $time $remote_fs
# Required-Stop:     $syslog $time $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Plone 4
# Description:       Plone 4 instance installed with the unified installer.
### END INIT INFO
#
# Author: Simon Wunderlin, swunderlin () gmail , com
#
set -e

ZINSTANCE=/usr/local/Plone/zinstance

PATH=/bin:/usr/bin:/sbin:/usr/sbin:$ZINSTANCE/bin
DAEMON=$ZINSTANCE/bin/plonectl

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
    start)
 log_daemon_msg "Starting plone"
 $DAEMON start >> /var/log/plone.log
 log_end_msg $?
    ;;
  stop)
 log_daemon_msg "Stopping plone"
 $DAEMON stop >> /var/log/plone.log
 log_end_msg $?
    ;;
  force-reload|restart)
    $DAEMON stop
    $DAEMON start
    ;;
  *)
    echo "Usage: /etc/init.d/plone {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
--

5 Sept 2010

Hmmm, connects on port 8080, what are they looking for ?

Lately I get many connects on port tcp/8080 at home. Sounds like someone is looking for an open proxy?

It's simple to monitor the traffic with minimal unix tools (even without a gui):

while true; do netcat -l 8080 >> 8080.log; done&

tail -f 8080.log
==> 8080.log <==

Now sit back and watch the log.

11 Aug 2010

Qnap NAS -- dnsmasq via ipkg

dnsmasq is a lightweight dns and dhcp server, well suited for a NAS and available through ipkg (Optware plugin) on Qnap devices.

First of all, make sure the dhcp server on the system is deactivated before using dnsmasq as dhcp server. Setting up a DHCP server the qnap way is a little bit hidden, you may check: System Administration » Network  » TCP/IP » IP Address » Edit.

there is a linux like package manager (similar to deb or rpm) which provides the most convenient way to install dnsmasq.

Before being able to install ipkg packages a qnap package (which contains ipkg) must be installed. The package is called Optware. Download it and install it via the Qnap admin interface (Application » QPKG Plugins » Insallation, upload the unzipped .qpkg file).

Make sure that init scripts from /opt/init.d are executed, this might be prevented by a bug in the 3.x firmware (this is the location where ipkg stores it's init scripts). Edit /etc/init.d/Optware.sh an add the following code snipped:

case "$1" in
  start)
               ...[elided]...
 # adding Ipkg apps into system path ...
 /bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
# Patch per http://wiki.qnap.com/wiki/Install_Optware_IPKG
#       [ $? -ne 0 ] && /bin/echo "export PATH=$PATH":/opt/bin:/opt/sbin >> /etc/profile
        # Bug fix for following: put IPKG first, per http://forum.qnap.com/viewtopic.php?f=124&t=15663
        # was [ $? -ne 0 ] && /bin/echo "export PATH=$PATH":/opt/bin:/opt/sbin >> /etc/profile
        [ $? -ne 0 ] && /bin/echo "export PATH=/opt/bin:/opt/sbin:\$PATH" >> /etc/profile

  /bin/echo "Run Optware/ipkg /opt/etc/init.d/*"
   source /etc/profile
        # Start all init scripts in /opt/etc/init.d
 # executing them in numerical order.
 #
 for i in /opt/etc/init.d/S??* ;do
     # Ignore dangling symlinks (if any).
         #[ ! -f "$i" ] && continue

            case "$i" in
                *.sh)
             # Source shell script for speed.
             (
          trap - INT QUIT TSTP
   set start
          . $i
          )
         ;;
         *)
          # No sh extension, so fork subprocess.
          $i start
                ;;          
            esac            
        done                
# End patch

 ;;
  stop)
               ...[elided]...
Then make sure, that the dnsmasq init script file name ends in .sh (which is not the case at the time of this writing).
ln -s /opt/etc/init.d/S56dnsmasq  /opt/etc/init.d/S200dnsmasq.sh
Make sure to disable the local dhcpd server when using dnsmasq as dhcp server (/opt/etc/init.d/S??*dnsmasq*):
#!/bin/sh

# disable the local dhcpd server if dnsmasq is to be used as dhcp server
/etc/init.d/dhcpd.sh stop

if [ -f /var/run/dnsmasq.pid ] ; then
  kill -9 `cat /var/run/dnsmasq.pid`
  rm -f /var/run/dnsmasq.pid
fi

sleep 2
/opt/sbin/dnsmasq
I have created a share System with subfolder etc pointing to /share/System/etc. /opt/etc/dnsmasq.conf
conf-file=/share/System/etc/dnsmasq.conf
/share/System/etc/dnsmasq.conf
################################################################################
## server settings

# The DHCP server needs somewhere on disk to keep its lease database.
# This defaults to a sane location, but if you want to change it, use
# the line below.
dhcp-leasefile=/tmp/dnsmasq.leases

# If you don't want dnsmasq to read /etc/resolv.conf or any other
# file, getting its servers from this file instead (see below), then
# uncomment this.
# CAREFUL: this willprevent dnsmasq to query exteral dns servers.
#no-resolv

# If you don't want dnsmasq to poll /etc/resolv.conf or other resolv
# files for changes and re-read them then uncomment this.
no-poll

# The following two options make you a better netizen, since they
# tell dnsmasq to filter out queries which the public DNS cannot
# answer, and which load the servers (especially the root servers)
# uneccessarily. If you have a dial-on-demand link they also stop
# these requests from bringing up the link uneccessarily. 

# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
 
# By  default,  dnsmasq  will  send queries to any of the upstream
# servers it knows about and tries to favour servers to are  known
# to  be  up.  Uncommenting this forces dnsmasq to try each query
# with  each  server  strictly  in  the  order  they   appear   in
# /etc/resolv.conf
#strict-order

# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
#expand-hosts

# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5
dhcp-option=option:ntp-server,92.42.186.250,192.33.96.102,195.216.64.208

# Set the NIS domain name 
#dhcp-option=40,wundinet

# Disable NetBIOS over TCP/IP
# NOTE: this will probably cause problems for clients < Win2K
dhcp-option=43,01:04:00:00:00:02

################################################################################
## domain settings

# Set the domain for dnsmasq. this is optional, but if it is set, it# Add 
# local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only.
# TODO: not sure if this is needed
local=/example.com/

# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
#     as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
#    domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
domain=example.com

# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
dhcp-range=10.0.0.150,10.0.0.180,12h

# Specify a subnet which can't be used for dynamic address allocation,
# is available for hosts with matching --dhcp-host lines. Note that
# dhcp-host declarations will be ignored unless there is a dhcp-range
# of some type for the subnet in question.
# In this case the netmask is implied (it comes from the network
# configuration on the machine running dnsmasq) it is possible to give 
# an explict netmask instead.
dhcp-range=10.0.0.0,static

# Override the default route supplied by dnsmasq, which assumes the
# router is the same machine as the one running dnsmasq.
dhcp-option=3,10.0.0.1

# Do the same thing, but using the option name
dhcp-option=option:router,10.0.0.1
dhcp-option=option:dns-server,10.0.0.48,10.0.0.1
dhcp-option=option:domain-name,example.com

# Send RFC-3397 DNS domain search DHCP option. WARNING: Your DHCP client
# probably doesn't support this......
dhcp-option=option:domain-search,example.com

# Set the DHCP server to authoritative mode. In this mode it will barge in
# and take over the lease for any client which broadcasts on the network,
# whether it has a record of the lease or not. This avoids long timeouts
# when a machine wakes up on a new network. DO NOT enable this if there's
# the slighest chance that you might end up accidentally configuring a DHCP
# server for your campus/company accidentally. The ISC server uses
# the same option, and this URL provides more information:
# http://www.isc.org/index.pl?/sw/dhcp/authoritative.php
dhcp-authoritative
/share/System/etc/dnsmasq.hosts.conf
################################################################################
# cannonical names
cname=www.example.com,infra3.example.com
 
## hosts with static ips
address=/splatter.example.com/10.0.0.33
ptr-record=33.0.0.10.in-addr.arpa,splatter.example.com
dhcp-host=00:17:9a:7b:c2:02,splatter.example.com,10.0.0.33,infinite
Substitute example.com with your own domain and 10.0.0.* with your ip range in the various config files.

Time to restart theservice
/opt/etc/init.d/S??*dnsmasq*
(the dnsmasq init script should really be named /opt/etc/init.d/S200dnsmasq.sh by now, this will make automatic start after reboot possible).

If you want to be 100% sure that Qnap's own dhcp server is not bindingthe port you want to use with  dnsmasq as dhcp server, use the following startup script (/opt/etc/init.s/S200dnsmasq):
#!/bin/sh

# disable the local dhcpd server
/etc/init.d/dhcpd.sh stop

if [ -f /var/run/dnsmasq.pid ] ; then
  kill -9 `cat /var/run/dnsmasq.pid`
  rm -f /var/run/dnsmasq.pid
fi

sleep 2
/opt/sbin/dnsmasq
.

9 Aug 2010

selecting text in vim from an xterm

I have line numbers turned on in vim. this makes selecting text awkward, since the line numbers are selected and copied too.

Fortunately, there is a helpful vimrc setting as long as you are using some sort of xterm:

set number
set mouse=a
Left-clicking and dragging in a terminal in which vim is running will result in text a only selection.

15 Feb 2010

Ubuntu default settings

The first time I used Ubuntu (Version 7 something) it just felt right out of the box. Nowadays, I will have to set quiet some config values after setting up a new one. Especially the default gnome configuration sucks big hairy monkey balls!

Some helpful default settings (for me) are:

# $Id$
# set up sane gnome config on ubuntu.

# update-notifier should stay in tray (pops up anooyingly if it detects updates)
gconftool -s --type bool /apps/update-notifier/auto_launch false

# enter paths manually in nautilus if needed
gconftool -s --type bool /apps/nautilus/preferences/always_use_location_entry true

# we want a browser, no fucking new window on every click
gconftool -s --type bool /apps/nautilus/preferences/always_use_browser true

# Delete baby, i want to delete, not move. if i want to move i use move FTW!
gconftool -s --type bool /apps/nautilus/preferences/enable_delete true

# show unix permissions in nautilus permission dalogs, not this mikey mouse ui
gconftool -s --type bool /apps/nautilus/preferences/show_advanced_permissions true

# default view should be listing in nautilus
gconftool -s --type string /apps/nautilus/preferences/default_folder_viewer "list_view"

# no text below toolbar icons, waste of scree nreal estate
gconftool -s --type string /desktop/gnome/interface/toolbar_style "icons"

# display unix permission, owner and group
gconftool-2 --set --type list --list-type=string /apps/nautilus/list_view/default_visible_columns \
[name,size,type,date_modified,permissions,owner,group]

# don't open inserted media in nautilus
gconftool -s --type bool /apps/nautilus/preferences/media_automount_open false

# do not confirm delete
gconftool -s --type bool  /apps/nautilus/preferences/confirm_trash false

29 Jan 2010

WTF, why can't I unmount a volume?

Sometimes some file locks are preventing unmounting a block devices (especially annoying on removable devices).

Some nice utilities are fuser (list processes using files, sockes or fs) and lsof (list open files).

This combined with kill gets those external block devices quickly unmounted when needed