//收到SentVoicePacket 表示 有一个VoiceMessage要发送,需要从第0个包开始发送语音分包。
voicePacket voicepacket = voicePacket.getInstanceSent();
if (voicepacket.getCurrentIndexToSent() < voicepacket.getPacketCount()) {
- ICLogger.i("voicepacket " + voicepacket.getName() + " filetype " + voicepacket.getFiletype() + " , datatype " + voicepacket.getDateType() + " " + voicepacket.getPacketTime() + " send " + (voicepacket.getCurrentIndexToSent() + 1) + "/" + voicepacket.getPacketCount());
+ ICLogger.i("voicepacket " + voicepacket.getName()
+ + " filetype " + voicepacket.getFiletype()
+ + " , datatype " + voicepacket.getDateType()
+ + " " + voicepacket.getPacketTime()
+ + " send "
+ + (voicepacket.getCurrentIndexToSent() + 1) + "/"
+ + voicepacket.getPacketCount());
if (mConnection instanceof NettyConnection) {
((NettyConnection) mConnection).sendMsg("RAWPACKET",
- protocolAPIHelper.getVoicePacketItem(voicepacket.getSender(), voicepacket.getDurationHex(), voicepacket.getPacketTime(),
+ protocolAPIHelper.getVoicePacketItem(voicepacket.getSender(),
+ voicepacket.getDurationHex(),
+ voicepacket.getPacketTime(),
voicepacket.getPacketCount(),
(voicepacket.getCurrentIndexToSent() + 1),
voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketLen(),
- voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketData(), voicepacket.getFiletype(), voicepacket.getDateType())
+ voicepacket.getVoicePacketWithIndex(voicepacket.getCurrentIndexToSent()).getPacketData(),
+ voicepacket.getFiletype(),
+ voicepacket.getDateType(),
+ voicepacket.getSender())
);
}
} else {
import android.net.Uri;
import android.os.Handler;
-import com.enqualcomm.support.provider.FZDDatabaseHelper;
-import com.enqualcomm.support.provider.FZDMessageProvider;
+import com.enqualcomm.support.provider.ICDatabaseHelper;
+import com.enqualcomm.support.provider.WeTalkMessageProvider;
import com.enqualcomm.support.utils.ICLogger;
import com.ic.protocols.protocolAPIHelper;
-import com.ic.protocols.protocol_fzd;
public class WeTalkMsgObserver extends ContentObserver {
private final ContentResolver mResolver;
//查询到数据,给到fzd协议上传数据
String lastPathSegment = uri.getLastPathSegment();
ICLogger.d("lastPathSegment == > " + lastPathSegment);
- Cursor query = mResolver.query(Uri.parse(FZDMessageProvider.MESSAGES), null, "_id=?",
+ Cursor query = mResolver.query(Uri.parse(WeTalkMessageProvider.MESSAGES), null, "_id=?",
new String[]{lastPathSegment}, null, null);
if (query != null && query.moveToNext()) {
String content = query.getString(query.getColumnIndex("content"));
//对方的ID,如果这个为null,那么则是群聊
//否则是单聊
String remoteNum = query.getString(query.getColumnIndex("remote_num"));
+ ICLogger.d("remoteNum ==> " + remoteNum);
int duration = query.getInt(query.getColumnIndex("duration"));
ICLogger.d("content --- > " + content);
//todo:还有类型也要查询出来
int type = query.getInt(query.getColumnIndex("type"));
+ ICLogger.d("type ==> " + type);
query.close();
-
- if (type == FZDDatabaseHelper.MessageType.VOICE) {
+ if (type == ICDatabaseHelper.MessageType.VOICE || type == ICDatabaseHelper.MessageType.FRIEND_VOICE) {
protocolAPIHelper.sendVoice(duration, remoteNum, content, lastPathSegment);
- } else if (type == FZDDatabaseHelper.MessageType.PIC) {
+ } else if (type == ICDatabaseHelper.MessageType.PIC) {
//图片数据
protocolAPIHelper.sendPicture(remoteNum, content, lastPathSegment);
}
}
});
}
-}
+}
\ No newline at end of file
case Config.PROTOCOL_JIAI:
break;
case Config.PROTOCOL_BEEHOME:
+ protocolbeehome_handler.sendVoice(duration, remoteNum, content, voiceId);
break;
case Config.PROTOCOL_IC:
break;
}
- public static byte[] getVoicePacketItem(String sender, String durationHEX, String packetTime, int count, int index, int datalen, byte[] amrdata, int filetype, int datatype) {
+ public static byte[] getVoicePacketItem(String sender, String durationHEX,
+ String packetTime, int count, int index,
+ int datalen, byte[] amrdata,
+ int filetype, int datatype, String targetNumber) {
byte[] ret = null;
if (is_protocol_not_Initialled()) return null;
switch (Config.protocol_no) {
ret = protocol_jiai.AP07(packetTime, count, index, datalen, amrdata);
break;
case Config.PROTOCOL_BEEHOME:
- ret = protocol_beehome.AP07(packetTime, count, index, datalen, amrdata);
+ ret = protocol_beehome.AP07(packetTime, count, index, datalen, amrdata, targetNumber);
break;
case Config.PROTOCOL_IC:
/***
import com.enqualcomm.support.utils.Util;
import com.ic.fzd.weather.FZDWeatherInfo;
+import org.apache.harmony.misc.SystemUtils;
+
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
}
}
+ /**
+ * 发送语音数据
+ *
+ * @param duration
+ * @param remoteNum
+ * @param content
+ * @param voiceId
+ */
+ public void sendVoice(int duration, String remoteNum, String content, String voiceId) {
+ // IWAP07,353456789012345,080835,20140818064408 ,135xxx,0,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#
+ File file = new File(content);
+ if (!file.exists()) {
+ ICLogger.d("语音文件不存在.");
+ return;
+ }
+ if (remoteNum == null || remoteNum.isEmpty()) {
+ remoteNum = "0";
+ }
+ ICLogger.d("remoteNum =====> " + remoteNum);
+ //这个分类目前用不了,用号码就是单聊,没号码就是群聊
+ final VoiceContent voiceContent =
+ VoiceContent.placeHolderOut(1, remoteNum, String.format("%04X", duration), content, 1, 3);
+ // 把voiceContent拆解成1024的分包
+ Util.parseToVoicePacketSent(voiceContent, 1024);
+ //trigger 分包发送
+ if (CoreService.getInstance().getConnection() != null) {
+ CoreService.getInstance().getConnection()
+ .DeliverCMDMessageToSystem("SentVoicePacket", "");
+ }
+ }
+
public static StringMessage AP03(Runtime ds) {
//示例数据:IWAP03,06000908000102,5555,30# IWAP03,000000null00000,0,0#
// }
- public static byte[] AP07(String packetTime, int count, int index, int datalen, byte[] amrdata) {
- //IWAP07,20140818064408,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#
- //说明:
- //IW:标识符
- //AP07 : 命令字符
- //20140818064408 :yyyyMMddHHmmss 格式的年月日时分秒,设备录音时间
- //6:语音包分包总数
- //1 :当前包数,第一包为1,第二包为2,。。。。。。同一个语音包的语音时间相同
- //1024 :语音包长度
- //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:当前音频数据, 每个音频数据包大小为1024字节,最后一包不足1024的取实际字节数
- //语音包上传规则:
- //按包次序依次上传,上传后如果没有收到服务器的响应包,则继续上传该语音包。
- //收到设备回复确认数据包接收成功状态后,继续开始依次上传下一个数据包。。。。。。
- //如果设备回复确认数据包接收失败状态,则重复发送上一个数据包
-
-
+ public static byte[] AP07(String packetTime, int count, int index,
+ int datalen, byte[] amrdata, String targetNum) {
+ //IWAP07,080835,20140818064408 ,135xxx,6,1,1024,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#
+ //- IW:标识符
+ //- AP07 : 命令字符
+ //- 080835:流水号
+ //- 20140818064408 :yyyyMMddHHmmss 格式的年月日时分秒,设备录音时间
+ //- 135xxx:目标联系人号,0表示群聊(我要发给谁)
+ //- 6:语音包分包总数
+ //- 1 :当前包数,第一包为1,第二包为2,。。。。。。同一个语音包的语音时间相同
+ //- 1024 :语音包长度
+ //- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:当前音频数据, 每个音频数据包大小为1024字节,最后一包不足1024的取实际字节数
+ //- 语音包上传规则:
+ // - 按包次序依次上传,上传后如果没有收到服务器的响应包,则继续上传该语音包。
+ // - 收到设备回复确认数据包接收成功状态后,继续开始依次上传下一个数据包。。。。。。
+ // - 如果设备回复确认数据包接收失败状态,则重复发送上一个数据包
String sb = new StringBuffer(CMDHEADER).append(cmdStrMap.get(CMD_TYPE.AP07))
+ .append(CMDSPLIT).append(TimeUtil.getUTCSystemTimeHHmmss())
.append(CMDSPLIT).append(packetTime)
+ .append(CMDSPLIT).append(targetNum)
.append(CMDSPLIT).append(count)
.append(CMDSPLIT).append(index)
.append(CMDSPLIT).append(datalen)
.append(CMDSPLIT).toString();
- byte[] sentbuf = new byte[sb.length() + datalen + 1];
- System.arraycopy(sb.getBytes(), 0, sentbuf, 0, sb.length());
- System.arraycopy(amrdata, 0, sentbuf, sb.length(), datalen);
- sentbuf[sb.length() + datalen] = '#';
-
- return sentbuf;
-
+ byte[] sentBuf = new byte[sb.length() + datalen + 1];
+ System.arraycopy(sb.getBytes(), 0, sentBuf, 0, sb.length());
+ System.arraycopy(amrdata, 0, sentBuf, sb.length(), datalen);
+ sentBuf[sb.length() + datalen] = '#';
+ ICLogger.d("sent buf ==> " + new String(sentBuf));
+ return sentBuf;
}
- public void handleBP07(String cmd, Connection connection) {
- //平台响应: IWBP07,20140818064408,6,1,1#
- //20140818064408:设备语音时间,yyyyMMddHHmmss 格式的年月日时分秒
- //6:语音包分包总数
- //1:当前设备收到的是第几个包
- //1:表示服务器接受数据成功,0表示服务器接受数据失败
- String[] cmdlist = cmd.split(CMDSPLIT);
- if (cmdlist.length == 5) {
- 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);
- }
- } else {
- ICLogger.i(" BP07 Format error!");
- }
+ public void handleBP07(String cmd) {
+ //平台收到语音数据
+ ICLogger.d("平台收到语音数据" + cmd);
}
}
private void message2Db(String remoteId, String amrFilepath, int type) {
-// try {
-// //通知有消息到
-// Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
-// Ringtone ringtone = RingtoneManager.getRingtone(mRuntime.getContextProxy().context, uri);
-// ringtone.play();
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
//计算文件时长
int amrDuration = 0;
if (type == ICDatabaseHelper.MessageType.VOICE ||
break;
case BP07:
//收到发送的语音包
- handleBP07(cmd, mConnection);
+ handleBP07(cmd);
break;
case BP10:
//报警包