From: snickersun Date: Fri, 25 Sep 2020 12:13:53 +0000 (+0800) Subject: 所有parseInt 都用try catch 包裹。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=bd3f3d74cc85513efedf2499bc11e69300f7e7da;p=protocol_srv.git 所有parseInt 都用try catch 包裹。 优化 Util.isNumeric 函数 --- diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index a9b81ccb..0313f45f 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -35,6 +35,7 @@ public class Config { public static int defaultHeartbeatCycle=5; public static int sw_release_no = -1; public static int bleScanTimeout=10; + public static boolean forceMoveCheck=false; public static String work_mode = "2@1"; public static final String JiAiHost="watch.jiai.pro"; diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index 151a44bc..6b41132a 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -695,6 +695,17 @@ public void updateCellInfo() { private static boolean NoMoveAndNoGPSsignalSkipGpsFlag=false; private static boolean noMove=false; + private static boolean last_noMove=false; + private static int noMoveCount=0; + private static final int MaxNoMoveTimeout=3000; + + private static void checkNoMove(){ + + + noMove=runtime.getLastStepCount() == runtime.getTotalStepCount(); + runtime.updateFZDDevStatusMoving(!noMove); //设置当前运动状态 + + } @@ -706,16 +717,12 @@ public void updateCellInfo() { ICLogger.i("locating ,skip location!"); return; } - noMove=runtime.getLastStepCount() == runtime.getTotalStepCount(); - runtime.updateFZDDevStatusMoving(!noMove); //设置当前运动状态 + + checkNoMove(); // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过 if ( ( forceLocation != 1 ) && - ( mod != ICLocation.REALTIME_MOD )&& - ( mod != ICLocation.EMERGNECY_MOD ) && - (mod != ICLocation.CUSTOM_MOD8_GPS ) && -// (mod != ICLocation.CUSTOM_MOD8_WIFI ) && - (mod != ICLocation.CUSTOM_MOD ) && + ((( mod == ICLocation.NORMAL_MOD ) || ( mod == ICLocation.LOWPOWER_MOD ) || (mod == ICLocation.CUSTOM_MOD8_WIFI ) ) || Config.forceMoveCheck==true) && (noMove) && (skipMoveCheck ==false )){ ICLogger.i("No Move ,skip location!"); return ; diff --git a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java index 0a5a1e54..50ec7a73 100644 --- a/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java +++ b/app/src/main/java/com/enqualcomm/support/service/HeartRateManager.java @@ -463,7 +463,14 @@ public static void triggerPPGtest(){ return true; } - if (spo2==null || (spo2!=null && Integer.parseInt(spo2 )<=0) ){ + if (spo2==null || + (spo2!=null && + ( (!Util.isNumeric(spo2.trim() )) || + (Util.isNumeric(spo2.trim() )&& Integer.parseInt(spo2.trim())<=0) + ) + ) + ) + { Random r = new Random(); int randomint = r.nextInt(98 - 95) + 95; spo2=String.valueOf(randomint); @@ -495,17 +502,22 @@ public static void triggerPPGtest(){ } }else { - StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(Integer.parseInt(ppg), Integer.parseInt(bph), Integer.parseInt(bpl), Integer.parseInt(spo2), runtime); - if (PPGDATA == null) { - StringMessage ppgd = protocolAPIHelper.getPPG_MSG(Integer.parseInt(ppg), runtime); - StringMessage bloodd = protocolAPIHelper.getBlood_MSG(Integer.parseInt(bph), Integer.parseInt(bpl), runtime); - StringMessage oxd = protocolAPIHelper.getOxygen_MSG(Integer.parseInt(spo2), runtime); - Deliver.sendLocationMSG(ppgd); - Deliver.sendLocationMSG(bloodd); - Deliver.sendLocationMSG(oxd); - } else { - Deliver.sendLocationMSG(PPGDATA); - ICLogger.i("Send PPG " + PPGDATA.isFromCache()); + try { + StringMessage PPGDATA = protocolAPIHelper.getPPG_ECG_MSG(Integer.parseInt(ppg), Integer.parseInt(bph), Integer.parseInt(bpl), Integer.parseInt(spo2), runtime); + if (PPGDATA == null) { + StringMessage ppgd = protocolAPIHelper.getPPG_MSG(Integer.parseInt(ppg), runtime); + StringMessage bloodd = protocolAPIHelper.getBlood_MSG(Integer.parseInt(bph), Integer.parseInt(bpl), runtime); + StringMessage oxd = protocolAPIHelper.getOxygen_MSG(Integer.parseInt(spo2), runtime); + Deliver.sendLocationMSG(ppgd); + Deliver.sendLocationMSG(bloodd); + Deliver.sendLocationMSG(oxd); + } else { + Deliver.sendLocationMSG(PPGDATA); + ICLogger.i("Send PPG " + PPGDATA.isFromCache()); + } + }catch (Exception e){ + e.printStackTrace(); + ICLogger.e(e.getMessage(),e); } } callback(message.replyTo, Constants.RESULT_OK); diff --git a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java index 1da02805..215dab07 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java @@ -117,29 +117,34 @@ public class ContextProxy { char c = '\002'; if (cursor2 != null) { while (cursor2.moveToNext()) { - if ("ON".equals(cursor2.getString(4))) { - String str2 = cursor2.getString(1); - String str1 = cursor2.getString(c); - String str3 = cursor2.getString(b2); - String str4 = cursor2.getString(b1); - calendar2.set(Calendar.HOUR_OF_DAY, Integer.parseInt(str2.substring(c, 4))); - calendar2.set(Calendar.MINUTE, Integer.parseInt(str2.substring(b1, 7))); - char[] arrayOfChar = str1.toCharArray(); - int i = arrayOfChar.length; - byte b = 1; - while (b < i) { - c = (char)(arrayOfChar[b] - '/'); //将ascii数字字符转换为对应的数字 - calendar2.set(Calendar.DAY_OF_WEEK, c); - long l1 = calendar2.getTimeInMillis(); - if (l1 <= l) - l1 += ONE_WEEK; - PendingIntent pendingIntent = getPendingIntent(str2, str1, str3, str4, c); - AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); - b++; - c = '\002'; - b1 = 5; - b2 = 3; + try { + if ("ON".equals(cursor2.getString(4))) { + String str2 = cursor2.getString(1); + String str1 = cursor2.getString(c); + String str3 = cursor2.getString(b2); + String str4 = cursor2.getString(b1); + calendar2.set(Calendar.HOUR_OF_DAY, Integer.parseInt(str2.substring(c, 4))); + calendar2.set(Calendar.MINUTE, Integer.parseInt(str2.substring(b1, 7))); + char[] arrayOfChar = str1.toCharArray(); + int i = arrayOfChar.length; + byte b = 1; + while (b < i) { + c = (char) (arrayOfChar[b] - '/'); //将ascii数字字符转换为对应的数字 + calendar2.set(Calendar.DAY_OF_WEEK, c); + long l1 = calendar2.getTimeInMillis(); + if (l1 <= l) + l1 += ONE_WEEK; + PendingIntent pendingIntent = getPendingIntent(str2, str1, str3, str4, c); + AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); + b++; + c = '\002'; + b1 = 5; + b2 = 3; + } } + }catch (Exception e){ + e.printStackTrace(); + ICLogger.e(e.getMessage(),e); } } cursor2.close(); @@ -149,29 +154,34 @@ public class ContextProxy { Cursor cursor1 = this.context.getContentResolver().query(ICContentProvider.NOTICE_URL, null, null, null, null); if (cursor1 != null) { while (cursor1.moveToNext()) { - String str1 = cursor1.getString(1); - String str2 = cursor1.getString(2); - String str3 = cursor1.getString(3); - String str4 = cursor1.getString(4); - String str5 = cursor1.getString(5); - String str6 = cursor1.getString(6); - String str7 = cursor1.getString(6); - if (str1 != null) { - String year = str1.substring(0, 4); - String month = str1.substring(4, 6); - String day = str1.substring(6, 8); - String hour = str1.substring(8, 10); - String minute = str1.substring(10, 12); - calendar1.set(Calendar.YEAR, Integer.parseInt(year)); - calendar1.set(Calendar.MONTH, Integer.parseInt(month)); - calendar1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day)); - calendar1.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour)); - calendar1.set(Calendar.MINUTE, Integer.parseInt(minute)); - long l1 = calendar1.getTimeInMillis(); - if (l1 > l) { - PendingIntent pendingIntent = getPendingIntent(str1, str2, str3, str4, str5, str6, str7); - AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); + try { + String str1 = cursor1.getString(1); + String str2 = cursor1.getString(2); + String str3 = cursor1.getString(3); + String str4 = cursor1.getString(4); + String str5 = cursor1.getString(5); + String str6 = cursor1.getString(6); + String str7 = cursor1.getString(6); + if (str1 != null) { + String year = str1.substring(0, 4); + String month = str1.substring(4, 6); + String day = str1.substring(6, 8); + String hour = str1.substring(8, 10); + String minute = str1.substring(10, 12); + calendar1.set(Calendar.YEAR, Integer.parseInt(year)); + calendar1.set(Calendar.MONTH, Integer.parseInt(month)); + calendar1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day)); + calendar1.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour)); + calendar1.set(Calendar.MINUTE, Integer.parseInt(minute)); + long l1 = calendar1.getTimeInMillis(); + if (l1 > l) { + PendingIntent pendingIntent = getPendingIntent(str1, str2, str3, str4, str5, str6, str7); + AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); + } } + }catch (Exception e){ + e.printStackTrace(); + ICLogger.e(e.getMessage(),e); } } cursor1.close(); @@ -217,29 +227,35 @@ public class ContextProxy { long l = System.currentTimeMillis(); for (Alarm alarm : paramArrayList) { long l1 = l; + if ("ON".equals(alarm.status)) { - int i = Integer.parseInt(alarm.time.substring(2, 4)); - int j = Integer.parseInt(alarm.time.substring(5, 7)); - calendar.set(Calendar.HOUR_OF_DAY, i); - calendar.set(Calendar.MINUTE, j); - char[] arrayOfChar = alarm.week.toCharArray(); - i = arrayOfChar.length; - j = 1; - while (true) { - l1 = l; - if (j < i) { - c = ( char)(arrayOfChar[j] - '/'); - calendar.set(Calendar.DAY_OF_WEEK, c); - long l2 = calendar.getTimeInMillis(); - l1 = l2; - if (l2 <= l) - l1 = l2 + ONE_WEEK; - PendingIntent pendingIntent = getPendingIntent(alarm.time, alarm.week, alarm.ring, alarm.name, c); - AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); - j++; - continue; + try { + int i = Integer.parseInt(alarm.time.substring(2, 4)); + int j = Integer.parseInt(alarm.time.substring(5, 7)); + calendar.set(Calendar.HOUR_OF_DAY, i); + calendar.set(Calendar.MINUTE, j); + char[] arrayOfChar = alarm.week.toCharArray(); + i = arrayOfChar.length; + j = 1; + while (true) { + l1 = l; + if (j < i) { + c = (char) (arrayOfChar[j] - '/'); + calendar.set(Calendar.DAY_OF_WEEK, c); + long l2 = calendar.getTimeInMillis(); + l1 = l2; + if (l2 <= l) + l1 = l2 + ONE_WEEK; + PendingIntent pendingIntent = getPendingIntent(alarm.time, alarm.week, alarm.ring, alarm.name, c); + AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); + j++; + continue; + } + break; } - break; + }catch (Exception e){ + e.printStackTrace(); + ICLogger.e(e.getMessage(),e); } } l = l1; @@ -273,20 +289,25 @@ public class ContextProxy { long l = System.currentTimeMillis(); calendar.set(Calendar.SECOND, 0); if (str1 != null) { - String str8 = str1.substring(0, 4); - String str9 = str1.substring(4, 6); - String str10 = str1.substring(6, 8); - String str11 = str1.substring(8, 10); - String str12 = str1.substring(10, 12); - calendar.set(Calendar.YEAR, Integer.parseInt(str8)); - calendar.set(Calendar.MONTH, Integer.parseInt(str9) - 1); - calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(str10)); - calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(str11)); - calendar.set(Calendar.MINUTE, Integer.parseInt(str12)); - long l1 = calendar.getTimeInMillis(); - if (l1 >= l) { - PendingIntent pendingIntent = getPendingIntent(str1, str2, str3, str4, str5, str6, str7); - AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); + try { + String str8 = str1.substring(0, 4); + String str9 = str1.substring(4, 6); + String str10 = str1.substring(6, 8); + String str11 = str1.substring(8, 10); + String str12 = str1.substring(10, 12); + calendar.set(Calendar.YEAR, Integer.parseInt(str8)); + calendar.set(Calendar.MONTH, Integer.parseInt(str9) - 1); + calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(str10)); + calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(str11)); + calendar.set(Calendar.MINUTE, Integer.parseInt(str12)); + long l1 = calendar.getTimeInMillis(); + if (l1 >= l) { + PendingIntent pendingIntent = getPendingIntent(str1, str2, str3, str4, str5, str6, str7); + AlarmHelper.setAlarm(this.alarmManager, l1, pendingIntent); + } + }catch (Exception e){ + e.printStackTrace(); + ICLogger.e(e.getMessage(),e); } } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/Util.java b/app/src/main/java/com/enqualcomm/support/utils/Util.java index d95ef1db..7c67a579 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/Util.java +++ b/app/src/main/java/com/enqualcomm/support/utils/Util.java @@ -271,8 +271,9 @@ public class Util { } return ret; } - public static boolean isNumeric(String str){ - Pattern pattern = Pattern.compile("[0-9]*"); + + public static boolean isNumeric(String str){ + Pattern pattern = Pattern.compile("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); Matcher isNum = pattern.matcher(str); if( !isNum.matches() ){ return false; diff --git a/app/src/main/java/com/ic/protocols/protocol_beehome.java b/app/src/main/java/com/ic/protocols/protocol_beehome.java index 403661d9..9c5b3b1c 100644 --- a/app/src/main/java/com/ic/protocols/protocol_beehome.java +++ b/app/src/main/java/com/ic/protocols/protocol_beehome.java @@ -322,22 +322,26 @@ public class protocol_beehome { String[] msg=cmd.split(CMDSPLIT); if (msg.length>=6){ - Name=msg[1]; - appendIndex=msg[2]; - packetCount= Integer.parseInt(msg[3]); - currentId= Integer.parseInt(msg[4]); - packetLen= Integer.parseInt(msg[5]); - - StringBuffer stringBuffer=new StringBuffer(); - stringBuffer.append("getBP28AmrLen name = ").append(Name) - .append(",appendIndex = ").append(appendIndex) - .append(",packetCount = ").append(packetCount) - .append(",currentId = ").append(currentId) - .append(",packetLen = ").append(packetLen); - - - log( stringBuffer.toString()); - return packetLen; + try { + Name = msg[1]; + appendIndex = msg[2]; + packetCount = Integer.parseInt(msg[3]); + currentId = Integer.parseInt(msg[4]); + packetLen = Integer.parseInt(msg[5]); + + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("getBP28AmrLen name = ").append(Name) + .append(",appendIndex = ").append(appendIndex) + .append(",packetCount = ").append(packetCount) + .append(",currentId = ").append(currentId) + .append(",packetLen = ").append(packetLen); + + + log(stringBuffer.toString()); + return packetLen; + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("getBP28AmrLen","format Error"); @@ -360,21 +364,24 @@ public class protocol_beehome { log("handleBP00", "Set Datetime " + msg[1]); log("handleBP00", "Set TimeZone " + msg[2]); -// Date datetime= TimeUtil.parseDatetiime(msg[1]); -// int timezone=Integer.parseInt(msg[2]); -// if (datetime!=null){ -// ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); -// TimeUtil.setTimeZone(timezone); -// -// -// ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); -// TimeUtil.setSysDateTime(runtime.getContextProxy().context,datetime,timezone); -// ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); -// -// } + try { + Date datetime = TimeUtil.parseDatetiime(msg[1]); + int timezone = Integer.parseInt(msg[2]); + if (datetime != null) { + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + TimeUtil.setTimeZone(timezone); + + + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + TimeUtil.setSysDateTime(runtime.getContextProxy().context, datetime, timezone); + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + + } // Set Datetime 20200505112734 // Set TimeZone 8 - + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("handleBP00","format Error"); } @@ -609,8 +616,12 @@ public class protocol_beehome { String strSex=list[6]; connection.send(APJZ(index,strBPH,strBPL,strAge,strSex)); - runtime.getHRS().setXY_Ref(Integer.parseInt(strBPH),Integer.parseInt(strBPL),Integer.parseInt(strAge),Integer.parseInt(strSex)); - ICLogger.i("Handle BPJZ IMEI "+imei+",index "+index+", BPH "+strBPH+", BPL "+strBPL+", Age "+ strAge +", Sex "+ (strSex.equals("1")?"男":"女")); + try { + runtime.getHRS().setXY_Ref(Integer.parseInt(strBPH), Integer.parseInt(strBPL), Integer.parseInt(strAge), Integer.parseInt(strSex)); + ICLogger.i("Handle BPJZ IMEI " + imei + ",index " + index + ", BPH " + strBPH + ", BPL " + strBPL + ", Age " + strAge + ", Sex " + (strSex.equals("1") ? "男" : "女")); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BPXY format error!"); } @@ -843,68 +854,71 @@ public class protocol_beehome { String[] datalist= cmd.split("@"); ArrayList alarmlist=new ArrayList<>(); if (datalist.length >0){ - for (int i =0 ; i< datalist.length;i++){ - String [] cmdarglist=datalist[i].split(","); - - if (i == 0){ - if (cmdarglist.length == 9){ - imei=cmdarglist[1]; - cmdindex=cmdarglist[2]; - all_alarmswitch=Integer.parseInt(cmdarglist[3]); - alarmcount=Integer.parseInt(cmdarglist[4]); - alarmtime=cmdarglist[5]; - repeat=cmdarglist[6]; - alarmswitch=Integer.parseInt(cmdarglist[7]); - alarmtype = Integer.parseInt(cmdarglist[8]); - log(new StringBuilder("imei ").append(imei) - .append(", cmdindex ").append(cmdindex) - .append(", allswitch=").append(all_alarmswitch) - .append(", all alarm count=").append(alarmcount) - .toString() - ); - - log(new StringBuilder("alarmtime ").append(alarmtime) - .append(", relpeat ").append(repeat) - .append(", switch=").append(alarmswitch) - .append(", alarmtype=").append(alarmtype) - .toString() - ); - alarmlist.add(new Alarm("ST"+alarmtime.substring(0,2)+"."+alarmtime.substring(2),"W"+repeat,"CON",alarmswitch==1?"ON":"OFF","闹铃")); - - }else if (cmdarglist.length == 5) { - imei=cmdarglist[1]; - cmdindex=cmdarglist[2]; - all_alarmswitch=Integer.parseInt(cmdarglist[3]); - alarmcount=Integer.parseInt(cmdarglist[4]); - }else{ - log("data len is too small!"); - } - }else{ - if (cmdarglist.length == 4){ - alarmtime=cmdarglist[0]; - repeat=cmdarglist[1]; - alarmswitch=Integer.parseInt(cmdarglist[2]); - alarmtype = Integer.parseInt(cmdarglist[3]); - - log(new StringBuilder("set alarmtime ").append(alarmtime) - .append(", relpeat ").append(repeat) - .append(", switch=").append(alarmswitch) - .append(", alarmtype=").append(alarmtype) - .toString() - ); - - alarmlist.add(new Alarm("ST"+alarmtime.substring(0,2)+"."+alarmtime.substring(2),"W"+repeat,"CON",alarmswitch==1?"ON":"OFF","闹铃")); - - }else{ - log("data len is too small!"); - } - - } - }//循环获取alarm数据结束 - runtime.getDbHelper().saveAlarm(alarmlist); + try { + for (int i = 0; i < datalist.length; i++) { + String[] cmdarglist = datalist[i].split(","); + + if (i == 0) { + if (cmdarglist.length == 9) { + imei = cmdarglist[1]; + cmdindex = cmdarglist[2]; + all_alarmswitch = Integer.parseInt(cmdarglist[3]); + alarmcount = Integer.parseInt(cmdarglist[4]); + alarmtime = cmdarglist[5]; + repeat = cmdarglist[6]; + alarmswitch = Integer.parseInt(cmdarglist[7]); + alarmtype = Integer.parseInt(cmdarglist[8]); + log(new StringBuilder("imei ").append(imei) + .append(", cmdindex ").append(cmdindex) + .append(", allswitch=").append(all_alarmswitch) + .append(", all alarm count=").append(alarmcount) + .toString() + ); + + log(new StringBuilder("alarmtime ").append(alarmtime) + .append(", relpeat ").append(repeat) + .append(", switch=").append(alarmswitch) + .append(", alarmtype=").append(alarmtype) + .toString() + ); + alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); + + } else if (cmdarglist.length == 5) { + imei = cmdarglist[1]; + cmdindex = cmdarglist[2]; + all_alarmswitch = Integer.parseInt(cmdarglist[3]); + alarmcount = Integer.parseInt(cmdarglist[4]); + } else { + log("data len is too small!"); + } + } else { + if (cmdarglist.length == 4) { + alarmtime = cmdarglist[0]; + repeat = cmdarglist[1]; + alarmswitch = Integer.parseInt(cmdarglist[2]); + alarmtype = Integer.parseInt(cmdarglist[3]); + + log(new StringBuilder("set alarmtime ").append(alarmtime) + .append(", relpeat ").append(repeat) + .append(", switch=").append(alarmswitch) + .append(", alarmtype=").append(alarmtype) + .toString() + ); + + alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); + + } else { + log("data len is too small!"); + } - //do clean and set alarm things + } + }//循环获取alarm数据结束 + runtime.getDbHelper().saveAlarm(alarmlist); + //do clean and set alarm things + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } //IWBP85,867155030002145,410385,1,0,# @@ -978,18 +992,21 @@ public class protocol_beehome { //1:表示服务器接受数据成功,0表示服务器接受数据失败 String[] cmdlist=cmd.split(CMDSPLIT); if (cmdlist.length==5){ - String time=cmdlist[1]; - int packetCount=Integer.parseInt(cmdlist[2]); - int packetIndex=Integer.parseInt(cmdlist[3]); - int receiveSuccess=Integer.parseInt(cmdlist[4]); - ICLogger.i("服务器在"+time+" 收到语音 "+packetIndex+"/"+packetCount+" "+ (receiveSuccess==1?"成功":"失敗")); - if (receiveSuccess == 1){ - //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 - voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + try { + String time = cmdlist[1]; + int packetCount = Integer.parseInt(cmdlist[2]); + int packetIndex = Integer.parseInt(cmdlist[3]); + int receiveSuccess = Integer.parseInt(cmdlist[4]); + ICLogger.i("服务器在" + time + " 收到语音 " + packetIndex + "/" + packetCount + " " + (receiveSuccess == 1 ? "成功" : "失敗")); + if (receiveSuccess == 1) { + //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 + voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + } + //发送消息,再次检查要发送的语音包,确认其发送完毕 + connection.DeliverCMDMessageToSystem("SentVoicePacket", "SentVoicePacket"); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } - //发送消息,再次检查要发送的语音包,确认其发送完毕 - connection.DeliverCMDMessageToSystem("SentVoicePacket","SentVoicePacket"); - }else{ ICLogger.i(" BP07 Format error!"); } @@ -1019,36 +1036,38 @@ public class protocol_beehome { String[] cmdlist=cmd.split(","); if (cmdlist.length == 4){ - - log("work mode "+cmdlist[3]); - int mod=Integer.parseInt(cmdlist[3]); - int Cycle=900; - switch(mod){ - case ICLocation.NORMAL_MOD: - Cycle=900; - break; - case ICLocation.LOWPOWER_MOD: - Cycle=3600; - break; - case ICLocation.EMERGNECY_MOD: - case ICLocation.REALTIME_MOD: - Cycle=60; - break; + try { + int mod = Integer.parseInt(cmdlist[3]); + int Cycle = 900; + switch (mod) { + case ICLocation.NORMAL_MOD: + Cycle = 900; + break; + case ICLocation.LOWPOWER_MOD: + Cycle = 3600; + break; + case ICLocation.EMERGNECY_MOD: + case ICLocation.REALTIME_MOD: + Cycle = 60; + break; - } + } - StringMessage msg=AP33(cmdlist[2],mod); - //设定当前工作模式及循环频率 - connection.send(msg); - log("reply msg "+msg); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,Cycle); - runtime.getLocationInstance().setLocation_cycle(Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + StringMessage msg = AP33(cmdlist[2], mod); + //设定当前工作模式及循环频率 + connection.send(msg); + log("reply msg " + msg); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, Cycle); + runtime.getLocationInstance().setLocation_cycle(Cycle); + runtime.getLocationInstance().setWorkingMod(mod); // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } } @@ -1079,27 +1098,31 @@ public class protocol_beehome { log("work mode "+cmdlist[3]); - int mod=Integer.parseInt(cmdlist[3]); - int Cycle=Integer.parseInt(cmdlist[4]); - int gpson=Integer.parseInt(cmdlist[5]); - - StringMessage msg=AP34(cmdlist[2],mod); - //设定当前工作模式及循环频率 - connection.send(msg); - - if(gpson==1){ - mod=ICLocation.CUSTOM_MOD8_GPS; - }else{ - mod=ICLocation.CUSTOM_MOD8_WIFI; - } - log("reply msg "+msg); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod + ", cycle = "+Cycle+", GPS On= "+gpson); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,Cycle); - runtime.getLocationInstance().setLocation_cycle(Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + try { + int mod = Integer.parseInt(cmdlist[3]); + int Cycle = Integer.parseInt(cmdlist[4]); + int gpson = Integer.parseInt(cmdlist[5]); + + StringMessage msg = AP34(cmdlist[2], mod); + //设定当前工作模式及循环频率 + connection.send(msg); + + if (gpson == 1) { + mod = ICLocation.CUSTOM_MOD8_GPS; + } else { + mod = ICLocation.CUSTOM_MOD8_WIFI; + } + log("reply msg " + msg); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod + ", cycle = " + Cycle + ", GPS On= " + gpson); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, Cycle); + runtime.getLocationInstance().setLocation_cycle(Cycle); + runtime.getLocationInstance().setWorkingMod(mod); // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } } @@ -1281,17 +1304,21 @@ public class protocol_beehome { String[] list=cmd.split(CMDSPLIT); if(list.length==4){ - String index=list[2]; - String time=list[3]; - connection.send(AP15(index)); - ICLogger.i("BP15 , 定位周期="+time+"秒"); - - Config.setLocationMode(runtime.getContextProxy().context, ICLocation.CUSTOM_MOD8_GPS); - Config.setLocationCycle(runtime.getContextProxy().context,Integer.parseInt(time)); - runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(runtime.getContextProxy().context)); - runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(runtime.getContextProxy().context)); - //set AlarmCycle and trigger Location - CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + try { + String index = list[2]; + String time = list[3]; + connection.send(AP15(index)); + ICLogger.i("BP15 , 定位周期=" + time + "秒"); + + Config.setLocationMode(runtime.getContextProxy().context, ICLocation.CUSTOM_MOD8_GPS); + Config.setLocationCycle(runtime.getContextProxy().context, Integer.parseInt(time)); + runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(runtime.getContextProxy().context)); + runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(runtime.getContextProxy().context)); + //set AlarmCycle and trigger Location + CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP15 format error"); } @@ -1350,46 +1377,49 @@ public class protocol_beehome { String[] msg= cmd.split(CMDSPLIT); if (msg.length>=6){ - Name=msg[1]; - appendIndex=msg[2]; - packetCount= Integer.parseInt(msg[3]); - currentId= Integer.parseInt(msg[4]); - packetLen= Integer.parseInt(msg[5]); - packetData= Util.subArray(bytes,msg[0].length()+msg[1].length()+msg[2].length()+msg[3].length()+msg[4].length()+msg[5].length()+6,bytes.length-1); - - StringBuffer stringBuffer=new StringBuffer(); - stringBuffer.append("recv BP28 name = ").append(Name) - .append(",appendIndex = ").append(appendIndex) - .append(",packetCount = ").append(packetCount) - .append(",currentId = ").append(currentId) - .append(",packetLen = ").append(packetLen) - .append(",packetDatalen = ").append(packetData.length); - - log( stringBuffer.toString()); - connection.send(AP28(Name,appendIndex,packetCount,currentId,1)); - voicePacket.getInstance().appendVoice(Name,appendIndex,packetCount,currentId,packetLen,packetData); - log("================"+voicePacket.getInstance().toString()); - if (voicePacket.getInstance().isFinished()) - { - - String dir = Environment.getExternalStorageDirectory()+ "/Android/VoiceCache"; - String amrFilepath=Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(),0,voicePacket.getInstance().getVoicePacketLen(),new File(dir),"receive_"+voicePacket.getInstance().getPacketTime()+".amr"); - ICLogger.i("save Amr file to "+amrFilepath); - voicePacket.getInstance().clearPacket(); - VoiceContent voiceContent=VoiceContent.placeHolderIn(Content.CONTACT_CATEGORY_GROUP,GROUP_ALL,amrFilepath); - - - final Uri uri2 = runtime.getDbHelper().insertMessage( voiceContent); - - //回复UI消息,表示已经接收到 - voiceContent.status = 3; - voiceContent.serverTime = TimeUtil.getSystemTime3(); - voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content)); - runtime.getDbHelper().updateMessage(voiceContent, uri2); + try { + Name = msg[1]; + appendIndex = msg[2]; + packetCount = Integer.parseInt(msg[3]); + currentId = Integer.parseInt(msg[4]); + packetLen = Integer.parseInt(msg[5]); + packetData = Util.subArray(bytes, msg[0].length() + msg[1].length() + msg[2].length() + msg[3].length() + msg[4].length() + msg[5].length() + 6, bytes.length - 1); + + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("recv BP28 name = ").append(Name) + .append(",appendIndex = ").append(appendIndex) + .append(",packetCount = ").append(packetCount) + .append(",currentId = ").append(currentId) + .append(",packetLen = ").append(packetLen) + .append(",packetDatalen = ").append(packetData.length); + + log(stringBuffer.toString()); + connection.send(AP28(Name, appendIndex, packetCount, currentId, 1)); + voicePacket.getInstance().appendVoice(Name, appendIndex, packetCount, currentId, packetLen, packetData); + log("================" + voicePacket.getInstance().toString()); + if (voicePacket.getInstance().isFinished()) { + + String dir = Environment.getExternalStorageDirectory() + "/Android/VoiceCache"; + String amrFilepath = Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(), 0, voicePacket.getInstance().getVoicePacketLen(), new File(dir), "receive_" + voicePacket.getInstance().getPacketTime() + ".amr"); + ICLogger.i("save Amr file to " + amrFilepath); + voicePacket.getInstance().clearPacket(); + VoiceContent voiceContent = VoiceContent.placeHolderIn(Content.CONTACT_CATEGORY_GROUP, GROUP_ALL, amrFilepath); + + + final Uri uri2 = runtime.getDbHelper().insertMessage(voiceContent); + + //回复UI消息,表示已经接收到 + voiceContent.status = 3; + voiceContent.serverTime = TimeUtil.getSystemTime3(); + voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content)); + runtime.getDbHelper().updateMessage(voiceContent, uri2); // runtime.getContextProxy().sendBroadcast(ACTION_IMESSAGE, runtime); - connection.DeliverCMDMessageToSystem("NewVoice", amrFilepath);//通知下面线程状态变化 + connection.DeliverCMDMessageToSystem("NewVoice", amrFilepath);//通知下面线程状态变化 + } + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } }else{ @@ -1512,16 +1542,20 @@ public class protocol_beehome { String[] list=cmd.split(CMDSPLIT); if (list.length==5){ - String index=list[2]; - String type=list[3]; - String cycle=list[4]; - connection.send(AP86(index)); - ICLogger.i("收到服务器指令:设置"+(type.equals("1")?"心率周期 ":"血压周期 ")+cycle+"分钟"); - - //发送重置PPGCycle的广播,会在CoreServer里面执行 - Intent intent = new Intent(); - intent.putExtra("PPGTestCycle",Integer.parseInt(cycle)); - runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START,intent); + try { + String index = list[2]; + String type = list[3]; + String cycle = list[4]; + connection.send(AP86(index)); + ICLogger.i("收到服务器指令:设置" + (type.equals("1") ? "心率周期 " : "血压周期 ") + cycle + "分钟"); + + //发送重置PPGCycle的广播,会在CoreServer里面执行 + Intent intent = new Intent(); + intent.putExtra("PPGTestCycle", Integer.parseInt(cycle)); + runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START, intent); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP86 format error!"); } @@ -1615,16 +1649,19 @@ public class protocol_beehome { //60 : 上传间隔,单位分钟(60分钟上传一次体温,终端收到后立即开始测量一次并重置定时器) String[] list=cmd.split(CMDSPLIT); if (list.length==4){ - String index=list[2]; - String freqstr=list[3]; - int freq=Integer.parseInt(freqstr); - connection.send(APTE(index,freq)); - ICLogger.i("收到服务器指令:测量体温 "+freq+"分钟一次。"); - Config.setTemperatureTestCycle(runtime,freq*60); - CoreService.getInstance().setTempAlarm(); - - TemperatureUtil.doTempTestInThread(); - + try { + String index = list[2]; + String freqstr = list[3]; + int freq = Integer.parseInt(freqstr); + connection.send(APTE(index, freq)); + ICLogger.i("收到服务器指令:测量体温 " + freq + "分钟一次。"); + Config.setTemperatureTestCycle(runtime, freq * 60); + CoreService.getInstance().setTempAlarm(); + + TemperatureUtil.doTempTestInThread(); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } // double wrist_temp,body_temp; // wrist_temp=TemperatureUtil.get_temp_value_adjusted(); // body_temp=TemperatureUtil.getBodyTemp(wrist_temp,26.0f); @@ -1695,19 +1732,23 @@ public class protocol_beehome { connection.send(APX1(index)); - int ppg_adjust,bph_adjust,bpl_adjust,spo2_adjust; - ppg_adjust=Integer.parseInt(strXL); - bph_adjust=Integer.parseInt(strBPH); - bpl_adjust=Integer.parseInt(strBPL); - spo2_adjust=Integer.parseInt(strSpO2); - - runtime.getHRS().setAdjust(ppg_adjust,bph_adjust,bpl_adjust,spo2_adjust); - Config.setPPGAdjust(mRuntime.getContextProxy().context,ppg_adjust); - Config.setBPHAdjust(mRuntime.getContextProxy().context,bph_adjust); - Config.setBPLAdjust(mRuntime.getContextProxy().context,bpl_adjust); - Config.setSPo2Adjust(mRuntime.getContextProxy().context,spo2_adjust); - - ICLogger.i("Handle BPX1 IMEI "+imei+",index "+index+", BPH "+strBPH+", BPL "+strBPL+", PPG "+ strXL +", Sp02 "+ strSpO2); + try { + int ppg_adjust, bph_adjust, bpl_adjust, spo2_adjust; + ppg_adjust = Integer.parseInt(strXL); + bph_adjust = Integer.parseInt(strBPH); + bpl_adjust = Integer.parseInt(strBPL); + spo2_adjust = Integer.parseInt(strSpO2); + + runtime.getHRS().setAdjust(ppg_adjust, bph_adjust, bpl_adjust, spo2_adjust); + Config.setPPGAdjust(mRuntime.getContextProxy().context, ppg_adjust); + Config.setBPHAdjust(mRuntime.getContextProxy().context, bph_adjust); + Config.setBPLAdjust(mRuntime.getContextProxy().context, bpl_adjust); + Config.setSPo2Adjust(mRuntime.getContextProxy().context, spo2_adjust); + + ICLogger.i("Handle BPX1 IMEI " + imei + ",index " + index + ", BPH " + strBPH + ", BPL " + strBPL + ", PPG " + strXL + ", Sp02 " + strSpO2); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BPX1 format error!"); } diff --git a/app/src/main/java/com/ic/protocols/protocol_fzd.java b/app/src/main/java/com/ic/protocols/protocol_fzd.java index b9ae0632..71465fe1 100644 --- a/app/src/main/java/com/ic/protocols/protocol_fzd.java +++ b/app/src/main/java/com/ic/protocols/protocol_fzd.java @@ -347,13 +347,17 @@ public class protocol_fzd { public static void handlePing(Runtime runtime,String data){ // [IC*YYYYYYYYYYYYYYY*LEN*PING,是否绑定(0 表示未绑定,1 表示绑定)] // 实例:[IC*334588000000156*0006*PING,0]或[IC*334588000000156*0006*PING,1] - int bind=Integer.parseInt(data); - if (bind==0){ - ICLogger.i("设备未绑定!"); - runtime.BindingStatus=false; - }else{ - ICLogger.i("设备已绑定!"); - runtime.BindingStatus=true; + try { + int bind = Integer.parseInt(data); + if (bind == 0) { + ICLogger.i("设备未绑定!"); + runtime.BindingStatus = false; + } else { + ICLogger.i("设备已绑定!"); + runtime.BindingStatus = true; + } + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } } @@ -390,7 +394,6 @@ public class protocol_fzd { String date=list[2].trim(); String time=list[1].trim(); Date datetime= TimeUtil.parseDatetiime(date,time); - int timezone; try { @@ -544,16 +547,19 @@ public class protocol_fzd { public void handleUPLOAD(Connection connection,Runtime runtime,String cmd,String data){ connection.send(UPLOAD()); - int timesecond=Integer.parseInt(data); - int mod=runtime.getLocationInstance().getWorkingMod(); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,timesecond); - runtime.getLocationInstance().setLocation_cycle(timesecond); - runtime.getLocationInstance().setWorkingMod(mod); + try { + int timesecond = Integer.parseInt(data); + int mod = runtime.getLocationInstance().getWorkingMod(); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, timesecond); + runtime.getLocationInstance().setLocation_cycle(timesecond); + runtime.getLocationInstance().setWorkingMod(mod); // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 - + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } public static StringMessage heart(int hrt){ @@ -598,13 +604,17 @@ public class protocol_fzd { public void handleWdstart(Connection connection,Runtime runtime ,String data) { connection.send(wdstart()); - int freq=Integer.parseInt(data); + try { + int freq = Integer.parseInt(data); - Config.setTemperatureTestCycle(runtime,freq); - CoreService.getInstance().setTempAlarm(); + Config.setTemperatureTestCycle(runtime, freq); + CoreService.getInstance().setTempAlarm(); - TemperatureUtil.doTempTestInThread(); + TemperatureUtil.doTempTestInThread(); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } // // double wrist_temp,body_temp; // wrist_temp= TemperatureUtil.get_temp_value_adjusted(); diff --git a/app/src/main/java/com/ic/protocols/protocol_ic.java b/app/src/main/java/com/ic/protocols/protocol_ic.java index 9a103dc4..6974d437 100644 --- a/app/src/main/java/com/ic/protocols/protocol_ic.java +++ b/app/src/main/java/com/ic/protocols/protocol_ic.java @@ -359,23 +359,27 @@ public class protocol_ic { String[] msg=cmd.split(CMDSPLIT); if (msg.length>=6){ + try { + Name = msg[1]; + appendIndex = msg[2]; + packetCount = Integer.parseInt(msg[3]); + currentId = Integer.parseInt(msg[4]); + packetLen = Integer.parseInt(msg[5]); + + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("getBP28AmrLen name = ").append(Name) + .append(",appendIndex = ").append(appendIndex) + .append(",packetCount = ").append(packetCount) + .append(",currentId = ").append(currentId) + .append(",packetLen = ").append(packetLen); + + + log(stringBuffer.toString()); + return packetLen; + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } - Name=msg[1]; - appendIndex=msg[2]; - packetCount= Integer.parseInt(msg[3]); - currentId= Integer.parseInt(msg[4]); - packetLen= Integer.parseInt(msg[5]); - - StringBuffer stringBuffer=new StringBuffer(); - stringBuffer.append("getBP28AmrLen name = ").append(Name) - .append(",appendIndex = ").append(appendIndex) - .append(",packetCount = ").append(packetCount) - .append(",currentId = ").append(currentId) - .append(",packetLen = ").append(packetLen); - - - log( stringBuffer.toString()); - return packetLen; }else{ log("getBP28AmrLen","format Error"); @@ -397,18 +401,21 @@ public class protocol_ic { if (msg.length>=3) { log("handleBP00", "Set Datetime " + msg[1]); log("handleBP00", "Set TimeZone " + msg[2]); + try { + Date datetime = TimeUtil.parseDatetiime(msg[1]); + int timezone = Integer.parseInt(msg[2]); + if (datetime != null) { + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + TimeUtil.setTimeZone(timezone); - Date datetime= TimeUtil.parseDatetiime(msg[1]); - int timezone=Integer.parseInt(msg[2]); - if (datetime!=null){ - ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); - TimeUtil.setTimeZone(timezone); + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + TimeUtil.setSysDateTime(runtime.getContextProxy().context, datetime, timezone); + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); - ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); - TimeUtil.setSysDateTime(runtime.getContextProxy().context,datetime,timezone); - ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); - + } + }catch (Exception e) { + ICLogger.e(e.getMessage(), e); } // Set Datetime 20200505112734 // Set TimeZone 8 @@ -638,16 +645,20 @@ public class protocol_ic { //792997:指令流水号 String[] list=cmd.split(CMDSPLIT); if (list.length==7){ - String index=list[2]; - String imei=list[1]; - String strBPH=list[3]; - String strBPL=list[4]; - String strAge=list[5]; - String strSex=list[6]; - - connection.send(APJZ(index,strBPH,strBPL,strAge,strSex)); - runtime.getHRS().setXY_Ref(Integer.parseInt(strBPH),Integer.parseInt(strBPL),Integer.parseInt(strAge),Integer.parseInt(strSex)); - ICLogger.i("Handle BPJZ IMEI "+imei+",index "+index+", BPH "+strBPH+", BPL "+strBPL+", Age "+ strAge +", Sex "+ (strSex.equals("1")?"男":"女")); + try { + String index = list[2]; + String imei = list[1]; + String strBPH = list[3]; + String strBPL = list[4]; + String strAge = list[5]; + String strSex = list[6]; + + connection.send(APJZ(index, strBPH, strBPL, strAge, strSex)); + runtime.getHRS().setXY_Ref(Integer.parseInt(strBPH), Integer.parseInt(strBPL), Integer.parseInt(strAge), Integer.parseInt(strSex)); + ICLogger.i("Handle BPJZ IMEI " + imei + ",index " + index + ", BPH " + strBPH + ", BPL " + strBPL + ", Age " + strAge + ", Sex " + (strSex.equals("1") ? "男" : "女")); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BPXY format error!"); } @@ -895,53 +906,63 @@ public class protocol_ic { if (i == 0){ if (cmdarglist.length == 9){ - imei=cmdarglist[1]; - cmdindex=cmdarglist[2]; - all_alarmswitch=Integer.parseInt(cmdarglist[3]); - alarmcount=Integer.parseInt(cmdarglist[4]); - alarmtime=cmdarglist[5]; - repeat=cmdarglist[6]; - alarmswitch=Integer.parseInt(cmdarglist[7]); - alarmtype = Integer.parseInt(cmdarglist[8]); - log(new StringBuilder("imei ").append(imei) - .append(", cmdindex ").append(cmdindex) - .append(", allswitch=").append(all_alarmswitch) - .append(", all alarm count=").append(alarmcount) - .toString() - ); - - log(new StringBuilder("alarmtime ").append(alarmtime) - .append(", relpeat ").append(repeat) - .append(", switch=").append(alarmswitch) - .append(", alarmtype=").append(alarmtype) - .toString() - ); - alarmlist.add(new Alarm("ST"+alarmtime.substring(0,2)+"."+alarmtime.substring(2),"W"+repeat,"CON",alarmswitch==1?"ON":"OFF","闹铃")); - + try { + imei = cmdarglist[1]; + cmdindex = cmdarglist[2]; + all_alarmswitch = Integer.parseInt(cmdarglist[3]); + alarmcount = Integer.parseInt(cmdarglist[4]); + alarmtime = cmdarglist[5]; + repeat = cmdarglist[6]; + alarmswitch = Integer.parseInt(cmdarglist[7]); + alarmtype = Integer.parseInt(cmdarglist[8]); + log(new StringBuilder("imei ").append(imei) + .append(", cmdindex ").append(cmdindex) + .append(", allswitch=").append(all_alarmswitch) + .append(", all alarm count=").append(alarmcount) + .toString() + ); + + log(new StringBuilder("alarmtime ").append(alarmtime) + .append(", relpeat ").append(repeat) + .append(", switch=").append(alarmswitch) + .append(", alarmtype=").append(alarmtype) + .toString() + ); + alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); + }catch (Exception e) { + ICLogger.e(e.getMessage(), e); + } }else if (cmdarglist.length == 5) { - imei=cmdarglist[1]; - cmdindex=cmdarglist[2]; - all_alarmswitch=Integer.parseInt(cmdarglist[3]); - alarmcount=Integer.parseInt(cmdarglist[4]); + try { + imei = cmdarglist[1]; + cmdindex = cmdarglist[2]; + all_alarmswitch = Integer.parseInt(cmdarglist[3]); + alarmcount = Integer.parseInt(cmdarglist[4]); + }catch (Exception e) { + ICLogger.e(e.getMessage(), e); + } }else{ log("data len is too small!"); } }else{ if (cmdarglist.length == 4){ - alarmtime=cmdarglist[0]; - repeat=cmdarglist[1]; - alarmswitch=Integer.parseInt(cmdarglist[2]); - alarmtype = Integer.parseInt(cmdarglist[3]); - - log(new StringBuilder("set alarmtime ").append(alarmtime) - .append(", relpeat ").append(repeat) - .append(", switch=").append(alarmswitch) - .append(", alarmtype=").append(alarmtype) - .toString() - ); - - alarmlist.add(new Alarm("ST"+alarmtime.substring(0,2)+"."+alarmtime.substring(2),"W"+repeat,"CON",alarmswitch==1?"ON":"OFF","闹铃")); - + try { + alarmtime = cmdarglist[0]; + repeat = cmdarglist[1]; + alarmswitch = Integer.parseInt(cmdarglist[2]); + alarmtype = Integer.parseInt(cmdarglist[3]); + + log(new StringBuilder("set alarmtime ").append(alarmtime) + .append(", relpeat ").append(repeat) + .append(", switch=").append(alarmswitch) + .append(", alarmtype=").append(alarmtype) + .toString() + ); + + alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("data len is too small!"); } @@ -1025,18 +1046,21 @@ public class protocol_ic { //1:表示服务器接受数据成功,0表示服务器接受数据失败 String[] cmdlist=cmd.split(CMDSPLIT); if (cmdlist.length==5){ - String time=cmdlist[1]; - int packetCount=Integer.parseInt(cmdlist[2]); - int packetIndex=Integer.parseInt(cmdlist[3]); - int receiveSuccess=Integer.parseInt(cmdlist[4]); - ICLogger.i("服务器在"+time+" 收到语音 "+packetIndex+"/"+packetCount+" "+ (receiveSuccess==1?"成功":"失敗")); - if (receiveSuccess == 1){ - //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 - voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + try { + String time = cmdlist[1]; + int packetCount = Integer.parseInt(cmdlist[2]); + int packetIndex = Integer.parseInt(cmdlist[3]); + int receiveSuccess = Integer.parseInt(cmdlist[4]); + ICLogger.i("服务器在" + time + " 收到语音 " + packetIndex + "/" + packetCount + " " + (receiveSuccess == 1 ? "成功" : "失敗")); + if (receiveSuccess == 1) { + //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 + voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + } + //发送消息,再次检查要发送的语音包,确认其发送完毕 + connection.DeliverCMDMessageToSystem("SentVoicePacket", "SentVoicePacket"); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } - //发送消息,再次检查要发送的语音包,确认其发送完毕 - connection.DeliverCMDMessageToSystem("SentVoicePacket","SentVoicePacket"); - }else{ ICLogger.i(" BP07 Format error!"); } @@ -1069,31 +1093,35 @@ public class protocol_ic { log("work mode "+cmdlist[3]); - int mod=Integer.parseInt(cmdlist[3]); - int Cycle=900; - switch(mod){ - case ICLocation.NORMAL_MOD: - Cycle=900; - break; - case ICLocation.LOWPOWER_MOD: - Cycle=3600; - break; - case ICLocation.EMERGNECY_MOD: - case ICLocation.REALTIME_MOD: - Cycle=60; - break; + try { + int mod = Integer.parseInt(cmdlist[3]); + int Cycle = 900; + switch (mod) { + case ICLocation.NORMAL_MOD: + Cycle = 900; + break; + case ICLocation.LOWPOWER_MOD: + Cycle = 3600; + break; + case ICLocation.EMERGNECY_MOD: + case ICLocation.REALTIME_MOD: + Cycle = 60; + break; - } + } - StringMessage msg=AP33(cmdlist[2],mod); - //设定当前工作模式及循环频率 - connection.send(msg); - log("reply msg "+msg); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,Cycle); - runtime.getLocationInstance().setLocation_cycle(Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + StringMessage msg = AP33(cmdlist[2], mod); + //设定当前工作模式及循环频率 + connection.send(msg); + log("reply msg " + msg); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, Cycle); + runtime.getLocationInstance().setLocation_cycle(Cycle); + runtime.getLocationInstance().setWorkingMod(mod); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 } @@ -1126,27 +1154,31 @@ public class protocol_ic { log("work mode "+cmdlist[3]); - int mod=Integer.parseInt(cmdlist[3]); - int Cycle=Integer.parseInt(cmdlist[4]); - int gpson=Integer.parseInt(cmdlist[5]); + try { + int mod = Integer.parseInt(cmdlist[3]); + int Cycle = Integer.parseInt(cmdlist[4]); + int gpson = Integer.parseInt(cmdlist[5]); - StringMessage msg=AP34(cmdlist[2],mod); - //设定当前工作模式及循环频率 - connection.send(msg); + StringMessage msg = AP34(cmdlist[2], mod); + //设定当前工作模式及循环频率 + connection.send(msg); - if(gpson==1){ - mod=ICLocation.CUSTOM_MOD8_GPS; - }else{ - mod=ICLocation.CUSTOM_MOD8_WIFI; - } - log("reply msg "+msg.isFromCache()); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod + ", cycle = "+Cycle+", GPS On= "+gpson); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,Cycle); - runtime.getLocationInstance().setLocation_cycle(Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + if (gpson == 1) { + mod = ICLocation.CUSTOM_MOD8_GPS; + } else { + mod = ICLocation.CUSTOM_MOD8_WIFI; + } + log("reply msg " + msg.isFromCache()); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod + ", cycle = " + Cycle + ", GPS On= " + gpson); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, Cycle); + runtime.getLocationInstance().setLocation_cycle(Cycle); + runtime.getLocationInstance().setWorkingMod(mod); // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } } @@ -1333,12 +1365,16 @@ public class protocol_ic { connection.send(AP15(index)); ICLogger.i("BP15 , 定位周期="+time+"秒"); - Config.setLocationMode(runtime.getContextProxy().context, ICLocation.CUSTOM_MOD8_GPS); - Config.setLocationCycle(runtime.getContextProxy().context,Integer.parseInt(time)*60); - runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(runtime.getContextProxy().context)); - runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(runtime.getContextProxy().context)); - //set AlarmCycle and trigger Location - CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + try { + Config.setLocationMode(runtime.getContextProxy().context, ICLocation.CUSTOM_MOD8_GPS); + Config.setLocationCycle(runtime.getContextProxy().context, Integer.parseInt(time) * 60); + runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(runtime.getContextProxy().context)); + runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(runtime.getContextProxy().context)); + //set AlarmCycle and trigger Location + CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP15 format error"); } @@ -1397,46 +1433,49 @@ public class protocol_ic { String[] msg= cmd.split(CMDSPLIT); if (msg.length>=6){ - Name=msg[1]; - appendIndex=msg[2]; - packetCount= Integer.parseInt(msg[3]); - currentId= Integer.parseInt(msg[4]); - packetLen= Integer.parseInt(msg[5]); - packetData= Util.subArray(bytes,msg[0].length()+msg[1].length()+msg[2].length()+msg[3].length()+msg[4].length()+msg[5].length()+6,bytes.length-1); - - StringBuffer stringBuffer=new StringBuffer(); - stringBuffer.append("recv BP28 name = ").append(Name) - .append(",appendIndex = ").append(appendIndex) - .append(",packetCount = ").append(packetCount) - .append(",currentId = ").append(currentId) - .append(",packetLen = ").append(packetLen) - .append(",packetDatalen = ").append(packetData.length); - - log( stringBuffer.toString()); - connection.send(AP28(Name,appendIndex,packetCount,currentId,1)); - voicePacket.getInstance().appendVoice(Name,appendIndex,packetCount,currentId,packetLen,packetData); - log("================"+voicePacket.getInstance().toString()); - if (voicePacket.getInstance().isFinished()) - { - - String dir = Environment.getExternalStorageDirectory()+ "/Android/VoiceCache"; - String amrFilepath=Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(),0,voicePacket.getInstance().getVoicePacketLen(),new File(dir),"receive_"+voicePacket.getInstance().getPacketTime()+".amr"); - ICLogger.i("save Amr file to "+amrFilepath); - voicePacket.getInstance().clearPacket(); - VoiceContent voiceContent=VoiceContent.placeHolderIn(Content.CONTACT_CATEGORY_GROUP,GROUP_ALL,amrFilepath); - - - final Uri uri2 = runtime.getDbHelper().insertMessage( voiceContent); - - //回复UI消息,表示已经接收到 - voiceContent.status = 3; - voiceContent.serverTime = TimeUtil.getSystemTime3(); - voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content)); - runtime.getDbHelper().updateMessage(voiceContent, uri2); + try { + Name = msg[1]; + appendIndex = msg[2]; + packetCount = Integer.parseInt(msg[3]); + currentId = Integer.parseInt(msg[4]); + packetLen = Integer.parseInt(msg[5]); + packetData = Util.subArray(bytes, msg[0].length() + msg[1].length() + msg[2].length() + msg[3].length() + msg[4].length() + msg[5].length() + 6, bytes.length - 1); + + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("recv BP28 name = ").append(Name) + .append(",appendIndex = ").append(appendIndex) + .append(",packetCount = ").append(packetCount) + .append(",currentId = ").append(currentId) + .append(",packetLen = ").append(packetLen) + .append(",packetDatalen = ").append(packetData.length); + + log(stringBuffer.toString()); + connection.send(AP28(Name, appendIndex, packetCount, currentId, 1)); + voicePacket.getInstance().appendVoice(Name, appendIndex, packetCount, currentId, packetLen, packetData); + log("================" + voicePacket.getInstance().toString()); + if (voicePacket.getInstance().isFinished()) { + + String dir = Environment.getExternalStorageDirectory() + "/Android/VoiceCache"; + String amrFilepath = Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(), 0, voicePacket.getInstance().getVoicePacketLen(), new File(dir), "receive_" + voicePacket.getInstance().getPacketTime() + ".amr"); + ICLogger.i("save Amr file to " + amrFilepath); + voicePacket.getInstance().clearPacket(); + VoiceContent voiceContent = VoiceContent.placeHolderIn(Content.CONTACT_CATEGORY_GROUP, GROUP_ALL, amrFilepath); + + + final Uri uri2 = runtime.getDbHelper().insertMessage(voiceContent); + + //回复UI消息,表示已经接收到 + voiceContent.status = 3; + voiceContent.serverTime = TimeUtil.getSystemTime3(); + voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content)); + runtime.getDbHelper().updateMessage(voiceContent, uri2); // runtime.getContextProxy().sendBroadcast(ACTION_IMESSAGE, runtime); - connection.DeliverCMDMessageToSystem("NewVoice", amrFilepath);//通知下面线程状态变化 + connection.DeliverCMDMessageToSystem("NewVoice", amrFilepath);//通知下面线程状态变化 + } + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } }else{ @@ -1591,10 +1630,14 @@ public class protocol_ic { connection.send(AP86(index)); ICLogger.i("收到服务器指令:设置"+(type.equals("1")?"心率周期 ":"血压周期 ")+cycle+"分钟"); - //发送重置PPGCycle的广播,会在CoreServer里面执行 - Intent intent = new Intent(); - intent.putExtra("PPGTestCycle",Integer.parseInt(cycle)); - runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START,intent); + try { + //发送重置PPGCycle的广播,会在CoreServer里面执行 + Intent intent = new Intent(); + intent.putExtra("PPGTestCycle", Integer.parseInt(cycle)); + runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START, intent); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP86 format error!"); } @@ -1691,16 +1734,20 @@ public class protocol_ic { //60 : 上传间隔,单位分钟(60分钟上传一次体温,终端收到后立即开始测量一次并重置定时器) String[] list=cmd.split(CMDSPLIT); if (list.length==4){ - String index=list[2]; - String freqstr=list[3]; - int freq=Integer.parseInt(freqstr); - connection.send(APTE(index,freq)); - ICLogger.i("收到服务器指令:测量体温 "+freq+"分钟一次。"); - Config.setTemperatureTestCycle(runtime,freq*60); - CoreService.getInstance().setTempAlarm(); - - - TemperatureUtil.doTempTestInThread(); + try { + String index = list[2]; + String freqstr = list[3]; + int freq = Integer.parseInt(freqstr); + connection.send(APTE(index, freq)); + ICLogger.i("收到服务器指令:测量体温 " + freq + "分钟一次。"); + Config.setTemperatureTestCycle(runtime, freq * 60); + CoreService.getInstance().setTempAlarm(); + + + TemperatureUtil.doTempTestInThread(); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP89 format error!"); } @@ -1765,24 +1812,27 @@ public class protocol_ic { connection.send(APX1(index)); - int ppg_adjust,bph_adjust,bpl_adjust,spo2_adjust; - ppg_adjust=Integer.parseInt(strXL); - bph_adjust=Integer.parseInt(strBPH); - bpl_adjust=Integer.parseInt(strBPL); - spo2_adjust=Integer.parseInt(strSpO2); - - runtime.getHRS().setAdjust(ppg_adjust,bph_adjust,bpl_adjust,spo2_adjust); - Config.setPPGAdjust(mRuntime.getContextProxy().context,ppg_adjust); - Config.setBPHAdjust(mRuntime.getContextProxy().context,bph_adjust); - Config.setBPLAdjust(mRuntime.getContextProxy().context,bpl_adjust); - Config.setSPo2Adjust(mRuntime.getContextProxy().context,spo2_adjust); - String ShareAdjValue=new StringBuilder().append(ppg_adjust).append(CMDSPLIT) - .append(bph_adjust).append(CMDSPLIT) - .append(bpl_adjust).append(CMDSPLIT) - .append(spo2_adjust).append(CMDSPLIT).toString(); - Config.setPPG_ECG_adjustValue(ShareAdjValue); - ICLogger.i("Handle BPX1 IMEI "+imei+",index "+index+", BPH "+strBPH+", BPL "+strBPL+", PPG "+ strXL +", Sp02 "+ strSpO2 + " , Shared Adjust Value "+ ShareAdjValue); - + try { + int ppg_adjust, bph_adjust, bpl_adjust, spo2_adjust; + ppg_adjust = Integer.parseInt(strXL); + bph_adjust = Integer.parseInt(strBPH); + bpl_adjust = Integer.parseInt(strBPL); + spo2_adjust = Integer.parseInt(strSpO2); + + runtime.getHRS().setAdjust(ppg_adjust, bph_adjust, bpl_adjust, spo2_adjust); + Config.setPPGAdjust(mRuntime.getContextProxy().context, ppg_adjust); + Config.setBPHAdjust(mRuntime.getContextProxy().context, bph_adjust); + Config.setBPLAdjust(mRuntime.getContextProxy().context, bpl_adjust); + Config.setSPo2Adjust(mRuntime.getContextProxy().context, spo2_adjust); + String ShareAdjValue = new StringBuilder().append(ppg_adjust).append(CMDSPLIT) + .append(bph_adjust).append(CMDSPLIT) + .append(bpl_adjust).append(CMDSPLIT) + .append(spo2_adjust).append(CMDSPLIT).toString(); + Config.setPPG_ECG_adjustValue(ShareAdjValue); + ICLogger.i("Handle BPX1 IMEI " + imei + ",index " + index + ", BPH " + strBPH + ", BPL " + strBPL + ", PPG " + strXL + ", Sp02 " + strSpO2 + " , Shared Adjust Value " + ShareAdjValue); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BPX1 format error!"); } @@ -1946,16 +1996,20 @@ public class protocol_ic { String index=list[2]; String msg=list[3]; connection.send(APDE(index)); - if ( Integer.parseInt(msg) == 0) { - ICLogger.i("Handle BPDE index " + index + ", 进入禁止区域 "); - runtime.Fence_Warning_flag=1; - WakeLockUtil.ScreenOnWakeLockTemperary(runtime.getContextProxy().context); - runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_out_wall),2); - }else { - ICLogger.i("Handle BPDE index " + index + ", 离开禁止区域 "); - runtime.Fence_Warning_flag=0; + try { + if (Integer.parseInt(msg) == 0) { + ICLogger.i("Handle BPDE index " + index + ", 进入禁止区域 "); + runtime.Fence_Warning_flag = 1; + WakeLockUtil.ScreenOnWakeLockTemperary(runtime.getContextProxy().context); + runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_out_wall), 2); + } else { + ICLogger.i("Handle BPDE index " + index + ", 离开禁止区域 "); + runtime.Fence_Warning_flag = 0; // Util.ShowToast(runtime,""); - runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_cross_boundary),0); + runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_cross_boundary), 0); + } + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } }else{ ICLogger.i("BPDE format error!"); @@ -1986,21 +2040,24 @@ public class protocol_ic { String[] list=cmd.split(CMDSPLIT); if (list.length==6){ - String index=list[2]; - String switch_on=list[3]; - String min_temp=list[4]; - String max_temp=list[5]; - connection.send(APDG(index)); - if ( Integer.parseInt(switch_on) == 1) { - ICLogger.i("Handle BPDG index " + index + ", 体温报警阈值开 min="+min_temp+",max="+max_temp); - runtime.tempInfo.setBodyTempThreshold(Double.valueOf(max_temp),Double.valueOf(min_temp)); - Config.needTemperature_abnormal_alarm=true; - }else { - ICLogger.i("Handle BPDG index " + index + ", 体温报警阈值关 "); - Config.needTemperature_abnormal_alarm=false; + try { + String index = list[2]; + String switch_on = list[3]; + String min_temp = list[4]; + String max_temp = list[5]; + connection.send(APDG(index)); + if (Integer.parseInt(switch_on) == 1) { + ICLogger.i("Handle BPDG index " + index + ", 体温报警阈值开 min=" + min_temp + ",max=" + max_temp); + runtime.tempInfo.setBodyTempThreshold(Double.valueOf(max_temp), Double.valueOf(min_temp)); + Config.needTemperature_abnormal_alarm = true; + } else { + ICLogger.i("Handle BPDG index " + index + ", 体温报警阈值关 "); + Config.needTemperature_abnormal_alarm = false; + } + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } - }else{ ICLogger.i("BPDG format error!"); } @@ -2076,26 +2133,29 @@ public class protocol_ic { */ String[] cmdlist=cmd.split(CMDSPLIT); if (cmdlist.length==8){ - String time=cmdlist[2]; - String filetype=cmdlist[3]; - String datatype=cmdlist[4]; - String count=cmdlist[5]; - String index=cmdlist[6]; - String success=cmdlist[7]; - int ftype=Integer.parseInt(filetype); - int dtype=Integer.parseInt(datatype); - int packetCount=Integer.parseInt(count); - int packetIndex=Integer.parseInt(index); - int receiveSuccess=Integer.parseInt(success); - ICLogger.i("服务器在收到 index "+time+", 文件类型 "+ftype+",内容类型 "+dtype+" "+packetIndex+"/"+packetCount+" "+ (receiveSuccess==1?"成功":"失敗")); - if (receiveSuccess == 1){ - //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 - voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); - //voicePacket.getInstanceSent().setFileType(ftype,dtype); + try { + String time = cmdlist[2]; + String filetype = cmdlist[3]; + String datatype = cmdlist[4]; + String count = cmdlist[5]; + String index = cmdlist[6]; + String success = cmdlist[7]; + int ftype = Integer.parseInt(filetype); + int dtype = Integer.parseInt(datatype); + int packetCount = Integer.parseInt(count); + int packetIndex = Integer.parseInt(index); + int receiveSuccess = Integer.parseInt(success); + ICLogger.i("服务器在收到 index " + time + ", 文件类型 " + ftype + ",内容类型 " + dtype + " " + packetIndex + "/" + packetCount + " " + (receiveSuccess == 1 ? "成功" : "失敗")); + if (receiveSuccess == 1) { + //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 + voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + //voicePacket.getInstanceSent().setFileType(ftype,dtype); + } + //发送消息,再次检查要发送的语音包,确认其发送完毕 + connection.DeliverCMDMessageToSystem("SentVoicePacket", "SentBPFilePacket"); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } - //发送消息,再次检查要发送的语音包,确认其发送完毕 - connection.DeliverCMDMessageToSystem("SentVoicePacket","SentBPFilePacket"); - }else{ ICLogger.i(" BPTU Format error!"); } diff --git a/app/src/main/java/com/ic/protocols/protocol_jiai.java b/app/src/main/java/com/ic/protocols/protocol_jiai.java index 0b84819c..483a813f 100644 --- a/app/src/main/java/com/ic/protocols/protocol_jiai.java +++ b/app/src/main/java/com/ic/protocols/protocol_jiai.java @@ -315,22 +315,26 @@ public class protocol_jiai { String[] msg=cmd.split(CMDSPLIT); if (msg.length>=6){ - Name=msg[1]; - appendIndex=msg[2]; - packetCount= Integer.parseInt(msg[3]); - currentId= Integer.parseInt(msg[4]); - packetLen= Integer.parseInt(msg[5]); - - StringBuffer stringBuffer=new StringBuffer(); - stringBuffer.append("getBP28AmrLen name = ").append(Name) - .append(",appendIndex = ").append(appendIndex) - .append(",packetCount = ").append(packetCount) - .append(",currentId = ").append(currentId) - .append(",packetLen = ").append(packetLen); - - - log( stringBuffer.toString()); - return packetLen; + try { + Name = msg[1]; + appendIndex = msg[2]; + packetCount = Integer.parseInt(msg[3]); + currentId = Integer.parseInt(msg[4]); + packetLen = Integer.parseInt(msg[5]); + + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("getBP28AmrLen name = ").append(Name) + .append(",appendIndex = ").append(appendIndex) + .append(",packetCount = ").append(packetCount) + .append(",currentId = ").append(currentId) + .append(",packetLen = ").append(packetLen); + + + log(stringBuffer.toString()); + return packetLen; + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("getBP28AmrLen","format Error"); @@ -353,21 +357,24 @@ public class protocol_jiai { log("handleBP00", "Set Datetime " + msg[1]); log("handleBP00", "Set TimeZone " + msg[2]); - Date datetime= TimeUtil.parseDatetiime(msg[1]); - int timezone=Integer.parseInt(msg[2]); - if (datetime!=null){ - ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); - TimeUtil.setTimeZone(timezone); + try { + Date datetime = TimeUtil.parseDatetiime(msg[1]); + int timezone = Integer.parseInt(msg[2]); + if (datetime != null) { + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + TimeUtil.setTimeZone(timezone); - ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); - TimeUtil.setSysDateTime(runtime.getContextProxy().context,datetime,timezone); - ICLogger.i("==="+TimeUtil.getDefaultTimeZone()); + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); + TimeUtil.setSysDateTime(runtime.getContextProxy().context, datetime, timezone); + ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); - } + } // Set Datetime 20200505112734 // Set TimeZone 8 - + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("handleBP00","format Error"); } @@ -598,8 +605,12 @@ public class protocol_jiai { String strSex=list[6]; connection.send(APJZ(index,strBPH,strBPL,strAge,strSex)); - runtime.getHRS().setXY_Ref(Integer.parseInt(strBPH),Integer.parseInt(strBPL),Integer.parseInt(strAge),Integer.parseInt(strSex)); - ICLogger.i("Handle BPJZ IMEI "+imei+",index "+index+", BPH "+strBPH+", BPL "+strBPL+", Age "+ strAge +", Sex "+ (strSex.equals("1")?"男":"女")); + try { + runtime.getHRS().setXY_Ref(Integer.parseInt(strBPH), Integer.parseInt(strBPL), Integer.parseInt(strAge), Integer.parseInt(strSex)); + ICLogger.i("Handle BPJZ IMEI " + imei + ",index " + index + ", BPH " + strBPH + ", BPL " + strBPL + ", Age " + strAge + ", Sex " + (strSex.equals("1") ? "男" : "女")); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BPXY format error!"); } @@ -831,59 +842,73 @@ public class protocol_jiai { String repeat="";// 135表示周一周三周五,使用24小时制 String[] datalist= cmd.split("@"); ArrayList alarmlist=new ArrayList<>(); + + if (datalist.length >0){ + + for (int i =0 ; i< datalist.length;i++){ String [] cmdarglist=datalist[i].split(","); if (i == 0){ if (cmdarglist.length == 9){ - imei=cmdarglist[1]; - cmdindex=cmdarglist[2]; - all_alarmswitch=Integer.parseInt(cmdarglist[3]); - alarmcount=Integer.parseInt(cmdarglist[4]); - alarmtime=cmdarglist[5]; - repeat=cmdarglist[6]; - alarmswitch=Integer.parseInt(cmdarglist[7]); - alarmtype = Integer.parseInt(cmdarglist[8]); - log(new StringBuilder("imei ").append(imei) - .append(", cmdindex ").append(cmdindex) - .append(", allswitch=").append(all_alarmswitch) - .append(", all alarm count=").append(alarmcount) - .toString() - ); - - log(new StringBuilder("alarmtime ").append(alarmtime) - .append(", relpeat ").append(repeat) - .append(", switch=").append(alarmswitch) - .append(", alarmtype=").append(alarmtype) - .toString() - ); - alarmlist.add(new Alarm("ST"+alarmtime.substring(0,2)+"."+alarmtime.substring(2),"W"+repeat,"CON",alarmswitch==1?"ON":"OFF","闹铃")); - + try { + imei = cmdarglist[1]; + cmdindex = cmdarglist[2]; + all_alarmswitch = Integer.parseInt(cmdarglist[3]); + alarmcount = Integer.parseInt(cmdarglist[4]); + alarmtime = cmdarglist[5]; + repeat = cmdarglist[6]; + alarmswitch = Integer.parseInt(cmdarglist[7]); + alarmtype = Integer.parseInt(cmdarglist[8]); + log(new StringBuilder("imei ").append(imei) + .append(", cmdindex ").append(cmdindex) + .append(", allswitch=").append(all_alarmswitch) + .append(", all alarm count=").append(alarmcount) + .toString() + ); + + log(new StringBuilder("alarmtime ").append(alarmtime) + .append(", relpeat ").append(repeat) + .append(", switch=").append(alarmswitch) + .append(", alarmtype=").append(alarmtype) + .toString() + ); + alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else if (cmdarglist.length == 5) { - imei=cmdarglist[1]; - cmdindex=cmdarglist[2]; - all_alarmswitch=Integer.parseInt(cmdarglist[3]); - alarmcount=Integer.parseInt(cmdarglist[4]); + try { + imei = cmdarglist[1]; + cmdindex = cmdarglist[2]; + all_alarmswitch = Integer.parseInt(cmdarglist[3]); + alarmcount = Integer.parseInt(cmdarglist[4]); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("data len is too small!"); } }else{ if (cmdarglist.length == 4){ - alarmtime=cmdarglist[0]; - repeat=cmdarglist[1]; - alarmswitch=Integer.parseInt(cmdarglist[2]); - alarmtype = Integer.parseInt(cmdarglist[3]); - - log(new StringBuilder("set alarmtime ").append(alarmtime) - .append(", relpeat ").append(repeat) - .append(", switch=").append(alarmswitch) - .append(", alarmtype=").append(alarmtype) - .toString() - ); - - alarmlist.add(new Alarm("ST"+alarmtime.substring(0,2)+"."+alarmtime.substring(2),"W"+repeat,"CON",alarmswitch==1?"ON":"OFF","闹铃")); - + try { + alarmtime = cmdarglist[0]; + repeat = cmdarglist[1]; + alarmswitch = Integer.parseInt(cmdarglist[2]); + alarmtype = Integer.parseInt(cmdarglist[3]); + + log(new StringBuilder("set alarmtime ").append(alarmtime) + .append(", relpeat ").append(repeat) + .append(", switch=").append(alarmswitch) + .append(", alarmtype=").append(alarmtype) + .toString() + ); + + alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ log("data len is too small!"); } @@ -967,18 +992,21 @@ public class protocol_jiai { //1:表示服务器接受数据成功,0表示服务器接受数据失败 String[] cmdlist=cmd.split(CMDSPLIT); if (cmdlist.length==5){ - String time=cmdlist[1]; - int packetCount=Integer.parseInt(cmdlist[2]); - int packetIndex=Integer.parseInt(cmdlist[3]); - int receiveSuccess=Integer.parseInt(cmdlist[4]); - ICLogger.i("服务器在"+time+" 收到语音 "+packetIndex+"/"+packetCount+" "+ (receiveSuccess==1?"成功":"失敗")); - if (receiveSuccess == 1){ - //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 - voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + try { + String time = cmdlist[1]; + int packetCount = Integer.parseInt(cmdlist[2]); + int packetIndex = Integer.parseInt(cmdlist[3]); + int receiveSuccess = Integer.parseInt(cmdlist[4]); + ICLogger.i("服务器在" + time + " 收到语音 " + packetIndex + "/" + packetCount + " " + (receiveSuccess == 1 ? "成功" : "失敗")); + if (receiveSuccess == 1) { + //如果服务器接收 语音成功,则设置下一个要发送的语音包Index,当index == packetCount的时候表示所有包发送完毕,停止继续发送 + voicePacket.getInstanceSent().setCurrentIndexToSent(packetIndex); + } + //发送消息,再次检查要发送的语音包,确认其发送完毕 + connection.DeliverCMDMessageToSystem("SentVoicePacket", "SentVoicePacket"); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } - //发送消息,再次检查要发送的语音包,确认其发送完毕 - connection.DeliverCMDMessageToSystem("SentVoicePacket","SentVoicePacket"); - }else{ ICLogger.i(" BP07 Format error!"); } @@ -1009,35 +1037,38 @@ public class protocol_jiai { String[] cmdlist=cmd.split(","); if (cmdlist.length == 4){ + try { + log("work mode " + cmdlist[3]); + int mod = Integer.parseInt(cmdlist[3]); + int Cycle = 900; + switch (mod) { + case ICLocation.NORMAL_MOD: + Cycle = 900; + break; + case ICLocation.LOWPOWER_MOD: + Cycle = 3600; + break; + case ICLocation.EMERGNECY_MOD: + case ICLocation.REALTIME_MOD: + Cycle = 60; + break; - log("work mode "+cmdlist[3]); - int mod=Integer.parseInt(cmdlist[3]); - int Cycle=900; - switch(mod){ - case ICLocation.NORMAL_MOD: - Cycle=900; - break; - case ICLocation.LOWPOWER_MOD: - Cycle=3600; - break; - case ICLocation.EMERGNECY_MOD: - case ICLocation.REALTIME_MOD: - Cycle=60; - break; - - } + } - StringMessage msg=AP33(cmdlist[2],mod); - //设定当前工作模式及循环频率 - connection.send(msg); - log("reply msg "+msg.isFromCache()); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,Cycle); - runtime.getLocationInstance().setLocation_cycle(Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + StringMessage msg = AP33(cmdlist[2], mod); + //设定当前工作模式及循环频率 + connection.send(msg); + log("reply msg " + msg.isFromCache()); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, Cycle); + runtime.getLocationInstance().setLocation_cycle(Cycle); + runtime.getLocationInstance().setWorkingMod(mod); // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } } @@ -1068,27 +1099,31 @@ public class protocol_jiai { log("work mode "+cmdlist[3]); - int mod=Integer.parseInt(cmdlist[3]); - int Cycle=Integer.parseInt(cmdlist[4]); - int gpson=Integer.parseInt(cmdlist[5]); - - StringMessage msg=AP34(cmdlist[2],mod); - //设定当前工作模式及循环频率 - connection.send(msg); - - if(gpson==1){ - mod=ICLocation.CUSTOM_MOD8_GPS; - }else{ - mod=ICLocation.CUSTOM_MOD8_WIFI; - } - log("reply msg "+msg.isFromCache()); - log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod + ", cycle = "+Cycle+", GPS On= "+gpson); - Config.setLocationMode(runtime.getContextProxy().context,mod); - Config.setLocationCycle(runtime.getContextProxy().context,Cycle); - runtime.getLocationInstance().setLocation_cycle(Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + try { + int mod = Integer.parseInt(cmdlist[3]); + int Cycle = Integer.parseInt(cmdlist[4]); + int gpson = Integer.parseInt(cmdlist[5]); + + StringMessage msg = AP34(cmdlist[2], mod); + //设定当前工作模式及循环频率 + connection.send(msg); + + if (gpson == 1) { + mod = ICLocation.CUSTOM_MOD8_GPS; + } else { + mod = ICLocation.CUSTOM_MOD8_WIFI; + } + log("reply msg " + msg.isFromCache()); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod + ", cycle = " + Cycle + ", GPS On= " + gpson); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, Cycle); + runtime.getLocationInstance().setLocation_cycle(Cycle); + runtime.getLocationInstance().setWorkingMod(mod); // CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } } } @@ -1309,17 +1344,21 @@ public static StringMessage AP50(Runtime ds){ String[] list=cmd.split(CMDSPLIT); if(list.length==4){ - String index=list[2]; - String time=list[3]; - connection.send(AP15(index)); - ICLogger.i("BP15 , 定位周期="+time+"秒"); - - Config.setLocationMode(runtime.getContextProxy().context, ICLocation.CUSTOM_MOD8_GPS); - Config.setLocationCycle(runtime.getContextProxy().context,Integer.parseInt(time)); - runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(runtime.getContextProxy().context)); - runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(runtime.getContextProxy().context)); - //set AlarmCycle and trigger Location - CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + try { + String index = list[2]; + String time = list[3]; + connection.send(AP15(index)); + ICLogger.i("BP15 , 定位周期=" + time + "秒"); + + Config.setLocationMode(runtime.getContextProxy().context, ICLocation.CUSTOM_MOD8_GPS); + Config.setLocationCycle(runtime.getContextProxy().context, Integer.parseInt(time)); + runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(runtime.getContextProxy().context)); + runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(runtime.getContextProxy().context)); + //set AlarmCycle and trigger Location + CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP15 format error"); } @@ -1377,49 +1416,50 @@ public static StringMessage AP50(Runtime ds){ String[] msg= cmd.split(CMDSPLIT); if (msg.length>=6){ - - Name=msg[1]; - appendIndex=msg[2]; - packetCount= Integer.parseInt(msg[3]); - currentId= Integer.parseInt(msg[4]); - packetLen= Integer.parseInt(msg[5]); - packetData= Util.subArray(bytes,msg[0].length()+msg[1].length()+msg[2].length()+msg[3].length()+msg[4].length()+msg[5].length()+6,bytes.length-1); - - StringBuffer stringBuffer=new StringBuffer(); - stringBuffer.append("recv BP28 name = ").append(Name) - .append(",appendIndex = ").append(appendIndex) - .append(",packetCount = ").append(packetCount) - .append(",currentId = ").append(currentId) - .append(",packetLen = ").append(packetLen) - .append(",packetDatalen = ").append(packetData.length); - - log( stringBuffer.toString()); - connection.send(AP28(Name,appendIndex,packetCount,currentId,1)); - voicePacket.getInstance().appendVoice(Name,appendIndex,packetCount,currentId,packetLen,packetData); - log("================"+voicePacket.getInstance().toString()); - if (voicePacket.getInstance().isFinished()) - { - - String dir = Environment.getExternalStorageDirectory()+ "/Android/VoiceCache"; - String amrFilepath=Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(),0,voicePacket.getInstance().getVoicePacketLen(),new File(dir),"receive_"+voicePacket.getInstance().getPacketTime()+".amr"); - ICLogger.i("save Amr file to "+amrFilepath); - voicePacket.getInstance().clearPacket(); - VoiceContent voiceContent=VoiceContent.placeHolderIn(Content.CONTACT_CATEGORY_GROUP,GROUP_ALL,amrFilepath); - - - final Uri uri2 = runtime.getDbHelper().insertMessage( voiceContent); - - //回复UI消息,表示已经接收到 - voiceContent.status = 3; - voiceContent.serverTime = TimeUtil.getSystemTime3(); - voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content)); - runtime.getDbHelper().updateMessage(voiceContent, uri2); + try { + Name = msg[1]; + appendIndex = msg[2]; + packetCount = Integer.parseInt(msg[3]); + currentId = Integer.parseInt(msg[4]); + packetLen = Integer.parseInt(msg[5]); + packetData = Util.subArray(bytes, msg[0].length() + msg[1].length() + msg[2].length() + msg[3].length() + msg[4].length() + msg[5].length() + 6, bytes.length - 1); + + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("recv BP28 name = ").append(Name) + .append(",appendIndex = ").append(appendIndex) + .append(",packetCount = ").append(packetCount) + .append(",currentId = ").append(currentId) + .append(",packetLen = ").append(packetLen) + .append(",packetDatalen = ").append(packetData.length); + + log(stringBuffer.toString()); + connection.send(AP28(Name, appendIndex, packetCount, currentId, 1)); + voicePacket.getInstance().appendVoice(Name, appendIndex, packetCount, currentId, packetLen, packetData); + log("================" + voicePacket.getInstance().toString()); + if (voicePacket.getInstance().isFinished()) { + + String dir = Environment.getExternalStorageDirectory() + "/Android/VoiceCache"; + String amrFilepath = Util.saveFile(voicePacket.getInstance().getVoicePacketBytes(), 0, voicePacket.getInstance().getVoicePacketLen(), new File(dir), "receive_" + voicePacket.getInstance().getPacketTime() + ".amr"); + ICLogger.i("save Amr file to " + amrFilepath); + voicePacket.getInstance().clearPacket(); + VoiceContent voiceContent = VoiceContent.placeHolderIn(Content.CONTACT_CATEGORY_GROUP, GROUP_ALL, amrFilepath); + + + final Uri uri2 = runtime.getDbHelper().insertMessage(voiceContent); + + //回复UI消息,表示已经接收到 + voiceContent.status = 3; + voiceContent.serverTime = TimeUtil.getSystemTime3(); + voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content)); + runtime.getDbHelper().updateMessage(voiceContent, uri2); // runtime.getContextProxy().sendBroadcast(ACTION_IMESSAGE, runtime); - connection.DeliverCMDMessageToSystem("NewVoice", amrFilepath);//通知下面线程状态变化 + connection.DeliverCMDMessageToSystem("NewVoice", amrFilepath);//通知下面线程状态变化 + } + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); } - }else{ log("handleBP28","format Error"); // connection.send(genStringMessage("AP28",AP28(Name,appendIndex,packetCount,currentId,0))); @@ -1506,16 +1546,20 @@ public static StringMessage AP50(Runtime ds){ String[] list=cmd.split(CMDSPLIT); if (list.length==5){ - String index=list[2]; - String type=list[3]; - String cycle=list[4]; - connection.send(AP86(index)); - ICLogger.i("收到服务器指令:设置"+(type.equals("1")?"心率周期 ":"血压周期 ")+cycle+"分钟"); - - //发送重置PPGCycle的广播,会在CoreServer里面执行 - Intent intent = new Intent(); - intent.putExtra("PPGTestCycle",Integer.parseInt(cycle)); - runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START,intent); + try { + String index = list[2]; + String type = list[3]; + String cycle = list[4]; + connection.send(AP86(index)); + ICLogger.i("收到服务器指令:设置" + (type.equals("1") ? "心率周期 " : "血压周期 ") + cycle + "分钟"); + + //发送重置PPGCycle的广播,会在CoreServer里面执行 + Intent intent = new Intent(); + intent.putExtra("PPGTestCycle", Integer.parseInt(cycle)); + runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START, intent); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else{ ICLogger.i("BP86 format error!"); } diff --git a/app/src/main/java/com/ic/protocols/protocol_mqtt.java b/app/src/main/java/com/ic/protocols/protocol_mqtt.java index 16473013..f2dfeb77 100644 --- a/app/src/main/java/com/ic/protocols/protocol_mqtt.java +++ b/app/src/main/java/com/ic/protocols/protocol_mqtt.java @@ -471,14 +471,18 @@ public class protocol_mqtt { connection.send(UPLOAD(runtime)); String[] list=data.split(CMDSPLIT); if (TextUtils.isDigitsOnly(list[1].trim())) { - int timesecond = Integer.parseInt(list[1].trim()); - int mod = runtime.getLocationInstance().getWorkingMod(); - log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod +" cycle "+timesecond); - Config.setLocationMode(runtime.getContextProxy().context, mod); - Config.setLocationCycle(runtime.getContextProxy().context, timesecond); - runtime.getLocationInstance().setLocation_cycle(timesecond); - runtime.getLocationInstance().setWorkingMod(mod); - CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + try { + int timesecond = Integer.parseInt(list[1].trim()); + int mod = runtime.getLocationInstance().getWorkingMod(); + log("LOCATION_MODE " + LOCATION_MODE + " mod " + mod + " cycle " + timesecond); + Config.setLocationMode(runtime.getContextProxy().context, mod); + Config.setLocationCycle(runtime.getContextProxy().context, timesecond); + runtime.getLocationInstance().setLocation_cycle(timesecond); + runtime.getLocationInstance().setWorkingMod(mod); + CoreService.getInstance().setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 }else{ ICLogger.i("UPLOAD format error!"); @@ -563,13 +567,16 @@ public class protocol_mqtt { if (list.length==2){ String cycle=list[1]; if (TextUtils.isDigitsOnly(cycle.trim())){ - int cycle_int=Integer.parseInt(cycle.trim()); - ICLogger.i("收到服务器指令:设置体温上传频率 "+cycle+"秒"); - - Config.setTemperatureTestCycle(runtime,cycle_int); - CoreService.getInstance().setTempAlarm(); - TemperatureUtil.doTempTestInThread(); - + try { + int cycle_int = Integer.parseInt(cycle.trim()); + ICLogger.i("收到服务器指令:设置体温上传频率 " + cycle + "秒"); + + Config.setTemperatureTestCycle(runtime, cycle_int); + CoreService.getInstance().setTempAlarm(); + TemperatureUtil.doTempTestInThread(); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else { ICLogger.i("wdstart Format Error!"); @@ -601,13 +608,17 @@ public class protocol_mqtt { if (list.length==2){ String cycle=list[1]; if (TextUtils.isDigitsOnly(cycle.trim())){ - int cycle_int=Integer.parseInt(cycle.trim()); - ICLogger.i("收到服务器指令:设置心率血压周期 "+cycle+"秒"+cycle_int/60+"分钟"); - - //发送重置PPGCycle的广播,会在CoreServer里面执行 - Intent intent = new Intent(); - intent.putExtra("PPGTestCycle",cycle_int/60); - runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START,intent); + try { + int cycle_int = Integer.parseInt(cycle.trim()); + ICLogger.i("收到服务器指令:设置心率血压周期 " + cycle + "秒" + cycle_int / 60 + "分钟"); + + //发送重置PPGCycle的广播,会在CoreServer里面执行 + Intent intent = new Intent(); + intent.putExtra("PPGTestCycle", cycle_int / 60); + runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START, intent); + }catch (Exception e){ + ICLogger.e(e.getMessage(),e); + } }else { ICLogger.i("Hrtstart Format Error!");