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:   EthernetInterface mbed-rtos

Revision:
6:86d72601ff54
Parent:
1:f74116b37bc9
--- a/EtherTcp.cpp	Mon Jul 08 13:09:22 2013 +0000
+++ b/EtherTcp.cpp	Thu Aug 29 05:26:09 2013 +0000
@@ -1,7 +1,12 @@
 #include "mbed.h"
+#define RTNO_SUBMODULE_DEFINE
+#include "RTno.h"
+
+#ifdef USE_ETHERNET_CONNECTION
+
 #include "EtherTcp.h"
-#include "EthernetNetIf.h"
-#include "TCPSocket.h"
+#include "EthernetInterface.h"
+
 
 #include "ip_addr.h"
 /**
@@ -11,16 +16,16 @@
 static EthernetServer *m_pServer;
 static EthernetClient *m_pClient;
 */
-static EthernetNetIf* m_pInterface;
-static TCPSocket* m_pServerSocket;
-static TCPSocket* m_pClientSocket;
+//static EthernetInterface* m_pInterface;
+static TCPSocketServer* m_pServerSocket;
+static TCPSocketConnection m_ClientSocket;
 
 
 #define ETCP_RX_BUFFER_SIZE 128
 uint8_t etcp_rx_buffer[ETCP_RX_BUFFER_SIZE];
 int etcp_rx_buffer_pointer_head = 0;
 int etcp_rx_buffer_pointer_tail = 0;
-Host m_Client;
+///Host m_Client;
 
 Serial *pSerial;
 
@@ -56,6 +61,7 @@
     return size;
 }
 
+/*
 static void EtherTcp_onClientEvent(TCPSocketEvent e) {
   switch (e) {
   // If the socket is readable, do stuff
@@ -88,28 +94,27 @@
     m_pClientSocket->setOnEvent(EtherTcp_onClientEvent);
   }
 }
+*/
 
-void EtherTcp_init(uint8_t* mac, uint8_t* ip, 
-           uint8_t* gateway, uint8_t* subnet,
+void EtherTcp_init(/*const char* mac, */const char* ip, 
+           const char* gateway, const char* 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;
-  }  
+  EthernetInterface::init(
+       ip, subnet, gateway);
+  //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 = new TCPSocketServer();
+  //m_pServerSocket->setOnEvent(EtherTcp_onServerEvent);
+  m_pServerSocket->bind(port);
   m_pServerSocket->listen();
+  m_pServerSocket->accept(m_ClientSocket);
   SerialDevice_available = EtherTcp_available;
   SerialDevice_getc = EtherTcp_getc;
   SerialDevice_putc = EtherTcp_putc;
@@ -117,20 +122,22 @@
 
 uint8_t EtherTcp_available()
 {
-  Net::poll();
+  //Net::poll();
   return etcp_rx_buffer_get_size();
 }
 
 
 void EtherTcp_putc(const char c) {
-  if(m_pClientSocket != NULL) {
-    m_pClientSocket->send(&c, 1);
+  char d = c;
+    m_ClientSocket.send(&d, 1);
   }
-}
 
 uint8_t EtherTcp_getc()
 {
   uint8_t c;
-  etcp_rx_buffer_pop(&c);
+  m_ClientSocket.receive((char*)&c, 1);
+  //etcp_rx_buffer_pop(&c);
   return c;
 }
+
+#endif
\ No newline at end of file