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:
57:bc4330dfa62f
Parent:
50:35e765380772
Child:
68:f7def7eb5504
--- a/core/uip/NyLPC_cUipService.c	Sat Aug 10 02:52:22 2013 +0000
+++ b/core/uip/NyLPC_cUipService.c	Fri Sep 13 06:38:16 2013 +0000
@@ -95,7 +95,7 @@
         struct NyLPC_TArpHeader arp;
         struct NyLPC_TIPv4Header ipv4;
     }data;
-};
+}PACK_STRUCT_END;
 
 
 
@@ -122,7 +122,7 @@
 
 static NyLPC_TBool sendIPv4Tx(struct NyLPC_TTxBufferHeader* i_eth_buf);
 static void copyAndSendIPv4Tx(const struct TEthPacket* i_buf);
-static void sendArpReqest(const struct TEthPacket* i_eth_packet);
+//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);
 
@@ -136,7 +136,6 @@
 
 NyLPC_TcThread_t th;
 
-void led(int i);
 NyLPC_TBool NyLPC_cUipService_initialize(void)
 {
     NyLPC_TcUipService_t* inst=&_service_instance;
@@ -396,31 +395,10 @@
 }
 
 
-
-
 /**
- * allocTxBufで取得したメモリを"IPパケットとして"送信します。
- * @param i_eth_payload
- * [NyLPC_TTxBufferHeader][NyLPC_TEthernetIIHeader][payload]メモリの、[payload]のアドレスを指定します。
- * 通常は、NyLPC_cUipService_allocTxBufの返却したメモリを指定します。
+ * IPv4パケットのpeerIPを問い合わせるARPパケットを送信します。
  */
-
-void NyLPC_cUipService_sendIPv4Tx(void* i_eth_payload)
-{
-    NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
-    NyLPC_cMutex_lock(&(inst->_mutex));
-    //IPパケットの送信を試行
-    if(!sendIPv4Tx(((struct NyLPC_TTxBufferHeader*)(((struct NyLPC_TEthernetIIHeader*)i_eth_payload)-1))-1)){
-        //ARPリクエストを代わりに送信
-        sendArpReqest(((struct TEthPacket*)i_eth_payload)-1);
-    }
-    NyLPC_cMutex_unlock(&(inst->_mutex));
-    return;
-}
-/**
- * 指定したIPアドレスに対してARPRequestを送信します。
- */
-void NyLPC_cUipService_sendArpRequest(const struct NyLPC_TIPv4Addr* i_addr)
+static void sendArpReqest(const struct NyLPC_TIPv4Addr* i_addr)
 {
     NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
     NyLPC_TUInt16 tx_len;
@@ -431,10 +409,48 @@
     }
     //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);
+    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);
+}
+
+
+
+
+/**
+ * allocTxBufで取得したペイロードメモリを"IPパケットとして"送信します。
+ * @param i_eth_payload
+ * [NyLPC_TTxBufferHeader][NyLPC_TEthernetIIHeader][payload]メモリの、[payload]のアドレスを指定します。
+ * 通常は、NyLPC_cUipService_allocTxBufの返却したメモリを指定します。
+ */
+
+void NyLPC_cUipService_sendIPv4Tx(void* i_eth_payload)
+{
+    NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
+    struct NyLPC_TTxBufferHeader* p=((struct NyLPC_TTxBufferHeader*)(((struct NyLPC_TEthernetIIHeader*)i_eth_payload)-1))-1;
+    NyLPC_cMutex_lock(&(inst->_mutex));
+
+    //IPパケットの送信を試行
+    if(!sendIPv4Tx(p)){
+        //ARPリクエストを代わりに送信
+        sendArpReqest(&((struct NyLPC_TIPv4Header*)i_eth_payload)->destipaddr);
+    }
+    NyLPC_cMutex_unlock(&(inst->_mutex));
+    return;
+}
+
+
+
+/**
+ * 指定したIPアドレスに対してARPRequestを送信します。
+ */
+void NyLPC_cUipService_sendArpRequest(const struct NyLPC_TIPv4Addr* i_addr)
+{
+    NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
+    NyLPC_cMutex_lock(&(inst->_mutex));
+    sendArpReqest(i_addr);
+    NyLPC_cMutex_unlock(&(inst->_mutex));
     return;
 }
 
@@ -448,6 +464,8 @@
 }
 
 
+
+
 /**
  * 送信ペイロードメモリを返します。
  * この関数は、リエントラントを許容します。
@@ -501,7 +519,7 @@
  */
 
 /**
- * 新たにメモリを確保して、"IPv4パケットを格納した"イーサフレームを送信します。
+ * "IPv4パケットを格納した"イーサフレームを送信します。
  * コール前に、必ずロックしてから呼び出してください。
  */
 static void copyAndSendIPv4Tx(const struct TEthPacket* i_buf)
@@ -517,29 +535,13 @@
     memcpy(inst->stx.buf,i_buf,s);
     if(!sendIPv4Tx(&(inst->stx.h))){
         //失敗した場合はARPリクエストに変換して再送
-        sendArpReqest(i_buf);
+//@todo unchecked PASS!
+        sendArpReqest(&i_buf->data.ipv4.destipaddr);
     }
     return;
 }
-/**
- * IPv4パケットのpeerIPを問い合わせるARPパケットを送信します。
- */
-static void sendArpReqest(const struct TEthPacket* i_eth_packet)
-{
-    NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
-    NyLPC_TUInt16 tx_len;
-    struct TEthPacket* ethbuf;
-    //ACK送信用の自己バッファが空くまで待つ
-    while(inst->stx.h.is_lock){
-        inst->_ethif->processTx();
-    }
-    //ARPパケットを作る。
-    ethbuf=(struct TEthPacket*)(inst->stx.buf);
-    NyLPC_TArpHeader_setArpRequest(&(ethbuf->data.arp),inst->_ref_config->ip_addr,&(inst->_ref_config->eth_mac),i_eth_packet->data.ipv4.destipaddr);
-    tx_len=NyLPC_TEthernetIIHeader_setArpTx(&(ethbuf->header),&(inst->_ref_config->eth_mac));
-    //送信
-    inst->_ethif->sendTxEthFrame(&(inst->stx.h),tx_len);
-}
+
+
 
 /**
  * uipタスクが所有するTXバッファを使用してデータを送信します。
@@ -623,36 +625,4 @@
 
 
 
-//static void startEther()
-//{
-//  NyLPC_TcUipService_t* inst=_NyLPC_TcUipService_inst;
-//
-//  //Ethernetの起動待ち
-//  while(lEMACInit(_NyLPC_TcUipService_inst->_emac_semapho,&(inst->_ref_config->eth_mac))!= pdPASS )
-//    {
-//        vTaskDelay( 100 / portTICK_RATE_MS );
-//    }
-//  //Ethernetの割込み開始設定
-//  portENTER_CRITICAL();
-//  {
-//      LPC_EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );
-//      /* Set the interrupt priority to the max permissible to cause some
-//      interrupt nesting. */
-//      NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );
-//
-//      /* Enable the interrupt. */
-//      NVIC_EnableIRQ( ENET_IRQn );
-//  }
-//  portEXIT_CRITICAL();
-//}
-//
-//static void stopEther()
-//{
-//  portENTER_CRITICAL();
-//  {
-//      LPC_EMAC->IntEnable = (~(INT_RX_DONE|INT_TX_DONE))&LPC_EMAC->IntEnable;
-//      NVIC_DisableIRQ( ENET_IRQn );
-//  }
-//  portEXIT_CRITICAL();
-//}