This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

libMiMic(MiMic library for mbed)は、WebService機能を提供するSDKです。 mbedでWebAPIに対応したネットワークデバイスを簡単に作ることが出来ます。

libMiMicはMiMic projectで開発しています。MiMic projectについてはこちらをご覧ください。 http://nyatla.jp/mimic/wp/

構成

libMiMicはmbedRTOS上で動作し、ユーザアプリケーションにAPIを提供します。コアAPIはC言語で記述されていますが、使用頻度の高いものについてはmbed向けのC++APIが準備されています。

/media/uploads/nyatla/libmimic-sdk.png

※libMiMicはmbedの標準イーサネットドライバをしようしていません。

標準イーサネットドライバと同時に使用することはできません。

  • MiMicIP - IPv4スタックです。レテンシとメモリ消費量を抑えたuipベースのライブラリです。
  • ARP/ICMP/UDP/TCP - 基礎的なソケットAPIを提供します。APIは独自です。
  • HTTP/1.1 Server - HTTP/1.1に対応したサーバです。マルチセッション・Chunked・持続性接続に対応しています。
  • HTTP Modules - HTTP/1.1の機能モジュールです。以下のモジュールがあります。
    • ROM file provider - ROMに格納したファイルイメージを公開します。
    • File system provider - mbedファイルシステムを公開します。
    • Onchip configuration - プログラムフラッシュを利用して設定を保存します。
    • MiMicVM processor - RPCリクエスト(MiMicVM)を処理します。
    • FileUpload - ファイルアップロードを受け取ります。
    • URL decoder - HTTPリクエストを解析します。
    • UPnP handler -UPnPメッセージを処理します。
    • WebSocket - Websocketサーバです。
  • mDNS - マルチキャストDNSサービスです。
  • UPnP - UPnP/1.0の機能を提供します。UPnP handlerと協調して動作します。(現在はデバイス探索(SSDP)・デスクリプション(Description)のみ実装してあります。)
  • DHCP/APIPA - ゼロコンフィギュレーション用のモジュールです。
  • HTTP/1.1 Client
  • mbed C++ class library - mbed向けのC++CPIです。C言語のものより簡単です。

対応機種

  • mbed(mbed LPC1768)
  • LPCXpresso1769

プログラム

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

サンプル

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

チュートリアル

English

libMiMic(MiMic library for mbed) is SDK which provides Webservice functions. It can be created networking device easily using mbed.

See more MiMic information, See MiMic project website. http://nyatla.jp/mimic/wp/

Structure

libMiMic run on mbed RTOS and provides networking API to user application. This library has C++ class API for the mbed, and low-level C language API.

/media/uploads/nyatla/libmimic-sdk.png

For WebService general, it can be written in a simple C + + API.

libMiMic does not have the standard Ethernet driver of mbed. It is not possible that will be used with the standard Ethernet driver.

  • MiMicIP - IPv4 protocol stack. This is based uip which is reduced memory and latency.
  • ARP / ICMP / UDP / TCP - Those are provide basic IP protocols.
  • HTTP/1.1 Server - The Http server compatible HTTP/1.1. It supports multi-session, chunked transport, persistent connection.
  • HTTP Modules - There are addon-module for HTTP server. The following modules.
    • ROM file module - Publish the file images in ROM.
    • File system module - Publish thefiles in mbed file system.
    • Onchip configuration module - To save the network settings to the program flash via REST.
    • MiMicVM module - To handle the (MiMicVM) RPC request.
    • FileUpload module - Accept a file via HTTP POST.
    • URL dedoce module - A versatility URL decoder.
    • UPnP handle module - To handle UPnP messages.
    • UPnP - This provides UPnP/1.0 device functions. It works together with UPnP handler.
    • Websocket - websocket (version13) server
  • mDNS Service - DNS-SD protocol server.
  • UPnP - This provides UPnP/1.0 device functions which works with UPnP handler. (You have been implemented (SSDP) ? description only (Description) device search now.) It is a module zero configuration for - DHCP / APIPA. mbed C + + class library - C of mbed for + + is the CPI. It is simple than that of the C language.
  • DHCP/APIPA - It support zero-cpnfigulation.
  • mbed C++ class library. Almost APIs for Web applications are available.
  • HTTP/1.1 Client

Supported target

  • mbed(mbed LPC1768)
  • LPCXpresso1769

Application

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

Sample

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

Tutorial

Revision:
68:f7def7eb5504
Parent:
57:bc4330dfa62f
Child:
69:8c5f220441f5
--- a/core/uip/NyLPC_cUipService.c	Wed Oct 23 04:49:08 2013 +0000
+++ b/core/uip/NyLPC_cUipService.c	Thu May 22 12:59:50 2014 +0000
@@ -62,25 +62,7 @@
 
 
 
