package com.tDiagnostics.diagnostics.blocks;

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

public class ACKBlock {
    public static void sendAckBlock(SerialPort device, ConnectionHandler con){
        System.out.println("START_sendAckBlock");
        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 void readACK(SerialPort port, ConnectionHandler con){
        System.out.println("START_readACK");
        int ack = con.readByte(port,0, false);
        con.sendByte(port, 0xFF-ack, true);
        con.readByte(port,0, false);
    }
}