/// <summary>
 /// Initialization Constructor
 /// </summary>
 /// <param name="config"></param>
 public Configure(ChrUm6OrientationSensorConfig config)
 {
     this.Body = config;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Default ChrConnection constructor
 /// </summary>
 /// <param name="config"></param>
 /// <param name="chrDataPort"></param>
 public ChrConnection(ChrUm6OrientationSensorConfig config, ChrDataPort chrDataPort)
 {
     this._config      = config;
     this._chrDataPort = chrDataPort;
 }