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
  • GroupReadingResponse.java
Find file
BlameHistoryPermalink
  • Tref's avatar
    upload structured project · bd8c3f69
    Tref committed 4 years ago
    bd8c3f69
GroupReadingResponse.java 2.61 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 78 79 80 81 82 83 84 85 86 87 88 89 90
package com.tDiagnostics.diagnostics.blocks;

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

public class GroupReadingResponse {
    public static int readFirstPackage(SerialPort in, ConnectionHandler con){
        System.out.println("START_readFirstPackage");
        int len = 1;
        byte buf[] = new byte[len];
        if(con.startZeros) {
            in.readBytes(buf, buf.length);
            in.readBytes(buf, buf.length);///mingi kahtlased nullid

            System.out.println("ignored two zeroes");
        }
        in.readBytes(buf, buf.length);
        con.syncbyte = con.bytesToHex(buf);

        System.out.println("syncbyte: " + String.format("0x%02x", con.syncbyte));
        if(con.syncbyte == 0)
            con.startZeros = true;
        if(con.syncbyte != 0x55)
            return 1;

        in.readBytes(buf, buf.length);
        con.LSB = con.bytesToHex(buf);
        System.out.println("LSB: " + String.format("0x%02x", con.LSB));
        if(con.LSB != 0x01)
            return 1;

        in.readBytes(buf, buf.length);
        con.HSB = con.bytesToHex(buf);
        System.out.println("HSB: " + String.format("0x%02x", con.HSB));
        if(con.HSB != 0x8A)
            return 1;

        in.writeBytes(con.toByteArray((0xFF - con.HSB)), len);

        if(!con.echoOn && !con.skipEchoCheck) {
            in.readBytes(buf, buf.length);
            if (con.bytesToHex(buf) == 0xFF - con.HSB) {
                con.echoOn = true;

                return 1;
            }else{
                con.skipEchoCheck = true;
            }

        }else{
            con.cancelEcho(in);
        }

        return 0;

    }
    //
    public static void readECUDataPackage(SerialPort port, ConnectionHandler con){
        System.out.println("START_readECUDataPackage");
        for(;;){
            int dat = con.readByte(port,0, false);
            System.out.println(dat);
            if(dat == 0x03)
                break;
            con.sendByte(port, 0xFF-dat, true);


        }

    }
    public static Integer[][] readSensorDataBlock(SerialPort port, ConnectionHandler con){
        System.out.println("START_readSensorDataBlock");
        Integer blockReadingValues[][] = new Integer[4][3];
        int j = 0, k = 0;
        for(;;){
            int dat = con.readByte(port,0, false);
            if(dat == 0x03)
                break;
            con.sendByte(port, 0xFF-dat, true);

            blockReadingValues[j][k] = dat;
            k++;
            if(k == 3){
                k = 0;
                j++;
            }
        }
        return blockReadingValues;
    }
}