Discussion: Table dtc edc16c34
Afficher un message
Vieux 07/05/2022, 07h59  
Jean_Luc
Membre habitué T-E
 
Avatar de Jean_Luc
 
Date d'inscription: mai 2015
Localisation: Grenoble
Messages: 110
Thanks: 36
Thanked 104 Times in 26 Posts
Pouvoir de réputation: 12
Jean_Luc will become famous soon enoughJean_Luc will become famous soon enough
Par défaut

Salut,

Voila un bout de code java qui trouve les adresses.
J'ai essayé sur quelques dump et ça a l'air d'être bon.
Mais comme dit dans les commentaires, j'ai bien peur que ça foire sur les véhicules sans clim.
J'essayerai de dumper le berlingo 1.6 HDI 90cv de ma belle mère qui n'a pas la clim.
Si des âmes charitable ont des dumps (pas forcement full) de véhicule sans clim,ce serait sympa de les poster.
Merci

Code:
package DTCController;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Class to read, write and find DTC info from a dump
 */

public class Dump {

    public static int DUMP_SIZE = 2048*1024; // 2MBytes
    public static final int A2L_REF = 0x1C001A;
    public static final int SWT_REF = 0x1C0010;
    public static final int MAX_DTC = 0xFFFF;

    byte[] memory;
    String software;
    String project;

    class DTCInfo {
        int nbDTC;          // Number of DTC
        int faultPathAddr;  // Fault path (list of 4 UWORD)
        int codeAddr;       // Fault code (list of UWORD)
        int classAddr;      // Fault class (list of UBYTE), The class defines the default behavior

        @Override
        public String toString() {
            return "DTCInfo{" +
                    "nbDTC=" + nbDTC +
                    ", faultPathAddr=" + String.format("%06X",faultPathAddr) +
                    ", codeAddr=" + String.format("%06X",codeAddr) +
                    ", classAddr="+ String.format("%06X",classAddr) +
                    '}';
        }
    }

    public Dump(String fileName) throws IOException {

        Path p = Paths.get(fileName);
        memory = Files.readAllBytes(p);

        StringBuffer sft = new StringBuffer();
        for(int i=0;i<10;i++)
            sft.append((char)memory[SWT_REF+i]);
        software = sft.toString();

        StringBuffer a2l = new StringBuffer();
        for(int i=0;i<8;i++)
            a2l.append((char)memory[A2L_REF+i]);
        project = a2l.toString();

        System.out.println(fileName + ":" + software + "/" + project);

    }

    public void write(String fileName) throws IOException {
        Path p = Paths.get(fileName);
        Files.write(p,memory);
    }

    public DTCInfo findDTCInfo() throws IOException {

        DTCInfo ret = new DTCInfo();

        // Known software
        // Please add kwonw projects there
        if (project.equals("C35374A_")) {

            // 206 1.6 HDI 110cv FAP
            ret.nbDTC = 195;
            ret.faultPathAddr = 0x1C5F96;
            ret.codeAddr = 0x1C65AE;
            ret.classAddr = 0x1C6734;

        } else if (project.startsWith("C")) {

            // PSA strategy, we assume that:
            // Last code of the codeTable is P1162
            // This code corresponds to DSM_CDKDfp_WdCom_C (ECU failure) sorted by alphabetic order when damos is generated
            // All vehicle should have this default (even if disabled)
            // PSA defines 30 classes for default
            // Try to find an occurrence of 0x16210D
            // 0x0D is the first class of the AirConditioningComponentDriver Pressure default (ACCDPresAna_C)
            // Then we parse the classTable containing value in [0..30] up the 0x2D
            // 0x2D correspond to the first byte of the code environment table that defines how code path are triggered
            // This might fail if the vehicle has no Air Conditioning

            ret.classAddr = search(new byte[]{0x16,0x21,0x0D}) + 2;
            if(ret.classAddr<0)
                throw new IOException("Cannot find DTC Table, please contribute to this project to add new platform.");
            ret.nbDTC = 0;
            while(ret.nbDTC<MAX_DTC && memory[ret.classAddr+ret.nbDTC]<=30) {
                ret.nbDTC++;
            }
            if(ret.nbDTC>=MAX_DTC)
                throw new IOException("Cannot find DTC Table, please contribute to this project to add new platform.");

            ret.codeAddr = ret.classAddr - ret.nbDTC*2;
            ret.faultPathAddr = ret.codeAddr - ret.nbDTC*8;

        } else {
            throw new IOException("Cannot find DTC Table, please contribute to this project to add new platform.");
        }

        return ret;
    }

    @Override
    public String toString() {
        return "Dump{" +
                "memory=" + memory.length +
                ", software='" + software + '\'' +
                ", project='" + project + '\'' +
                '}';
    }

    private boolean match(int add, byte[] pattern) {
        boolean equal = true;
        int i = 0;
        while(equal && i<pattern.length) {
            equal = pattern[i] == memory[add + i];
            i++;
        }
        return equal;
    }

    private int search(byte[] pattern) {

        int add = 0x1C0000;
        boolean found = false;
        while(!found && add<DUMP_SIZE-pattern.length) {
            found = match(add, pattern);
            if (!found) add++;
        }

        if(!found)
            return -1;
        else
            return add;

    }

}
Jean_Luc est déconnecté   Réponse avec citation