コード例 #1
0
ファイル: Program.cs プロジェクト: sjmulder/HybridDrone
        public Program()
        {
            try
            {
                this.drone = new Wrapper.Dotnet.Drone();

                webserver = new WebServer("http", "*", 6606);

                AddActions();

                drone.Init();
                drone.StartOrientationThread();

                webserver.AddAuthorizationMethod(new TimeBasedHmacAuthorizationHandler("mySecret", new TimeSpan(0, 0, 3), 1));
                webserver.Start();
            } catch (Exception exception)
            {
                Console.WriteLine($"{exception.Message}\n{exception.StackTrace}");
            }
        }
コード例 #2
0
        public void AddRoutes(WebServer webserver, Wrapper.Dotnet.Drone drone)
        {
            webserver.AddAction("GET", "/orientation", (context) =>
            {
                Orientation orientation = drone.Orientation;
                return(new
                {
                    yaw = orientation.Yaw,
                    pitch = orientation.Pitch,
                    roll = orientation.Roll,
                });
            });

            webserver.AddAction("POST", "/orientation", (context) =>
            {
                drone.StartOrientationThread();
                return(new
                {
                    message = "Orientation sensor enabled"
                });
            });

            webserver.AddAction("DELETE", "/orientation", (context) =>
            {
                drone.StartOrientationThread();
                return(new
                {
                    message = "Orientation sensor disabled"
                });
            });

            webserver.AddAction("POST", "/orientationAssist", (context) =>
            {
                drone.StartOrientationAssist();
                return(new
                {
                    message = "Orientation assist enabled"
                });
            });

            webserver.AddAction("DELETE", "/orientationAssist", (context) =>
            {
                drone.StopOrientationAssist();
                return(new
                {
                    message = "Orientation assist disabled"
                });
            });

            webserver.AddAction("POST", "/orientationAssistAgression", (context) =>
            {
                string input;
                using (StreamReader reader = new StreamReader(context.Request.InputStream))
                {
                    input = reader.ReadToEnd();
                }

                float value = JsonConvert.DeserializeObject <RunTestStruct>(input).Value;

                drone.OrientationAssistAgression = value;
                return(new
                {
                    message = "Orientation assist aggression set"
                });
            });
        }