package com.casic.missiles.service.listeners.device;

import com.casic.missiles.service.Impl.business.BusinessReadWriterServiceImpl;
import com.casic.missiles.utils.SerialPortUtil;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;

import java.util.HashSet;
import java.util.Set;

/**
 * @Description: 设备串口接收数据监听器
 * @Author: wangpeng
 * @Date: 2023/4/4 16:46
 */
public class CodeGunDataListener implements SerialPortEventListener {
    public static Set<String> dataSet = new HashSet<>();

    @Override
    public void serialEvent(SerialPortEvent event) {
        if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            SerialPortUtil serialPortUtil = SerialPortUtil.getSerialPortUtil();
            byte[] bytes = serialPortUtil.readFromPort(BusinessReadWriterServiceImpl.serialPort);
            dataSet.add(new String(bytes, 0, bytes.length).trim());
        }
    }
}
