Example #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();
        }
Example #2
0
        public void TestSQLiteRegularTask()
        {
            // Client Simulator
            var cs = this.sqliteConStr.Split(',');

            DbAccessorHelper.Init(new SQLiteDbAccessor(cs[0]));
            // Thread.Sleep(8000);
            ComDtuServer _server = new ComDtuServer();

            _server.Start();

            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(), null, DtuType.Com);
            DACTaskManager.SensorMatcher = (sensor) =>
            {
                return(true);
            };
            //DACTaskManager.OnTimerDacFinished = (DACTaskResult r) =>
            //{
            //};

            tm.ArrangeTimedTask();
            Thread.Sleep(30000);
//            int r = tm.ArrangeInstantTask(tid, 1, sensors, this.OnTaskFinished, false);
//            System.Console.WriteLine("result = {0}", r);
        }
Example #3
0
        public DacService(string svrConfig, string busPath)
            : base(MyName, svrConfig, busPath)
        {
            string cs            = ConfigurationManager.AppSettings["SecureCloud"];
            int    dacServerPort = Convert.ToInt32(ConfigurationManager.AppSettings["Port"], 10);

            Log.InfoFormat("DBConnecting: {0}", cs);
            try
            {
                DbAccessorHelper.Init(new MsDbAccessor(cs));// 配置
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("系统初始化失败:{0}", ex.Message);
                return;
            }

            etDataStatus = new DataStatusConsumer(this);
            DACTaskManager.OnDacTaskFinished += etDataStatus.ProcessResult;
            DACTaskManager.OnDacTaskFinished += this.WriteDacTaskResultToJsonFile;

            this._warningHelper = new WarningHelper();
            this._dacServer     = new GprsDtuServer(dacServerPort);
            this._fileServer    = new FileDtuServer();
            this.Dtm            = new DACTaskManager(this._dacServer, DbAccessorHelper.DbAccessor.QueryDtuNodes(), null); // DbAccessorHelper.DbAccessor.GetUnfinishedTasks()
            this.Dtm.SetFileServer(this._fileServer);
            // Push/Pull mode.
            this.Pull(null, this.OnMessageReceived);
            this.Response(this.ResponseHandler);
            this.Subscribe("cm", "/cm/datachanged/dtu/sensor/", this.OnSubscribed);
            ConsoleCtrlManager.Instance.RegCmd("reload", this.LoadHandler); // 注册重新加载传感器信息
            ConsoleCtrlManager.Instance.Exit += this.Instance_Exit;
            this._warningHelper.UpdateAllDtuStatus();
        }
Example #4
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);
 }
Example #5
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);
 }
Example #6
0
        public EtService(string svrConfig, string busPath)
            : base(MyName, svrConfig, busPath)
        {
            string cs            = ConfigurationManager.AppSettings["SecureCloud"];
            int    dacServerPort = Convert.ToInt32(ConfigurationManager.AppSettings["Port"], 10);

            Log.InfoFormat("DBConnecting: {0}", cs);
            try
            {
                DbAccessorHelper.Init(new MsDbAccessor(cs)); // 配置
                DACTaskResultConsumerService.Init();         // 消费
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("系统初始化失败:{0}", ex.Message);
                return;
            }

            etDataStatus = new EtDataStatusConsumer(this);
            // 自定义消费者
            if (DACTaskResultConsumerService.Queues.Count == 0)
            {
                var queue = new DACTaskResultConsumerQueue(ConsumeType.Async);
                queue.Enqueue(etDataStatus);
                DACTaskResultConsumerService.AddComsumerQueue(queue);
            }
            else
            {
                DACTaskResultConsumerService.InsertComsumer(0, 2, etDataStatus);
                //DACTaskResultConsumerService.Queues[0].Insert(etDataStatus, 1);
            }

            _warningHelper = new WarningHelper();
            _dacServer     = new GprsDtuServer(dacServerPort);
            _fileServer    = new FileDtuServer();
            Dtm            = new DACTaskManager(_dacServer, DbAccessorHelper.DbAccessor.QueryDtuNodes(), null); // DbAccessorHelper.DbAccessor.GetUnfinishedTasks()
            Dtm.SetFileServer(_fileServer);
            // Push/Pull mode.
            Pull(null, OnMessageReceived);
            Response(ResponseHandler);
            Subscribe("cm", "/cm/datachanged/dtu/sensor/", OnSubscribed);
            ConsoleCtrlManager.Instance.RegCmd("reload", LoadHandler); // 注册重新加载传感器信息
            ConsoleCtrlManager.Instance.Exit += Instance_Exit;
            _warningHelper.UpdateAllDtuStatus();
        }
Example #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);
        }
Example #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();
        }