public SensorOriginalData[] QueryRows(int rowCount) { IList <SensorOriginalData> rows = new List <SensorOriginalData>(); StringBuilder fields = new StringBuilder(); int idx = 0; for (int i = Meta.ThemesDataOffset; i < Meta.ThemeColums.Length; i++) { fields.Append(",").Append(Meta.ThemeColums[i]);//.Append(" val_").Append(idx++); idx++; } string sql = string.Format("select ID,SENSOR_SET_ID,ModuleNo,ChannelID,ACQUISITION_DATETIME ACQ_TIME {0} from {1} where lastSyncTime is null limit 0,{2}", fields, Meta.TableName, rowCount); DataSet ds = _sqlHelper.Query(sql); foreach (DataRow row in ds.Tables[0].Rows) { SensorOriginalData d = new SensorOriginalData { ID = Convert.ToInt32(row["ID"]), ChannelNo = Convert.ToInt32(row["ChannelID"]), ModuleNo = Convert.ToInt32(row["ModuleNo"]), SID = Convert.ToInt32(row["SENSOR_SET_ID"]), AcqTime = DateTime.Parse(Convert.ToString(row["ACQ_TIME"])) }; d.Values = new double[idx]; for (int i = 0; i < idx; i++) { d.Values[i] = Convert.ToDouble(row[5 + i]); } rows.Add(d); } return(rows.ToArray()); }
// Tested 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); }