Esempio n. 1
0
        public Sensor GetSensor(Sensor sensor)
        {
            sensor.SensorID        = 32;
            sensor.StructId        = 4;
            sensor.ModuleNo        = 9590;
            sensor.ChannelNo       = 1;
            sensor.Name            = "K791左侧三阶平台2号测斜孔-中";
            sensor.FactorType      = 10;
            sensor.FactorTypeTable = "T_THEMES_DEFORMATION_DEEP_DISPLACEMENT";
            sensor.TableColums     =
                "DEEP_DISPLACEMENT_X_VALUE,DEEP_DISPLACEMENT_Y_VALUE,DEEP_CUMULATIVEDISPLACEMENT_X_VALUE,DEEP_CUMULATIVEDISPLACEMENT_Y_VALUE";
            sensor.ProductCode  = "FS-GGC01";
            sensor.ProtocolType = 1503;
            var para = new SensorParam(new FormulaParam
            {
                FID   = 2,
                Index = 1,
                Name  = "x0",
                Alias = "x方向角度初值",
                PID   = 20
            })
            {
                Value = 0.7675540000000
            };

            sensor.AddParameter(para);

            para = new SensorParam(new FormulaParam
            {
                FID   = 2,
                Index = 2,
                Name  = "y0",
                Alias = "y方向角度初值",
                PID   = 21
            })
            {
                Value = -0.0599570000000
            };
            sensor.AddParameter(para);

            para = new SensorParam(new FormulaParam
            {
                FID   = 2,
                Index = 1,
                Name  = "len",
                Alias = "测斜杆长度(mm)",
                PID   = 20
            })
            {
                Value = 3000.0000000000000
            };
            sensor.AddParameter(para);
            return(sensor);
        }
Esempio n. 2
0
        // 获取传感器参数定义。
        private void GetParameters(DataTable table, Sensor sensor, Dictionary <int, FormulaParam> formulaParamDict)
        {
            var sr = from r in table.AsEnumerable()
                     where r.Field <int>("SENSOR_ID") == sensor.SensorID
                     select r;

            if (!sr.Any())
            {
                return;
            }
            foreach (DataRow row in sr)
            {
                for (int i = 1; i < 7; i++)
                {
                    string pName  = string.Format("FormulaParaID{0}", i);
                    string pValue = string.Format("Parameter{0}", i);
                    if (row.IsNull(pName))
                    {
                        break;
                    }
                    int          pid  = Convert.ToInt32(row[pName]);
                    FormulaParam temp = this.GetFormulaParam(pid, formulaParamDict);
                    var          pi   = new SensorParam(temp);
                    if (row.IsNull(pValue))
                    {
                        Console.WriteLine("Sensor: {0}'s param: {1}-{2} 's value is NULL!", sensor.SensorID, i,
                                          temp.Name);
                    }
                    pi.Value = row.IsNull(pValue) ? 0 : Convert.ToDouble(row[pValue]);
                    sensor.AddParameter(pi);
                }
            }
        }
Esempio n. 3
0
        // 获取传感器参数定义。
        private void GetParameters(DataTable table, Sensor sensor)
        {
            var sr = from r in table.AsEnumerable()
                     where r.Field <int>("SENSOR_SET_ID") == sensor.SensorID
                     select r;

            if (!sr.Any())
            {
                return;
            }
            foreach (DataRow row in sr)
            {
                ushort paraCount = Convert.ToUInt16(row["ParaCount"]);
                for (int i = 1; i <= paraCount; i++)
                {
                    string pName  = string.Format("PARA_NAME_ID{0}", i);
                    string pValue = string.Format("PARAMETER{0}", i);
                    if (row.IsNull(pName))
                    {
                        break;
                    }
                    int          pid  = Convert.ToInt32(row[pName]);
                    FormulaParam temp = GetFormulaParam(pid);
                    SensorParam  pi   = new SensorParam(temp);
                    if (row.IsNull(pValue))
                    {
                        // TODO write Log.
                        Console.WriteLine("Sensor: {0}'s param: {1}-{2} 's value is NULL!", sensor.SensorID, i,
                                          temp.Name);
                    }
                    pi.Value = row.IsNull(pValue) ? 0 : Convert.ToDouble(row[pValue]);
                    sensor.AddParameter(pi);
                }
            }
        }
