public void Add(byte [] messageBytes) { NodeDataByTimeAndSerialNumber newGuy = new NodeDataByTimeAndSerialNumber(messageBytes, DateTime.Now.ToString()); if (dataByTime == null) { dataByTime = new List <NodeDataByTimeAndSerialNumber> { newGuy }; return; } var existingRecord = dataByTime.FirstOrDefault(o => o.SerialId.Value == newGuy.SerialId.Value && o.Timestamp == newGuy.Timestamp); if (existingRecord == null) { dataByTime.Add(newGuy); return; } byte[] substring = new byte[32]; Buffer.BlockCopy(messageBytes, 15, substring, 0, 32); existingRecord.AddCode(substring[0]); // code existingRecord.AddCode(substring[1]); // index }
public Metrics(NodeDataByTimeAndSerialNumber nodeData) { if (dataByTime == null) { dataByTime = new List <NodeDataByTimeAndSerialNumber> { nodeData }; SerialId = nodeData.SerialId.Value; } }
public void ProcessLiveData(byte[] asBytes, DateTime time) { if (asBytes.Length < 48 || asBytes[3] != 0x90) { return; // change if we want to see other messages or add other messages to parse } NodeDataByTimeAndSerialNumber nd = new NodeDataByTimeAndSerialNumber(asBytes, time.ToString()); var existing = datas.FirstOrDefault(o => o.SerialId.Value == nd.SerialId.Value && o.Timestamp.Value == nd.Timestamp.Value); // grab it if it exists already if (existing == null) { // is there one that needs to be analyzed from the previous time period? var lastOne = datas.FirstOrDefault(o => o.SerialId.Value == nd.SerialId.Value); // grab it if it exists already if (lastOne != null) { var result = lastOne.EvaluateYourself(time.ToString()); // see if the number of pbs is off var maxCounterForThisSN = maxPbsForEachSN.FirstOrDefault(o => o.serialNumber == lastOne.SerialId.Value); if (maxCounterForThisSN == null) { PBCounter newMaxPbCounter = new PBCounter(0xd0); newMaxPbCounter.serialNumber = lastOne.SerialId.Value; newMaxPbCounter.Count = lastOne.Codes.Count; maxPbsForEachSN.Add(newMaxPbCounter); } else { if (maxCounterForThisSN.Count < lastOne.Codes.Count) { result += ",possible (GAP)"; } } if (result != string.Empty) { Debug.WriteLine(result); if (!CheckAccess()) { // On a different thread Dispatcher.Invoke(() => OutputTextBox.Text += result); return; } } else { Debug.WriteLine($"{DateTime.Now} Good reading for {lastOne.SerialId.Value}"); } datas.Remove(lastOne); } // doesn't exist, create it datas.Add(nd); } else // does exist, add to it { existing.AddCode(asBytes[15]); existing.AddIndex(asBytes[16]); } }