示例#1
0
        public virtual IEnumerator <ITask> SendChrCommandHandler(SendChrUm6OrientationSensorCommand update)
        {
            //update.ResponsePort.Post(
            //    Fault.FromException(
            //        new NotImplementedException("The CHR UM6 Sensor service is a sample. Sending commands to the sensor is an exercise left to the community.")));

            string command = update.Body.Command;

            switch (command)
            {
            case "ZeroRateGyros":
            case "SetAccelRefVector":
            case "SetMagnRefVector":
                Console.WriteLine("SendChrCommandHandler received command " + command);
                if (_state.Connected)
                {
                    _chrConnection.SendCommand(command);
                }
                break;

            default:
                Console.WriteLine("SendChrCommandHandler received unknown command '" + command + "'");
                break;
            }

            update.ResponsePort.Post(new DefaultUpdateResponseType());
            yield break;
        }
示例#2
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"] == "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;
        }