-/****************************************************
- * UipServiceに関する宣言:タスクメッセージ
- ***************************************************/
-/*
-#define TTaskMsg_NOP 0
-#define TTaskMsg_START 1
-#define TTaskMsg_STOP 2
-*/
-/**
- * サービスの起動メッセージです。
- *//*
-struct TTaskMsg{
-    NyLPC_TUInt16 msg;
-    union{
-        struct{
-            const NyLPC_TcIPv4Config_t* ref_config;
-        }start;
-    };
-};*/
+
 
 /****************************************************
  * UipServiceに関する宣言:その他
@@ -117,6 +99,9 @@
  */
 static int uipTask(void *pvParameters);
 
+/** イーサネットドライバからのハンドラ*/
+static void ethernet_handler(void* i_param,NyLPC_TiEthernetDevice_EVENT i_type);
+
 //--------------------------------------------------------------
 
 
@@ -124,7 +109,6 @@
 static void copyAndSendIPv4Tx(const struct TEthPacket* i_buf);
 //static void sendArpReqest(const struct TEthPacket* i_eth_packet);
 static void sendRawEthFrame(void* i_buf,NyLPC_TUInt16 i_len);
-static void emacIsrHandler(unsigned long i_status);
 
 /**メッセージなし*/
 #define TTaskMessage_MSG_NULL    0x0000
@@ -143,8 +127,6 @@
     NyLPC_Assert(!NyLPC_TcUipService_isInitService());
     //IP処理部分の初期化
     NyLPC_cIPv4_initialize(&(inst->_tcpv4));
-    //EMACからの割込処理
-    NyLPC_cIsr_setEnetISR(emacIsrHandler);
     //EMAC割込セマフォ
     NyLPC_cSemaphore_initialize(&inst->_emac_semapho);
 
@@ -219,7 +201,7 @@
 const char* NyLPC_cUipService_refDeviceName(void)
 {
     NyLPC_TcUipService_t* inst=&_service_instance;
-    return NyLPC_cUipService_isRun()?inst->_ethif->device_name:NULL;
+    return NyLPC_cUipService_isRun()?NyLPC_iEthernetDevice_getDevicName(inst->_ethif):NULL;
 }
 const NyLPC_TcIPv4Config_t* NyLPC_cUipService_refCurrentConfig(void)
 {
@@ -232,23 +214,6 @@
  *
  *********************************************************************/
 
-/**
- * EMACからのハンドラ
- */
-static void emacIsrHandler(unsigned long i_status)
-{
-    NyLPC_TcUipService_t* inst=&_service_instance;
-
-    if( i_status & INT_RX_DONE )
-    {
-        //受信系のセマフォブロックの解除
-        NyLPC_cSemaphore_giveFromISR(&inst->_emac_semapho);
-    }
-    if( i_status & INT_TX_DONE )
-    {
-    }
-}
-
 
 //PERIODIC rate
 #define PERIODIC_TIMER (1*200)
@@ -270,7 +235,7 @@
         if(NyLPC_TUInt16_isBitOn(inst->_status,NyLPC_TcUipService_ORDER_STOP))
         {
             //停止操作
-            inst->_ethif->stop();
+            NyLPC_iEthernetDevice_stop(inst->_ethif);
             NyLPC_cIPv4_stop(&(inst->_tcpv4));
             NyLPC_cIPv4IComp_finalize(&(inst->_icomp));
             NyLPC_cIPv4Arp_finalize(&(inst->_arp));
@@ -295,7 +260,7 @@
             inst->stx.h.is_lock=NyLPC_TUInt8_FALSE;
             inst->stx.h.ref=0;
             //EtherNETデバイス初期化
-            while(!inst->_ethif->start(&(inst->_ref_config->eth_mac)));
+            while(!NyLPC_iEthernetDevice_start(inst->_ethif,&(inst->_ref_config->eth_mac),ethernet_handler,inst));
             NyLPC_TUInt16_setBit(inst->_status,NyLPC_TcUipService_STATUSBIT_IS_RUNNING);
             NyLPC_TUInt16_unsetBit(inst->_status,NyLPC_TcUipService_ORDER_START);
             return NyLPC_TBool_TRUE;
@@ -326,7 +291,7 @@
         //イーサネットフレームの取得
         //Ethernet Device Lock(ARPを含む)
         NyLPC_cMutex_lock(&(inst->_mutex));
-        ethbuf= (struct TEthPacket*)inst->_ethif->getRxEthFrame(&rx_len);
+        ethbuf= (struct TEthPacket*)NyLPC_iEthernetDevice_getRxEthFrame(inst->_ethif,&rx_len);
         tx_len=0;
         while(ethbuf != NULL){
             if(rx_len>0)
@@ -370,9 +335,9 @@
                 }
             }
             //受信キューを進行。
-            inst->_ethif->nextRxEthFrame();
+            NyLPC_iEthernetDevice_nextRxEthFrame(inst->_ethif);
             //受信処理
-            ethbuf= (struct TEthPacket*)inst->_ethif->getRxEthFrame(&rx_len);
+            ethbuf= (struct TEthPacket*)NyLPC_iEthernetDevice_getRxEthFrame(inst->_ethif,&rx_len);
         }
         //データが無い。
         if(NyLPC_cStopwatch_isExpired(&(inst->_arp_sw))){
@@ -396,6 +361,21 @@
 
 
 /**
+ * イーサネットドライバからのハンドラ
+ */
+static void ethernet_handler(void* i_param,NyLPC_TiEthernetDevice_EVENT i_type)
+{
+    switch(i_type){
+    case NyLPC_TiEthernetDevice_EVENT_ON_RX:
+        //受信系のセマフォブロックの解除
+        NyLPC_cSemaphore_giveFromISR(&(((NyLPC_TcUipService_t*)i_param)->_emac_semapho));
+        break;
+    default:
+        break;
+    }
+}
+
+/**
  * IPv4パケットのpeerIPを問い合わせるARPパケットを送信します。
  */
 static void sendArpReqest(const struct NyLPC_TIPv4Addr* i_addr)
@@ -405,14 +385,14 @@
     struct TEthPacket* ethbuf;
     //ACK送信用の自己バッファが空くまで待つ
     while(inst->stx.h.is_lock){
-        inst->_ethif->processTx();
+        NyLPC_iEthernetDevice_processTx(inst->_ethif);
     }
     //ARPパケットを作る。
     ethbuf=(struct TEthPacket*)(inst->stx.buf);
     NyLPC_TArpHeader_setArpRequest(&(ethbuf->data.arp),inst->_ref_config->ip_addr,&(inst->_ref_config->eth_mac),i_addr);
     tx_len=NyLPC_TEthernetIIHeader_setArpTx(&(ethbuf->header),&(inst->_ref_config->eth_mac));
     //送信
-    inst->_ethif->sendTxEthFrame(&(inst->stx.h),tx_len);
+    NyLPC_iEthernetDevice_sendTxEthFrame(inst->_ethif,&(inst->stx.h),tx_len);
 }
 
 
@@ -484,7 +464,7 @@
     struct NyLPC_TTxBufferHeader* ethbuf;
     //排他処理をして、メモリを取得する。
     NyLPC_cMutex_lock(&(inst->_mutex));
-    ethbuf=(struct NyLPC_TTxBufferHeader*)inst->_ethif->allocTxBuf(i_hint+sizeof(struct NyLPC_TEthernetIIHeader),o_size);
+    ethbuf=(struct NyLPC_TTxBufferHeader*)NyLPC_iEthernetDevice_allocTxBuf(inst->_ethif,i_hint+sizeof(struct NyLPC_TEthernetIIHeader),o_size);
     NyLPC_cMutex_unlock(&(inst->_mutex));
     if(ethbuf==NULL){
         return NULL;
@@ -502,7 +482,7 @@
     NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
     NyLPC_cMutex_lock(&(inst->_mutex));
     //ペイロードの位置から、メモリブロックを再生。
-    inst->_ethif->releaseTxBuf(((struct NyLPC_TTxBufferHeader*)(((struct NyLPC_TEthernetIIHeader*)i_buf)-1))-1);
+    NyLPC_iEthernetDevice_releaseTxBuf(inst->_ethif,((struct NyLPC_TTxBufferHeader*)(((struct NyLPC_TEthernetIIHeader*)i_buf)-1))-1);
     NyLPC_cMutex_unlock(&(inst->_mutex));
     return NULL;
 }
@@ -528,7 +508,7 @@
     NyLPC_TUInt16 s;
     //ACK送信用の自己バッファが空くまで待つ
     while(inst->stx.h.is_lock){
-        inst->_ethif->processTx();
+        NyLPC_iEthernetDevice_processTx(inst->_ethif);
     }
     //送信する。
     s=NyLPC_htons(i_buf->data.ipv4.len16)+sizeof(struct NyLPC_TEthernetIIHeader);
@@ -557,7 +537,7 @@
 
     //ACK送信用の自己バッファが空くまで待つ
     while(inst->stx.h.is_lock){
-        inst->_ethif->processTx();
+        NyLPC_iEthernetDevice_processTx(inst->_ethif);
     }
     //64バイトを超えるとかありえない。
     if(i_len+sizeof(struct NyLPC_TEthernetIIHeader)>NyLPC_TcUipService_SIZE_OF_REPLY_BUF){
@@ -565,7 +545,7 @@
     }
     //送信する。
     memcpy(inst->stx.buf,i_buf,i_len);
-    inst->_ethif->sendTxEthFrame(&(inst->stx.h),i_len);
+    NyLPC_iEthernetDevice_sendTxEthFrame(inst->_ethif,&(inst->stx.h),i_len);
     return;
 }
 
@@ -619,7 +599,7 @@
     }
     //変換可能なら、イーサネットヘッダを更新して、送信処理へ。
     tx_len=NyLPC_TEthernetIIHeader_setIPv4Tx(&(ethbuf->header),&(inst->_ref_config->eth_mac),eth_dest);
-    inst->_ethif->sendTxEthFrame(i_eth_buf,tx_len);
+    NyLPC_iEthernetDevice_sendTxEthFrame(inst->_ethif,i_eth_buf,tx_len);
     return NyLPC_TBool_TRUE;
 }