Exemple #1
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;
                }
            }
        }
Exemple #2
0
 public int GotoCommand(CMD_NAV_Target cmd)
 {
     using (var db = new NestContainer())
     {
         Clients.Group("vehicles").sendTargetCommand(cmd, Context.ConnectionId);
         return(cmd.Id);
     }
 }
Exemple #3
0
 /**
  * Returns -1 if the insertion into the database failed.
  */
 public int SendCommand(CMD_NAV_Target target)
 {
     using (var db = new NestContainer())
     {
         target = db.CMD_NAV_Target.Add(target);
         int result = db.SaveChanges();
         if (result == 1)
         {
             //The target was added, so send the target command to the vehicles.
             Clients.Group("vehicles").sendTargetCommand(target, Context.ConnectionId);
             //Return the target ID so they know what the ID is in the database.
             return(target.Id);
         }
         else
         {
             //Not added, return, let caller know
             return(-1);
         }
     }
 }