feature/simcards_checker #2
@ -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,8 +245,20 @@ 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());
|
||||||
|
|
||||||
|
// 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";
|
String sendCmd = "AT+ICCID";
|
||||||
int msgType = 0xD310 + 10; // DTU
|
int msgType = 0xD310 + 10; // DTU
|
||||||
short len = (short) (sendCmd.length() + 5);
|
short len = (short) (sendCmd.length() + 5);
|
||||||
@ -254,7 +267,6 @@ public class APIController extends BasicController{
|
|||||||
"01" + HexUtil.String2HexString(sendCmd);
|
"01" + HexUtil.String2HexString(sendCmd);
|
||||||
rtcmClient.config(device.getDeviceid(), sendCmd);
|
rtcmClient.config(device.getDeviceid(), sendCmd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void updateICCID(GnssDevice device, String dtuAck) {
|
void updateICCID(GnssDevice device, String dtuAck) {
|
||||||
// 只检查 "ICCID:" 的十六进制部分
|
// 只检查 "ICCID:" 的十六进制部分
|
||||||
if(!dtuAck.contains("49434349443a")){
|
if(!dtuAck.contains("49434349443a")){
|
||||||
@ -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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user