Laser cutter software

Dependencies:   EthernetNetIf mbed SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
pbrier
Date:
Thu Aug 11 09:33:15 2011 +0000
Commit message:
Laos server

Changed in this revision

ConfigFile/ConfigFile.cpp Show annotated file Show diff for this revision Revisions of this file
ConfigFile/ConfigFile.h Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
LaosDisplay/LaosDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
LaosDisplay/LaosDisplay.h Show annotated file Show diff for this revision Revisions of this file
LaosFile/SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
LaosIO/LaosIO.cpp Show annotated file Show diff for this revision Revisions of this file
LaosIO/LaosIO.h Show annotated file Show diff for this revision Revisions of this file
LaosMenu/LaosMenu.cpp Show annotated file Show diff for this revision Revisions of this file
LaosMenu/LaosMenu.h Show annotated file Show diff for this revision Revisions of this file
LaosMotion/LaosMotion.cpp Show annotated file Show diff for this revision Revisions of this file
LaosMotion/LaosMotion.h Show annotated file Show diff for this revision Revisions of this file
LaosServer/EthConfig.cpp Show annotated file Show diff for this revision Revisions of this file
LaosServer/EthConfig.h Show annotated file Show diff for this revision Revisions of this file
LaosServer/LaosServer.cpp Show annotated file Show diff for this revision Revisions of this file
LaosServer/LaosServer.h Show annotated file Show diff for this revision Revisions of this file
global.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConfigFile/ConfigFile.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,130 @@
+/*
+ * ConfigFile.cpp
+ * Simple Config file reader class
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+#include "ConfigFile.h"
+
+// Make new config file object
+ConfigFile::ConfigFile(char *file) 
+{
+ // printf("ConfigFile(%s)\n\r", file);
+  fp = fopen(file,"rb");
+}
+
+// Destroy a config file (closes the file handle)
+ConfigFile::~ConfigFile() 
+{
+ // printf("~ConfigFile()\n\r");
+  if ( fp != NULL )
+    fclose(fp);
+}
+
+// Read value
+bool ConfigFile::Value(char *key, char *value,  size_t maxlen, char *def)
+{
+  int m=0,n=0,c,s=0;
+  if (fp == NULL)
+  {
+    strncpy(value, def, maxlen);
+    return false;
+  }
+  // printf("Value()\n\r");
+  n = strlen(key);
+  fseek(fp, 0L, SEEK_SET);
+  while( s != 99  ) 
+  {
+    c = fgetc(fp);
+    if ( c == EOF ) 
+      break;
+   // printf("%d: '%c'\n\r", s, c);
+    switch( s  )// sate machine
+    { 
+      case 0: // (re) start: note: no break; fall through to case 1
+        m=0; 
+        s=1;
+      case 1: // read key, skip spaces
+        if ( c == key[m] ) 
+          m++; 
+        else 
+          s = 0;
+        if ( c == ';' ) 
+          s = 10; 
+        else if ( c == ' ' || c == '\t' || c == '\n' || c == '\r') 
+        {
+          if ( n == m ) // key found
+          {
+            s = 2;
+            m = 0; 
+          }
+          else
+            s = 0;
+        }
+        break;
+      case 2: // key matched, skip whitepaces upto the first char
+        if ( c == ';' ) s = 99;
+        else if ( c != ' ' && c != '\t' ) 
+        { 
+          s = 3;
+          m = 1;
+          if ( m < maxlen) 
+            *value++ = c;
+        }
+        break;
+        
+      case 3: // copy value content, upto eol or comment
+        if ( m == maxlen || c == '\n' || c == '\r' || c == ';' ) 
+          s = 99;
+        else
+        {
+          m++;
+          *value++ = c;
+        }
+        break;         
+      case 10: // skip comments, upto eol or eof
+        if ( c == '\n' || c == '\r' ) s = 0;
+        break;
+     }
+  }
+  if ( s == 99 && m > 1) // key found, and value assigned
+  {
+     *value = 0; // terminate string
+    return true; 
+  }
+  else
+  {
+    strncpy(value, def, maxlen);
+    return false;
+  } 
+}
+
+// Read int value
+bool ConfigFile::Value(char *key, int *value, int def)
+{
+  char val[16];
+  bool b = Value(key, val, 12, "");
+  if ( b )
+    *value = atoi(val);
+  else
+  {
+     *value = def;
+  }
+  return b;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConfigFile/ConfigFile.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,109 @@
+/**
+ * ConfigFile.cpp
+ * Simple Config file reader class
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Reads a setting, based on the key. (case sensitive)
+ * If the key is not found, the default value is returned.
+ *
+ * Simple, not (time) efficient. For every request, the complete file is reset and read again
+ *
+ @code 
+ file format
+ 
+ ; comment
+ key value [newline || comment]
+
+ For example:
+ 
+ ; This is a test config file
+ ip 192.168.1.1
+ port 1234 ; the key is "port" the value is "1234". The rest is comment
+ ; EOF
+ @endcode
+ */
+#ifndef _CONFIG_FILE_H_
+#define _CONFIG_FILE_H_
+
+#include "global.h"
+
+    /** Simple config file object
+      * Only supports reading config files. Tries to limit memory usage.
+      * Note: the file handle is kept open during the lifetime of this object.
+      * To close the file: destroy this ConfigFile object! A simple way is to enclose the creation
+      * of this object inside a code block
+      * Example:
+      * @code 
+      * char ip[16];
+      * int port;
+      * {
+      *   ConfigFile cfg("/local/config.txt");
+      *   cfg.Value("ip", ip, sizeof(ip), "192.168.1.10");
+      *   cfg.Value("port", &port, 80);
+      * }
+      * @endcode
+      */
+class ConfigFile {
+public:
+    /** Make new ConfigFile object. Open config file.
+      * Note: the file handle is kept open during the lifetime of this object.
+      * To close the file: destroy this ConfigFile object!
+      * @param file Filename of the configuration file.
+      */
+    ConfigFile(char *name);
+
+    ~ConfigFile();
+
+/** Read value. If file is not open, or key does not exist: copy default value (return false)
+  * @param key name of the key in the file
+  * @param value pointer to buffer that receives the value
+  * @param maxlen the maximum length of the value. If the actual value is longer, it is truncated
+  * @param def Default value. If the key is not found in the file, this value is copied. 
+  * @return "true" if the key is found "false" is key is not found (default value is returned)
+  */ 
+    bool Value(char *key, char *value,  size_t maxlen, char *def);
+
+/** Read Integer value. If file is not open, or key does not exist: copy default value (return false)
+  * @param key name of the key in the file
+  * @param value pointer to integer that receives the value
+  * @param def Default value. If the key is not found in the file, this value is copied. 
+  * @return "true" if the key is found "false" is key is not found (default value is returned)
+  */ 
+    bool Value(char *key, int *value, int def);
+    
+  /** See if file was present
+  * @return "true" if file is open, "false" file is not found 
+  */ 
+  bool IsOpen(void) { return fp != NULL; }
+  
+private:
+    FILE *fp;
+
+};
+
+#define K_UP '8'
+#define K_DOWN '2'
+#define K_LEFT '4'
+#define K_RIGHT '6'
+#define K_OK '5'
+#define K_CANCEL '0'
+#define K_FUP '9'
+#define K_FDOWN '3'
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FATFileSystem.lib	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_unsupported/code/fatfilesystem/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosDisplay/LaosDisplay.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,149 @@
+/**
+ * LaosDisplay.cpp
+ * User interface class, for 2x16 display and keypad
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Assume (USB) serial connected display (or terminal) in future, this could be CAN or I2C connected
+ *
+ */
+#include "LaosDisplay.h"
+
+
+// I2C
+I2C i2c(p9, p10);        // sda, scl
+#define _I2C_ADDRESS 0x04
+#define _I2C_HOME 0xFE
+#define _I2C_CLS 0xFF
+#define _I2C_BAUD 10000
+
+  
+// Make new config file object
+LaosDisplay::LaosDisplay()
+{
+  serial = new Serial(USBTX, USBRX);
+  serial->baud(115200);
+}
+
+
+//Write char
+ void LaosDisplay::write(char c) 
+{
+  serial->putc(c);
+}
+
+// Write string
+void LaosDisplay::write(char *s) 
+{
+  if ( s == NULL ) return;
+  i2c.write(_I2C_ADDRESS, s, strlen(s));
+  while (*s)
+    serial->putc(*s++);
+}
+
+// Clear screen
+void LaosDisplay::cls() 
+{
+    write('\t');
+}
+
+
+// Read Key
+int LaosDisplay::read() 
+{
+  char key;
+  int result;
+  result = i2c.read(_I2C_ADDRESS,&key, 1);
+  if ( result ) return key;
+  if ( serial->readable() )
+    return serial->getc();
+  else
+    return 0;
+}
+
+
+
+/**
+*** Screens are defined with:
+*** name, line[2], int* i[4], char *s;
+***
+*** in the lines, the following replacements are made:
+*** $$$$$$ : "$" chars are replaced with the string argument for this screen (left alligned), if argument is NULL, spaces are inserted
+*** +9876543210: "+" and numbers are replaced with decimal digits from the integer arguments (the "+" sign is replaced with '-' if the argument is negative
+*** 
+***
+**/
+inline char digit(int i, int n)
+{
+  int d=1;
+  char c;
+  if ( i<0 ) i *= -1;
+  while(n--) d *= 10;
+  c = '0' + ((i/d) % 10);
+  return c;
+}
+void LaosDisplay::ShowScreen(const char *l, int *arg, char *s)
+{
+  char c, next=0,surpress=1;
+  cls(); 
+  while ( (c=*l) )
+  {
+    switch ( c )
+    {
+    case '$': 
+      if (s != NULL && *s)
+        c = *s++;
+      else 
+        c = ' ';
+      break;
+      
+    case '+':
+      if (arg != NULL && *arg < 0)
+        c = '-';
+      else 
+        c = '+';
+      break;
+        
+    case '0': next=1; surpress=0; 
+    case '1': case '2': case '3': case '4': 
+    case '5': case '6': case '7': case '8': case '9':
+      char d = ' ';
+      if (arg != NULL )
+      {
+        d = digit(*arg, *l-'0');
+        if ( d == '0' && surpress  ) // supress leading zeros 
+          d =  ' ';
+        else
+          surpress = 0;
+        if ( next && arg != NULL ) // take next numeric argument
+        {
+          arg++;
+          next=0;
+          surpress=1;
+        }
+      }
+      c = d;
+      break;
+    }
+    write(c);
+    l++;
+  }
+}
+
+
+// EOF
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosDisplay/LaosDisplay.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,74 @@
+/**
+ * LaosDisplay.cpp
+ * User interface class, for 2x16 display and keypad
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Assume (USB) serial connected display (or terminal) in future, this could be CAN or I2C connected
+ *
+ */
+#ifndef _LAOS_DISPLAY_H_
+#define _LAOS_DISPLAY_H_
+#include "global.h"
+
+    /** LaosDisplay
+      * Connect to LCD terminal or PC
+      * Example:
+      * @code 
+      * @endcode
+      */
+class LaosDisplay {
+public:
+    /** Make new LaosDisplay object. 
+      */
+    LaosDisplay();
+
+/** Display string at position (x,y)
+  * @param x  x position in characters (zero based)
+  * @param y  y position in characters (zero based)
+  * @param s The string to display
+  */ 
+  void write(char *s);
+  void write(char c);
+  void ShowScreen(const char *l, int *arg, char *s);
+   
+
+/** Clear screen
+  */ 
+   void cls();
+
+/** Read key value. (non blocking)
+  * @return (ASCII) character value, zero if no character is available
+  */ 
+  int read();
+    
+private:
+  Serial *serial;
+};
+
+#define K_UP '8'
+#define K_DOWN '2'
+#define K_LEFT '4'
+#define K_RIGHT '6'
+#define K_FUP '9'
+#define K_FDOWN '3'
+#define K_OK '5'
+#define K_CANCEL '0'
+#define K_ORIGIN '1'
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosFile/SDFileSystem.lib	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosIO/LaosIO.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,50 @@
+/**
+ * LaosIO.cpp
+ * input / output system
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * set and get inputs/outputs for the peripherals
+ *
+ @code 
+ --code--
+ @endcode
+ */
+
+#include "LaosIO.h"
+
+LaosIO::LaosIO()
+{
+  state = 0;
+}
+
+LaosIO::~LaosIO()
+{
+}
+
+
+void LaosIO::set(int line, bool state)
+{
+}
+
+bool LaosIO::get(int line)
+{
+  return false;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosIO/LaosIO.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,51 @@
+/**
+ * LaosIO.h
+ * input / output system
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * set and get inputs/outputs for the peripherals
+ *
+ @code 
+ --code--
+ 
+ @endcode
+ */
+#ifndef _LAOSIO_H_
+#define _LAOSIO_H_
+#include "global.h"
+
+    /** IO System
+      * Get and Set IO lines
+      */
+class LaosIO {
+public:
+    /** Make new LaosIO object. 
+      */
+  LaosIO();
+
+  ~LaosIO();
+
+  void set(int line, bool state);
+  bool get(int line);
+
+private:
+  unsigned int state;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosMenu/LaosMenu.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,290 @@
+/*
+ * LaosMenu.cpp
+ * Menu structure and user interface. Uses LaosDisplay
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+#include "LaosMenu.h"
+
+//extern int x0,y0,z0;
+
+static const char *menus[] = {
+    "MAIN",        //0 
+    "MOVE",        //1
+    "FOCUS",       //2
+    "HOME",        //3
+    "ORIGIN",      //4
+    "START JOB",   //5
+    "DELETE JOB",  //6 
+    "IP",          //7
+    "POWER / SPEED",//8
+    "IO", //9
+};
+
+static const char *screens[] = {
+    //0: main, navigate to  MOVE, FOCUS, HOME, ORIGIN, START JOB, IP, DELETE JOB, POWER
+#define MAIN (0)
+    "$$$$$$$$$$$$$$$$" "\n"
+    "<--- 0 ---> [ok]",
+  
+#define MOVE (MAIN+1)
+    "X: +6543210 MOVE" "\n"
+    "Y: +6543210 [ok]",
+    
+#define FOCUS (MOVE+1)
+    "Z: +543210 FOCUS" "\n"
+    "            [ok]",
+
+#define HOME (FOCUS+1)
+    "     HOME?      " "\n"
+    "[cancel]    [ok]",  
+
+#define ORIGIN (HOME+1)
+    "  SET ORIGIN?   " "\n"
+    "[cancel]    [ok]",   
+
+#define RUN (ORIGIN+1)
+    "RUN: $$$$$$$$$$$" "\n"
+    "[cancel]<10><ok>",   
+
+#define DELETE (RUN+1)
+    "DEL: $$$$$$$$$$$" "\n"
+    "[cancel]<10>[ok]",   
+
+#define IP (DELETE+1)
+    "210.210.210.210 " "\n"
+    "$$$$$$$$<0> [ok]",    
+
+#define POWER (IP+1)
+    "$$$$$$$: 6543210" "\n"
+    "[cancel] <0>[ok]",    
+
+#define IO (POWER+1)
+    "$$$$$$$$$$$=0 IO" "\n"
+    "[cancel]    [ok]",    
+
+// Intermediate screens
+#define DELETE_OK (POWER+1)
+    "   DELETE 10?   " "\n"
+    "<cancel>    [ok]",   
+
+#define HOMING (DELETE_OK+1) 
+    "HOMING...6543210" "\n"
+    "[cancel]        ",   
+    
+#define BUSY (HOMING+1)
+    "BUSY: $$$$$$$$$$" "\n"
+    "[cancel]    [ok]",
+
+#define PAUSE (BUSY+1)
+    "PAUSE: $$$$$$$$$" "\n"
+    "[cancel]    [ok]",
+
+};
+
+static  const char *ipfields[] = { "IP", "NETMASK", "GATEWAY", "DNS" };
+static  const char *powerfields[] = { "Pmin %", "Pmax %", "Voff", "Von" };
+static  const char *iofields[] = { "o1:PURGE", "o2:EXHAUST", "o3:PUMP", "i1:COVER", "i2:PUMPOK", "i3:LASEROK", "i4:PURGEOK" };
+  
+  
+/**
+*** Make new menu object
+**/
+// LaosMenu::LaosMenu(const LaosDisplay &display) : dsp(display) 
+LaosMenu::LaosMenu() 
+{
+  waitup=timeout=0;
+  sarg = NULL;
+  x=y=z=0;
+  screen=prevscreen=menu=speed=0;
+  dsp.cls();
+}
+
+
+
+/**
+*** Destroy menu object
+**/
+LaosMenu::~LaosMenu() 
+{
+
+}
+
+
+
+/**
+*** Handle menu system
+*** Read keys, an plan next action on the screen, output screen if something changed
+**/
+void LaosMenu::Handle()
+{
+  static int count=0;
+  int c = dsp.read();
+  if ( count++ > 10) count = 0;
+  if ( c )
+    timeout = 10;
+  else
+    if ( timeout ) timeout--;
+  if ( screen != prevscreen ) 
+    waitup = 1;
+  if ( waitup && timeout) // if we have to wait for key-up, cancel the keypress
+    c = 0;
+  if ( waitup && !timeout )
+    waitup=0;
+  if ( !timeout )  // increase speed if we keep button pressed longer 
+    speed = 1;
+  else
+  {
+    speed += 1;
+    if ( speed >= 500 ) speed = 100;    
+  }
+
+  if ( c || screen != prevscreen || count >9 ) 
+  {
+    
+    switch(c) // screen independent handling
+    { 
+      case K_FUP: screen=FOCUS; break;
+      case K_FDOWN: screen=FOCUS; break;
+      case K_ORIGIN: screen=ORIGIN; break;
+    }
+    
+    prevscreen = screen;  
+    
+    switch ( screen ) 
+    {
+      case MAIN:
+        switch ( c )
+        {
+          case K_RIGHT: menu+=1; waitup=1; break;
+          case K_LEFT: menu-=1; waitup=1; break;
+          case K_UP: screen=MOVE; break;
+          case K_DOWN: screen=MOVE; break;
+          case K_OK: screen=menu; break;
+          case K_CANCEL: menu=MAIN; break;
+        }
+        menu =  menu % (sizeof(menus) / sizeof(menus[0]));
+        sarg = (char*)menus[menu]; 
+        args[0] = menu;
+        break;
+      
+      case MOVE: // pos xy
+        switch ( c )
+        {
+          case K_UP: y+=speed; break;
+          case K_DOWN: y-=speed; break;
+          case K_LEFT: x-=speed; break;
+          case K_RIGHT: x+=speed; break;
+          case K_OK: case K_CANCEL: screen=MAIN; waitup=1; break;
+        }
+        args[0]=x; args[1]=y; 
+        break;
+        
+      case FOCUS: // focus
+        switch ( c )
+        {
+          case K_FUP: case K_UP: z+=speed; break;
+          case K_FDOWN: case K_DOWN: z-=speed; break;
+          case K_LEFT: screen=MAIN; menu -= 1; break;
+          case K_RIGHT: screen=MAIN; menu += 1; break;
+          case 0: break;
+          default: screen=MOVE; break;
+        }
+        args[0]=z;  
+        break;
+
+      case HOME:// home
+        switch ( c )
+        {
+          case K_OK: x=0; y=0; screen=HOMING; break;
+          case K_CANCEL: screen=MOVE; waitup=1; break;
+        }
+        break;
+  
+      case ORIGIN: // origin
+        switch ( c )
+        {
+          case K_OK: x=0; y=0; screen=MOVE; break;
+          case K_CANCEL: screen=MOVE;  break;
+        }
+        break;
+        
+      case IP: // IP
+        switch ( c )
+        {
+          case K_RIGHT: ipfield++; waitup=1; break;
+          case K_LEFT: ipfield--; waitup=1; break;
+          case K_OK: screen=MAIN; break; 
+          case K_CANCEL: screen=MAIN; break;
+        }
+        ipfield %= 4;
+        sarg = (char*)ipfields[ipfield];
+        args[4] = ipfield;
+        switch(ipfield)
+        {
+          case 0: memcpy(args, ipInfo.ip, 4*sizeof(int) ); break;
+          default: memset(args,0,4*sizeof(int)); break;
+        }
+        break; 
+        
+       case IO: // IO
+        switch ( c )
+        {
+          case K_RIGHT: iofield++; waitup=1; break;
+          case K_LEFT: iofield--; waitup=1; break;
+          case K_OK: screen=MAIN; break; 
+          case K_CANCEL: screen=MAIN; break;
+        }
+        iofield %= sizeof(iofields)/sizeof(char*);
+        sarg = (char*)iofields[iofield];
+        args[0] = ipfield;
+        args[1] = ipfield;
+        break;       
+        
+      case POWER: // POWER
+        switch ( c )
+        {
+          case K_RIGHT: powerfield++; waitup=1; break;
+          case K_LEFT: powerfield--; waitup=1; break;
+          case K_UP: power[powerfield % 4] += speed;  break;
+          case K_DOWN: power[powerfield % 4] -= speed;  break;
+          case K_OK: screen=MAIN;  break; 
+          case K_CANCEL: screen=MAIN;  break;
+        }
+        powerfield %= 4;
+        args[1] = powerfield;
+        sarg = (char*)powerfields[powerfield];
+        args[0] = power[powerfield];
+        break;     
+
+
+      case HOMING: // Homing screen
+        switch ( c )
+        {
+          case K_CANCEL: screen=MAIN; break;
+        }
+        args[0]++;
+        break;     
+        
+      default: screen = MAIN; break;    
+    }  
+    dsp.ShowScreen(screens[screen], args, sarg);
+  }
+  
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosMenu/LaosMenu.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,75 @@
+/**
+ * LaosMenu.h
+ * Simple menu system
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ @code 
+ --code--
+ @endcode
+ */
+#ifndef _LAOSMENU_H_
+#define _LAOSMENU_H_
+
+#include "global.h"
+#include "LaosDisplay.h"
+
+
+    /** Menu system
+      * Create server based on config file. 
+      *
+      * Example:
+      * @code 
+      * LaosMenu menu();
+      * menu.Handle();
+      * @endcode
+      */
+class LaosMenu {
+public:
+    /** Make new LaosMenu object. 
+      */
+ // LaosMenu(const LaosDisplay& disp);
+  LaosMenu();
+  ~LaosMenu();
+
+/** Handle the menu system
+  * Reads inputs, displays screen
+  */ 
+  void Handle();
+  
+  int x,y,z;
+
+private:
+  // LaosDisplay *display;
+  int args[5];
+  unsigned char waitup, timeout;
+  char *sarg;
+  int speed;
+  
+  // menu states
+  unsigned char screen, prevscreen, menu;
+  unsigned char ipfield, iofield;
+  unsigned char powerfield, power[4];
+  LaosDisplay dsp;
+  
+};
+
+ 
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosMotion/LaosMotion.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,285 @@
+/**
+ * LaosMotion.cpp
+ * Motion Controll functions for Laos system
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 
+ *
+ */
+#include "LaosMotion.h"
+
+  
+// status leds
+extern DigitalOut led1,led2,led3,led4;
+
+// Inputs;
+DigitalIn xhome(p8);
+DigitalIn yhome(p17);
+DigitalIn zmin(p15);
+DigitalIn zmax(p16);
+
+// motors
+DigitalOut enable(p7);
+DigitalOut xdir(p23);
+DigitalOut xstep(p24);
+DigitalOut ydir(p25);
+DigitalOut ystep(p26);
+DigitalOut zdir(p27);
+DigitalOut zstep(p28);
+
+// laser
+
+// DigitalOut laser(p22);       // O1: PWM (Yellow)
+PwmOut pwm(p22);
+DigitalOut laser_enable(p21);   // O2: enable laser
+DigitalOut o3(p6);              // 03: NC
+DigitalOut laser(p5);           // O4: LaserON (White)
+
+
+// Analog in/out (cover sensor) + NC
+DigitalIn cover(p19);
+
+// globals
+Ticker ticker;  // Timer
+int ctr;
+
+int step, prevcommand, command;
+volatile int state, laseron;
+
+// Besenham variables
+int x0,y0,x1,y1,z0,z1;  // positions: 0=current, 1=new
+int dx, sx; // step
+int dy, sy;  // delta
+int err, e2; // error
+
+
+#define LASEROFF 1
+#define LASERON 0
+
+#define LOW_SPEED 400
+#define HIGH_SPEED 90
+
+
+/**
+*** ticker: implement timer ticker, step if required
+**/
+void tick() 
+{
+  ctr++;
+  // Control X,Y: line tracker
+  switch ( state )
+  {
+    case 0: // idle (make sure laser is off)
+      laser=LASEROFF;
+      break;
+    case 1: // init
+      dx = abs(x1-x0);
+      sx = x0<x1 ? 1 : -1;
+      dy = abs(y1-y0);
+      sy = y0<y1 ? 1 : -1; 
+      err = (dx>dy ? dx : -dy)/2;
+      xdir = sx > 0;
+      ydir = sy > 0;
+      if ( laseron )
+        laser = LASERON;
+      else
+        laser = LASEROFF;
+      state++;
+      break;
+    case 2: // moving
+      if (x0==x1 && y0==y1) 
+        state = 0;
+      else
+      {
+        e2 = err;
+        if (e2 >-dx) { err -= dy; x0 += sx; xstep = 1;}
+        if (e2 < dy) { err += dx; y0 += sy; ystep = 1;}
+      }
+      break;
+  }
+  // Controll Z: tracking controller (independent of XY motion, not queued)
+  if ( z1 != z0 ) 
+  {
+    zdir = z1 > z0;
+    wait_us(5);
+    zstep= 1;
+    if ( z1 > z0 ) z0++;
+    else z0--;
+  }
+  
+  if ( xstep == 1 || ystep == 1 || zstep == 1 )
+  {
+    wait_us(5);
+    xstep = ystep = zstep = 0;
+  }
+  
+  // diagnostic info
+  led1 = xdir;
+  led2 = ydir;
+  led3 = laseron;
+  led4 = ctr & 4096;
+} // ticker
+
+
+/**
+*** LaosMotion() Constructor
+*** Make new motion object
+**/
+LaosMotion::LaosMotion()
+{
+  reset();
+  laser=LASEROFF;
+  pwm.period(0.0005);
+  pwm = 0.5;
+  //start.mode(PullUp);
+  xhome.mode(PullUp);
+  yhome.mode(PullUp);
+  isHome = false;
+  ticker.attach_us(&tick, HIGH_SPEED); // the address of the function to be attached (flip) and the interval (microseconds)
+}
+
+/**
+***Destructor
+**/
+LaosMotion::~LaosMotion()
+{
+
+}
+
+/**
+*** reset()
+*** reset the state
+**/
+void LaosMotion::reset()
+{
+  step = prevcommand = command = state = laseron = xstep = xdir = ystep = ydir = zstep = zdir = 0;
+  laser=LASEROFF;
+}
+
+
+
+/**
+*** ready()
+*** ready to receive new commands 
+**/
+int LaosMotion::ready()
+{
+  return state == 0;
+}
+
+/**
+*** write()
+*** Write command to motion controller 
+**/
+void LaosMotion::write(int i)
+{
+ // printf("m:%d %d %d %d\n", state, step, i, command);
+  if ( step == 0 )
+  {
+    prevcommand = command;
+    command = i;
+    step++;
+  }
+  else
+  { 
+     switch( command )
+     {
+          case 0: // move x,y (laser off)
+          case 1: // line x,y (laser on)
+            switch ( step )
+            {
+              case 1: x1 = i; break;
+              case 2: 
+                y1 = i;
+                if ( prevcommand != command )
+                 ticker.attach_us(&tick, (command ? LOW_SPEED : HIGH_SPEED)); // the address of the function to be attached (flip) and the interval (microseconds)
+                laseron = (command == 1); state = 1; step = 0;
+                break;
+            } 
+            break;
+          case 2: // move z 
+            switch(step)
+            {
+              case 1: z1 = i; step = 0; break;
+            }
+          case 3: // set t (1/v)
+          switch(step)
+          {
+            case 1: ticker.attach_us(&tick, i); step=0; break;
+          }
+         case 4: // set x,y,z absolute
+           switch ( step )
+            {
+              case 1: x0 = i; break;
+              case 2: y0 = i; break;
+              case 3: z0=z1 = i; step=0; break;
+            }
+         case 5: // nop
+           step=0;
+           break;
+         default: // I do not understand: stop motion
+            state = 0;
+            step = 0;
+          break;
+    }
+    if ( step ) step++;
+  } 
+}
+
+
+/**
+*** Return true if start button is pressed
+**/
+bool LaosMotion::isStart()
+{
+  return cover;
+}
+
+
+/**
+*** Home the axis, stop when button is pressed
+**/
+void LaosMotion::home()
+{
+  int i=0;
+  xdir = 0;
+  ydir = 0;
+  zdir = 0;
+  led1 = 0;
+  isHome = false;
+  while ( 1 )
+  {
+    xstep = ystep = 0;
+    wait(0.0001);
+    xstep = xhome;
+    ystep = yhome;
+    wait(0.0001);
+    
+    led2 = !xhome;
+    led3 = !yhome;
+    led4 = ((i++) & 0x10000);
+    if ( (!xhome) && (!yhome) ) return;
+ //   if ( i > 2000 && !isStart()  ) return;  // debounce, and quit if key pressed again
+  }
+  isHome = true;
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosMotion/LaosMotion.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,54 @@
+/**
+ * LaosMotion.cpp
+ * Motion Controll functions for Laos system
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 
+ *
+ */
+#ifndef _LAOSMOTION_H_
+#define _LAOSMOTION_H_
+#include "global.h"
+
+    /** Motion Controll system
+      *
+      * Example:
+      * @code 
+      * @endcode
+      */
+class LaosMotion {
+public:
+    /** Make new LaosMotion object. 
+      * Installs ticker
+      */
+  LaosMotion();
+  ~LaosMotion();
+  void write(int i); // write command word to motion controller
+  int ready();
+  void reset();
+  void home();
+  bool isStart();
+  bool isHome;
+private:
+  
+};
+
+ 
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosServer/EthConfig.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,134 @@
+/*
+ * EthSetup.cpp
+ * Setup ethernet interface, based on config file
+ * Read IP, Gateway, DNS and port for server.
+ * if IP is not defined, or dhcp is set, use dhcp for Ethernet
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "EthConfig.h"
+
+// Ethernet connection status inputs (from phy) and outputs (to leds)
+#define ETH_LINK (1<<25)
+#define ETH_SPEED (1<<26)
+PortIn eth_conn(Port1, ETH_LINK | ETH_SPEED);   // p25: link, 0=connected, 1=NC, p26: speed, 0=100mbit, 1=10mbit
+
+IPInfo ipInfo;
+
+/**
+*** Return Speed status, true==100mbps
+**/
+bool EthSpeed(void)
+{
+  int s = eth_conn.read();
+  return !(s & ETH_SPEED) && !(s & ETH_LINK);
+}
+
+/**
+*** Return Link status, true==connected
+**/
+bool EthLink(void)
+{
+  int s = eth_conn.read();
+  return !(s & ETH_LINK);
+}
+
+      
+
+/**
+*** Return a IpAddress, from a string in the format: ppp.qqq.rrr.sss
+**/
+IpAddr IpParse(char *a) 
+{
+    int n = 0, j, i[4];
+    char c[4];
+
+    i[0] = i[1] = i[2] = i[3] =0;
+    for (n=0; n<4; n++) {
+        while (*a && (*a < '0' || *a > '9'))
+            a++;
+        j = 0;
+        while (*a && *a >= '0' && *a <= '9') 
+        {
+            if ( j<3 )
+                c[j++] = *a;
+            a++;
+        }
+        c[j] = 0;
+        i[n] = atoi(c);
+    }
+    return IpAddr(i[0], i[1], i[2], i[3]);
+}
+
+
+/**
+*** EthConfig
+**/
+EthernetNetIf * EthConfig(char *name, int *port)
+ {
+    char val[32];
+    int dhcp=0;
+    EthernetNetIf *eth;
+    IpAddr ip, mask, gw, dns;
+    printf("\r\nOpen config file: \r\n");
+    ConfigFile cfg(name);
+    if ( !cfg.IsOpen() ) 
+    {
+      printf("File does not exists. Using defaults\n");
+    }
+    cfg.Value("ip", val, sizeof(val), "192.168.12.10");
+    printf("ip: '%s'\n\r", val);
+    ip = IpParse(val);
+
+    cfg.Value("netmask", val, sizeof(val), "255.255.255.0");
+    printf("netmask: '%s'\n\r", val);
+    mask = IpParse(val);
+
+    cfg.Value("gateway", val, sizeof(val), "192.168.12.254");
+    printf("gateway: '%s'\n\r", val);
+    gw = IpParse(val);
+
+    cfg.Value("dns", val, sizeof(val), "192.168.12.254");
+    printf("dns: '%s'\n\r", val);
+    dns = IpParse(val);
+
+    cfg.Value("port", port, 4000);
+    printf("port: '%d'\n\r", *port);
+    cfg.Value("dhcp", &dhcp, dhcp);
+    printf("dhcp: '%d'\n\r", dhcp);
+    if ( dhcp )
+        eth = new EthernetNetIf();
+    else
+        eth = new EthernetNetIf(ip, mask, gw, dns);
+
+    printf("Setup...\n");
+    if ( eth->setup() == ETH_TIMEOUT ) 
+    {
+        printf("Timeout!\n");
+    }
+
+    IpAddr myip = eth->getIp();
+    ipInfo.ip[0] = myip[0];
+    ipInfo.ip[1] = myip[1];
+    ipInfo.ip[2] = myip[2];
+    ipInfo.ip[3] = myip[3];
+    
+    printf("mbed IP Address is %d.%d.%d.%d\r\n", myip[0], myip[1], myip[2], myip[3]);
+    return eth;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosServer/EthConfig.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,38 @@
+/*
+ * EthSetup.cpp
+ * Setup ethernet interface, based on config file
+ * Read IP, Gateway, DNS and port for server.
+ * if IP is not defined, or dhcp is set, use dhcp for Ethernet
+ * 
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+#ifndef _ETHCONFIG_H_
+#define _ETHCONFIG_H_
+#include "global.h"
+#include "EthernetNetIf.h"
+#include "TCPSocket.h"
+#include "ConfigFile.h"
+
+IpAddr IpParse(char *a);
+EthernetNetIf * EthConfig(char *name, int *port);
+bool EthSpeed(void);
+bool EthLink(void);
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosServer/LaosServer.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,152 @@
+/*
+ * LaosServer.cpp
+ * Simple TCP/IP server
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+#include "LaosServer.h"
+
+// Destroy the server
+LaosServer::~LaosServer() 
+{
+
+}
+
+
+// Make new server
+LaosServer::LaosServer(int port) 
+{
+// Set the callbacks for Listening
+  ListeningSock.setOnEvent(this, &LaosServer::onListeningTCPSocketEvent); 
+  
+  // bind and listen on TCP
+  err=ListeningSock.bind(Host(IpAddr(),port));
+  printf("Binding..\r\n");
+  if(err)
+  {
+   //Deal with that error...
+    printf("Binding Error\n");
+  }
+   err=ListeningSock.listen(); // Starts listening
+   printf("Listening...\r\n");
+   if(err)
+   {
+    printf("Listening Error\r\n");
+   }
+   pConnectedSock = NULL;
+}
+
+// Read value
+int LaosServer::read()
+{
+  char buf;
+  if ( pConnectedSock != NULL )
+  {
+     int len = pConnectedSock->recv(&buf, 1);
+     if ( len )
+       return buf;
+   }
+   else
+     return -2;
+  return -1;
+}
+
+// Write int value
+void LaosServer::write(int i)
+{
+
+}
+
+
+
+// Connected socket
+void LaosServer::onConnectedTCPSocketEvent(TCPSocketEvent e)
+{
+   switch(e)
+    {
+    case TCPSOCKET_CONNECTED:
+        printf("TCP Socket Connected\r\n");
+        break;
+    case TCPSOCKET_WRITEABLE:
+      //Can now write some data...
+        printf("TCP Socket Writable\r\n");
+        break;
+    case TCPSOCKET_READABLE:
+      //Can now read dome data...
+        //printf("TCP Socket Readable\r\n");
+       // Read in any available data into the buffer
+       // char buff[128];
+      // while ( int len = pConnectedSock->recv(buff, 128) ) {
+       // And send straight back out again
+        //   pConnectedSock->send(buff, len);
+        //   buff[len]=0; // make terminater
+          // printf("Received&Wrote:%s\r\n",buff);
+       //}
+        //int len = pConnectedSock->recv(buff, 10);
+       //printf("R%d\n", len);
+       break;
+    case TCPSOCKET_CONTIMEOUT:
+        printf("TCP Socket Timeout\r\n");
+        break;
+    case TCPSOCKET_CONRST:
+        printf("TCP Socket CONRST\r\n");
+        break;
+    case TCPSOCKET_CONABRT:
+        printf("TCP Socket CONABRT\r\n");
+        break;
+    case TCPSOCKET_ERROR:
+        printf("TCP Socket Error\r\n");
+        break;
+    case TCPSOCKET_DISCONNECTED:
+    //Close socket...
+        printf("TCP Socket Disconnected\r\n");        
+        pConnectedSock->close();
+        pConnectedSock = NULL;
+        break;
+    default:
+        printf("DEFAULT\r\n"); 
+      }
+}
+
+// Listening socket
+void LaosServer::onListeningTCPSocketEvent(TCPSocketEvent e)
+{
+    switch(e)
+    {
+    case TCPSOCKET_ACCEPT:
+        printf("Listening: TCP Socket Accepted\r\n");
+        // Accepts connection from client and gets connected socket.   
+        err=ListeningSock.accept(&client, &pConnectedSock);
+        if (err) {
+            printf("onListeningTcpSocketEvent : Could not accept connection.\r\n");
+            return; //Error in accept, discard connection
+        }
+        // Setup the new socket events
+        pConnectedSock->setOnEvent(this, &LaosServer::onConnectedTCPSocketEvent);
+        // We can find out from where the connection is coming by looking at the
+        // Host parameter of the accept() method
+        IpAddr clientIp = client.getIp();
+        printf("Listening: Incoming TCP connection from %d.%d.%d.%d\r\n", 
+           clientIp[0], clientIp[1], clientIp[2], clientIp[3]);
+       break;
+    default:
+        printf("Listening socket: DEFAULT\r\n"); 
+     };
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LaosServer/LaosServer.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,81 @@
+/**
+ * LaosServer.cpp
+ * Simple TCP/IP server
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Sends and Receives integers via TCP/IP
+ *
+ @code 
+ --code--
+ 
+ @endcode
+ */
+
+#ifndef _LAOSSERVER_H_
+#define _LAOSSERVER_H_
+
+#include "global.h"
+#include "EthernetNetIf.h"
+#include "TCPSocket.h"
+
+
+    /** Simple TCP/IP Server
+      * Create server based on config file. 
+      *
+      * Example:
+      * @code 
+      * LaosServer srv("config.txt");
+      * int i = srv.read();
+      * srv.write(i);
+      * @endcode
+      */
+class LaosServer {
+public:
+    /** Make new LaosServer object. Open config file.
+      * Note: the file handle is kept open during the lifetime of this object.
+      * To close the file: destroy this ConfigFile object!
+      * @param file Filename of the configuration file.
+      */
+    LaosServer(int port);
+
+    ~LaosServer();
+
+/** Read value. If socket is not open, this blocks
+  * @return integer value, read from socket
+  */ 
+    int read();
+
+/** Write Integer value. If socket is not open, or cannot write: block
+  * @param i Integer 
+  * @return "true" if the key is found "false" is key is not found (default value is returned)
+  */ 
+    void write(int i);
+    
+private:
+    int port;
+    TCPSocket ListeningSock;
+    TCPSocket* pConnectedSock; 
+    Host client;
+    TCPSocketErr err;
+    void onConnectedTCPSocketEvent(TCPSocketEvent e);
+    void onListeningTCPSocketEvent(TCPSocketEvent e);
+    
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/global.h	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,35 @@
+/*
+ * global.h
+ * Laos Controller, global header file, included in all other files
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+#ifndef _GLOBAL_H_
+#define _GLOBAL_H_
+ 
+#include "mbed.h"
+#include "LaosDisplay.h"
+ 
+typedef struct 
+{
+  int ip[4], gw[4], nm[4], dns[4], port;  
+} IPInfo;
+extern IPInfo ipInfo; 
+ 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,223 @@
+/*
+ * main.cpp
+ * Laos Controller, main function
+ *
+ * Copyright (c) 2011 Peter Brier
+ *
+ *   This file is part of the LaOS project (see: http://wiki.protospace.nl/index.php/LaOS)
+ *
+ *   LaOS is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   LaOS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with LaOS.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * This program consists of a few parts:
+ *
+ * ConfigFile   Read configuration files
+ * EthConfig    Initialize an ethernet stack, based on a configuration file (includes link status monitoring)
+ * LaosDisplay  User interface functions (read keys, display text and menus on LCD)
+ * LaosMenu     User interface stuctures (menu navigation)
+ * LaosServer   TCP/IP server, accept connections read/write data
+ * LaosMotion   Motion control functions (X,Y,Z motion, homing)
+ * LaosIO       Input/Output functions
+ * LaosFile     File based jobs (read/write/delete)
+ *
+ * Program functions:
+ * 1) Read config file
+ * 2) Enable TCP/IP stack (Fixed ip or DHCP)
+ * 3) Instantiate tcp/ip port and accept connections
+ * 4) Show menus, peform user actions
+ * 5) Controll laser
+ * 6) Controll motion
+ * 7) Set and read IO, check status (e.g. interlocks)
+ *
+ */
+#include "global.h"
+#include "ConfigFile.h"
+#include "EthConfig.h"
+#include "LaosServer.h"
+#include "LaosMenu.h"
+#include "LaosMotion.h"
+#include "SDFileSystem.h"
+
+//
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+
+// Status and communication
+DigitalOut eth_link(p29); // green
+DigitalOut eth_speed(p30); // yellow
+EthernetNetIf *eth; // Ethernet, tcp/ip
+
+// Filesystems
+LocalFileSystem local("local");   //File System
+// SparkFun board  SDFileSystem sd(p5, p6, p7, p8, "sd");
+SDFileSystem sd(p11, p12, p13, p14, "sd");
+
+// Laos objects
+LaosDisplay *dsp;
+LaosMenu *mnu;
+LaosServer *srv;
+LaosMotion *mot;
+int port;
+
+// Externs
+extern int x0,y0,z0;
+
+// Protos
+void ReadFile(void);
+
+
+/**
+*** Main function
+**/
+int main() 
+{
+  printf("BOOT...\n");  
+  eth_speed = 1;
+  
+  printf("MENU...\n"); 
+  mnu = new LaosMenu();
+  eth_speed=0;
+  
+  printf("CONFIG...\n");
+  eth = EthConfig("/local/config.txt", &port);
+  eth_speed=1;
+      
+  printf("SERVER...\n");
+  srv = new LaosServer(port);
+  
+  printf("MOTION...\n"); 
+  mot = new LaosMotion();
+  
+  printf("RUN...\n");
+  
+  // Wait for key, and then home
+  printf("WAIT FOR HOME KEY...\n");
+  
+  // Start homing
+  while ( !mot->isStart() );
+  mot->home();
+  // if ( !mot->isHome ) exit(1);
+  printf("HOME DONE.\n");
+  
+  
+  while(1) 
+  {
+    // Get file
+    printf("GET FILE...\n");
+  
+    led1=led2=led3=led4=0;
+    ReadFile();
+    mot->reset();
+    printf("RUN FILE...\n");
+    // Read from BIN file
+    FILE *in = fopen("/sd/1.bin", "rb");
+    int v;
+    while (!feof(in))
+    { 
+      fread(&v, sizeof(v),1,in);   
+      while (! mot->ready() );
+      mot->write(v);  
+    }
+    fclose(in);
+    // done
+    printf("DONE!...\n");
+  }
+  
+  exit(2);
+  
+  
+  // Read from ASCII file
+  /* in = fopen("/sd/3.txt", "r");
+  while (!feof(in))
+  {    
+    fscanf(in, "%d", &v);
+    while (! mot->ready() );
+    mot->write(v);  
+  }
+  fclose(in);
+  */
+  
+}
+
+
+/**
+*** Read file from network and save on SDcard
+**/
+void ReadFile(void)
+{
+  unsigned short int i=0,j=0,done=0,connected=0;
+  int c, sign=1;
+  Timer tmr;
+  tmr.start();
+  FILE *out = fopen("/sd/1.bin", "wb");
+  char str[16];
+  
+  while(!done)
+  {
+    Net::poll();
+    if(tmr.read() > 0.01) // sec
+    {
+      mnu->x = x0;
+      mnu->y = y0;
+      mnu->Handle();
+      if ( mnu->x != x0 || mnu->y != y0 )
+      {
+        mot->write(0); mot->write(mnu->x); mot->write(mnu->y);
+        while(!mot->ready());
+      }
+      
+      tmr.reset();
+      if ( i++ & ( EthSpeed() ? 0x400 : 0x800) )
+        eth_speed = !eth_speed; //Show that we are alive
+      eth_link = EthLink();
+    } 
+    c =  srv->read();
+    if ( c != -2 && !connected) 
+    {
+      connected=1;
+      printf("Connected...");
+    }
+    switch(c)
+    {
+      case -2: if ( connected ) done=1; break;
+      case '0': case '1': case '2':  case '3':  case '4': 
+      case '5': case '6': case '7':  case '8':  case '9':  
+        if ( j < 16) 
+          str[j++] = (char)c;
+        break;
+      case '-': sign = -1; break;
+      case ' ': case '\t': case '\r': case '\n':
+        if ( j )
+        {
+          int val=0, d=1;
+          while(j) 
+          {
+            if ( str[j-1] == '-' ) 
+              d *= -1;
+            else
+              val += (str[j-1]-'0') * d;
+            d *= 10;
+            j--;
+          }
+          val *= sign;
+          sign = 1;
+          fwrite(&val, sizeof(val), 1, out); 
+        }
+        break;
+    } // Switch
+  } // while true
+  fclose(out);
+} // read file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Aug 11 09:33:15 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1