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
RpcSerial.cpp
00001 #include "RpcHandlerBase.h" 00002 namespace MiMic 00003 { 00004 class SerialHandler :RpcHandlerBase 00005 { 00006 public: 00007 static NyLPC_TBool new1(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00008 { 00009 //uu 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<Serial>(new Serial(pins[0],pins[1]))); 00014 } 00015 return NyLPC_TBool_TRUE; 00016 } 00017 static NyLPC_TBool format(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00018 { 00019 //dddd return none 00020 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00021 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00022 if(inst!=NULL){ 00023 int p[3]; 00024 if(getParamsInt(mod,i_rpc,p,3,1)){ 00025 inst->format(p[0],(SerialBase::Parity)p[1],p[2]); 00026 mod->putResult(i_rpc->method.id); 00027 } 00028 } 00029 return NyLPC_TBool_TRUE; 00030 }; 00031 static NyLPC_TBool readable(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00032 { 00033 //d return d 00034 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00035 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00036 if(inst!=NULL){ 00037 mod->putResult(i_rpc->method.id,"%d",inst->readable()); 00038 } 00039 return NyLPC_TBool_TRUE; 00040 } 00041 static NyLPC_TBool writeable(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00042 { 00043 //d return d 00044 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00045 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00046 if(inst!=NULL){ 00047 mod->putResult(i_rpc->method.id,"%d",inst->writeable()); 00048 } 00049 return NyLPC_TBool_TRUE; 00050 } 00051 static NyLPC_TBool send_break(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00052 { 00053 //d return none 00054 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00055 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00056 if(inst!=NULL){ 00057 mod->putResult(i_rpc->method.id); 00058 } 00059 return NyLPC_TBool_TRUE; 00060 } 00061 static NyLPC_TBool putc(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00062 { 00063 //d return d 00064 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00065 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00066 if(inst!=NULL){ 00067 int v; 00068 if(getParamInt(mod,i_rpc,v,1)){ 00069 mod->putResult(i_rpc->method.id,"%d",inst->putc(v)); 00070 } 00071 } 00072 return NyLPC_TBool_TRUE; 00073 } 00074 static NyLPC_TBool puts(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00075 { 00076 //ds return d 00077 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00078 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00079 if(inst!=NULL){ 00080 const char* s; 00081 if(getParamString(mod,i_rpc,s,1)){ 00082 mod->putResult(i_rpc->method.id,"%d",inst->puts(s)); 00083 } 00084 } 00085 return NyLPC_TBool_TRUE; 00086 } 00087 static NyLPC_TBool getc(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00088 { 00089 //d return d 00090 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00091 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00092 if(inst!=NULL){ 00093 mod->putResult(i_rpc->method.id,"%d",inst->getc()); 00094 } 00095 return NyLPC_TBool_TRUE; 00096 } 00097 static NyLPC_TBool gets(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00098 { 00099 //dd return s 00100 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00101 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00102 if(inst!=NULL){ 00103 unsigned char l; 00104 if(getParamByte(mod,i_rpc,l,1)){ 00105 char* b=new char[l]; 00106 inst->gets(b,l); 00107 mod->putResult(i_rpc->method.id,"\"%s\"",b); 00108 delete[] b; 00109 } 00110 } 00111 return NyLPC_TBool_TRUE; 00112 } 00113 static NyLPC_TBool baud(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00114 { 00115 //d return d 00116 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00117 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00118 if(inst!=NULL){ 00119 int v; 00120 if(getParamInt(mod,i_rpc,v,1)){ 00121 inst->baud(v); 00122 mod->putResult(i_rpc->method.id); 00123 } 00124 } 00125 return NyLPC_TBool_TRUE; 00126 } 00127 /** 00128 * for binary array 00129 */ 00130 static NyLPC_TBool puts_2(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00131 { 00132 //dB return d 00133 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00134 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00135 if(inst!=NULL){ 00136 const unsigned char* data; 00137 unsigned char len; 00138 if(getParamByteArray(mod,i_rpc,data,len,1)){ 00139 for(int i=0;i<len;i++){ 00140 inst->putc(data[i]); 00141 } 00142 mod->putResult(i_rpc->method.id,"%d",len); 00143 } 00144 } 00145 return NyLPC_TBool_TRUE; 00146 } 00147 /** 00148 * for binary array 00149 */ 00150 static NyLPC_TBool gets_2(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00151 { 00152 //ds return B 00153 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00154 Serial* inst=(Serial*)getObjectBatch(mod,i_rpc); 00155 if(inst!=NULL){ 00156 unsigned char l; 00157 if(getParamByte(mod,i_rpc,l,1)){ 00158 unsigned char* b=new unsigned char[l]; 00159 int i=0; 00160 for(;;){ 00161 *(b+i)=(unsigned char)(inst->getc()); 00162 i++; 00163 if(i>=l){ 00164 break; 00165 } 00166 }; 00167 mod->putResult(i_rpc->method.id,"\"%.*B\"",l,b); 00168 delete[] b; 00169 } 00170 } 00171 return NyLPC_TBool_TRUE; 00172 } 00173 }; 00174 00175 00176 00177 const static struct NyLPC_TJsonRpcMethodDef func_table[]= 00178 { 00179 { "_new1" ,"uu" ,SerialHandler::new1}, 00180 { "format" ,"dddd" ,SerialHandler::format}, 00181 { "readable" ,"d" ,SerialHandler::readable}, 00182 { "writeable" ,"d" ,SerialHandler::writeable}, 00183 { "send_break" ,"d" ,SerialHandler::send_break}, 00184 { "putc" ,"dd" ,SerialHandler::putc}, 00185 { "puts" ,"ds" ,SerialHandler::puts}, 00186 { "getc" ,"d" ,SerialHandler::getc}, 00187 { "gets" ,"db" ,SerialHandler::gets}, 00188 { "baud" ,"dd" ,SerialHandler::baud}, 00189 { "gets_2" ,"db" ,SerialHandler::gets_2}, 00190 { "puts_2" ,"dB" ,SerialHandler::puts_2}, 00191 { NULL ,NULL ,NULL} 00192 }; 00193 00194 const struct NyLPC_TJsonRpcClassDef MbedJsApi::RPC_MBED_SERIAL={ 00195 "mbedJS","Serial",func_table 00196 }; 00197 00198 00199 00200 } 00201
Generated on Tue Jul 12 2022 16:22:59 by
