package com.doverfuelingsolutions.issp.driver.serialPort;

import com.doverfuelingsolutions.issp.driver.printer.PrintStatusListen;
import com.doverfuelingsolutions.issp.driver.scan.ScanValueListener;

public class SerialControl extends SerialHelper {
    private final static String TAG = "SerialControl";
    DataReceivedListener listener;
    ScanValueListener scanValueListener;//扫描器的监听
    PrintStatusListen printStatusListen;//小票的监听

    public SerialControl(String sPort, int iBaudRate, DataReceivedListener listener, ScanValueListener scanValueListener) {
        super(sPort, iBaudRate);
        this.listener = listener;
        this.scanValueListener = scanValueListener;
    }

    public SerialControl(String sPort, int iBaudRate, DataReceivedListener listener, PrintStatusListen printStatusListen) {
        super(sPort, iBaudRate);
        this.listener = listener;
        this.printStatusListen = printStatusListen;
    }

    @Override
    protected void onDataReceived(final ComBean ComRecData) {
        if (null != listener) {
            if (null != scanValueListener) {
                listener.onDataReceived(ComRecData.bRec, scanValueListener);
                return;
            }
            if (null != printStatusListen) {
                listener.onDataReceived(ComRecData.bRec, printStatusListen);
                return;
            }
            listener.onDataReceived(ComRecData.bRec);
        }
    }
}
