From: snickersun Date: Mon, 13 Apr 2020 07:36:25 +0000 (+0800) Subject: 增加对AP01,AP02,AP10三个定位相关命令的服务器响应。如果服务器5秒内没有响应重试发送,三次后还没有响应就放弃发送。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=9e2878a4e7011191d2c43a1ea74b47d1e6f027a4;p=icsupport.git 增加对AP01,AP02,AP10三个定位相关命令的服务器响应。如果服务器5秒内没有响应重试发送,三次后还没有响应就放弃发送。 --- diff --git a/app/src/main/java/com/enqualcomm/support/service/Deliver.java b/app/src/main/java/com/enqualcomm/support/service/Deliver.java index 8ac59406..be2583bb 100644 --- a/app/src/main/java/com/enqualcomm/support/service/Deliver.java +++ b/app/src/main/java/com/enqualcomm/support/service/Deliver.java @@ -158,6 +158,11 @@ public class Deliver extends AbstractConnectionService { // mSendMSGHandler.sendEmptyMessage(1); } + private static boolean NeedCheckServerResponse=true; + private static boolean ServerResponsed=false; + private static String needCheckResponseCMD=null; + private static int CheckCount=0; + public static boolean getAndSendMsgFromQueue(){ boolean ret=false; if (mRuntime.getUseQueue()) { @@ -170,6 +175,27 @@ public class Deliver extends AbstractConnectionService { //如果没有数据从缓存中尝试读取 // if (queue.isEmpty()) // loadMessage2Queue(); + if (NeedCheckServerResponse==true && ServerResponsed==false){ + if (needCheckResponseCMD!=null && CheckCount < 3) { + //如果cmd有效,且尝试次数小于3, 没有收到反馈的情况下,可以重新插入queue进行下一次尝试! + ICLogger.i("checkSrvResponse "+CheckCount+" times for "+needCheckResponseCMD); + if (!ServiceUtil.offerQueue(new StringMessage(needCheckResponseCMD), true)) { + ICLogger.i("checkSrvResponse failed ,重新添加MessageQueue 已满,数据将被丢弃!" + needCheckResponseCMD); + if (Config.LOG_TOFILE) + ICLogger.logToFile("APILog", "response failed queueFullskip! " + needCheckResponseCMD); + }else{ + if (Config.LOG_TOFILE) + ICLogger.logToFile("APILog", "response failed retry ! " +CheckCount+" " + needCheckResponseCMD); + } + CheckCount++; + }else{ + ICLogger.i("checkSrvResponse CheckCount="+CheckCount+" Timeout or cmd is null, skip "); + if (Config.LOG_TOFILE) + ICLogger.logToFile("APILog", "response timeout skip! " + needCheckResponseCMD); + CheckCount=0; + } + } + if (!queue.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); if (checkNetwork()) { @@ -181,6 +207,13 @@ public class Deliver extends AbstractConnectionService { if (checkNetwork()) { connection.sendMsg(cmd); // stringMessage = queue.poll(); + + //如果需要Check + if (NeedCheckServerResponse==true){ + ICLogger.i("checkSrvResponse "+cmd); + needCheckResponseCMD=cmd; + ServerResponsed=false; + } ret=true; } else { //已经拿到的缓存,如果刚巧没有网络,就原路放回去 @@ -288,6 +321,19 @@ public static void sendLocationMSG( String Msg){ this.mConnection = paramConnection; this.mRuntime = paramRuntime; String cmd = paramStringMessage.cmd(); + + //如果需要检测是否响应。 + if (NeedCheckServerResponse==true){ + + if(needCheckResponseCMD!=null) { + if( cmd.equals(needCheckResponseCMD.substring(0,6))){ + + ICLogger.i("checkSrvResponse "+cmd+" "+needCheckResponseCMD.substring(0,6)+" is responsed!"); + ServerResponsed=true; + CheckCount=0; + } + } + } ICLogger.i("Deliver receive cmd " + paramStringMessage.cmd()); if (cmd.equals("BP07") || cmd.equals("SentVoicePacket")) { //收到BP07 表示服务器收到一个voicePacket 分包成功,开始检查下一个包是否存在需要发送。 diff --git a/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java b/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java index fcc4cc50..38b56fa1 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java +++ b/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java @@ -62,10 +62,12 @@ public class NettyConnection implements Connection { case BP01: API.handleBP01(cmd); ICLogger.i("服务器收到定位AP01"); + DeliverCMDMessageToSystem("IWAP01",cmd);//通知下面线程状态变化 break; case BP02: API.handleBP02(cmd); ICLogger.i("服务器收到定位AP02"); + DeliverCMDMessageToSystem("IWAP02",cmd);//通知下面线程状态变化 break; case BP03: API.handleBP03(cmd); @@ -77,6 +79,10 @@ public class NettyConnection implements Connection { //收到发送的语音包 API.handleBP07(cmd,NettyConnection.this); break; + case BP10: + DeliverCMDMessageToSystem("IWAP10",cmd);//通知下面线程状态变化 + break; + case BPTM: API.handleBPTM(cmd); ICLogger.i("服务器收到校时命令APTM");