Esempio n. 4
0
        public void TestHcGpsParseData()
        {
            byte[] data =
                Encoding.ASCII.GetBytes(
                    "2,3,2014/8/14  6:54:43,30:49:59.31026N,121:31:23.58789E,3639542.8400,2680979.7673,28.0908,30:49:59.30982N,121:31:23.58559E,3639542.8124,2680979.7071,28.1878");
            IFileSensorAdapter sa = new Gps_HC_SensorAdapter();

            var sensor = new Sensor {
                ModuleNo = 3, TableColums = "height"
            };

            sensor.AddParameter(new SensorParam(null)
            {
                Value = 1
            });
            sensor.AddParameter(new SensorParam(null)
            {
                Value = 1
            });
            sensor.AddParameter(new SensorParam(null)
            {
                Value = 1
            });
            sensor.AddParameter(new SensorParam(null)
            {
                Value = 0
            });
            var r = new SensorAcqResult {
                Response = data, ErrorCode = (int)Errors.SUCCESS, Sensor = sensor
            };

            sa.ParseResult(ref r);
            var gpsData = r.Data as GpsHeightData;

            Assert.IsNotNull(gpsData);
            //Assert.AreEqual(Convert.ToDateTime("2014-8-14  6:54:43"), gpsData.AcqTime);
            Assert.AreEqual(28187.8, gpsData.CoordHeight);
            Assert.AreEqual(28186.8, gpsData.ChangeHeight);
        }
Esempio n. 5
0
        public void TestParseResponseLvdtnew()
        {
            ISensorAdapter sa     = new VoltageSensorAdapter();
            var            sensor = new Sensor()
            {
                ModuleNo    = 1010,
                ChannelNo   = 10,
                ProductCode = "FS-LFV-V0P10",
                FormulaID   = 16
            };

            sensor.AddParameter(new SensorParam(new FormulaParam())
            {
                Value = 1.5
            });
            sensor.AddParameter(new SensorParam(new FormulaParam())
            {
                Value = 1.5
            });
            sensor.AddParameter(new SensorParam(new FormulaParam())
            {
                Value = 2.0
            });
            var res = new SensorAcqResult()
            {
                Response = ValueHelper.StrToToHexByte("fe 46 41 53 17 00 00 03 f2 01 01 0a 08 00 00 00 00 00 00 00 00 00 4e ef"),
                Sensor   = sensor
            };

            sa.ParseResult(ref res);
            var data = res.Data;

            Assert.IsNotNull(data);
            Assert.AreEqual(5.00, data.RawValues[1], 0.00000001);
            Assert.AreEqual(6.00, data.PhyValues[0], 0.00000001);
        }
