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が準備されています。
※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.
チュートリアル
- HTTPD解説
- UPnPデバイスの作り方
- MiMicRemoteMCUの紹介(pdf)
- MiMicRemoteMCUのマニュアル(pdf)
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.
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
- HTTPD hello world.
- How to make own UPnP device.
- MiMicRemoteMCUの紹介(pdf)
- MiMicRemoteMCUのマニュアル(pdf)
Revision 76:b375b3d750d8, committed 2014-06-14
- Comitter:
- nyatla
- Date:
- Sat Jun 14 17:42:11 2014 +0000
- Parent:
- 75:2a18df0ef111
- Child:
- 77:8651d3c19a55
- Commit message:
- MiMic core r361???; JsonRPC????????
Changed in this revision
--- a/core/NyLPC_cMiMicEnv.c Sat Jun 14 15:55:57 2014 +0000 +++ b/core/NyLPC_cMiMicEnv.c Sat Jun 14 17:42:11 2014 +0000 @@ -1,7 +1,7 @@ #include "NyLPC_cMiMicEnv.h" #include "../uip/NyLPC_cUipService_protected.h" -const static char* VERSION="MiMic/1.5.4"; +const static char* VERSION="MiMic/1.5.5"; #if NyLPC_MCU==NyLPC_MCU_LPC4088 const static char* MCU="LPC4088";
--- a/core/uip/NyLPC_cUipService.h Sat Jun 14 15:55:57 2014 +0000 +++ b/core/uip/NyLPC_cUipService.h Sat Jun 14 17:42:11 2014 +0000 @@ -84,8 +84,9 @@ /** サービスタスクスタックサイズ * mdns 256+96(MIN) * upnp 256+160(MIN) + * mbedのExportしたのをLPCXpressoでコンパイルするときは+192しないと落ちる。 */ -#define NyLPC_TcUipService_config_STACK_SIZE (256+192) +#define NyLPC_TcUipService_config_STACK_SIZE (256+192+192) /** 登録できるリスナの最大数*/ #define NyLPC_TcUipService_config_MAX_LISTENER 4
--- a/mbed/jsonrpc/MbedJsApi.h Sat Jun 14 15:55:57 2014 +0000 +++ b/mbed/jsonrpc/MbedJsApi.h Sat Jun 14 17:42:11 2014 +0000 @@ -1,9 +1,15 @@ #pragma once #include "NyLPC_http.h" +#include "mbed.h" namespace MiMic { class MbedJsApi{ public: + /** + * MiMicRPCの定義するピンIDをmbedピンIDへ変換します。 + */ + static PinName pinId2PinName(unsigned int i_id); + public: const static struct NyLPC_TJsonRpcClassDef RPC_MBED_DIGITAL_OUT; }; -} \ No newline at end of file +}
--- a/mbed/jsonrpc/RpcDigitalOut.cpp Sat Jun 14 15:55:57 2014 +0000 +++ b/mbed/jsonrpc/RpcDigitalOut.cpp Sat Jun 14 17:42:11 2014 +0000 @@ -3,10 +3,12 @@ #include "mbed.h" namespace MiMic { + + class RpcHandlerBase { public: - static void addNewObjectBatch(ModJsonRpc& i_mod,unsigned int i_id,void* i_new_object) + static void addNewObjectBatch(ModJsonRpc& i_mod,unsigned int i_id,ModJsonRpc::BasicRpcObject* i_new_object) { int i=i_mod.addObject(i_new_object); if(i<0){ @@ -37,7 +39,7 @@ if(!NyLPC_TJsonRpcParserResult_getUInt32(i_rpc,0,&pin)){ mod->putError(i_rpc->method.id,ModJsonRpc::INVALID_PARAMS); }else{ - addNewObjectBatch(*mod,i_rpc->method.id,new DigitalOut(PinName(pin))); + addNewObjectBatch(*mod,i_rpc->method.id,new ModJsonRpc::RpcObject<DigitalOut>(new DigitalOut(MbedJsApi::pinId2PinName(pin)))); } return NyLPC_TBool_TRUE; } @@ -52,7 +54,7 @@ { mod->putError(i_rpc->method.id,ModJsonRpc::INVALID_PARAMS); }else{ - addNewObjectBatch(*mod,i_rpc->method.id,new DigitalOut(PinName(pin),value)); + addNewObjectBatch(*mod,i_rpc->method.id,new ModJsonRpc::RpcObject<DigitalOut>(new DigitalOut(MbedJsApi::pinId2PinName(pin),value))); } return NyLPC_TBool_TRUE; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed/jsonrpc/TargetTypes.h Sat Jun 14 17:42:11 2014 +0000 @@ -0,0 +1,36 @@ +/** + * @file + * このファイルはTarget定義ファイルからのみincludeして下さい。 + */ +#pragma once +#include "mbed.h" + +namespace MiMic +{ + +/* + * mbed1768,LPC4088に定義されているピン名の名前空間を定義します。 + * 一時的にPINIDを加える場合は、NS_USER_PINから始まるIDを使用してください。 + */ + +/** Px_yピンに該当するピンID。 P0_0,P0_1...P0_31,P1_0の順番*/ +#define PINID_LPC 0x00010000 +/** */ +#define PINID_MBED_DIP 0x00020000 +#define PINID_OTHER_MBED 0x00030000 +#define PINID_OTHER_MBED_LEDx (PINID_OTHER_MBED | 0x00000000) +#define PINID_OTHER_MBED_USBx (PINID_OTHER_MBED | 0x00000100) +#define PINID_ARCH_PRO 0x00040000 +#define PINID_ARCH_PRO_Dx (PINID_ARCH_PRO | 0x00000000) +#define PINID_ARCH_PRO_Ax (PINID_ARCH_PRO | 0x00000100) +#define PINID_ARCH_PRO_I2C_x (PINID_ARCH_PRO | 0x00000200) +#define PINID_USER 0x40000000 +#define PINID_NC 0x7fffffff + + +struct TPinNameMapItem{ + PinName name; + unsigned int id; +}; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed/jsonrpc/Target_LPC176x.cpp Sat Jun 14 17:42:11 2014 +0000 @@ -0,0 +1,108 @@ +/** + * @file + * LPC176xのターゲットテーブルです。 + */ +#include "TargetTypes.h" +#include "MbedJsApi.h" +#ifdef TARGET_LPC1768 +namespace MiMic +{ + +#define NS_LPC_PIN_0 PINID_LPC +#define NS_LPC_PIN_1 (NS_LPC_PIN_0+32) +#define NS_LPC_PIN_2 (NS_LPC_PIN_1+32) +#define NS_LPC_PIN_3 (NS_LPC_PIN_2+32) +#define NS_LPC_PIN_4 (NS_LPC_PIN_2+32) +#define NS_LPC_PIN_5 (NS_LPC_PIN_2+32) + +const static struct TPinNameMapItem table[]={ + {P0_0 ,NS_LPC_PIN_0+0}, {P0_1 ,NS_LPC_PIN_0+1}, {P0_2 ,NS_LPC_PIN_0+2}, {P0_3 ,NS_LPC_PIN_0+3}, + {P0_4 ,NS_LPC_PIN_0+4}, {P0_5 ,NS_LPC_PIN_0+5}, {P0_6 ,NS_LPC_PIN_0+6}, {P0_7 ,NS_LPC_PIN_0+7}, + {P0_8 ,NS_LPC_PIN_0+8}, {P0_9 ,NS_LPC_PIN_0+9}, {P0_10 ,NS_LPC_PIN_0+10}, {P0_11 ,NS_LPC_PIN_0+11}, + {P0_12 ,NS_LPC_PIN_0+12}, {P0_13 ,NS_LPC_PIN_0+13}, {P0_14 ,NS_LPC_PIN_0+14}, {P0_15 ,NS_LPC_PIN_0+15}, + {P0_16 ,NS_LPC_PIN_0+16}, {P0_17 ,NS_LPC_PIN_0+17}, {P0_18 ,NS_LPC_PIN_0+18}, {P0_19 ,NS_LPC_PIN_0+19}, + {P0_20 ,NS_LPC_PIN_0+20}, {P0_21 ,NS_LPC_PIN_0+21}, {P0_22 ,NS_LPC_PIN_0+22}, {P0_23 ,NS_LPC_PIN_0+23}, + {P0_24 ,NS_LPC_PIN_0+24}, {P0_25 ,NS_LPC_PIN_0+25}, {P0_26 ,NS_LPC_PIN_0+26}, {P0_27 ,NS_LPC_PIN_0+27}, + {P0_28 ,NS_LPC_PIN_0+28}, {P0_29 ,NS_LPC_PIN_0+29}, {P0_30 ,NS_LPC_PIN_0+30}, {P0_31 ,NS_LPC_PIN_0+31}, + + {P1_0 ,NS_LPC_PIN_1+0}, {P1_1 ,NS_LPC_PIN_1+1}, {P1_2 ,NS_LPC_PIN_1+2}, {P1_3 ,NS_LPC_PIN_1+3}, + {P1_4 ,NS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_MBED_DIP+7}, {P0_6 ,PINID_MBED_DIP+8}, + {P0_0 ,PINID_MBED_DIP+9}, {P0_1 ,PINID_MBED_DIP+10},{P0_18 ,PINID_MBED_DIP+11},{P0_17 ,PINID_MBED_DIP+12}, + {P0_15 ,PINID_MBED_DIP+13},{P0_16 ,PINID_MBED_DIP+14},{P0_23 ,PINID_MBED_DIP+15},{P0_24 ,PINID_MBED_DIP+16}, + {P0_25 ,PINID_MBED_DIP+17},{P0_26 ,PINID_MBED_DIP+18},{P1_30, PINID_MBED_DIP+19}, {P1_31, PINID_MBED_DIP+20}, + {P2_5, PINID_MBED_DIP+21}, {P2_4, PINID_MBED_DIP+22}, {P2_3, PINID_MBED_DIP+23}, {P2_2, PINID_MBED_DIP+24}, + {P2_1, PINID_MBED_DIP+25}, {P2_0, PINID_MBED_DIP+26}, {P0_11, PINID_MBED_DIP+27}, {P0_10, PINID_MBED_DIP+28}, + {P0_5, PINID_MBED_DIP+29}, {P0_4, PINID_MBED_DIP+30}, + + // Other mbed Pin Names + +#ifdef MCB1700 + {P1_28 ,PINID_OTHER_MBED_LEDx+0}, {P1_29 ,PINID_OTHER_MBED_LEDx+1}, {P1_31 ,PINID_OTHER_MBED_LEDx+2}, {P2_2 ,PINID_OTHER_MBED_LEDx+3}, +#else + {P1_18 ,PINID_OTHER_MBED_LEDx+0}, {P1_20 ,PINID_OTHER_MBED_LEDx+1}, {P1_21 ,PINID_OTHER_MBED_LEDx+2}, {P1_23 ,PINID_OTHER_MBED_LEDx+3}, +#endif + {P0_2,PINID_OTHER_MBED_USBx+0},{P0_3,PINID_OTHER_MBED_USBx+1}, + + // Arch Pro Pin Names + + {P4_29 ,PINID_ARCH_PRO_Dx+0}, {P4_28 ,PINID_ARCH_PRO_Dx+1}, {P0_4 ,PINID_ARCH_PRO_Dx+2}, {P0_5 ,PINID_ARCH_PRO_Dx+3}, + {P2_2 ,PINID_ARCH_PRO_Dx+4}, {P2_3 ,PINID_ARCH_PRO_Dx+5}, {P2_4 ,PINID_ARCH_PRO_Dx+6}, {P2_5 ,PINID_ARCH_PRO_Dx+7}, + {P0_0 ,PINID_ARCH_PRO_Dx+8}, {P0_1 ,PINID_ARCH_PRO_Dx+9}, {P0_6 ,PINID_ARCH_PRO_Dx+10},{P0_9 ,PINID_ARCH_PRO_Dx+11}, + {P0_8 ,PINID_ARCH_PRO_Dx+12},{P0_7 ,PINID_ARCH_PRO_Dx+13},{P0_27 ,PINID_ARCH_PRO_Dx+14},{P0_28 ,PINID_ARCH_PRO_Dx+15}, + + {P0_23,PINID_ARCH_PRO_Ax+0},{P0_24,PINID_ARCH_PRO_Ax+1},{P0_25,PINID_ARCH_PRO_Ax+2},{P0_26,PINID_ARCH_PRO_Ax+3}, + {P1_30,PINID_ARCH_PRO_Ax+4},{P1_31,PINID_ARCH_PRO_Ax+5}, + + {D15,PINID_ARCH_PRO_I2C_x+0},{D14,PINID_ARCH_PRO_I2C_x+1}, + {NC,PINID_NC} +}; + +PinName MbedJsApi::pinId2PinName(unsigned int i_id) +{ + for(int i=0;table[i].name!=NC;i++){ + if(i_id==table[i].id){ + return table[i].name; + } + } + return NC; +} +} +#endif +
--- a/mbed/mod/ModJsonRpc.cpp Sat Jun 14 15:55:57 2014 +0000 +++ b/mbed/mod/ModJsonRpc.cpp Sat Jun 14 17:42:11 2014 +0000 @@ -4,21 +4,21 @@ namespace MiMic { - #define NUM_OF_OBJECTS 3 - void** newObjectArray() + #define NUM_OF_OBJECTS 32 + ModJsonRpc::BasicRpcObject** newObjectArray() { - void** r=new void*[NUM_OF_OBJECTS]; - memset(r,sizeof(void*)*NUM_OF_OBJECTS,0); + ModJsonRpc::BasicRpcObject** r=new ModJsonRpc::BasicRpcObject*[NUM_OF_OBJECTS]; + memset(r,0,sizeof(ModJsonRpc::BasicRpcObject*)*NUM_OF_OBJECTS); return r; } - void deleteObjectArray(void** v) + void deleteObjectArray(ModJsonRpc::BasicRpcObject** v) { for(int i=0;i<NUM_OF_OBJECTS;i++){ if(v[i]!=NULL){ delete v[i]; } } - delete v; + delete[] v; } ModJsonRpc::ModJsonRpc(const char* i_path,const struct NyLPC_TJsonRpcClassDef** i_rpc_table):ModBaseClass(i_path) @@ -119,7 +119,7 @@ return NyLPC_cModJsonRpc_putError(this->_mod,i_id,i_code)?true:false; } - int ModJsonRpc::addObject(void* i_object) + int ModJsonRpc::addObject(BasicRpcObject* i_object) { for(int i=0;i<NUM_OF_OBJECTS;i++){ if(this->_objects[i]==NULL){ @@ -131,7 +131,7 @@ } void* ModJsonRpc::getObject(int i_oid) { - return this->_objects[i_oid]; - } + return this->_objects[i_oid]->obj; + } -} \ No newline at end of file +}
--- a/mbed/mod/ModJsonRpc.h Sat Jun 14 15:55:57 2014 +0000 +++ b/mbed/mod/ModJsonRpc.h Sat Jun 14 17:42:11 2014 +0000 @@ -20,6 +20,24 @@ */ class ModJsonRpc:ModBaseClass { + public: + class BasicRpcObject + { + public: + void* obj; + BasicRpcObject(void* i_ptr) : obj(i_ptr){}; + virtual ~BasicRpcObject(){} + }; + template< class T > class RpcObject : public BasicRpcObject{ + public: + RpcObject(T* i_ptr) : BasicRpcObject(i_ptr){}; + virtual ~RpcObject(){delete (static_cast<T*>(this->obj));} + }; + template< class T > class RpcArray : public BasicRpcObject{ + public: + RpcArray(T* i_ptr) : BasicRpcObject(i_ptr){}; + virtual ~RpcArray(){delete[] (static_cast<T*>(this->obj));} + }; private: public: const static int PARSE_ERROR=NyLPC_TJsonRpcErrorCode_PARSE_ERROR; @@ -29,7 +47,7 @@ const static int INTERNAL_ERROR=NyLPC_TJsonRpcErrorCode_INTERNAL_ERROR; const static int SERVER_ERROR_BASE=NyLPC_TJsonRpcErrorCode_SERVER_ERROR_BASE; private: - void** _objects; + BasicRpcObject** _objects; const struct NyLPC_TJsonRpcClassDef** _rpc_table; protected: NyLPC_TcModJsonRpc_t* _mod; @@ -52,9 +70,9 @@ public: //for development - int addObject(void* i_object); + int addObject(BasicRpcObject* i_object); void* getObject(int i_oid); bool putResult(unsigned int i_id,const char* i_params_fmt,...); bool putError(unsigned int i_id,int i_code); }; -} \ No newline at end of file +}