Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

trkall / T-Diagnostics

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • T-Diagnostics
  • src
  • com
  • tDiagnostics
  • diagnostics
  • blocks
  • DTCBlock.java
Find file
BlameHistoryPermalink
  • Tref's avatar
    upload structured project · bd8c3f69
    Tref committed 4 years ago
    bd8c3f69
DTCBlock.java 2.06 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
package com.tDiagnostics.diagnostics.blocks;

import com.fazecast.jSerialComm.SerialPort;
import com.tDiagnostics.communication.handler.ConnectionHandler;

public class DTCBlock{
    static int arrSize = 4;

    static String strDTC[] = new String[arrSize];

    public static void sendDTCBlock(SerialPort device, ConnectionHandler con){
        con.sendByte(device, 0x03, true);
        con.readByte(device, 0x03, true);
        if(con.WRONG_ANSWER)
            return ;
        con.sendByte(device, con.blockCounter+1, true);
        con.readByte(device, con.blockCounter+1, true);
        if(con.WRONG_ANSWER)
            return ;

        con.sendByte(device, 0x09, true);
        con.readByte(device,0x09, true);
        if(con.WRONG_ANSWER)
            return ;

        con.sendByte(device, 0x03, true);

    }

    public static String[] readDTCBlock(SerialPort port, ConnectionHandler con){
        int i = 0;


        for(i=0;i<4;i++){
            int hex = 0x00;
            for(int j=0;j<3;j++){
                int asciiData = con.readByte(port,0, false);
                if(asciiData == 0x03) {
                    i = 5;
                    break;
                }
                con.sendByte(port, 0xFF-asciiData, true);
                if(j==0)
                    hex = 0x1100 * asciiData;
                else if(j==1)
                    hex += asciiData;
            }
            strDTC[i] = String.format("%d", hex);


        }
        if(i==5)
            con.readByte(port,0, false);//end
        return strDTC;
    }

    public static int removeDTCs(SerialPort port, ConnectionHandler con){
        con.sendByte(port, 0x03, true);
        con.readByte(port, 0x03, true);
        if(con.WRONG_ANSWER)
            return 1;

        con.sendByte(port, con.blockCounter+1, true);
        con.readByte(port, con.blockCounter+1, true);
        if(con.WRONG_ANSWER)
            return 1;

        con.sendByte(port, 0x05, true);
        con.readByte(port, 0x05, true);
        if(con.WRONG_ANSWER)
            return 1;


        con.sendByte(port, 0x03, true);
        return 0;
    }
}