예제 #1
0
        /**
         * Sets the status of a specific RPi, and returns it's information afterwards.
         */
        public RPiConnection SetRPiConnectionStatus(int rpiConnectionId, string status)
        {
            this.UpdateLastTouch();
            RPiConnection rpiConnection = this.rpiConDbService.SetRPiConnectionStatus(rpiConnectionId, status, this.GetUserId());

            if (rpiConnection.userId == this.GetUserId())
            {
                rpiConnection.status = "connected";
            }
            return(rpiConnection);
        }
예제 #2
0
        /**
         * Gets a specific RPi connection, and changes its status to connected if you are connected to it.
         */
        public RPiConnection GetRPiConnection(int rpiConnectionId)
        {
            this.UpdateLastTouch();
            RPiConnection rpiConnection = this.rpiConDbService.GetRPiConnection(rpiConnectionId);

            if (rpiConnection.userId == this.GetUserId())
            {
                rpiConnection.status = "connected";
            }
            return(rpiConnection);
        }
예제 #3
0
        /**
         * This method executes a flightplan at a RPi connection. This basically means that the method does:
         * Get the proper information needed, like the RPi connection object and the Flightplan object.
         * Then it validates that you are connected to the RPi connection.
         * Then it formats the classes (found below this class), so that it is readable by the RPi backend.
         * It then starts a flight in this system.
         * Then it sends the flightplan to the RPi backend.
         * It then asks the RPi connection to execute the flightplan.
         */
        public bool HandFlightplanToRPiConnection(int receiverRPiConnectionId, string flightplanName, int priority)
        {
            this.rpiConDbService.DisconnectOldRPiConnections();
            this.UpdateLastTouch();
            Flightplan    fpToSend = this.fpService.GetFlightplan(flightplanName);
            RPiConnection receiverRPiConnection = this.GetRPiConnection(receiverRPiConnectionId);

            int uid = this.GetUserId();

            if (receiverRPiConnection.status == "disconnected")
            {
                Console.WriteLine("RPi not connected");
                return(false);
            }
            else if (receiverRPiConnection.userId != uid)
            {
                Console.WriteLine("You have no connections!");
                return(false);
            }

            FlightplanModelForJava flightplanModelForJava = new FlightplanModelForJava();

            flightplanModelForJava.created_at = fpToSend.createdAt;
            flightplanModelForJava.priority   = priority;
            flightplanModelForJava.commands   = new List <CommandModelForJava>();
            foreach (KeyValuePair <int, Command> entry in fpToSend.commands)
            {
                CommandModelForJava commandModelForJava = new CommandModelForJava();
                commandModelForJava.cmd_id     = entry.Value.CmdId;
                commandModelForJava.parameters = entry.Value.Params;
                flightplanModelForJava.commands.Insert(entry.Key, commandModelForJava);
            }

            // Start flight
            this.rpiConDbService.StartFlight(receiverRPiConnection.rowId, fpToSend.rowId, uid);

            string urlIpPort = "http://" + receiverRPiConnection.ip + ":" + receiverRPiConnection.port;

            string urlStoreFlightplan   = urlIpPort + "/api/flightplan/store/";
            string sendFlightplanResult = this.sendHttpService.SendPost(urlStoreFlightplan, ref flightplanModelForJava, receiverRPiConnection.password);

            if (!this.sendHttpService.DeserializeJsonString <bool>(sendFlightplanResult))
            {
                throw new TimeoutException("Could not send flightplan to RPi!");
            }

            // TODO: Log to flight that flightplan has been sent

            string     urlExecuteFlightplan = urlIpPort + "/api/flightplan/execute/";
            EmptyModel emptyModel           = new EmptyModel();
            string     executeFlightplan    = this.sendHttpService.SendPost(urlExecuteFlightplan, ref emptyModel, receiverRPiConnection.password);

            if (!this.sendHttpService.DeserializeJsonString <bool>(executeFlightplan))
            {
                throw new TimeoutException("Could not execute flightplan at RPi!");
            }

            // TODO: Log to flight that flightplan has been executed


            return(true);
        }