[fix]
[蓝牙维持30s连接]
This commit is contained in:
yangyakun
2024-11-25 10:08:15 +08:00
parent c1b8f78923
commit f18b9e8ed8
8 changed files with 103 additions and 302 deletions

View File

@@ -28,7 +28,6 @@ import mogo.telematics.pad.MessagePad
import mogo_msg.MogoReportMsg
import system_master.SsmInfo
import system_master.SystemStatusInfo
import java.lang.Exception
import java.util.concurrent.atomic.AtomicLong
import kotlin.properties.Delegates
@@ -169,15 +168,8 @@ object OchAutoPilotStatusListenerManager : CallerBase<IOchAutopilotStatusListene
}
}
when (guardianInfo?.code) {
MogoReport.Code.Error.EMAP.TRA_LOAD_FAILED -> {
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 加载轨迹文件失败", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY)
}
MogoReport.Code.Error.EMAP.TRA_NOT_EXIST -> {
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 无法找到轨迹文件", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY)
}
else -> {}
}
TrajectoryManager.carDownLoadTrajectoryLog(guardianInfo?.code)
M_LISTENERS.forEach {
val listener = it.value
listener.onAutopilotGuardian(guardianInfo)

View File

@@ -8,7 +8,9 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import com.mogo.eagle.core.utilcode.util.CoordinateUtils
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager.writeChainLog
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil
import com.zhjt.mogo.adas.data.bean.MogoReport
import mogo.telematics.pad.MessagePad
import java.util.concurrent.ConcurrentHashMap
@@ -104,7 +106,7 @@ object TrajectoryManager : IMoGoPlanningRottingListener {
fun addDownLoadSuccessLine(lineId:Long){
if(lineId>0){
OchChainLogManager.writeChainLog("轨迹监控", "onAutopilotGuardian() 轨迹下载成功${lineId}", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY)
OchChainLogManager.writeChainLog("轨迹监控", " 轨迹下载成功${lineId}", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY)
downLoadSuccessLineIds.add(lineId)
}
}
@@ -113,5 +115,25 @@ object TrajectoryManager : IMoGoPlanningRottingListener {
downLoadSuccessLineIds.remove(lineId)
}
}
fun carDownLoadTrajectoryLog(code:String?){
when (code) {
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START -> writeTrajectoryLog("轨迹开始下载")
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS -> writeTrajectoryLog("轨迹下载成功")
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE -> writeTrajectoryLog("轨迹下载失败,本地无对应轨迹")
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING -> writeTrajectoryLog("轨迹下载失败,本地有对应轨迹,认为成功")
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT -> writeTrajectoryLog("轨迹下载超时")
MogoReport.Code.Info.ISSM.FUNC_AUTO_PILOT_READY -> writeTrajectoryLog("再次发起下载、 ssm ready再次发起下载")
MogoReport.Code.Error.EMAP.TRA_LOAD_FAILED -> writeTrajectoryLog("onAutopilotGuardian() 加载轨迹文件失败")
MogoReport.Code.Error.EMAP.TRA_NOT_EXIST -> writeTrajectoryLog("onAutopilotGuardian() 无法找到轨迹文件")
else -> {}
}
}
private fun writeTrajectoryLog(message:String){
writeChainLog("轨迹监控", "再次发起下载", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY)
}
}

View File

@@ -1,19 +0,0 @@
package com.mogo.och.common.module.manager.bluetooth
import android.bluetooth.BluetoothDevice
import android.bluetooth.le.ScanResult
data class BleDevItem(val dev: BluetoothDevice,val scanResult: ScanResult,val gattcallback:OchBluetoothGattCallback){
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as BleDevItem
return dev.address == other.dev.address
}
override fun hashCode(): Int {
return dev.hashCode()
}
}

View File

