public Task OnMajor(DateTime time, ReadingData data) { return Task.Run(() => { WriteReading(true, time, data); }); }
public Task OnMinor(DateTime time, ReadingData data) { return Task.Run(() => { WriteReading(false, time, data); }); }
public Task OnSecond(DateTime time, ReadingData data, ReadingData minorData, ReadingData majorData) { return Task.Run(() => { double value = (double)typeof(ReadingData).GetMethod(displayItem).Invoke(data, new object[] { }); DispatcherHelper.CheckBeginInvokeOnUI(() => { LineValues.Add(new Tuple<DateTime, double>(time, value)); }); }); }
private void TestReadings(double expected, List <double> readings) { List <ReadingData> readingsData = new EditableList <ReadingData>(); foreach (var readingData in readings) { readingsData.Add(new ReadingData() { LAeq = readingData }); } var result = ReadingData.Average(readingsData); Assert.AreEqual(Math.Round(expected, 2), Math.Round(result.LAeq, 2)); }
public Task<ReadingData> GetSecondReading() { return Task.Run(() => { ReadingData reading = new ReadingData(); lock (deviceLock) { logger.Trace("Performing seconds reading from NTI XL2 on port {0}", portName); if (!DeviceAction((serialPort, token) => { token.ThrowIfCancellationRequested(); // Initiate first measurement this.WriteLine(serialPort, NTIXL2Commands.InitiateMeasurement); if(token.IsCancellationRequested) return; // ask for leq this.WriteLine(serialPort, NTIXL2Commands.Measurement + " LAEQ LAFMAX LAFMIN LZFMAX LZFMIN"); if (token.IsCancellationRequested) return; // getting LEQ reading.LAeq = NTIXL2Utilities.ParseMeasurement(ReadToDB(serialPort)); reading.LAMax = NTIXL2Utilities.ParseMeasurement(ReadToDB(serialPort)); reading.LAMin = NTIXL2Utilities.ParseMeasurement(ReadToDB(serialPort)); reading.LZMax = NTIXL2Utilities.ParseMeasurement(ReadToDB(serialPort)); reading.LZMin = NTIXL2Utilities.ParseMeasurement(ReadToDB(serialPort)); // Getting EQ this.WriteLine(serialPort, NTIXL2Commands.Octive); reading.LAeqOctaveBandOneThird = NTIXL2Utilities.ParseOctive(ReadToDB(serialPort)); previousReadings.AddLast(new Tuple<DateTime, ReadingData>(DateTime.Now, reading)); logger.Trace("LAeq response {0} from NTI LX2 port {1}.", reading.LAeq, portName); })) { return null; } } // Null reading if (reading.LAeq < 0) { return null; } return reading; }); }
public Task<ReadingData> GetMajorReading() { return Task.Run(() => { RemoveOldReadings(); var reading = new ReadingData(); lock (previousReadings) { if (previousReadings.Count == 0) { return null; } reading = ReadingData.Average(previousReadings.Select(x => x.Item2).ToList()); } return reading; }); }
public Task OnMajor(DateTime time, ReadingData data) { return Task.FromResult<object>(null); }
public static ReadingData Average(List<ReadingData> readings) { var result = new ReadingData() { lAeqOctaveBandOneThird = new OctaveBandOneThird(), LAeqOctaveBandOneOne = new OctaveBandOneOne() }; foreach (var readingData in readings) { result.LAeq += DecibelHelper.GetPowerFromDecibel(readingData.LAeq); result.LAMax += DecibelHelper.GetPowerFromDecibel(readingData.LAMax); result.LAMin += DecibelHelper.GetPowerFromDecibel(readingData.LAMin); result.LZMax += DecibelHelper.GetPowerFromDecibel(readingData.LZMax); result.LZMin += DecibelHelper.GetPowerFromDecibel(readingData.LZMin); // OneOne result.LAeqOctaveBandOneOne.Hz16 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz16); result.LAeqOctaveBandOneOne.Hz31_5 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz31_5); result.LAeqOctaveBandOneOne.Hz63 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz63); result.LAeqOctaveBandOneOne.Hz125 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz125); result.LAeqOctaveBandOneOne.Hz250 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz250); result.LAeqOctaveBandOneOne.Hz500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz500); result.LAeqOctaveBandOneOne.Hz1000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz1000); result.LAeqOctaveBandOneOne.Hz2000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz2000); result.LAeqOctaveBandOneOne.Hz4000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz4000); result.LAeqOctaveBandOneOne.Hz8000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz8000); result.LAeqOctaveBandOneOne.Hz16000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz16000); // OneThird result.LAeqOctaveBandOneThird.Hz6_3 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz6_3); result.LAeqOctaveBandOneThird.Hz8 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz8); result.LAeqOctaveBandOneThird.Hz10 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz10); result.LAeqOctaveBandOneThird.Hz12_5 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz12_5); result.LAeqOctaveBandOneThird.Hz16 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz16); result.LAeqOctaveBandOneThird.Hz20 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz20); result.LAeqOctaveBandOneThird.Hz25 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz25); result.LAeqOctaveBandOneThird.Hz31_5 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz31_5); result.LAeqOctaveBandOneThird.Hz40 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz40); result.LAeqOctaveBandOneThird.Hz50 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz50); result.LAeqOctaveBandOneThird.Hz63 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz63); result.LAeqOctaveBandOneThird.Hz80 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz80); result.LAeqOctaveBandOneThird.Hz100 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz100); result.LAeqOctaveBandOneThird.Hz125 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz125); result.LAeqOctaveBandOneThird.Hz160 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz160); result.LAeqOctaveBandOneThird.Hz200 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz200); result.LAeqOctaveBandOneThird.Hz250 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz250); result.LAeqOctaveBandOneThird.Hz315 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz315); result.LAeqOctaveBandOneThird.Hz400 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz400); result.LAeqOctaveBandOneThird.Hz500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz500); result.LAeqOctaveBandOneThird.Hz630 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz630); result.LAeqOctaveBandOneThird.Hz800 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz800); result.LAeqOctaveBandOneThird.Hz1000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz1000); result.LAeqOctaveBandOneThird.Hz1250 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz1250); result.LAeqOctaveBandOneThird.Hz1600 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz1600); result.LAeqOctaveBandOneThird.Hz2000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz2000); result.LAeqOctaveBandOneThird.Hz2500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz2500); result.LAeqOctaveBandOneThird.Hz3150 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz3150); result.LAeqOctaveBandOneThird.Hz4000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz4000); result.LAeqOctaveBandOneThird.Hz5000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz5000); result.LAeqOctaveBandOneThird.Hz6300 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz6300); result.LAeqOctaveBandOneThird.Hz8000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz8000); result.LAeqOctaveBandOneThird.Hz10000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz10000); result.LAeqOctaveBandOneThird.Hz12500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz12500); result.LAeqOctaveBandOneThird.Hz16000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz16000); result.LAeqOctaveBandOneThird.Hz20000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz20000); } // Avarage the power and convert that to decibel result.LAeq = DecibelHelper.GetDecibelFromPower(result.LAeq / readings.Count); result.LAMax = DecibelHelper.GetDecibelFromPower(result.LAMax / readings.Count); result.LAMin = DecibelHelper.GetDecibelFromPower(result.LAMin / readings.Count); result.LZMax = DecibelHelper.GetDecibelFromPower(result.LZMax / readings.Count); result.LZMin = DecibelHelper.GetDecibelFromPower(result.LZMin / readings.Count); // OneOne result.LAeqOctaveBandOneOne.Hz16 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz16 / readings.Count); result.LAeqOctaveBandOneOne.Hz31_5 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz31_5 / readings.Count); result.LAeqOctaveBandOneOne.Hz63 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz63 / readings.Count); result.LAeqOctaveBandOneOne.Hz125 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz125 / readings.Count); result.LAeqOctaveBandOneOne.Hz250 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz250 / readings.Count); result.LAeqOctaveBandOneOne.Hz500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz500 / readings.Count); result.LAeqOctaveBandOneOne.Hz1000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz1000 / readings.Count); result.LAeqOctaveBandOneOne.Hz2000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz2000 / readings.Count); result.LAeqOctaveBandOneOne.Hz4000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz4000 / readings.Count); result.LAeqOctaveBandOneOne.Hz8000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz8000 / readings.Count); result.LAeqOctaveBandOneOne.Hz16000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz16000 / readings.Count); // OneThird result.LAeqOctaveBandOneThird.Hz6_3 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz6_3 / readings.Count); result.LAeqOctaveBandOneThird.Hz8 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz8 / readings.Count); result.LAeqOctaveBandOneThird.Hz10 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz10 / readings.Count); result.LAeqOctaveBandOneThird.Hz12_5 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz12_5 / readings.Count); result.LAeqOctaveBandOneThird.Hz16 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz16 / readings.Count); result.LAeqOctaveBandOneThird.Hz20 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz20 / readings.Count); result.LAeqOctaveBandOneThird.Hz25 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz25 / readings.Count); result.LAeqOctaveBandOneThird.Hz31_5 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz31_5 / readings.Count); result.LAeqOctaveBandOneThird.Hz40 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz40 / readings.Count); result.LAeqOctaveBandOneThird.Hz50 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz50 / readings.Count); result.LAeqOctaveBandOneThird.Hz63 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz63 / readings.Count); result.LAeqOctaveBandOneThird.Hz80 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz80 / readings.Count); result.LAeqOctaveBandOneThird.Hz100 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz100 / readings.Count); result.LAeqOctaveBandOneThird.Hz125 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz125 / readings.Count); result.LAeqOctaveBandOneThird.Hz160 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz160 / readings.Count); result.LAeqOctaveBandOneThird.Hz200 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz200 / readings.Count); result.LAeqOctaveBandOneThird.Hz250 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz250 / readings.Count); result.LAeqOctaveBandOneThird.Hz315 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz315 / readings.Count); result.LAeqOctaveBandOneThird.Hz400 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz400 / readings.Count); result.LAeqOctaveBandOneThird.Hz500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz500 / readings.Count); result.LAeqOctaveBandOneThird.Hz630 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz630 / readings.Count); result.LAeqOctaveBandOneThird.Hz800 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz800 / readings.Count); result.LAeqOctaveBandOneThird.Hz1000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz1000 / readings.Count); result.LAeqOctaveBandOneThird.Hz1250 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz1250 / readings.Count); result.LAeqOctaveBandOneThird.Hz1600 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz1600 / readings.Count); result.LAeqOctaveBandOneThird.Hz2000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz2000 / readings.Count); result.LAeqOctaveBandOneThird.Hz2500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz2500 / readings.Count); result.LAeqOctaveBandOneThird.Hz3150 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz3150 / readings.Count); result.LAeqOctaveBandOneThird.Hz4000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz4000 / readings.Count); result.LAeqOctaveBandOneThird.Hz5000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz5000 / readings.Count); result.LAeqOctaveBandOneThird.Hz6300 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz6300 / readings.Count); result.LAeqOctaveBandOneThird.Hz8000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz8000 / readings.Count); result.LAeqOctaveBandOneThird.Hz10000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz10000 / readings.Count); result.LAeqOctaveBandOneThird.Hz12500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz12500 / readings.Count); result.LAeqOctaveBandOneThird.Hz16000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz16000 / readings.Count); result.LAeqOctaveBandOneThird.Hz20000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz20000 / readings.Count); return result; }
public Task OnSecond(DateTime time, ReadingData data, ReadingData minorData, ReadingData majorData) { return Task.Run(() => { SendMessageToAll(string.Format(TcpMessages.OnSecondResponse, JsonConvert.SerializeObject(new TcpWrapperOnSecond() { Second = data, Minor = minorData, Major = majorData }))); }); }
public Task OnMajor(DateTime time, ReadingData data) { return Task.Run(() => { SendMessageToAll(string.Format(TcpMessages.OnMajorResponse, JsonConvert.SerializeObject(data))); }); }
public static ReadingData Average(ICollection <ReadingData> readings) { var result = new ReadingData() { lAeqOctaveBandOneThird = new OctaveBandOneThird(), LAeqOctaveBandOneOne = new OctaveBandOneOne() }; foreach (var readingData in readings) { result.LAeq += DecibelHelper.GetPowerFromDecibel(readingData.LAeq); result.LCeq += DecibelHelper.GetPowerFromDecibel(readingData.LCeq); result.LAMax += DecibelHelper.GetPowerFromDecibel(readingData.LAMax); result.LAMin += DecibelHelper.GetPowerFromDecibel(readingData.LAMin); result.LZMax += DecibelHelper.GetPowerFromDecibel(readingData.LZMax); result.LZMin += DecibelHelper.GetPowerFromDecibel(readingData.LZMin); // OneOne result.LAeqOctaveBandOneOne.Hz16 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz16); result.LAeqOctaveBandOneOne.Hz31_5 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz31_5); result.LAeqOctaveBandOneOne.Hz63 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz63); result.LAeqOctaveBandOneOne.Hz125 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz125); result.LAeqOctaveBandOneOne.Hz250 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz250); result.LAeqOctaveBandOneOne.Hz500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz500); result.LAeqOctaveBandOneOne.Hz1000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz1000); result.LAeqOctaveBandOneOne.Hz2000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz2000); result.LAeqOctaveBandOneOne.Hz4000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz4000); result.LAeqOctaveBandOneOne.Hz8000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz8000); result.LAeqOctaveBandOneOne.Hz16000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneOne.Hz16000); // OneThird result.LAeqOctaveBandOneThird.Hz6_3 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz6_3); result.LAeqOctaveBandOneThird.Hz8 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz8); result.LAeqOctaveBandOneThird.Hz10 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz10); result.LAeqOctaveBandOneThird.Hz12_5 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz12_5); result.LAeqOctaveBandOneThird.Hz16 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz16); result.LAeqOctaveBandOneThird.Hz20 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz20); result.LAeqOctaveBandOneThird.Hz25 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz25); result.LAeqOctaveBandOneThird.Hz31_5 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz31_5); result.LAeqOctaveBandOneThird.Hz40 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz40); result.LAeqOctaveBandOneThird.Hz50 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz50); result.LAeqOctaveBandOneThird.Hz63 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz63); result.LAeqOctaveBandOneThird.Hz80 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz80); result.LAeqOctaveBandOneThird.Hz100 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz100); result.LAeqOctaveBandOneThird.Hz125 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz125); result.LAeqOctaveBandOneThird.Hz160 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz160); result.LAeqOctaveBandOneThird.Hz200 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz200); result.LAeqOctaveBandOneThird.Hz250 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz250); result.LAeqOctaveBandOneThird.Hz315 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz315); result.LAeqOctaveBandOneThird.Hz400 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz400); result.LAeqOctaveBandOneThird.Hz500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz500); result.LAeqOctaveBandOneThird.Hz630 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz630); result.LAeqOctaveBandOneThird.Hz800 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz800); result.LAeqOctaveBandOneThird.Hz1000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz1000); result.LAeqOctaveBandOneThird.Hz1250 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz1250); result.LAeqOctaveBandOneThird.Hz1600 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz1600); result.LAeqOctaveBandOneThird.Hz2000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz2000); result.LAeqOctaveBandOneThird.Hz2500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz2500); result.LAeqOctaveBandOneThird.Hz3150 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz3150); result.LAeqOctaveBandOneThird.Hz4000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz4000); result.LAeqOctaveBandOneThird.Hz5000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz5000); result.LAeqOctaveBandOneThird.Hz6300 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz6300); result.LAeqOctaveBandOneThird.Hz8000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz8000); result.LAeqOctaveBandOneThird.Hz10000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz10000); result.LAeqOctaveBandOneThird.Hz12500 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz12500); result.LAeqOctaveBandOneThird.Hz16000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz16000); result.LAeqOctaveBandOneThird.Hz20000 += DecibelHelper.GetPowerFromDecibel(readingData.LAeqOctaveBandOneThird.Hz20000); } // Avarage the power and convert that to decibel result.LAeq = DecibelHelper.GetDecibelFromPower(result.LAeq / readings.Count); result.LCeq = DecibelHelper.GetDecibelFromPower(result.LCeq / readings.Count); result.LAMax = DecibelHelper.GetDecibelFromPower(result.LAMax / readings.Count); result.LAMin = DecibelHelper.GetDecibelFromPower(result.LAMin / readings.Count); result.LZMax = DecibelHelper.GetDecibelFromPower(result.LZMax / readings.Count); result.LZMin = DecibelHelper.GetDecibelFromPower(result.LZMin / readings.Count); // OneOne result.LAeqOctaveBandOneOne.Hz16 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz16 / readings.Count); result.LAeqOctaveBandOneOne.Hz31_5 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz31_5 / readings.Count); result.LAeqOctaveBandOneOne.Hz63 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz63 / readings.Count); result.LAeqOctaveBandOneOne.Hz125 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz125 / readings.Count); result.LAeqOctaveBandOneOne.Hz250 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz250 / readings.Count); result.LAeqOctaveBandOneOne.Hz500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz500 / readings.Count); result.LAeqOctaveBandOneOne.Hz1000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz1000 / readings.Count); result.LAeqOctaveBandOneOne.Hz2000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz2000 / readings.Count); result.LAeqOctaveBandOneOne.Hz4000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz4000 / readings.Count); result.LAeqOctaveBandOneOne.Hz8000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz8000 / readings.Count); result.LAeqOctaveBandOneOne.Hz16000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneOne.Hz16000 / readings.Count); // OneThird result.LAeqOctaveBandOneThird.Hz6_3 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz6_3 / readings.Count); result.LAeqOctaveBandOneThird.Hz8 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz8 / readings.Count); result.LAeqOctaveBandOneThird.Hz10 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz10 / readings.Count); result.LAeqOctaveBandOneThird.Hz12_5 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz12_5 / readings.Count); result.LAeqOctaveBandOneThird.Hz16 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz16 / readings.Count); result.LAeqOctaveBandOneThird.Hz20 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz20 / readings.Count); result.LAeqOctaveBandOneThird.Hz25 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz25 / readings.Count); result.LAeqOctaveBandOneThird.Hz31_5 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz31_5 / readings.Count); result.LAeqOctaveBandOneThird.Hz40 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz40 / readings.Count); result.LAeqOctaveBandOneThird.Hz50 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz50 / readings.Count); result.LAeqOctaveBandOneThird.Hz63 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz63 / readings.Count); result.LAeqOctaveBandOneThird.Hz80 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz80 / readings.Count); result.LAeqOctaveBandOneThird.Hz100 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz100 / readings.Count); result.LAeqOctaveBandOneThird.Hz125 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz125 / readings.Count); result.LAeqOctaveBandOneThird.Hz160 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz160 / readings.Count); result.LAeqOctaveBandOneThird.Hz200 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz200 / readings.Count); result.LAeqOctaveBandOneThird.Hz250 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz250 / readings.Count); result.LAeqOctaveBandOneThird.Hz315 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz315 / readings.Count); result.LAeqOctaveBandOneThird.Hz400 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz400 / readings.Count); result.LAeqOctaveBandOneThird.Hz500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz500 / readings.Count); result.LAeqOctaveBandOneThird.Hz630 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz630 / readings.Count); result.LAeqOctaveBandOneThird.Hz800 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz800 / readings.Count); result.LAeqOctaveBandOneThird.Hz1000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz1000 / readings.Count); result.LAeqOctaveBandOneThird.Hz1250 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz1250 / readings.Count); result.LAeqOctaveBandOneThird.Hz1600 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz1600 / readings.Count); result.LAeqOctaveBandOneThird.Hz2000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz2000 / readings.Count); result.LAeqOctaveBandOneThird.Hz2500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz2500 / readings.Count); result.LAeqOctaveBandOneThird.Hz3150 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz3150 / readings.Count); result.LAeqOctaveBandOneThird.Hz4000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz4000 / readings.Count); result.LAeqOctaveBandOneThird.Hz5000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz5000 / readings.Count); result.LAeqOctaveBandOneThird.Hz6300 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz6300 / readings.Count); result.LAeqOctaveBandOneThird.Hz8000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz8000 / readings.Count); result.LAeqOctaveBandOneThird.Hz10000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz10000 / readings.Count); result.LAeqOctaveBandOneThird.Hz12500 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz12500 / readings.Count); result.LAeqOctaveBandOneThird.Hz16000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz16000 / readings.Count); result.LAeqOctaveBandOneThird.Hz20000 = DecibelHelper.GetDecibelFromPower(result.LAeqOctaveBandOneThird.Hz20000 / readings.Count); return(result); }
private Task StartRemoveReader() { return Task.Run(async () => { while (run) { try { TcpClient client = new TcpClient(ip, port); try { OnConnectionStatus(true); using (StreamReader reader = new StreamReader(client.GetStream(), Encoding.UTF8)) { CancellationTokenSource token = new CancellationTokenSource(); token.CancelAfter(new TimeSpan(0, 0, 15)); // If no message after 15 sek = disconnected string line; while ((line = await reader.ReadLineAsync().WithCancellation(token.Token).ConfigureAwait(false)) != null) { if (this.engine == null) { continue; } if (line.StartsWith(TCPServerListener.TcpMessages.OnMinorResponse.Replace("{0}", ""))) { var json = line.Substring( TCPServerListener.TcpMessages.OnMinorResponse.Replace("{0}", "").Length); this.lastMinorReading = JsonConvert.DeserializeObject<ReadingData>(json); this.engine.OnMinorInterval(DateTime.Now); } else if ( line.StartsWith(TCPServerListener.TcpMessages.OnMajorResponse.Replace("{0}", ""))) { var json = line.Substring( TCPServerListener.TcpMessages.OnMajorResponse.Replace("{0}", "") .Length); this.lastMajorReading = JsonConvert.DeserializeObject<ReadingData>(json); this.engine.OnMajorInterval(DateTime.Now); } else if ( line.StartsWith(TCPServerListener.TcpMessages.OnSecondResponse.Replace("{0}", ""))) { var json = line.Substring( TCPServerListener.TcpMessages.OnSecondResponse.Replace("{0}", "") .Length); var wrapper = JsonConvert.DeserializeObject<TcpWrapperOnSecond>(json); this.lastSecondReading = wrapper.Second; this.engine.OnSecond(DateTime.Now, wrapper.Second, wrapper.Minor, wrapper.Major); } token.CancelAfter(new TimeSpan(0, 0, 15)); // If no message after 15 sek = disconnected } } } catch (Exception exp) { OnConnectionStatus(false); logger.Warn(exp, "Connection to remote device {0}:{1} lost, trying to reconnect.", ip, port); // Try and close it just to be sure. try { client.Close(); } catch { } client = new TcpClient(ip, port); } } catch (Exception exp) { logger.Error(exp, "Unable to make connection to remote server {0}:{1}.", ip, port); } } OnConnectionStatus(false); }); }
public Task Close() { return Task.Run(() => { ReadingData reading = new ReadingData(); lock (deviceLock) { logger.Trace("Telling NTI XL2 on port {0} to stop the measurements.", portName); DeviceAction((serialPort, token) => { token.ThrowIfCancellationRequested(); // Initiate first measurement this.WriteLine(serialPort, NTIXL2Commands.Stop); }); } performClose(); }); }
public Task<ReadingData> GetMinorReading() { return Task.Run(() => { RemoveOldReadings(); var reading = new ReadingData(); lock (previousReadings) { var minorReadings = previousReadings.Where(x => x.Item1 >= DateTime.Now - minorInterval).ToList(); if (!minorReadings.Any()) { return null; } reading = ReadingData.Average(minorReadings.Select(x=>x.Item2).ToList()); } return reading; }); }
private void WriteOfline(bool major, DateTime time, ReadingData data, Guid readingGuid) { lock (LogFileLock) { DirectoryInfo directory = new DirectoryInfo(DataFolder); if (!directory.Exists) { directory.Create(); } FileInfo file = new FileInfo(Path.Combine(directory.FullName, Id + ".bin")); if (!file.Exists) { using (var f = file.Create()) { } File.WriteAllLines(file.FullName, new[]{ JsonConvert.SerializeObject(new MeasurementSettingsDataStorageWarpper() { Id = Id, Created = created, MeasurementSettings = Settings })}); } File.AppendAllLines(file.FullName, new []{ JsonConvert.SerializeObject(new ReadingDataDataStorageWarpper() { Id = readingGuid, Data = data, IsMajor = major, Time = time }) }); } }
private async void WriteReading(bool major, DateTime time, ReadingData data) { var readingGuid = Guid.NewGuid(); try { // Ensure the inital create have finished if (initalCreate != null) { lock (initalCreateLock) { if (initalCreate != null) { Task.WaitAll(initalCreate); initalCreate = null; } } } var reading = new Reading() { Id = readingGuid, Project = this.Id, Major = major ? (byte)1 : (byte)0, Time = time, LAeq = data.LAeq, LAMax = data.LAMax, LAMin = data.LAMin, LZMax = data.LZMax, LZMin = data.LZMin, // 1/3 Hz6_3 = data.LAeqOctaveBandOneThird.Hz6_3, Hz8 = data.LAeqOctaveBandOneThird.Hz8, Hz10 = data.LAeqOctaveBandOneThird.Hz10, Hz12_5 = data.LAeqOctaveBandOneThird.Hz12_5, Hz16 = data.LAeqOctaveBandOneThird.Hz16, Hz20 = data.LAeqOctaveBandOneThird.Hz20, Hz25 = data.LAeqOctaveBandOneThird.Hz25, Hz31_5 = data.LAeqOctaveBandOneThird.Hz31_5, Hz40 = data.LAeqOctaveBandOneThird.Hz40, Hz50 = data.LAeqOctaveBandOneThird.Hz50, Hz63 = data.LAeqOctaveBandOneThird.Hz63, Hz80 = data.LAeqOctaveBandOneThird.Hz80, Hz100 = data.LAeqOctaveBandOneThird.Hz100, Hz125 = data.LAeqOctaveBandOneThird.Hz125, Hz160 = data.LAeqOctaveBandOneThird.Hz160, Hz200 = data.LAeqOctaveBandOneThird.Hz200, Hz250 = data.LAeqOctaveBandOneThird.Hz250, Hz315 = data.LAeqOctaveBandOneThird.Hz315, Hz400 = data.LAeqOctaveBandOneThird.Hz400, Hz500 = data.LAeqOctaveBandOneThird.Hz500, Hz630 = data.LAeqOctaveBandOneThird.Hz630, Hz800 = data.LAeqOctaveBandOneThird.Hz800, Hz1000 = data.LAeqOctaveBandOneThird.Hz1000, Hz1250 = data.LAeqOctaveBandOneThird.Hz1250, Hz1600 = data.LAeqOctaveBandOneThird.Hz1600, Hz2000 = data.LAeqOctaveBandOneThird.Hz2000, Hz2500 = data.LAeqOctaveBandOneThird.Hz2500, Hz3150 = data.LAeqOctaveBandOneThird.Hz3150, Hz4000 = data.LAeqOctaveBandOneThird.Hz4000, Hz5000 = data.LAeqOctaveBandOneThird.Hz5000, Hz6300 = data.LAeqOctaveBandOneThird.Hz6300, Hz8000 = data.LAeqOctaveBandOneThird.Hz8000, Hz10000 = data.LAeqOctaveBandOneThird.Hz10000, Hz12500 = data.LAeqOctaveBandOneThird.Hz12500, Hz16000 = data.LAeqOctaveBandOneThird.Hz16000, Hz20000 = data.LAeqOctaveBandOneThird.Hz20000, // 1/1 OOHz16 = data.LAeqOctaveBandOneOne.Hz16, OOHz31_5 = data.LAeqOctaveBandOneOne.Hz31_5, OOHz63 = data.LAeqOctaveBandOneOne.Hz63, OOHz125 = data.LAeqOctaveBandOneOne.Hz125, OOHz250 = data.LAeqOctaveBandOneOne.Hz250, OOHz500 = data.LAeqOctaveBandOneOne.Hz500, OOHz1000 = data.LAeqOctaveBandOneOne.Hz1000, OOHz2000 = data.LAeqOctaveBandOneOne.Hz2000, OOHz4000 = data.LAeqOctaveBandOneOne.Hz4000, OOHz8000 = data.LAeqOctaveBandOneOne.Hz8000, OOHz16000 = data.LAeqOctaveBandOneOne.Hz16000 }; using (var audioViewEntities = new AudioViewEntities()) { audioViewEntities.Readings.Add(reading); await audioViewEntities.SaveChangesAsync(); } if (isServerDown && OnSQLServerStatusChanged != null) { OnSQLServerStatusChanged(false); } isServerDown = false; // Reading ok, try to load offline files await UploadLocalFiles(); } catch (Exception exp) { logger.Debug(exp, "Got database exception, starting to write offline for \"{0}\".", this.Settings.ProjectName); WriteOfline(major, time, data, readingGuid); if (!isServerDown && OnSQLServerStatusChanged != null) { OnSQLServerStatusChanged(true); } isServerDown = true; } }
public Task OnSecond(DateTime time, ReadingData second, ReadingData minor, ReadingData major) { return Task.Run(() => { try { logger.Trace("Triggered second reading \"{0}\".", second.LAeq); lock (this.listeners) { foreach (var listener in this.listeners) { listener.OnSecond(time, second, minor, major); } } } catch (Exception exp) { logger.Error(exp, "Failed on second reading"); } }); }
public Task OnSecond(DateTime time, ReadingData data, ReadingData minorData, ReadingData majorData) { return Task.Run(() => { LastReading = data; LastBuildingInterval = isMajor ? majorData : minorData; }); }
public Task OnMajor(DateTime time, ReadingData data) { return Task.Run(() => { if (isMajor) LastInterval = data; }); }
public Task OnMajor(DateTime time, ReadingData data) { return Task.Run(() => { MajorReadings.Enqueue(new Tuple<DateTime, ReadingData>(time, data)); DispatcherHelper.CheckBeginInvokeOnUI(() => { BarMajorValues.Add(new Tuple<DateTime, double>(time, data.LAeq)); }); }); }
public Task OnSecond(DateTime time, ReadingData data, ReadingData minorData, ReadingData majorData) { return Task.Run(() => { DispatcherHelper.CheckBeginInvokeOnUI(() => { LineValues.Add(new Tuple<DateTime, double>(time, data.LAeq)); // Add data for the octave bar OctaveValues.Clear(); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz16); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz31_5); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz63); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz125); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz250); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz500); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz1000); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz2000); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz4000); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz8000); OctaveValues.Add(data.LAeqOctaveBandOneOne.Hz16000); }); }); }
public Task OnSecond(DateTime time, ReadingData data, ReadingData minorData, ReadingData majorData) { return Task.FromResult<object>(null); }