예제 #1
0
 public void AddAtResult(ATCommandResult r)
 {
     if (AtResults == null)
     {
         AtResults = new List <ATCommandResult>();
     }
     AtResults.Add(r);
 }
예제 #2
0
        public ATCommandResult Execute(GprsDtuConnection conn, ATCommand cmd, ushort timeout = 2)
        {
            var r = new ATCommandResult();

            if (!conn.IsOnline)
            {
                r.IsOK = false;
                r.GetJsonResult(cmd.ToATString());
                return(r);
            }
            try
            {
                logger.InfoFormat("======> AtCommand:{0}-{1} ,timeout={2}", conn.DtuID, cmd.ToATString(), timeout);
                DtuMsg result = conn.Ssend(Encoding.ASCII.GetBytes(cmd.ToATString()), timeout);

                r.ResultBuffer = result.Databuffer;
                string bufstr = string.Empty;
                if (r.ResultBuffer != null)
                {
                    bufstr = Encoding.ASCII.GetString(result.Databuffer);
                }
                r.IsOK = ((bufstr.Contains("OK")) || ("Remote Config Ready" == bufstr)) ||
                         cmd.ToATString().Contains("RESET");
                // r.GetJsonResult(cmd.ToATString());
                r.Elapsed = result.Elapsed;
                // System.Console.WriteLine("> {0}\r\n< {1} : {2}", cmd.ToATString(), bufstr, r.IsOK? "successed":"failed");
                logger.InfoFormat("======> AtCommand:{0}-{1} ,result: {2}, {3} ", conn.DtuID, cmd.ToATString(), bufstr,
                                  r.IsOK ? "successed" : "failed");
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("CommandExecutor Error: {0}", ex);
            }
            r.GetJsonResult(cmd.ToATString());
            return(r);
        }
예제 #3
0
        public ExecuteResult Execute(ATTask task, DacTaskContext context, ushort timeout = 2)
        {
            CommandExecutor ce = new CommandExecutor();
            ExecuteResult   r  = new ExecuteResult();

            r.Task        = task;
            r.Task.Status = DACTaskStatus.RUNNING;
            context.DtuConnection.Connect();
            // 循环发送数据
            long totalElapsed = 0;
            int  index        = 0;

            for (; index < r.Task.AtCommands.AtCommands.Count; index++)
            {
                var             ac  = r.Task.AtCommands.AtCommands[index];
                ATCommandResult atr = ce.Execute((GprsDtuConnection)context.DtuConnection, ac, timeout);
                if (ac.ToATString() == "***COMMIT CONFIG***")
                {
                    int i = 0;
                    while (!atr.IsOK)
                    {
                        if (i >= 10 || (r.Task.AtCommands.AtCommands.Count == 2))
                        {
                            break;
                        }
                        atr           = ce.Execute((GprsDtuConnection)context.DtuConnection, ac, timeout);
                        totalElapsed += atr.Elapsed;
                        i++;
                    }
                }

                if (!atr.IsOK)
                {
                    if (r.Task.AtCommands.AtCommands.Count == 2 && index == 0)
                    {
                        continue;
                    }
                    break;
                }
                r.AddAtResult(atr);
                totalElapsed += atr.Elapsed;
                r.ToJsonString();
            }
            if (index < r.Task.AtCommands.AtCommands.Count - 1)
            {
                for (; index < r.Task.AtCommands.AtCommands.Count; index++)
                {
                    var ar = new ATCommandResult()
                    {
                        ResultBuffer = null,
                        IsOK         = false,
                    };
                    ar.GetJsonResult(r.Task.AtCommands.AtCommands[index].ToATString());
                    r.AddAtResult(ar);
                }
            }
            r.Elapsed     = totalElapsed;
            r.Finished    = DateTime.Now;
            r.Task.Status = DACTaskStatus.DONE;
            context.DtuConnection.Disconnect();
            return(r);
        }