pgmfi.org

Hacking up Honda's ECU
It is currently Fri Mar 29, 2024 4:43 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Feb 02, 2019 6:03 pm 
Offline

Joined: Wed Apr 27, 2011 2:30 am
Posts: 20
Had a bit of a mission set out for myself to get QD3 logging directly to my dyno.
Bits of info were scattered every where so thought id make a post with it all in 1 place.

Here is what I came up with for processing QD3 serial string.
Use it how youd like.

Code:
 using System;
using System.Collections;
using System.Windows.Forms;

namespace QD3_processor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //String to test
            byte[] byteData =
            {
                0X46, 0X26, 0Xc7, 0X05, 0X05, 0Xed, 0X00, 0X5d, 0X02, 0X74, 0X08, 0X48, 0X00, 0X80, 0Xb1, 0X22, 0X57, 0X0a, 0X49, 0X46, 0X00, 0X93, 0X23, 0X25, 0X22, 0X7c, 0X00, 0Xff, 0Xff, 0X00, 0X93, 0Xa9, 0Xa2, 0X72, 0Xbc, 0X02, 0XA8, 0XA0, 0X00, 0X00, 0X5D
               // 0X46, 0X26, 0X5f, 0X08, 0X02, 0Xed, 0X01, 0X80, 0X08, 0X74, 0X00, 0X65, 0X00, 0X80, 0Xf5, 0X25, 0X57, 0X0a, 0X49, 0X46, 0X00, 0X8f, 0X3f, 0X2b, 0X29, 0X7b, 0X00, 0Xff, 0Xff, 0X00, 0X8f, 0Xa9, 0Xa2, 0X75, 0Xfc, 0X02, 0X00, 0X00, 0X00, 0X00, 0X96
            };

            //Calls decode of QD3 data stream.
            QD3Decode(byteData);

        }

        private void QD3Decode(byte[] byteData)
        {
            byte rpmLowRaw = byteData[2];           // Low Byte of RPM
            byte rpmHighRaw = byteData[3];          // High Byte of RPM
            byte ignRaw = byteData[9];              // Ignition Timing Raw
            byte o2Raw = byteData[11];              // Oxygen Sensor Byte
            byte vtecRaw = byteData[19];            // Vtec Engaged Yes/No
            byte vssRaw = byteData[20];             // Vehicle Speed Sensor Byte
            byte batteryRaw = byteData[21];         // Battery Byte
            float mapRaw = byteData[22];            // Map Sensor Byte
            byte tpsRaw = byteData[24];             // Throttle Position Sensor Byte
            byte iatRaw = byteData[25];             // Intake Air Temp Byte
            byte ectRaw = byteData[33];             // Engine Coolant Temp Byte
            byte injLowRaw= byteData[7];            // Injector low Byte
            byte injHighRaw= byteData[8];           // Injector high Byte
            byte knockraw = byteData[10];              // Knock sensor Byte
            byte cel1 = byteData[36];               // Cel Byte1
            byte cel2 = byteData[37];               // Cel Byte2
            byte cel3 = byteData[38];               // Cel Byte3
            byte cel4 = byteData[39];               // Cel Byte4


            //RPM
            float rpm = 1875000 / ((rpmHighRaw * 256) + rpmLowRaw);

            //Injectors
            double injms = ((((256.0 * injHighRaw ) + injLowRaw) - 24.0) / 4.0 ) / 57;
            double dutycycle = Math.Round(rpm * injms / 1200,0,MidpointRounding.AwayFromZero);


            //Knock retard
            double knock = (0.25 * knockraw);

            //Ignition Advance
            double ign = (0.25 * ignRaw) - 6;
            //O2 sensor voltage 0-5V
            double O2 = o2Raw / 51.0;
            //TPS %
            double TPS = (0.472637 * tpsRaw) - 11.46119;
            //Battery Voltage
            double battery = (26.0 * batteryRaw) / 275.0;
            //Map Voltage
            float mapvolt = mapRaw / 51;
            //Map Mbar
            float map = (1764 / 255) * (mapRaw) * 2 + 6;
            //Map inghg
            double inHg = -10.87 * ((mapRaw) * 5 / 256) + 30.48;

            //vtec code
            var bits = new BitArray(vtecRaw);
            bool vtec = bits[0];

            //Speed kph
            double speed = vssRaw; //Do what ever conversion here

            //IAT C
              double iat = iatRaw;
              iat = iat / 51;
              iat = (0.1423* Math.Pow(iat, 6)) - (2.4938* Math.Pow(iat, 5))  + (17.837* Math.Pow(iat, 4)) - (68.698* Math.Pow(iat, 3)) + (154.69* Math.Pow(iat, 2)) - (232.75* iat) + 284.24;
              iat = ((iat - 32)*5)/9;

            //ECT C
              double ect = ectRaw;
              ect = ect / 51;
              ect = (0.1423 * Math.Pow(ect, 6)) - (2.4938 * Math.Pow(ect, 5)) + (17.837 * Math.Pow(ect, 4)) - (68.698 * Math.Pow(ect, 3)) + (154.69 * Math.Pow(ect, 2)) - (232.75 * ect) + 284.24;
              ect = ((ect - 32) * 5) / 9;


            // CRC CHECKING CODE HERE
            int checksum = byteData[0];
            int x = 0;
            while (x < 39)
            {
                x++;
                checksum = checksum + byteData[x];
            }
            byte calchecksum = (byte)(checksum & 0xff);

            if (calchecksum == byteData[40])
            {
                //Check sum matched code here
                //MessageBox.Show("checksum match");
            }
            else
            {
                //Checksum failed code here.
            }




            // Read error codes
            string errorstring = Reverse(ToBitsString(cel1)) + Reverse(ToBitsString(cel2))  + Reverse(ToBitsString(cel3))  + Reverse(ToBitsString(cel4)); ;
            char[] OBD1DTCL = errorstring.ToCharArray();
            int i = 0;
            while (i < 31)
            {

                if (OBD1DTCL[i].ToString() == "1")
                {
                    //Message box for each code (Code number = i + 1.
                  MessageBox.Show("error code " + (int.Parse(i.ToString())+1).ToString());
                }
                i++;
            }

        }


        //Converts a byte to a 8 bit
        public static string ToBitsString(byte value)
        {
            return Convert.ToString(value, 2).PadLeft(8, '0');
        }


        //Inverts the bit string to make storing error codes as a 0-32 bit array easier.
        public string Reverse(string text)
        {
            if (text == null) return null;
            char[] array = text.ToCharArray();
            Array.Reverse(array);
            return new String(array);
        }


    }
}



Last edited by bmgjet on Wed Feb 20, 2019 1:34 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 04, 2019 6:24 pm 
Offline

Joined: Thu Jun 12, 2008 2:38 am
Posts: 33
Location: OZ
Thanks always wanted to work out the cel stuff


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 20, 2019 1:35 am 
Offline

Joined: Wed Apr 27, 2011 2:30 am
Posts: 20
ISR datalogging info (eCtune) (Honda Tuning Suite)

Code:
/*
·▄▄▄▄   ▄▄▄· ▄▄▄▄▄ ▄▄▄· ▄▄▌         ▄▄ •  ▄▄ • ▪   ▐ ▄  ▄▄ •     ▪  .▄▄ · ▄▄▄ 
██▪ ██ ▐█ ▀█ •██  ▐█ ▀█ ██•  ▪     ▐█ ▀ ▪▐█ ▀ ▪██ •█▌▐█▐█ ▀ ▪    ██ ▐█ ▀. ▀▄ █·
▐█· ▐█▌▄█▀▀█  ▐█.▪▄█▀▀█ ██▪   ▄█▀▄ ▄█ ▀█▄▄█ ▀█▄▐█·▐█▐▐▌▄█ ▀█▄    ▐█·▄▀▀▀█▄▐▀▀▄
██. ██ ▐█ ▪▐▌ ▐█▌·▐█ ▪▐▌▐█▌▐▌▐█▌.▐▌▐█▄▪▐█▐█▄▪▐█▐█▌██▐█▌▐█▄▪▐█    ▐█▌▐█▄▪▐█▐█•█▌
▀▀▀▀▀•  ▀  ▀  ▀▀▀  ▀  ▀ .▀▀▀  ▀█▄▀▪·▀▀▀▀ ·▀▀▀▀ ▀▀▀▀▀ █▪·▀▀▀▀     ▀▀▀ ▀▀▀▀ .▀  ▀
 */

using System;
namespace HondaTuningSuite
{
    //Variable for every byte of datalogging coming out of ecu.
    class DLISR{
        public static char[] OBD1DTCL;
        public static int COLY;
        public static int COLV;
        public static int COLX;
        public static int GEARFuelC;
        public static int PWMTarget;
        public static float RPM;
        public static float IGN;
        public static float AFR;
        public static float VSS;
        public static float BATTERY;
        public static float MAP;
        public static float BOOST;
        public static float TPS;
        public static float IAT;
        public static float ECT;
        public static int MIL;
        public static int O2Heater;
        public static int VTS;
        public static int Baro;
        public static  int PostFuel; 
        public static int ServiceConector;
        public static int IgnCut;
        public static int VTSM;
        public static int FuelCut1;
        public static int FuelCut2;
        public static int ATShift1;
        public static int ATShift2;
        public static double injFV;
        public static int injDuration;
        public static float injduty;
        public static float ignTable;
        public static int Park;
        public static int BKSW;
        public static int ACC;
        public static int VTPS;
        public static int Start;
        public static int SCC;
        public static int VTSFeedBack;
        public static int PSP;
        public static int FuelPump;
        public static int IABV;
        public static int ALTCTRL;
        public static int Purge;
        public static int AC;
        public static int ELD;
        public static double ECTFC;
        public static long O2Short;
        public static long O2Long;
        public static long IATFC;
        public static double VEFC;
        public static float IATIC;
        public static float ECTIC;
        public static float GEARIC;
        public static int InputFTL;
        public static int InputFTS;
        public static int InputEBC;
        public static int InputEBCH;
        public static int InputGPO1;
        public static int InputGPO2;
        public static int InputGPO3;
        public static int InputBST;
        public static int OutputFTL;
        public static int OutputAntilag;
        public static int OutputFTS;
        public static int OutputBoostCut;
        public static int OutputEBC;
        public static int Output2ndMap;
        public static int OutputFanCtrl;
        public static int OutputBST;
        public static double EBCBaseDuty;
        public static double EBCDuty;
        public static int OutputGPO1;
        public static int OutputGPO2;
        public static int OutputGPO3;
        public static int OutputBSTStage2;
        public static int OutputBSTStage3;
        public static int OutputBSTStage4;
        public static int OverHeatProtection;
        public static int LeanProtect;
        public static int EGR;
        public static int B6;
        public static int IACVDuty;
        public static bool _continue = true;

        //array to hold every value as a table.
        public static string[] DataloggedTable = new string[192000];


        public static string ToBitsString(byte value)
        {
            return Convert.ToString(value, 2).PadLeft(8, '0');
        }


     
        public static string Reverse(string text)
        {
            if (text == null) return null;
            char[] array = text.ToCharArray();
            Array.Reverse(array);
            return new String(array);
        }

    //Checks to see if a sensor bit is set.
    public static int GetSET(int ThisByte, int ThisPos)
     {
        int[] bitArray = new int[8];


        for (int i=0; i< 8; ++i){
            bitArray[i] = ThisByte & 1;
            ThisByte >>= 1;
            }
            return bitArray[ThisPos];
    }
        //Gets fuel correction values
        public static double GetFC(long ThisByte, long ThisLong)
        {
            double num = (double)ThisByte / (double)ThisLong;
            return Math.Round((num) * 100) / 100;
        }

        public static long Long2Bytes(byte ThisByte1, byte ThisByte2)
        {
            return ((long) ThisByte2 * 256) + (long) ThisByte1;
        }

        //Gets ignition correction values
        public static float GetIC(byte ThisByte)
        {
            if ((int)ThisByte == 128)
                return 0.0f;
            if ((int)ThisByte < 128)
                return (float)(128 - (int)ThisByte) * -0.25f;
            return (float)((int)ThisByte - 128) * 0.25f;
        }

        //Gets duty cycle of boost solenoid
        public static double GetEBC(byte ThisByte)
        {
            double num = (double)ThisByte / 2.0;
            if (num > 100.0)
                num = 100.0;
            return Math.Round((num * 10)) / 10;
        }

        //Gets injector duration
        public static float GetDuration(int ThisInt)
         {
        return ((float) ThisInt * 3.20000004768372f) / 1000.0f;
        }

        //Process datalogging frame.
    public static void Process(int[] byteData)
        {
                int ectRaw = byteData[0];             // Engine Coolant Temp Byte
                int iatRaw = byteData[1];             // Intake Air Temp Byte
                int o2Raw = byteData[2];              // Oxygen Sensor Byte
                Baro = byteData[3];                   //Baro sensor byte
                int mapRaw = byteData[4];            // Map Sensor Byte
                int tpsRaw = byteData[5];             // Throttle Position Sensor Byte
                int rpmLowRaw = byteData[6];           // Low Byte of RPM
                int rpmHighRaw = byteData[7];          // High Byte of RPM
                PostFuel = GetSET(byteData[8], 0);      //Post Start Fuel Enrichment
                ServiceConector = GetSET(byteData[8], 1);   //Service Connector status
                IgnCut = GetSET(byteData[8], 2); //Ignition cut status
                VTSM = GetSET(byteData[8], 3); //
                FuelCut1 = GetSET(byteData[8], 4);//
                FuelCut2 = GetSET(byteData[8], 5);//
                ATShift1 = GetSET(byteData[8], 6);//
                ATShift2 = GetSET(byteData[8], 7);
                COLY = byteData[9];                        //Map trace Y
                COLV = byteData[10];                       //Map trace vtec Y
                COLX = byteData[11];                        //Map trace X
                int cel1 = (byteData[12]);               // Cel Byte1
                int cel2 = (byteData[13]);               // Cel Byte2
                int cel3 = (byteData[14]);               // Cel Byte3
                int cel4 = (byteData[15]);               // Cel Byte4
                int vssRaw = byteData[16];             // Vehicle Speed Sensor Byte
                int injLowRaw = byteData[17];            // Injector low Byte
                int injHighRaw = byteData[18];           // Injector high Byte
                int ignRaw = byteData[19];              // Ignition Timing RawFat
                ignTable = (0.25f * byteData[20]) - 6f;
                Park = GetSET(byteData[21], 0);
                BKSW = GetSET(byteData[21], 1);
                ACC = GetSET(byteData[21], 2);
                VTPS = GetSET(byteData[21], 3);
                Start = GetSET(byteData[21], 4);
                SCC = GetSET(byteData[21], 5);
                VTSFeedBack = GetSET(byteData[21], 6);
                PSP = GetSET(byteData[21], 7);
                FuelPump = GetSET(byteData[22], 0);
                //int empty = GetSET(byteData[22], 1);
                IABV = GetSET(byteData[22], 2);
                //int empty2 = GetSET(byteData[22], 3);
                //int empty3 = GetSET(byteData[22], 4);
                ALTCTRL = GetSET(byteData[22], 5);
                Purge = GetSET(byteData[22], 6);
                AC = GetSET(byteData[22], 7);
                //int empty4 = GetSET(byteData[23], 0);
                //int empty5 = GetSET(byteData[23], 1);
                //int empty6 = GetSET(byteData[23], 2);
                //int empty7 = GetSET(byteData[23], 3);
                //int empty8 = GetSET(byteData[23], 4);
                MIL = GetSET(byteData[23], 5);
                O2Heater = GetSET(byteData[23], 6);
                VTS = GetSET(byteData[23], 7);
                ELD = byteData[24];
                int batteryRaw = byteData[25];         // Battery Byte
                ECTFC = GetFC(byteData[26], 128);
                O2Short = (long)GetFC(Long2Bytes((byte)byteData[27], (byte)byteData[28]), 32768);
                O2Long = (long)GetFC(Long2Bytes((byte)byteData[29], (byte)byteData[30]), 32768);
                IATFC = (long)GetFC(Long2Bytes((byte)byteData[31], (byte)byteData[32]), 32768);
                VEFC = GetFC(byteData[33], 128);
                IATIC = GetIC((byte)byteData[34]);
                ECTIC = GetIC((byte)byteData[35]);
                GEARIC = GetIC((byte)byteData[36]);
                GEARFuelC = byteData[37];
                InputFTL = GetSET(byteData[38], 0);
                InputFTS = GetSET(byteData[38], 1);
                InputEBC = GetSET(byteData[38], 2);
                InputEBCH = GetSET(byteData[38], 3);
                InputGPO1 = GetSET(byteData[38], 4);
                InputGPO2 = GetSET(byteData[38], 5);
                InputGPO3 = GetSET(byteData[38], 6);
                InputBST = GetSET(byteData[38], 7);
                OutputFTL = GetSET(byteData[39], 0);
                OutputAntilag = GetSET(byteData[39], 1);
                OutputFTS = GetSET(byteData[39], 2);
                OutputBoostCut = GetSET(byteData[39], 3);
                OutputEBC = GetSET(byteData[39], 4);
                Output2ndMap = GetSET(byteData[39], 5);
                OutputFanCtrl = GetSET(byteData[39], 6);
                OutputBST = GetSET(byteData[39], 7);
                EBCBaseDuty = GetEBC((byte)byteData[40]);
                EBCDuty = GetEBC((byte)byteData[41]);
                PWMTarget = byteData[42];
                OutputGPO1 = GetSET(byteData[43], 0);
                OutputGPO2 = GetSET(byteData[43], 1);
                OutputGPO3 = GetSET(byteData[43], 2);
                OutputBSTStage2 = GetSET(byteData[43], 3);
                OutputBSTStage3 = GetSET(byteData[43], 4);
                OutputBSTStage4 = GetSET(byteData[43], 5);
                OverHeatProtection = GetSET(byteData[43], 6);
                LeanProtect = GetSET(byteData[43], 7);
                EGR = byteData[44];
                B6 = byteData[45];
                IACVDuty = (int)(Long2Bytes((byte)byteData[49], (byte)byteData[50]) / 327.68);

            try
            {

                RPM = 1875000 / ((rpmHighRaw * 256) + rpmLowRaw); //valid
            }
            catch { RPM = 28; }
                injFV = (double)Long2Bytes((byte)injLowRaw, (byte)injHighRaw) / 4.0;
                injDuration = (int)Math.Round(((double)GetDuration((int)Long2Bytes((byte)injLowRaw, (byte)injHighRaw))) * 100) / 100;
                injduty = (float)((double)RPM * GetDuration((int)Long2Bytes((byte)injLowRaw, (byte)injHighRaw)) / 1200.0);

                //double knock = (0.00 * knockraw);

                //Ignition Advance
                IGN = (0.25f * ignRaw) - 6f;
                //O2 sensor voltage 0-5V
                AFR = o2Raw / 51.0f;
                //TPS %
                TPS = (0.472637f * (float)tpsRaw) - 11.46119f;
                //Battery Voltage
                BATTERY = (26.0f * batteryRaw) / 270.0f;
                //Map Voltage
               // float mapvolt = mapRaw / 51;
                //Map Mbar
                float map = YourTune.B105.ConvertRange(0, 255, -70, 1790, int.Parse(mapRaw.ToString()));
                //float map = (1764 / 255) * (mapRaw) * 2 + 6;
                //Map inghg
                //double inHg = -10.87 * ((mapRaw) * 5 / 256) + 30.48;
                MAP = map;

            if (map > 1014)
            {
                BOOST = float.Parse(Math.Round((map / 68.948) - 14.7, 2).ToString());
            }
            else
                BOOST = 0;


            //Speed kph
            VSS = vssRaw; //Do what ever conversion here for ratio of wheels.


                //IAT C
                double iat = iatRaw;
                iat /= 51;
                iat = (0.1423 * Math.Pow(iat, 6)) - (2.4938 * Math.Pow(iat, 5)) + (17.837 * Math.Pow(iat, 4)) - (68.698 * Math.Pow(iat, 3)) + (154.69 * Math.Pow(iat, 2)) - (232.75 * iat) + 284.24;
                iat = ((iat - 32) * 5) / 9;
                IAT = (float)iat;

                //ECT C
                double ect = ectRaw;
                ect /= 51;
                ect = (0.1423 * Math.Pow(ect, 6)) - (2.4938 * Math.Pow(ect, 5)) + (17.837 * Math.Pow(ect, 4)) - (68.698 * Math.Pow(ect, 3)) + (154.69 * Math.Pow(ect, 2)) - (232.75 * ect) + 284.24;
                ect = ((ect - 32) * 5) / 9;
                ECT = (float)ect;



                //check error codes
                string errorstring = Reverse(ToBitsString((byte)cel1)) + Reverse(ToBitsString((byte)cel2)) +
                                         Reverse(ToBitsString((byte)cel3)) + Reverse(ToBitsString((byte)cel4));

                    if (double.Parse(errorstring) == 0)
                    {
                    }
                        else {
                            OBD1DTCL = errorstring.ToCharArray();
                            }
                    }
            }   
}


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 10, 2020 6:51 pm 
Offline

Joined: Mon Nov 25, 2019 5:18 pm
Posts: 6
Thank you


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group