public void TestDataToSegment()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("sqlitedbcongxml", this.path);
            p.Init_Sqlite(args);
            var d = new SensorOriginalData
            {
                AcqTime   = System.DateTime.Now,
                ModuleNo  = 12,
                ChannelNo = 23,
                Type      = ProtocolType.VibratingWire,
                Values    = new double[] { 1924, 12.340000d, 2.340000d }
            };

            byte[] buff   = new byte[39];
            int    writed = p.DataToSegment(d, buff, 0);

            Assert.AreEqual(39, writed);
            Assert.AreEqual(ProtocolType.VibratingWire, (uint)ValueHelper.GetShort(buff, 0));
            Assert.AreEqual(1924, ValueHelper.GetDouble(buff, 15));
            Assert.AreEqual(12.34f, ValueHelper.GetDouble(buff, 23));
            Assert.AreEqual(2.34f, ValueHelper.GetDouble(buff, 31));

            Assert.AreEqual(23, p.CalcDataLength(1));
            Assert.AreEqual(31, p.CalcDataLength(2));
            Assert.AreEqual(39, p.CalcDataLength(3));
            Assert.AreEqual(47, p.CalcDataLength(4));
            Assert.AreEqual(55, p.CalcDataLength(5));

            Console.WriteLine("buff={0}", ValueHelper.BytesToHexStr(buff));
        }
Example #2
0
        public void TestSpliter()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("dbcongxml", this.path);
            p.Init(args);
            var d = new SensorOriginalData
            {
                AcqTime = DateTime.Now,
                SID     = 108,
                Type    = ProtocolType.GPS_ZHD,
                Values  = new double[]
                {
                    2.134, 1.945, 1.07
                }
            };

            byte[] buff   = new byte[39];
            int    writed = p.DataToSegment(d, buff, 0);

            TranMsg[] msgs = p.Splite(buff, writed);
            Assert.AreEqual(1, msgs.Length);
            Console.WriteLine("MSG1={0}", ValueHelper.BytesToHexStr(msgs[0].Marshall()));
        }
Example #3
0
        public SensorOriginalData[] QueryRows(int maxRows)
        {
            var sqlstr = new StringBuilder(this._sqlstr);

            if (this.TableInfo.DbType == DbType.SQLite)
            {
                sqlstr.AppendFormat(" limit 0,{0}", maxRows);
            }
            else
            {
                sqlstr.Insert(6, string.Format(" top {0} ", maxRows));
            }
            DataSet ds = this.SqlHelper.Query(sqlstr.ToString());
            IList <SensorOriginalData> rows = new List <SensorOriginalData>();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                var d = new SensorOriginalData()
                {
                    Type = this.TableInfo.Type
                };
                if (this.TableInfo.StandardFields.Contains("ID"))
                {
                    d.ID = Convert.ToInt32(row["ID"]);
                }
                if (this.TableInfo.StandardFields.Contains("SID"))
                {
                    d.SID = Convert.ToInt32(row["SID"]);
                }
                if (this.TableInfo.StandardFields.Contains("ModuleNo"))
                {
                    d.ModuleNo = Convert.ToInt32(row["ModuleNo"]);
                }
                if (this.TableInfo.StandardFields.Contains("ChannelNo"))
                {
                    d.ChannelNo = Convert.ToInt32(row["ChannelNo"]);
                }
                if (this.TableInfo.StandardFields.Contains("AcqTime"))
                {
                    d.AcqTime = DateTime.Parse(Convert.ToString(row["AcqTime"]));
                }
                d.Values = new double[this.TableInfo.DataCount];
                for (int i = 1; i <= this.TableInfo.DataCount; i++)
                {
                    d.Values[i - 1] = Convert.ToDouble(row[string.Format("Value{0}", i)]);
                }
                rows.Add(d);
            }

            return(rows.ToArray());
        }
Example #4
0
        public int DataToSegment(SensorOriginalData data, byte[] buff, int offset)
        {
            /*
             * 0-1(2)	     2(1)	            3,4(2)	    5,6(2)  7-13 (8)	         数据N*4
             * 数据类型 数据个数(N)	模块号	通道号	采集时间timestamp(ms) double(8) * 数据个数.
             */
            double[] values  = data.Values;
            int      toWrite = CalcDataLength(values.Length);

            ValueHelper.WriteShort(buff, offset, (short)data.Type);                         // 0,1: type
            buff[offset + 2] = (byte)values.Length;                                         // 数据个数
            ValueHelper.WriteShort(buff, offset + 3, (short)data.ModuleNo);                 // 3-4: 模块号
            ValueHelper.WriteShort(buff, offset + 5, (short)data.ChannelNo);                // 5-6: 通道号
            ValueHelper.WriteLong(buff, offset + 7, ValueHelper.MillSeconds(data.AcqTime)); //时间: 8
            for (int i = 0; i < values.Length; i++)
            {
                ValueHelper.WriteDouble(buff, offset + 15 + i * 8, (float)values[i]);
            }
            return(toWrite);
        }
        public void TestSpliter()
        {
            DbDacDataProvider           p    = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("sqlitedbcongxml", this.path);
            p.Init_Sqlite(args);
            var d = new SensorOriginalData
            {
                AcqTime   = System.DateTime.Now,
                ModuleNo  = 12,
                ChannelNo = 23,
                Type      = ProtocolType.VibratingWire,
                Values    = new double[] { 1924, 12.340000d, 2.340000d }
            };

            byte[] buff   = new byte[39];
            int    writed = p.DataToSegment(d, buff, 0);

            TranMsg[] msgs = p.Splite(buff, writed);
            Assert.AreEqual(1, msgs.Length);
            Console.WriteLine("MSG1={0}", ValueHelper.BytesToHexStr(msgs[0].Marshall()));
        }
Example #6
0
        public void TestDataToSegment()
        {
            DbDacDataProvider           dp   = new DbDacDataProvider();
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("dbcongxml", this.path);
            dp.Init(args);

            var d = new SensorOriginalData
            {
                AcqTime = DateTime.Now,
                SID     = 108,
                Type    = ProtocolType.GPS_ZHD,
                Values  = new double[]
                {
                    2.134, 1.945, 1.07
                }
            };

            byte[] bytes  = new byte[39];
            int    writed = dp.DataToSegment(d, bytes, 0);

            Assert.AreEqual(39, writed);

            Assert.AreEqual(ProtocolType.GPS_ZHD, (uint)ValueHelper.GetShort(bytes, 0));
            Assert.AreEqual(2.134f, ValueHelper.GetDouble(bytes, 15));
            Assert.AreEqual(1.945f, ValueHelper.GetDouble(bytes, 23));
            Assert.AreEqual(1.07f, ValueHelper.GetDouble(bytes, 31));

            Assert.AreEqual(23, dp.CalcDataLength(1));
            Assert.AreEqual(31, dp.CalcDataLength(2));
            Assert.AreEqual(39, dp.CalcDataLength(3));
            Assert.AreEqual(47, dp.CalcDataLength(4));
            Assert.AreEqual(55, dp.CalcDataLength(5));

            Console.WriteLine("buff={0}", ValueHelper.BytesToHexStr(bytes));
        }