@@ -4,11 +4,8 @@ import android.annotation.SuppressLint
import android.bluetooth.le.BluetoothLeScanner
import android.bluetooth.le.ScanCallback
import android.bluetooth.le.ScanResult
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.mogo.och.common.module.manager.loop.BizLoopManager
import com.mogo.och.common.module.utils.RxUtils
import java.util.UUID
@@ -21,15 +18,17 @@ object BleManager : BaseBluetoothManager() {
private var scanning = false
private val handler = Handler(Looper.getMainLooper())
private var bluetoothLeScanner: BluetoothLeScanner? = null
private val SCAN_PERIOD = 10000L
private val SCAN_PERIOD = 60_000L
private const val TAG = "BleManager"
private val scanList = mutableListOf<BleDevItem>()
// 未连接到的设备
val scanList = mutableListOf<OchBluetoothGattCallback>()
val sendDataIntDev = mutableListOf<OchBluetoothGattCallback>()
var listener: BleDevListener? = null
@@ -37,37 +36,8 @@ object BleManager : BaseBluetoothManager() {
@SuppressLint("MissingPermission")
override fun onScanResult(callbackType: Int, result: ScanResult?) {
result?.let {
val device = it.device
it.rssi// 信号强度
it.scanRecord?.advertiseFlags
it.scanRecord?.serviceUuids
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
it.scanRecord?.serviceSolicitationUuids
}
it.scanRecord?.manufacturerSpecificData
it.scanRecord?.serviceData
it.scanRecord?.txPowerLevel
it.scanRecord?.deviceName
it.scanRecord?.manufacturerSpecificData
it.timestampNanos//
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
it.isLegacy
} else {
TODO("VERSION.SDK_INT < O")
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
it.isLegacy//是否传统蓝牙
} else {
TODO("VERSION.SDK_INT < O")
}
it.primaryPhy
it.secondaryPhy
it.advertisingSid
it.txPower
it.periodicAdvertisingInterval
if(!it.device.name.isNullOrEmpty()){
val bleDevItem = BleDevItem(result.device, result,OchBluetoothGattCallback(result.device))
val bleDevItem = OchBluetoothGattCallback(result.device)
if(!scanList.contains(bleDevItem)){
scanList.add(bleDevItem)
}
@@ -76,14 +46,6 @@ object BleManager : BaseBluetoothManager() {
}
}
}
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
Log.d(TAG, "results:${results}")
}
override fun onScanFailed(errorCode: Int) {
Log.d(TAG, "errorCode:${errorCode}")
}
}
@@ -102,17 +64,14 @@ object BleManager : BaseBluetoothManager() {
try {
if (!scanning) { // Stops scanning after a pre-defined scan period.
handler.postDelayed({
RxUtils.createSubscribeOnOwnThread(SCAN_PERIOD) {
scanning = false
bluetoothLeScanner?.stopScan(leScanCallback)
}, SCAN_PERIOD)
}
scanning = true
bluetoothLeScanner?.startScan(leScanCallback)
scanList.clear()
listener?.dataChange(scanList)
} else {
scanning = false
bluetoothLeScanner?.stopScan(leScanCallback)
}
}catch (e:SecurityException){
e.printStackTrace()
@@ -120,8 +79,31 @@ object BleManager : BaseBluetoothManager() {
}
@SuppressLint("MissingPermission")
fun sendData2Wx(devName: String, data: String): Boolean {
var needDev:OchBluetoothGattCallback?=null
scanList.forEach {
if(it.device.name==devName){
needDev = it
return@forEach
}
}
needDev?.let {
it.connectGattAndSend(data)
scanList.remove(it)
sendDataIntDev.add(it)
return true
}
return false
}
fun copy2ScanList(ochBluetoothGattCallback: OchBluetoothGattCallback) {
sendDataIntDev.remove(ochBluetoothGattCallback)
scanList.add(ochBluetoothGattCallback)
}
interface BleDevListener{
fun dataChange(scanList:MutableList<BleDevItem>)
fun dataChange(scanList:MutableList<OchBluetoothGattCallback>)
}
}

View File

@@ -12,34 +12,40 @@ import android.util.Log
import com.mogo.commons.AbsMogoApplication
import com.mogo.eagle.core.utilcode.util.ToastUtils
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
import com.mogo.och.common.module.utils.RxUtils
import io.reactivex.disposables.Disposable
import java.util.UUID
import kotlin.properties.Delegates
@SuppressLint("MissingPermission")
class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback() {
private val device = device
private val _device = device
val device:BluetoothDevice
get() {
return _device
}
private var mBluetoothGatt: BluetoothGatt? = null
var connectListener: ConnectListener?=null
private val waitSendData = mutableMapOf<String,UUID>()
private val maxTryCount = 6
private var currentTryCount = 0
// 10s后关闭蓝牙
private var timeoutCLose: Disposable? = null
var isConnected:Boolean by Delegates.observable(false) { _, oldValue, newValue ->
if (oldValue != newValue) {
Log.i(TAG,"链接状态发生变化${newValue}")
connectListener?.connectChangeListener()
connectListener = null
Log.i(TAG,"${device.name}:链接状态发生变化${newValue}")
}
}
private val TAG = "GattCallback"
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
val dev = gatt.device
Log.i(TAG, "onConnectionStateChange:${dev.name},${dev.address},${status},${newState},${dev.type}")
Log.i(TAG, "${device.name}:onConnectionStateChange:${dev.name},${dev.address},${status},${newState},${dev.type}")
if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED) {
isConnected = true
gatt.discoverServices() //启动服务发现
@@ -49,12 +55,12 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
}
if(status==0){
if(newState==2){
Log.i(TAG,"与[${dev}]连接成功")
Log.i(TAG,"与[${dev.name}]连接成功")
}else{
Log.i(TAG,"与[${dev}]连接断开")
Log.i(TAG,"与[${dev.name}]连接断开")
}
}else{
Log.i(TAG,"与[${dev}]连接出错,错误码:$status")
Log.i(TAG,"与[${dev.name}]连接出错,错误码:$status")
if(status==133){
connect()
}
@@ -65,19 +71,6 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
Log.i(TAG,"onServicesDiscovered:${gatt.device.name},${gatt.device.address},${status}")
if (status == BluetoothGatt.GATT_SUCCESS) { //BLE服务发现成功
// 遍历获取BLE服务Services/Characteristics/Descriptors的全部UUID
for (service in gatt.services) {
val allUUIDs = StringBuilder(
"UUIDs={\n S=${service.uuid}".trimIndent()
)
for (characteristic in service.characteristics) {
allUUIDs.append(",\nC=").append(characteristic.uuid)
for (descriptor in characteristic.descriptors) {
allUUIDs.append(",\nD=").append(descriptor.uuid)
}
}
allUUIDs.append("}")
Log.i(TAG, "onServicesDiscovered:$allUUIDs")
}
// 链接成功 服务发现也成功后
waitSendData.forEach {
writeData2UUID(it.key,it.value)
@@ -107,31 +100,17 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
"onCharacteristicWrite:${gatt.device.name},${gatt.device.address},$uuid,$valueStr,$status"
)
if(status==BluetoothGatt.GATT_SUCCESS){
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","${device.name}:发送数据${valueStr} 小程序接受成功")
waitSendData.remove(valueStr)
closeConn()
connectListener?.sendDataSuccessAndCloseListener(device)
if(waitSendData.isEmpty()){
RxUtils.disposeSubscribe(timeoutCLose)
timeoutCLose = RxUtils.createSubscribeOnOwnThread(30_000) {
closeConn()
}
}
}
}
override fun onCharacteristicChanged(
gatt: BluetoothGatt,
characteristic: BluetoothGattCharacteristic
) {
val uuid = characteristic.uuid
val valueStr = String(characteristic.value)
Log.i(TAG,"onCharacteristicChanged:${gatt.device.name},${ gatt.device.address},$uuid,$valueStr")
}
override fun onDescriptorRead(
gatt: BluetoothGatt,
descriptor: BluetoothGattDescriptor,
status: Int
) {
val uuid = descriptor.uuid
val valueStr = descriptor.value.contentToString()
Log.i(TAG,"onDescriptorRead:${gatt.device.name},${gatt.device.address},$uuid,$valueStr,$status")
}
override fun onDescriptorWrite(
gatt: BluetoothGatt,
descriptor: BluetoothGattDescriptor,
@@ -142,29 +121,14 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
Log.i(TAG,"onDescriptorWrite:${gatt.device.name},${gatt.device.address},$uuid,$valueStr,$status")
}
private fun refreshDeviceCache(mBluetoothGatt: BluetoothGatt?): Boolean {
if (mBluetoothGatt != null) {
try {
val refresh = mBluetoothGatt.javaClass.getMethod("refresh")
if (refresh != null) {
return refresh.invoke(mBluetoothGatt) as Boolean
}
} catch (e: Exception) {
e.printStackTrace()
}
}
return false
}
// BLE中心设备连接外围设备的数量有限(大概2~7个)在建立新连接之前必须释放旧连接资源否则容易出现连接错误133
fun closeConn() {
if (mBluetoothGatt != null) {
mBluetoothGatt!!.disconnect()
mBluetoothGatt!!.close()
refreshDeviceCache(mBluetoothGatt)
mBluetoothGatt = null
isConnected = false
BleManager.copy2ScanList(this)
}
}
@@ -180,7 +144,7 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
// 注意连续频繁读写数据容易失败读写操作间隔最好200ms以上或等待上次回调完成后再进行下次读写操作
// 写入数据成功会回调->onCharacteristicWrite()
fun writeData2UUID(text:String,uuid: UUID){
private fun writeData2UUID(text:String,uuid: UUID){
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","发送数据${text}")
val service = getGattService(BleManager.UUID_SERVICE)
if (service != null) {
@@ -189,41 +153,16 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
mBluetoothGatt!!.writeCharacteristic(characteristic)
}
}
// 注意连续频繁读写数据容易失败读写操作间隔最好200ms以上或等待上次回调完成后再进行下次读写操作
// 读取数据成功会回调->onCharacteristicChanged()
fun readDataByUUId(uuid: UUID){
val service = getGattService(BleManager.UUID_SERVICE)
if (service != null) {
val characteristic =
service.getCharacteristic(uuid) //通过UUID获取可读的Characteristic
mBluetoothGatt!!.readCharacteristic(characteristic)
}
}
fun notifyByUUID(uuid: UUID,notify:UUID){
// 设置通知Characteristic变化会回调->onCharacteristicChanged()
val service = getGattService(BleManager.UUID_SERVICE)
if (service != null) {
// 设置Characteristic通知
val characteristic =
service.getCharacteristic(BleManager.UUID_CHAR_READ_NOTIFY) //通过UUID获取可通知的Characteristic
mBluetoothGatt!!.setCharacteristicNotification(characteristic, true)
// 向Characteristic的Descriptor属性写入通知开关使蓝牙设备主动向手机发送数据
val descriptor = characteristic.getDescriptor(BleManager.UUID_DESC_NOTITY)
// descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);//和通知类似,但服务端不主动发数据,只指示客户端读取数据
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
mBluetoothGatt!!.writeDescriptor(descriptor)
}
}
fun connectGatt(code: String, businessTime: Long) {
fun connectGattAndSend(data: String) {
RxUtils.disposeSubscribe(timeoutCLose)
if(isConnected){
ToastUtils.showShort("已连接成功")
writeData2UUID("$code,$businessTime",BleManager.UUID_CHAR_WRITE)
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","已连接成功")
writeData2UUID(data,BleManager.UUID_CHAR_WRITE)
}else {
connect()
waitSendData["$code,$businessTime"] = BleManager.UUID_CHAR_WRITE
waitSendData[data] = BleManager.UUID_CHAR_WRITE
}
}
@@ -234,11 +173,6 @@ class OchBluetoothGattCallback(device: BluetoothDevice) : BluetoothGattCallback(
return
}
currentTryCount += 1
mBluetoothGatt = device.connectGatt(AbsMogoApplication.getApp(), false, this)
}
interface ConnectListener{
fun connectChangeListener(){}
fun sendDataSuccessAndCloseListener(device: BluetoothDevice)
mBluetoothGatt = _device.connectGatt(AbsMogoApplication.getApp(), false, this)
}
}

View File

@@ -16,6 +16,7 @@ import com.mogo.och.data.bean.LineInfo;
import com.mogo.och.weaknet.constant.BusConst;
import com.mogo.och.weaknet.model.OrderModel;
import com.mogo.och.weaknet.model.LineModel;
import com.zhjt.mogo.adas.data.bean.MogoReport;
import java.util.concurrent.TimeUnit;
@@ -76,39 +77,11 @@ public class BusTrajectoryManager {
*/
public void onAutopilotGuardian(@Nullable MogoReportMsg.MogoReportMessage guardianInfo) {
if (guardianInfo == null || !guardianInfo.hasCode()) return;
if ("ISYS_INIT_TRAJECTORY_START".equals(guardianInfo.getCode())) {
// 1. 轨迹管理_轨迹开始下载本地已有对应轨迹也触发
CallerLogger.d(M_BUS + TAG, "onAutopilotGuardian() 轨迹开始下载");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹开始下载", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
// ToastUtils.showShort("轨迹开始下载");
if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START.equals(guardianInfo.getCode())) {
stopTrajReqLoop();
} else if ("ISYS_INIT_TRAJECTORY_SUCCESS".equals(guardianInfo.getCode())) {
// 2. 轨迹管理_轨迹下载成功本地已有对应轨迹也触发
CallerLogger.d(M_BUS + TAG, "onAutopilotGuardian() 轨迹下载成功");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载成功", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
// ToastUtils.showShort("轨迹下载成功");
} else if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS.equals(guardianInfo.getCode())) {
stopTrajReqLoop();
} else if ("ISYS_INIT_TRAJECTORY_FAILURE".equals(guardianInfo.getCode())) {
// 3. 轨迹管理_轨迹下载失败本地无对应轨迹
CallerLogger.d(M_BUS + TAG, "onAutopilotGuardian() " +
"轨迹下载失败,本地无对应轨迹");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载失败,本地无对应轨迹", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
// ToastUtils.showShort("轨迹下载失败,本地无对应轨迹");
} else if ("ISYS_INIT_TRAJECTORY_WARNING".equals(guardianInfo.getCode())) {
// 4. 轨迹管理_轨迹下载失败本地有对应轨迹认为成功
CallerLogger.d(M_BUS + TAG, "onAutopilotGuardian() " +
"轨迹下载失败,本地有对应轨迹,认为成功");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载失败,本地有对应轨迹,认为成功", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
// ToastUtils.showShort("轨迹下载失败,本地有对应轨迹,认为成功");
} else if ("ISYS_INIT_TRAJECTORY_TIMEOUT".equals(guardianInfo.getCode())) {
// 5. 轨迹管理_轨迹下载超时
CallerLogger.d(M_BUS + TAG, "onAutopilotGuardian() 轨迹下载超时");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载超时", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
// ToastUtils.showShort("轨迹下载超时");
} else if ("ISSM_FUNC_AUTO_PILOT_READY".equals(guardianInfo.getCode())) {
// 收到ssm的自动驾驶变为ready再次下发轨迹下载.解决域控重启或者102域控启动太早107节点初始化未完成导致的轨迹未进行下载。
CallerLogger.d(M_BUS + TAG, "onAutopilotGuardian() ssm ready再次发起下载");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 再次发起下载", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
} else if (MogoReport.Code.Info.ISSM.FUNC_AUTO_PILOT_READY.equals(guardianInfo.getCode())) {
syncTrajectoryInfo();
}
}

View File

@@ -6,10 +6,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.eagle.core.utilcode.util.RegexUtils
import com.mogo.och.common.module.manager.bluetooth.BleDevItem
import com.mogo.och.common.module.manager.bluetooth.BleManager
import com.mogo.och.common.module.manager.bluetooth.BleManager.BleDevListener
import com.mogo.och.common.module.manager.bluetooth.OchBluetoothGattCallback.ConnectListener
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
import com.mogo.och.common.module.manager.loop.BizLoopManager
import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
@@ -26,25 +23,6 @@ object TicketModel : StateChangeListener {
private const val TAG = "TicketModel"
// 等待链接
private val waitConnectDev = mutableListOf<BleDevItem>()
private val waitConnectDevNameList = mutableListOf<String>()
private val connectListener: ConnectListener = object : ConnectListener {
override fun sendDataSuccessAndCloseListener(device: BluetoothDevice) {
waitConnectDev.forEach {
if(it.dev==device){
waitConnectDev.remove(it)
return
}
}
}
}
init {
}
private val writeOffResultMsg = object : ILanMessageListener<WriteOffResultMsg> {
override fun targetLan(): Class<WriteOffResultMsg> = WriteOffResultMsg::class.java
@@ -57,31 +35,19 @@ object TicketModel : StateChangeListener {
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","去连接蓝牙并发送数据 次数:${count}")
// 收到核销结果扫描蓝牙并写会核销结果
obj?.phone?.let {phone->
var haveDevices = false
var tempRemove:BleDevItem?=null
waitConnectDev.forEach {
if(it.dev.name == getBleName(phone)){
haveDevices = true
OchChainLogManager.writeChainLogWriteOff("司机端核销结果","${obj}_找到设备dev.name:${it.dev.name}${getBleName(phone)}")
when (obj.code) {
99 -> {
it.gattcallback.connectGatt("99",obj.businessTime)
}
0 -> {
it.gattcallback.connectGatt("00",obj.businessTime)
}
else -> {
it.gattcallback.connectGatt("01",obj.businessTime)
}
}
it.gattcallback.connectListener = connectListener
tempRemove = it
return@forEach
val findDev = when (obj.code) {
99 -> {
BleManager.sendData2Wx(getBleName(phone),"99,${obj.businessTime}")
}
0 -> {
BleManager.sendData2Wx(getBleName(phone),"00,${obj.businessTime}")
}
else -> {
BleManager.sendData2Wx(getBleName(phone),"01,${obj.businessTime}")
}
}
waitConnectDev.remove(tempRemove)
if(!haveDevices&&count<6){
if(!findDev&&count<6){
RxUtils.createSubscribe {
// 没有找到设备重试5次
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","2s后重试")
@@ -91,36 +57,16 @@ object TicketModel : StateChangeListener {
}
}
private val bleDevs = object : BleDevListener{
@SuppressLint("MissingPermission")
@Synchronized
override fun dataChange(scanList: MutableList<BleDevItem>) {
val tempList = mutableListOf<String>()
waitConnectDevNameList.forEach { waitConnectName->
scanList.forEach {
if(it.dev.name==waitConnectName){
waitConnectDev.add(it)
tempList.add(waitConnectName)
}
}
}
waitConnectDevNameList.removeAll(tempList)
}
}
fun load(){
OchChainLogManager.writeChainLogInit("初始化信息","核销功能初始化")
ScannerManager.addStateChangeListener(TAG, this)
// 核销信息
LanSocketManager.registerSocketMessageListener(DPMsgType.TYPE_WRITEOFF_INFO_RESULT.type,writeOffResultMsg)
BleManager.listener = bleDevs
}
fun release(){
ScannerManager.removeListener(TAG)
LanSocketManager.unRegisterSocketMessageListener(DPMsgType.TYPE_WRITEOFF_INFO_RESULT.type,writeOffResultMsg)
BleManager.listener = null
}
override fun parseData(params: MutableMap<String, String>, payload: String?) {
@@ -163,7 +109,6 @@ object TicketModel : StateChangeListener {
)
CallerLogger.d(M_BUS_P + TAG, "sendTaskDetailsToClients = " + GsonUtils.toJson(writeOffDetail))
LanSocketManager.sendMsgToServer(writeOffDetail)
addWaitConnectDevName(phone)
scanBle()
}catch (e:Exception){
e.printStackTrace()
@@ -181,14 +126,6 @@ object TicketModel : StateChangeListener {
}
}
private fun addWaitConnectDevName(phone: String?) {
var tempPhone = phone
tempPhone?.let {
waitConnectDevNameList.add( getBleName(it))
}
}
fun getBleName(phone: String):String{
var tempPhone = phone
tempPhone.let {

View File

@@ -97,28 +97,8 @@ public class TaxiTrajectoryManager {
public void onAutopilotGuardian(@Nullable MogoReportMsg.MogoReportMessage guardianInfo) {
if (guardianInfo == null || !guardianInfo.hasCode()) return;
if ("ISYS_INIT_TRAJECTORY_START".equals(guardianInfo.getCode())) {
// 1. 轨迹管理_轨迹开始下载本地已有对应轨迹也触发
CallerLogger.d(M_TAXI + TAG, "onAutopilotGuardian() 轨迹开始下载");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹开始下载", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
stopTrajReqLoop();
} else if ("ISYS_INIT_TRAJECTORY_SUCCESS".equals(guardianInfo.getCode())) {
// 2. 轨迹管理_轨迹下载成功本地已有对应轨迹也触发
CallerLogger.d(M_TAXI + TAG, "onAutopilotGuardian() 轨迹下载成功");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载成功", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
stopTrajReqLoop();
} else if ("ISYS_INIT_TRAJECTORY_FAILURE".equals(guardianInfo.getCode())) {
// 3. 轨迹管理_轨迹下载失败本地无对应轨迹
CallerLogger.d(M_TAXI + TAG, "onAutopilotGuardian() " +
"轨迹下载失败,本地无对应轨迹");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载失败,本地无对应轨迹", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
} else if ("ISYS_INIT_TRAJECTORY_WARNING".equals(guardianInfo.getCode())) {
// 4. 轨迹管理_轨迹下载失败本地有对应轨迹认为成功
CallerLogger.d(M_TAXI + TAG, "onAutopilotGuardian() " +
"轨迹下载失败,本地有对应轨迹,认为成功");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载失败,本地有对应轨迹,认为成功", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
} else if ("ISYS_INIT_TRAJECTORY_TIMEOUT".equals(guardianInfo.getCode())) {
// 5. 轨迹管理_轨迹下载超时
CallerLogger.d(M_TAXI + TAG, "onAutopilotGuardian() 轨迹下载超时");
OchChainLogManager.writeChainLog("轨迹监控","onAutopilotGuardian() 轨迹下载超时", true, OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY);
}
}