|
|
|
@ -17,6 +17,8 @@ import java.util.*; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@ -93,7 +95,16 @@ public class TCPClient { |
|
|
|
while ((responseLine = in.readLine()) != null) { |
|
|
|
if (StringUtils.hasText(responseLine) && !"STO".equals(responseLine) && !"\u0018".equals(responseLine)) { |
|
|
|
log.info("{}设备, IP: {}, Port: {}, 采集数据: {}", config.getEquipmentNo(), config.getIp(), config.getPort(), responseLine); |
|
|
|
saveData(config, responseLine); |
|
|
|
if (StringUtils.hasText(config.getRegexp())){ |
|
|
|
log.info("正则表达式: {}",config.getRegexp()); |
|
|
|
Pattern pattern = Pattern.compile(config.getRegexp()); |
|
|
|
Matcher matcher = pattern.matcher(responseLine); |
|
|
|
if (matcher.find()){ |
|
|
|
saveData(config, matcher.group(1)); |
|
|
|
} |
|
|
|
}else { |
|
|
|
saveData(config, responseLine); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
@ -157,4 +168,19 @@ public class TCPClient { |
|
|
|
closeConnection(key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
String input = "1.79260e-08,1.15843e-03,40"; |
|
|
|
String regex = "^([1-9]\\d*(\\.\\d+)?|1\\.\\d+)(?=e.*|,|$)"; |
|
|
|
|
|
|
|
Pattern pattern = Pattern.compile(regex); |
|
|
|
Matcher matcher = pattern.matcher(input); |
|
|
|
System.out.println(regex.length()); |
|
|
|
if (matcher.find()) { |
|
|
|
String matchedValue = matcher.group(1); |
|
|
|
System.out.println("匹配到的值:" + matchedValue); |
|
|
|
} else { |
|
|
|
System.out.println("没有匹配到符合条件的值"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |