Esempio n. 1
0
int WiFiCmdRobot::ReplyKO ()
{
     tcpClient.println("HTTP/1.1 500 Internal Server Error");
     tcpClient.println("Content-Type: text/html");
     tcpClient.println("Server: ChipkitEDH/0.1");                                   
     tcpClient.println();
     
     return SUCCESS;
                                  
}
Esempio n. 2
0
int WiFiCmdRobot::ReplyOK ()
{
    int ret=SUCCESS; 
    
    if (cmd[0] == CMD_PICTURE)
    { 
          Serial.println("cmd[0] == CMD_PICTURE");
          if (tcpClient.isConnected()) Serial.println("tcpClient.isConnected");
          else Serial.println("tcpClient.is not Connected");
          tcpClient.println("HTTP/1.1 200 OK");
          tcpClient.println("Content-Type: application/octet-stream");
          tcpClient.println("Server: ChipkitEDH/0.1");                                             
          tcpClient.println();

          ret= WiFiSendPicture (resp[0]);
          
          if (ret != SUCCESS){  Serial.print("WiFiSendPicture error"); Serial.print(ret);}
    }
    else                                           
    {                               
          tcpClient.println("HTTP/1.1 200 OK");
          for(int i=0; i<resp_len; i++)
          {
              tcpClient.print("Field ");
              tcpClient.print(String(i));
              tcpClient.print(":");
              tcpClient.print(String((int)resp[i]));
              tcpClient.println(";");
         }
         tcpClient.println("Content-Type: text/html");
         tcpClient.println("Server: ChipkitEDH/0.1");                                             
         tcpClient.println();
    }
    
    return ret;    
}
Esempio n. 3
0
int WiFiCmdRobot::Cmd (String s)
{
   int cmdTag;
   int And;
   String szparam[10];
   int iparam[10];
   int paramTag;
   int Start;
   int Semicolumn;
   int ret=SUCCESS;
   
   //GET /Robot?CMD=MOVE_TILT_PAN&PARAM=122;118; HTTP/1.1[\r][\n]
   //GET /Robot?CMD=INFOS HTTP/1.1[\r][\n]

   cmdTag = s.indexOf("CMD=");
   if (cmdTag > 0)
   {   
       Serial.print("CMD=");
       And = s.indexOf('&', cmdTag + 1);
       if (And == -1) And = s.indexOf(' ', cmdTag + 1);  
       szcmd = s.substring(cmdTag + 4, And);
       Serial.println(szcmd);

       paramTag = s.indexOf("PARAM=");
       if (paramTag > 0)
       {   
          Start = paramTag + 6;
          Semicolumn = s.indexOf('%3B', Start + 1); // semi column is encoded in URL
          for (int p=0; Semicolumn != -1; p++)
          {
               szparam[p] = s.substring(Start, Semicolumn - 2);
               iparam[p] = szparam[p].toInt();
               Serial.print("param");
               Serial.print(p);
               Serial.print("=");
               Serial.print(szparam[p]);
               Serial.print("/");
               Serial.println(iparam[p]);
               Start = Semicolumn + 1;
               Semicolumn = s.indexOf('%3B', Start + 1);
               
          }                                   
       }
       // CMD
       
       if (szcmd == "START")
       {
               cmd[0] = CMD_START;
               cmd[1] = iparam[0];
               cmd[2] = 0;
               cmd_GO[0]= 0; //reset GO command
       }        
       if (szcmd == "STOP")
       {
               cmd[0] = CMD_STOP;
               cmd[1] = 0;
               cmd[2] = 0;
               cmd_GO[0]= 0; //reset GO command
       }                                 
       if (szcmd == "INFOS")
       {
               cmd[0] = CMD_INFOS;
               cmd[1] = 0;
               cmd[2] = 0;
       }                                    
       if (szcmd == "PICTURE")
       {
               cmd[0] = CMD_PICTURE;
               cmd[1] = 0;
               cmd[2] = 0;
       }                                    
       if (szcmd == "TURN_RIGHT")
       {
               cmd[0] = CMD_TURN_RIGHT;
               cmd[1] = iparam[0];
               cmd[2] = 0;
       }                                    
       if (szcmd == "TURN_LEFT")
       {
               cmd[0] = CMD_TURN_LEFT;
               cmd[1] = iparam[0];
               cmd[2] = 0;
       }                                           
       if (szcmd == "CHECK_AROUND")
       {
               cmd[0] = CMD_CHECK_AROUND;
               cmd[1] = iparam[0];
               cmd[2] = 0;
       }                                    
       if (szcmd == "MOVE_TILT_PAN")
       {
               cmd[0] = CMD_MOVE_TILT_PAN;
               cmd[1] = iparam[0];
               cmd[2] = iparam[1];
       }                                    
       if (szcmd == "GO")
       {
               cmd_GO[0] = CMD_GO;
               cmd_GO[1] = iparam[0];
               cmd_GO[2] = iparam[1];
               cmd[0] = cmd_GO[0];
               cmd[1] = t_GO;
               cmd[2] = cmd_GO[2];
       } 
       
       ret = CmdRobot (cmd, resp, &resp_len);
       
       Serial.print("Call CmdRobot, ret: ");
       Serial.print(ret);
       Serial.print(" / resp_len: ");
       Serial.println(resp_len); 
       
       return ret;                                                                                           
   }
   else
   {
       // no CMD
       tcpClient.println("HTTP/1.1 400 Bad Request");
       tcpClient.println("Content-Type: text/html");
       tcpClient.println("Server: ChipkitEDH/0.1"); 
       tcpClient.println(); 
       
       return -400;                              
   }
   
}