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:
69:8c5f220441f5
Parent:
37:fc4b4fd6a649
--- a/core/uip/NyLPC_cIPv4Payload.c	Thu May 22 12:59:50 2014 +0000
+++ b/core/uip/NyLPC_cIPv4Payload.c	Thu May 29 14:29:15 2014 +0000
@@ -58,64 +58,6 @@
 
 
 
-static NyLPC_TUInt16 ipv4id=39;
-
-
-
-
-static void writeTxIpHeader(
-    struct NyLPC_TIPv4Header* i_struct,
-    NyLPC_TUInt8 i_proto);
-
-
-
-/**
- * IPヘッダを送信パケット用に設定する。
- * ipcecksumには0を設定する。
- * この関数は、パケットサイズ,ローカルIP/リモートIPの設定はしない。
- */
-static void writeTxIpHeader(
-    struct NyLPC_TIPv4Header* i_struct,
-    NyLPC_TUInt8 i_proto)
-{
-    //IPパケットのセット
-    i_struct->proto=i_proto;
-    i_struct->ttl = UIP_DEFAULT_IP_TTL;
-    ++ipv4id;//パケットidのインクリメント
-    i_struct->tos = 0;
-    i_struct->ipoffset=NyLPC_htons(0);
-    i_struct->ipid16= NyLPC_htons(ipv4id);
-    i_struct->ipchksum = 0;
-}
-/**
- * TCPヘッダに値をセットする。checksum,wndは0初期化する。
- */
-static void setTcpTxHeader(struct NyLPC_TTcpHeader* i_struct,NyLPC_TUInt8 i_flag,const struct uip_conn* i_conn)
-{
-    i_struct->flags    = i_flag;
-    //sorce & destination port
-    i_struct->srcport  = i_conn->lport;
-    i_struct->destport = i_conn->rport;
-    //ACK number
-    i_struct->ackno32  = NyLPC_htonl(i_conn->rcv_nxt32);
-    //Seq Number
-    i_struct->seqno32  = NyLPC_htonl(i_conn->snd_nxt32);
-    //uip_func_tcp_send_noconn(BUF);
-    i_struct->urgp[0]  = i_struct->urgp[1] = 0;
-    i_struct->tcpchksum= 0;
-}
-/**
- * UDPヘッダに値をセットする。checksumは0初期化する。
- */
-static void setUdpTxHeader(struct NyLPC_TUdpHeader* i_struct,const struct uip_udp_conn* i_conn,NyLPC_TUInt16 i_dest_port)
-{
-    //sorce & destination port
-    i_struct->srcport  = i_conn->lport;
-    i_struct->destport = i_dest_port;
-    //uip_func_tcp_send_noconn(BUF);
-    i_struct->udpchksum= 0;
-}
-
 
 /*********************************************************************************
  * public 関数
@@ -133,10 +75,10 @@
  * IPパケットを格納したバッファをセットして、ペイロードのポインタを返します。
  * 失敗時はFALSE
  */
