for internet orgel

Dependents:   Internet_Orgel

Fork of httpServer by justin kim

Committer:
justinkim
Date:
Thu Jun 02 00:58:45 2016 +0000
Revision:
6:9aefb9ff74ce
Parent:
5:3c24e937da61
internet orgel

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hjjeon 0:e59cc54df17c 1 /* FsHandler.cpp */
hjjeon 0:e59cc54df17c 2 #include "mbed.h"
hjjeon 0:e59cc54df17c 3 #include "FsHandler.h"
hjjeon 0:e59cc54df17c 4 //#define DEBUG
hjjeon 0:e59cc54df17c 5 #include "hl_debug.h"
justinkim 6:9aefb9ff74ce 6 #include "pwm_tone.h"
hjjeon 0:e59cc54df17c 7
justinkim 6:9aefb9ff74ce 8 PwmOut Buzzer1(D5);
justinkim 6:9aefb9ff74ce 9 PwmOut Buzzer2(D6);
justinkim 6:9aefb9ff74ce 10 PwmOut Buzzer3(D11);
justinkim 6:9aefb9ff74ce 11 PwmOut Buzzer4(D12);
hjjeon 0:e59cc54df17c 12
justinkim 6:9aefb9ff74ce 13 float C_3 = 1000000/Do3,
justinkim 6:9aefb9ff74ce 14 Cs_3 = 1000000/Do3s,
justinkim 6:9aefb9ff74ce 15 D_3 = 1000000/Re3,
justinkim 6:9aefb9ff74ce 16 Ds_3 = 1000000/Re3s,
justinkim 6:9aefb9ff74ce 17 E_3 = 1000000/Mi3,
justinkim 6:9aefb9ff74ce 18 F_3 = 1000000/Fa3,
justinkim 6:9aefb9ff74ce 19 Fs_3 = 1000000/Fa3s,
justinkim 6:9aefb9ff74ce 20 G_3 = 1000000/So3,
justinkim 6:9aefb9ff74ce 21 Gs_3 = 1000000/So3s,
justinkim 6:9aefb9ff74ce 22 A_3 = 1000000/La3,
justinkim 6:9aefb9ff74ce 23 As_3 = 1000000/La3s,
justinkim 6:9aefb9ff74ce 24 B_3 = 1000000/Ti3,
justinkim 6:9aefb9ff74ce 25 C_4 = 1000000/Do4,
justinkim 6:9aefb9ff74ce 26 Cs_4 = 1000000/Do4s,
justinkim 6:9aefb9ff74ce 27 D_4 = 1000000/Re4,
justinkim 6:9aefb9ff74ce 28 Ds_4 = 1000000/Re4s,
justinkim 6:9aefb9ff74ce 29 E_4 = 1000000/Mi4,
justinkim 6:9aefb9ff74ce 30 F_4 = 1000000/Fa4,
justinkim 6:9aefb9ff74ce 31 Fs_4 = 1000000/Fa4s,
justinkim 6:9aefb9ff74ce 32 G_4 = 1000000/So4,
justinkim 6:9aefb9ff74ce 33 Gs_4 = 1000000/So4s,
justinkim 6:9aefb9ff74ce 34 A_4 = 1000000/La4,
justinkim 6:9aefb9ff74ce 35 As_4 = 1000000/La4s,
justinkim 6:9aefb9ff74ce 36 B_4 = 1000000/Ti4,
justinkim 6:9aefb9ff74ce 37 C_5 = 1000000/Do5,
justinkim 6:9aefb9ff74ce 38 Cs_5 = 1000000/Do5s,
justinkim 6:9aefb9ff74ce 39 D_5 = 1000000/Re5,
justinkim 6:9aefb9ff74ce 40 Ds_5 = 1000000/Re5s,
justinkim 6:9aefb9ff74ce 41 E_5 = 1000000/Mi5,
justinkim 6:9aefb9ff74ce 42 F_5 = 1000000/Fa5,
justinkim 6:9aefb9ff74ce 43 Fs_5 = 1000000/Fa5s,
justinkim 6:9aefb9ff74ce 44 G_5 = 1000000/So5,
justinkim 6:9aefb9ff74ce 45 Gs_5 = 1000000/So5s,
justinkim 6:9aefb9ff74ce 46 A_5 = 1000000/La5,
justinkim 6:9aefb9ff74ce 47 As_5 = 1000000/La5s,
justinkim 6:9aefb9ff74ce 48 B_5 = 1000000/Ti5,
justinkim 6:9aefb9ff74ce 49 C_6 = 1000000/Do6,
justinkim 6:9aefb9ff74ce 50 Cs_6 = 1000000/Do6s,
justinkim 6:9aefb9ff74ce 51 D_6 = 1000000/Re6,
justinkim 6:9aefb9ff74ce 52 Ds_6 = 1000000/Re6s,
justinkim 6:9aefb9ff74ce 53 E_6 = 1000000/Mi6,
justinkim 6:9aefb9ff74ce 54 F_6 = 1000000/Fa6,
justinkim 6:9aefb9ff74ce 55 Fs_6 = 1000000/Fa6s,
justinkim 6:9aefb9ff74ce 56 G_6 = 1000000/So6,
justinkim 6:9aefb9ff74ce 57 Gs_6 = 1000000/So6s,
justinkim 6:9aefb9ff74ce 58 A_6 = 1000000/La6,
justinkim 6:9aefb9ff74ce 59 As_6 = 1000000/La6s,
justinkim 6:9aefb9ff74ce 60 B_6 = 1000000/Ti6;
justinkim 6:9aefb9ff74ce 61
justinkim 6:9aefb9ff74ce 62 int mario1[80] = {E_5,E_5,0,E_5,0,C_5,E_5,0,
justinkim 6:9aefb9ff74ce 63 G_5,0,0,0,G_4,0,0,0,
justinkim 6:9aefb9ff74ce 64 C_5,0,0,G_4,0,0,E_4,0,
justinkim 6:9aefb9ff74ce 65 E_4,A_4,0,B_4,0,As_4,A_4,0,
justinkim 6:9aefb9ff74ce 66 G_4,E_5,G_5,0,A_5,0,F_5,G_5,
justinkim 6:9aefb9ff74ce 67 0,E_5,0,C_5,D_5,B_4,0,0,
justinkim 6:9aefb9ff74ce 68 C_5,0,0,G_4,0,0,E_4,0,
justinkim 6:9aefb9ff74ce 69 E_4,A_4,0,B_4,0,As_4,A_4,0,
justinkim 6:9aefb9ff74ce 70 G_4,E_5,G_5,0,A_5,0,F_5,G_5,
justinkim 6:9aefb9ff74ce 71 0,E_5,0,C_5,D_5,B_4,0,0
justinkim 6:9aefb9ff74ce 72 };
justinkim 6:9aefb9ff74ce 73 int mario2[80] = {Fs_4,F_4,0,F_4,0,F_4,F_4,0,
justinkim 6:9aefb9ff74ce 74 G_4,0,0,0,0,0,0,0,
justinkim 6:9aefb9ff74ce 75 E_4,0,0,E_4,0,0,C_4,0,
justinkim 6:9aefb9ff74ce 76 C_4,C_4,0,D_4,0,Cs_4,C_4,0,
justinkim 6:9aefb9ff74ce 77 C_4,G_4,B_4,0,C_5,0,A_4,B_4,
justinkim 6:9aefb9ff74ce 78 0,G_4,0,E_4,F_4,D_4,0,0,
justinkim 6:9aefb9ff74ce 79 E_4,0,0,E_4,0,0,C_4,0,
justinkim 6:9aefb9ff74ce 80 C_4,C_4,0,D_4,0,Cs_4,C_4,0,
justinkim 6:9aefb9ff74ce 81 C_4,G_4,B_4,0,C_5,0,A_4,B_4,
justinkim 6:9aefb9ff74ce 82 0,G_4,0,E_4,F_4,D_4,0,0
justinkim 6:9aefb9ff74ce 83 };
justinkim 6:9aefb9ff74ce 84 int mario3[80] = {B_4,B_4,0,B_4,0,B_4,B_4,0,
justinkim 6:9aefb9ff74ce 85 E_5,0,0,0,E_5,0,0,0,
justinkim 6:9aefb9ff74ce 86 E_5,0,0,C_4,0,0,A_4,0,
justinkim 6:9aefb9ff74ce 87 A_4,D_5,0,E_5,0,Ds_5,D_5,0,
justinkim 6:9aefb9ff74ce 88 C_5,A_5,C_6,0,D_6,0,B_5,C_6,
justinkim 6:9aefb9ff74ce 89 0,A_5,0,F_5,G_5,E_5,0,0,
justinkim 6:9aefb9ff74ce 90 E_5,0,0,C_5,0,0,A_4,0,
justinkim 6:9aefb9ff74ce 91 A_4,D_5,0,E_5,0,Ds_5,D_5,0,
justinkim 6:9aefb9ff74ce 92 C_5,A_5,C_6,0,D_6,0,B_5,C_6,
justinkim 6:9aefb9ff74ce 93 0,A_5,0,F_5,G_5,E_5,0,0
justinkim 6:9aefb9ff74ce 94 };
justinkim 6:9aefb9ff74ce 95
justinkim 6:9aefb9ff74ce 96 //int love1[512] = {G_4,0,0,0,0,0,0,0,0,0,0,0,B_4,0,0,G_4,F_4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,E_4,0,0,0,0,0,0,0,0,0,0,0,C_5,0,0,G_4,D_4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,C_5,0,0,0,0,0,0,0,0,0,0,0,C_5,B_4,A_4,0,G_4,0,0,B_4,B_4,0,0,0,0,0,0,0,0,0,0,0,A_4,0,0,0,0,0,0,0,0,0,0,0,A_4,0,0,G_4,G_4,0,0,0,0,0,0,0,0,0,0,0,B_4,0,C_5,B_4,G_4,0,0,0,0,0,0,0,0,0,0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)
hjjeon 0:e59cc54df17c 105 {
hjjeon 0:e59cc54df17c 106 int m = 0;
hjjeon 0:e59cc54df17c 107
hjjeon 0:e59cc54df17c 108 for (m = 0; m < min(strlen(one), strlen(two)) ; m++) {
hjjeon 0:e59cc54df17c 109 if (one[m] != two[m])
hjjeon 0:e59cc54df17c 110 return m;
hjjeon 0:e59cc54df17c 111 }
hjjeon 0:e59cc54df17c 112 return m;
hjjeon 0:e59cc54df17c 113 }
hjjeon 0:e59cc54df17c 114
hjjeon 0:e59cc54df17c 115 std::map<const char*, const char*> HTTPFsRequestHandler::m_fsMap;
hjjeon 0:e59cc54df17c 116
hjjeon 0:e59cc54df17c 117 HTTPFsRequestHandler::HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp)
hjjeon 0:e59cc54df17c 118 : HTTPRequestHandler(Msg, Tcp)
hjjeon 0:e59cc54df17c 119 {
hjjeon 0:e59cc54df17c 120 m_rootPath = rootPath;
hjjeon 0:e59cc54df17c 121 m_localPath = localPath;
hjjeon 0:e59cc54df17c 122
hjjeon 0:e59cc54df17c 123 string myPath = m_rootPath + m_localPath;
hjjeon 0:e59cc54df17c 124
hjjeon 0:e59cc54df17c 125 // Now replace the virtual root path with a mounted device path
hjjeon 0:e59cc54df17c 126 std::map<const char*, const char*>::iterator it;
hjjeon 0:e59cc54df17c 127 const char *bestMatch = NULL;
hjjeon 0:e59cc54df17c 128 const char *bestMatchExchange = NULL;
hjjeon 0:e59cc54df17c 129 int match_ind = -1;
hjjeon 0:e59cc54df17c 130 for (it = m_fsMap.begin() ; it != m_fsMap.end() ; it++) {
hjjeon 0:e59cc54df17c 131 // find best match (if the given logical path is containted in the root
hjjeon 0:e59cc54df17c 132 int s = matchstrings(myPath.c_str(), it->second);
hjjeon 0:e59cc54df17c 133 INFO("Matching Root %s with handler %s results in %d identical characters\n", myPath.c_str(), it->second, s);
hjjeon 0:e59cc54df17c 134 if ((s == strlen(it->second)) && (s > match_ind)) {
hjjeon 0:e59cc54df17c 135 match_ind = s;
hjjeon 0:e59cc54df17c 136 bestMatch = it->first;
hjjeon 0:e59cc54df17c 137 bestMatchExchange = it->second;
hjjeon 0:e59cc54df17c 138 }
hjjeon 0:e59cc54df17c 139 }
hjjeon 0:e59cc54df17c 140
hjjeon 0:e59cc54df17c 141 if (bestMatch != NULL) {
hjjeon 0:e59cc54df17c 142 m_rootPath = bestMatch;
hjjeon 0:e59cc54df17c 143 m_localPath = string(myPath).substr(strlen(bestMatchExchange));
hjjeon 0:e59cc54df17c 144 }
hjjeon 0:e59cc54df17c 145
hjjeon 0:e59cc54df17c 146 handleRequest();
hjjeon 0:e59cc54df17c 147 }
hjjeon 0:e59cc54df17c 148
hjjeon 0:e59cc54df17c 149 HTTPFsRequestHandler::~HTTPFsRequestHandler()
hjjeon 0:e59cc54df17c 150 {
hjjeon 0:e59cc54df17c 151 }
hjjeon 0:e59cc54df17c 152
justinkim 2:dd293a10a772 153 std::map<int, EthernetInterface*> HTTPFsRequestHandler::m_eth_list;
justinkim 2:dd293a10a772 154
hjjeon 0:e59cc54df17c 155 int HTTPFsRequestHandler::handleGetRequest()
hjjeon 0:e59cc54df17c 156 {
hjjeon 0:e59cc54df17c 157 HTTPHeaders headers;
justinkim 2:dd293a10a772 158 EthernetInterface test_eth;
hjjeon 0:e59cc54df17c 159 int retval = 0; //success
hjjeon 0:e59cc54df17c 160
justinkim 2:dd293a10a772 161 if( std::string::npos != msg.uri.find("get_netinfo.cgi") )
hjjeon 0:e59cc54df17c 162 {
justinkim 2:dd293a10a772 163 char buf[256];
hjjeon 4:2903435e3811 164
hjjeon 4:2903435e3811 165 sprintf(buf, "NetinfoCallback({\"mac\":\"%s\",\"ip\":\"%s\",\"sn\":\"%s\",\"gw\":\"%s\",\"temp\":\"%s\"});"
justinkim 2:dd293a10a772 166 ,m_eth_list[0]->getMACAddress(),m_eth_list[0]->getIPAddress(),m_eth_list[0]->getNetworkMask(),m_eth_list[0]->getGateway());
justinkim 2:dd293a10a772 167
justinkim 2:dd293a10a772 168 tcp.send(buf, strlen(buf));
justinkim 2:dd293a10a772 169 }
justinkim 2:dd293a10a772 170
justinkim 2:dd293a10a772 171 else if( std::string::npos != msg.uri.find("get_ain.cgi") )
justinkim 2:dd293a10a772 172 {
justinkim 2:dd293a10a772 173 char buf[256];
hjjeon 0:e59cc54df17c 174
justinkim 5:3c24e937da61 175 //sprintf(buf, "AinCallback({\"ain_v0\":\"%.3f\",\"ain_v1\":\"%.3f\"});",ain0.read()*100, ain1.read()*100);
justinkim 2:dd293a10a772 176
justinkim 2:dd293a10a772 177 tcp.send(buf, strlen(buf));
hjjeon 0:e59cc54df17c 178 }
justinkim 2:dd293a10a772 179
hjjeon 0:e59cc54df17c 180 else //read html pages
hjjeon 0:e59cc54df17c 181 {
hjjeon 0:e59cc54df17c 182 if (m_localPath.length() > 4)
hjjeon 0:e59cc54df17c 183 getStandardHeaders(headers, m_localPath.substr(m_localPath.length()-4).c_str());
hjjeon 0:e59cc54df17c 184 else
hjjeon 0:e59cc54df17c 185 getStandardHeaders(headers);
hjjeon 0:e59cc54df17c 186
hjjeon 0:e59cc54df17c 187 INFO("Handling Get Request (root = %s, local = %s).", m_rootPath.c_str(), m_localPath.c_str());
hjjeon 0:e59cc54df17c 188
hjjeon 0:e59cc54df17c 189 std::string reqPath;
hjjeon 0:e59cc54df17c 190
hjjeon 0:e59cc54df17c 191 // Check if we received a directory with the local bath
hjjeon 0:e59cc54df17c 192 if ((m_localPath.length() == 0) || (m_localPath.substr( m_localPath.length()-1, 1) == "/")) {
hjjeon 0:e59cc54df17c 193 // yes, we shall append the default page name
hjjeon 0:e59cc54df17c 194 m_localPath += "index.html";
hjjeon 0:e59cc54df17c 195 }
hjjeon 0:e59cc54df17c 196
hjjeon 0:e59cc54df17c 197 reqPath = m_rootPath + m_localPath;
hjjeon 0:e59cc54df17c 198
hjjeon 0:e59cc54df17c 199 INFO("Mapping \"%s\" to \"%s\"", msg.uri.c_str(), reqPath.c_str());
hjjeon 0:e59cc54df17c 200
hjjeon 0:e59cc54df17c 201 FILE *fp = fopen(reqPath.c_str(), "r");
hjjeon 0:e59cc54df17c 202 if (fp != NULL) {
hjjeon 0:e59cc54df17c 203 char * pBuffer = NULL;
hjjeon 0:e59cc54df17c 204 int sz = 8192;
hjjeon 0:e59cc54df17c 205 while( pBuffer == NULL) {
hjjeon 0:e59cc54df17c 206 sz /= 2;
hjjeon 0:e59cc54df17c 207 pBuffer = (char*)malloc(sz);
hjjeon 0:e59cc54df17c 208 if (sz < 128)
hjjeon 0:e59cc54df17c 209 error ("OutOfMemory");
hjjeon 0:e59cc54df17c 210 }
hjjeon 0:e59cc54df17c 211
hjjeon 0:e59cc54df17c 212 // File was found and can be returned
hjjeon 0:e59cc54df17c 213
hjjeon 0:e59cc54df17c 214 // first determine the size
hjjeon 0:e59cc54df17c 215 fseek(fp, 0, SEEK_END);
hjjeon 0:e59cc54df17c 216 long size = ftell(fp);
hjjeon 0:e59cc54df17c 217 fseek(fp, 0, SEEK_SET);
hjjeon 0:e59cc54df17c 218
hjjeon 0:e59cc54df17c 219 startResponse(200, size);
hjjeon 0:e59cc54df17c 220 while(!feof(fp) && !ferror(fp)) {
hjjeon 0:e59cc54df17c 221 int cnt = fread(pBuffer, 1, sz , fp);
hjjeon 0:e59cc54df17c 222 if (cnt < 0)
hjjeon 0:e59cc54df17c 223 cnt = 0;
hjjeon 0:e59cc54df17c 224 processResponse(cnt, pBuffer);
hjjeon 0:e59cc54df17c 225 }
hjjeon 0:e59cc54df17c 226 delete pBuffer;
hjjeon 0:e59cc54df17c 227 endResponse();
hjjeon 0:e59cc54df17c 228 fclose(fp);
hjjeon 0:e59cc54df17c 229 }
hjjeon 0:e59cc54df17c 230 else {
hjjeon 0:e59cc54df17c 231 retval = 404;
hjjeon 0:e59cc54df17c 232 ERR("Requested file was not found !");
hjjeon 0:e59cc54df17c 233 }
hjjeon 0:e59cc54df17c 234 }
hjjeon 0:e59cc54df17c 235
hjjeon 0:e59cc54df17c 236 return retval;
hjjeon 0:e59cc54df17c 237 }
hjjeon 0:e59cc54df17c 238
hjjeon 0:e59cc54df17c 239 int HTTPFsRequestHandler::handlePostRequest()
hjjeon 0:e59cc54df17c 240 {
hjjeon 0:e59cc54df17c 241 int pin = 0;
justinkim 6:9aefb9ff74ce 242 int i;
hjjeon 0:e59cc54df17c 243
justinkim 6:9aefb9ff74ce 244 if( std::string::npos != msg.uri.find("set_LED.cgi") )
hjjeon 0:e59cc54df17c 245 {
hjjeon 0:e59cc54df17c 246 pin = get_http_param_value("pin");
justinkim 6:9aefb9ff74ce 247 if(pin==0) Tune(Buzzer1, C_4, 4);
justinkim 6:9aefb9ff74ce 248 else if(pin==1) Tune(Buzzer1, Cs_4, 4);
justinkim 6:9aefb9ff74ce 249 else if(pin==2) Tune(Buzzer1, D_4, 4);
justinkim 6:9aefb9ff74ce 250 else if(pin==3) Tune(Buzzer1, Ds_4, 4);
justinkim 6:9aefb9ff74ce 251 else if(pin==4) Tune(Buzzer1, E_4, 4);
justinkim 6:9aefb9ff74ce 252 else if(pin==5) Tune(Buzzer1, F_4, 4);
justinkim 6:9aefb9ff74ce 253 else if(pin==6) Tune(Buzzer1, Fs_4, 4);
justinkim 6:9aefb9ff74ce 254 else if(pin==7) Tune(Buzzer1, G_4, 4);
justinkim 6:9aefb9ff74ce 255 else if(pin==8) Tune(Buzzer1, Gs_4, 4);
justinkim 6:9aefb9ff74ce 256 else if(pin==9) Tune(Buzzer1, A_4, 4);
justinkim 6:9aefb9ff74ce 257 else if(pin==10) Tune(Buzzer1, As_4, 4);
justinkim 6:9aefb9ff74ce 258 else if(pin==11) Tune(Buzzer1, B_4, 4);
justinkim 6:9aefb9ff74ce 259 else if(pin==12) Tune(Buzzer1, C_5, 4);
justinkim 6:9aefb9ff74ce 260 else if(pin==13) Tune(Buzzer1, Cs_5, 4);
justinkim 6:9aefb9ff74ce 261 else if(pin==14) Tune(Buzzer1, D_5, 4);
justinkim 6:9aefb9ff74ce 262 else if(pin==15) Tune(Buzzer1, Ds_5, 4);
justinkim 6:9aefb9ff74ce 263 else if(pin==16) Tune(Buzzer1, E_5, 4);
justinkim 6:9aefb9ff74ce 264 else if(pin==17) Tune(Buzzer1, F_5, 4);
justinkim 6:9aefb9ff74ce 265 else if(pin==18) Tune(Buzzer1, Fs_5, 4);
justinkim 6:9aefb9ff74ce 266 else if(pin==19) Tune(Buzzer1, G_5, 4);
justinkim 6:9aefb9ff74ce 267 else if(pin==20) Tune(Buzzer1, Gs_5, 4);
justinkim 6:9aefb9ff74ce 268 else if(pin==21) Tune(Buzzer1, A_5, 4);
justinkim 6:9aefb9ff74ce 269 else if(pin==22) Tune(Buzzer1, As_5, 4);
justinkim 6:9aefb9ff74ce 270 else if(pin==23) Tune(Buzzer1, B_5, 4);
hjjeon 0:e59cc54df17c 271 else
hjjeon 0:e59cc54df17c 272 {
hjjeon 0:e59cc54df17c 273 WARN("Wrong pin number");
hjjeon 0:e59cc54df17c 274 }
hjjeon 0:e59cc54df17c 275
hjjeon 0:e59cc54df17c 276 return 0;
justinkim 6:9aefb9ff74ce 277 }
justinkim 6:9aefb9ff74ce 278 else if( std::string::npos != msg.uri.find("set_AUTO.cgi") )
justinkim 5:3c24e937da61 279 {
justinkim 6:9aefb9ff74ce 280 pin = get_http_param_value("pin");
justinkim 6:9aefb9ff74ce 281 if(pin==0)
justinkim 5:3c24e937da61 282 {
justinkim 6:9aefb9ff74ce 283 for(i=0; i<tones_num; i++)
justinkim 6:9aefb9ff74ce 284 {
justinkim 6:9aefb9ff74ce 285 Auto_tunes(Buzzer1, mario1[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 286 Auto_tunes(Buzzer2, mario2[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 287 Auto_tunes(Buzzer3, mario3[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 288 Stop_tunes(Buzzer1);
justinkim 6:9aefb9ff74ce 289 Stop_tunes(Buzzer2);
justinkim 6:9aefb9ff74ce 290 Stop_tunes(Buzzer3);
justinkim 6:9aefb9ff74ce 291 }
justinkim 5:3c24e937da61 292 }
justinkim 6:9aefb9ff74ce 293 else if(pin == 1)
justinkim 5:3c24e937da61 294 {
justinkim 6:9aefb9ff74ce 295 for(i=0; i<love_num; i++)
justinkim 6:9aefb9ff74ce 296 {
justinkim 6:9aefb9ff74ce 297 //Auto_tunes(Buzzer1, love1[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 298 //Auto_tunes(Buzzer2, love2[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 299 //Auto_tunes(Buzzer3, love3[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 300 //Auto_tunes(Buzzer4, love4[i], 1); // Auto performance
justinkim 6:9aefb9ff74ce 301 Stop_tunes(Buzzer1);
justinkim 6:9aefb9ff74ce 302 Stop_tunes(Buzzer2);
justinkim 6:9aefb9ff74ce 303 Stop_tunes(Buzzer3);
justinkim 6:9aefb9ff74ce 304 Stop_tunes(Buzzer4);
justinkim 6:9aefb9ff74ce 305 }
justinkim 5:3c24e937da61 306 }
justinkim 6:9aefb9ff74ce 307 else if(pin == 99)
justinkim 5:3c24e937da61 308 {
justinkim 6:9aefb9ff74ce 309 ;
justinkim 6:9aefb9ff74ce 310 }
justinkim 6:9aefb9ff74ce 311 else
justinkim 6:9aefb9ff74ce 312 {
justinkim 6:9aefb9ff74ce 313 WARN("Wrong pin number");
justinkim 6:9aefb9ff74ce 314 }
justinkim 6:9aefb9ff74ce 315
justinkim 6:9aefb9ff74ce 316 return 0;
justinkim 6:9aefb9ff74ce 317 }
hjjeon 0:e59cc54df17c 318 else
hjjeon 0:e59cc54df17c 319 {
hjjeon 0:e59cc54df17c 320 return 404;
hjjeon 0:e59cc54df17c 321 }
hjjeon 0:e59cc54df17c 322 }
hjjeon 0:e59cc54df17c 323
hjjeon 0:e59cc54df17c 324 int HTTPFsRequestHandler::handlePutRequest()
hjjeon 0:e59cc54df17c 325 {
hjjeon 0:e59cc54df17c 326 return 404;
hjjeon 0:e59cc54df17c 327 }
hjjeon 0:e59cc54df17c 328
hjjeon 0:e59cc54df17c 329 uint32_t HTTPFsRequestHandler::get_http_param_value(char* param_name)
hjjeon 0:e59cc54df17c 330 {
hjjeon 0:e59cc54df17c 331 uint8_t * name = 0;
hjjeon 0:e59cc54df17c 332 uint8_t * pos2;
hjjeon 0:e59cc54df17c 333 uint16_t len = 0;
hjjeon 0:e59cc54df17c 334 char value[10];
hjjeon 0:e59cc54df17c 335 uint32_t ret = 0;
hjjeon 0:e59cc54df17c 336
hjjeon 0:e59cc54df17c 337 //msg.attri
hjjeon 0:e59cc54df17c 338 if((name = (uint8_t *)strstr(msg.attri, param_name)))
hjjeon 0:e59cc54df17c 339 {
hjjeon 0:e59cc54df17c 340 name += strlen(param_name) + 1;
hjjeon 0:e59cc54df17c 341 pos2 = (uint8_t*)strstr((char*)name, "&");
hjjeon 0:e59cc54df17c 342 if(!pos2)
hjjeon 0:e59cc54df17c 343 {
hjjeon 0:e59cc54df17c 344 pos2 = name + strlen((char*)name);
hjjeon 0:e59cc54df17c 345 }
hjjeon 0:e59cc54df17c 346 len = pos2 - name;
hjjeon 0:e59cc54df17c 347
hjjeon 0:e59cc54df17c 348 if(len)
hjjeon 0:e59cc54df17c 349 {
hjjeon 0:e59cc54df17c 350 strncpy(value, (char*)name, len);
hjjeon 0:e59cc54df17c 351 ret = atoi(value);
hjjeon 0:e59cc54df17c 352 }
hjjeon 0:e59cc54df17c 353 }
hjjeon 0:e59cc54df17c 354 return ret;
hjjeon 0:e59cc54df17c 355 }
hjjeon 0:e59cc54df17c 356
justinkim 2:dd293a10a772 357