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
RpcMcu.cpp
00001 #include "RpcHandlerBase.h" 00002 /** 00003 * malloc出来る最大サイズを得る関数 00004 */ 00005 static int getFreeMemory() 00006 { 00007 int size=1; 00008 for(;;){ 00009 void* buf=malloc(size); 00010 if(buf==NULL){ 00011 break; 00012 } 00013 free(buf); 00014 size*=2; 00015 } 00016 int min=size/2; 00017 int max=size; 00018 for(;;){ 00019 int n=(max+min)/2; 00020 void* b=malloc(n); 00021 if(b){ 00022 free(b); 00023 min=n; 00024 }else{ 00025 max=n; 00026 } 00027 if(max-min==1){ 00028 return min; 00029 } 00030 } 00031 } 00032 namespace MiMic 00033 { 00034 class McuHandler :RpcHandlerBase 00035 { 00036 public: 00037 static NyLPC_TBool disposeObject(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00038 { 00039 //d 00040 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00041 int id; 00042 if(getParamInt(mod,i_rpc,id,0)){ 00043 mod->putResult(i_rpc->method.id,"%d",mod->removeObject(id)); 00044 } 00045 return NyLPC_TBool_TRUE; 00046 } 00047 /** idに合致するオブジェクトを削除します。 00048 * RPC-returnは1:成功、0:失敗です。 00049 */ 00050 static NyLPC_TBool getInfo(const union NyLPC_TJsonRpcParserResult* i_rpc,void* i_param) 00051 { 00052 //d return d 00053 ModJsonRpc* mod=((ModJsonRpc::TcJsonRpcEx_t*)i_param)->cppmod_ptr; 00054 //version,mcu,memoryの順 00055 mod->putResult(i_rpc->method.id, 00056 "\"%s\",\"%s\",\"%s\",\"%s\",%d", 00057 NyLPC_cMiMicEnv_getStrProperty(NyLPC_cMiMicEnv_VERSION), 00058 NyLPC_cMiMicEnv_getStrProperty(NyLPC_cMiMicEnv_SHORT_NAME), 00059 NyLPC_cMiMicEnv_getStrProperty(NyLPC_cMiMicEnv_ETHERNET_PHY), 00060 NyLPC_cMiMicEnv_getStrProperty(NyLPC_cMiMicEnv_MCU_NAME), 00061 /*getFreeMemory()*/-1); 00062 return NyLPC_TBool_TRUE; 00063 } 00064 }; 00065 00066 const static struct NyLPC_TJsonRpcMethodDef func_table[]= 00067 { 00068 { "getInfo" ,"" ,McuHandler::getInfo}, 00069 { "disposeObject","d",McuHandler::disposeObject}, 00070 { NULL ,NULL ,NULL} 00071 }; 00072 00073 const struct NyLPC_TJsonRpcClassDef MbedJsApi::RPC_MBED_MCU={ 00074 "mbedJS","Mcu",func_table 00075 }; 00076 00077 00078 00079 } 00080
Generated on Tue Jul 12 2022 16:22:59 by
1.7.2
