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

core/http/NyLPC_cHttpBasicHeaderParser.h

Committer:
nyatla
Date:
2013-09-13
Revision:
57:bc4330dfa62f
Parent:
49:d4334acc3ec3

File content as of revision 57:bc4330dfa62f:

/*********************************************************************************
 * PROJECT: MiMic
 * --------------------------------------------------------------------------------
 *
 * This file is part of MiMic
 * Copyright (C)2011 Ryo Iizuka
 *
 * MiMic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For further information please contact.
 *  http://nyatla.jp/
 *  <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
 *
 *********************************************************************************/

#ifndef NyLPC_TcHttpBasicHeaderParser_H
#define NyLPC_TcHttpBasicHeaderParser_H
#include "NyLPC_stdlib.h"
#include "NyLPC_cHttpStream.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * HeaderParserのステータス定義値。
 */
typedef NyLPC_TUInt8 NyLPC_TcHttpBasicHeaderParser_ST;
#define NyLPC_TcHttpBasicHeaderParser_ST_START                  ((NyLPC_TcHttpBasicHeaderParser_ST)0x01)//HTTPステータスラインか、リクエストライン
#define NyLPC_TcHttpBasicHeaderParser_ST_RL_URL                 ((NyLPC_TcHttpBasicHeaderParser_ST)0x12)//URL
#define NyLPC_TcHttpBasicHeaderParser_ST_RL_VERSION             ((NyLPC_TcHttpBasicHeaderParser_ST)0x13)//VERSION
#define NyLPC_TcHttpBasicHeaderParser_ST_SL_STATUSCODE          ((NyLPC_TcHttpBasicHeaderParser_ST)0x21)//ステータスコード
#define NyLPC_TcHttpBasicHeaderParser_ST_SL_REASON              ((NyLPC_TcHttpBasicHeaderParser_ST)0x22)//Reason-Phrase
#define NyLPC_TcHttpBasicHeaderParser_ST_MSGHEAD                ((NyLPC_TcHttpBasicHeaderParser_ST)0x31)//MESSAGE
#define NyLPC_TcHttpBasicHeaderParser_ST_MSGPARAM               ((NyLPC_TcHttpBasicHeaderParser_ST)0x32)//MESSAGEパラメータ部
#define NyLPC_TcHttpBasicHeaderParser_ST_MSG_CONTENTLENGTH      ((NyLPC_TcHttpBasicHeaderParser_ST)0x33)//MESSAGEContentLength
#define NyLPC_TcHttpBasicHeaderParser_ST_MSG_CONNECTION         ((NyLPC_TcHttpBasicHeaderParser_ST)0x34)//MESSAGEConnection
#define NyLPC_TcHttpBasicHeaderParser_ST_MSG_TRANSFERENCODING   ((NyLPC_TcHttpBasicHeaderParser_ST)0x35)//TransferEncoding
#define NyLPC_TcHttpBasicHeaderParser_ST_MSG_RANGE              ((NyLPC_TcHttpBasicHeaderParser_ST)0x36)//Range
#define NyLPC_TcHttpBasicHeaderParser_ST_EOH                    ((NyLPC_TcHttpBasicHeaderParser_ST)0x7F)//終わり
#define NyLPC_TcHttpBasicHeaderParser_ST_ERROR                  ((NyLPC_TcHttpBasicHeaderParser_ST)0x80)//終わり
/*
    プライベート関数
*/
#define NyLPC_TcHttpBasicHeaderParser_ST_isError(i_v) ((i_v)==NyLPC_TcHttpBasicHeaderParser_ST_ERROR)



/**
 * このクラスは、Httpヘッダのパーサを定義します。
 */
typedef struct NyLPC_TcHttpBasicHeaderParser NyLPC_TcHttpBasicHeaderParser_t;


/**
 * HTTPメソッドの定義値。
 */
typedef NyLPC_TUInt8 NyLPC_THttpMethodType;
//HTTP STANDARD
#define NyLPC_THttpMethodType_NULL          ((NyLPC_THttpMethodType)0x00)
#define NyLPC_THttpMethodType_GET           ((NyLPC_THttpMethodType)0x01)
#define NyLPC_THttpMethodType_POST          ((NyLPC_THttpMethodType)0x02)
#define NyLPC_THttpMethodType_HEAD          ((NyLPC_THttpMethodType)0x03)
//SSDP
#define NyLPC_THttpMethodType_M_SEARCH      ((NyLPC_THttpMethodType)0x11)
#define NyLPC_THttpMethodType_NOTIFY        ((NyLPC_THttpMethodType)0x12)

