11 changed files with 315 additions and 311 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,116 @@ |
|||||
|
package com.yunqiinnovation.ble_service |
||||
|
import io.flutter.embedding.engine.plugins.FlutterPlugin |
||||
|
import io.flutter.plugin.common.EventChannel |
||||
|
import io.flutter.plugin.common.MethodCall |
||||
|
import io.flutter.plugin.common.MethodChannel |
||||
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler |
||||
|
import io.flutter.plugin.common.MethodChannel.Result |
||||
|
import android.bluetooth.BluetoothDevice |
||||
|
import android.bluetooth.BluetoothGatt |
||||
|
import android.bluetooth.BluetoothProfile |
||||
|
import android.content.Context |
||||
|
import com.jieli.jl_bt_ota.constant.ErrorCode; |
||||
|
import com.jieli.jl_bt_ota.constant.StateCode; |
||||
|
import com.jieli.jl_bt_ota.impl.BluetoothOTAManager; |
||||
|
import com.jieli.jl_bt_ota.interfaces.BtEventCallback; |
||||
|
import com.jieli.jl_bt_ota.interfaces.IActionCallback; |
||||
|
import com.jieli.jl_bt_ota.interfaces.IUpgradeCallback; |
||||
|
import com.jieli.jl_bt_ota.model.BluetoothOTAConfigure; |
||||
|
import com.jieli.jl_bt_ota.model.base.BaseError; |
||||
|
import com.jieli.jl_bt_ota.model.response.TargetInfoResponse; |
||||
|
import android.util.Log |
||||
|
import java.util.* |
||||
|
class CustomUpdateCallback( |
||||
|
val context: Context, |
||||
|
val device: BluetoothDevice? |
||||
|
) : IUpgradeCallback { |
||||
|
companion object { |
||||
|
private const val TAG = "JlOtaPlugin" |
||||
|
private const val CHANNEL_NAME = "com.yunqiinnovation.jl_ota" |
||||
|
private const val EVENT_CHANNEL_NAME = "com.yunqiinnovation.jl_ota/events" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
override fun onStartOTA() { |
||||
|
Log.d(TAG, "onStartOTA开始升级") |
||||
|
// viewModel.otaStateMLD.value = OTAStart(device) |
||||
|
} |
||||
|
|
||||
|
override fun onNeedReconnect(addr: String?, isNewReconnectWay: Boolean) { |
||||
|
Log.d(TAG, "onNeedReconnect需要重新链接") |
||||
|
|
||||
|
} |
||||
|
|
||||
|
override fun onProgress(type: Int, progress: Float) { |
||||
|
Log.d(TAG, "onProgress正在进展") |
||||
|
//viewModel.otaStateMLD.value = OTAWorking(device, type, progress) |
||||
|
} |
||||
|
|
||||
|
override fun onStopOTA() { |
||||
|
Log.d(TAG, "onStartOTA停止升级") |
||||
|
|
||||
|
} |
||||
|
|
||||
|
override fun onCancelOTA() { |
||||
|
Log.d(TAG, "onCancelOTA取消升级") |
||||
|
|
||||
|
} |
||||
|
|
||||
|
override fun onError(error: BaseError?) { |
||||
|
val errorMessage = error?.message ?: "Unknown error" |
||||
|
Log.e(TAG, "升级失败: ${error?.message ?: "未知错误"}") |
||||
|
|
||||
|
// 如果需要打印完整错误对象信息(假设BaseError有重写toString()) |
||||
|
Log.d(TAG, "完整错误对象: ${error ?: "null"}") |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
class OTAManager(context: Context) : BluetoothOTAManager(context) { |
||||
|
|
||||
|
|
||||
|
// 定义回调接口 |
||||
|
interface DataCallback { |
||||
|
fun onDataReceived(device: BluetoothDevice?, data: ByteArray?) |
||||
|
} |
||||
|
// 保存回调的实例 |
||||
|
private var dataCallback: DataCallback? = null |
||||
|
|
||||
|
// 设置回调的方法 |
||||
|
fun setDataCallback(callback: DataCallback) { |
||||
|
this.dataCallback = callback |
||||
|
} |
||||
|
override fun getConnectedDevice(): BluetoothDevice? { |
||||
|
// 这里可以添加空实现的注释说明 |
||||
|
Log.i(TAG, "ota数据发送getConnectedDevice") |
||||
|
return null |
||||
|
} |
||||
|
|
||||
|
override fun getConnectedBluetoothGatt(): BluetoothGatt? { |
||||
|
// 这里可以添加空实现的注释说明 |
||||
|
Log.i(TAG, "ota数据发送getConnectedBluetoothGatt") |
||||
|
return null |
||||
|
} |
||||
|
|
||||
|
override fun connectBluetoothDevice(bluetoothDevice: BluetoothDevice?) { |
||||
|
// 这里可以添加空实现的注释说明 |
||||
|
Log.i(TAG, "ota数据发送connectBluetoothDevice") |
||||
|
} |
||||
|
|
||||
|
override fun disconnectBluetoothDevice(bluetoothDevice: BluetoothDevice?) { |
||||
|
// 这里可以添加空实现的注释说明 |
||||
|
Log.i(TAG, "ota数据发送disconnectBluetoothDevice") |
||||
|
} |
||||
|
|
||||
|
/** 数据发送方法(协议无关) */ |
||||
|
override fun sendDataToDevice( |
||||
|
bluetoothDevice: BluetoothDevice?, |
||||
|
bytes: ByteArray? |
||||
|
): Boolean { |
||||
|
Log.i(TAG, "ota数据发送${bluetoothDevice},${bytes?.size}") |
||||
|
// 触发回调,将数据回传给调用者 |
||||
|
dataCallback?.onDataReceived(bluetoothDevice, bytes) |
||||
|
// context.onReceiveDeviceData(device, data); |
||||
|
return true |
||||
|
} |
||||
|
} |
||||
|
|
||||
Binary file not shown.
@ -1 +1 @@ |
|||||
rootProject.name = 'jl_ota' |
rootProject.name = 'jl_ota' |
||||
Loading…
Reference in new issue