public async Task <string> GetVehicleParameterValue(DiagnosticPIDs pid) { //TODO: just for demo, remove this when this functionality actually works if (pid == DiagnosticPIDs.GetVIN) { return(await GetRandomVin()); } var pidCode = String.Format("{0:X}1\r", pid).Substring(4); await _diagnosticSocket.OutputStream.WriteAsync(pidCode.Select(c => (byte)c).ToArray(), 0, pidCode.Length); await _diagnosticSocket.OutputStream.FlushAsync(); return(await GetResponseFromStream(_diagnosticSocket.InputStream, 4)); }
public async Task <string> GetVehicleParameterValue(DiagnosticPIDs pid) { switch (pid) { case DiagnosticPIDs.GetVIN: return(await GetRandomVin()); case DiagnosticPIDs.MassAirflowRate: case DiagnosticPIDs.ThrottlePercentage: case DiagnosticPIDs.VehicleSpeed: case DiagnosticPIDs.GetSupportedPIDs1: return(await GetNextValue(pid)); default: return(await Task.FromResult("NO DATA")); } }
private async Task <string> GetNextValue(DiagnosticPIDs pid) { await Task.Delay(200); string pidCode = String.Format("{0:X}", pid).Substring(4); if (!_sampleParameterValues.ContainsKey(pidCode)) { return(await Task.FromResult("NO DATA")); } var nextValue = _sampleParameterValues[pidCode].Dequeue(); //roll this back onto the end of the queue so it keeps going _sampleParameterValues[pidCode].Enqueue(nextValue); return(await Task.FromResult(nextValue)); }