Пример #1
0
        public virtual IEnumerator<ITask> HttpPostHandler(HttpPost httpPost)
        {
            Fault fault = null;
            NameValueCollection parameters = new NameValueCollection();

            ReadFormData readForm = new ReadFormData(httpPost);
            _httpUtilities.Post(readForm);

            // Wait for result
            yield return Arbiter.Choice(
                readForm.ResultPort,
                delegate(NameValueCollection col)
                {
                    parameters = col;
                },
                delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
            );

            if(fault != null)
            {
                httpPost.ResponsePort.Post(fault);
                yield break;
            }

            if (!string.IsNullOrEmpty(parameters["NewMode"]))
            {
                int mod = int.Parse(parameters["NewMode"]);
                _biclops.setMode(mod);
            }

            if(!string.IsNullOrEmpty(parameters["pos1"]))
            {
                double newr = double.Parse(parameters["pos1"]);
                _biclops.setJointPosition(0, newr);
            }

            if(!string.IsNullOrEmpty(parameters["pos2"]))
            {
                double newr = double.Parse(parameters["pos2"]);
                _biclops.setJointPosition(1, newr);
            }

            HttpResponseType rsp = new HttpResponseType(HttpStatusCode.OK, _state, _transform);
            httpPost.ResponsePort.Post(rsp);

            SaveState(_state);
        }
        public virtual IEnumerator<ITask> HttpPostHandler(HttpPost httpPost)
        {
            string ErrorMessage = String.Empty;
            Fault fault = null;
            NameValueCollection parameters = new NameValueCollection();

            // use helper to read from data
            ReadFormData readForm = new ReadFormData(httpPost);
            _httpUtilities.Post(readForm);

            //wait for result
            yield return Arbiter.Choice(
                readForm.ResultPort,
                delegate(NameValueCollection col)
                {
                    parameters = col;
                },
                delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                    LogError(null, "Error Processing from data", fault);
                    ErrorMessage += e;
                }
            );

            if (fault != null)
            {
                httpPost.ResponsePort.Post(fault);
                yield break;
            }

            bool validDelta = false;
            double[] _delta = new double[2];

            if (!string.IsNullOrEmpty(parameters["delta"]))
            {
                try
                {
                    _delta[0] = double.Parse(parameters["delta"]);
                    _delta[1] = double.Parse(parameters["delta"]);
                    validDelta = true;
                }
                catch (Exception e)
                {
                    string msg = "Could not parse Desired MaxDelta ref value: " + e.Message;
                    LogError(msg);
                    ErrorMessage += msg;
                }
            }
            if (validDelta)
            {
                _state.MaxDelta.dat[0] = _delta[0];
                _state.MaxDelta.dat[1] = _delta[1];
            }

            double[] _ref = new double[2];
            bool validValues = true;

            if (!string.IsNullOrEmpty(parameters["DesPan"]))
            {
                try
                {
                    _ref[0] = double.Parse(parameters["DesPan"]);
                }
                catch (Exception e)
                {
                    string msg = "Could not parse Desired Pan ref value: " + e.Message;
                    LogError(msg);
                    ErrorMessage += msg;
                    validValues = validValues && false;
                }
            }
            if (!string.IsNullOrEmpty(parameters["DesTilt"]))
            {
                try
                {
                    _ref[1] = double.Parse(parameters["DesTilt"]);
                }
                catch (Exception e)
                {
                    string msg = "Could not parse Desired Tilt ref value: " + e.Message;
                    LogError(msg);
                    ErrorMessage += msg;
                    validValues = validValues && false;
                }
            }

            if (!string.IsNullOrEmpty(parameters["lock"]))
            {
                try
                {
                    _state.Lock = true;
                }
                catch (Exception e)
                {
                    string msg = "Could not parse Lock check: " + e.Message;
                    LogError(msg);
                    ErrorMessage += msg;
                }
            }
            else
            {
                Console.WriteLine("Lock set to false");
                _state.Lock = false;
                newDesiredJointPositions = true;
            }

            if (validValues)
            {
                // scale down here...
                _state.DesiredJointAngles.dat[0] = _ref[0];
                _state.DesiredJointAngles.dat[1] = _ref[1];
            }

            if (!string.IsNullOrEmpty(parameters["Home"]))
            {
                /*
                Console.WriteLine("BiclopsRightCameraJointConfiguration::Home()");
                _biclopsPort.Post(new biclops.Home());
                _state.Lock = true;
                Activate(
                Arbiter.Choice(
                    _biclopsPort.Home(new biclops.HomeRequest()),
                    delegate(DefaultUpdateResponseType response)
                    {
                        LogError(LogGroups.Console, "got response from Bicops.Home");
                        //Console.WriteLine("got response from Biclops.Home");
                    },
                    delegate(W3C.Soap.Fault failure)
                    {
                        LogError(LogGroups.Console, "Fault posting Bicops.Home");
                        //Console.WriteLine("Fault posting SetJointPositionReference");
                    }));
                 */
            }
            if (!string.IsNullOrEmpty(parameters["Park"]))
            {
                /*
                Console.WriteLine("BiclopsRightCameraJointConfiguration::Park()");
                _biclopsPort.Post(new biclops.Park());
                 */
            }

            if (ErrorMessage == string.Empty)
            {
                httpPost.ResponsePort.Post(new HttpResponseType(HttpStatusCode.OK, _state, _transform));
            }
            else
            {
                fault = Fault.FromCodeSubcodeReason(FaultCodes.Receiver,
                                                    DsspFaultCodes.OperationFailed,
                                                    ErrorMessage);
                httpPost.ResponsePort.Post(new Fault());
            }
            yield break;
        }
