Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
mbed/jsonrpc/RpcSPI.cpp@85:416f8bbbdf54, 2014-07-04 (annotated)
- Committer:
- nyatla
- Date:
- Fri Jul 04 14:28:46 2014 +0000
- Revision:
- 85:416f8bbbdf54
- Parent:
- 78:8cdb8fc7eda8
RPC???I2C/Slave/Memory/Serial???; ?????????????RPC????????;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyatla | 78:8cdb8fc7eda8 | 1 | #include "RpcHandlerBase.h" |
nyatla | 78:8cdb8fc7eda8 | 2 | namespace MiMic |
nyatla | 78:8cdb8fc7eda8 | 3 | { |
nyatla | 78:8cdb8fc7eda8 | 4 | class SPIHandler :RpcHandlerBase |
nyatla | 78:8cdb8fc7eda8 | 5 | { |
nyatla | 78:8cdb8fc7eda8 | 6 | public: |
nyatla | 78:8cdb8fc7eda8 | 7 | static NyLPC_TBool new1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) |
nyatla | 78:8cdb8fc7eda8 | 8 | { |
nyatla | 78:8cdb8fc7eda8 | 9 | //uuuu |
nyatla | 85:416f8bbbdf54 | 10 | ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; |
nyatla | 78:8cdb8fc7eda8 | 11 | PinName pin[4]; |
nyatla | 78:8cdb8fc7eda8 | 12 | if(getParamsAsPin(mod,i_rpc,pin,4)){ |
nyatla | 78:8cdb8fc7eda8 | 13 | addNewObjectBatch(mod,i_rpc->method.id,new ModJsonRpc::RpcObject<SPI>(new SPI(pin[0],pin[1],pin[2],pin[3]))); |
nyatla | 78:8cdb8fc7eda8 | 14 | } |
nyatla | 78:8cdb8fc7eda8 | 15 | return NyLPC_TBool_TRUE; |
nyatla | 78:8cdb8fc7eda8 | 16 | } |
nyatla | 78:8cdb8fc7eda8 | 17 | static NyLPC_TBool format(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) |
nyatla | 78:8cdb8fc7eda8 | 18 | { |
nyatla | 78:8cdb8fc7eda8 | 19 | //ddd return void |
nyatla | 85:416f8bbbdf54 | 20 | ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; |
nyatla | 78:8cdb8fc7eda8 | 21 | SPI* inst=(SPI*)getObjectBatch(mod,i_rpc); |
nyatla | 78:8cdb8fc7eda8 | 22 | if(inst!=NULL){ |
nyatla | 78:8cdb8fc7eda8 | 23 | int p[2]; |
nyatla | 78:8cdb8fc7eda8 | 24 | if(getParamsInt(mod,i_rpc,p,2,1)){ |
nyatla | 78:8cdb8fc7eda8 | 25 | inst->format(p[0],p[1]); |
nyatla | 85:416f8bbbdf54 | 26 | mod->putResult(i_rpc->method.id); |
nyatla | 78:8cdb8fc7eda8 | 27 | |
nyatla | 78:8cdb8fc7eda8 | 28 | } |
nyatla | 78:8cdb8fc7eda8 | 29 | } |
nyatla | 78:8cdb8fc7eda8 | 30 | return NyLPC_TBool_TRUE; |
nyatla | 78:8cdb8fc7eda8 | 31 | } |
nyatla | 78:8cdb8fc7eda8 | 32 | static NyLPC_TBool frequency(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) |
nyatla | 78:8cdb8fc7eda8 | 33 | { |
nyatla | 78:8cdb8fc7eda8 | 34 | //dd return void |
nyatla | 85:416f8bbbdf54 | 35 | ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; |
nyatla | 78:8cdb8fc7eda8 | 36 | SPI* inst=(SPI*)getObjectBatch(mod,i_rpc); |
nyatla | 78:8cdb8fc7eda8 | 37 | if(inst!=NULL){ |
nyatla | 78:8cdb8fc7eda8 | 38 | int v; |
nyatla | 78:8cdb8fc7eda8 | 39 | if(getParamInt(mod,i_rpc,v,1)){ |
nyatla | 78:8cdb8fc7eda8 | 40 | inst->frequency(v); |
nyatla | 85:416f8bbbdf54 | 41 | mod->putResult(i_rpc->method.id); |
nyatla | 78:8cdb8fc7eda8 | 42 | } |
nyatla | 78:8cdb8fc7eda8 | 43 | } |
nyatla | 78:8cdb8fc7eda8 | 44 | return NyLPC_TBool_TRUE; |
nyatla | 78:8cdb8fc7eda8 | 45 | } |
nyatla | 78:8cdb8fc7eda8 | 46 | static NyLPC_TBool write(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) |
nyatla | 78:8cdb8fc7eda8 | 47 | { |
nyatla | 78:8cdb8fc7eda8 | 48 | //dd return d |
nyatla | 85:416f8bbbdf54 | 49 | ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; |
nyatla | 78:8cdb8fc7eda8 | 50 | SPI* inst=(SPI*)getObjectBatch(mod,i_rpc); |
nyatla | 78:8cdb8fc7eda8 | 51 | if(inst!=NULL){ |
nyatla | 78:8cdb8fc7eda8 | 52 | int v; |
nyatla | 78:8cdb8fc7eda8 | 53 | if(getParamInt(mod,i_rpc,v,1)){ |
nyatla | 78:8cdb8fc7eda8 | 54 | mod->putResult(i_rpc->method.id,"%d",(int)(inst->write(v))); |
nyatla | 78:8cdb8fc7eda8 | 55 | } |
nyatla | 78:8cdb8fc7eda8 | 56 | } |
nyatla | 78:8cdb8fc7eda8 | 57 | return NyLPC_TBool_TRUE; |
nyatla | 78:8cdb8fc7eda8 | 58 | } |
nyatla | 78:8cdb8fc7eda8 | 59 | }; |
nyatla | 78:8cdb8fc7eda8 | 60 | |
nyatla | 78:8cdb8fc7eda8 | 61 | |
nyatla | 78:8cdb8fc7eda8 | 62 | |
nyatla | 78:8cdb8fc7eda8 | 63 | const static struct NyLPC_TJsonRpcMethodDef func_table[]= |
nyatla | 78:8cdb8fc7eda8 | 64 | { |
nyatla | 78:8cdb8fc7eda8 | 65 | { "_new1" ,"uuuu" ,SPIHandler::new1}, |
nyatla | 78:8cdb8fc7eda8 | 66 | { "format" ,"ddd" ,SPIHandler::format}, |
nyatla | 78:8cdb8fc7eda8 | 67 | { "frequency" ,"dd" ,SPIHandler::frequency}, |
nyatla | 78:8cdb8fc7eda8 | 68 | { "write" ,"dd" ,SPIHandler::write}, |
nyatla | 78:8cdb8fc7eda8 | 69 | { NULL ,NULL ,NULL} |
nyatla | 78:8cdb8fc7eda8 | 70 | }; |
nyatla | 78:8cdb8fc7eda8 | 71 | |
nyatla | 78:8cdb8fc7eda8 | 72 | const struct NyLPC_TJsonRpcClassDef MbedJsApi::RPC_MBED_SPI={ |
nyatla | 78:8cdb8fc7eda8 | 73 | "mbedJS","SPI",func_table |
nyatla | 78:8cdb8fc7eda8 | 74 | }; |
nyatla | 78:8cdb8fc7eda8 | 75 | |
nyatla | 78:8cdb8fc7eda8 | 76 | |
nyatla | 78:8cdb8fc7eda8 | 77 | |
nyatla | 78:8cdb8fc7eda8 | 78 | } |