fix: 更改 ICCID 更新逻辑
- 确保离线又重新上线后,是否有换卡
This commit is contained in:
parent
e3870f6680
commit
b011289fdf
@ -30,6 +30,8 @@ public class APIController extends BasicController{
|
||||
DeviceCacheCmdMapper cacheCmdMapper;
|
||||
@Autowired
|
||||
WarningMsgMapper warningMsgMapper;
|
||||
@Autowired
|
||||
GnssStatusMapper gnssStatusMapper;
|
||||
|
||||
/****** config ack *******/
|
||||
@PostMapping(value = "/api/config_ack")
|
||||
@ -151,6 +153,7 @@ public class APIController extends BasicController{
|
||||
// 保存
|
||||
saveMsg(deviceId, tenantId,0xD312, uploadCmd, true);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -189,10 +192,8 @@ public class APIController extends BasicController{
|
||||
// 保存
|
||||
saveMsg(deviceId, tenantId,cacheCmd.getMsgtype(), cacheCmd.getCmd(), true);
|
||||
}
|
||||
|
||||
// 检查iccid
|
||||
// 设备上线后,检查是否需要重新查询更新 ICCID
|
||||
checkAndAskICCID(device);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -245,7 +246,19 @@ public class APIController extends BasicController{
|
||||
}
|
||||
|
||||
void checkAndAskICCID(GnssDevice device) {
|
||||
if(device.getIccid() == null || device.getIccid().trim().isEmpty()) {
|
||||
GnssStatus status = gnssStatusMapper.getByDeviceId(device.getDeviceid());
|
||||
|
||||
// 1. 检查设备是否有 ICCID记录 (初始化)
|
||||
// 2. 检查设备是否从离线恢复 (防止更换 SIM 卡)
|
||||
// 3. 如果两种情况都不满足,则不查询 ICCID
|
||||
|
||||
boolean isDeviceReconnecting = status != null && status.getState() == GnssStatus.STATE_OFFLINE;
|
||||
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);
|
||||
@ -254,7 +267,6 @@ public class APIController extends BasicController{
|
||||
"01" + HexUtil.String2HexString(sendCmd);
|
||||
rtcmClient.config(device.getDeviceid(), sendCmd);
|
||||
}
|
||||
}
|
||||
void updateICCID(GnssDevice device, String dtuAck) {
|
||||
// 只检查 "ICCID:" 的十六进制部分
|
||||
if(!dtuAck.contains("49434349443a")){
|
||||
@ -262,7 +274,6 @@ public class APIController extends BasicController{
|
||||
}
|
||||
String content = HexUtil.HexString2String(dtuAck);
|
||||
if(content.contains("+ICCID:")){
|
||||
//System.out.println(content);
|
||||
String iccid = content.substring(content.indexOf("+ICCID:") + 8).trim();
|
||||
iccid = iccid.split("\r\n")[0].trim();
|
||||
device.setIccid(iccid);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user