DarthAffe / OBD.NET

C#-Library to read data from car through an ELM327-/STN1170-Adapter
GNU General Public License v2.0
178 stars 82 forks source link

Adding a new PID, struggling...., c# newbie #16

Open MartinParis opened 4 years ago

MartinParis commented 4 years ago

I have created a new class for Odometer. It needs a PID value of 3B6 (CAN message: 3B64597BF00). The whole technical architecture seems to be made around a PID of one byte so I need somehow to make AbstractOBDData.cs aware of this larger PID, but I fail because my knowledge of c# is not enough. Can anyone give a pointer for this? And I think I also need to convince AbstractPidsSupported.cs of this larger PID and adding it to the supported list. I want to use this library to get Odometer from my Tesla Model 3 Vehicle Bus through the OBDLINK MX+.

`using OBD.NET.Common.DataTypes;

namespace OBD.NET.Common.OBDData { public class Odometer : AbstractOBDData {

region Properties & Fields

    public Kilometre Odom => new Kilometre((D + C << 8) + (B << 16) + (A << 24), 0, 0);

    #endregion

    #region Constructors

    public Odometer()
        : base(0x3B6, 4)
    { }

    #endregion

    #region Methods

    public override string ToString() => Odom.ToString();

    #endregion
}

} `

DarthAffe commented 4 years ago

Hey, assuming, that tesla isn't doing anything weird with their can-bus you have a misconception about the PID in the can message: If 3B64597BF00 would be a OBD message it should normally be parsed as:

3B6   CAN-ID (not OBD-PID!)
45    number if data-bytes (this indicates, that you're not looking at OBD-data since it should be 01, 02, 03 or 04)
97    OBD SID (41 for a response)
BF    OBD PID
00    OBD Data

Since the amount of bytes and the SID doesn't look valid this doesn't seem to be OBD-data. Parsing raw CAN-data isn't part of this library.

MartinParis commented 4 years ago

Thanks for the reply! Oh boy. I only need the CAN data 3B6, it is not OBD data. I do not know my CAN from OBD... This CAN data is my number of kilometers in some Endian format, so I can parse it to real meters. My idea was to filter the CAN data STFA so I would only get 3B6 messages, that is all I need in my C# code. Mixing up OBD with CAN made it possible in my world :-(. So that would not be possible with this library? Bummer. I will search on, if you have a pointer it would be greatly appreciated.