|
|
|
@ -3,6 +3,7 @@ package com.xydl.cac.service.impl;
|
|
|
|
|
import com.fazecast.jSerialComm.SerialPort;
|
|
|
|
|
import com.xydl.cac.model.StaticVariable;
|
|
|
|
|
import com.xydl.cac.service.SerialPortService;
|
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@ -18,6 +20,10 @@ public class SerialPortServiceImpl implements SerialPortService {
|
|
|
|
|
|
|
|
|
|
@Value("${cac.warnport.name}")
|
|
|
|
|
public String warnportname;
|
|
|
|
|
@Value("${cac.warnport.intervaltime:60000}")
|
|
|
|
|
public Integer intervaltime;
|
|
|
|
|
@Value("${cac.warnport.warntime:5000}")
|
|
|
|
|
public Integer warntime;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean discoverSerialPort() {
|
|
|
|
@ -56,20 +62,28 @@ public class SerialPortServiceImpl implements SerialPortService {
|
|
|
|
|
@Async
|
|
|
|
|
public void sendData(boolean data) {
|
|
|
|
|
if (openSerialPort()) {
|
|
|
|
|
byte[] openbuffer = new byte[]{00, (byte) 0xf1, (byte) 0xff};
|
|
|
|
|
byte[] stopbuffer = new byte[]{00, (byte) 0x01, (byte) 0xff};
|
|
|
|
|
byte[] openbuffer = new byte[]{00, (byte) 0xf1, (byte) 0xff};//发送串口告警
|
|
|
|
|
byte[] stopbuffer = new byte[]{00, (byte) 0x01, (byte) 0xff};//关闭串口告警
|
|
|
|
|
SerialPort port = StaticVariable.currentPort;
|
|
|
|
|
if (port != null) {
|
|
|
|
|
if (data) {
|
|
|
|
|
port.writeBytes(openbuffer, openbuffer.length);
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
if (StaticVariable.LastWarningTime == null) {
|
|
|
|
|
StaticVariable.LastWarningTime = new Date();
|
|
|
|
|
} else {
|
|
|
|
|
port.writeBytes(stopbuffer, stopbuffer.length);
|
|
|
|
|
long lastWarningTimeTime = StaticVariable.LastWarningTime.getTime();
|
|
|
|
|
long time = date.getTime();
|
|
|
|
|
if (time - lastWarningTimeTime <= intervaltime) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StaticVariable.LastWarningTime = date;
|
|
|
|
|
port.writeBytes(openbuffer, openbuffer.length);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(5000);
|
|
|
|
|
port.writeBytes(stopbuffer, stopbuffer.length);
|
|
|
|
|
Thread.sleep(warntime);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
port.writeBytes(stopbuffer, stopbuffer.length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|