/// <summary> /// Build the list of columns for the given profile /// </summary> private void AddColumnsAndDependents(IList <LogColumn> columns, LogProfile newProfile) { List <LogColumn> dependencies = new List <LogColumn>(); foreach (LogColumn column in newProfile.Columns) { Parameter parameter = column.Parameter; Conversion conversion = column.Conversion; DependencyMap dependencyMap = null; if (parameter.IsCalculated) { dependencyMap = new DependencyMap(); foreach (Parameter dependency in parameter.Dependencies) { string depencencyKey; Conversion dependencyConversion; InternalLogProfile.GetDependencyConversion( dependency, conversion, out dependencyConversion, out depencencyKey); this.VerifyParameter(dependency); LogColumn dependencyColumn = LogColumn.GetInstance( dependency, dependencyConversion, null, true); dependencyMap[depencencyKey] = dependencyColumn; dependencies.Add(dependencyColumn); } } this.VerifyParameter(parameter); LogColumn newColumn = LogColumn.GetInstance(parameter, conversion, dependencyMap, false); columns.Add(newColumn); } if (dependencies != null) { foreach (LogColumn dependency in dependencies) { columns.Add(dependency); } } }
/// <summary> /// Invoked when a between-rows query has completed. /// </summary> /// <param name="asyncResult">Async result.</param> private void QueryCallback(IAsyncResult asyncResult) { // Store the block-read result and signal the awaiter. byte[] queryResultBytes = this.ecu.EndBlockRead(asyncResult); int queryResult = 0; if (queryResultBytes != null && queryResultBytes.Length == 4) { queryResult = BitConverter.ToInt32(queryResultBytes, 0); } this.queryAddress = 0; this.queryResult.SetResult(queryResult); // Continue logging rows as usual. InternalLogProfile profile = (InternalLogProfile)asyncResult.AsyncState; this.ecu.BeginMultipleRead(profile.Addresses, EndMultipleReadCallback, profile); }
/// <summary> /// Add columns for external sensors. /// </summary> private void StoreExternalSensorValues() { PlxSensors plxSensors = ExternalSensors.GetInstance().PlxSensors; if (plxSensors == null) { return; } foreach (LogColumn column in this.logEventArgs.Row.Columns) { PlxParameter parameter = column.Parameter as PlxParameter; if (parameter != null) { PlxSensorId id = (PlxSensorId)parameter.SensorId; double rawValue = plxSensors.GetValue(id, PlxSensorUnits.Raw); InternalLogProfile.ConvertAndStoreValue(column.Parameter, rawValue, column.Conversion, column); } } }
/// <summary> /// Store values directly from the SSM bytes. /// </summary> /// <param name="rawData"></param> private void StoreDirectSsmValues(byte[] rawData) { foreach (LogColumn column in this.logEventArgs.Row.Columns) { if (!(column.Parameter is SsmParameter)) { continue; } if (column.DependencyMap != null) { continue; } int index = (int)column.PropertyBag[ColumnAddressIndex]; int length = ((SsmParameter)column.Parameter).Length; double rawValue = InternalLogProfile.GetSsmValue(rawData, index, length); InternalLogProfile.ConvertAndStoreValue(column.Parameter, rawValue, column.Conversion, column); } }
private void EndMultipleReadCallback(IAsyncResult asyncResult) { byte[] rawValues; Exception exception = null; InternalLogProfile oldProfile = (InternalLogProfile)asyncResult.AsyncState; try { rawValues = this.ecu.EndMultipleRead(asyncResult); oldProfile.StoreSsmValues(rawValues); if (this.LogEntry != null) { this.LogEntry(this, oldProfile.LogEventArgs); } if (this.state == LoggerState.Logging) { InternalLogProfile newProfile = this.internalProfile; if (newProfile != oldProfile) { if (this.LogStop != null) { LogStopEventArgs stopArgs = new LogStopEventArgs(oldProfile.LogEventArgs.UserData); this.LogStop(this, stopArgs); } if (this.LogStart != null) { this.LogStart(this, newProfile.LogEventArgs); } } if (this.queryAddress != 0) { // Read a single value from the ECU before resuming logging. int address = this.queryAddress; this.queryAddress = 0; this.ecu.BeginBlockRead(address, 4, QueryCallback, newProfile); } else { // Continue logging rows as usual. this.ecu.BeginMultipleRead(newProfile.Addresses, EndMultipleReadCallback, newProfile); } } else { this.SetState(LoggerState.Stopped, "EndMultipleReadCallback", delegate { if (this.stopLoggingAsyncResult != null) { this.stopLoggingAsyncResult.Completed(); this.stopLoggingAsyncResult = null; } }); if (this.LogStop != null) { LogStopEventArgs stopArgs = new LogStopEventArgs(oldProfile.LogEventArgs.UserData); this.LogStop(this, stopArgs); } } } catch (UnauthorizedAccessException ex) { exception = ex; } catch (IOException ex) { exception = ex; } if (exception != null) { Trace.WriteLine("SsmBasicLogger.EndMultipleReadCallback: Exception thrown from consumer's log event handler"); LogErrorEventArgs args = new LogErrorEventArgs(exception); if (this.LogError != null) { this.LogError(this, args); } this.SetState(LoggerState.Stopped, "EndMultipleReadCallback, exception thrown"); if (this.LogStop != null) { LogStopEventArgs stopArgs = new LogStopEventArgs(oldProfile.LogEventArgs.UserData); this.LogStop(this, stopArgs); } if (this.stopLoggingAsyncResult != null) { this.stopLoggingAsyncResult.Completed(); this.stopLoggingAsyncResult = null; } } }
/// <summary> /// Selects parameters to be logged /// </summary> public void SetProfile(LogProfile profile, ParameterDatabase database) { Trace.WriteLine("SsmBasicLogger.SetProfile"); this.internalProfile = InternalLogProfile.GetInstance(profile, database); }