示例#1
0
        public ConfigCommand GetAtCommands(JObject[] cmdobjs)
        {
            var lst        = new List <ATCommand>();
            var atCommands = new ConfigCommand();

            if (cmdobjs != null && cmdobjs.Length > 0)
            {
                try
                {
                    if (cmdobjs.Length == 8)
                    {
                        lst.Add(new SetMainIpCount(cmdobjs[0].Value <JObject>("param").ToString()));
                        lst.Add(new SetIP(new StringBuilder(cmdobjs[1].Value <JObject>("param").ToString()).Insert(1, "'index':1,").ToString()));
                        lst.Add(new SetPort(new StringBuilder(cmdobjs[2].Value <JObject>("param").ToString()).Insert(1, "'index':1,").ToString()));
                        lst.Add(new SetIP(new StringBuilder(cmdobjs[3].Value <JObject>("param").ToString()).Insert(1, "'index':2,").ToString()));
                        lst.Add(new SetPort(new StringBuilder(cmdobjs[4].Value <JObject>("param").ToString()).Insert(1, "'index':2,").ToString()));
                        lst.Add(new SetWorkMode(cmdobjs[5].Value <JObject>("param").ToString()));
                        lst.Add(new SetByteInterval(cmdobjs[6].Value <JObject>("param").ToString()));
                        lst.Add(new SetRetryTimes(cmdobjs[7].Value <JObject>("param").ToString()));
                        //lst.Add(new QuitConfig());
                    }
                    else
                    {
                        lst.Add(new SetReset());
                    }

                    atCommands.AddRange(lst);
                    return(atCommands);
                }
                catch (Exception ex)
                {
                    return(atCommands);
                }
            }
            lst.Add(new SetReset());
            atCommands.AddRange(lst);
            return(atCommands);
        }
        public void TestConfigCommandExecutor()
        {
            ConfigCommand cfgCmd = new ConfigCommand();

            cfgCmd.AddRange(new List <ATCommand> {
                new SetIP("{'ip':'192.168.1.145'}"), new SetPort("{'port':5050}"), new SetReset()
            });
            string        dtu     = "12345678";
            GprsDtuServer _server = new GprsDtuServer(5055);

            _server.Start();
            DacTaskContext context = new DacTaskContext()
            {
                DtuConnection = new GprsDtuConnection(_server),
                Node          = new DtuNode()
                {
                    DtuCode = dtu
                }
            };

            Thread.Sleep(8000);

            //conn = (GprsDtuConnection) _server.GetConnection(new DtuNode{DtuCode = dtu});

            if (context.DtuConnection != null && context.DtuConnection.IsAvaliable())
            {
                var cce = new ConfigCommandExecutor();
                //cce.Execute(conn, cfgCmd, 12000);
                ExecuteResult result = cce.Execute(null, context, 12000);
                // Assert.IsTrue(result.IsOK);
            }
            else
            {
                //Assert.
            }
        }