Example #1
0
        /// <summary>
        /// Select a logging profile.
        /// </summary>
        private async void selectProfile_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.AddExtension       = true;
            dialog.CheckFileExists    = true;
            dialog.AutoUpgradeEnabled = true;
            dialog.CheckPathExists    = true;
            dialog.DefaultExt         = ".profile";
            dialog.Multiselect        = false;
            dialog.ValidateNames      = true;
            dialog.Filter             = "Logging profiles (*.profile)|*.profile";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                await this.LoadProfile(dialog.FileName);
            }
            else
            {
                this.profile     = null;
                this.profileName = null;
            }

            this.UpdateStartStopButtonState();
        }
Example #2
0
        /// <summary>
        /// Start logging
        /// </summary>
        public async Task <DpidCollection> ConfigureDpids(LogProfile profile)
        {
            List <byte> dpids = new List <byte>();

            foreach (ParameterGroup group in profile.ParameterGroups)
            {
                int position = 1;
                foreach (ProfileParameter parameter in group.Parameters)
                {
                    Message configurationMessage = this.protocol.ConfigureDynamicData(
                        (byte)group.Dpid,
                        parameter.DefineBy,
                        position,
                        parameter.ByteCount,
                        parameter.Address);

                    if (!await this.SendMessage(configurationMessage))
                    {
                        return(null);
                    }

                    // Wait for a success or fail message.
                    // TODO: move this into the protocol layer.
                    //
                    for (int attempt = 0; attempt < 3; attempt++)
                    {
                        Message responseMessage = await this.ReceiveMessage();

                        if (responseMessage == null)
                        {
                            continue;
                        }

                        if (responseMessage.Length < 5)
                        {
                            continue;
                        }

                        if (responseMessage[3] == 0x6C)
                        {
                            this.logger.AddDebugMessage("Configured " + parameter.ToString());
                            break;
                        }

                        if (responseMessage[3] == 0x7F && responseMessage[4] == 0x2C)
                        {
                            this.logger.AddUserMessage("Unable to configure " + parameter.ToString());
                            break;
                        }
                    }


                    position += parameter.ByteCount;
                }
                dpids.Add((byte)group.Dpid);
            }

            return(new DpidCollection(dpids.ToArray()));
        }
Example #3
0
 public LogProfileAndMath(LogProfile profile, MathValueConfiguration mathValueConfiguration)
 {
     this.profile = profile;
     this.mathValueConfiguration = mathValueConfiguration;
     this.mathValueProcessor     = new MathValueProcessor(
         this.profile,
         this.mathValueConfiguration);
 }
Example #4
0
 public async Task WriteAsync(LogProfile profile)
 {
     using (StreamWriter writer = new StreamWriter(stream))
     {
         string json = JsonConvert.SerializeObject(profile, new UnsignedHexValueConverter());
         await writer.WriteLineAsync(json);
     }
 }
Example #5
0
        /// <summary>
        /// Call this once to write the file header.
        /// </summary>
        public async Task WriteHeader(LogProfile profile)
        {
            this.startTime = DateTime.Now;
            string text = profile.GetParameterNames(", ");

            await this.writer.WriteAsync("Clock Time, Elapsed Time, ");

            await this.writer.WriteLineAsync(text);
        }
