250228:AI2.0版本
authorxiewei <892331662@qq.com>
Fri, 28 Feb 2025 10:21:14 +0000 (18:21 +0800)
committerxiewei <892331662@qq.com>
Fri, 28 Feb 2025 10:21:14 +0000 (18:21 +0800)
hssdk/build.gradle
hssdk/src/main/java/com/zhixun/blesdk/hssdk/bttools/BleHandle.java
hssdk/src/main/java/com/zhixun/blesdk/hssdk/data/BleMsgReceiverHandler.java
hssdk/src/main/java/com/zhixun/blesdk/hssdk/data/ReceiverLooperThread.java
hssdk/src/main/java/com/zhixun/blesdk/hssdk/entity/MsgBody.java
hssdk/src/main/java/com/zhixun/blesdk/hssdk/util/BleUuidUtil.java

index 89b86d1..a69a1ef 100644 (file)
@@ -12,7 +12,7 @@ android {
         versionCode 1
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         consumerProguardFiles "consumer-rules.pro"
-        versionName '0.0.6'
+        versionName '2.0.0'
         buildConfigField("String", "SDK_VERSION", "\"${versionName}\"")
         multiDexEnabled true
     }
index 138a30d..9190ba5 100644 (file)
@@ -43,6 +43,7 @@ import com.zhixun.blesdk.hssdk.callback.OnBleControlCallback;
 import com.zhixun.blesdk.hssdk.callback.OnMsgSendCallBack;
 import com.zhixun.blesdk.hssdk.data.BleMsgReceiverHandler;
 import com.zhixun.blesdk.hssdk.data.BleMsgSendHandler;
+import com.zhixun.blesdk.hssdk.data.bean.ReceiverData;
 import com.zhixun.blesdk.hssdk.entity.AppTime;
 import com.zhixun.blesdk.hssdk.entity.E4MsgBody;
 import com.zhixun.blesdk.hssdk.entity.HsDeviceInfo;
