This is a Json-RPC/2.0 server with websocket and httpd. You can control mbed(s) by Javascript, processing, Java. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088
Dependencies: NyFileSystems libMiMic mbed-rtos mbed
Fork of MiMicRemoteMCU-for-Mbed by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "SDFileSystem.h" 00004 #include "mimic.h" 00005 #include "fsdata.h" 00006 #include "rpctbl.h" 00007 /** 00008 * local filesystem support. 00009 * MiMic::LocalFileSystem2 do not freeze on LPCXpresso. 00010 */ 00011 LocalFileSystem2 lf("local"); 00012 00013 /** 00014 * initialization 00015 */ 00016 #if defined(TARGET_LPC1768) || defined(TARGET_LPC4088) 00017 void pf_init() 00018 { 00019 } 00020 SDFileSystem sd(p5, p6, p7, p8,"sd"); 00021 #elif defined(TARGET_K64F) 00022 void pf_init() 00023 { 00024 DigitalOut led_r(LED1); 00025 DigitalOut led_g(LED2); 00026 DigitalOut led_b(LED3); 00027 led_r=1; 00028 led_b=1; 00029 led_g=1; 00030 } 00031 #endif 00032 00033 00034 00035 00036 /** 00037 * MiMic RemoteMCU httpd.<br/> 00038 * <p>Service list</p> 00039 * <pre> 00040 * /rom/ - romfs 00041 * /setup/ - MiMic configulation REST API. 00042 * /local/ - mbed LocalFileSystem 00043 * /mvm/ - MiMicVM REST API 00044 * </pre> 00045 */ 00046 class MiMicRemoteMcu:public MiMic::Httpd 00047 { 00048 private: 00049 ModRomFiles modromfs; //ROM file module 00050 ModMiMicSetting mimicsetting; //mimic setting API 00051 ModRemoteMcu remotemcu; // remotemcu API 00052 ModLocalFileSystem modlocal; //FileSystem mounter 00053 ModLocalFileSystem modsd; //FileSystem mounter 00054 ModFileIo modfio; //fileupload API 00055 ModUPnPDevice modupnp; 00056 ModJsonRpc modrpc; 00057 public: 00058 MiMicRemoteMcu(Net& i_net,NetConfig& i_cfg):Httpd(i_cfg.getHttpPort()) 00059 { 00060 this->modromfs.setParam("rom",RMCU_FSDATA,18); 00061 this->mimicsetting.setParam("setup"); 00062 this->remotemcu.setParam("mvm"); 00063 this->modlocal.setParam("local"); 00064 this->modsd.setParam("sd",ModLocalFileSystem::FST_SDFATFS); 00065 this->modfio.setParam("fio"); 00066 this->modupnp.setParam(i_net); 00067 this->modrpc.setParam("rpc",RPCTBL); 00068 } 00069 /** 00070 * Http handler 00071 */ 00072 virtual void onRequest(HttpdConnection& i_connection) 00073 { 00074 //pause persistent mode if websocket ready. 00075 if(this->modrpc.isStarted()){ 00076 i_connection.breakPersistentConnection(); 00077 } 00078 //try to ModRomFS module. 00079 if(this->modromfs.execute(i_connection)){ 00080 return; 00081 } 00082 //try to ModMiMicSetting module. 00083 if(this->mimicsetting.execute(i_connection)){ 00084 return; 00085 } 00086 //try to ModRemoteMcu module. 00087 if(this->remotemcu.execute(i_connection)){ 00088 return; 00089 } 00090 //try to ModLocalFileSystem 00091 if(this->modlocal.execute(i_connection)){ 00092 return; 00093 } 00094 //try to ModLocalFileSystem(SD) 00095 if(this->modsd.execute(i_connection)){ 00096 return; 00097 } 00098 //try to FileUpload 00099 if(this->modfio.execute(i_connection)){ 00100 return; 00101 } 00102 //try to UPnP 00103 if(this->modupnp.execute(i_connection)){ 00104 return; 00105 } 00106 if(this->modrpc.execute(i_connection)){ 00107 this->modrpc.dispatchRpc(); 00108 return; 00109 } 00110 00111 //Otherwise, Send the redirect response to /rom/index.html 00112 i_connection.sendHeader(302, 00113 "text/html", 00114 "Status: 302:Moved Temporarily\r\n" 00115 "Location: /rom/index.html\r\n"); 00116 return; 00117 } 00118 }; 00119 00120 /* 00121 extern "C" void setLed(int i){ 00122 switch(i){ 00123 case 0:{DigitalOut led_r(p23);led_r=0;}break; 00124 case 1:{DigitalOut led_g(p24);led_g=0;}break; 00125 case 2:{DigitalOut led_b(p25);led_b=0;}break; 00126 } 00127 }*/ 00128 00129 00130 MiMicRemoteMcu* httpd; //create a httpd instance. 00131 char friendly_name[48];//32(HostNameMAX)+16で十分(mbedJSの場合) 00132 int main() 00133 { 00134 MiMicNetIf netif; 00135 Net net(netif);//Net constructor must be created after started RTOS 00136 NetConfig cfg; //create network configulation with onchip-setting. 00137 pf_init(); 00138 //Prepare configulation. 00139 cfg.setUPnPIcon(64,64,8,"image/png","/rom/icon.png"); 00140 cfg.setUPnPUdn(0xe29f7101,0x4ba2,0x01e0,0); 00141 cfg.setUPnPPresentationURL("/rom/index.html"); 00142 //try to override setting by local file. 00143 if(!cfg.loadFromFile("/local/mimic.cfg")){ 00144 Thread::wait(2000);//wait for SD card initialization. 00145 cfg.loadFromFile("/sd/mimic.cfg"); 00146 } 00147 //FriendlyNameの上書き 00148 strcpy(friendly_name,"mbedJS-"); 00149 strcpy(friendly_name+7,cfg.getHostName()); 00150 cfg.setFriendlyName(friendly_name); 00151 00152 00153 httpd=new MiMicRemoteMcu(net,cfg); //create a httpd instance. 00154 net.start(cfg); 00155 httpd->loop(); //start httpd loop. 00156 return 0; 00157 }
Generated on Fri Jul 15 2022 12:44:23 by 1.7.2