Example #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public LogRowParser(LogProfile profile)
        {
            this.profile = profile;

            // Create a place to put response data.
            foreach (ParameterGroup group in this.profile.ParameterGroups)
            {
                responseData[(byte)group.Dpid] = new byte[6];
            }

            this.dpidsInProfile = this.profile.ParameterGroups.Count;
        }
        public MathValueProcessor(LogProfile profile, MathValueConfiguration mathValueConfiguration)
        {
            this.profile    = profile;
            this.mathValues = new List <MathValueAndDependencies>();

            foreach (MathValue mathValue in mathValueConfiguration.MathValues)
            {
                ProfileParameter xParameter  = null;
                Conversion       xConversion = null;
                ProfileParameter yParameter  = null;
                Conversion       yConversion = null;

                foreach (ProfileParameter parameter in this.profile.AllParameters)
                {
                    // TODO: Find the parameter in a configuration file that contains all parameters and conversions,
                    // pick the appropriate conversion even if it's not what the user chose for this log profile.
                    if (parameter.Name == mathValue.XParameter)
                    {
                        xParameter  = parameter;
                        xConversion = parameter.Conversion;
                    }

                    if (parameter.Name == mathValue.YParameter)
                    {
                        yParameter  = parameter;
                        yConversion = parameter.Conversion;
                    }
                }

                if ((xParameter != null) &&
                    (xConversion != null) &&
                    (yParameter != null) &&
                    (yConversion != null))
                {
                    MathValueAndDependencies valueAndDependencies = new MathValueAndDependencies(
                        mathValue,
                        xParameter,
                        xConversion,
                        yParameter,
                        yConversion);

                    this.mathValues.Add(valueAndDependencies);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Load the profile from the given path.
        /// </summary>
        private async Task LoadProfile(string path)
        {
            try
            {
                using (Stream stream = File.OpenRead(path))
                {
                    LogProfileReader reader = new LogProfileReader(stream);
                    this.profile = await reader.ReadAsync();
                }

                this.profilePath.Text           = path;
                this.profileName                = Path.GetFileNameWithoutExtension(this.profilePath.Text);
                this.logValues.Text             = this.profile.GetParameterNames(Environment.NewLine);
                LoggerConfiguration.ProfilePath = path;
            }
            catch (Exception exception)
            {
                this.logValues.Text = exception.Message;
                this.AddDebugMessage(exception.ToString());
                this.profilePath.Text = "[no profile loaded]";
                this.profileName      = null;
            }
        }
Example #9
0
        /// <summary>
        /// Create a logging profile for testing (this was also use for testing the JSON serialization / deserialization).
        /// </summary>
        private async void GenerateTestProfile()
        {
            LogProfile     test  = new LogProfile();
            ParameterGroup group = new ParameterGroup();

            group.Dpid = 0xFE;
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Engine Speed",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 2,
                Address    = 0x000c,
                Conversion = new Conversion {
                    Name = "RPM", Expression = "x*.25"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Mass Air Flow",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 2,
                Address    = 0x0010,
                Conversion = new Conversion {
                    Name = "g/s", Expression = "x/100"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Manifold Absolute Pressure",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x000B,
                Conversion = new Conversion {
                    Name = "kpa", Expression = "x"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Throttle Position Sensor",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x0011,
                Conversion = new Conversion {
                    Name = "%", Expression = "x/2.56"
                },
            });

            test.TryAddGroup(group);

            group      = new ParameterGroup();
            group.Dpid = 0xFD;
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Intake Air Temperature",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x000F,
                Conversion = new Conversion {
                    Name = "C", Expression = "x-40"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Engine Coolant Temperature",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x000c,
                Conversion = new Conversion {
                    Name = "C", Expression = "x-40"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Left Long Term Fuel Trim",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x0007,
                Conversion = new Conversion {
                    Name = "%", Expression = "(x-128)/1.28"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Right Long Term Fuel Trim",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x0009,
                Conversion = new Conversion {
                    Name = "%", Expression = "(x-128)/1.28"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Knock Retard",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x11A6,
                Conversion = new Conversion {
                    Name = "Degrees", Expression = "(x*256)/22.5"
                },
            });
            group.TryAddParameter(
                new ProfileParameter
            {
                Name       = "Target AFR",
                DefineBy   = DefineBy.Pid,
                ByteCount  = 1,
                Address    = 0x119E,
                Conversion = new Conversion {
                    Name = "AFR", Expression = "x*10"
                },
            });
            test.TryAddGroup(group);

            using (Stream outputStream = File.OpenWrite(@"C:\temp\test.profile"))
            {
                LogProfileWriter writer = new LogProfileWriter(outputStream);
                await writer.WriteAsync(test);
            }
        }
        public void Write(LogProfile profile)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(LogProfile));

            serializer.Serialize(stream, profile);
        }
Example #11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public Logger(Vehicle vehicle, LogProfile profile)
 {
     this.vehicle = vehicle;
     this.profile = profile;
 }