告警硬接点装置增加停顿时间配置,和告警间隔配置

main
liuguijing 6 months ago
parent fc720c9389
commit b094504dc8

@ -10,10 +10,7 @@ import com.xydl.cac.iec.IecClient;
import com.xydl.cac.iec.IecServer;
import com.xydl.cac.util.DateUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class StaticVariable {
@ -34,6 +31,7 @@ public class StaticVariable {
public static ConcurrentHashMap<Integer, WarnRule> rule_Cache = new ConcurrentHashMap<>();
public static SerialPort currentPort;
public static Date LastWarningTime;//最后一次硬接点告警时间
public static void wait(int seconds) throws InterruptedException {
for (int i = 0; i < seconds; i++) {

@ -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);
}
}
}

@ -51,3 +51,5 @@ cac:
rsakey: MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=
warnport:
name: ttyCH341USB0
intervaltime: 60000
warntime: 5000

Loading…
Cancel
Save