Skip to content

Commit 99c514a

Browse files
sevenhheSundoggyNew
authored andcommitted
对接llsync标准蓝牙辅助配网协议
http://tapd.oa.com/NEW_IOT/prong/stories/view/1020393192863935819# Change-Id: Id5e0894279cada756afb446076c07cf2bb8fced7
1 parent 9668e7f commit 99c514a

File tree

10 files changed

+419
-3
lines changed

10 files changed

+419
-3
lines changed

app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.os.Bundle
1010
import android.os.Handler
1111
import android.text.TextUtils
1212
import android.util.DisplayMetrics
13+
import android.util.Log
1314
import android.view.LayoutInflater
1415
import android.view.View
1516
import android.view.ViewGroup
@@ -36,6 +37,7 @@ import com.tencent.iot.explorer.link.T
3637
import com.tencent.iot.explorer.link.core.auth.callback.MyCallback
3738
import com.tencent.iot.explorer.link.core.auth.response.BaseResponse
3839
import com.tencent.iot.explorer.link.core.link.entity.TrtcDeviceInfo
40+
import com.tencent.iot.explorer.link.core.link.service.BleConfigService
3941
import com.tencent.iot.explorer.link.customview.recyclerview.CRecyclerView
4042
import com.tencent.iot.explorer.link.customview.verticaltab.*
4143
import com.tencent.iot.explorer.link.kitlink.consts.CommonField
@@ -78,14 +80,15 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI
7880
App.data.tabPosition = 0 // Reset the position of vertical tab
7981
App.data.screenWith = getScreenWidth()
8082
HttpRequest.instance.getParentCategoryList(this)
83+
BleConfigService.get().context = this
8184
beginScanning()
8285
}
8386

84-
8587
private val runnable = Runnable {
8688
iv_loading_cirecle.clearAnimation()
8789
scanning.visibility = View.GONE
8890
not_found_dev.visibility = View.VISIBLE
91+
BleConfigService.get().stopScanBluetoothDevices()
8992
}
9093

9194
override fun onResume() {
@@ -380,7 +383,7 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI
380383
}
381384

382385
private fun isBluetoothValid() : Boolean {
383-
val adapter = BluetoothAdapter.getDefaultAdapter()
386+
val adapter = BluetoothAdapter.getDefaultAdapter()
384387
return adapter?.isEnabled ?: false
385388
}
386389

@@ -393,7 +396,8 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI
393396
not_found_dev.visibility = View.GONE
394397
scann_fail.visibility = View.GONE
395398
iv_loading_cirecle.startAnimation(rotateAnimation)
396-
handler.postDelayed(runnable, 15000)
399+
handler.postDelayed(runnable, 60000)
400+
BleConfigService.get().startScanBluetoothDevices()
397401
} else {
398402
scann_fail.visibility = View.VISIBLE
399403
scanning.visibility = View.GONE

sdk/explorer-link-android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.tenext">
33

4+
<uses-permission android:name="android.permission.BLUETOOTH" />
5+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
46
<uses-permission android:name="android.permission.INTERNET" />
57
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
68
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.tencent.iot.explorer.link.core.link.entity
2+
3+
import android.bluetooth.BluetoothDevice
4+
5+
class BleDevice {
6+
var url = ""
7+
var productName = ""
8+
var devName = ""
9+
var blueDev : BluetoothDevice? = null
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.tencent.iot.explorer.link.core.link.entity
2+
3+
class BleDeviceInfo {
4+
companion object {
5+
6+
fun byteArr2BleDeviceInfo(byteArray: ByteArray): BleDeviceInfo {
7+
var ret = BleDeviceInfo()
8+
if (byteArray.isEmpty()) return ret
9+
if (byteArray.get(0) != 0x08.toByte()) return ret
10+
11+
ret.llsyncVersion = byteArray[3].toInt().toString()
12+
ret.mtuFlag = if ((byteArray[4].toInt() and 0x80) == 8) 1 else 0
13+
ret.mtuSize = (byteArray[4].toInt() and 0x02 shl 8) or (byteArray[5].toInt() and 0xFF)
14+
ret.devNameLen = byteArray[6].toInt()
15+
val nameByteArr = ByteArray(ret.devNameLen)
16+
System.arraycopy(byteArray, 7, nameByteArr, 0, ret.devNameLen)
17+
ret.devName = String(nameByteArr)
18+
19+
return ret
20+
}
21+
}
22+
23+
var llsyncVersion = "" // 协议版本号
24+
var mtuFlag = 0 // 是否设置 mtu 当 mtu flag为 1 时,进行 MTU 设置;当 mtu flag 为 0 时,不设置 MTU
25+
var mtuSize = 0 // mtu 大小
26+
var devNameLen = 0
27+
var devName = ""
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.tencent.iot.explorer.link.core.link.entity
2+
3+
class BleDeviceWifiInfo {
4+
var ssid = ""
5+
var pwd = ""
6+
7+
fun formatByteArr(): ByteArray {
8+
if (ssid == null || pwd == null) {
9+
return ByteArray(0)
10+
}
11+
12+
var byteArr = ByteArray( 5 + ssid.toByteArray().size + pwd.toByteArray().size)
13+
byteArr[0] = 0xE2.toByte()
14+
byteArr[1] = ((byteArr.size - 3) / Math.pow(2.0, 8.0).toInt()).toByte()
15+
byteArr[2] = ((byteArr.size - 3) % Math.pow(2.0, 8.0).toInt()).toByte()
16+
byteArr[3] = ssid.toByteArray().size.toByte()
17+
System.arraycopy(ssid.toByteArray(), 0, byteArr, 4, ssid.toByteArray().size)
18+
byteArr[4 + ssid.toByteArray().size] = pwd.toByteArray().size.toByte()
19+
System.arraycopy(pwd.toByteArray(), 0, byteArr, 5 + ssid.toByteArray().size, pwd.toByteArray().size)
20+
return byteArr
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.tencent.iot.explorer.link.core.link.entity
2+
3+
enum class BleDeviceWifiMode(var modeValue : Byte) {
4+
NULL(0x00.toByte()),
5+
STA(0x01.toByte());
6+
7+
fun getValue(): Byte {
8+
return modeValue
9+
}
10+
11+
companion object {
12+
fun valueOf(modeValue : Byte) : BleDeviceWifiMode{
13+
if (modeValue == 0x01.toByte()) {
14+
return STA
15+
}
16+
return NULL
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.tencent.iot.explorer.link.core.link.entity
2+
3+
class BleWifiConnectInfo {
4+
var wifiMode: BleDeviceWifiMode = BleDeviceWifiMode.NULL
5+
var connected: Boolean = false
6+
var softAp = false
7+
var ssid = ""
8+
var ssidLen = 0
9+
10+
companion object {
11+
fun byteArr2BleWifiConnectInfo(byteArray: ByteArray): BleWifiConnectInfo {
12+
var ret = BleWifiConnectInfo()
13+
if (byteArray.isEmpty()) return ret
14+
if (byteArray.get(0) != 0xE2.toByte()) return ret
15+
16+
ret.wifiMode = BleDeviceWifiMode.valueOf(byteArray[3].toInt().toByte())
17+
ret.connected = byteArray[4].toInt() == 0
18+
ret.ssidLen = byteArray[6].toInt()
19+
val ssidByteArr = ByteArray(ret.ssidLen)
20+
System.arraycopy(byteArray, 7, ssidByteArr, 0, ret.ssidLen)
21+
ret.ssid = String(ssidByteArr)
22+
23+
return ret
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.tencent.iot.explorer.link.core.link.listener
2+
3+
import com.tencent.iot.explorer.link.core.link.entity.BleDeviceInfo
4+
import com.tencent.iot.explorer.link.core.link.entity.BleWifiConnectInfo
5+
import com.tencent.iot.explorer.link.core.link.exception.TCLinkException
6+
7+
interface BleDeviceConnectionListener {
8+
fun onBleDeviceConnected()
9+
fun onBleDeviceDisconnected(exception : TCLinkException)
10+
fun onBleDeviceInfo(bleDeviceInfo: BleDeviceInfo)
11+
fun onBleSetWifiModeResult(success: Boolean)
12+
fun onBleSendWifiInfoResult(success: Boolean)
13+
fun onBleWifiConnectedInfo(wifiConnectInfo: BleWifiConnectInfo)
14+
fun onBlePushTokenResult(success: Boolean)
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.tencent.iot.explorer.link.core.link.listener
2+
3+
import com.tencent.iot.explorer.link.core.link.entity.BleDevice
4+
5+
interface BleDeviceScanResult {
6+
fun onBleDeviceFounded(bleDevice: BleDevice)
7+
}

0 commit comments

Comments
 (0)