Пример #3
0
        public IEnumerator<ITask> HttpPostHandler(HttpPost httpPost)
        {
            // Use helper to read form data
            ReadFormData readForm = new ReadFormData(httpPost);
            _httpUtilities.Post(readForm);

            // Wait for result
            Activate(Arbiter.Choice(readForm.ResultPort,
                delegate(NameValueCollection parameters)
                {
                    if (!string.IsNullOrEmpty(parameters["Action"])
                        && parameters["Action"] == "MicrosoftGpsConfig"
                        )
                    {
                        if (parameters["buttonOk"] == "Search")
                        {
                            FindGpsConfig findConfig = new FindGpsConfig();
                            _mainPort.Post(findConfig);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<MicrosoftGpsConfig>(false, findConfig.ResponsePort,
                                        delegate(MicrosoftGpsConfig response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, findConfig.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );

                        }
                        else if (parameters["buttonOk"] == "Connect and Update")
                        {

                            MicrosoftGpsConfig config = (MicrosoftGpsConfig)_state.MicrosoftGpsConfig.Clone();
                            int port;
                            if (int.TryParse(parameters["CommPort"], out port) && port >= 0)
                            {
                                config.CommPort = port;
                                config.PortName = "COM" + port.ToString();
                            }

                            int baud;
                            if (int.TryParse(parameters["BaudRate"], out baud) && GpsConnection.ValidBaudRate(baud))
                            {
                                config.BaudRate = baud;
                            }

                            config.CaptureHistory = ((parameters["CaptureHistory"] ?? "off") == "on");
                            config.CaptureNmea = ((parameters["CaptureNmea"] ?? "off") == "on");
                            config.RetrackNmea = ((parameters["RetrackNmea"] ?? "off") == "on");

                            Console.WriteLine(string.Format("Switches: CaptureHistory={0}   CaptureNmea={1}   RetrackNmea={2}", config.CaptureHistory, config.CaptureNmea, config.RetrackNmea));

                            Configure configure = new Configure(config);
                            _mainPort.Post(configure);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<DefaultUpdateResponseType>(false, configure.ResponsePort,
                                        delegate(DefaultUpdateResponseType response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, configure.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );
                        }

                    }
                    else
                    {
                        HttpPostFailure(httpPost, null);
                    }
                },
                delegate(Exception Failure)
                {
                    LogError(Failure.Message);
                })
            );
            yield break;
        }
        public IEnumerator<ITask> HttpPostHandler(HttpPost httpPost)
        {
            // Use helper to read form data
            ReadFormData readForm = new ReadFormData(httpPost);
            _httpUtilities.Post(readForm);

            // Wait for result
            Activate(Arbiter.Choice(readForm.ResultPort,
                delegate(NameValueCollection parameters)
                {
                    if (!string.IsNullOrEmpty(parameters["Action"])
                        && parameters["Action"] == "ChrUm6OrientationSensorConfig"
                        )
                    {
                        if (parameters["buttonOk"] == "Search")
                        {
                            FindChrConfig findConfig = new FindChrConfig();
                            _mainPort.Post(findConfig);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<ChrUm6OrientationSensorConfig>(false, findConfig.ResponsePort,
                                        delegate(ChrUm6OrientationSensorConfig response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, findConfig.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );

                        }
                        else if (parameters["buttonOk"] == "Connect")
                        {
                            ChrUm6OrientationSensorConfig config = (ChrUm6OrientationSensorConfig)_state.ChrUm6OrientationSensorConfig.Clone();
                            int port;
                            if (int.TryParse(parameters["CommPort"], out port) && port >= 0)
                            {
                                config.CommPort = port;
                                config.PortName = "COM" + port.ToString();
                            }

                            int baud;
                            if (int.TryParse(parameters["BaudRate"], out baud) && ChrConnection.ValidBaudRate(baud))
                            {
                                config.BaudRate = baud;
                            }

                            Configure configure = new Configure(config);
                            _mainPort.Post(configure);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<DefaultUpdateResponseType>(false, configure.ResponsePort,
                                        delegate(DefaultUpdateResponseType response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, configure.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );
                        }
                        else if (parameters["buttonOk"] == "Refresh Data")
                        {
                            HttpPostSuccess(httpPost);
                        }
                        else if (parameters["buttonOk"] == "Set Accelerometer Reference Vector")
                        {
                            ChrUm6OrientationSensorCommand cmd = new ChrUm6OrientationSensorCommand() { Command = "SetAccelRefVector" };
                            SendChrUm6OrientationSensorCommand sCmd = new SendChrUm6OrientationSensorCommand(cmd);

                            _mainPort.Post(sCmd);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<DefaultUpdateResponseType>(false, sCmd.ResponsePort,
                                        delegate(DefaultUpdateResponseType response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, sCmd.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );
                        }
                        else if (parameters["buttonOk"] == "Set Magnetometer Reference Vector")
                        {
                            ChrUm6OrientationSensorCommand cmd = new ChrUm6OrientationSensorCommand() { Command = "SetMagnRefVector" };
                            SendChrUm6OrientationSensorCommand sCmd = new SendChrUm6OrientationSensorCommand(cmd);

                            _mainPort.Post(sCmd);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<DefaultUpdateResponseType>(false, sCmd.ResponsePort,
                                        delegate(DefaultUpdateResponseType response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, sCmd.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );
                        }
                        else if (parameters["buttonOk"] == "Zero Rate Gyros")
                        {
                            ChrUm6OrientationSensorCommand cmd = new ChrUm6OrientationSensorCommand() { Command = "ZeroRateGyros" };
                            SendChrUm6OrientationSensorCommand sCmd = new SendChrUm6OrientationSensorCommand(cmd);

                            _mainPort.Post(sCmd);
                            Activate(
                                Arbiter.Choice(
                                    Arbiter.Receive<DefaultUpdateResponseType>(false, sCmd.ResponsePort,
                                        delegate(DefaultUpdateResponseType response)
                                        {
                                            HttpPostSuccess(httpPost);
                                        }),
                                    Arbiter.Receive<Fault>(false, sCmd.ResponsePort,
                                        delegate(Fault f)
                                        {
                                            HttpPostFailure(httpPost, f);
                                        })
                                )
                            );
                        }
                    }
                    else
                    {
                        HttpPostFailure(httpPost, null);
                    }
                },
                delegate(Exception Failure)
                {
                    LogError(Failure.Message);
                })
            );
            yield break;
        }
Пример #5
0
        /// <summary>
        /// Http Post Handler.  Handles http form inputs
        /// </summary>
        //[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
        public IEnumerator<ITask> HttpPostHandler(HttpPost httpPost)
        {
            // Use helper to read form data
            ReadFormData readForm = new ReadFormData(httpPost);
            _httpUtilities.Post(readForm);

            // Read form data
            NameValueCollection parameters = null;
            yield return Arbiter.Choice(readForm.ResultPort,
                delegate(NameValueCollection p) { parameters = p; },
                delegate(Exception e) { throw new Exception("Error reading form data", e); });

            // Act on form data
            if (!string.IsNullOrEmpty(parameters["Action"])
                  && parameters["Action"] == "ScribblerConfig")
            {
                if (parameters["buttonOk"] == "Change" && _state.Connected)
                {
                    SetNameBody newname = new SetNameBody(parameters["Name"]);
                    SetName newnamemessage = new SetName(newname);
                    _mainPort.PostUnknownType(newnamemessage);
                    Activate(
                        Arbiter.Choice(
                            Arbiter.Receive<DefaultUpdateResponseType>(false, newnamemessage.ResponsePort,
                                delegate(DefaultUpdateResponseType response)
                                {
                                    HttpPostSuccess(httpPost);
                                }),
                            Arbiter.Receive<Fault>(false, newnamemessage.ResponsePort,
                                delegate(Fault f)
                                {
                                    HttpPostFailure(httpPost, f.Reason[0].Value);
                                })
                        )
                    );

                }
                else if (parameters["buttonOk"] == "Connect" && _state.Connected)
                {
                    //close down this connection to make a new connection below

                    PollTimer.Close();

                    System.Threading.Thread.Sleep(100);

                    _scribblerCom.Close();

                    _state.Connected = false;

                    //HttpPostSuccess(httpPost);
                }

                if (parameters["buttonOk"] == "Connect" && !_state.Connected)
                {
                    int port = 0;
                    int.TryParse(parameters["ComPort"], out port);
                    string name = parameters["Name"];
                    if (!string.IsNullOrEmpty(name) && name.Length > 8)
                        name = name.Substring(0, 8);

                    _state.ComPort = port;
                    _state.RobotName = name;

                    //open Scribbler Communications port
                    LogInfo("connecting to scribbler...");
                    Reconnect rec = new Reconnect();
                    _mainPort.PostUnknownType(rec);
                    yield return Arbiter.Choice(rec.ResponsePort,
                        delegate(DefaultUpdateResponseType r)
                        {
                            LogInfo("connected, sending http reply");
                            HttpPostSuccess(httpPost);
                            LogInfo("http reply sent");
                        },
                        delegate(Fault f)
                        {
                            httpPost.ResponsePort.Post(f);
                        });
                }
            }
            else if (!string.IsNullOrEmpty(parameters["Action"])
                  && parameters["Action"] == "ScribblerSensors")
            {
                if (parameters["buttonOk"] == "Poll" && _state.Connected)
                {
                    ScribblerCommand cmd = new ScribblerCommand(ScribblerHelper.Commands.GET_ALL);
                    SendScribblerCommand sendcmd = new SendScribblerCommand(cmd);
                    _scribblerComPort.Post(sendcmd);
                    Activate(
                        Arbiter.Choice(
                            Arbiter.Receive<ScribblerResponse>(false, sendcmd.ResponsePort,
                                delegate(ScribblerResponse response)
                                {
                                    HttpPostSuccess(httpPost);
                                }),
                            Arbiter.Receive<Fault>(false, sendcmd.ResponsePort,
                                delegate(Fault f)
                                {
                                    HttpPostFailure(httpPost, f.Reason[0].Value);
                                })
                        )
                    );
                }
            }
            else if (!string.IsNullOrEmpty(parameters["Action"])
                && parameters["Action"] == "ScribblerMotors")
            {
                if (parameters["buttonOk"] == "Set" && _state.Connected)
                {
                    int left = _state.MotorLeft;
                    int right = _state.MotorRight;
                    int.TryParse(parameters["LeftMotor"], out left);
                    int.TryParse(parameters["RightMotor"], out right);

                    SetMotorsBody setMotorsBody = new SetMotorsBody(left, right);
                    SetMotors setMotorsRequest = new SetMotors(setMotorsBody);

                    _mainPort.PostUnknownType(setMotorsRequest);

                    Activate(
                        Arbiter.Choice(
                            Arbiter.Receive<DefaultUpdateResponseType>(false, setMotorsRequest.ResponsePort,
                                delegate(DefaultUpdateResponseType response)
                                {
                                    HttpPostSuccess(httpPost);
                                }),
                            Arbiter.Receive<Fault>(false, setMotorsRequest.ResponsePort,
                                delegate(Fault f)
                                {
                                    HttpPostFailure(httpPost, f.Reason[0].Value);
                                })
                        )
                    );
                }
                else if (parameters["buttonOk"] == "All Stop" && _state.Connected)
                {
                    SetMotorsBody setMotorsBody = new SetMotorsBody(100, 100);
                    SetMotors setMotorsRequest = new SetMotors(setMotorsBody);

                    _mainPort.PostUnknownType(setMotorsRequest);

                    Activate(
                        Arbiter.Choice(
                            Arbiter.Receive<DefaultUpdateResponseType>(false, setMotorsRequest.ResponsePort,
                                delegate(DefaultUpdateResponseType response)
                                {
                                    HttpPostSuccess(httpPost);
                                }),
                            Arbiter.Receive<Fault>(false, setMotorsRequest.ResponsePort,
                                delegate(Fault f)
                                {
                                    HttpPostFailure(httpPost, f.Reason[0].Value);
                                })
                        )
                    );
                }
            }
            else if (!string.IsNullOrEmpty(parameters["Action"])
                && parameters["Action"] == "ScribblerLEDs")
            {
                if (parameters["buttonOk"] == "Set" && _state.Connected)
                {
                    bool left = ((parameters["LeftLED"] ?? "off") == "on");
                    bool center = ((parameters["CenterLED"] ?? "off") == "on");
                    bool right = ((parameters["RightLED"] ?? "off") == "on");

                    SetAllLedsBody leds = new SetAllLedsBody(left, center, right);
                    SetAllLEDs setAllLeds = new SetAllLEDs(leds);
                    _mainPort.PostUnknownType(setAllLeds);

                    Activate(
                        Arbiter.Choice(
                            Arbiter.Receive<DefaultUpdateResponseType>(false, setAllLeds.ResponsePort,
                                delegate(DefaultUpdateResponseType response)
                                {
                                    HttpPostSuccess(httpPost);
                                }),
                            Arbiter.Receive<Fault>(false, setAllLeds.ResponsePort,
                                delegate(Fault f)
                                {
                                    HttpPostFailure(httpPost, f.Reason[0].Value);
                                })
                        )
                    );

                }
            }
            else if (!string.IsNullOrEmpty(parameters["Action"])
                && parameters["Action"] == "ScribblerSpeaker")
            {
                if (parameters["buttonOk"] == "Play" && _state.Connected)
                {
                    int tone1 = 0;
                    int tone2 = 0;
                    int duration = 0;
                    int.TryParse(parameters["Tone1"], out tone1);
                    int.TryParse(parameters["Tone2"], out tone2);
                    int.TryParse(parameters["Duration"], out duration);

                    PlayToneBody playTone = new PlayToneBody(duration, tone1, tone2);
                    PlayTone playToneMessage = new PlayTone(playTone);
                    _mainPort.PostUnknownType(playToneMessage);

                    Activate(
                        Arbiter.Choice(
                            Arbiter.Receive<DefaultUpdateResponseType>(false, playToneMessage.ResponsePort,
                                delegate(DefaultUpdateResponseType response)
                                {
                                    HttpPostSuccess(httpPost);
                                }),
                            Arbiter.Receive<Fault>(false, playToneMessage.ResponsePort,
                                delegate(Fault f)
                                {
                                    HttpPostFailure(httpPost, f.Reason[0].Value);
                                })
                        )
                    );
                }
            }
            else
            {
                HttpPostFailure(httpPost, "Unknown Http Post");
            }
            yield break;
        }