Exemple #1
0
        /// <summary>
        /// Look for a file on the SD card and send it back if it exists
        /// </summary>
        /// <param name="request"></param>
        private static void TrySendFile(Request request)
        {
            // Replace / with \
            string filePath = WebFolder + request.URL.Replace('/', '\\');

            if (File.Exists(filePath))
                request.SendFile(filePath);
            else
                request.Send404();
        }
Exemple #2
0
        private static void RequestReceived(Request request)
        {
            // Use this for a really basic check that it's working
            //request.SendResponse("<html><body><p>Request from " + request.Client.ToString() + " received at " + DateTime.Now.ToString() + "</p><p>Method: " + request.Method + "<br />URL: " + request.URL +"</p></body></html>");

            //Break apart the request
            //request.URL.ToString()
            string[] commands = request.URL.Split('&');
            try
            {
                int cmdCount = 0;
                foreach (string c in commands)
                {
                    cmdCount++;
                }
                if (cmdCount != 6){request.SendResponse("<html><body>Invalid Number of Commands</body></html>");}
            }
            catch (Exception ex)
            {
                request.SendResponse("<html><body>" + ex + "</body></html>");
            }

            try
            {
                string direction = commands[0];
                int t = Int32.Parse(commands[1]);
                int d = Int32.Parse(commands[2]);
                string dir = commands[3].ToString();
                int deg = Int32.Parse(commands[4]);
                int spe = Int32.Parse(commands[5]);

                // sent to output
                if (direction.ToLower() == "/forward" || direction.ToLower() == "/reverse")
                {
                    //TrySendFile(request);
                    //OutputPort D0 = new OutputPort(Pins.GPIO_PIN_D0, false);
                    //D0.Write(true);

                    if (Navigate(direction, t, d, spe, dir, deg))
                    {
                        request.SendResponse("<html><body><p>FORWARD<BR><BR>Request from " + request.Client.ToString() + " received at " + DateTime.Now.ToString() + "</p><p>Method: " + request.Method + "<br />URL: " + request.URL + "</p></body></html>");
                    }
                    else { request.Send404(); }

                }
                //else if (direction == "/backward" || direction == "/test2.html")
                //{

                //    //xl5.DriveMode = SpeedController.DriveModes.Reverse;
                //    //for (int j = 50; j >= 0; j--)
                //    //{
                //    //    xl5.Throttle = j;
                //    //    Thread.Sleep(30);
                //    //}

                //    request.SendResponse("<html><body><p>BACKWARD<BR><BR>Request from " + request.Client.ToString() + " received at " + DateTime.Now.ToString() + "</p><p>Method: " + request.Method + "<br />URL: " + request.URL + "</p></body></html>");

                //}
                else
                {
                    request.SendResponse("<html><body><p>UNKNOWN COMMAND<BR><BR>Request from " + request.Client.ToString() + " received at " + DateTime.Now.ToString() + "</p><p>Method: " + request.Method + "<br />URL: " + request.URL + "</p></body></html>");
                }

                // Send a file
                //TrySendFile(request);
            }
            catch (Exception ex)
            {
                request.SendResponse("<html><body>" + ex + "</body></html>");
            }
        }