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
RpcI2C.cpp
00001 #include "RpcHandlerBase.h" 00002 namespace MiMic 00003 { 00004 class I2CHandler :RpcHandlerBase 00005 { 00006 public: 00007 static NyLPC_TBool new1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00008 { 00009 //u 00010 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00011 PinName pins[2]; 00012 if(getParamsAsPin(mod,i_rpc,pins,2)){ 00013 addNewObjectBatch(mod,i_rpc->method.id,new ModJsonRpc::RpcObject<I2C>(new I2C(pins[0],pins[1]))); 00014 } 00015 return NyLPC_TBool_TRUE; 00016 } 00017 static NyLPC_TBool frequency(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00018 { 00019 //d return d 00020 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00021 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00022 if(inst!=NULL){ 00023 int v; 00024 if(getParamInt(mod,i_rpc,v,1)){ 00025 inst->frequency(v); 00026 mod->putResult(i_rpc->method.id); 00027 } 00028 } 00029 return NyLPC_TBool_TRUE; 00030 } 00031 static NyLPC_TBool read1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00032 { 00033 //ddd return dB 00034 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00035 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00036 if(inst!=NULL){ 00037 int addr; 00038 unsigned char repeated,len; 00039 if(getParamInt(mod,i_rpc,addr,1)){ 00040 if(getParamByte(mod,i_rpc,len,2)){ 00041 if(getParamByte(mod,i_rpc,repeated,3)){ 00042 char* data=new char[len]; 00043 int r=inst->read(addr,data,len,repeated?true:false); 00044 mod->putResult(i_rpc->method.id,"%d,\"%.*B\"",r,(int)len,data); 00045 delete[] data; 00046 } 00047 } 00048 } 00049 } 00050 return NyLPC_TBool_TRUE; 00051 } 00052 static NyLPC_TBool read2(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00053 { 00054 //dd return d 00055 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00056 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00057 if(inst!=NULL){ 00058 int ack; 00059 if(getParamInt(mod,i_rpc,ack,1)){ 00060 mod->putResult(i_rpc->method.id,"%d",inst->read(ack)); 00061 } 00062 } 00063 return NyLPC_TBool_TRUE; 00064 } 00065 static NyLPC_TBool write1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00066 { 00067 //ddBd return d 00068 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00069 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00070 if(inst!=NULL){ 00071 int addr; 00072 const unsigned char* data; 00073 unsigned char repeated,len; 00074 if(getParamInt(mod,i_rpc,addr,1)){ 00075 if(getParamByteArray(mod,i_rpc,data,len,2)){ 00076 if(getParamByte(mod,i_rpc,repeated,3)){ 00077 mod->putResult(i_rpc->method.id,"%d",inst->write(addr,(const char*)data,len,repeated?true:false)); 00078 } 00079 } 00080 } 00081 } 00082 return NyLPC_TBool_TRUE; 00083 } 00084 static NyLPC_TBool write2(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00085 { 00086 //dd return d 00087 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00088 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00089 if(inst!=NULL){ 00090 int ack; 00091 if(getParamInt(mod,i_rpc,ack,1)){ 00092 mod->putResult(i_rpc->method.id,"%d",inst->write(ack)); 00093 } 00094 } 00095 return NyLPC_TBool_TRUE; 00096 } 00097 static NyLPC_TBool start(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00098 { 00099 //d return d 00100 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00101 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00102 if(inst!=NULL){ 00103 inst->start(); 00104 mod->putResult(i_rpc->method.id); 00105 } 00106 return NyLPC_TBool_TRUE; 00107 } 00108 static NyLPC_TBool stop(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00109 { 00110 //d return d 00111 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00112 I2C* inst=(I2C*)getObjectBatch(mod,i_rpc); 00113 if(inst!=NULL){ 00114 inst->stop(); 00115 mod->putResult(i_rpc->method.id); 00116 } 00117 return NyLPC_TBool_TRUE; 00118 } 00119 }; 00120 00121 00122 const static struct NyLPC_TJsonRpcMethodDef func_table[]= 00123 { 00124 { "_new1" ,"uu" ,I2CHandler::new1}, 00125 { "frequency" ,"dd" ,I2CHandler::frequency}, 00126 { "read1" ,"ddbb" ,I2CHandler::read1}, 00127 { "read2" ,"dd" ,I2CHandler::read2}, 00128 { "write1" ,"ddBb" ,I2CHandler::write1}, 00129 { "write2" ,"dd" ,I2CHandler::write2}, 00130 { "start" ,"d" ,I2CHandler::start}, 00131 { "stop" ,"d" ,I2CHandler::stop}, 00132 { NULL ,NULL ,NULL} 00133 }; 00134 00135 const struct NyLPC_TJsonRpcClassDef MbedJsApi::RPC_MBED_I2C={ 00136 "mbedJS","I2C",func_table 00137 }; 00138 } 00139
Generated on Tue Jul 12 2022 16:22:59 by
1.7.2
