/// <summary> /// Convert the data stream values retrieved from the VCU to a format that can be plotted by the <c>FormViewDataStream</c> class. /// </summary> /// <remarks> /// The value array retrieved by from the VCU is initially mapped to the WatchIdentifierList property of Column[0] of the workset, however, the WatchElement /// array associated with each frame must be mapped to the WatchElementList property of the workset. /// </remarks> /// <param name="startTime">The start time of the fault log.</param> /// <param name="sampleCount">The number of samples in the data stream.</param> /// <param name="frameIntervalMs">The interval, in ms, between consecutive data frames.</param> /// <param name="values">The point values corresponding to each variable.</param> /// <param name="dataTypes">The data types associated with each value.</param> /// <param name="workset">The workset that is to be used to define the output format.</param> /// <returns>The watch variable values in the format that can be plotted by the <c>FormViewDataStream</c> class.</returns> /// <exception cref="ArgumentException">Thrown if one or more of the the watch identifiers defined in the WatchElementList property of the workset does nor exist.</exception> private List<WatchFrame_t> ConvertToWatchFrameList(DateTime startTime, short sampleCount, short frameIntervalMs, int[] values, short[] dataTypes, Workset_t workset) { Debug.Assert(sampleCount > 1, "CommunicationEvent.ConvertToWatchFrameList() - [pointCount > 1]"); Debug.Assert(frameIntervalMs > 0, "CommunicationEvent.ConvertToWatchFrameList() - [frameIntervalMs > 0"); Debug.Assert(values != null, "CommunicationEvent.ConvertToWatchFrameList() - [values != null]"); Debug.Assert(dataTypes != null, "CommunicationEvent.ConvertToWatchFrameList() - [dataTypes != null]"); short watchCount = (short)workset.WatchElementList.Count; // Create a look-up array to translate the watch variable data retrieved from the VCU to the order defined by the WatchElementList property of the workset. short[] translate = new short[watchCount]; short watchIdentifier, rowIndex, columnIndex; WatchVariable watchVariable; for (short watchElementIndex = 0; watchElementIndex < watchCount; watchElementIndex++) { watchIdentifier = workset.WatchElementList[watchElementIndex]; try { watchVariable = Lookup.WatchVariableTable.Items[watchIdentifier]; if (watchVariable == null) { throw new ArgumentException(Resources.MBTWatchVariableNotDefined); } } catch (Exception) { throw new ArgumentException(Resources.MBTWatchVariableNotDefined); } workset.GetWatchVariableLocation(watchVariable.OldIdentifier, out columnIndex, out rowIndex); Debug.Assert(((columnIndex != CommonConstants.NotFound) && (rowIndex != CommonConstants.NotFound)), "CommunicationEvent.ConvertToWatchFrameList() - [((columnIndex != 0) || (rowIndex != CommonConstants.NotFound))]"); translate[watchElementIndex] = rowIndex; } // Translate the values of the watch variables retrieved from the VCU to a list of watch frames. List<WatchFrame_t> watchFrameList = new List<WatchFrame_t>(); WatchFrame_t watchFrame; WatchElement_t watchElement; for (int frameIndex = 0; frameIndex < sampleCount; frameIndex++) { watchFrame = new WatchFrame_t(); watchFrame.CurrentDateTime = startTime.AddMilliseconds(frameIndex * frameIntervalMs); watchFrame.WatchElements = new WatchElement_t[watchCount]; for (short watchElementIndex = 0; watchElementIndex < watchCount; watchElementIndex++) { watchElement = new WatchElement_t(); watchElement.ElementIndex = watchElementIndex; watchElement.WatchIdentifier = workset.WatchElementList[watchElementIndex]; watchElement.DataType = dataTypes[translate[watchElementIndex]]; watchElement.Value = (double)values[(frameIndex * watchCount) + translate[watchElementIndex]]; watchFrame.WatchElements[watchElementIndex] = watchElement; } watchFrameList.Add(watchFrame); } return watchFrameList; }