package com.ic.protocols;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
+import android.support.v4.app.ActivityCompat;
import android.telephony.TelephonyManager;
import com.enqualcomm.support.Config;
import static com.enqualcomm.support.Constants.FROM_SERVER;
import static com.enqualcomm.support.bean.Contact.GROUP_ALL;
+import static com.ic.protocols.protocol_anan.CMD_TYPE.AP32;
import static java.lang.Math.abs;
/**
AP31/*关机上行*/,
AP12/*SOS名单上行*/,
APXL/*血压心率 上行*/,
- APXY, AP88, AP15, AP84, AP14/*白名单电话本上行*/
+ APXY,
+ AP88,
+ AP15,
+ AP84,
+ AP14/*白名单电话本上行*/,
+ AP32/*拨号上行*/
}
cmdMap.put(CMD_TYPE.AP28, "AP28");
cmdMap.put(CMD_TYPE.AP17, "AP17");
cmdMap.put(CMD_TYPE.AP18, "AP18");
+ cmdMap.put(AP32, "AP32");
}
String last_inCompletecmd = "";
String cmd_msgbuf = new String(bytes);
ICLogger.d("bytes.size " + bytes.length);
-// cmdbuf.append(cmd_msgbuf);
cmdbuf.append(cmd_msgbuf);
ICLogger.d("cmdbuf.size " + cmdbuf.length() + " " + cmdbuf.toString());
- /*
+ /*
如果不是 #结尾,就认为 接收数据不全,置位。
*/
if (cmdbuf.toString().endsWith(CMDEND)) {
iscmdComplete = true;
}
- String[] cmdlist = cmd_msgbuf.split(CMDEND);
- int listLen = cmdlist.length;
+ String[] cmdList = cmd_msgbuf.split(CMDEND);
+ int listLen = cmdList.length;
ICLogger.d("listLen " + listLen);
/*
如果解析出来的cmdlist不是空,且数据不是完整cmd则保留 最后一条数据到last_inCompletecmd
*/
- if (cmdlist.length > 0 && !iscmdComplete) {
+ if (cmdList.length > 0 && !iscmdComplete) {
listLen -= 1;
- last_inCompletecmd = cmdlist[listLen];
+ last_inCompletecmd = cmdList[listLen];
ICLogger.d("cmd not complete , " + last_inCompletecmd);
}
for (int i = 0; i < listLen; i++) {
for (CMD_TYPE key : cmdMap.keySet()) {
- if (cmdlist[i].startsWith(CMDHEADER + cmdMap.get(key))) {
+ if (cmdList[i].startsWith(CMDHEADER + cmdMap.get(key))) {
ICLogger.d("found cmd keyid=" + key +
" ,keyname=" + cmdMap.get(key)
- + " , " + cmdlist[i]);
+ + " , " + cmdList[i]);
if (key == CMD_TYPE.BP28) {
//如果是BP28则 后面的数据是音频,需要保留
- int amrLen = getBP28Amrlen(cmdlist[i]);
+ int amrLen = getBP28Amrlen(cmdList[i]);
if (bytes.length > amrLen) {
- handleCmd(key, cmdlist[i], bytes);
+ handleCmd(key, cmdList[i], bytes);
}
} else {
- handleCmd(key, cmdlist[i]);
+ handleCmd(key, cmdList[i]);
}
}
}
public void handleCmd(CMD_TYPE type, String cmd) {
//普通非二进制命令用此函数处理
- boolean ret = true;
ICLogger.i("handleCmd " + type.name() + " strLen=" + cmd.length());
if (Config.LOG_TOFILE) ICLogger.logToFile("APILog", " recv " + cmd);
switch (type) {
//收到发送的语音包
handleBP07(cmd, mConnection);
break;
+ case BP32:
+ ICLogger.d("收到拨号指令..." + cmd);
+ handleBP32(cmd, mConnection);
+ break;
+ }
+ }
+ private void handleBP32(String cmd, Connection mConnection) {
+ //返回AP32
+ //IWBP32,353456789012345,080835,133xxxxxxxx#
+ String[] split = cmd.split(CMD_SPLIT);
+ if (split.length == 4) {
+ String responseCode = split[2];
+ String phoneNum = split[3];
+ ICLogger.d("response code ==> " + responseCode);
+ ICLogger.d("response phoneNum ==> " + phoneNum);
+ mConnection.send(AP32(responseCode));
+ //拨号
+ Intent intent = new Intent(Intent.ACTION_CALL);
+ intent.setData(Uri.parse("tel:" + phoneNum));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ if (ActivityCompat.checkSelfPermission(mRuntime.getContextProxy().context,
+ Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
+ ICLogger.d("no permission to call...");
+ return;
+ }
+ mRuntime.getContextProxy().context.startActivity(intent);
+ } else {
+ ICLogger.d("format data error");
}
}
+ private static StringMessage AP32(String responseCode) {
+ //IWAP32,080835#
+ return genStringMessage(cmdMap.get(AP32),
+ new StringBuilder(CMDHEADER).append(cmdMap.get(AP32))
+ .append(CMDSPLIT).append(responseCode).append(CMDEND).toString());
+ }
+
public void handleBP07(String cmd, Connection connection) {
-//平台响应: IWBP07,20140818064408,6,1,1#
-//20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒
-//6:语音包分包总数
-//1:当前设备收到的是第几个包
-//1:表示服务器接受数据成功,0表示服务器接受数据失败
+ //平台响应: IWBP07,20140818064408,6,1,1#
+ //20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒
+ //6:语音包分包总数
+ //1:当前设备收到的是第几个包
+ //1:表示服务器接受数据成功,0表示服务器接受数据失败
String[] cmdlist = cmd.split(CMDSPLIT);
if (cmdlist.length == 5) {
try {
public void handleBP84(String cmd, Connection connection) {
-//示例:
+ //示例:
//IWBP84,353456789012345,080835,1#
//说明:
//IW:标识符
public void handleBP18(Connection connection, String cmd) {
// IWBP18,867155030001063,161723
- String[] cmdlist = cmd.split(CMDSPLIT);
- if (cmdlist.length == 3) {
-
- connection.send(AP18(cmdlist[2]));
-
+ String[] cmdList = cmd.split(CMDSPLIT);
+ ICLogger.d("cmdList == > " + cmdList.length);
+ if (cmdList.length == 3) {
+ connection.send(AP18(cmdList[2]));
}
}