RTno is communicating library and framework which allows you to make your embedded device capable of communicating with RT-middleware world. RT-middleware is a platform software to realize Robotic system. In RTM, robots are developed by constructing robotics technologies\' elements (components) named RT-component. Therefore, the RTno helps you to create your own RT-component with your mbed and arduino. To know how to use your RTno device, visit here: http://ysuga.net/robot_e/rtm_e/rtc_e/1065?lang=en To know about RT-middleware and RT-component, visit http://www.openrtm.org

Dependencies:   EthernetNetIf

Dependents:   RTnoV3_LED RTnoV3_Template RTnoV3_ADC RTnoV3_Timer ... more

Files at this revision

API Documentation at this revision

Comitter:
ysuga
Date:
Thu Feb 09 02:33:10 2012 +0000
Commit message:
RTno Version 3: RTno is a software library and tool to connect embedded devices like arduino and mbed to RT-middleware world.

Changed in this revision

BasicDataType.h Show annotated file Show diff for this revision Revisions of this file
EtherTcp.cpp Show annotated file Show diff for this revision Revisions of this file
EtherTcp.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
ExecutionContext.cpp Show annotated file Show diff for this revision Revisions of this file
ExecutionContext.h Show annotated file Show diff for this revision Revisions of this file
InPort.h Show annotated file Show diff for this revision Revisions of this file
NullBuffer.cpp Show annotated file Show diff for this revision Revisions of this file
NullBuffer.h Show annotated file Show diff for this revision Revisions of this file
OutPort.h Show annotated file Show diff for this revision Revisions of this file
Packet.h Show annotated file Show diff for this revision Revisions of this file
PortBase.cpp Show annotated file Show diff for this revision Revisions of this file
PortBase.h Show annotated file Show diff for this revision Revisions of this file
PortBuffer.h Show annotated file Show diff for this revision Revisions of this file
ProxySyncEC.cpp Show annotated file Show diff for this revision Revisions of this file
ProxySyncEC.h Show annotated file Show diff for this revision Revisions of this file
RTno.cpp Show annotated file Show diff for this revision Revisions of this file
RTno.h Show annotated file Show diff for this revision Revisions of this file
RTnoProfile.cpp Show annotated file Show diff for this revision Revisions of this file
RTnoProfile.h Show annotated file Show diff for this revision Revisions of this file
Sequence.h Show annotated file Show diff for this revision Revisions of this file
SerialDevice.h Show annotated file Show diff for this revision Revisions of this file
Timer1ExecutionContext.cpp Show annotated file Show diff for this revision Revisions of this file
Timer1ExecutionContext.h Show annotated file Show diff for this revision Revisions of this file
Transport.cpp Show annotated file Show diff for this revision Revisions of this file
Transport.h Show annotated file Show diff for this revision Revisions of this file
TypeCode.cpp Show annotated file Show diff for this revision Revisions of this file
TypeCode.h Show annotated file Show diff for this revision Revisions of this file
UART.cpp Show annotated file Show diff for this revision Revisions of this file
UART.h Show annotated file Show diff for this revision Revisions of this file
rtcconf.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9fac71a0bff3 BasicDataType.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BasicDataType.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,88 @@
+/*******************************************
+ * BasicDataType.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+
+#ifndef BASIC_DATA_TYPE_HEADER_INCLUDED
+#define BASIC_DATA_TYPE_HEADER_INCLUDED
+
+#include <stdint.h>
+#include "Sequence.h"
+
+#pragma pack(1)
+struct TimedBoolean  {
+  static const char typeCode = 'b';
+  char data;
+};
+
+struct TimedChar {
+  static const char typeCode = 'c';
+  char data;
+};
+
+struct TimedOctet {
+  static const char typeCode = 'o';
+  int8_t data;
+};
+
+struct TimedShort {
+  static const char typeCode = 's';
+  int16_t data;
+
+};
+
+struct TimedLong {
+  static const char typeCode = 'l';
+  int32_t data;
+};
+
+struct TimedDouble {
+  static const char typeCode = 'd';
+  double data;
+};
+
+struct TimedFloat {
+  static const char typeCode = 'f';
+  float data;
+};
+
+
+struct TimedOctetSeq {
+  static const char typeCode = 'O';
+  Sequence<int8_t> data;
+};
+
+struct TimedCharSeq {
+  static const char typeCode = 'C';
+  Sequence<char> data;
+};
+
+struct TimedBooleanSeq {
+  static const char typeCode = 'B';
+  Sequence<char> data;
+};
+
+struct TimedShortSeq {
+  static const char typeCode = 'S';
+  Sequence<int16_t> data;
+};
+
+struct TimedLongSeq {
+  static const char typeCode = 'L';
+  Sequence<int32_t> data;
+};
+
+struct TimedFloatSeq {
+  static const char typeCode = 'F';
+  Sequence<float> data;
+};
+
+struct TimedDoubleSeq {
+  static const char typeCode = 'D';
+  Sequence<double> data;
+};
+
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 EtherTcp.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EtherTcp.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,136 @@
+#include "mbed.h"
+#include "EtherTcp.h"
+#include "EthernetNetIf.h"
+#include "TCPSocket.h"
+
+#include "ip_addr.h"
+/**
+#include <../SPI/SPI.h>
+#include <../Ethernet/Ethernet.h>
+
+static EthernetServer *m_pServer;
+static EthernetClient *m_pClient;
+*/
+static EthernetNetIf* m_pInterface;
+static TCPSocket* m_pServerSocket;
+static TCPSocket* m_pClientSocket;
+
+
+#define ETCP_RX_BUFFER_SIZE 128
+unsigned char etcp_rx_buffer[ETCP_RX_BUFFER_SIZE];
+int etcp_rx_buffer_pointer_head = 0;
+int etcp_rx_buffer_pointer_tail = 0;
+Host m_Client;
+
+Serial *pSerial;
+
+/**
+ * Push data to ring buffer.
+ */
+int etcp_rx_buffer_push(unsigned char c) {
+    etcp_rx_buffer[etcp_rx_buffer_pointer_tail] = c;
+    etcp_rx_buffer_pointer_tail++;
+    if(etcp_rx_buffer_pointer_tail >= ETCP_RX_BUFFER_SIZE) {
+        etcp_rx_buffer_pointer_tail = 0;
+    }
+    return 0;
+}
+
+/**
+ * Pop data fron ring buffer
+ */
+int etcp_rx_buffer_pop(unsigned char *c) {
+    *c = etcp_rx_buffer[etcp_rx_buffer_pointer_head];
+    etcp_rx_buffer_pointer_head++;
+    if(etcp_rx_buffer_pointer_head >= ETCP_RX_BUFFER_SIZE) {
+        etcp_rx_buffer_pointer_head = 0;
+    }
+    return 0;
+}
+
+int etcp_rx_buffer_get_size() {
+    int size = etcp_rx_buffer_pointer_tail - etcp_rx_buffer_pointer_head;
+    if(size < 0) {
+        size += ETCP_RX_BUFFER_SIZE;
+    }
+    return size;
+}
+
+static void EtherTcp_onClientEvent(TCPSocketEvent e) {
+  switch (e) {
+  // If the socket is readable, do stuff
+  case TCPSOCKET_READABLE:
+    while(1) {
+      char buf;
+      int ret = m_pClientSocket->recv(&buf, 1);
+      if (ret == 0) break;
+      etcp_rx_buffer_push(buf);
+    }
+    
+    break;
+  case TCPSOCKET_CONTIMEOUT:
+  case TCPSOCKET_CONRST:
+  case TCPSOCKET_CONABRT:
+  case TCPSOCKET_ERROR:
+  case TCPSOCKET_DISCONNECTED:
+    delete m_pClientSocket;
+    m_pClientSocket = NULL;
+    break;
+  }
+}
+
+static void EtherTcp_onServerEvent(TCPSocketEvent e) {
+  if(e == TCPSOCKET_ACCEPT ) {
+    if ( m_pServerSocket->accept(&m_Client, &m_pClientSocket) ) {
+      return; //Error in accept, discard connection
+    }
+    
+    m_pClientSocket->setOnEvent(EtherTcp_onClientEvent);
+  }
+}
+
+void EtherTcp_init(uint8_t* mac, uint8_t* ip, 
+           uint8_t* gateway, uint8_t* subnet,
+           uint16_t port) 
+
+{
+  pSerial = new Serial(USBTX, USBRX);
+  m_pInterface = new EthernetNetIf(
+       IpAddr(ip[0], ip[1], ip[2], ip[3]), 
+       IpAddr(subnet[0], subnet[1], subnet[2], subnet[3]),
+       IpAddr(gateway[0], gateway[1], gateway[2], gateway[3]),
+       IpAddr(gateway[0], gateway[1], gateway[2], gateway[3]));    
+  printf("Hello %d %d %d %d\r\n", ip[0], ip[1], ip[2], ip[3]);
+  EthernetErr ethErr = m_pInterface->setup();
+  if (ethErr) {
+    return;
+  }  
+  
+  m_pServerSocket = new TCPSocket();
+  m_pServerSocket->setOnEvent(EtherTcp_onServerEvent);
+  m_pServerSocket->bind(Host(IP_ADDR_ANY, port));
+  m_pServerSocket->listen();
+  SerialDevice_available = EtherTcp_available;
+  SerialDevice_getc = EtherTcp_getc;
+  SerialDevice_putc = EtherTcp_putc;
+}
+
+uint8_t EtherTcp_available()
+{
+  Net::poll();
+  return etcp_rx_buffer_get_size();
+}
+
+
+void EtherTcp_putc(const char c) {
+  if(m_pClientSocket != NULL) {
+    m_pClientSocket->send(&c, 1);
+  }
+}
+
+char EtherTcp_getc()
+{
+  char c;
+  etcp_rx_buffer_pop((unsigned char*)&c);
+  return c;
+}
diff -r 000000000000 -r 9fac71a0bff3 EtherTcp.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EtherTcp.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,14 @@
+#ifndef ETHER_TCP_HEADER_INCLUDED
+#define ETHER_TCP_HEADER_INCLUDED
+
+
+#include <stdint.h>
+#include "SerialDevice.h"
+
+void EtherTcp_init(uint8_t* mac, uint8_t *ip, uint8_t *gateway, uint8_t *subnet, uint16_t port);
+
+void EtherTcp_putc(const char c);
+uint8_t EtherTcp_available();
+char EtherTcp_getc();
+
+#endif // #ifndef ETHER_HEADER_INCLUDED
diff -r 000000000000 -r 9fac71a0bff3 EthernetNetIf.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sherckuith/code/EthernetNetIf/#479ce5546098
diff -r 000000000000 -r 9fac71a0bff3 ExecutionContext.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ExecutionContext.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,87 @@
+#define RTNO_SUBMODULE_DEFINE
+
+#include <stdint.h>
+#include "RTno.h"
+#include "Packet.h"
+
+#include "ExecutionContext.h"
+
+static int8_t m_Type;
+static LifeCycleState m_Condition;
+
+void EC_init(int8_t Type) {
+  m_Type = Type;
+  m_Condition = RTC_STATE_INACTIVE;
+}
+
+int8_t EC_get_type() {
+  return m_Type;
+}
+
+LifeCycleState EC_get_component_state() {
+  return m_Condition;
+}
+
+ReturnValue_t EC_activate_component() {
+  if(m_Condition != RTC_STATE_INACTIVE) {
+    return RTC_PRECONDITION_NOT_MET;
+  }
+  
+  if(RTno::onActivated() == RTC_OK) {
+    m_Condition = RTC_STATE_ACTIVE;
+    return RTC_OK;
+  }
+
+  m_Condition = RTC_STATE_ERROR;
+  return RTC_ERROR;
+}
+
+
+ReturnValue_t EC_deactivate_component() {
+  if(m_Condition != RTC_STATE_ACTIVE) {
+    return RTC_PRECONDITION_NOT_MET;
+  }
+  
+  if(RTno::onDeactivated() == RTC_OK) {
+    m_Condition = RTC_STATE_INACTIVE;
+    return RTC_OK;
+  } else {
+    m_Condition = RTC_STATE_ERROR;
+    return RTC_ERROR;
+  }
+}
+
+ReturnValue_t EC_execute() {
+  if(m_Condition != RTC_STATE_ACTIVE) {
+    return RTC_PRECONDITION_NOT_MET;
+  }
+  
+  if(RTno::onExecute() == RTC_OK) {
+    return RTC_OK;
+  } else {
+    m_Condition = RTC_STATE_ERROR;
+    return RTC_ERROR;
+  }
+}
+
+ReturnValue_t EC_error() {
+  if(m_Condition != RTC_STATE_ERROR) {
+    return RTC_PRECONDITION_NOT_MET;
+  }
+  
+  RTno::onError();
+  return RTC_OK;
+}
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void (*EC_start)();
+void (*EC_resume)();
+void (*EC_suspend)();
+
+#ifdef __cplusplus
+}
+#endif
diff -r 000000000000 -r 9fac71a0bff3 ExecutionContext.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ExecutionContext.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,23 @@
+#ifndef EXECUTION_CONTEXT_HEADER_INCLUDED
+#define EXECUTION_CONTEXT_HEADER_INCLUDED
+
+#include <stdint.h>
+
+extern "C" {
+  typedef int8_t LifeCycleState;
+  typedef int8_t ReturnValue_t;
+  
+  void EC_init(int8_t);
+  LifeCycleState EC_get_component_state();
+  ReturnValue_t EC_activate_component();
+  ReturnValue_t EC_deactivate_component();
+  ReturnValue_t EC_execute();
+  ReturnValue_t EC_error();
+  int8_t EC_get_type();
+  
+  extern void (*EC_start)();
+  extern void (*EC_suspend)();
+  extern void (*EC_resume)();
+}
+
+#endif // #ifndef EXECUTION_CONTEXT_HEADER_INCLDUED
diff -r 000000000000 -r 9fac71a0bff3 InPort.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InPort.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,60 @@
+#ifndef INPORT_HEADER_INCLUDED
+#define INPORT_HEADER_INCLUDED
+
+/*******************************************
+ * InPort.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+
+#include <stdint.h>
+#include "PortBase.h"
+#include "NullBuffer.h"
+#include <string.h>
+#include <stdlib.h>
+
+class InPortBase : public PortBase{
+ private:
+
+ public:
+  InPortBase(char* name, char tCode) {
+    PortBase_init(this, name, tCode, NullBuffer_create());
+  }
+
+ public:
+
+};
+
+template<typename T>
+class InPort : public InPortBase {
+ public:
+  T* m_pData;
+ public:
+ InPort(char* name, T& data) : InPortBase(name, data.typeCode) {
+    m_pData = &data;
+  }
+
+  ~InPort() {}
+ public:
+  uint8_t isNew() {
+    return pPortBuffer->hasNext(pPortBuffer);
+  }
+
+  uint8_t read() {
+    uint8_t dataSize = pPortBuffer->getNextDataSize(pPortBuffer);
+    if(TypeCode_isSequence(m_pData->typeCode)) {
+      ((SequenceBase*)&(m_pData->data))->length(dataSize/TypeCode_getElementSize(m_pData->typeCode));
+      pPortBuffer->pop(pPortBuffer, (int8_t*)((SequenceBase*)&(m_pData->data))->getData(), dataSize);
+    } else {
+    // This code must be okay for little endian system.
+      pPortBuffer->pop(pPortBuffer, (int8_t*)&(m_pData->data), dataSize);
+    }
+    return dataSize;
+  }
+
+};
+
+
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 NullBuffer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NullBuffer.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,72 @@
+#include <stdint.h>
+#include "mbed.h"
+
+#include "NullBuffer.h"
+
+struct NullBuffer_private {
+  int8_t *pData;
+  uint8_t size;
+  uint8_t isUpdated;
+};
+
+void NullBuffer_push(PortBuffer* _this, const int8_t* data, uint8_t size);
+void NullBuffer_pop(PortBuffer* _this, int8_t* dst, uint8_t size);
+uint8_t NullBuffer_getNextDataSize(PortBuffer* _this);
+uint8_t NullBuffer_hasNext(PortBuffer* _this);
+
+
+PortBuffer* NullBuffer_create() 
+{
+  struct NullBuffer_private* privateData = 
+    (struct NullBuffer_private*)malloc(sizeof(struct NullBuffer_private));
+
+  privateData->pData = NULL;
+  privateData->size = 0;
+  privateData->isUpdated = 0;
+  PortBuffer* retval = (PortBuffer*)malloc(sizeof(PortBuffer));
+  retval->push = NullBuffer_push;
+  retval->pop = NullBuffer_pop;
+  retval->getNextDataSize = NullBuffer_getNextDataSize;
+  retval->hasNext = NullBuffer_hasNext;
+  retval->privateData = (void*)privateData;
+  return retval;
+}
+
+void NullBuffer_destroy(PortBuffer* _this) {
+  struct NullBuffer_private* nullBuffer = 
+    (struct NullBuffer_private*)(_this->privateData);
+  free(nullBuffer->pData);
+  free(nullBuffer);
+  free(_this);
+}
+
+void NullBuffer_push(PortBuffer* _this, const int8_t* data, uint8_t size) {
+  struct NullBuffer_private* nullBuffer = 
+    (struct NullBuffer_private*)(_this->privateData);
+  if(size != nullBuffer->size) {
+    free(nullBuffer->pData);
+    nullBuffer->pData = (int8_t*)malloc(size);
+    nullBuffer->size = size;
+  }
+  memcpy(nullBuffer->pData, data, size);
+  nullBuffer->isUpdated = 1;
+}
+
+void NullBuffer_pop(PortBuffer* _this, int8_t* dst, uint8_t size)
+{
+  struct NullBuffer_private* nullBuffer = 
+    (struct NullBuffer_private*)(_this->privateData);
+  if(nullBuffer->size <= size) {
+    memcpy(dst, nullBuffer->pData, nullBuffer->size);
+  }
+  nullBuffer->isUpdated = 0;
+}
+
+uint8_t NullBuffer_getNextDataSize(PortBuffer* _this){
+  return ((struct NullBuffer_private*)(_this->privateData))->size;
+}
+
+uint8_t NullBuffer_hasNext(PortBuffer* _this) {
+  return ((struct NullBuffer_private*)(_this->privateData))->isUpdated;
+}
+
diff -r 000000000000 -r 9fac71a0bff3 NullBuffer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NullBuffer.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,9 @@
+#ifndef NULL_BUFFER_HEADER_INCLUDED
+#define NULL_BUFFER_HEADER_INCLUDED
+
+#include "PortBuffer.h"
+
+PortBuffer* NullBuffer_create();
+void NullBuffer_destroy(PortBuffer* _this);
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 OutPort.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OutPort.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,58 @@
+#ifndef OUTPORT_HEADER_INCLUDED
+#define OUTPORT_HEADER_INCLUDED
+
+/*******************************************
+ * OutPort.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+
+#include <stdint.h>
+#include "PortBase.h"
+#include "PortBuffer.h"
+#include "NullBuffer.h"
+#include "TypeCode.h"
+#include <string.h>
+#include <stdlib.h>
+
+class OutPortBase : public PortBase {
+ private:
+
+ public:
+  OutPortBase(const char* name, char tCode) {
+    PortBase_init(this, name, tCode, NullBuffer_create());
+  }
+
+ public:
+
+};
+
+template<typename T>
+class OutPort : public OutPortBase {
+ private:
+  T* m_pData;
+  
+ public:
+ OutPort(const char* name, T& data) : OutPortBase(name, data.typeCode) {
+    m_pData = &data;
+  }
+  ~OutPort() {}
+
+ public:
+  uint8_t write() {
+    uint8_t size = TypeCode_getElementSize(m_pData->typeCode);
+    if(TypeCode_isSequence(m_pData->typeCode)) {
+      size *= ((SequenceBase*)&(m_pData->data))->length();
+      pPortBuffer->push(pPortBuffer,
+            (int8_t*)((SequenceBase*)&(m_pData->data))->getData(),
+            size);
+    } else {
+      pPortBuffer->push(pPortBuffer, (const int8_t*)&(m_pData->data), size);
+    }
+    return size;
+  }
+};
+
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 Packet.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Packet.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,86 @@
+/*******************************************
+ * Packet.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+
+#ifndef PACKET_HEADER_INCLUDED
+#define PACKET_HEADER_INCLUDED
+
+// Return Values
+#define TIMEOUT 1
+#define DATA_TIMEOUT 2
+#define CHECKSUM_ERROR 3
+
+#define INVALID_PACKET_INTERFACE 65
+#define INVALID_PACKET_DATASIZE  66
+
+// Packet Settings
+#define PACKET_HEADER_SIZE 2
+#define INTERFACE 0
+#define DATA_LENGTH 1
+#define DATA_START_ADDR 2
+
+enum {
+  RTC_STATE_CREATED='C',
+  RTC_STATE_INACTIVE='I',
+  RTC_STATE_ACTIVE='A',
+  RTC_STATE_ERROR='E',
+  RTC_STATE_NONE='N',
+};
+
+
+// Protocol
+// Interface
+#define INITIALIZE 'I'
+#define ACTIVATE 'A'
+#define DEACTIVATE 'D'
+#define EXECUTE 'E'
+#define ONERROR 'C'
+#define RESET 'R'
+#define GET_STATUS 'X'
+#define GET_DATA 'G'
+#define SEND_DATA 'S'
+#define GET_PROFILE 'Z'
+#define GET_CONTEXT 'B'
+#define PACKET_ERROR 'F'
+#define RECEIVE_DATA 'V'
+
+#define ADD_INPORT 'P'
+#define ADD_OUTPORT 'Q'
+
+#define INPORT_ISNEW 'N'
+#define INPORT_READ  'J'
+
+#define RTNO_OK '@'
+#define RTNO_ERROR 'x'
+#define RTNO_NONE '!'
+
+#define OUTPORT_WRITE 'W'
+
+// Communication Settings
+#define PACKET_WAITING_TIME 100 // ms
+#define PACKET_WAITING_DELAY 100 //us
+#define PACKET_WAITING_COUNT (PACKET_WAITING_TIME*1000/PACKET_WAITING_DELAY)
+
+
+#define TYPECODE_TIMED_BOOLEAN 'b'
+#define TYPECODE_TIMED_CHAR 'c'
+#define TYPECODE_TIMED_OCTET 'o'
+
+
+#define TYPECODE_TIMED_LONG 'l'
+#define TYPECODE_TIMED_FLOAT 'f'
+#define TYPECODE_TIMED_DOUBLE 'd'
+
+#define TYPECODE_TIMED_BOOLEAN_SEQ 'B'
+#define TYPECODE_TIMED_CHAR_SEQ 'C'
+#define TYPECODE_TIMED_OCTET_SEQ 'O'
+
+
+#define TYPECODE_TIMED_LONG_SEQ 'L'
+#define TYPECODE_TIMED_FLOAT_SEQ 'F'
+#define TYPECODE_TIMED_DOUBLE_SEQ 'D'
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 PortBase.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortBase.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,30 @@
+/*******************************************
+ * PortBase.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+#define RTNO_SUBMODULE_DEFINE
+
+#include <stdlib.h>
+#include <string.h>
+#include "PortBase.h"
+#include "NullBuffer.h"
+
+PortBase* PortBase_create() {
+  return (PortBase*)malloc(sizeof(PortBase));
+}
+
+void PortBase_init(PortBase* portBase, const char* name, char typeCode, PortBuffer* dataBuffer)
+{
+  portBase->pName = (char*)malloc(strlen(name)+1);
+  strcpy(portBase->pName, name);
+  portBase->typeCode = typeCode;
+  portBase->pPortBuffer = dataBuffer;
+}
+
+void PortBase_destroy(PortBase* pPortBase)
+{
+  free(pPortBase->pName);
+  free(pPortBase);
+}
diff -r 000000000000 -r 9fac71a0bff3 PortBase.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortBase.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,34 @@
+/*******************************************
+ * PortBase.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+
+#ifndef PORT_BASE_HEADER_INCLUDED
+#define PORT_BASE_HEADER_INCLUDED
+
+#include <stdint.h>
+#include "BasicDataType.h"
+#include "PortBuffer.h"
+
+typedef struct _PortBase {
+  unsigned char portBuffer;
+  void* pData;
+  char* pName;
+  char typeCode;
+  PortBuffer *pPortBuffer;
+} PortBase;
+
+PortBase* PortBase_create();
+void PortBase_init(PortBase* pPortBase, const char* name, char typeCode, PortBuffer* dataBuffer);
+void PortBase_destroy(PortBase* pPortBase);
+
+uint8_t PortBase_isSequence(PortBase* pPortBase);
+uint8_t PortBase_getLength(PortBase* pPortBase);
+void PortBase_setLength(PortBase* pPortBase, uint8_t length);
+PortBuffer* PortBase_getBuffer(PortBase* pPortBase);
+
+
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 PortBuffer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortBuffer.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,28 @@
+#ifndef PORT_BUFFER_HEADER_INCLUDED
+#define PORT_BUFFER_HEADER_INCLUDED
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+  struct _PortBuffer;
+
+  typedef struct _PortBuffer PortBuffer;
+  struct _PortBuffer {
+    void(*push)(PortBuffer* _this, const int8_t* data, uint8_t size);
+    void(*pop)(PortBuffer* _this, int8_t* data, uint8_t size);
+    uint8_t(*getNextDataSize)(PortBuffer* _this);
+    uint8_t(*hasNext)(PortBuffer *_this);
+    void* privateData;
+  };
+  
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif // #ifndef PORT_BUFFER_HEADER_INCLUDED
diff -r 000000000000 -r 9fac71a0bff3 ProxySyncEC.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProxySyncEC.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,14 @@
+#include "ProxySyncEC.h"
+
+void ProxySyncEC_start() {}
+void ProxySyncEC_resume() {}
+void ProxySyncEC_suspend() {}
+
+
+void ProxySyncEC_init() {
+  EC_init(0x21);
+  
+  EC_start = ProxySyncEC_start;
+  EC_suspend = ProxySyncEC_suspend;
+  EC_resume = ProxySyncEC_resume;
+}
diff -r 000000000000 -r 9fac71a0bff3 ProxySyncEC.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProxySyncEC.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,23 @@
+#ifndef PROXY_SYNC_EXECUTION_CONTEXT
+#define PROXY_SYNC_EXECUTION_CONTEXT
+#include "ExecutionContext.h"
+void ProxySyncEC_init();
+
+#if 0
+
+namespace RTC {
+  class ProxySyncEC : public ExecutionContext {
+  private:
+    
+  public:
+  ProxySyncEC() : ExecutionContext() {};
+    virtual ~ProxySyncEC(){};
+    
+    void start(){};
+    void suspend(){};
+    void resume(){};
+  };
+};
+#endif
+
+#endif //#ifndef PROXY_SYNC_EXECUTION_CONTEXT
diff -r 000000000000 -r 9fac71a0bff3 RTno.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTno.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,245 @@
+/*******************************************
+ * RTno.cpp
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+#define RTNO_SUBMODULE_DEFINE
+#include <stdint.h>
+#include "mbed.h"
+
+#include "RTno.h"
+#include "Packet.h"
+
+#include "Transport.h"
+//#include "UART.h"
+#include "RTnoProfile.h"
+
+using namespace RTno;
+
+// global variables
+// module private variables.
+#define PRIVATE static
+
+// static value declaration.
+void(*SerialDevice_putc)(const char c);
+uint8_t(*SerialDevice_available)();
+char(*SerialDevice_getc)();
+
+PRIVATE int8_t m_pPacketBuffer[PACKET_BUFFER_SIZE];
+
+/*
+ * Send Profile Data
+ */
+PRIVATE void _SendProfile();
+
+/**
+ * Packet Handler in Error State.
+ */
+PRIVATE void _PacketHandlerOnError();
+
+/**
+ * Packet Handler in Inactive State.
+ */
+PRIVATE void _PacketHandlerOnInactive();
+
+/**
+ * Packet Handler in Active State.
+ */
+PRIVATE void _PacketHandlerOnActive();
+
+void EC_setup(exec_cxt_str& exec_cxt);
+void Connection_setup(config_str& conf);
+
+/**
+ * Arduino Setup Routine.
+ * This function is called when arduino device is turned on.
+ */
+void setup() {
+  RTnoProfile_init();
+  // This function must be called first.
+  exec_cxt_str* exec_cxt = (exec_cxt_str*)malloc(sizeof(exec_cxt_str));
+  config_str* conf = (config_str*)malloc(sizeof(config_str));
+  rtcconf(*conf, *exec_cxt);
+  if(onInitialize() == RTC_OK) {
+    EC_setup(*exec_cxt);
+    Connection_setup(*conf);
+    free(exec_cxt);
+    free(conf);
+    Transport_init();
+    EC_start();
+  }
+}
+
+
+/**
+ * Arduino Loop routine.
+ * This function is repeadedly called when arduino is turned on.
+ */
+void loop() {
+  int8_t ret;
+  ret = Transport_ReceivePacket(m_pPacketBuffer);
+  if(ret < 0) { // Timeout Error or Checksum Error
+    Transport_SendPacket(PACKET_ERROR, 1, &ret);
+  } else if (ret == 0) {
+  } else if (ret > 0) { // Packet is successfully received
+    if (m_pPacketBuffer[INTERFACE] == GET_PROFILE) {
+      _SendProfile();
+    } else if(m_pPacketBuffer[INTERFACE] == GET_STATUS) {
+      int8_t state = EC_get_component_state();
+      Transport_SendPacket(GET_STATUS, 1, &state);
+    } else if(m_pPacketBuffer[INTERFACE] == GET_CONTEXT) {
+      int8_t type = EC_get_type();
+      Transport_SendPacket(GET_CONTEXT, 1, &type);
+    } else {
+      switch(EC_get_component_state()) {
+      case RTC_STATE_ERROR:
+    _PacketHandlerOnError();
+    break;
+      case RTC_STATE_INACTIVE:
+    _PacketHandlerOnInactive();
+    break;
+      case RTC_STATE_ACTIVE:
+    _PacketHandlerOnActive();
+    break;
+      case RTC_STATE_NONE:
+    ret = RTNO_NONE;
+    Transport_SendPacket(m_pPacketBuffer[INTERFACE], 1, &ret);
+    break;
+      default: // if m_Condition is unknown...
+    
+    break;
+      }
+    }
+  }
+
+  
+  int numOutPort = RTnoProfile_getNumOutPort();
+  for(int i = 0;i < numOutPort;i++) {
+    EC_suspend();
+    PortBase* pOutPort = RTnoProfile_getOutPortByIndex(i);
+    if(pOutPort->pPortBuffer->hasNext(pOutPort->pPortBuffer)) {
+      char* name = pOutPort->pName;
+      unsigned char nameLen = strlen(name);
+      unsigned char dataLen = pOutPort->pPortBuffer->getNextDataSize(pOutPort->pPortBuffer);
+
+      m_pPacketBuffer[0] = nameLen;
+      m_pPacketBuffer[1] = dataLen;
+      memcpy(m_pPacketBuffer + 2, name, nameLen);
+      pOutPort->pPortBuffer->pop(pOutPort->pPortBuffer, m_pPacketBuffer + 2 + nameLen, dataLen);
+      Transport_SendPacket(RECEIVE_DATA, 2 + nameLen + dataLen, m_pPacketBuffer);
+    }
+    EC_resume();
+  }
+  
+}
+
+/**
+ * add InPort data to Profile.
+ */
+void addInPort(InPortBase& Port)
+{
+  RTnoProfile_addInPort(&Port);
+}
+
+/**
+ * add OutPort data to Profile
+ */
+void addOutPort(OutPortBase& Port)
+{
+  RTnoProfile_addOutPort(&Port);
+}
+
+
+/**
+ * Private Function Definitions
+ *
+ */
+
+
+/**
+ * Send Profile Data
+ */
+PRIVATE void _SendProfile() {
+  int8_t ret = RTNO_OK;
+  for(uint8_t i = 0;i < RTnoProfile_getNumInPort();i++) {
+    PortBase* inPort = RTnoProfile_getInPortByIndex(i);
+    uint8_t nameLen = strlen(inPort->pName);
+    m_pPacketBuffer[0] = inPort->typeCode;
+    memcpy(&(m_pPacketBuffer[1]), inPort->pName, nameLen);
+    Transport_SendPacket(ADD_INPORT, 1+nameLen, m_pPacketBuffer);
+  }
+
+  for(uint8_t i = 0;i < RTnoProfile_getNumOutPort();i++) {
+    PortBase* outPort = RTnoProfile_getOutPortByIndex(i);
+    uint8_t nameLen = strlen(outPort->pName);
+    m_pPacketBuffer[0] = outPort->typeCode;
+    memcpy(&(m_pPacketBuffer[1]), outPort->pName, nameLen);
+    Transport_SendPacket(ADD_OUTPORT, 1+nameLen, m_pPacketBuffer);
+  }
+
+  Transport_SendPacket(GET_PROFILE, 1, &ret);
+}
+
+
+
+/**
+ * Packet Handler in Error State
+ */
+PRIVATE void _PacketHandlerOnError() {
+  char intface;
+  int8_t ret = RTNO_OK;
+
+  int8_t retval = EC_error();
+  if(retval < 0) ret = RTNO_ERROR;
+  Transport_SendPacket(intface, 1, &ret);
+}
+
+
+/** 
+ * Packet Handler in Inactive State
+ */
+PRIVATE void _PacketHandlerOnInactive() {
+
+  int8_t ret = RTNO_OK;
+  int8_t retval = EC_activate_component();
+  if(retval < 0) ret = RTNO_ERROR;
+  Transport_SendPacket(ACTIVATE, 1, &ret);
+}
+
+/**
+ * Packet Handler in Active State.
+ */
+PRIVATE void _PacketHandlerOnActive() {
+  int8_t ret = RTNO_OK;
+  //char intface;
+  int8_t retval;
+  switch(m_pPacketBuffer[INTERFACE]) {
+  case DEACTIVATE:
+    retval = EC_deactivate_component();
+    if(retval < 0) ret = RTNO_ERROR;
+    Transport_SendPacket(DEACTIVATE, 1, &ret);
+    break;
+  case EXECUTE:
+    retval = EC_execute();
+    if(retval < 0) ret = RTNO_ERROR;
+    Transport_SendPacket(EXECUTE, 1, &ret);
+    break;
+  case SEND_DATA: {
+      PortBase* pInPort = RTnoProfile_getInPort((const char*)&(m_pPacketBuffer[DATA_START_ADDR+2]), m_pPacketBuffer[DATA_START_ADDR]);
+      if(pInPort == NULL) {
+
+      } else {
+    PortBuffer* pBuffer = pInPort->pPortBuffer;
+    EC_suspend();
+    pBuffer->push(pBuffer,&(m_pPacketBuffer[DATA_START_ADDR+2+m_pPacketBuffer[DATA_START_ADDR]]), m_pPacketBuffer[DATA_START_ADDR+1]);
+    EC_resume();
+    Transport_SendPacket(SEND_DATA, 1, &ret);
+      }
+    }
+    break;
+  default:
+    break;
+  }
+}
+
diff -r 000000000000 -r 9fac71a0bff3 RTno.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTno.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,177 @@
+#ifndef RTNO_HEADER_INCLUDED
+#define RTNO_HEADER_INCLUDED
+
+/*******************************************
+ * RTno.h
+ * @author Yuki Suga
+ * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
+ * @license LGPLv3
+ *****************************************/
+
+
+//#define BAUDRATE 19200
+
+#define RTC_OK 0
+#define RTC_ERROR -1
+#define RTC_PRECONDITION_NOT_MET -2
+
+
+#define USE_UART_CONNECTION
+#define USE_ETHERNET_CONNECTION
+#define USE_TIMER1_EC
+
+#include "mbed.h"
+#include "BasicDataType.h"
+#include "InPort.h"
+#include "OutPort.h"
+#include "rtcconf.h"
+
+#ifdef USE_UART_CONNECTION
+#include "UART.h"
+#endif
+
+#ifdef USE_ETHERNET_CONNECTION
+#include "EtherTcp.h"
+#include "EthernetNetIf.h"
+#endif
+
+#ifdef USE_TIMER1_EC
+#include "Timer1ExecutionContext.h"
+#endif
+
+#include "ProxySyncEC.h"
+#define PACKET_BUFFER_SIZE 128
+
+#define MAX_PORT 8
+
+
+// global variables for rtcconf
+//extern volatile exec_cxt_str exec_cxt;
+//extern config_str conf;
+
+// global functions
+// RTno APIs
+extern "C" {
+  void rtcconf(config_str& conf, exec_cxt_str& exec_cxt);
+};
+
+extern "C" {
+  void addInPort(InPortBase& inPort);
+  void addOutPort(OutPortBase& outPort);
+}
+
+namespace RTno {
+  //extern "C" {
+
+  // These call-back funcitons should be defined in user program code.
+  // Use RTno_template.pde to create your own project.
+
+  /**
+   * onInitialize()
+   * This function is called when RTno is initialized.
+   * RTno is usually initialized when your device is turned on.
+   */
+  int onInitialize();
+
+  /**
+   * onActivated()
+   * This function is called when RTno is activated only if RTno is RTC_INACTIVE condition.
+   * RTno is usually activated by RT System Editor or other tools for OpenRTM-aist.
+   */
+  int onActivated();
+
+  /**
+   * onExecute()
+   * This function is periodically called when the RTno-proxy is RTC_ACTIVE condition.
+   */
+  int onExecute();
+
+  /**
+   * onDeactivated()
+   * This function is called when RTno is deactivated only if RTno is RTC_ACTIVE condition.
+   * RTno is usually deactivated by RT System Editor or other tools for OpenRTM-aist.
+   */
+  int onDeactivated();
+
+  /**
+   * onError
+   * This function is called when RTno is error only if RTno is in RTC_ERROR condition.
+   * [DANGEROUS] This function is periodically called in very short interval.
+   */ 
+ int onError();
+
+  /**
+   * onReset
+   * This function is called when RTno is reset only if RTno is in RTC_ERROR condition.
+   * RTno is usually reset by RT System Editor or other tools for OpenRTM-aist.
+   */
+  int onReset();
+  //};// extern "C"
+};
+
+
+#ifndef RTNO_SUBMODULE_DEFINE
+
+
+void EC_setup(exec_cxt_str& exec_cxt) {
+  switch(exec_cxt.periodic.type) {
+#ifdef USE_TIMER1_EC
+  case Timer1ExecutionContext:
+    Timer1EC_init(exec_cxt.periodic.rate);
+    break;
+#endif // USE_TIMER1_EC
+  case ProxySynchronousExecutionContext:
+  default:
+    ProxySyncEC_init();
+    break;
+  }
+}
+
+
+void Connection_setup(config_str& conf) {
+  switch(conf._default.connection_type) {
+#ifdef USE_ETHERNET_CONNECTION
+  case ConnectionTypeEtherTcp:
+    EtherTcp_init((uint8_t*)&conf._default.mac_address,
+          (uint8_t*)&conf._default.ip_address,
+          (uint8_t*)&conf._default.default_gateway,
+          (uint8_t*)&conf._default.subnet_mask,
+              conf._default.port);
+    break;
+#endif // USE_ETHERNET_CONNECTION
+#ifdef USE_UART_CONNECTION
+  case ConnectionTypeSerialUSB:
+    UART_init(0, conf._default.baudrate);
+    break;
+  case ConnectionTypeSerial1:
+    UART_init(1, conf._default.baudrate);
+    break;
+  case ConnectionTypeSerial2:
+    UART_init(2, conf._default.baudrate);
+    break;
+  case ConnectionTypeSerial3:
+    UART_init(3, conf._default.baudrate);
+    break;
+#endif // USE_UART_CONNECTION
+  default:
+    break;
+  }
+}
+
+void setup();
+void loop();
+
+int main(void) {
+    setup();
+    while(1) {
+#ifdef USE_ETHERNET_CONNECTION
+        Net::poll();
+#endif
+        loop();
+    }
+}
+
+#endif
+
+#endif
+
diff -r 000000000000 -r 9fac71a0bff3 RTnoProfile.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTnoProfile.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,82 @@
+#define RTNO_SUBMODULE_DEFINE
+
+#include "mbed.h"
+
+#include "RTnoProfile.h"
+
+static PortBase *m_ppInPort[MAX_PORT];
+static PortBase *m_ppOutPort[MAX_PORT];
+
+void RTnoProfile_init()
+{
+}
+
+int RTnoProfile_addInPort(PortBase* port) 
+{
+  int index = RTnoProfile_getNumInPort();
+  if(index == MAX_PORT) return -1;
+  m_ppInPort[index] = port;
+  return index;
+}
+
+
+int RTnoProfile_addOutPort(PortBase* port) 
+{
+  int index = RTnoProfile_getNumOutPort();
+  if(index == MAX_PORT) return -1;
+  m_ppOutPort[index] = port;
+  return index;
+}
+
+int RTnoProfile_getNumInPort() {
+  for(int i = 0;i < MAX_PORT;i++) {
+    if(m_ppInPort[i] == NULL) {
+      return i;
+    }
+  }
+  return MAX_PORT;
+}
+
+
+int RTnoProfile_getNumOutPort() {
+  for(int i = 0;i < MAX_PORT;i++) {
+    if(m_ppOutPort[i] == NULL) {
+      return i;
+    }
+  }
+  return MAX_PORT;
+
+}
+
+PortBase* RTnoProfile_getInPort(const char* name, uint8_t nameLen)
+{
+  for(uint8_t i = 0;i < MAX_PORT;i++) {
+    if(m_ppInPort[i] == NULL) return NULL;
+    if(strncmp(name, m_ppInPort[i]->pName, nameLen) == 0) {
+      return m_ppInPort[i];
+    }
+  }
+  return NULL;
+}
+
+
+PortBase* RTnoProfile_getOutPort(const char* name, uint8_t nameLen)
+{
+  for(uint8_t i = 0;i < MAX_PORT;i++) {
+    if(m_ppOutPort[i] == NULL) return NULL;
+    if(strncmp(name, m_ppOutPort[i]->pName, nameLen) == 0) {
+      return m_ppOutPort[i];
+    }
+  }
+  return NULL;
+}
+
+PortBase* RTnoProfile_getInPortByIndex(const uint8_t i)
+{
+  return m_ppInPort[i];
+}
+
+PortBase* RTnoProfile_getOutPortByIndex(const uint8_t i)
+{
+  return m_ppOutPort[i];
+}
diff -r 000000000000 -r 9fac71a0bff3 RTnoProfile.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTnoProfile.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,24 @@
+#ifndef RTNO_PROFILE_HEADER_INCLUDED
+#define RTNO_PROFILE_HEADER_INCLUDED
+
+#include <stdint.h>
+#include "RTno.h"
+
+#include "InPort.h"
+#include "OutPort.h"
+
+
+void RTnoProfile_init();
+int RTnoProfile_addInPort(PortBase* port);
+int RTnoProfile_addOutPort(PortBase* port);
+
+PortBase* RTnoProfile_getInPort(const char* name, uint8_t nameLen);
+PortBase* RTnoProfile_getOutPort(const char* name, uint8_t nameLen);
+PortBase* RTnoProfile_getInPortByIndex(const uint8_t i);
+PortBase* RTnoProfile_getOutPortByIndex(const uint8_t i);
+
+int RTnoProfile_getNumInPort();
+int RTnoProfile_getNumOutPort();
+
+#endif
+
diff -r 000000000000 -r 9fac71a0bff3 Sequence.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sequence.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,45 @@
+#ifndef SEQUENCE_HEADER_INCLUDED
+#define SEQUENCE_HEADER_INCLUDED
+
+#include <stdint.h>
+#include <stdlib.h>
+
+class SequenceBase {
+ protected:
+    uint8_t m_length;
+
+ public:
+  virtual uint8_t length() {
+    return m_length;
+  }
+  
+  virtual void length(uint8_t len) {};
+
+  virtual void* getData() = 0;
+};
+
+
+template<typename T>
+class Sequence : public SequenceBase {
+  T *m_ptr;
+
+ public:
+  Sequence() {m_ptr = 0;}
+  virtual void length(uint8_t len) {
+    m_length = len;
+    free((void*)m_ptr);
+    m_ptr = (T*)malloc(len * sizeof(T));
+  }
+
+  virtual uint8_t length() {
+    return SequenceBase::length();
+  }
+  T& operator[](uint8_t index) {
+    return m_ptr[index];
+  }
+
+  virtual void* getData() { return m_ptr; }
+};
+
+
+#endif //#ifndef SEQUENCE_HEADER_INCLUDED
diff -r 000000000000 -r 9fac71a0bff3 SerialDevice.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialDevice.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,10 @@
+#ifndef SERIAL_DEVICE_HEADER_INCLUDED
+#define SERIAL_DEVICE_HEADER_INCLUDED
+
+#include <stdint.h>
+
+extern void(*SerialDevice_putc)(const char c);
+extern uint8_t(*SerialDevice_available)();
+extern char(*SerialDevice_getc)();
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 Timer1ExecutionContext.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Timer1ExecutionContext.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,50 @@
+#define RTNO_SUBMODULE_DEFINE
+
+#include <stdint.h>
+#include "RTno.h"
+#include "Packet.h"
+#include "Timer1ExecutionContext.h"
+//#include <avr/io.h>
+//#include <avr/interrupt.h>
+
+static float m_Period;
+//static uint8_t m_ClockSetting;
+
+Ticker *m_pTimer;
+
+void Timer1EC_start();
+void Timer1EC_suspend();
+void Timer1EC_resume();
+
+void tick () {
+    EC_execute();
+}
+
+
+void Timer1EC_init(double rate)
+{
+  EC_init(0x22);
+  m_pTimer = new Ticker();
+  // Initialize Period
+  m_Period = (1.0 / rate);
+  EC_start = Timer1EC_start;
+  EC_suspend = Timer1EC_suspend;
+  EC_resume = Timer1EC_resume;
+}
+
+void Timer1EC_start()
+{
+    m_pTimer->attach(tick, m_Period);
+}
+
+void Timer1EC_suspend()
+{
+    m_pTimer->detach();
+}
+
+void Timer1EC_resume()
+{
+    Timer1EC_start();
+}
+
+
diff -r 000000000000 -r 9fac71a0bff3 Timer1ExecutionContext.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Timer1ExecutionContext.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,17 @@
+#ifndef TIMER1_EXECUTION_CONTEXT
+#define TIMER1_EXECUTION_CONTEXT
+
+#include "ExecutionContext.h"
+
+#ifdef __cplusplus
+//extern "C" {
+#endif
+
+void Timer1EC_init(double microsecond);
+
+#ifdef __cplusplus
+//}
+#endif
+
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 Transport.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Transport.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,89 @@
+#define RTNO_SUBMODULE_DEFINE
+#include <stdint.h>
+#include "mbed.h"
+#include "Transport.h"
+#include "Packet.h"
+
+int8_t Transport_init()
+{
+    return 0;
+}
+
+
+int8_t Transport_SendPacket(const char interface, const uint8_t data_length, const int8_t* packet_data) {
+  uint8_t sum = 0;
+  uint8_t sender[4] = {'U', 'A', 'R', 'T'};
+  SerialDevice_putc(interface);
+  sum += interface;
+  SerialDevice_putc(data_length);
+  sum += data_length;
+
+  for(uint8_t i = 0;i < 4;i++) {
+    sum += sender[i];
+    SerialDevice_putc(sender[i]);
+  }
+
+  for(uint8_t i = 0;i < data_length;i++) {
+    sum += packet_data[i];
+    SerialDevice_putc(packet_data[i]);
+  }
+  SerialDevice_putc(sum);
+  return PACKET_HEADER_SIZE + data_length + 1;
+}
+
+int8_t Transport_ReceivePacket(int8_t* packet) {
+  uint8_t counter = 0;
+  uint8_t sum = 0;
+
+  if(SerialDevice_available() == 0) {
+    return 0;
+  }
+
+  while(SerialDevice_available() < PACKET_HEADER_SIZE) {
+    wait(PACKET_WAITING_DELAY/1000.0);
+    counter++;
+    if(counter == PACKET_WAITING_COUNT) {
+      return -TIMEOUT;
+    }
+  }
+  packet[INTERFACE] = SerialDevice_getc();
+  sum += packet[INTERFACE];
+  packet[DATA_LENGTH] = SerialDevice_getc();
+  sum += packet[DATA_LENGTH];
+
+  counter = 0;
+  while(SerialDevice_available() < 4) {
+    wait(PACKET_WAITING_DELAY/1000.0);
+    counter++;
+    if(counter == PACKET_WAITING_COUNT) {
+      return -TIMEOUT;
+    }
+  }
+  for(uint8_t i = 0;i < 4;i++) {
+    uint8_t val = SerialDevice_getc();
+    sum += val;
+  }
+
+  for(uint8_t i = 0;i < packet[DATA_LENGTH];i++) {
+    counter = 0;
+    while(SerialDevice_available() == 0) {
+      wait(PACKET_WAITING_DELAY/1000.0);
+      counter++;
+      if(counter == PACKET_WAITING_COUNT) {
+    return -DATA_TIMEOUT;
+      }
+    }
+    packet[PACKET_HEADER_SIZE+i] = SerialDevice_getc();
+    sum += packet[PACKET_HEADER_SIZE+i];
+  }
+  
+  while(SerialDevice_available() == 0) {
+    ;
+  }
+  uint8_t checksum = SerialDevice_getc();
+  
+  if(sum != checksum) {
+    return -CHECKSUM_ERROR;
+  }
+  return PACKET_HEADER_SIZE + packet[DATA_LENGTH] + 1;
+}
diff -r 000000000000 -r 9fac71a0bff3 Transport.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Transport.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,13 @@
+#ifndef TRANSPORT_HEADER_INCLUDED
+#define TRANSPORT_HEADER_INCLUDED
+
+#include <stdint.h>
+#include "SerialDevice.h"
+
+int8_t Transport_init();
+
+int8_t Transport_SendPacket(const char interface, const uint8_t data_length, const int8_t* packet_data);
+	
+int8_t Transport_ReceivePacket(int8_t* packet);
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 TypeCode.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TypeCode.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,24 @@
+#include <ctype.h>
+
+#include "TypeCode.h"
+
+uint8_t TypeCode_isSequence(const char typeCode) {
+  return isupper(typeCode);
+}
+
+uint8_t TypeCode_getElementSize(const char typeCode) {
+  switch(tolower(typeCode)) {
+  case 'b':
+  case 'c':
+  case 'o':
+    return 1;
+  case 's':
+    return 2;
+  case 'l':
+  case 'f':
+  case 'd': // double is 32 bit in arduino
+    return 4;
+  default:
+    return 4;
+  }
+}
diff -r 000000000000 -r 9fac71a0bff3 TypeCode.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TypeCode.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,9 @@
+#ifndef TYPECODE_HEADER_INCLUDED
+#define TYPECODE_HEADER_INCLUDED
+
+#include <stdint.h>
+uint8_t TypeCode_isSequence(const char typeCode);
+
+uint8_t TypeCode_getElementSize(const char typeCode);
+
+#endif // #ifndef TYPECODE_HEADER_INCLUDED
diff -r 000000000000 -r 9fac71a0bff3 UART.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UART.cpp	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,94 @@
+#define RTNO_SUBMODULE_DEFINE
+
+#include "mbed.h"
+#include "UART.h"
+
+#define UART_RX_BUFFER_SIZE 128
+
+static Serial *m_pSerial;
+unsigned char uart_rx_buffer[UART_RX_BUFFER_SIZE];
+int uart_rx_buffer_pointer_head = 0;
+int uart_rx_buffer_pointer_tail = 0;
+
+
+/**
+ * Push data to ring buffer.
+ */
+int uart_rx_buffer_push(unsigned char c) {
+    uart_rx_buffer[uart_rx_buffer_pointer_tail] = c;
+    uart_rx_buffer_pointer_tail++;
+    if(uart_rx_buffer_pointer_tail >= UART_RX_BUFFER_SIZE) {
+        uart_rx_buffer_pointer_tail = 0;
+    }
+    return 0;
+}
+
+/**
+ * Pop data fron ring buffer
+ */
+int uart_rx_buffer_pop(unsigned char *c) {
+    *c = uart_rx_buffer[uart_rx_buffer_pointer_head];
+    uart_rx_buffer_pointer_head++;
+    if(uart_rx_buffer_pointer_head >= UART_RX_BUFFER_SIZE) {
+        uart_rx_buffer_pointer_head = 0;
+    }
+    return 0;
+}
+
+int uart_rx_buffer_get_size() {
+    int size = uart_rx_buffer_pointer_tail - uart_rx_buffer_pointer_head;
+    if(size < 0) {
+        size += UART_RX_BUFFER_SIZE;
+    }
+    return size;
+}
+
+void rx_isr(void) {
+    uart_rx_buffer_push(m_pSerial->getc());
+}
+
+
+
+void UART_init(unsigned char num, unsigned long baudrate)
+{
+    PinName rx, tx;
+    switch(num) {
+    case 0:
+      rx = USBRX; tx = USBTX;
+      break;
+    case 1:
+      tx = p9, rx = p10;
+      break;
+    case 2:
+      tx = p13, rx = p14;
+      break;
+    case 3:
+      tx = p28, rx = p27;
+      break;
+    }
+    
+    m_pSerial = new Serial(tx, rx);
+    m_pSerial->baud(baudrate);
+    m_pSerial->attach(rx_isr, Serial::RxIrq);
+
+    SerialDevice_putc = UART_putc;
+    SerialDevice_getc = UART_getc;
+    SerialDevice_available = UART_available;
+}
+
+void UART_putc(const char c) {
+  m_pSerial->putc(c);
+}
+
+uint8_t UART_available()
+{
+    return uart_rx_buffer_get_size();
+}
+
+
+char UART_getc()
+{
+    unsigned char c;
+    uart_rx_buffer_pop(&c);
+    return c;
+}
diff -r 000000000000 -r 9fac71a0bff3 UART.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UART.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,11 @@
+#ifndef UART_HEADER_INCLUDED
+#define UART_HEADER_INCLUDED
+
+#include "SerialDevice.h"
+
+void UART_init(unsigned char num, unsigned long baudrate);
+void UART_putc(const char c);
+uint8_t UART_available();
+char UART_getc();
+
+#endif
diff -r 000000000000 -r 9fac71a0bff3 rtcconf.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtcconf.h	Thu Feb 09 02:33:10 2012 +0000
@@ -0,0 +1,69 @@
+#ifndef RTC_CONF_HEADER_INCLUDED
+#define RTC_CONF_HEADER_INCLUDED
+
+
+#ifdef USE_ETHERNET_CONNECTION
+
+#define IPaddr(a1, a2, a3, a4) \
+  ((((uint32_t)a4) << 24) | (((uint32_t)a3) << 16) | (((uint32_t)a2) << 8) | (((uint32_t)a1) << 0))
+
+#define MACaddr(a1, a2, a3, a4, a5, a6) \
+  ((((uint64_t)a6) << 40) | (((uint64_t)a5) << 32) | (((uint64_t)a4) << 24) | (((uint64_t)a3) << 16) | (((uint64_t)a2) << 8) | (((uint64_t)a1) << 0))
+
+#endif
+
+
+
+struct default_str {
+  //#ifdef USE_ETHERNET_CONNECTION
+  uint64_t mac_address;
+  uint16_t port;
+  uint32_t default_gateway;
+  uint32_t ip_address;
+  uint32_t subnet_mask;
+  //#endif
+
+  //#ifdef USE_UART_CONNECTION
+  uint16_t baudrate;
+  //#endif
+  
+  uint8_t connection_type;
+};
+
+
+struct ether_str {
+};
+
+struct config_str {
+  struct default_str _default;
+};
+
+struct exec_cxt_str {
+  struct periodic_str {
+    //#ifdef USE_TIMER1_EC
+    float rate;
+    //#endif
+    uint8_t type;
+  }periodic;
+};
+
+#ifdef USE_UART_CONNECTION
+#define ConnectionTypeSerialUSB 0x11
+#define ConnectionTypeSerial1 0x01
+#define ConnectionTypeSerial2 0x02
+#define ConnectionTypeSerial3 0x03
+#endif
+
+#ifdef USE_ETHERNET_CONNECTION
+#define ConnectionTypeEtherTcp 0x04
+#endif
+
+#define ProxySynchronousExecutionContext 0x21
+
+#ifdef USE_TIMER1_EC
+#define Timer1ExecutionContext 0x22
+#endif
+
+#define Timer2ExecutionContext 0x23
+
+#endif