@@ -431,12 +432,20 @@ public class BleHandle {
             byte[] value = characteristic.getValue();
             SobLog.d(TAG, "onCharacteristicChanged--" + characteristic.getUuid().toString() + ":" +
                     (value.length > 100 ? value.length : ByteTools.byteArrToHex(value)));
-            if (BleUuidUtil.getInstance().getNotifyUUID().toString().equals(characteristic.getUuid().toString())) {
+            if (BleUuidUtil.getInstance().getNotifyUUID().toString().equals(characteristic.getUuid().toString())
+                ||BleUuidUtil.getInstance().getmAudioNotifyUUID().toString().equals(characteristic.getUuid().toString())) {
                 BleMsgReceiverHandler.getInstance().receiverData(value);
             } else if (BleUuidUtil.getInstance().getFileNotifyUUID().toString().equals(characteristic.getUuid().toString())) {
-                if (onBleControlCallback != null) {
-                    onBleControlCallback.onE7Receiver(value);
+
+                if(value[1]==0x08){
+                    //ai数据内容
+                    BleMsgReceiverHandler.getInstance().receiverData(value);
+                }else {
+                    if (onBleControlCallback != null) {
+                        onBleControlCallback.onE7Receiver(value);
+                    }
                 }
+
             }
 
         }
@@ -762,6 +771,9 @@ public class BleHandle {
 
         BluetoothGattCharacteristic characteristic3 = service.getCharacteristic(BleUuidUtil.getInstance().getFileNotifyUUID());//对应server端的setCharacteristic方法
         mBluetoothGatt.setCharacteristicNotification(characteristic3, true);
+
+        BluetoothGattCharacteristic characteristic4 = service.getCharacteristic(BleUuidUtil.getInstance().getmAudioNotifyUUID());//对应server端的setCharacteristic方法
+        mBluetoothGatt.setCharacteristicNotification(characteristic4, true);
     }
 
     public void deviceWrite(byte[] msg, int type) {
@@ -926,4 +938,6 @@ public class BleHandle {
         deviceWrite(data,6);
     }
 
+
+
 }
index c329c81..4a65043 100644 (file)
@@ -59,50 +59,55 @@ public class BleMsgReceiverHandler {
         int dirrction = ByteTools.byte2Int(data[0]);//传输方向
         SobLog.d(TAG, "receiverData--" +
                 dirrction);
-        if(dirrction==0x72){
-            ReceiverData receiverData = BleDataUtil.anscyData(data);
 
-            if(receiverData==null)return;
-            SobLog.d(TAG,"receiverData--"+receiverData.toString());
-            if(receiverData.getDataNum()==1
-                    ||receiverData.getType()==TYPE_RECEIVER_LOG
+        if(receiverLooperThread.isStartSendAudio()){
+            receiverLooperThread.sendAudio(data);
+        }else {
+            if(dirrction==0x72){
+                ReceiverData receiverData = BleDataUtil.anscyData(data);
+                if(receiverData==null)return;
+                SobLog.d(TAG,"receiverData--"+receiverData.toString());
+                if(receiverData.getDataNum()==1
+                        ||receiverData.getType()==TYPE_RECEIVER_LOG
 //                    ||receiverData.getType()==TYPE_GET_WEAR_AUDIO
                 ){
-                //说明只有一条数据
-                handData(receiverData);
-            }else {
-                SobLog.d(TAG,"receiverData-分包数据-"+receiverData.toString());
-                //是分包数据
-                if(splitDataMap.containsKey(receiverData.getType())){
-                    if (receiverData.getType()==TYPE_GET_WEAR_AUDIO){
-                        receiverLooperThread.removeAudioTimeOut();
-                    }
-                    ArrayList<ReceiverData> cacheData = splitDataMap.get(receiverData.getType());
-                    cacheData.add(receiverData);
-                    SobLog.d(TAG,"receiverData-已有-"+cacheData.size());
-                    if(receiverData.getDataNum()==receiverData.getPageId()
-                        &&cacheData.size()==receiverData.getDataNum()){
-                        //数据包已接收完成,进行组包
-                        //对列表里面的数据进行排序
-                        receiverData.setContent(composeData(cacheData));
-                        handData(receiverData);
-                        splitDataMap.remove(receiverData.getType());
-
-                    }else {
+                    //说明只有一条数据
+                    handData(receiverData);
+                }else {
+                    SobLog.d(TAG,"receiverData-分包数据-"+receiverData.toString());
+                    //是分包数据
+                    if(splitDataMap.containsKey(receiverData.getType())){
                         if (receiverData.getType()==TYPE_GET_WEAR_AUDIO){
-                            receiverLooperThread.startAudioTimeOut();
+                            receiverLooperThread.removeAudioTimeOut();
+                        }
+                        ArrayList<ReceiverData> cacheData = splitDataMap.get(receiverData.getType());
+                        cacheData.add(receiverData);
+                        SobLog.d(TAG,"receiverData-已有-"+cacheData.size());
+                        if(receiverData.getDataNum()==receiverData.getPageId()
+                                &&cacheData.size()==receiverData.getDataNum()){
+                            //数据包已接收完成,进行组包
+                            //对列表里面的数据进行排序
+                            receiverData.setContent(composeData(cacheData));
+                            handData(receiverData);
+                            splitDataMap.remove(receiverData.getType());
+
+                        }else {
+                            if (receiverData.getType()==TYPE_GET_WEAR_AUDIO){
+                                receiverLooperThread.startAudioTimeOut();
+                            }
+                            splitDataMap.put(receiverData.getType(),cacheData);
                         }
+
+                    }else {
+                        ArrayList<ReceiverData> cacheData = new ArrayList<>();
+                        cacheData.add(receiverData);
                         splitDataMap.put(receiverData.getType(),cacheData);
                     }
-
-                }else {
-                    ArrayList<ReceiverData> cacheData = new ArrayList<>();
-                    cacheData.add(receiverData);
-                    splitDataMap.put(receiverData.getType(),cacheData);
                 }
-            }
 
+            }
         }
+
     }
 
     private byte[] composeData(ArrayList<ReceiverData> cacheData){
index 42a5680..47282ba 100644 (file)
@@ -9,6 +9,7 @@ import android.os.Looper;
 import android.os.Message;
 import android.util.Log;
 
+import androidx.annotation.BoolRes;
 import androidx.annotation.NonNull;
 
 import com.google.gson.Gson;
@@ -82,6 +83,7 @@ public class ReceiverLooperThread extends Thread {
 
     public static final int TYPE_LOSS_FILE_PAGE = 1030;
     public static final int TYPE_AI_READY = 1285;
+
     public static final int TYPE_AI_CANCLE_CHAT = 1797;
     public static final int TYPE_AI_CHECK_USERD = 1541;
 
@@ -92,6 +94,9 @@ public class ReceiverLooperThread extends Thread {
     public static final int TYPE_GET_WEAR_AUDIO = 13313;
     public static final int TYPE_SEND_AI_RESULT = 7938;
 
+    public static final int TYPE_START_SEND = 264;
+    public static final int TYPE_STOP_SEND = 520;
+    private boolean startSendAudio = false;
     private Handler mReceiverMsgHandle;
     private HashMap<Integer, OnMsgSendCallBack> callBackMap = new HashMap<>();
 
@@ -530,6 +535,7 @@ public class ReceiverLooperThread extends Thread {
                                 FileHandler.getInstance().addLogContent(content);
                                 break;
                             case TYPE_AI_READY:
+                                SobLog.d(TAG, "TYPE_START_CHAT--");
                                 E3MsgBody msgBody = new E3MsgBody(TYPE_AI_READY);
                                 msgBody.setData(ByteTools.little_intToByte(1, 1));
                                 BleMsgSendHandler.getInstance().sendMsg(msgBody, null);
@@ -538,6 +544,24 @@ public class ReceiverLooperThread extends Thread {
                                 }
 //                                AiManage.getInstance().startTrans();
                                 break;
+                            case TYPE_START_SEND:
+                                SobLog.d(TAG, "TYPE_START_SEND--");
+                                if(iAiFunctionListener!=null){
+                                    iAiFunctionListener.onStart();
+                                }
+                                startSendAudio = true;
+                                break;
+                            case TYPE_STOP_SEND:
+                                SobLog.d(TAG, "TYPE_STOP_SEND--");
+                                if(iAiFunctionListener!=null){
+                                    iAiFunctionListener.onStop();
+                                }
+                                startSendAudio = false;
+                                if(iAiFunctionListener!=null){
+                                    iAiFunctionListener.sendAudio(audioCache.length,audioCache);
+                                }
+                                audioCache = new byte[0];
+                                break;
                             case TYPE_AI_CANCLE_CHAT:
                                 SobLog.d(TAG, "TYPE_AI_CANCLE_CHAT--");
                                 if(iAiFunctionListener!=null){
@@ -695,11 +719,22 @@ public class ReceiverLooperThread extends Thread {
         mReceiverMsgHandle.sendMessage(message);
     }
 
+    private byte[] audioCache = new byte[0];
+    public synchronized void sendAudio(byte[] data){
+        SobLog.d(TAG, "sendAudio---");
+        audioCache = ByteTools.concatAll(audioCache,data);
+
+    }
+    public boolean isStartSendAudio() {
+        return startSendAudio;
+    }
+
     public void addResponseCallBack(int type, OnMsgSendCallBack callBack) {
         callBackMap.put(type, callBack);
     }
 
     public void clear() {
+        startSendAudio = false;
         callBackMap.clear();
         if (mReceiverMsgHandle != null) mReceiverMsgHandle.removeMessages(MSG_RECEIVERDATA);
 
index 129fa71..7f7b9f0 100644 (file)
@@ -85,6 +85,13 @@ public class MsgBody implements Serializable {
     public static final int TYPE_GET_SOS = 13825;
     public static final int TYPE_SET_SOS = 9474;
 
+    //AI2.0
+//    public static final int TYPE_START_CHAT = 264;
+//    public static final int TYPE_CHAT_AUDIO = 520;
+//    public static final int TYPE_CHAT_MSG = 776;
+//    public static final int TYPE_CHAT_ENABLE = 1032;
+//    public static final int TYPE_CHAT_CANCLE = 1288;
+
     public static final int TYPE_GET_DIR = 289;
     public static int TRAIN_TYPE_WALKING = 0;
     public static int TRAIN_TYPE_RUN = 1;
@@ -101,7 +108,7 @@ public class MsgBody implements Serializable {
     public static final int CHANNEL_E4 = 4;
 
     public static final int CHANNEL_E6 = 6;
-
+    public static final int CHANNEL_E8 = 8;
     private int channel;
     private int port;
     private int type;
index e374303..fc3e65b 100644 (file)
@@ -17,6 +17,8 @@ public class BleUuidUtil {
 
     private UUID w2AE6UUID = UUID.fromString("00002ae6-0000-1000-8000-00805f9b34fb");//新的文件传输通道
 
+    private UUID mAudioNotifyUUID = UUID.fromString("00002ae8-0000-1000-8000-00805f9b34fb");//新的AI传输通道
+
     private UUID w2AE1UUID = UUID.fromString("00002ae1-0000-1000-8000-00805f9b34fb");//客户端推送消息(仅Android)(发送字节数>20)
 
     private UUID mNotifyUUID = UUID.fromString("00002ae5-0000-1000-8000-00805f9b34fb");//客户端接收
@@ -44,6 +46,10 @@ public class BleUuidUtil {
         return mFileNotifyUUID;
     }
 
+    public UUID getmAudioNotifyUUID() {
+        return mAudioNotifyUUID;
+    }
+
     public UUID getServiceUUID() {
         return mServiceUUID;
     }