package com.gto.ethernet_sample_code;

import android.content.Context;
import android.content.res.AssetManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.Toast;

import com.gainscha.gtspl_sdk.GTSPLWIFIActivity;

import org.json.JSONObject;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class PlusUtils{
    public static GTSPLWIFIActivity mGtsplWIFICmdTest;
    private String title, type;
    private Context context;

    public PlusUtils(GTSPLWIFIActivity mGtsplWIFICmdTest, Context context, String title, String type) {
        this.mGtsplWIFICmdTest = mGtsplWIFICmdTest;
        this.context = context;
        this.title = title;
        this.type = type;
    }


    public void print() {
        // TODO: 2024/11/25 打印机连接代码
        String ip = "192.168.66.137";
        int port = 9100;
        int timeout=4000;
        //set to print mode
        mGtsplWIFICmdTest.GTSPL_setCmdSendMode("P");
        setPlusMode(ip, port);
        mGtsplWIFICmdTest.setCallback(isConnected -> {
            if (isConnected) {
                System.out.println("Connection succeeded!");
            } else {
                System.out.println("Connection failed!");
                mGtsplWIFICmdTest.GTSPL_openPort(ip,port,timeout);
            }
        });


    }

    public void setPlusMode(String ip, int port) {
        mGtsplWIFICmdTest.GTSPL_openPort(ip, port, 4000);
    }
}