const char* NyLPC_THttpMethodType_toString(NyLPC_THttpMethodType i_method);

/**
 * HTTPバージョンの定義値
 */
typedef NyLPC_TUInt8 NyLPC_THttpVersion;
#define NyLPC_THttpVersion_09       ((NyLPC_THttpVersion)0x01)
#define NyLPC_THttpVersion_10       ((NyLPC_THttpVersion)0x02)
#define NyLPC_THttpVersion_11       ((NyLPC_THttpVersion)0x03)
#define NyLPC_THttpVersion_UNKNOWN  ((NyLPC_THttpVersion)0x04)


typedef NyLPC_TUInt8 NyLPC_THttpHeaderType;
#define NyLPC_THttpHeaderType_REQUEST  ((NyLPC_THttpHeaderType)0x01)
#define NyLPC_THttpHeaderType_RESPONSE ((NyLPC_THttpHeaderType)0x02)


typedef NyLPC_TUInt8 NyLPC_THttpMessgeHeader_Connection;
#define NyLPC_THttpMessgeHeader_Connection_NONE  ((NyLPC_THttpMessgeHeader_Connection)0x01)
#define NyLPC_THttpMessgeHeader_Connection_CLOSE ((NyLPC_THttpMessgeHeader_Connection)0x02)
#define NyLPC_THttpMessgeHeader_Connection_KEEPALIVE ((NyLPC_THttpMessgeHeader_Connection)0x03)
#define NyLPC_THttpMessgeHeader_Connection_UPGRADE ((NyLPC_THttpMessgeHeader_Connection)0x04)
#define NyLPC_THttpMessgeHeader_Connection_UNKNOWN ((NyLPC_THttpMessgeHeader_Connection)0x10)

typedef NyLPC_TUInt8 NyLPC_THttpMessgeHeader_TransferEncoding;
#define NyLPC_THttpMessgeHeader_TransferEncoding_NONE    ((NyLPC_THttpMessgeHeader_TransferEncoding)0x01)   //TEはない
#define NyLPC_THttpMessgeHeader_TransferEncoding_CHUNKED ((NyLPC_THttpMessgeHeader_TransferEncoding)0x02)
#define NyLPC_THttpMessgeHeader_TransferEncoding_UNKNOWN ((NyLPC_THttpMessgeHeader_TransferEncoding)0x10)

#define NyLPC_THttpContentLength_INVALID_LENGTH 0xFFFFFFFF





/**
 * この構造体は、NyLPC_cHttpBasicHeaderParserの結果を格納します。
 */
struct NyLPC_THttpBasicHeader
{
    NyLPC_THttpMessgeHeader_TransferEncoding transfer_encoding;
    NyLPC_THttpMessgeHeader_Connection connection;
    NyLPC_THttpHeaderType type;
    NyLPC_TUInt8 _padding;
    union{
        struct{
            NyLPC_THttpVersion version;
            NyLPC_THttpMethodType method;
        }req;
        struct{
            NyLPC_THttpVersion version;
            NyLPC_TUInt32 status;
        }res;
    }startline;
    NyLPC_TUInt32 content_length;
};

/**
 * このヘッダが持続性接続を求めているか判定します。
 */
NyLPC_TBool NyLPC_THttpBasicHeader_isPersistent(const struct NyLPC_THttpBasicHeader* i_struct);






/**
 * コンフィギュレーション値。
 * ショートパラメータ解析バッファのサイズ
 */
#define NyLPC_cHttpBasicHeaderParser_SIZE_OF_WBS 32




