feature/simcards_checker #2

Merged
admin merged 5 commits from feature/simcards_checker into develop 2025-06-03 08:29:08 +00:00
Showing only changes of commit b011289fdf - Show all commits

View File

@ -30,6 +30,8 @@ public class APIController extends BasicController{
DeviceCacheCmdMapper cacheCmdMapper; DeviceCacheCmdMapper cacheCmdMapper;
@Autowired @Autowired
WarningMsgMapper warningMsgMapper; WarningMsgMapper warningMsgMapper;
@Autowired
GnssStatusMapper gnssStatusMapper;
/****** config ack *******/ /****** config ack *******/
@PostMapping(value = "/api/config_ack") @PostMapping(value = "/api/config_ack")
@ -151,6 +153,7 @@ public class APIController extends BasicController{
// 保存 // 保存
saveMsg(deviceId, tenantId,0xD312, uploadCmd, true); saveMsg(deviceId, tenantId,0xD312, uploadCmd, true);
return null; return null;
} }
@ -189,10 +192,8 @@ public class APIController extends BasicController{
// 保存 // 保存
saveMsg(deviceId, tenantId,cacheCmd.getMsgtype(), cacheCmd.getCmd(), true); saveMsg(deviceId, tenantId,cacheCmd.getMsgtype(), cacheCmd.getCmd(), true);
} }
// 设备上线后检查是否需要重新查询更新 ICCID
// 检查iccid
checkAndAskICCID(device); checkAndAskICCID(device);
return null; return null;
} }
@ -244,16 +245,27 @@ public class APIController extends BasicController{
msgMapper.insert(gnssMsg); msgMapper.insert(gnssMsg);
} }
void checkAndAskICCID(GnssDevice device){ void checkAndAskICCID(GnssDevice device) {
if(device.getIccid() == null || device.getIccid().trim().isEmpty()) { GnssStatus status = gnssStatusMapper.getByDeviceId(device.getDeviceid());
String sendCmd = "AT+ICCID";
int msgType = 0xD310 + 10; // DTU // 1. 检查设备是否有 ICCID记录 初始化
short len = (short) (sendCmd.length() + 5); // 2. 检查设备是否从离线恢复 防止更换 SIM
sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len) + // 3. 如果两种情况都不满足则不查询 ICCID
HexUtil.Int2HexString(Integer.parseInt(device.getDeviceid())) +
"01" + HexUtil.String2HexString(sendCmd); boolean isDeviceReconnecting = status != null && status.getState() == GnssStatus.STATE_OFFLINE;
rtcmClient.config(device.getDeviceid(), sendCmd); boolean isIccidEmpty = device.getIccid() == null || device.getIccid().trim().isEmpty();
if (!isDeviceReconnecting && !isIccidEmpty) {
return;
} }
String sendCmd = "AT+ICCID";
int msgType = 0xD310 + 10; // DTU
short len = (short) (sendCmd.length() + 5);
sendCmd = Integer.toHexString(msgType) + HexUtil.Short2HexString(len) +
HexUtil.Int2HexString(Integer.parseInt(device.getDeviceid())) +
"01" + HexUtil.String2HexString(sendCmd);
rtcmClient.config(device.getDeviceid(), sendCmd);
} }
void updateICCID(GnssDevice device, String dtuAck) { void updateICCID(GnssDevice device, String dtuAck) {
// 只检查 "ICCID:" 的十六进制部分 // 只检查 "ICCID:" 的十六进制部分
@ -262,7 +274,6 @@ public class APIController extends BasicController{
} }
String content = HexUtil.HexString2String(dtuAck); String content = HexUtil.HexString2String(dtuAck);
if(content.contains("+ICCID:")){ if(content.contains("+ICCID:")){
//System.out.println(content);
String iccid = content.substring(content.indexOf("+ICCID:") + 8).trim(); String iccid = content.substring(content.indexOf("+ICCID:") + 8).trim();
iccid = iccid.split("\r\n")[0].trim(); iccid = iccid.split("\r\n")[0].trim();
device.setIccid(iccid); device.setIccid(iccid);