Ejemplo n.º 1
0
        public void TestSnGpsTask()
        {
            if (System.IO.File.Exists("lastAcqDate.dat"))
            {
                System.IO.File.Delete("lastAcqDate.dat");
            }

            (new Gps_SN_SensorAdapter() as GpsBaseAdapter).UpdateSensorLastDataAcqTime(1, new DateTime(2015, 1, 28, 23, 51, 35));

            var adapterManager = SensorAdapterManager.InitializeManager();
            var taskexcutor    = new DACTaskExecutor(adapterManager);
            var dtusens        = new List <uint>();

            dtusens.Add(1);
            var task    = new DACTask("1", 100, dtusens, TaskType.TIMED, null);
            var dtunode = new DtuNode
            {
                DtuId       = 100,
                Type        = DtuType.File,
                NetworkType = NetworkType.hclocal
            };
            var s = new Sensor
            {
                SensorID     = 1,
                ModuleNo     = 9003,
                ProtocolType = 9403,
                ChannelNo    = 1,
                TableColums  = "SURFACE_DISPLACEMENT_X_VALUE,SURFACE_DISPLACEMENT_Y_VALUE,SURFACE_DISPLACEMENT_Z_VALUE"
            };

            s.AddParameter(new SensorParam(null)
            {
                Value = 2
            });
            s.AddParameter(new SensorParam(null)
            {
                Value = 2
            });
            s.AddParameter(new SensorParam(null)
            {
                Value = 2
            });
            s.AddParameter(new SensorParam(null)
            {
                Value = 0
            });
            dtunode.AddSensor(s);
            dtunode.AddProperty("param1", filepath);
            var conn   = new FileDtuConnection(dtunode);
            var contxt = new DacTaskContext()
            {
                Node          = dtunode,
                DtuConnection = conn
            };

            var dactaskresult = taskexcutor.Run(task, contxt);

            Assert.IsNotNull(dactaskresult);
            Assert.IsTrue(dactaskresult.Task.Status == DACTaskStatus.DONE);
            var sensorresults = dactaskresult.SensorResults;

            Assert.NotNull(sensorresults);
            Assert.IsNotEmpty(sensorresults);
            Assert.AreEqual(101, sensorresults.Count);
            var senres = sensorresults[0];

            Assert.IsTrue(senres.IsOK);
            var sendata = senres.Data;

            Assert.IsTrue(sendata is Gps3dData);
            Assert.AreEqual(sendata.RawValues[0], 4435175.4523 * 1000, 0.0000001);
            Assert.AreEqual(sendata.RawValues[1], 524121.0006 * 1000, 0.0000001);
            Assert.AreEqual(sendata.RawValues[2], 82.2112 * 1000, 0.0000001);
            Assert.AreEqual(sendata.ThemeValues[0].Value, 4435175.4523 * 1000 - 2, 0.0000001);
            Assert.AreEqual(sendata.ThemeValues[1].Value, 524121.0006 * 1000 - 2, 0.0000001);
            Assert.AreEqual(sendata.ThemeValues[2].Value, 82.2112 * 1000 - 2, 0.0000001);
        }
Ejemplo n.º 2
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();
        }