Browse Source

调整蓝牙相关接口

master
白凤吉 4 months ago
parent
commit
80a3b779cd
  1. 5
      app/src/main/java/com/iflytop/profilometer/MainActivity.java
  2. 3
      app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java
  3. 3
      app/src/main/java/com/iflytop/profilometer/api/ble/BleApi.java
  4. 2
      app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java
  5. 22
      app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java
  6. 28
      app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java
  7. 112
      app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java
  8. 8
      app/src/main/java/com/iflytop/profilometer/core/system/DeviceState.java
  9. 34
      app/src/main/java/com/iflytop/profilometer/core/websocket/WebSocketManager.kt
  10. 19
      app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java
  11. 32
      app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java

5
app/src/main/java/com/iflytop/profilometer/MainActivity.java

@ -12,8 +12,6 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.iflytop.profilometer.api.ws.BleWebsocketManager;
import com.iflytop.profilometer.api.ws.DeviceStateWebsocketManager;
import com.iflytop.profilometer.core.bluetooth.BleManager;
import com.iflytop.profilometer.server.HttpServer;
@ -43,7 +41,8 @@ public class MainActivity extends AppCompatActivity {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadUrl("http://127.0.0.1:8080/");
// webView.loadUrl("http://127.0.0.1:8080/");
webView.loadUrl("http://192.168.1.112:3000/");
bleManager = BleManager.getInstance(this);
// 针对 Android 12 及以上版本请求必要的运行时权限

3
app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java

@ -6,6 +6,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import com.iflytop.profilometer.api.ws.DeviceStateWebsocketManager;
import com.iflytop.profilometer.dao.BaseProfileRecordPointSetDao;
import com.iflytop.profilometer.dao.UserDao;
import com.iflytop.profilometer.model.entity.BaseProfileRecordPointSet;
@ -17,6 +18,8 @@ public class ProfilometerApplication extends Application {
public void onCreate() {
super.onCreate();
DeviceStateWebsocketManager.getInstance().startWsPush();
UserDao userDao = new UserDao(this);
userDao.insertAdminUserIfNotExists();

3
app/src/main/java/com/iflytop/profilometer/api/ble/BleApi.java

@ -54,8 +54,6 @@ public class BleApi {
public String connect(String mac) {
try {
BleManager.getInstance().connectToDevice(mac);
DeviceStateWebsocketManager.getInstance().startWsPush();
BlePingManager.getInstance().startPing();
return Result.success();
} catch (Exception e) {
@ -70,7 +68,6 @@ public class BleApi {
public String disconnect() {
try {
BleManager.getInstance().disconnect();
DeviceStateWebsocketManager.getInstance().stopWsPush();
return Result.success();
} catch (Exception e) {
Log.e(TAG, "断开蓝牙设备链接失败", e);

2
app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java

@ -2,6 +2,7 @@ package com.iflytop.profilometer.api.measure;
import android.content.Context;
import com.iflytop.profilometer.common.enums.SyncStatus;
import com.iflytop.profilometer.common.result.Result;
import com.iflytop.profilometer.core.bluetooth.BleDeviceDriver;
import com.iflytop.profilometer.core.migration.measure.drawer.type.RailProfileMeasureTaskStatus;
@ -79,6 +80,7 @@ public class MeasureApi {
profileRecordDescription.setLineName(params.get("lineName"));//线路名称
profileRecordDescription.setLocation(params.get("location"));//位置
profileRecordDescription.setDirection(params.get("direction"));//行车方向
profileRecordDescription.setSyncStatus(SyncStatus.wait);
profileRecordDao.insertProfileRecord(profileRecordDescription);
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();

22
app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java

@ -5,6 +5,7 @@ import android.content.Context;
import com.iflytop.profilometer.common.result.Result;
import com.iflytop.profilometer.dao.ProfileRecordDao;
import com.iflytop.profilometer.dao.ProfileRecordPointSetDao;
import com.iflytop.profilometer.model.entity.ProfileRecordDescription;
import com.iflytop.profilometer.model.entity.ProfileRecordPointSet;
import java.util.HashMap;
@ -38,9 +39,26 @@ public class RecordApi {
* 测量记录详情
*/
public String detail(Long id) {
ProfileRecordDao profileRecordDao = new ProfileRecordDao(context);
ProfileRecordPointSetDao profileRecordPointSetDao = new ProfileRecordPointSetDao(context);
ProfileRecordPointSet pointSet = profileRecordPointSetDao.getProfileRecordPointSetById(id);
return Result.success(pointSet);
ProfileRecordDescription profileRecordDescription = profileRecordDao.getProfileRecordById(id);
ProfileRecordPointSet pointSet = profileRecordPointSetDao.getProfileRecordPointSetByUuid(profileRecordDescription.getUuid());
Map<String, Object> map = new HashMap<>();
map.put("id",profileRecordDescription.getId());
map.put("uuid",profileRecordDescription.getUuid());
map.put("operatorName",profileRecordDescription.getOperatorName());
map.put("trackShapeCode",profileRecordDescription.getTrackShapeCode());
map.put("verificationMethodCode",profileRecordDescription.getVerificationMethodCode());
map.put("name",profileRecordDescription.getName());
map.put("lineName",profileRecordDescription.getLineName());
map.put("location",profileRecordDescription.getLocation());
map.put("direction",profileRecordDescription.getDirection());
map.put("syncStatus",profileRecordDescription.getSyncStatus());
map.put("points",pointSet.getPoints());
map.put("createTime",profileRecordDescription.getCreateTime());
return Result.success(map);
}
/**

28
app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java

@ -48,18 +48,30 @@ public class BleWebsocketManager {
listMap.put("type", "ble-list");
List<Map<String, Object>> bleList = new ArrayList<>();
BluetoothGatt gatt = BleManager.getInstance().getBluetoothGatt();
for (BluetoothDevice bluetoothDevice : scannedDevices) {
if (gatt != null) {
Map<String, Object> bleMap = new HashMap<>();
BluetoothDevice gattDevice = gatt.getDevice();
bleMap.put("mac", gattDevice.getAddress());
bleMap.put("name", gattDevice.getName());
bleMap.put("linked", true);
bleList.add(bleMap);
}
for (BluetoothDevice bluetoothDevice : scannedDevices) {
String mac = bluetoothDevice.getAddress();
bleMap.put("mac", mac);
bleMap.put("name", bluetoothDevice.getName() == null ? "未命名" : bluetoothDevice.getName());
if (gatt != null && mac.equals(gatt.getDevice().getAddress())) {
bleMap.put("linked", true);
} else {
bleMap.put("linked", false);
boolean exists = bleList.stream() .anyMatch(map -> mac.equals(map.get("mac")));
if(! exists){
Map<String, Object> bleMap = new HashMap<>();
bleMap.put("mac", mac);
bleMap.put("name", bluetoothDevice.getName() == null ? "未命名" : bluetoothDevice.getName());
if (gatt != null && mac.equals(gatt.getDevice().getAddress())) {
bleMap.put("linked", true);
} else {
bleMap.put("linked", false);
}
bleList.add(bleMap);
}
bleList.add(bleMap);
}
bleList.sort(Comparator.comparing(map -> (String) map.get("mac")));
listMap.put("data", bleList);
WebSocketManager.send(JSONUtil.toJsonStr(listMap));
}, 0, 2000, TimeUnit.MILLISECONDS);

112
app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java

@ -28,12 +28,15 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.iflytop.profilometer.core.migration.channel.BleDeviceUartChannel;
import com.iflytop.profilometer.core.system.DeviceState;
import com.iflytop.profilometer.core.system.SystemService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
@ -48,8 +51,10 @@ public class BleManager {
private final BluetoothManager bluetoothManager;
private BluetoothAdapter bluetoothAdapter;
private BluetoothLeScanner bluetoothLeScanner;
// 仅添加支持目标服务的设备
private final List<BluetoothDevice> scannedDevices = new ArrayList<>();
private ScanCallback scanCallback;
// 设备连接后的通信回调用于 connectToDevice 方法
private BluetoothGatt bluetoothGatt;
private final Context context;
@ -60,13 +65,15 @@ public class BleManager {
public static final UUID CLIENT_CHARACTERISTIC_CONFIG_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
//扫描时设备实时性管理
// 超时阈值10秒内未更新则认为设备已消失
private static final long DEVICE_TIMEOUT = 10000;
// 超时阈值20秒内未更新则认为设备已消失
private static final long DEVICE_TIMEOUT = 20000;
// 清理间隔每5秒执行一次清理任务
private static final long CLEANUP_INTERVAL = 5000;
private final Handler cleanupHandler = new Handler(Looper.getMainLooper());
// 记录设备最后出现时间
private final Map<BluetoothDevice, Long> deviceLastSeenMap = new HashMap<>();
// 记录已经进行服务查询的设备 MAC 地址为 key避免重复连接
private final Set<String> processedDevices = new HashSet<>();
// 数据回调接口外部可以通过此接口接收 BLE 设备返回的数据
public interface BleDataListener {
@ -85,7 +92,7 @@ public class BleManager {
this.bleDataListener = listener;
}
// 定时清理 Runnable
// 定时清理 Runnable移除超时设备同时清除 processedDevices 中的记录
private final Runnable cleanupRunnable = new Runnable() {
@SuppressLint("MissingPermission")
@Override
@ -101,6 +108,7 @@ public class BleManager {
for (BluetoothDevice device : toRemove) {
deviceLastSeenMap.remove(device);
scannedDevices.remove(device);
processedDevices.remove(device.getAddress());
Log.d(TAG, "移除超时设备: " + device.getName() + " - " + device.getAddress());
}
}
@ -108,7 +116,7 @@ public class BleManager {
}
};
// BluetoothGattCallback 处理连接服务发现通知及数据写入结果
// 原有的 BluetoothGattCallback 用于设备连接后的通信处理
private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
@SuppressLint("MissingPermission")
@Override
@ -119,6 +127,8 @@ public class BleManager {
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.d(TAG, "设备已断开连接");
bluetoothGatt = null;
DeviceState deviceState = SystemService.getInstance().getDeviceState();
deviceState.setConnected(false);
}
}
@ -147,10 +157,8 @@ public class BleManager {
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
// 收到通知数据后将数据通过回调接口传递出去
if (NOTIFY_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) {
byte[] data = characteristic.getValue();
// Log.d(TAG, "收到通知数据: " + new String(data));
if (bleDataListener != null) {
bleDataListener.onDataReceived(data);
}
@ -160,7 +168,7 @@ public class BleManager {
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// Log.d(TAG, "数据写入成功");
// 数据写入成功
} else {
Log.e(TAG, "数据写入失败,错误码:" + status);
}
@ -168,6 +176,51 @@ public class BleManager {
};
/**
* 内部类用于扫描过程中连接设备后进行服务查询判断设备是否支持目标服务
*/
private class ServiceDiscoveryGattCallback extends BluetoothGattCallback {
private final BluetoothDevice device;
public ServiceDiscoveryGattCallback(BluetoothDevice device) {
this.device = device;
}
@SuppressLint("MissingPermission")
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.d(TAG, "已连接到 " + device.getAddress() + ",开始发现服务");
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.d(TAG, "与 " + device.getAddress() + " 断开连接");
gatt.close();
}
}
@SuppressLint("MissingPermission")
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.d(TAG, "在 " + device.getAddress() + " 上发现服务");
BluetoothGattService service = gatt.getService(SERVICE_UUID);
if (service != null) {
// 设备支持目标服务添加到 scannedDevices 列表切换到主线程操作
new Handler(Looper.getMainLooper()).post(() -> {
if (!scannedDevices.contains(device)) {
scannedDevices.add(device);
Log.d(TAG, "设备 " + device.getName() + " 支持目标服务,已添加");
}
});
} else {
Log.d(TAG, "设备 " + device.getAddress() + " 不支持目标服务");
}
}
// 完成服务发现后断开连接
gatt.disconnect();
}
}
/**
* 私有构造函数防止外部直接实例化
*
* @param context 上下文
@ -239,7 +292,7 @@ public class BleManager {
}
/**
* 开始扫描 BLE 设备并记录扫描到设备的最后出现时间定时清理超时设备
* 开始扫描 BLE 设备扫描到的每个设备均依次连接进行服务查询
*/
@SuppressLint("MissingPermission")
public void startScan() {
@ -256,31 +309,45 @@ public class BleManager {
Log.e(TAG, "获取 BluetoothLeScanner 失败");
return;
}
// 清空之前的数据
scannedDevices.clear();
deviceLastSeenMap.clear();
processedDevices.clear();
scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice device = result.getDevice();
if (device != null) {
deviceLastSeenMap.put(device, System.currentTimeMillis());
if (!scannedDevices.contains(device)) {
scannedDevices.add(device);
Log.d(TAG, "发现设备: " + device.getName() + " - " + device.getAddress());
if (device != null && device.getName() != null) {
if (result.getScanRecord() != null) {
deviceLastSeenMap.put(device, System.currentTimeMillis());
}
String address = device.getAddress();
// 如果该设备已经处理过则跳过连接
if (processedDevices.contains(address)) {
return;
}
processedDevices.add(address);
// 对扫描到的设备进行连接查询服务
device.connectGatt(context, false, new ServiceDiscoveryGattCallback(device));
}
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
for (ScanResult result : results) {
BluetoothDevice device = result.getDevice();
if (device != null) {
deviceLastSeenMap.put(device, System.currentTimeMillis());
if (!scannedDevices.contains(device)) {
scannedDevices.add(device);
Log.d(TAG, "批量发现设备: " + device.getName() + " - " + device.getAddress());
if(device != null && device.getName() != null){
if (result.getScanRecord() != null) {
deviceLastSeenMap.put(device, System.currentTimeMillis());
}
String address = device.getAddress();
if (processedDevices.contains(address)) {
continue;
}
processedDevices.add(address);
device.connectGatt(context, false, new ServiceDiscoveryGattCallback(device));
}
}
}
@ -290,6 +357,8 @@ public class BleManager {
Log.e(TAG, "BLE 扫描失败,错误码:" + errorCode);
}
};
// 开始扫描此处未使用 ScanFilter若设备广播中包含目标服务 UUID 也可添加过滤器
bluetoothLeScanner.startScan(scanCallback);
cleanupHandler.postDelayed(cleanupRunnable, CLEANUP_INTERVAL);
}
@ -314,7 +383,7 @@ public class BleManager {
}
/**
* 返回当前扫描到的设备列表仅包含实时在线设备
* 返回当前扫描到的设备列表仅包含支持目标服务的设备
*/
public List<BluetoothDevice> getScannedDevices() {
return scannedDevices;
@ -356,7 +425,8 @@ public class BleManager {
BleDeviceUartChannel channel = SystemService.getInstance().getChannel();
channel.init();
channel.setDeviceOnReportListener(new BleDeviceListener());
DeviceState deviceState = SystemService.getInstance().getDeviceState();
deviceState.setConnected(true);
} catch (IllegalArgumentException e) {
Log.e(TAG, "无效的 MAC 地址: " + macAddress, e);
}
@ -397,6 +467,8 @@ public class BleManager {
bluetoothGatt.disconnect();
bluetoothGatt.close();
bluetoothGatt = null;
DeviceState deviceState = SystemService.getInstance().getDeviceState();
deviceState.setConnected(false);
Log.d(TAG, "当前蓝牙设备已断开连接");
}
}

8
app/src/main/java/com/iflytop/profilometer/core/system/DeviceState.java

@ -1,7 +1,7 @@
package com.iflytop.profilometer.core.system;
public class DeviceState {
private Boolean isConnected;
private Boolean connected;
private Integer power;
private Integer state;
private Integer flag;
@ -10,7 +10,7 @@ public class DeviceState {
private Double temperature;
public DeviceState() {
isConnected = false;
connected = false;
power = 0;
state = 0;
flag = 0;
@ -20,11 +20,11 @@ public class DeviceState {
}
public Boolean getConnected() {
return isConnected;
return connected;
}
public void setConnected(Boolean connected) {
isConnected = connected;
this.connected = connected;
}
public Integer getPower() {

34
app/src/main/java/com/iflytop/profilometer/core/websocket/WebSocketManager.kt

@ -2,15 +2,30 @@ package com.iflytop.profilometer.core.websocket
import io.ktor.websocket.Frame
import io.ktor.websocket.WebSocketSession
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
import java.util.Collections
object WebSocketManager {
// 线程安全的 WebSocket 会话集合
private val sessions = Collections.synchronizedSet<WebSocketSession>(mutableSetOf())
// 使用 actor 模式保证消息顺序发送。actor 会在内部依次处理所有接收到的消息。
private val sendActor = GlobalScope.actor<String>(capacity = Channel.UNLIMITED) {
for (message in channel) {
sessions.forEach { session ->
try {
// suspend 调用,但在 actor 内部运行
session.send(Frame.Text(message))
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}
fun addSession(session: WebSocketSession) {
sessions.add(session)
}
@ -20,19 +35,12 @@ object WebSocketManager {
}
/**
*
*
*
*/
@OptIn(DelicateCoroutinesApi::class)
@JvmStatic
fun send(message: String) {
GlobalScope.launch {
sessions.forEach { session ->
try {
session.send(Frame.Text(message))
} catch (e: Exception) {
e.printStackTrace()
}
}
}
// 直接将消息发送到 actor 中,actor 内部保证先进先出顺序处理消息
sendActor.trySend(message)
}
}

19
app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java

@ -101,6 +101,25 @@ public class ProfileRecordPointSetDao {
return pointSet;
}
// 根据 uuid 查询测量点集记录
@SuppressLint("Range")
public ProfileRecordPointSet getProfileRecordPointSetByUuid(String uuid) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.query(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, "profile_record_uuid = ?", new String[]{uuid}, null, null, null);
ProfileRecordPointSet pointSet = null;
if (cursor.moveToFirst()) {
pointSet = new ProfileRecordPointSet();
pointSet.setId(cursor.getLong(cursor.getColumnIndex("id")));
pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid")));
pointSet.setPoints(cursor.getString(cursor.getColumnIndex("points")));
pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER));
pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER));
cursor.close();
}
db.close();
return pointSet;
}
private String getCurrentTime() {
return LocalDateTime.now().format(FORMATTER);
}

32
app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java

@ -23,7 +23,7 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
private final RailProfileDrawer railProfileDrawer = new RailProfileDrawer(this);
public void processStateReport(TPMIPacket packet) {
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
if (taskState.getTaskStatus().equals(RailProfileMeasureTaskStatus.IDLE) || taskState.getTaskStatus().equals(RailProfileMeasureTaskStatus.FINISHED)) {
return;
}
@ -31,6 +31,7 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
railProfileDrawer.processRawEncoderData(report.getArm1Angle(), report.getArm2Angle());
}
}
/**
* 新的质心位置
*/
@ -45,7 +46,7 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
@Override
public void onProfilePointPos(XYPoint xyPoint) {
// Log.i("RailProfileDrawerService","新的轮廓点位置");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
taskState.pushOutlinePoint(xyPoint);
Map<String, Object> map = new HashMap<>();
@ -59,14 +60,14 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
*/
@Override
public void onStartRecordProfileSig(MeasureSide side) {
Log.i("RailProfileDrawerService","开始记录轮廓点信号");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
Log.i("RailProfileDrawerService", "开始记录轮廓点信号");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
taskState.setTaskStatus(RailProfileMeasureTaskStatus.MEASURING);
Map<String, Object> map = new HashMap<>();
map.put("type", "measure-event");
if (side == MeasureSide.LEFT) {
map.put("data", RailProfileMeasureTaskEvent.START_RECORD_LEFT);
}else{
} else {
map.put("data", RailProfileMeasureTaskEvent.START_RECORD_RIGHT);
}
WebSocketManager.send(JSONUtil.toJsonStr(map));
@ -77,8 +78,8 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
*/
@Override
public void onErrorStartRecordProfileSig() {
Log.i("RailProfileDrawerService","用户启动记录方向错误");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
Log.i("RailProfileDrawerService", "用户启动记录方向错误");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
taskState.setWrongSide(true);
Map<String, Object> map = new HashMap<>();
@ -92,8 +93,8 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
*/
@Override
public void onEndRecordProfileSig(MeasureSide side, Boolean finished) {
Log.i("RailProfileDrawerService","结束记录轮廓点信号");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
Log.i("RailProfileDrawerService", "结束记录轮廓点信号");
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
Map<String, Object> map = new HashMap<>();
map.put("type", "measure-event");
if (side == MeasureSide.LEFT) {
@ -108,12 +109,13 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
if (finished) {
taskState.setTaskStatus(RailProfileMeasureTaskStatus.FINISHED);
map.put("data", RailProfileMeasureTaskEvent.FINISH_RECORD);
} else {
taskState.setTaskStatus(RailProfileMeasureTaskStatus.WAITING_FOR_MEASURING);
map.put("data", RailProfileMeasureTaskEvent.END_RECORD);
WebSocketManager.send(JSONUtil.toJsonStr(map));
}
WebSocketManager.send(JSONUtil.toJsonStr(map));
// else {
// taskState.setTaskStatus(RailProfileMeasureTaskStatus.WAITING_FOR_MEASURING);
// map.put("data", RailProfileMeasureTaskEvent.END_RECORD);
// }
}
/**
@ -121,7 +123,7 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
*/
@Override
public void onErrorSpeedDetected() {
Log.i("RailProfileDrawerService","移动超速,图像可能会发生失真");
Log.i("RailProfileDrawerService", "移动超速,图像可能会发生失真");
Map<String, Object> map = new HashMap<>();
map.put("type", "measure-event");
map.put("data", RailProfileMeasureTaskEvent.SPEED_DETECTED);

Loading…
Cancel
Save