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 httpServer by
FsHandler.cpp
00001 /* FsHandler.cpp */ 00002 #include "mbed.h" 00003 #include "FsHandler.h" 00004 //#define DEBUG 00005 #include "hl_debug.h" 00006 #include "pwm_tone.h" 00007 00008 PwmOut Buzzer1(D5); 00009 PwmOut Buzzer2(D6); 00010 PwmOut Buzzer3(D11); 00011 PwmOut Buzzer4(D12); 00012 00013 float C_3 = 1000000/Do3, 00014 Cs_3 = 1000000/Do3s, 00015 D_3 = 1000000/Re3, 00016 Ds_3 = 1000000/Re3s, 00017 E_3 = 1000000/Mi3, 00018 F_3 = 1000000/Fa3, 00019 Fs_3 = 1000000/Fa3s, 00020 G_3 = 1000000/So3, 00021 Gs_3 = 1000000/So3s, 00022 A_3 = 1000000/La3, 00023 As_3 = 1000000/La3s, 00024 B_3 = 1000000/Ti3, 00025 C_4 = 1000000/Do4, 00026 Cs_4 = 1000000/Do4s, 00027 D_4 = 1000000/Re4, 00028 Ds_4 = 1000000/Re4s, 00029 E_4 = 1000000/Mi4, 00030 F_4 = 1000000/Fa4, 00031 Fs_4 = 1000000/Fa4s, 00032 G_4 = 1000000/So4, 00033 Gs_4 = 1000000/So4s, 00034 A_4 = 1000000/La4, 00035 As_4 = 1000000/La4s, 00036 B_4 = 1000000/Ti4, 00037 C_5 = 1000000/Do5, 00038 Cs_5 = 1000000/Do5s, 00039 D_5 = 1000000/Re5, 00040 Ds_5 = 1000000/Re5s, 00041 E_5 = 1000000/Mi5, 00042 F_5 = 1000000/Fa5, 00043 Fs_5 = 1000000/Fa5s, 00044 G_5 = 1000000/So5, 00045 Gs_5 = 1000000/So5s, 00046 A_5 = 1000000/La5, 00047 As_5 = 1000000/La5s, 00048 B_5 = 1000000/Ti5, 00049 C_6 = 1000000/Do6, 00050 Cs_6 = 1000000/Do6s, 00051 D_6 = 1000000/Re6, 00052 Ds_6 = 1000000/Re6s, 00053 E_6 = 1000000/Mi6, 00054 F_6 = 1000000/Fa6, 00055 Fs_6 = 1000000/Fa6s, 00056 G_6 = 1000000/So6, 00057 Gs_6 = 1000000/So6s, 00058 A_6 = 1000000/La6, 00059 As_6 = 1000000/La6s, 00060 B_6 = 1000000/Ti6; 00061 00062 int mario1[80] = {E_5,E_5,0,E_5,0,C_5,E_5,0, 00063 G_5,0,0,0,G_4,0,0,0, 00064 C_5,0,0,G_4,0,0,E_4,0, 00065 E_4,A_4,0,B_4,0,As_4,A_4,0, 00066 G_4,E_5,G_5,0,A_5,0,F_5,G_5, 00067 0,E_5,0,C_5,D_5,B_4,0,0, 00068 C_5,0,0,G_4,0,0,E_4,0, 00069 E_4,A_4,0,B_4,0,As_4,A_4,0, 00070 G_4,E_5,G_5,0,A_5,0,F_5,G_5, 00071 0,E_5,0,C_5,D_5,B_4,0,0 00072 }; 00073 int mario2[80] = {Fs_4,F_4,0,F_4,0,F_4,F_4,0, 00074 G_4,0,0,0,0,0,0,0, 00075 E_4,0,0,E_4,0,0,C_4,0, 00076 C_4,C_4,0,D_4,0,Cs_4,C_4,0, 00077 C_4,G_4,B_4,0,C_5,0,A_4,B_4, 00078 0,G_4,0,E_4,F_4,D_4,0,0, 00079 E_4,0,0,E_4,0,0,C_4,0, 00080 C_4,C_4,0,D_4,0,Cs_4,C_4,0, 00081 C_4,G_4,B_4,0,C_5,0,A_4,B_4, 00082 0,G_4,0,E_4,F_4,D_4,0,0 00083 }; 00084 int mario3[80] = {B_4,B_4,0,B_4,0,B_4,B_4,0, 00085 E_5,0,0,0,E_5,0,0,0, 00086 E_5,0,0,C_4,0,0,A_4,0, 00087 A_4,D_5,0,E_5,0,Ds_5,D_5,0, 00088 C_5,A_5,C_6,0,D_6,0,B_5,C_6, 00089 0,A_5,0,F_5,G_5,E_5,0,0, 00090 E_5,0,0,C_5,0,0,A_4,0, 00091 A_4,D_5,0,E_5,0,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,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,A_3,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0,D_4,0,0,0}; 00100 00101 int tones_num = 80; 00102 int love_num = 512; 00103 00104 static int matchstrings(const char* one, const char* two) 00105 { 00106 int m = 0; 00107 00108 for (m = 0; m < min(strlen(one), strlen(two)) ; m++) { 00109 if (one[m] != two[m]) 00110 return m; 00111 } 00112 return m; 00113 } 00114 00115 std::map<const char*, const char*> HTTPFsRequestHandler::m_fsMap; 00116 00117 HTTPFsRequestHandler::HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp) 00118 : HTTPRequestHandler(Msg, Tcp) 00119 { 00120 m_rootPath = rootPath; 00121 m_localPath = localPath; 00122 00123 string myPath = m_rootPath + m_localPath; 00124 00125 // Now replace the virtual root path with a mounted device path 00126 std::map<const char*, const char*>::iterator it; 00127 const char *bestMatch = NULL; 00128 const char *bestMatchExchange = NULL; 00129 int match_ind = -1; 00130 for (it = m_fsMap.begin() ; it != m_fsMap.end() ; it++) { 00131 // find best match (if the given logical path is containted in the root 00132 int s = matchstrings(myPath.c_str(), it->second); 00133 INFO("Matching Root %s with handler %s results in %d identical characters\n", myPath.c_str(), it->second, s); 00134 if ((s == strlen(it->second)) && (s > match_ind)) { 00135 match_ind = s; 00136 bestMatch = it->first; 00137 bestMatchExchange = it->second; 00138 } 00139 } 00140 00141 if (bestMatch != NULL) { 00142 m_rootPath = bestMatch; 00143 m_localPath = string(myPath).substr(strlen(bestMatchExchange)); 00144 } 00145 00146 handleRequest(); 00147 } 00148 00149 HTTPFsRequestHandler::~HTTPFsRequestHandler() 00150 { 00151 } 00152 00153 std::map<int, EthernetInterface*> HTTPFsRequestHandler::m_eth_list; 00154 00155 int HTTPFsRequestHandler::handleGetRequest() 00156 { 00157 HTTPHeaders headers; 00158 EthernetInterface test_eth; 00159 int retval = 0; //success 00160 00161 if( std::string::npos != msg.uri.find("get_netinfo.cgi") ) 00162 { 00163 char buf[256]; 00164 00165 sprintf(buf, "NetinfoCallback({\"mac\":\"%s\",\"ip\":\"%s\",\"sn\":\"%s\",\"gw\":\"%s\",\"temp\":\"%s\"});" 00166 ,m_eth_list[0]->getMACAddress(),m_eth_list[0]->getIPAddress(),m_eth_list[0]->getNetworkMask(),m_eth_list[0]->getGateway()); 00167 00168 tcp.send(buf, strlen(buf)); 00169 } 00170 00171 else if( std::string::npos != msg.uri.find("get_ain.cgi") ) 00172 { 00173 char buf[256]; 00174 00175 //sprintf(buf, "AinCallback({\"ain_v0\":\"%.3f\",\"ain_v1\":\"%.3f\"});",ain0.read()*100, ain1.read()*100); 00176 00177 tcp.send(buf, strlen(buf)); 00178 } 00179 00180 else //read html pages 00181 { 00182 if (m_localPath.length() > 4) 00183 getStandardHeaders(headers, m_localPath.substr(m_localPath.length()-4).c_str()); 00184 else 00185 getStandardHeaders(headers); 00186 00187 INFO("Handling Get Request (root = %s, local = %s).", m_rootPath.c_str(), m_localPath.c_str()); 00188 00189 std::string reqPath; 00190 00191 // Check if we received a directory with the local bath 00192 if ((m_localPath.length() == 0) || (m_localPath.substr( m_localPath.length()-1, 1) == "/")) { 00193 // yes, we shall append the default page name 00194 m_localPath += "index.html"; 00195 } 00196 00197 reqPath = m_rootPath + m_localPath; 00198 00199 INFO("Mapping \"%s\" to \"%s\"", msg.uri.c_str(), reqPath.c_str()); 00200 00201 FILE *fp = fopen(reqPath.c_str(), "r"); 00202 if (fp != NULL) { 00203 char * pBuffer = NULL; 00204 int sz = 8192; 00205 while( pBuffer == NULL) { 00206 sz /= 2; 00207 pBuffer = (char*)malloc(sz); 00208 if (sz < 128) 00209 error ("OutOfMemory"); 00210 } 00211 00212 // File was found and can be returned 00213 00214 // first determine the size 00215 fseek(fp, 0, SEEK_END); 00216 long size = ftell(fp); 00217 fseek(fp, 0, SEEK_SET); 00218 00219 startResponse(200, size); 00220 while(!feof(fp) && !ferror(fp)) { 00221 int cnt = fread(pBuffer, 1, sz , fp); 00222 if (cnt < 0) 00223 cnt = 0; 00224 processResponse(cnt, pBuffer); 00225 } 00226 delete pBuffer; 00227 endResponse(); 00228 fclose(fp); 00229 } 00230 else { 00231 retval = 404; 00232 ERR("Requested file was not found !"); 00233 } 00234 } 00235 00236 return retval; 00237 } 00238 00239 int HTTPFsRequestHandler::handlePostRequest() 00240 { 00241 int pin = 0; 00242 int i; 00243 00244 if( std::string::npos != msg.uri.find("set_LED.cgi") ) 00245 { 00246 pin = get_http_param_value("pin"); 00247 if(pin==0) Tune(Buzzer1, C_4, 4); 00248 else if(pin==1) Tune(Buzzer1, Cs_4, 4); 00249 else if(pin==2) Tune(Buzzer1, D_4, 4); 00250 else if(pin==3) Tune(Buzzer1, Ds_4, 4); 00251 else if(pin==4) Tune(Buzzer1, E_4, 4); 00252 else if(pin==5) Tune(Buzzer1, F_4, 4); 00253 else if(pin==6) Tune(Buzzer1, Fs_4, 4); 00254 else if(pin==7) Tune(Buzzer1, G_4, 4); 00255 else if(pin==8) Tune(Buzzer1, Gs_4, 4); 00256 else if(pin==9) Tune(Buzzer1, A_4, 4); 00257 else if(pin==10) Tune(Buzzer1, As_4, 4); 00258 else if(pin==11) Tune(Buzzer1, B_4, 4); 00259 else if(pin==12) Tune(Buzzer1, C_5, 4); 00260 else if(pin==13) Tune(Buzzer1, Cs_5, 4); 00261 else if(pin==14) Tune(Buzzer1, D_5, 4); 00262 else if(pin==15) Tune(Buzzer1, Ds_5, 4); 00263 else if(pin==16) Tune(Buzzer1, E_5, 4); 00264 else if(pin==17) Tune(Buzzer1, F_5, 4); 00265 else if(pin==18) Tune(Buzzer1, Fs_5, 4); 00266 else if(pin==19) Tune(Buzzer1, G_5, 4); 00267 else if(pin==20) Tune(Buzzer1, Gs_5, 4); 00268 else if(pin==21) Tune(Buzzer1, A_5, 4); 00269 else if(pin==22) Tune(Buzzer1, As_5, 4); 00270 else if(pin==23) Tune(Buzzer1, B_5, 4); 00271 else 00272 { 00273 WARN("Wrong pin number"); 00274 } 00275 00276 return 0; 00277 } 00278 else if( std::string::npos != msg.uri.find("set_AUTO.cgi") ) 00279 { 00280 pin = get_http_param_value("pin"); 00281 if(pin==0) 00282 { 00283 for(i=0; i<tones_num; i++) 00284 { 00285 Auto_tunes(Buzzer1, mario1[i], 1); // Auto performance 00286 Auto_tunes(Buzzer2, mario2[i], 1); // Auto performance 00287 Auto_tunes(Buzzer3, mario3[i], 1); // Auto performance 00288 Stop_tunes(Buzzer1); 00289 Stop_tunes(Buzzer2); 00290 Stop_tunes(Buzzer3); 00291 } 00292 } 00293 else if(pin == 1) 00294 { 00295 for(i=0; i<love_num; i++) 00296 { 00297 //Auto_tunes(Buzzer1, love1[i], 1); // Auto performance 00298 //Auto_tunes(Buzzer2, love2[i], 1); // Auto performance 00299 //Auto_tunes(Buzzer3, love3[i], 1); // Auto performance 00300 //Auto_tunes(Buzzer4, love4[i], 1); // Auto performance 00301 Stop_tunes(Buzzer1); 00302 Stop_tunes(Buzzer2); 00303 Stop_tunes(Buzzer3); 00304 Stop_tunes(Buzzer4); 00305 } 00306 } 00307 else if(pin == 99) 00308 { 00309 ; 00310 } 00311 else 00312 { 00313 WARN("Wrong pin number"); 00314 } 00315 00316 return 0; 00317 } 00318 else 00319 { 00320 return 404; 00321 } 00322 } 00323 00324 int HTTPFsRequestHandler::handlePutRequest() 00325 { 00326 return 404; 00327 } 00328 00329 uint32_t HTTPFsRequestHandler::get_http_param_value(char* param_name) 00330 { 00331 uint8_t * name = 0; 00332 uint8_t * pos2; 00333 uint16_t len = 0; 00334 char value[10]; 00335 uint32_t ret = 0; 00336 00337 //msg.attri 00338 if((name = (uint8_t *)strstr(msg.attri, param_name))) 00339 { 00340 name += strlen(param_name) + 1; 00341 pos2 = (uint8_t*)strstr((char*)name, "&"); 00342 if(!pos2) 00343 { 00344 pos2 = name + strlen((char*)name); 00345 } 00346 len = pos2 - name; 00347 00348 if(len) 00349 { 00350 strncpy(value, (char*)name, len); 00351 ret = atoi(value); 00352 } 00353 } 00354 return ret; 00355 } 00356 00357
Generated on Wed Jul 13 2022 05:01:21 by
1.7.2