-NyLPC_TBool NyLPC_cIPv4Payload_setRxBuf(NyLPC_TcIPv4Payload_t* i_inst,void* i_buf,NyLPC_TUInt16 i_flagment_size)
+NyLPC_TBool NyLPC_cIPv4Payload_attachRxBuf(NyLPC_TcIPv4Payload_t* i_inst,const void* i_buf,NyLPC_TUInt16 i_flagment_size)
 {
-    i_inst->header=(struct NyLPC_TIPv4Header*)i_buf;
-    i_inst->payload.rawbuf=(NyLPC_TUInt8*)i_buf+(i_inst->header->vhl & 0x0f)*4;
+    i_inst->header=(const struct NyLPC_TIPv4Header*)i_buf;
+    i_inst->payload.rawbuf=(const NyLPC_TUInt8*)i_buf+(i_inst->header->vhl & 0x0f)*4;
     //IPパケットのバージョンチェック
     if((i_inst->header->vhl & 0xf0)!=0x40){
         NyLPC_OnErrorGoto(Error);
@@ -174,102 +116,14 @@
 }
 */
 
-/**
- * セット済みのバッファを、TCPの送信ペイロードへ初期化します。
- */
-void* NyLPC_cIPv4Payload_initTcpTx(NyLPC_TcIPv4Payload_t* i_inst,NyLPC_TUInt8 i_iph_word,NyLPC_TUInt8 i_tcph_word,NyLPC_TUInt16 i_tcp_payload_size)
-{
-    i_inst->header->vhl=0x40|(0x0f&i_iph_word);
-    i_inst->payload.rawbuf=((NyLPC_TUInt8*)(i_inst->header))+i_iph_word*4;
-    i_inst->payload.tcp->tcpoffset=(i_tcph_word<<4);
-    i_inst->header->len16=NyLPC_htons(i_tcp_payload_size+((i_iph_word+i_tcph_word)*4));
-    return i_inst->payload.rawbuf+(i_tcph_word*4);
-}
 
-/**
- * コネクション情報から、TCPのコントロールヘッダをセットします。
- */
-void NyLPC_cIPv4Payload_setTcpTxHeaderByConnection(NyLPC_TcIPv4Payload_t* i_inst,const struct uip_conn* i_conn,NyLPC_TUInt8 i_flag)
+const void* NyLPC_cIPv4Payload_detachBuf(NyLPC_TcIPv4Payload_t* i_inst)
 {
-    //IPv4のTxヘッダを書き込む。
-    i_inst->header->destipaddr=i_conn->ripaddr;
-    i_inst->header->srcipaddr =*(i_conn->lipaddr);
-    writeTxIpHeader(i_inst->header,UIP_PROTO_TCP);
-    //TCPのTxヘッダを書き込む
-    setTcpTxHeader(i_inst->payload.tcp,i_flag,i_conn);
-    return;
-}
-
-/**
- * 送信バッファをセットする。
- *
- */
-void NyLPC_cIPv4Payload_setTxBuf(NyLPC_TcIPv4Payload_t* i_inst,void* i_buf)
-{
-    i_inst->header=(struct NyLPC_TIPv4Header*)i_buf;
-}
-void* NyLPC_cIPv4Payload_detachBuf(NyLPC_TcIPv4Payload_t* i_inst)
-{
-    void* r=i_inst->header;
+    const void* r=i_inst->header;
     NyLPC_ArgAssert(r!=NULL);
     i_inst->header=NULL;
     return r;
 }
-
-/**
- * 入力したTCP/IPペイロードをRSTレスポンスに変換する。
- */
-void NyLPC_cIPv4Payload_setTcpReverseRstAck(
-    NyLPC_TcIPv4Payload_t* i_inst)
-{
-    struct NyLPC_TIPv4Addr src_addr,dest_addr;
-    NyLPC_TUInt32 ack,seq;
-    NyLPC_TUInt16 src_port,dest_port;
-    struct NyLPC_TTcpHeader* tcp=i_inst->payload.tcp;
-
-    //送信元IP,Portを退避
-    src_addr=i_inst->header->srcipaddr;
-    dest_addr=i_inst->header->destipaddr;
-    dest_port=tcp->destport;
-    src_port=tcp->srcport;
-    //送信元sq,ackを退避
-    ack=tcp->ackno32;
-    seq=tcp->seqno32;
-    //パケットマップの設定
-    NyLPC_cIPv4Payload_initTcpTx(i_inst,0x05,((UIP_TCPH_LEN) / 4),0);
-    //ipの設定
-    i_inst->header->destipaddr=src_addr;
-    i_inst->header->srcipaddr=dest_addr;
-    writeTxIpHeader(i_inst->header,UIP_PROTO_TCP);
-    //TCP設定
-    tcp->flags = TCP_RST | TCP_ACK;
-    tcp->tcpoffset = 5<<4;
-    tcp->seqno32=ack;
-    tcp->ackno32=NyLPC_htonl(NyLPC_ntohl(seq)+1);
-    tcp->srcport=dest_port;
-    tcp->destport=src_port;
-    tcp->urgp[0] = tcp->urgp[1] = 0;
-    tcp->wnd16=0;
-    i_inst->header->ipchksum = ~(NyLPC_TIPv4Header_makeIpChecksum(i_inst->header));
-    i_inst->payload.tcp->tcpchksum=~(NyLPC_TIPv4Header_makeTcpChecksum(i_inst->header));
-    return;
-}
-
-void NyLPC_cIPv4Payload_setTcpWnd(
-    NyLPC_TcIPv4Payload_t* i_inst,
-    NyLPC_TUInt16 i_wnd)
-{
-    i_inst->payload.tcp->wnd16=NyLPC_htons(i_wnd);
-}
-/**
- * パケットを閉じで完成させる。
- */
-void NyLPC_cIPv4Payload_closeTcpTxPacket(
-    NyLPC_TcIPv4Payload_t* i_inst)
-{
-    i_inst->payload.tcp->tcpchksum=~(NyLPC_TIPv4Header_makeTcpChecksum(i_inst->header));
-    i_inst->header->ipchksum = ~(NyLPC_TIPv4Header_makeIpChecksum(i_inst->header));
-}
 /* なんだっけっこれ?
 //1の補数v1にv2を加算する。
 static NyLPC_TUInt16 add16c(NyLPC_TUInt16 i_v1,NyLPC_TUInt16 i_v2)
@@ -286,90 +140,5 @@
     return (t<i_v1)?t:t-1;
 }
 */
-/**
- * o_instに、同一なバッファを参照するインスタンスを生成します。
- */
-void NyLPC_cIPv4Payload_copyTo(
-    const NyLPC_TcIPv4Payload_t* i_inst,
-    NyLPC_TcIPv4Payload_t* o_inst)
-{
-    o_inst->buf_len=i_inst->buf_len;
-    o_inst->header=i_inst->header;
-    o_inst->payload=i_inst->payload;
-}
-
-/**
- * ACK番号を更新する。
- * @param i_ackno
- * ネットワークオーダーのACK番号
- */
-void NyLPC_cIPv4Payload_updateAckNo(
-    NyLPC_TcIPv4Payload_t* i_inst,
-    NyLPC_TUInt32 i_ackno)
-{
-    NyLPC_Assert(i_inst->header!=NULL);
 
 
-/*  union{
-        NyLPC_TUInt32 l;
-        NyLPC_TUInt8 b[4];
-    }old_ack,new_ack;
-    NyLPC_TUInt16 v1;
-    //checksumの計算
-    old_ack.l=i_inst->payload.tcp->ackno32;//古いACK番号
-    new_ack.l=i_ackno;//新しいACK番号
-    v1=NyLPC_ntohs(~(i_inst->payload.tcp->tcpchksum));//1の補数を取って、ホストオーダーに戻す。
-    //減算
-    v1=sub16c(v1,(old_ack.b[0]<<8)+old_ack.b[1]);
-    v1=sub16c(v1,(old_ack.b[2]<<8)+old_ack.b[3]);
-    //加算
-    v1=add16c(v1,(new_ack.b[0]<<8)+new_ack.b[1]);
-    v1=add16c(v1,(new_ack.b[2]<<8)+new_ack.b[3]);
-    v1=~NyLPC_htons(v1);*/
-NyLPC_Trace();
-    i_inst->payload.tcp->ackno32=i_ackno;
-NyLPC_Trace();
-    i_inst->payload.tcp->tcpchksum = 0;
-NyLPC_Trace();
-    i_inst->payload.tcp->tcpchksum = ~(NyLPC_TIPv4Header_makeTcpChecksum(i_inst->header));
-NyLPC_Trace();
-
-/*
-    if((i_inst->payload.tcp->tcpchksum!=v1)){
-        NyLPC_Warning();
-    }*/
-}
-
-///////////////UDP//////////////
-
-/**
- * UDPの送信バッファを初期化します。
- */
-void* NyLPC_cIPv4Payload_initUdpTx(NyLPC_TcIPv4Payload_t* i_inst,NyLPC_TUInt8 i_iph_word,NyLPC_TUInt16 i_tcp_payload_size)
-{
-    i_inst->header->vhl=0x40|(0x0f&i_iph_word);
-    i_inst->payload.rawbuf=((NyLPC_TUInt8*)(i_inst->header))+i_iph_word*4;
-    i_inst->header->len16=NyLPC_htons(i_tcp_payload_size+(i_iph_word*4+8));
-    i_inst->payload.udp->udplen=NyLPC_htons(i_tcp_payload_size+(8));
-    return i_inst->payload.rawbuf+8;
-}
-
-/**
- * コネクション情報から、UDPのコントロールヘッダをセットします。
- */
-void NyLPC_cIPv4Payload_setUdpTxHeaderByConnection(NyLPC_TcIPv4Payload_t* i_inst,const struct uip_udp_conn* i_conn,const struct NyLPC_TIPv4Addr* i_dest_ip,NyLPC_TUInt16 i_dest_port)
-{
-    //IPv4のTxヘッダを書き込む。
-    i_inst->header->destipaddr=*i_dest_ip;
-    i_inst->header->srcipaddr =i_conn->lipaddr;
-    writeTxIpHeader(i_inst->header,UIP_PROTO_UDP);
-    //UDPのTxヘッダを書き込む
-    setUdpTxHeader(i_inst->payload.udp,i_conn,NyLPC_htons(i_dest_port));
-    return;
-}
-void NyLPC_cIPv4Payload_closeUdpTxPacket(
-    NyLPC_TcIPv4Payload_t* i_inst)
-{
-    i_inst->payload.udp->udpchksum=~(NyLPC_TIPv4Header_makeTcpChecksum(i_inst->header));
-    i_inst->header->ipchksum = ~(NyLPC_TIPv4Header_makeIpChecksum(i_inst->header));
-}