feat: 调整温度采集和保存

hc-jna3
huangfeng 16 hours ago
parent 8d64ad8e57
commit 3f71d05990

@ -3,15 +3,9 @@ package com.xydl.cac.thermal;
import com.hcsdk.HCNetSDK; import com.hcsdk.HCNetSDK;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.xydl.cac.entity.NSensor; import com.xydl.cac.entity.NSensor;
import com.xydl.cac.entity.ThermalConfig;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.service.DataService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service @Service
@Slf4j @Slf4j
public class HCRemoteConfigCallBack implements HCNetSDK.FRemoteConfigCallBack { public class HCRemoteConfigCallBack implements HCNetSDK.FRemoteConfigCallBack {
@ -19,43 +13,38 @@ public class HCRemoteConfigCallBack implements HCNetSDK.FRemoteConfigCallBack {
public boolean done; public boolean done;
public NSensor item; public NSensor item;
public String time; public String time;
public ThermalConfig config; public HCThermalService service;
@Resource
DataService dataService;
@Override @Override
public void invoke(int dwType, Pointer lpBuffer, int dwBufLen, Pointer pUserData) { public void invoke(int dwType, Pointer lpBuffer, int dwBufLen, Pointer pUserData) {
if (done) { if (done) {
return; return;
} }
HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD data = new HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD(); try {
Pointer pointer = data.getPointer(); HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD data = new HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD();
pointer.write(0, lpBuffer.getByteArray(0, data.size()), 0, data.size()); Pointer pointer = data.getPointer();
data.read(); pointer.write(0, lpBuffer.getByteArray(0, data.size()), 0, data.size());
float fAverageTemperature = data.struLinePolygonThermCfg.fAverageTemperature; data.read();
float fMinTemperature = data.struLinePolygonThermCfg.fMinTemperature; float max, min, aver;
float fMaxTemperature = data.struLinePolygonThermCfg.fMaxTemperature; if (0 == data.byRuleCalibType) {
log.info("海康热成像采集到max=" + fMaxTemperature + ", min=" + fMinTemperature + ", aver=" + fAverageTemperature); max = data.struPointThermCfg.fTemperature;
done = true; min = max;
aver = max;
if (StringUtils.isNotBlank(config.getMaxtemp())) { log.info("海康热成像采集到max=" + max + ", min=" + min + ", aver=" + aver);
String value = String.valueOf(fMaxTemperature); service.save(item.getTableName(), item.getDevId(),
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getMaxtemp(), value); max, min, aver, time);
// 更新最新数据缓存 done = true;
StaticVariable.updateLastData(item.getDevId(), config.getMaxtemp(), value, time); } else if (1 == data.byRuleCalibType || 2 == data.byRuleCalibType) {
} max = data.struLinePolygonThermCfg.fAverageTemperature;
if (StringUtils.isNotBlank(config.getMintemp())) { min = data.struLinePolygonThermCfg.fMinTemperature;
String value = String.valueOf(fMinTemperature); aver = data.struLinePolygonThermCfg.fMaxTemperature;
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getMintemp(), value); log.info("海康热成像采集到max=" + max + ", min=" + min + ", aver=" + aver);
// 更新最新数据缓存 service.save(item.getTableName(), item.getDevId(),
StaticVariable.updateLastData(item.getDevId(), config.getMintemp(), value, time); max, min, aver, time);
} done = true;
if (StringUtils.isNotBlank(config.getAvertemp())) { }
String value = String.valueOf(fAverageTemperature); } catch (Exception ex) {
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getAvertemp(), value); log.error("HCRemoteConfigCallBack异常", ex);
// 更新最新数据缓存
StaticVariable.updateLastData(item.getDevId(), config.getAvertemp(), value, time);
} }
} }
} }

@ -3,8 +3,12 @@ package com.xydl.cac.thermal;
import com.hcsdk.HCModule; import com.hcsdk.HCModule;
import com.xydl.cac.entity.NSensor; import com.xydl.cac.entity.NSensor;
import com.xydl.cac.entity.ThermalConfig; import com.xydl.cac.entity.ThermalConfig;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.service.DataService;
import com.xydl.cac.util.DateUtil; import com.xydl.cac.util.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
@ -16,9 +20,12 @@ import java.util.List;
@Slf4j @Slf4j
public class HCThermalService { public class HCThermalService {
@Resource
DataService dataService;
@Resource @Resource
HCRemoteConfigCallBack _callBack; HCRemoteConfigCallBack _callBack;
ThermalConfig _config;
int shutdown = 0; int shutdown = 0;
@PreDestroy @PreDestroy
@ -30,6 +37,7 @@ public class HCThermalService {
if (shutdown == 1) { if (shutdown == 1) {
return; return;
} }
_config = config;
try { try {
HCModule.init(); HCModule.init();
NSensor sensor = list.get(0); NSensor sensor = list.get(0);
@ -43,8 +51,8 @@ public class HCThermalService {
for (NSensor item : list) { for (NSensor item : list) {
_callBack.done = false; _callBack.done = false;
_callBack.item = item; _callBack.item = item;
_callBack.config = config;
_callBack.time = DateUtil.format(new Date()); _callBack.time = DateUtil.format(new Date());
_callBack.service = this;
r = HCModule.startRemoteConfig(_callBack, 2, item.getTmId()); r = HCModule.startRemoteConfig(_callBack, 2, item.getTmId());
if (r) { if (r) {
int sec = 0; int sec = 0;
@ -65,4 +73,27 @@ public class HCThermalService {
HCModule.cleanup(); HCModule.cleanup();
} }
} }
@Async
public void save(String tableName, Integer devId,
float max, float min, float aver, String time) {
if (StringUtils.isNotBlank(_config.getMaxtemp())) {
String value = String.valueOf(max);
dataService.insertData(tableName, devId, time, _config.getMaxtemp(), value);
// 更新最新数据缓存
StaticVariable.updateLastData(devId, _config.getMaxtemp(), value, time);
}
if (StringUtils.isNotBlank(_config.getMintemp())) {
String value = String.valueOf(min);
dataService.insertData(tableName, devId, time, _config.getMintemp(), value);
// 更新最新数据缓存
StaticVariable.updateLastData(devId, _config.getMintemp(), value, time);
}
if (StringUtils.isNotBlank(_config.getAvertemp())) {
String value = String.valueOf(aver);
dataService.insertData(tableName, devId, time, _config.getAvertemp(), value);
// 更新最新数据缓存
StaticVariable.updateLastData(devId, _config.getAvertemp(), value, time);
}
}
} }

Loading…
Cancel
Save