Beispiel #1
0
 public int HoldCommand(CMD_NAV_Hold cmd)
 {
     Clients.Group("vehicles").sendHoldCommand(cmd, Context.ConnectionId);
     System.Diagnostics.Debug.WriteLine("ID is: " + cmd.Id);
     System.Diagnostics.Debug.WriteLine("Context ID is: " + Context.ConnectionId);
     return(cmd.Id);
 }
Beispiel #2
0
        public async Task BroadcastAcceptedCommand(CMD_ACK ack)
        {
            NestContainer db = new NestContainer();
            {
                switch (ack.CommandType)
                {
                case "CMD_NAV_Target":
                    CMD_NAV_Target target = await db.CMD_NAV_Target.FindAsync(ack.CommandId);

                    if (target != null && ack.Accepted == true)
                    {
                        target.Acked = true;
                        Clients.All.targetCommandAccepted(target);
                        db.Entry(target).State = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                    break;

                case "CMD_NAV_Hold":
                    CMD_NAV_Hold hold = await db.CMD_NAV_Hold.FindAsync(ack.CommandId);

                    if (hold != null && ack.Accepted == true)
                    {
                        hold.Acked = true;
                        Clients.All.targetCommandAccepted(hold);
                        db.Entry(hold).State = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                    break;

                case "CMD_NAV_Return":
                    CMD_NAV_Return goBack = await db.CMD_NAV_Return.FindAsync(ack.CommandId);

                    if (goBack != null && ack.Accepted == true)
                    {
                        goBack.Acked = true;
                        Clients.All.targetCommandAccepted(goBack);
                        db.Entry(goBack).State = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                    break;

                case "CMD_NAV_Land":
                    CMD_NAV_Land land = await db.CMD_NAV_Land.FindAsync(ack.CommandId);

                    if (land != null && ack.Accepted == true)
                    {
                        land.Acked = true;
                        Clients.All.targetCommandAccepted(land);
                        db.Entry(land).State = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #3
0
        public IHttpActionResult PostCMD_NAV_HOLD(int uid, CMD_NAV_Hold jsObject)
        {
            int          result       = 0;
            CMD_NAV_Hold cmd_nav_hold = new CMD_NAV_Hold();

            //cmd_nav_hold.Id = jsObject.Id;
            cmd_nav_hold.Altitude  = jsObject.Altitude;
            cmd_nav_hold.Latitude  = jsObject.Latitude;
            cmd_nav_hold.Longitude = jsObject.Longitude;
            cmd_nav_hold.UAVId     = jsObject.UAVId;
            cmd_nav_hold.Time      = jsObject.Time;
            cmd_nav_hold.Throttle  = jsObject.Throttle;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            try
            {
                db.CMD_NAV_Hold.Add(cmd_nav_hold);
                result = db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    System.Diagnostics.Debug.Write("Entity of type " + eve.Entry.Entity.GetType().Name + " in state " + eve.Entry.State + " has the following validation errors:");
                    foreach (var ve in eve.ValidationErrors)
                    {
                        System.Diagnostics.Debug.Write("- Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage);
                    }
                }
                throw;
            }
            if (result == 1)
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }