Exemple #1
0
        public void TestProcessResult()
        {
            DbAccessorHelper.Init(new MsDbAccessor("server=192.168.1.128;database=DW_iSecureCloud_Empty2.2;uid=sa;pwd=861004;pooling=false"));
            IDtuServer _dacServer;

            _dacServer = new GprsDtuServer(5005);
            DACTaskManager Dtm  = new DACTaskManager(_dacServer, DbAccessorHelper.DbAccessor.QueryDtuNodes(), null);
            var            rslt = new DACTaskResult();

            rslt.AddSensorResult(
                new SensorAcqResult {
                ErrorCode = 103, Sensor = new Sensor {
                    SensorID = 1, ProductId = 145
                }, Data = new LVDTData(560, 20)
            });
            rslt.AddSensorResult(
                new SensorAcqResult {
                Sensor = new Sensor {
                    SensorID = 2, ProductId = 145
                }, Data = new LVDTData(560, 20)
            });
            rslt.AddSensorResult(
                new SensorAcqResult {
                Sensor = new Sensor {
                    SensorID = 3, ProductId = 70
                }, Data = new TempHumidityData(180, -2)
            });

            new EtDataStatusConsumer(null)
            .ProcessResult(rslt);

            Assert.Pass();
        }
Exemple #2
0
 public void AtCommandTester()
 {
     int    dacServerPort = 5055;
     var    _DacServer    = new GprsDtuServer(dacServerPort);
     var    dtm           = new DACTaskManager(_DacServer, DbAccessorHelper.DbAccessor.QueryDtuNodes(), DbAccessorHelper.DbAccessor.GetUnfinishedTasks());
     string tid           = "";
     uint   dtu           = 2;
     int    taskId        = dtm.ArrangeInstantTask(tid, dtu, this.cmds, null);
 }
Exemple #3
0
 public void TestATCommandWorker()
 {
     IDtuServer     _DacServer = new GprsDtuServer(5055);
     DACTaskManager dtm        = new DACTaskManager(_DacServer, DbAccessorHelper.DbAccessor.QueryDtuNodes(), DbAccessorHelper.DbAccessor.GetUnfinishedTasks());
     // _DacServer.Start();
     // _DacServer.OnConnectStatusChanged += dtm.OnConnectionStatusChanged;
     string tid = "8d516ed8-568a-4228-bc53-2132c37cd7ce";
     uint   dtu = 90;
     //  int taskId = dtm.ArrangeInstantTask(tid, dtu, cmds, null);
 }
Exemple #4
0
        public void TestOnDtuConnected()
        {
            GprsDtuServer _server = new GprsDtuServer(5055);

            _server.Start();
            _server.OnConnectStatusChanged += OnConnectionStatusChanged;
            Thread.Sleep(6000);

            Thread t = new Thread(this.DoWork);

            t.Start();
            t.Join();
            Assert.IsTrue(connected);
        }
Exemple #5
0
        public void TestAtCommandExecutor()
        {
            GprsDtuServer _server = new GprsDtuServer(5055);

            _server.Start();
            string dtu = "12345678";

            Thread.Sleep(500);
            if (client.Connect(12345678, "22222222", "127.0.0.2"))
            {
                Console.WriteLine("Connected");
            }
            else
            {
                Console.WriteLine("ERROR");
            }
            client.OnReceived = (msg, len) => client.Send("OK");
            Thread.Sleep(500);
            GprsDtuConnection conn = (GprsDtuConnection)_server.GetConnection(new DtuNode {
                DtuCode = dtu
            });
            ATCommand       cmd = new EnterConfig();
            CommandExecutor ce  = new CommandExecutor();

            Assert.IsNotNull(conn);

            if (conn != null && conn.IsAvaliable())
            {
                ATCommandResult r = ce.Execute(conn, cmd);
                Assert.IsTrue(r.IsOK);
            }

            if (conn != null && conn.IsAvaliable())
            {
                cmd = new SetPort("{'port':5008}");
                ATCommandResult r = ce.Execute(conn, cmd);
                Assert.IsTrue(r.IsOK);
            }

            if (conn != null && conn.IsAvaliable())
            {
                cmd = new SetPort("{'port':5009");
                ATCommandResult r = ce.Execute(conn, cmd);
                Assert.IsTrue(r.IsOK);
            }
        }
        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.
            }
        }
Exemple #7
0
        public void TestMsSqlInstantTask()
        {
            // Client Simulator
            client             = new DtuClient("127.0.0.1", 5055);
            client.OnReceived += OnMsg;
            GprsDtuServer _server = new GprsDtuServer(5055);

            _server.Start();
            client.Connect(20120049, "18651895100", "192.168.1.42");
            DbAccessorHelper.Init(new MsDbAccessor(this.mssqlConnStr));
            // Thread.Sleep(8000);
            string      tid     = new Guid().ToString();
            List <uint> sensors = new List <uint> {
                (uint)17
            };
            DACTask ut = new DACTask(tid, 1, sensors, TaskType.INSTANT, this.OnTaskFinished); //

            tm = new DACTaskManager(_server, DbAccessorHelper.DbAccessor.QueryDtuNodes(), DbAccessorHelper.DbAccessor.GetUnfinishedTasks());
            //  tm.DealDailyWork();
            //           Thread.Sleep(8000);
            int r = tm.ArrangeInstantTask(tid, 1, sensors, this.OnTaskFinished, false);

            System.Console.WriteLine("result = {0}", r);
        }
Exemple #8
0
        public void TestRemoteDtuRead()
        {
            this.Log.Debug("TestRemoteDtuRead");
            IList <DtuNode> _nodes = new List <DtuNode>();
            DtuNode         dn1    = new DtuNode
            {
                DtuCode     = "20140168",
                DacTimeout  = 2,  // 10s timeout
                DacInterval = 10, //30s interval
                DtuId       = 999,
                NetworkType = NetworkType.gprs,
                Type        = DtuType.Gprs
            };
            DtuNode dn2 = new DtuNode
            {
                DtuCode     = "20140167",
                DacTimeout  = 6,  // 10s timeout
                DacInterval = 20, //30s interval
                DtuId       = 998,
                NetworkType = NetworkType.gprs,
                Type        = DtuType.Gprs
            };
            Sensor s02 = new Sensor
            {
                ProtocolType = (uint)ProtocolType.Pressure_MPM,
                DtuID        = 999,
                SensorID     = 1,
                ModuleNo     = 2,
                ChannelNo    = 0,
                FactorType   = (uint)SafetyFactor.StressStrainPoreWaterPressure,
                Name         = "Pressure 02"
            };
            Sensor s27 = new Sensor
            {
                ProtocolType = (uint)ProtocolType.Pressure_MPM,
                DtuID        = 999,
                SensorID     = 2,
                ModuleNo     = 27,
                ChannelNo    = 0,
                FactorType   = (uint)SafetyFactor.StressStrainPoreWaterPressure,
                Name         = "Pressure 27"
            };

            Sensor s5135 = new Sensor
            {
                ProtocolType = (uint)ProtocolType.VibratingWire_OLD, //
                DtuID        = 998,
                SensorID     = 3,
                ModuleNo     = 5135,
                ChannelNo    = 1,
                FactorType   = (uint)SafetyFactor.Forcesteelbar,
                Name         = "Pressure 5135"
            };

            _nodes.Add(dn1);
            //_nodes.Add(dn2);
            dn1.AddSensor(s02);
            dn1.AddSensor(s27);
            dn1.AddSensor(s5135);

            GprsDtuServer _server = new GprsDtuServer(5056);

            this.Log.Debug("Server started.");
            string sqlconn = "server=localhost;database=iSecureCloud;uid=tester;pwd=Fas123";

            // sqlconn = "server=192.168.1.128;database=DW_iSecureCloud_Empty2.2;uid=sa;pwd=861004";
            this.Log.DebugFormat("Connect to db: {0}", sqlconn);
            DbAccessorHelper.Init(new MsDbAccessor(sqlconn));

            _server.Start();

            tm = new DACTaskManager(_server, _nodes, null, DtuType.Gprs);
            tm.ArrangeTimedTask();
            Console.ReadLine();
        }