public float[] GetData(int channel, DateTime timeBegin, int secLen) { int channelNum = listChannel.Count; if (channelNum <= 0) { return(null); } if (timeBegin > this.EndTime) { return(null); } if (timeBegin.AddSeconds(secLen) < this.BeginTime) { return(null); } long startSec = (long)((timeBegin - this.BeginTime).TotalSeconds); int sampleRate = listChannel[0].SampleRate; int bytesPerSec = channelNum * sampleRate; long secTotal = (long)((this.Length - 512 * 2) * 1f / (channelNum * sampleRate)); //去掉最后一秒的数据 if (startSec + secLen > secTotal) { secLen = (int)(secTotal - startSec); } long startRd = (this.Offset + 512 * 2 + startSec * sampleRate * channelNum - 511) / 512L * 512; long rdOffset = (this.Offset + 512 * 2 + startSec * sampleRate * channelNum - startRd); long endRd = (this.Offset + 512 * 2 + sampleRate * (startSec + secLen) * channelNum + 511) / 512L * 512; disk.Position = startRd; byte[] adData = new byte[endRd - startRd]; float[] rdVal = new float[sampleRate * secLen]; int length = disk.Read(adData, 0, adData.Length); for (int i = 0; i < sampleRate * secLen; i++) { rdVal[i] = adData[i * channelNum + channel + rdOffset]; } return(rdVal); }
public RecordControl(DiskUtil disk) { this.IsValid = false; disk.Read(data, 0, data.Length); this.Tag = Encoding.ASCII.GetString(data, 0, 4); if (this.Tag != "ctrl") { return; } this.IsValid = true; this.TotalSector = BitConverter.ToInt32(data, 4); this.UsedSector = BitConverter.ToInt32(data, 8); }
public RecordDevice(DiskUtil disk) { this.IsValid = false; disk.Read(sectorData, 0, 512); this.Tag = Encoding.ASCII.GetString(sectorData, 0, 4); if (this.Tag != " dev") { return; } this.IsValid = true; this.Time = new DateTime(sectorData[4] + 2000, sectorData[5], sectorData[6], sectorData[7], sectorData[8], sectorData[9]); this.devInfo = new DeviceInfo(sectorData, 10); this.UsedSector = BitConverter.ToInt32(sectorData, 138); this.UsedRate = BitConverter.ToInt16(sectorData, 142); this.Overflow = BitConverter.ToInt32(sectorData, 144); }
public RecordFile(DiskUtil disk, long offset, int index) { this.disk = disk; this.Offset = offset; disk.Position = offset; device = new RecordDevice(disk); if (device.IsValid == false) { return; } disk.Read(dataChannel, 0, 512); string tag = ASCIIEncoding.ASCII.GetString(dataChannel, 0, 4); if (tag != " chn") { return; } int channelNum = dataChannel[4]; eventWaits = new EventWaitHandle[channelNum]; for (int i = 0; i < channelNum; i++) { AutoResetEvent autoEvent = new AutoResetEvent(false); SignalChannel info = new SignalChannel(this, autoEvent, dataChannel, 5 + 128 * i); eventWaits[i] = autoEvent; listChannel.Add(info); } this.FileIndex = index + 1; }