/**
 * 独自のメッセージフィールドを受け取るイベントハンドラです。
 * メッセージハンドラはNyLPC_cHttpBasicHeaderParserから3種類のメッセージを受け取ります。
 * ハンドラは、NyLPC_TcHttpBasicHeaderParserが処理しないメッセージヘッダをパース中に、次の順番で呼び出されます。
 * <ol>
 * <li>開始メッセージ - i_nameに有効な文字列を指定して、そのフィールド値が入力される事を伝えます。i_cはnullです。
 * <li>フィールドメッセージ - i_nameにNULL,i_cに\0以外の文字を指定して、フィールド値が入力されている事を指示します。
 * <li>フィールドエンド - i_nameにNULL,i_cに0を指定して、フィールドが完了した事を指示します。
 * </ol>
*/
typedef NyLPC_TBool (*NyLPC_cHttpBasicHeaderParser_messageHandler) (NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out);
/**
 * リクエストのURL文字列を受け取るイベントハンドラです。
 * メッセージハンドラはNyLPC_cHttpBasicHeaderParserから3種類のメッセージを受け取ります。
 * ハンドラは、NyLPC_TcHttpBasicHeaderParserが処理しないメッセージヘッダをパース中に、次の順番で呼び出されます。
 * <ol>
 * <li>URLメッセージ - i_cに\0以外の文字を指定して、URL値が入力されている事を指示します。
 * <li>URLエンド - i_cに0を指定して、URLが完了した事を指示します。
 * </ol>
*/
typedef NyLPC_TBool (*NyLPC_cHttpBasicHeaderParser_urlHandler) (NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out);



/**
 * HTTPヘッダパーサハンドラの集合です。
 * ハンドラにNULL指定の場合TRUEを返したと見なします。
 */
struct NyLPC_TcHttpBasicHeaderParser_Handler
{
    NyLPC_cHttpBasicHeaderParser_messageHandler messageHandler;
    NyLPC_cHttpBasicHeaderParser_urlHandler urlHandler;
};



/**
 * クラス構造体
 */
struct NyLPC_TcHttpBasicHeaderParser
{
    /**継承クラスで実装すべきインタフェイス*/
    const struct NyLPC_TcHttpBasicHeaderParser_Handler* _handler;
    NyLPC_TUInt16 _rcode;//_stがERRORの時にエラーコードを格納する。
    /** パースの実行状態*/
    NyLPC_TcHttpBasicHeaderParser_ST _st;
    /**ワーク文字列*/
    NyLPC_TcStr_t _wsb;
    /**ワーク文字列のバッファ*/
    char _wsb_buf[NyLPC_cHttpBasicHeaderParser_SIZE_OF_WBS];
};


void NyLPC_cHttpBasicHeaderParser_initialize(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const struct NyLPC_TcHttpBasicHeaderParser_Handler* i_handler);
#define NyLPC_cHttpBasicHeaderParser_finalize(i_inst)

/**
 * パーサの開始処理をします。
 * 関数は、parseInit->parseChar[n回]->(parseStream)->parseFinishの順でコールします。
 * parseChar、又はparseStreamでエラーが発生した場合は、後続の関数を呼び出すことは出来ません。
 * parseCharでEOHに達した場合、parseCharまたはparseStreamを続けて呼ぶことは出来ません。
 * parseFinishはparseCharまたはparseStreamでEOHに達した場合のみ呼び出すことが出来ます。
 */
void NyLPC_cHttpBasicHeaderParser_parseInit(NyLPC_TcHttpBasicHeaderParser_t* i_inst,struct NyLPC_THttpBasicHeader* o_out);

/**
 * パーサの処理を閉じます。
 * @return
 * パース処理が正常に終了したかの真偽値
 */
NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseFinish(NyLPC_TcHttpBasicHeaderParser_t* i_inst,struct NyLPC_THttpBasicHeader* o_out);

/**
 * 文字列をパースします。
 * コール前にNyLPC_cHttpBasicHeaderParser_parseInitでパーサを開始してください。
 * @return
 * パースした文字数。エラーの場合-1です。
 * 0以上の場合、getParseStatusでパーサの状態を確認してください。
 */
NyLPC_TInt32 NyLPC_cHttpBasicHeaderParser_parseChar(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_c,NyLPC_TInt32 i_size,struct NyLPC_THttpBasicHeader* o_out);


/**
 * ストリームから読み出して、EOHに達するまでパースします。
 * コール前にNyLPC_cHttpBasicHeaderParser_parseInitでパーサを開始してください。
 * @return
 * 処理が正常に終了したかを返します。
 * TRUEの場合、ステータスはEOHに達しています。(parseFinishをコールできます。)
 */
NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out);


/**
 * parse関数がエラーの場合に、
 * 候補のエラーのステータスコードを返す。
 */
#define NyLPC_cHttpBasicHeaderParser_getStatusCode(inst) ((inst)->_rcode)

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif