From 65cb50eab917cc8ac8b36c86de04dfb323dd2bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Tue, 15 Apr 2025 09:24:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=87=87=E9=9B=86=E7=AE=97?= =?UTF-8?q?=E6=B3=95=20=E8=B0=83=E6=95=B4=E4=BF=9D=E5=AD=98=E6=B5=8B?= =?UTF-8?q?=E9=87=8F=E7=BB=93=E6=9E=9Capi=E5=A2=9E=E5=8A=A0=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profilometer/ProfilometerApplication.java | 2 +- .../profilometer/api/measure/MeasureApi.java | 11 ++ .../core/bluetooth/BleDeviceDriver.java | 6 +- .../core/bluetooth/BleDeviceListener.java | 7 +- .../profilometer/core/bluetooth/BleManager.java | 28 +++-- .../core/db/helper/MyDatabaseHelper.java | 2 +- .../migration/channel/BleDeviceUartChannel.java | 114 ++++++++++----------- .../core/migration/config/AppConstantConfig.java | 9 ++ .../core/migration/measure/AppConstantConfig.java | 9 -- .../measure/drawer/RailProfileDrawer.java | 20 ++-- .../drawer/type/RailProfileDrawerState.java | 2 +- .../migration/measure/drawer/type/XYPoint.java | 8 ++ .../core/migration/type/protocol/TPMIPacket.java | 3 + .../migration/type/protocol/TPMIPosReport.java | 43 +++++--- .../model/entity/ProfileRecordPointSet.java | 9 ++ .../service/RailProfileDrawerService.java | 15 +-- 16 files changed, 170 insertions(+), 118 deletions(-) create mode 100644 app/src/main/java/com/iflytop/profilometer/core/migration/config/AppConstantConfig.java delete mode 100644 app/src/main/java/com/iflytop/profilometer/core/migration/measure/AppConstantConfig.java diff --git a/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java b/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java index 3aa1f41..1fa9f19 100644 --- a/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java +++ b/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java @@ -70,7 +70,7 @@ public class ProfilometerApplication extends Application { userDao.insertAdminUserIfNotExists(); BaseProfileRecordPointSetDao baseProfileRecordPointSetDao = new BaseProfileRecordPointSetDao(this); - BaseProfileRecordPointSet baseProfileRecordPointSet = baseProfileRecordPointSetDao.getBaseProfileRecordPointSetByCode("60"); + BaseProfileRecordPointSet baseProfileRecordPointSet = baseProfileRecordPointSetDao.getBaseProfileRecordPointSetByCode("GX-60"); if (baseProfileRecordPointSet == null) { baseProfileRecordPointSet = new BaseProfileRecordPointSet(); baseProfileRecordPointSet.setName("60型标准轨"); diff --git a/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java b/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java index a9a14ee..367eddb 100644 --- a/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java +++ b/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java @@ -109,6 +109,17 @@ public class MeasureApi { profileRecordPointSet.setProfileRecordUuid(profileRecordDescription.getUuid()); profileRecordPointSet.setLeftPoints(JSONUtil.toJsonStr(leftPoint)); profileRecordPointSet.setRightPoints(JSONUtil.toJsonStr(rightPoint)); + List alignPoints = JSONUtil.toList(params.get("alignPoints"), XYPoint.class); + if (alignPoints == null || alignPoints.isEmpty()) { + alignPoints = taskState.getAlignPointSetList(); + } + if (alignPoints.isEmpty()) { + List leftPointsRevers = new ArrayList<>(leftPoint); + Collections.reverse(leftPointsRevers); + alignPoints.addAll(leftPointsRevers); + alignPoints.addAll(rightPoint); + } + profileRecordPointSet.setAlignPoints(JSONUtil.toJsonStr(alignPoints)); profileRecordPointSetDao.insertProfileRecordPointSet(profileRecordPointSet); return Result.success(); diff --git a/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceDriver.java b/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceDriver.java index 77c9623..d7c2de5 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceDriver.java +++ b/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceDriver.java @@ -1,14 +1,14 @@ package com.iflytop.profilometer.core.bluetooth; import com.iflytop.profilometer.core.migration.channel.BleDeviceUartChannel; +import com.iflytop.profilometer.core.migration.config.AppConstantConfig; import com.iflytop.profilometer.core.migration.factory.TPMIPacketFactory; -import com.iflytop.profilometer.core.migration.measure.AppConstantConfig; import com.iflytop.profilometer.core.migration.type.DeviceAppearance; import com.iflytop.profilometer.core.migration.type.protocol.TPMIPacket; import com.iflytop.profilometer.model.bo.RailProfileMeasureTaskState; public class BleDeviceDriver { - static final public Integer CMD_OVERTIME = 50; + static final public Integer CMD_OVERTIME = 2000; private final BleDeviceUartChannel uartChannel; private RailProfileMeasureTaskState taskState = new RailProfileMeasureTaskState(); @@ -56,7 +56,7 @@ public class BleDeviceDriver { * 启动位移采样(启动测量) */ public void startSampling() { - TPMIPacket packet = TPMIPacketFactory.buildStartPosSampleCmd(AppConstantConfig.POINT_REPORT_PERIOD); + TPMIPacket packet = TPMIPacketFactory.buildStartPosSampleCmd(AppConstantConfig.SAMPLE_PERIOD); uartChannel.sendCommand(packet, CMD_OVERTIME); } diff --git a/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceListener.java b/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceListener.java index d013023..f6635c6 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceListener.java +++ b/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceListener.java @@ -26,9 +26,10 @@ public class BleDeviceListener implements BleDeviceOnReportListener { @Override public void onPosReport(TPMIPosReport report) { -// Log.i(TAG, "位置信息上报:"); -// Log.i(TAG, "ARM0角度 " + report.getArm1Angle()); -// Log.i(TAG, "ARM1角度" + report.getArm2Angle()); +// Log.i(TAG, "位置信息上报:" + report.getIndexAsInt()); +// for (int i = 0; i < report.getPosReportNum(); i++) { +// Log.i(TAG, "ARM0角度 " + report.getArm1Angle(i) + " ARM1角度 " + report.getArm2Angle(i)); +// } RailProfileDrawerService railProfileDrawerService = SystemService.getInstance().getRailProfileDrawerService(); railProfileDrawerService.processStateReport(report); } diff --git a/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java b/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java index 80813e0..858d833 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java +++ b/app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleManager.java @@ -10,6 +10,7 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCallback; import android.bluetooth.BluetoothGattCharacteristic; +import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; @@ -459,14 +460,28 @@ public class BleManager { @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { + Log.d(TAG, "服务发现成功,目标服务存在"); + // 获取目标服务 BluetoothGattService service = gatt.getService(SERVICE_UUID); if (service != null) { - Log.d(TAG, "服务发现成功,目标服务存在"); - connectionSuccess.set(true); - } else { - Log.e(TAG, "服务发现成功,但未找到目标服务"); - connectionSuccess.set(false); + // 获取通知特征 + BluetoothGattCharacteristic notifyCharacteristic = service.getCharacteristic(NOTIFY_CHARACTERISTIC_UUID); + if (notifyCharacteristic != null) { + // 启用通知 + gatt.setCharacteristicNotification(notifyCharacteristic, true); + // 获取描述符 + BluetoothGattDescriptor descriptor = notifyCharacteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_UUID); + if (descriptor != null) { + descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); + gatt.writeDescriptor(descriptor); + } else { + Log.e(TAG, "未发现描述符 " + CLIENT_CHARACTERISTIC_CONFIG_UUID); + } + } else { + Log.e(TAG, "未发现通知特征 " + NOTIFY_CHARACTERISTIC_UUID); + } } + connectionSuccess.set(true); } else { Log.e(TAG, "服务发现失败,错误码:" + status); connectionSuccess.set(false); @@ -476,6 +491,7 @@ public class BleManager { } } + @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { if (NOTIFY_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) { @@ -490,7 +506,7 @@ public class BleManager { public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status != BluetoothGatt.GATT_SUCCESS) { Log.i(TAG, "数据写入失败,错误码:" + status); - }else{ + } else { Log.i(TAG, "数据写入成功" + status); } } diff --git a/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java b/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java index bbf4a17..6cc79cc 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java +++ b/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 = 11; // 升级版本号 + private static final int DATABASE_VERSION = 12; // 升级版本号 // 表名 public static final String TABLE_APP_USER = "app_user"; diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/channel/BleDeviceUartChannel.java b/app/src/main/java/com/iflytop/profilometer/core/migration/channel/BleDeviceUartChannel.java index d9df5d9..1004eb1 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/channel/BleDeviceUartChannel.java +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/channel/BleDeviceUartChannel.java @@ -9,25 +9,27 @@ import com.iflytop.profilometer.core.migration.type.protocol.TPMIBasicReport; import com.iflytop.profilometer.core.migration.type.protocol.TPMIPacket; import com.iflytop.profilometer.core.migration.type.protocol.TPMIPosReport; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; +import java.nio.ByteBuffer; +import java.util.concurrent.*; public class BleDeviceUartChannel { - public interface OnBleReportListener { void onReportReceived(TPMIPacket packet); } private OnBleReportListener reportListener; private BleDeviceOnReportListener deviceOnReportListener; - private final byte[] buffer = new byte[1024]; - private int bufferLen = 0; + private final ByteBuffer receiveBuffer = ByteBuffer.allocate(10240); private final CommandTransactionContext ctCxt = new CommandTransactionContext(); + private final BlockingQueue reportPacketList = new ArrayBlockingQueue<>(100); - private BlockingQueue reportPacketList = new ArrayBlockingQueue<>(100); + private final ExecutorService bleExecutor = Executors.newSingleThreadExecutor(r -> { + Thread t = new Thread(r); + t.setName("ble-handler-thread"); + t.setPriority(Thread.MAX_PRIORITY); + return t; + }); public static class CommandTransactionContext { private TPMIPacket txPacket; @@ -42,7 +44,7 @@ public class BleDeviceUartChannel { } synchronized TPMIPacket clearCtCxt() { - var packet = this.rxPacket; + TPMIPacket packet = this.rxPacket; this.rxPacket = null; this.txPacket = null; this.semaphore = null; @@ -50,19 +52,12 @@ public class BleDeviceUartChannel { return packet; } - void waitCxt(Integer overtime) throws InterruptedException { - this.semaphore.tryAcquire(overtime, TimeUnit.MILLISECONDS); + void waitCxt(Integer timeoutMs) throws InterruptedException { + this.semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS); } synchronized void trySetReceiptPacket(TPMIPacket packet) { - if (this.txPacket == null) { -// log.warn("rx receipt but no tx packet, ignore"); - return; - } - if (this.waitIndex != packet.getIndex()) { -// log.warn("rx receipt but index not match, expect {}, but {}", this.waitIndex, packet.getIndex()); - return; - } + if (txPacket == null || waitIndex != packet.getIndex()) return; this.rxPacket = packet; this.semaphore.release(); } @@ -80,56 +75,54 @@ public class BleDeviceUartChannel { this.deviceOnReportListener = listener; } - public synchronized TPMIPacket sendCommand(TPMIPacket tx, Integer overtime) { - Log.i("BLE", "TX PACKET :" + tx); + public synchronized TPMIPacket sendCommand(TPMIPacket tx, Integer timeoutMs) { + Log.i("BLE", "TX PACKET: " + tx); ctCxt.newCtCxt(tx); - BleManager.getInstance().sendMessage(tx.rawpacket); - try { - ctCxt.waitCxt(overtime); - } catch (InterruptedException ignored) { + ctCxt.waitCxt(timeoutMs); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } return ctCxt.clearCtCxt(); } private void handleReceivedData(byte[] data) { -// Log.d("BLE", "收到原始数据: " + Arrays.toString(data)); + bleExecutor.execute(() -> processIncomingData(data)); + } - // 追加到缓冲区 - if (bufferLen + data.length > buffer.length) { - Log.w("BLE", "BLE缓冲区溢出,已清空"); - bufferLen = 0; - } - System.arraycopy(data, 0, buffer, bufferLen, data.length); - bufferLen += data.length; - - int offset = 0; - while (offset < bufferLen) { - var report = TPMIPacketFactory.analysisRawRxData(buffer, bufferLen, offset); - if (report.result.equals(TPMIPacketFactory.PacketAnalysisResult.SUC)) { -// Log.d("BLE", "BLE协议包解析成功: " + report.packet); -// if (reportListener != null) { -// reportListener.onReportReceived(report.packet); -// } - if (deviceOnReportListener != null) { - dispatchTypedPacket(report.packet); + private void processIncomingData(byte[] data) { + synchronized (receiveBuffer) { + if (receiveBuffer.remaining() < data.length) { + Log.w("BLE", "BLE缓冲区溢出,已清空"); + receiveBuffer.clear(); + } + receiveBuffer.put(data); + receiveBuffer.flip(); // 切换为读模式 + + while (receiveBuffer.remaining() > 0) { + int offset = receiveBuffer.position(); + var report = TPMIPacketFactory.analysisRawRxData( + receiveBuffer.array(), + receiveBuffer.limit(), + offset + ); + + if (report.result == TPMIPacketFactory.PacketAnalysisResult.SUC) { + if (reportListener != null) reportListener.onReportReceived(report.packet); + if (deviceOnReportListener != null) dispatchTypedPacket(report.packet); + receiveBuffer.position(offset + report.packet.getPacketLen()); + Log.i("BLE","SUC : " + report.packet.getPacketLen()); + } else if (report.result == TPMIPacketFactory.PacketAnalysisResult.PACKE_NOT_FULLY_RECEIVED) { +// Log.i("BLE","PACKE_NOT_FULLY_RECEIVED : " + data.length); + break; + } else { + receiveBuffer.position(offset + 1); } - offset += report.packet.getPacketLen(); - } else if (report.result.equals(TPMIPacketFactory.PacketAnalysisResult.CHECKSUM_ERROR)) { - Log.w("BLE", "BLE数据包校验失败,跳过 1 字节"); - offset += 1; - } else if (report.result.equals(TPMIPacketFactory.PacketAnalysisResult.PACKE_NOT_FULLY_RECEIVED)) { - break; - } else { - offset += 1; } - } - // 移除已处理部分数据 - if (offset > 0 && offset <= bufferLen) { - System.arraycopy(buffer, offset, buffer, 0, bufferLen - offset); - bufferLen -= offset; + // 保留未解析部分 + receiveBuffer.compact(); // 相当于 left shift:将未读部分移到开头 } } @@ -146,12 +139,9 @@ public class BleDeviceUartChannel { } private void processRXPacket(TPMIPacket rx) { - if (rx.getPacketType().equals(TPMIPacket.PacketType.RESPONSE)) { + if (rx.getPacketType() == TPMIPacket.PacketType.RESPONSE) { ctCxt.trySetReceiptPacket(rx); - } else if (rx.getPacketType().equals(TPMIPacket.PacketType.REPORT)) { - /* - * 处理上报包 - */ + } else if (rx.getPacketType() == TPMIPacket.PacketType.REPORT) { reportPacketList.offer(rx); } } diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/config/AppConstantConfig.java b/app/src/main/java/com/iflytop/profilometer/core/migration/config/AppConstantConfig.java new file mode 100644 index 0000000..ee31ee7 --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/config/AppConstantConfig.java @@ -0,0 +1,9 @@ +package com.iflytop.profilometer.core.migration.config; + +public class AppConstantConfig { + public static final int HEARTBEAT_INTERVAL = 10000; + + //100ms上报一次点位 + public static final int SAMPLE_PERIOD = 1; + +} diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/AppConstantConfig.java b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/AppConstantConfig.java deleted file mode 100644 index 4514117..0000000 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/AppConstantConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.iflytop.profilometer.core.migration.measure; - -public class AppConstantConfig { - public static final int HEARTBEAT_INTERVAL = 10000; - - //100ms上报一次点位 - public static final int POINT_REPORT_PERIOD = 3; - -} diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/RailProfileDrawer.java b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/RailProfileDrawer.java index 774d20f..75a4e31 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/RailProfileDrawer.java +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/RailProfileDrawer.java @@ -1,5 +1,8 @@ package com.iflytop.profilometer.core.migration.measure.drawer; +import android.util.Log; + +import com.iflytop.profilometer.core.migration.config.AppConstantConfig; import com.iflytop.profilometer.core.migration.measure.drawer.type.MeasureSide; import com.iflytop.profilometer.core.migration.measure.drawer.type.RailProfileDrawerListener; import com.iflytop.profilometer.core.migration.measure.drawer.type.RailProfileDrawerState; @@ -7,6 +10,7 @@ import com.iflytop.profilometer.core.migration.measure.drawer.type.RailProfileMe import com.iflytop.profilometer.core.migration.measure.drawer.type.XYPoint; public class RailProfileDrawer { + private static final String TAG = "measurer"; /* * 轮廓绘制,启动信号判断相关参数 * 逻辑: @@ -21,7 +25,7 @@ public class RailProfileDrawer { * 静止判断位置阈值(毫米) * STILL_JUDGE_THRESHOLD */ - public static final double PRECISION = 0.2;// mm 满足13cm,1500个点 + public static final double PRECISION = 0.12;// mm 满足13cm,1500个点 public static final int OUTLINE_START_RECORD_SIG_JUDGE_TIME_THRESHOLD = 1500; public static final int START_OUTLINE_RECORDING_TIMING_JUDGMENT_AREA_HIGHT = 30; public static final int START_OUTLINE_RECORDING_TIMING_JUDGMENT_AREA_WEIGHT = 50; @@ -37,9 +41,9 @@ public class RailProfileDrawer { } Config cfg = new Config(); // 配置 - RailProfileDrawerState state = new RailProfileDrawerState(); + RailProfileDrawerState state = new RailProfileDrawerState(); RailProfileDrawerListener railProfileDrawerListener; - MeasureSide startSide = MeasureSide.LEFT; + MeasureSide startSide = MeasureSide.LEFT; public RailProfileDrawer(RailProfileDrawerListener railProfileDrawerListener) { this.railProfileDrawerListener = railProfileDrawerListener; @@ -48,8 +52,8 @@ public class RailProfileDrawer { synchronized public void startDraw(double arm1Length, double arm2Length, double pulleyRadius, double profilometerHight) { -// log.info("startDraw arm1Length:{} arm2Length:{} pulleyRadius:{} profilometerHight:{}", arm1Length, arm2Length, -// pulleyRadius, profilometerHight); + Log.i(TAG, String.format("startDraw arm1Length:%s arm2Length:%s pulleyRadius:%s profilometerHight:%s", + arm1Length, arm2Length, pulleyRadius, profilometerHight)); this.cfg.arm1Length = arm1Length; this.cfg.arm2Length = arm2Length; this.cfg.pulleyRadius = pulleyRadius; @@ -141,7 +145,7 @@ public class RailProfileDrawer { } if (!expectSide.equals(side)) { -// log.warn("用户启动记录方向错误"); + Log.w(TAG, "用户启动记录方向错误"); railProfileDrawerListener.onErrorStartRecordProfileSig(); state.stayStillDurationCnt = 0; } else { @@ -168,7 +172,7 @@ public class RailProfileDrawer { // } // } - if (distance(state.lastPulleyPoint, newPulleyPoint) < 0.002) { + if (distance(state.lastPulleyPoint, newPulleyPoint) < 0.005) { // log.info("same point, skip"); return; } @@ -222,7 +226,7 @@ public class RailProfileDrawer { if (speedNow > 100) { state.errorSpeedDetectedCnt++; if (state.errorSpeedDetectedCnt > 3) { -// log.warn("error speed detected, speed:{}", speedNow); + Log.w(TAG, String.format("error speed detected, speed:%s", speedNow)); state.speedNow = speedNow; if (!state.errorSpeedDetected) { state.errorSpeedDetected = true; diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/RailProfileDrawerState.java b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/RailProfileDrawerState.java index dd9d8b9..3e2a740 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/RailProfileDrawerState.java +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/RailProfileDrawerState.java @@ -17,7 +17,7 @@ public class RailProfileDrawerState { public boolean errorSpeedDetected = false; // 用户移动滑轮的速度过快 public int errorSpeedDetectedCnt = 0; // 用户移动滑轮的速度过快 // public ZLockList pulleyPoints = new ZLockList<>(10); - public RefPointFinder pulleyPointsRecordForTangentCalculation = new RefPointFinder(0.01); + public RefPointFinder pulleyPointsRecordForTangentCalculation = new RefPointFinder(0.05); public RefPointFinder pulleyPointDirectionJudge = new RefPointFinder(0.3); // 滑轮点位方向判断 public ZLockList leftPulleyRecord = new ZLockList<>(); // 记录滑轮点位 diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/XYPoint.java b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/XYPoint.java index 3ef412d..033cf23 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/XYPoint.java +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/type/XYPoint.java @@ -44,4 +44,12 @@ public class XYPoint { } return false; } + + public void setX(double x) { + this.x = x; + } + + public void setY(double y) { + this.y = y; + } } diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPacket.java b/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPacket.java index b1d5fdc..8b47369 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPacket.java +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPacket.java @@ -206,6 +206,9 @@ public class TPMIPacket { return (byte) (rawpacket[P_DATA_LEN_OFF] + FIX_PACKET_LEN); } + public byte getDataLen() { + return (byte) (rawpacket[P_DATA_LEN_OFF]); + } public byte getIndex() { return rawpacket[P_INDEX_OFF]; diff --git a/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPosReport.java b/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPosReport.java index 968d69e..5bbc4a5 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPosReport.java +++ b/app/src/main/java/com/iflytop/profilometer/core/migration/type/protocol/TPMIPosReport.java @@ -1,30 +1,39 @@ package com.iflytop.profilometer.core.migration.type.protocol; -import androidx.annotation.NonNull; - import cn.hutool.core.lang.Assert; public class TPMIPosReport extends TPMIPacket { - public TPMIPosReport(byte[] data) { - super(data); - Assert.isTrue(Command.SAMPLE_VAL_REPORT.equals(getCommand()), "Invalid command"); - } + public TPMIPosReport(byte[] data) { + super(data); + Assert.isTrue(Command.SAMPLE_VAL_REPORT.equals(getCommand()), "Invalid command"); + } + + public Integer getPosReportNum() { + return this.getDataLen() / 8; + } - //value:ARM0角度 - public Integer getArm1Angle() { - return this.getDataAsInt(0); - } + //value:ARM0角度 + public Integer getArm1Angle(Integer off) { + return this.getDataAsInt(off * 2); + } - //value:ARM1角度 - public Integer getArm2Angle() { - return this.getDataAsInt(1); - } + //value:ARM1角度 + public Integer getArm2Angle(Integer off) { + return this.getDataAsInt(1 + off * 2); + } - @NonNull public String toString() { - return String.format("ARM0Angle:%d ARM1Angle:%d ", getArm1Angle(), getArm2Angle()); - } + StringBuilder sb = new StringBuilder(); + sb.append("{"); + for (int i = 0; i < getPosReportNum(); i++) { + sb.append("[").append(getArm1Angle(i)).append(",").append(getArm2Angle(i)).append("]"); + if (i < getPosReportNum() - 1) + sb.append(", "); + } + sb.append('}'); + return sb.toString(); + } } diff --git a/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java b/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java index 55f90a9..83577ba 100644 --- a/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java +++ b/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java @@ -6,6 +6,7 @@ public class ProfileRecordPointSet extends BaseEntity { private String profileRecordUuid; private String leftPoints; private String rightPoints; + private String alignPoints; public String getProfileRecordUuid() { return profileRecordUuid; @@ -30,4 +31,12 @@ public class ProfileRecordPointSet extends BaseEntity { public void setRightPoints(String rightPoints) { this.rightPoints = rightPoints; } + + public String getAlignPoints() { + return alignPoints; + } + + public void setAlignPoints(String alignPoints) { + this.alignPoints = alignPoints; + } } diff --git a/app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java b/app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java index 0e9e4de..b118f82 100644 --- a/app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java +++ b/app/src/main/java/com/iflytop/profilometer/service/RailProfileDrawerService.java @@ -30,7 +30,9 @@ public class RailProfileDrawerService implements RailProfileDrawerListener { return; } if (packet instanceof TPMIPosReport report) { - railProfileDrawer.processRawEncoderData(report.getArm1Angle(), report.getArm2Angle()); + for (int i = 0; i < report.getPosReportNum(); i++) { + railProfileDrawer.processRawEncoderData(report.getArm1Angle(i), report.getArm2Angle(i)); + } } } @@ -80,7 +82,6 @@ public class RailProfileDrawerService implements RailProfileDrawerListener { */ @Override public void onErrorStartRecordProfileSig() { - Log.i("RailProfileDrawerService", "用户启动记录方向错误"); RailProfileMeasureTaskState taskState = SystemService.getInstance().getTaskState(); taskState.setWrongSide(true); @@ -125,11 +126,11 @@ public class RailProfileDrawerService implements RailProfileDrawerListener { */ @Override public void onErrorSpeedDetected() { - Log.i("RailProfileDrawerService", "移动超速,图像可能会发生失真"); - Map map = new HashMap<>(); - map.put("type", "measure-event"); - map.put("data", RailProfileMeasureTaskEvent.SPEED_DETECTED); - WebSocketManager.send(JSONUtil.toJsonStr(map)); +// Log.i("RailProfileDrawerService", "移动超速,图像可能会发生失真"); +// Map map = new HashMap<>(); +// map.put("type", "measure-event"); +// map.put("data", RailProfileMeasureTaskEvent.SPEED_DETECTED); +// WebSocketManager.send(JSONUtil.toJsonStr(map)); } public RailProfileDrawer getRailProfileDrawer() {