package com.tDiagnostics.diagnostics.blocks;

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

public class GroupReadingBlock {
    public Integer groupReadingData[][] = new Integer[4][3];///group,nr,data
    //public String groupReadingDataString[][] = new String[26][4];
    ConnectionHandler con;
    public GroupReadingBlock(ConnectionHandler connection){
        con = connection;
    }

    public int sendGroupReading(SerialPort port, int key){
        System.out.println("START_sendGroupReading");
        con.sendByte(port, 0x04, true);
        con.readByte(port, 0x04, 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, 0x29, true);
        con.readByte(port, 0x29, true);
        if(con.WRONG_ANSWER)
            return 1;

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

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