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
RpcSPISlave.cpp
00001 #include "RpcHandlerBase.h" 00002 namespace MiMic 00003 { 00004 class SPISlaveHandler :RpcHandlerBase 00005 { 00006 public: 00007 static NyLPC_TBool new1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00008 { 00009 //uuuu 00010 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00011 PinName pin[4]; 00012 if(getParamsAsPin(mod,i_rpc,pin,4)){ 00013 addNewObjectBatch(mod,i_rpc->method.id,new ModJsonRpc::RpcObject<SPISlave>(new SPISlave(pin[0],pin[1],pin[2],pin[3]))); 00014 } 00015 return NyLPC_TBool_TRUE; 00016 } 00017 static NyLPC_TBool format(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00018 { 00019 //ddd return void 00020 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00021 SPISlave* inst=(SPISlave*)getObjectBatch(mod,i_rpc); 00022 if(inst!=NULL){ 00023 int p[2]; 00024 if(getParamsInt(mod,i_rpc,p,2,1)){ 00025 inst->format(p[0],p[1]); 00026 mod->putResult(i_rpc->method.id); 00027 } 00028 } 00029 return NyLPC_TBool_TRUE; 00030 } 00031 static NyLPC_TBool frequency(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00032 { 00033 //dd return void 00034 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00035 SPISlave* inst=(SPISlave*)getObjectBatch(mod,i_rpc); 00036 if(inst!=NULL){ 00037 int v; 00038 if(getParamInt(mod,i_rpc,v,1)){ 00039 inst->frequency(v); 00040 mod->putResult(i_rpc->method.id); 00041 } 00042 } 00043 return NyLPC_TBool_TRUE; 00044 } 00045 static NyLPC_TBool read(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00046 { 00047 //dd return d 00048 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00049 SPISlave* inst=(SPISlave*)getObjectBatch(mod,i_rpc); 00050 if(inst!=NULL){ 00051 mod->putResult(i_rpc->method.id,"%d",(int)(inst->read())); 00052 } 00053 return NyLPC_TBool_TRUE; 00054 } 00055 static NyLPC_TBool receive(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00056 { 00057 //dd return d 00058 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00059 SPISlave* inst=(SPISlave*)getObjectBatch(mod,i_rpc); 00060 if(inst!=NULL){ 00061 mod->putResult(i_rpc->method.id,"%d",(int)(inst->receive())); 00062 } 00063 return NyLPC_TBool_TRUE; 00064 } 00065 static NyLPC_TBool reply(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00066 { 00067 //dd return d 00068 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00069 SPISlave* inst=(SPISlave*)getObjectBatch(mod,i_rpc); 00070 if(inst!=NULL){ 00071 int v; 00072 if(getParamInt(mod,i_rpc,v,1)){ 00073 inst->reply(v); 00074 mod->putResult(i_rpc->method.id); 00075 } 00076 } 00077 return NyLPC_TBool_TRUE; 00078 } 00079 }; 00080 00081 00082 00083 const static struct NyLPC_TJsonRpcMethodDef func_table[]= 00084 { 00085 { "_new1" ,"uuuu" ,SPISlaveHandler::new1}, 00086 { "format" ,"ddd" ,SPISlaveHandler::format}, 00087 { "frequency" ,"dd" ,SPISlaveHandler::frequency}, 00088 { "read" ,"d" ,SPISlaveHandler::read}, 00089 { "receive" ,"d" ,SPISlaveHandler::receive}, 00090 { "reply" ,"dd" ,SPISlaveHandler::reply}, 00091 { NULL ,NULL ,NULL} 00092 }; 00093 00094 const struct NyLPC_TJsonRpcClassDef MbedJsApi::RPC_MBED_SPI_SLAVE={ 00095 "mbedJS","SPISlave",func_table 00096 }; 00097 00098 00099 00100 }
Generated on Tue Jul 12 2022 16:22:59 by