Esempio n. 6
0
        public void TestParseResult()
        {
            DbAccessorHelper.Init(new MsDbAccessor(connstr));// 配置
            // X U 0 0 3 0 0 2
            var bts = ValueHelper.StrToToHexByte("32 55 30 30 33 30 30 32");
            var s   = new Sensor()
            {
                ModuleNo = 2
            };

            s.AddParameter(new SensorParam(new FormulaParam())
            {
                Value = 0.002
            });
            var res = new SensorAcqResult
            {
                Response = bts,
                Sensor   = s
            };

            var sa = new FTM50SSmallLaserSensorAdapter();

            sa.ParseResult(ref res);
            var data = res.Data;

            Assert.IsNotNull(data);
            Assert.AreEqual(3.002, data.RawValues[0], 0.0000001);
            Assert.AreEqual(3000.000, data.PhyValues[0], 0.0000001);
            bts = ValueHelper.StrToToHexByte("32 55 30 46 33 59 30 32");
            Trace.WriteLine(res.Data.JsonResultData);
            res.Response = bts;
            try
            {
                sa.ParseResult(ref res);
            }
            catch
            {
            }

            Assert.AreEqual((int)Errors.ERR_DATA_PARSEFAILED, res.ErrorCode);
            Trace.WriteLine(res.Data.JsonResultData);
            bts          = ValueHelper.StrToToHexByte("32 56 30 46 33 59 30 32");
            res.Response = bts;
            sa.ParseResult(ref res);
            Assert.AreEqual((int)Errors.ERR_INVALID_DATA, res.ErrorCode);
            Trace.WriteLine(res.Data.JsonResultData);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public static Sensor GetSensorInfo(uint sensorId)
        {
            string sql = string.Format(@"
SELECT 
	s.STRUCT_ID structId,
    s.SENSOR_ID sid,
    s.SENSOR_LOCATION_DESCRIPTION name,
    s.SAFETY_FACTOR_TYPE_ID factor,
    factor.THEMES_TABLE_NAME tablename,
    factor.THEMES_COLUMNS columns,
    s.Identification sensortype,
    s.Enable enable,
    product.PRODUCT_ID pid,
    product.PRODUCT_CODE pcode,
    protocol.PROTOCOL_CODE protocol,
    product.FORMAULAID formulaid
FROM T_DIM_SENSOR as s
join T_DIM_SENSOR_PRODUCT product on s.PRODUCT_SENSOR_ID=product.PRODUCT_ID
left join T_DIM_PROTOCOL_TYPE protocol on product.PROTOCOL_ID=protocol.PROTOCOL_ID
join T_DIM_SAFETY_FACTOR_TYPE factor on s.SAFETY_FACTOR_TYPE_ID=factor.SAFETY_FACTOR_TYPE_ID
WHERE s.SENSOR_ID = {0}
", sensorId);

            try
            {
                var dt = _sqlHelper.Query(sql).Tables[0];
                if (dt.Rows.Count == 0)
                {
                    throw new Exception("sensor: [" + sensorId + "] config is incomplete");
                }

                Sensor sensor = new Sensor()
                {
                    StructId        = Convert.ToUInt32(dt.Rows[0]["structId"]),
                    SensorID        = Convert.ToUInt32(dt.Rows[0]["sid"]),
                    Name            = dt.Rows[0]["name"].ToString(),
                    FactorType      = Convert.ToUInt32(dt.Rows[0]["factor"]),
                    FactorTypeTable = dt.Rows[0]["tablename"].ToString(),
                    TableColums     = dt.Rows[0]["columns"].ToString(),
                    SensorType      = (SensorType)dt.Rows[0]["sensortype"],
                    Enabled         = !Convert.ToBoolean(dt.Rows[0]["enable"]),
                    ProductId       = Convert.ToInt32(dt.Rows[0]["pid"]),
                    ProductCode     = dt.Rows[0]["pcode"].ToString(),
                    ProtocolType    =
                        DBNull.Value.Equals(dt.Rows[0]["protocol"])
                                                ? 0
                                                : Convert.ToUInt32(dt.Rows[0]["protocol"]),
                    FormulaID =
                        DBNull.Value.Equals(dt.Rows[0]["formulaid"])
                                                ? 0
                                                : Convert.ToUInt32(dt.Rows[0]["formulaid"])
                };

                if (sensor.FormulaID != 0)
                {
                    foreach (SensorParam param in GetSensorParam(sensor))
                    {
                        sensor.AddParameter(param);
                    }
                }

                return(sensor);
            }
            catch (SqlException e)
            {
                throw new Exception("sql exception when querying sensor: [" + sensorId + "] info", e);
            }
            catch (Exception e)
            {
                throw new Exception("query sensor: [" + sensorId + "] config info error", e);
            }
        }