@@ -1,6 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project version="4"> | |||
<component name="CompilerConfiguration"> | |||
<bytecodeTargetLevel target="9" /> | |||
<bytecodeTargetLevel target="1.8" /> | |||
</component> | |||
</project> |
@@ -8,7 +8,6 @@ | |||
<option name="distributionType" value="DEFAULT_WRAPPED" /> | |||
<option name="externalProjectPath" value="$PROJECT_DIR$" /> | |||
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-5.1.1" /> | |||
<option name="gradleJvm" value="1.8 (2)" /> | |||
<option name="modules"> | |||
<set> | |||
<option value="$PROJECT_DIR$" /> | |||
@@ -16,6 +15,7 @@ | |||
</set> | |||
</option> | |||
<option name="resolveModulePerSourceSet" value="false" /> | |||
<option name="useQualifiedModuleNames" value="true" /> | |||
</GradleProjectSettings> | |||
</option> | |||
</component> |
@@ -5,7 +5,7 @@ | |||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> | |||
</configurations> | |||
</component> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||
<output url="file://$PROJECT_DIR$/build/classes" /> | |||
</component> | |||
<component name="ProjectType"> |
@@ -82,6 +82,11 @@ A7 data encryption method, cid is the product ID, and the ble protocol will incl | |||
byte[] mcuEncrypt(int cid, String mac, byte[] payload); | |||
/** | |||
Broadcast data decryption method | |||
*/ | |||
byte[] decryptBroadcast(int cid, int vid,int pid, byte[] payload); | |||
``` | |||
### 5、How to use |
@@ -83,6 +83,17 @@ byte[] mcuDecrypt(byte[] hex, String mac); | |||
byte[] mcuEncrypt(int cid, String mac, byte[] payload); | |||
/** | |||
A7数据加密方法,cid为产品ID,ble协议中会包含 | |||
*/ | |||
byte[] mcuEncrypt(int cid, String mac, byte[] payload); | |||
/** | |||
广播数据解密方法 | |||
*/ | |||
byte[] decryptBroadcast(int cid, int vid,int pid, byte[] payload); | |||
``` | |||
### 五、使用方法 |
@@ -36,5 +36,5 @@ dependencies { | |||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | |||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | |||
implementation 'com.github.elinkthings:AILinkSecretAndroid:1.0.0' | |||
implementation 'com.github.elinkthings:AILinkSecretAndroid:2.0.0' | |||
} |
@@ -352,6 +352,24 @@ public class AnalyticalDataUtil { | |||
} | |||
/** | |||
* 将广播数据进行解密 | |||
* | |||
* @param cid cid | |||
* @param vid vid | |||
* @param pid pid | |||
* @param payload byte[] | |||
* @return byte[] | |||
*/ | |||
public byte[] decryptBroadcast(int cid, int vid,int pid, byte[] payload) { | |||
byte[] data = null; | |||
if (payload != null && payload.length >= 1) { | |||
data = AiLinkBleCheckUtil.decryptBroadcast(cid, vid, pid,payload); | |||
} | |||
return data; | |||
} | |||
public void close() { | |||
if (mBluetoothGatt != null) { | |||
mBluetoothGatt.disconnect(); |
@@ -328,6 +328,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | |||
super.onScanResult(callbackType, result); | |||
String address = result.getDevice().getAddress(); | |||
saveScanData(address); | |||
// SparseArray<byte[]> manufacturerSpecificData = result.getScanRecord().getManufacturerSpecificData();//获取自定义厂商数据列表,正常情况只有1个 | |||
// if (manufacturerSpecificData.size() > 0) { | |||
// byte[] data = manufacturerSpecificData.get(0); | |||
// decryptBroadcastExample(data); | |||
// } | |||
} | |||
@@ -345,6 +350,34 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | |||
} | |||
} | |||
/** | |||
* 解密广播数据参考例子 | |||
* @param data 自定义厂商数据 | |||
*/ | |||
private void decryptBroadcastExample(byte[] data){ | |||
if (data.length < 3) | |||
return; | |||
byte[] cidB = new byte[1]; | |||
byte[] vidB = new byte[1]; | |||
byte[] pidB = new byte[1]; | |||
int start = 0; | |||
System.arraycopy(data, start, cidB, 0, cidB.length); | |||
start += 1; | |||
System.arraycopy(data, start, vidB, 0, vidB.length); | |||
start += 1; | |||
System.arraycopy(data, start, pidB, 0, pidB.length); | |||
start += 1; | |||
//特殊广播,包含是否可以绑定的标志 | |||
int cid = (cidB[0] & 0xff); | |||
int vid = (vidB[0] & 0xff); | |||
int pid = (pidB[0] & 0xff); | |||
byte[] decryptData=new byte[10];//根据协议取出需要解密的广播数据 | |||
mAnalyticalDataUtil.decryptBroadcast(cid, vid, pid, decryptData); | |||
} | |||
/** | |||
* 搜索到的数据到列表 | |||
*/ |