Browse Source

调整蓝牙设备链接逻辑

master
白凤吉 4 months ago
parent
commit
0667dde1c9
  1. 11
      app/src/main/java/com/iflytop/profilometer/api/ble/BleApi.java
  2. 8
      app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java
  3. 25
      app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java
  4. 5
      app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java
  5. 15
      app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java
  6. 32
      app/src/main/java/com/iflytop/profilometer/model/bo/RailProfileMeasureTaskState.java
  7. 19
      app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java
  8. 5
      app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java

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

@ -43,6 +43,7 @@ public class BleApi {
public String stop() {
try {
BleWebsocketManager.getInstance().stopWsPush();
BleManager.getInstance().stopScan();
return Result.success();
} catch (Exception e) {
Log.e(TAG, "结束获取蓝牙设备列表失败", e);
@ -55,11 +56,15 @@ public class BleApi {
*/
public String connect(String mac) {
try {
BleWebsocketManager.getInstance().stopWsPush();
BleManager.getInstance().stopScan();//连接后停止扫描
BleManager.getInstance().connectToDevice(mac);
BlePingManager.getInstance().startPing();
return Result.success();
} catch (Exception e) {
BleWebsocketManager.getInstance().startWsPush();//链接失败后继续扫描并推送
BleManager.getInstance().startScan();
BlePingManager.getInstance().stopPing();
Log.e(TAG, "链接蓝牙设备失败", e);
return Result.failed("链接蓝牙设备失败");
}
@ -70,10 +75,14 @@ public class BleApi {
*/
public String disconnect() {
try {
BleManager.getInstance().startScan();//断开连接后开始扫描
BleManager.getInstance().disconnect();
BlePingManager.getInstance().stopPing();
BleManager.getInstance().startScan();//断开连接后开始扫描
return Result.success();
} catch (Exception e) {
BleWebsocketManager.getInstance().stopWsPush();//断开连接失败
BleManager.getInstance().stopScan();
BlePingManager.getInstance().startPing();
Log.e(TAG, "断开蓝牙设备链接失败", e);
return Result.failed("断开蓝牙设备链接失败");
}

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

@ -19,8 +19,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import cn.hutool.core.convert.impl.UUIDConverter;
import cn.hutool.core.lang.generator.UUIDGenerator;
import cn.hutool.json.JSONUtil;
/**
@ -84,10 +82,12 @@ public class MeasureApi {
profileRecordDao.insertProfileRecord(profileRecordDescription);
RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState();
List<XYPoint> xyPointList = taskState.getOutlinePointSetList();
List<XYPoint> leftPoint = taskState.getLeftPointSetList();
List<XYPoint> rightPoint = taskState.getRightPointSetList();
ProfileRecordPointSet profileRecordPointSet = new ProfileRecordPointSet();
profileRecordPointSet.setProfileRecordUuid(profileRecordDescription.getUuid());
profileRecordPointSet.setPoints(JSONUtil.toJsonStr(xyPointList));
profileRecordPointSet.setLeftPoints(JSONUtil.toJsonStr(leftPoint));
profileRecordPointSet.setRightPoints(JSONUtil.toJsonStr(rightPoint));
profileRecordPointSetDao.insertProfileRecordPointSet(profileRecordPointSet);
return Result.success();

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

@ -45,18 +45,19 @@ public class RecordApi {
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());
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("leftPoints", pointSet.getLeftPoints());
map.put("rightPoints", pointSet.getRightPoints());
map.put("createTime", profileRecordDescription.getCreateTime());
return Result.success(map);
}

5
app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java

@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteOpenHelper;
public class MyDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "app.db";
private static final int DATABASE_VERSION = 1; // 升级版本号
private static final int DATABASE_VERSION = 2; // 升级版本号
// 表名
public static final String TABLE_APP_USER = "app_user";
@ -52,7 +52,8 @@ public class MyDatabaseHelper extends SQLiteOpenHelper {
"CREATE TABLE IF NOT EXISTS " + TABLE_PROFILE_RECORD_POINT_SET + " ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "profile_record_uuid TEXT, "
+ "points TEXT, "
+ "left_points TEXT, "
+ "right_points TEXT, "
+ "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "
+ "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
+ ");";

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

@ -34,7 +34,8 @@ public class ProfileRecordPointSetDao {
values.put("create_time", currentTime);
values.put("update_time", currentTime);
values.put("profile_record_uuid", pointSet.getProfileRecordUuid());
values.put("points", pointSet.getPoints());
values.put("left_points", pointSet.getLeftPoints());
values.put("right_points", pointSet.getRightPoints());
long id = db.insert(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, values);
db.close();
return id;
@ -46,7 +47,8 @@ public class ProfileRecordPointSetDao {
ContentValues values = new ContentValues();
values.put("update_time", getCurrentTime());
values.put("profile_record_uuid", pointSet.getProfileRecordUuid());
values.put("points", pointSet.getPoints());
values.put("left_points", pointSet.getLeftPoints());
values.put("right_points", pointSet.getRightPoints());
int rows = db.update(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, values, "id = ?", new String[]{String.valueOf(pointSet.getId())});
db.close();
return rows;
@ -71,7 +73,8 @@ public class ProfileRecordPointSetDao {
ProfileRecordPointSet 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.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points")));
pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points")));
pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER));
pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER));
list.add(pointSet);
@ -92,7 +95,8 @@ public class ProfileRecordPointSetDao {
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.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points")));
pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_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();
@ -111,7 +115,8 @@ public class ProfileRecordPointSetDao {
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.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points")));
pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_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();

32
app/src/main/java/com/iflytop/profilometer/model/bo/RailProfileMeasureTaskState.java

@ -8,9 +8,13 @@ import java.util.List;
public class RailProfileMeasureTaskState {
/**
* 轮廓点集
* 左侧轮廓点集
*/
private transient List<XYPoint> outlinePointSetList = new ArrayList<>();
private transient List<XYPoint> leftPointSetList = new ArrayList<>();
/**
* 右侧轮廓采集点
*/
private transient List<XYPoint> rightPointSetList = new ArrayList<>();
/**
* 当前测量状态
*/
@ -49,7 +53,7 @@ public class RailProfileMeasureTaskState {
* 重置设备状态
*/
public void reset() {
this.outlinePointSetList.clear();
this.leftPointSetList.clear();
this.taskStatus = RailProfileMeasureTaskStatus.IDLE;
this.measureSideCnt = 0;
this.isMeasuringLeftEnd = false;
@ -61,15 +65,19 @@ public class RailProfileMeasureTaskState {
}
public void pushOutlinePoint(XYPoint point) {
outlinePointSetList.add(point);
if(isMeasuringLeftEnd){//左侧测量完毕
rightPointSetList.add(point);
}else{
leftPointSetList.add(point);
}
}
public List<XYPoint> getOutlinePointSetList() {
return outlinePointSetList;
public List<XYPoint> getLeftPointSetList() {
return leftPointSetList;
}
public void setOutlinePointSetList(List<XYPoint> outlinePointSetList) {
this.outlinePointSetList = outlinePointSetList;
public void setLeftPointSetList(List<XYPoint> leftPointSetList) {
this.leftPointSetList = leftPointSetList;
}
public RailProfileMeasureTaskStatus getTaskStatus() {
@ -135,4 +143,12 @@ public class RailProfileMeasureTaskState {
public void setSpeedDetected(Boolean speedDetected) {
isSpeedDetected = speedDetected;
}
public List<XYPoint> getRightPointSetList() {
return rightPointSetList;
}
public void setRightPointSetList(List<XYPoint> rightPointSetList) {
this.rightPointSetList = rightPointSetList;
}
}

19
app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java

@ -4,7 +4,8 @@ import com.iflytop.profilometer.common.base.BaseEntity;
public class ProfileRecordPointSet extends BaseEntity {
private String profileRecordUuid;
private String points;
private String leftPoints;
private String rightPoints;
public String getProfileRecordUuid() {
return profileRecordUuid;
@ -14,11 +15,19 @@ public class ProfileRecordPointSet extends BaseEntity {
this.profileRecordUuid = profileRecordUuid;
}
public String getPoints() {
return points;
public String getLeftPoints() {
return leftPoints;
}
public void setPoints(String points) {
this.points = points;
public void setLeftPoints(String leftPoints) {
this.leftPoints = leftPoints;
}
public String getRightPoints() {
return rightPoints;
}
public void setRightPoints(String rightPoints) {
this.rightPoints = rightPoints;
}
}

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

@ -14,7 +14,9 @@ import com.iflytop.profilometer.core.system.SystemService;
import com.iflytop.profilometer.core.websocket.WebSocketManager;
import com.iflytop.profilometer.model.bo.RailProfileMeasureTaskState;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.json.JSONUtil;
@ -100,6 +102,9 @@ public class RailProfileDrawerService implements RailProfileDrawerListener {
if (side == MeasureSide.LEFT) {
map.put("data", RailProfileMeasureTaskEvent.FINISH_RECORD_LEFT);
taskState.setMeasuringLeftEnd(true);
//左侧测量完毕后将数据反转
// List<XYPoint> outlinePointSetList = taskState.getOutlinePointSetList();
// Collections.reverse(outlinePointSetList);
} else if (side == MeasureSide.RIGHT) {
map.put("data", RailProfileMeasureTaskEvent.FINISH_RECORD_RIGHT);
taskState.setMeasuringRightEnd(true);

Loading…
Cancel
Save