react-native-beidou 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BeiDouAIDLTestPage.tsx +7 -7
- package/Compass.android.tsx +20 -0
- package/Compass.ios.tsx +15 -0
- package/Compass.tsx +6 -0
- package/README.md +48 -124
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.idea/AndroidProjectSystem.xml +6 -0
- package/android/.idea/gradle.xml +13 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +3 -0
- package/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/java/com/cmcc_rn_module/BeiDouBluetoothModule.java +343 -101
- package/android/src/main/java/com/cmcc_rn_module/BeiDouBluetoothPackage.java +4 -1
- package/android/src/main/java/com/cmcc_rn_module/ChatDBManager.java +306 -0
- package/android/src/main/java/com/cmcc_rn_module/JsonUtil.java +113 -7
- package/android/src/main/java/com/cmcc_rn_module/view/CompassManager.java +41 -0
- package/android/src/main/java/com/cmcc_rn_module/view/CompassView.java +277 -0
- package/android/src/main/libs/bluetooth-sdk.aar +0 -0
- package/index.ts +188 -10
- package/ios/BDTCompassViewManager.h +15 -0
- package/ios/BDTCompassViewManager.m +24 -0
- package/ios/BeiDouBluetoothModule.h +20 -0
- package/ios/BeiDouBluetoothModule.m +424 -0
- package/ios/BeidouBluetooth.framework/BeidouBluetooth +0 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTBluetoothManager.h +76 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTChatDBManager.h +41 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTDataPacketBuilder.h +62 -0
- package/ios/BeidouBluetooth.framework/Headers/BeidouBluetooth.h +21 -0
- package/ios/BeidouBluetooth.framework/Info.plist +0 -0
- package/ios/BeidouBluetooth.framework/Modules/module.modulemap +6 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements-1 +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +177 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
- package/ios/CompassView.h +20 -0
- package/ios/CompassView.m +201 -0
- package/package.json +4 -1
- package/android/.gradle/8.8/checksums/checksums.lock +0 -0
- package/android/.gradle/8.8/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.8/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.8/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.8/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.8/gc.properties +0 -0
- package/ios/Podfile +0 -79
- package/ios/build_sdk.sh +0 -30
- package/ios/cmcc_rn_module/AppDelegate.h +0 -8
- package/ios/cmcc_rn_module/AppDelegate.mm +0 -108
- package/ios/cmcc_rn_module/CMCCAssetsLoaderModule.h +0 -17
- package/ios/cmcc_rn_module/CMCCAssetsLoaderModule.m +0 -38
- package/ios/cmcc_rn_module/Images.xcassets/AppIcon.appiconset/Contents.json +0 -53
- package/ios/cmcc_rn_module/Images.xcassets/Contents.json +0 -6
- package/ios/cmcc_rn_module/Info.plist +0 -62
- package/ios/cmcc_rn_module/LaunchScreen.storyboard +0 -47
- package/ios/cmcc_rn_module/main.m +0 -10
- package/ios/cmcc_rn_module.xcodeproj/project.pbxproj +0 -708
- package/ios/cmcc_rn_module.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/cmcc_rn_module.xcodeproj/xcshareddata/xcschemes/cmcc_rn_module.xcscheme +0 -88
- package/ios/cmcc_rn_module.xcworkspace/contents.xcworkspacedata +0 -10
- package/ios/cmcc_rn_module.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/cmcc_rn_moduleTests/Info.plist +0 -24
- package/ios/cmcc_rn_moduleTests/cmcc_rn_moduleTests.m +0 -66
- package/ios/reset_env.sh +0 -24
- package/ios/scripts/RNReanimated.podspec +0 -90
- package/ios/scripts/generate_dynamic_pod.rb +0 -166
- package/ios/scripts/native_modules_dy.rb +0 -317
- package/ios/scripts/react_native_pods_dy.rb +0 -773
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
package com.cmcc_rn_module.view;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.Canvas;
|
|
5
|
+
import android.graphics.Color;
|
|
6
|
+
import android.graphics.Paint;
|
|
7
|
+
import android.graphics.Typeface;
|
|
8
|
+
import android.hardware.Sensor;
|
|
9
|
+
import android.hardware.SensorEvent;
|
|
10
|
+
import android.hardware.SensorEventListener;
|
|
11
|
+
import android.hardware.SensorManager;
|
|
12
|
+
import android.util.AttributeSet;
|
|
13
|
+
import android.util.Log;
|
|
14
|
+
import android.view.HapticFeedbackConstants;
|
|
15
|
+
import android.view.View;
|
|
16
|
+
|
|
17
|
+
import com.facebook.react.bridge.ReactContext;
|
|
18
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
19
|
+
|
|
20
|
+
public class CompassView extends View implements SensorEventListener {
|
|
21
|
+
private static final String TAG = "OptimizedCompassView";
|
|
22
|
+
private static final float HAPTIC_FEEDBACK_INTERVAL = 45f; // 每45度触发一次震动反
|
|
23
|
+
|
|
24
|
+
// 传感器相关x
|
|
25
|
+
private SensorManager sensorManager;
|
|
26
|
+
private Sensor rotationVectorSensor;
|
|
27
|
+
private float[] rotationMatrix = new float[16];
|
|
28
|
+
private float[] orientation = new float[3];
|
|
29
|
+
|
|
30
|
+
// 绘制元素
|
|
31
|
+
private Paint circlePaint, markerPaint, textPaint, arrowPaint;
|
|
32
|
+
private int viewSize;
|
|
33
|
+
private int centerX, centerY;
|
|
34
|
+
private int compassRadius;
|
|
35
|
+
private float lastHapticAngle = 0;
|
|
36
|
+
|
|
37
|
+
// 方向处理
|
|
38
|
+
private float currentAzimuth = 0;
|
|
39
|
+
private float targetAzimuth = 0;
|
|
40
|
+
private long lastUpdateTime = 0;
|
|
41
|
+
private static final float MAX_ROTATION_RATE = 60f; // 度/秒
|
|
42
|
+
private Sensor accelerometer, magnetometer;
|
|
43
|
+
|
|
44
|
+
public CompassView(Context context, AttributeSet attrs) {
|
|
45
|
+
super(context, attrs);
|
|
46
|
+
init();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private void init() {
|
|
50
|
+
// 启用硬件加速层
|
|
51
|
+
setLayerType(LAYER_TYPE_HARDWARE, null);
|
|
52
|
+
|
|
53
|
+
// 初始化绘制工具
|
|
54
|
+
initPaints();
|
|
55
|
+
|
|
56
|
+
// 初始化传感器
|
|
57
|
+
sensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
58
|
+
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
|
59
|
+
magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
|
60
|
+
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
|
|
61
|
+
sensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME);
|
|
62
|
+
Sensor rotationVectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
|
|
63
|
+
sensorManager.registerListener(this, rotationVectorSensor, SensorManager.SENSOR_DELAY_GAME);
|
|
64
|
+
|
|
65
|
+
// 检查并注册磁力计传感器
|
|
66
|
+
Sensor magneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
|
67
|
+
sensorManager.registerListener(this, magneticFieldSensor, SensorManager.SENSOR_DELAY_GAME);
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
// private void registerRotationVectorSensorListener(SensorManager sensorManager, Sensor rotationVectorSensor) {
|
|
71
|
+
// boolean success = sensorManager.registerListener(
|
|
72
|
+
// compassSensorEventListener,
|
|
73
|
+
// rotationVectorSensor,
|
|
74
|
+
// SensorManager.SENSOR_DELAY_FASTEST
|
|
75
|
+
// );
|
|
76
|
+
// if (success) {
|
|
77
|
+
// Log.d(TAG, "Registered listener for rotation vector sensor");
|
|
78
|
+
// } else {
|
|
79
|
+
// Log.w(TAG, "Could not enable rotation vector sensor");
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
//
|
|
83
|
+
// private void registerMagneticFieldSensorListener(SensorManager sensorManager, Sensor magneticFieldSensor) {
|
|
84
|
+
// boolean success = sensorManager.registerListener(
|
|
85
|
+
// compassSensorEventListener,
|
|
86
|
+
// magneticFieldSensor,
|
|
87
|
+
// SensorManager.SENSOR_DELAY_NORMAL
|
|
88
|
+
// );
|
|
89
|
+
// if (success) {
|
|
90
|
+
// Log.d(TAG, "Registered listener for magnetic field sensor");
|
|
91
|
+
// } else {
|
|
92
|
+
// Log.w(TAG, "Could not enable magnetic field sensor");
|
|
93
|
+
// showErrorDialog(AppError.MAGNETIC_FIELD_SENSOR_FAILED);
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
private void initPaints() {
|
|
97
|
+
// 外圈画笔
|
|
98
|
+
circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
99
|
+
circlePaint.setStyle(Paint.Style.STROKE);
|
|
100
|
+
circlePaint.setStrokeWidth(dpToPx(2));
|
|
101
|
+
circlePaint.setColor(Color.WHITE);
|
|
102
|
+
|
|
103
|
+
// 刻度线画笔
|
|
104
|
+
markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
105
|
+
markerPaint.setStrokeWidth(dpToPx(1));
|
|
106
|
+
markerPaint.setColor(Color.WHITE);
|
|
107
|
+
|
|
108
|
+
// 文字画笔
|
|
109
|
+
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
110
|
+
textPaint.setTextSize(spToPx(14));
|
|
111
|
+
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
|
|
112
|
+
textPaint.setTextAlign(Paint.Align.CENTER);
|
|
113
|
+
textPaint.setColor(Color.WHITE);
|
|
114
|
+
|
|
115
|
+
// 指针画笔
|
|
116
|
+
arrowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
117
|
+
arrowPaint.setStrokeWidth(dpToPx(4));
|
|
118
|
+
arrowPaint.setColor(Color.RED);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Override
|
|
122
|
+
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
123
|
+
super.onSizeChanged(w, h, oldw, oldh);
|
|
124
|
+
viewSize = Math.min(w, h);
|
|
125
|
+
centerX = w / 2;
|
|
126
|
+
centerY = h / 2;
|
|
127
|
+
compassRadius = (int) ((viewSize / 2) - dpToPx(20));
|
|
128
|
+
|
|
129
|
+
// 根据视图大小动态调整文字大小
|
|
130
|
+
textPaint.setTextSize(compassRadius * 0.08f);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@Override
|
|
134
|
+
protected void onDraw(Canvas canvas) {
|
|
135
|
+
super.onDraw(canvas);
|
|
136
|
+
|
|
137
|
+
// 1. 绘制固定元素(不需要旋转的部分)
|
|
138
|
+
drawFixedElements(canvas);
|
|
139
|
+
|
|
140
|
+
// 2. 绘制旋转元素
|
|
141
|
+
canvas.save();
|
|
142
|
+
canvas.rotate(-currentAzimuth, centerX, centerY);
|
|
143
|
+
drawRotatingElements(canvas);
|
|
144
|
+
canvas.restore();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private void drawFixedElements(Canvas canvas) {
|
|
148
|
+
// 绘制固定指针(始终指向上方)
|
|
149
|
+
float arrowLength = compassRadius * 0.9f;
|
|
150
|
+
canvas.drawLine(centerX, centerY, centerX, centerY - arrowLength, arrowPaint);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private void drawRotatingElements(Canvas canvas) {
|
|
154
|
+
// 绘制外圈
|
|
155
|
+
canvas.drawCircle(centerX, centerY, compassRadius, circlePaint);
|
|
156
|
+
|
|
157
|
+
// 绘制刻度线和标签
|
|
158
|
+
for (int i = 0; i < 360; i += 10) {
|
|
159
|
+
float angleRad = (float) Math.toRadians(i);
|
|
160
|
+
boolean isMajor = i % 30 == 0;
|
|
161
|
+
|
|
162
|
+
float lineLength = isMajor ? compassRadius * 0.15f : compassRadius * 0.08f;
|
|
163
|
+
float startX = centerX + (compassRadius - lineLength) * (float) Math.sin(angleRad);
|
|
164
|
+
float startY = centerY - (compassRadius - lineLength) * (float) Math.cos(angleRad);
|
|
165
|
+
float endX = centerX + compassRadius * (float) Math.sin(angleRad);
|
|
166
|
+
float endY = centerY - compassRadius * (float) Math.cos(angleRad);
|
|
167
|
+
|
|
168
|
+
canvas.drawLine(startX, startY, endX, endY, markerPaint);
|
|
169
|
+
|
|
170
|
+
if (isMajor) {
|
|
171
|
+
String label = String.valueOf(i);
|
|
172
|
+
float textX = centerX + (compassRadius * 0.75f) * (float) Math.sin(angleRad);
|
|
173
|
+
float textY = centerY - (compassRadius * 0.75f) * (float) Math.cos(angleRad) + textPaint.getTextSize()/3;
|
|
174
|
+
canvas.drawText(label, textX, textY, textPaint);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 绘制主要方向标记
|
|
179
|
+
drawCardinalDirections(canvas);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private void drawCardinalDirections(Canvas canvas) {
|
|
183
|
+
String[] directions = {"N", "E", "S", "W"};
|
|
184
|
+
for (int i = 0; i < 4; i++) {
|
|
185
|
+
float angleRad = (float) Math.toRadians(i * 90);
|
|
186
|
+
float textX = centerX + (compassRadius * 0.6f) * (float) Math.sin(angleRad);
|
|
187
|
+
float textY = centerY - (compassRadius * 0.6f) * (float) Math.cos(angleRad) + textPaint.getTextSize()/3;
|
|
188
|
+
canvas.drawText(directions[i], textX, textY, textPaint);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Override
|
|
193
|
+
public void onSensorChanged(SensorEvent event) {
|
|
194
|
+
Log.i(TAG, "方向改变了"+event.sensor.getType());
|
|
195
|
+
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
|
|
196
|
+
Log.i(TAG, "修改指针");
|
|
197
|
+
|
|
198
|
+
// 使用旋转矢量传感器获取更精确的方向数据
|
|
199
|
+
SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
|
|
200
|
+
SensorManager.getOrientation(rotationMatrix, orientation);
|
|
201
|
+
|
|
202
|
+
float newAzimuth = (float) Math.toDegrees(orientation[0]);
|
|
203
|
+
if (newAzimuth < 0) newAzimuth += 360;
|
|
204
|
+
|
|
205
|
+
updateAzimuth(newAzimuth);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private void updateAzimuth(float newAzimuth) {
|
|
210
|
+
long currentTime = System.currentTimeMillis();
|
|
211
|
+
float timeDelta = (currentTime - lastUpdateTime) / 1000f; // 转换为秒
|
|
212
|
+
lastUpdateTime = currentTime;
|
|
213
|
+
|
|
214
|
+
// 计算角度变化量(考虑跨越360°的情况)
|
|
215
|
+
float delta = ((newAzimuth - currentAzimuth + 540) % 360) - 180;
|
|
216
|
+
|
|
217
|
+
// 限制最大旋转速度
|
|
218
|
+
float maxDelta = MAX_ROTATION_RATE * timeDelta;
|
|
219
|
+
delta = Math.max(-maxDelta, Math.min(delta, maxDelta));
|
|
220
|
+
|
|
221
|
+
targetAzimuth = (currentAzimuth + delta) % 360;
|
|
222
|
+
if (targetAzimuth < 0) targetAzimuth += 360;
|
|
223
|
+
|
|
224
|
+
// 检查是否需要触发触觉反馈
|
|
225
|
+
checkHapticFeedback(targetAzimuth);
|
|
226
|
+
|
|
227
|
+
// 直接更新当前角度(不再使用平滑过渡,依靠传感器自身滤波)
|
|
228
|
+
currentAzimuth = targetAzimuth;
|
|
229
|
+
|
|
230
|
+
// 通知React Native
|
|
231
|
+
sendDirectionUpdate(currentAzimuth);
|
|
232
|
+
|
|
233
|
+
// 使用更高效的刷新方法
|
|
234
|
+
postInvalidateOnAnimation();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private void checkHapticFeedback(float newAngle) {
|
|
238
|
+
float angleDiff = Math.abs(((newAngle - lastHapticAngle + 540) % 360) - 180);
|
|
239
|
+
if (angleDiff >= HAPTIC_FEEDBACK_INTERVAL) {
|
|
240
|
+
performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK);
|
|
241
|
+
lastHapticAngle = newAngle;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private void sendDirectionUpdate(float azimuth) {
|
|
246
|
+
if (getContext() instanceof ReactContext) {
|
|
247
|
+
((ReactContext) getContext())
|
|
248
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
249
|
+
.emit("onCompassUpdate", azimuth);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
public void start() {
|
|
253
|
+
if (rotationVectorSensor != null) {
|
|
254
|
+
// 使用最快的传感器更新速率
|
|
255
|
+
sensorManager.registerListener(this, rotationVectorSensor, SensorManager.SENSOR_DELAY_FASTEST);
|
|
256
|
+
} else {
|
|
257
|
+
Log.w(TAG, "Rotation vector sensor not available");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public void stop() {
|
|
262
|
+
sensorManager.unregisterListener(this);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private float dpToPx(float dp) {
|
|
266
|
+
return dp * getResources().getDisplayMetrics().density;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private float spToPx(float sp) {
|
|
270
|
+
return sp * getResources().getDisplayMetrics().scaledDensity;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@Override
|
|
274
|
+
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
275
|
+
// 可以在这里处理精度变化通知
|
|
276
|
+
}
|
|
277
|
+
}
|
|
Binary file
|
package/index.ts
CHANGED
|
@@ -9,13 +9,13 @@ const LINKING_ERROR =
|
|
|
9
9
|
const BeiDouBluetoothModule = NativeModules.BeiDouBluetoothModule
|
|
10
10
|
? NativeModules.BeiDouBluetoothModule
|
|
11
11
|
: new Proxy(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
get() {
|
|
15
|
+
throw new Error(LINKING_ERROR);
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
19
|
|
|
20
20
|
// ================== 蓝牙相关类型定义 ==================
|
|
21
21
|
export interface BlueDeviceInfo {
|
|
@@ -57,10 +57,29 @@ export interface BDMsgEphemerisFileDLResponse {
|
|
|
57
57
|
version: string;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// ================== 新增数据类型定义 ==================
|
|
61
|
+
export interface WriteInfoResponse {
|
|
62
|
+
type: number;
|
|
63
|
+
data: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ConversationInfo {
|
|
67
|
+
phone: string;
|
|
68
|
+
lastMsg: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
is_send: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface MessageInfo {
|
|
74
|
+
content: string;
|
|
75
|
+
is_send: boolean;
|
|
76
|
+
timestamp: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
60
79
|
// ================== 蓝牙模块接口定义 ==================
|
|
61
80
|
interface BeiDouBluetoothModuleType {
|
|
62
81
|
// 原有蓝牙相关方法
|
|
63
|
-
getAllConversations(
|
|
82
|
+
getAllConversations(): Promise<string>; // 更新为Promise版本
|
|
64
83
|
startScanForService(): void;
|
|
65
84
|
stopScanning(): void;
|
|
66
85
|
getDiscoveredDevices(): Promise<string>; // JSON string of BlueDeviceInfoEntity[]
|
|
@@ -71,7 +90,14 @@ interface BeiDouBluetoothModuleType {
|
|
|
71
90
|
initializeBluetooth(callback: (status: BluetoothStatus) => void): void;
|
|
72
91
|
generateRandom16BytesString(): string;
|
|
73
92
|
writeData(randomString: string, deviceNo: string, command: number, attrType: number, encrypt: boolean, callback: (result: number) => void): void;
|
|
74
|
-
|
|
93
|
+
|
|
94
|
+
// 新增的iOS兼容方法
|
|
95
|
+
writeInfo(base64Payload: string | null, deviceNO: string, command: number, opCode: number, attrType: number, encrypted: boolean): Promise<WriteInfoResponse>;
|
|
96
|
+
insertMsg(phone: string, content: string, timestamp: number, isSend: boolean): void;
|
|
97
|
+
getMessagesForPhone(phone: string, page: number, pageSize: number, callback: (result: string) => void): void;
|
|
98
|
+
setBLEKey(bleKey: string): Promise<number>;
|
|
99
|
+
|
|
100
|
+
// 原有方法保持兼容
|
|
75
101
|
writeValueInfo(randomString: string, deviceNo: string, command: number, attrType: number, value: number, callback: (result: any) => void): void;
|
|
76
102
|
disConnectWithDeviceUUID(deviceNo: string): Promise<number>;
|
|
77
103
|
fetchCurrentWifiName(callback: (wifiName: string) => void): void;
|
|
@@ -89,6 +115,15 @@ interface BeiDouBluetoothModuleType {
|
|
|
89
115
|
BDMailboxQueryEncrypt(): Promise<BDMsgEncryptResponse>;
|
|
90
116
|
BDMsgDecrypt(msg: number[], len: number): Promise<BDMsgDecryptResponse>;
|
|
91
117
|
DLEphemerisFile(type: string, version: string): Promise<BDMsgEphemerisFileDLResponse>;
|
|
118
|
+
|
|
119
|
+
// 位置
|
|
120
|
+
getGpsLocation(): Promise<{
|
|
121
|
+
latitude: number;
|
|
122
|
+
longitude: number;
|
|
123
|
+
provider: string;
|
|
124
|
+
accuracy: number;
|
|
125
|
+
timestamp: number;
|
|
126
|
+
} | null>;
|
|
92
127
|
}
|
|
93
128
|
|
|
94
129
|
// ================== 导出的便利方法 ==================
|
|
@@ -240,19 +275,104 @@ export const downloadEphemerisFile = async (
|
|
|
240
275
|
return await BeiDouBluetoothModule.DLEphemerisFile(type, version);
|
|
241
276
|
};
|
|
242
277
|
|
|
243
|
-
|
|
278
|
+
// ================== 新增iOS兼容方法的便利函数 ==================
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 写入信息到北斗设备 (iOS兼容版本)
|
|
282
|
+
*/
|
|
283
|
+
export const writeInfoToDevice = async (
|
|
284
|
+
base64Payload: string | null,
|
|
285
|
+
deviceNO: string,
|
|
286
|
+
command: number,
|
|
287
|
+
opCode: number,
|
|
288
|
+
attrType: number,
|
|
289
|
+
encrypted: boolean
|
|
290
|
+
): Promise<WriteInfoResponse> => {
|
|
291
|
+
return await BeiDouBluetoothModule.writeInfo(base64Payload, deviceNO, command, opCode, attrType, encrypted);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 插入北斗蓝牙短信
|
|
296
|
+
*/
|
|
297
|
+
export const insertBeiDouMessage = (
|
|
298
|
+
phone: string,
|
|
299
|
+
content: string,
|
|
300
|
+
timestamp: number,
|
|
301
|
+
isSend: boolean
|
|
302
|
+
): void => {
|
|
303
|
+
BeiDouBluetoothModule.insertMsg(phone, content, timestamp, isSend);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 获取所有会话列表的Promise封装
|
|
308
|
+
*/
|
|
309
|
+
export const getAllConversationsList = async (): Promise<ConversationInfo[]> => {
|
|
310
|
+
try {
|
|
311
|
+
const conversationsJson = await BeiDouBluetoothModule.getAllConversations();
|
|
312
|
+
return JSON.parse(conversationsJson);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error('解析会话列表JSON失败:', error);
|
|
315
|
+
return [];
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 获取指定手机号的消息列表的Promise封装
|
|
321
|
+
*/
|
|
322
|
+
export const getMessagesForPhoneNumber = (
|
|
323
|
+
phone: string,
|
|
324
|
+
page: number = 0,
|
|
325
|
+
pageSize: number = 20
|
|
326
|
+
): Promise<MessageInfo[]> => {
|
|
327
|
+
return new Promise((resolve, reject) => {
|
|
328
|
+
BeiDouBluetoothModule.getMessagesForPhone(phone, page, pageSize, (result: string) => {
|
|
329
|
+
try {
|
|
330
|
+
const messages = JSON.parse(result);
|
|
331
|
+
resolve(messages);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error('解析消息列表JSON失败:', error);
|
|
334
|
+
reject(error);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 设置BLE密钥
|
|
342
|
+
*/
|
|
343
|
+
export const setBeiDouBLEKey = async (bleKey: string): Promise<boolean> => {
|
|
344
|
+
try {
|
|
345
|
+
const result = await BeiDouBluetoothModule.setBLEKey(bleKey);
|
|
346
|
+
return result === 1;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
console.error('设置BLE密钥失败:', error);
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// export default BeiDouBluetoothModule as BeiDouBluetoothModuleType;
|
|
244
354
|
|
|
245
355
|
export const BeiDouModule = {
|
|
246
356
|
// 蓝牙相关
|
|
247
357
|
bluetooth: {
|
|
248
358
|
startScan: () => BeiDouBluetoothModule.startScanForService(),
|
|
359
|
+
startScanIOS: (callback: (result: number) => void) => BeiDouBluetoothModule.startScanForService(callback),
|
|
249
360
|
stopScan: () => BeiDouBluetoothModule.stopScanning(),
|
|
250
361
|
getDevices: getDiscoveredDevicesArray,
|
|
251
362
|
connect: (deviceNo: string) => BeiDouBluetoothModule.connectToDeviceFromCloudDeviceNO(deviceNo, 0),
|
|
252
363
|
disconnect: (deviceNo: string) => BeiDouBluetoothModule.disConnectWithDeviceUUID(deviceNo),
|
|
253
364
|
writeData: (randomString: string, deviceNo: string, command: number, attrType: number, encrypt: boolean, callback: (result: number) => void) =>
|
|
254
365
|
BeiDouBluetoothModule.writeData(randomString, deviceNo, command, attrType, encrypt, callback),
|
|
366
|
+
writeInfo: writeInfoToDevice,
|
|
255
367
|
generateRandomString: () => BeiDouBluetoothModule.generateRandom16BytesString(),
|
|
368
|
+
setBLEKey: setBeiDouBLEKey,
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
// 消息管理相关
|
|
372
|
+
message: {
|
|
373
|
+
insertMsg: insertBeiDouMessage,
|
|
374
|
+
getAllConversations: getAllConversationsList,
|
|
375
|
+
getMessagesForPhone: getMessagesForPhoneNumber,
|
|
256
376
|
},
|
|
257
377
|
|
|
258
378
|
// 系统相关
|
|
@@ -261,6 +381,13 @@ export const BeiDouModule = {
|
|
|
261
381
|
checkBluetoothPermission,
|
|
262
382
|
initializeBluetooth,
|
|
263
383
|
fetchCurrentWifiName,
|
|
384
|
+
getGpsLocation: (): Promise<{
|
|
385
|
+
latitude: number;
|
|
386
|
+
longitude: number;
|
|
387
|
+
provider: string;
|
|
388
|
+
accuracy: number;
|
|
389
|
+
timestamp: number;
|
|
390
|
+
} | null> => BeiDouBluetoothModule.getGpsLocation(),
|
|
264
391
|
},
|
|
265
392
|
|
|
266
393
|
// 北斗服务相关
|
|
@@ -279,4 +406,55 @@ export const BeiDouModule = {
|
|
|
279
406
|
decryptMessage: decryptBeiDouMessage,
|
|
280
407
|
downloadEphemeris: downloadEphemerisFile,
|
|
281
408
|
},
|
|
409
|
+
|
|
410
|
+
// 所有原生方法的原名导出
|
|
411
|
+
all: {
|
|
412
|
+
// 原有蓝牙相关方法
|
|
413
|
+
getAllConversations: getAllConversationsList,
|
|
414
|
+
startScanForService: BeiDouBluetoothModule.startScanForService,
|
|
415
|
+
stopScanning: BeiDouBluetoothModule.stopScanning,
|
|
416
|
+
getDiscoveredDevices: BeiDouBluetoothModule.getDiscoveredDevices,
|
|
417
|
+
connectToDeviceFromCloudDeviceNO: BeiDouBluetoothModule.connectToDeviceFromCloudDeviceNO,
|
|
418
|
+
getAndroidNetWorkInfo: BeiDouBluetoothModule.getAndroidNetWorkInfo,
|
|
419
|
+
checkBlueToothPermission: BeiDouBluetoothModule.checkBlueToothPermission,
|
|
420
|
+
shouldShowBlueToothPermissionRationale: BeiDouBluetoothModule.shouldShowBlueToothPermissionRationale,
|
|
421
|
+
initializeBluetooth: BeiDouBluetoothModule.initializeBluetooth,
|
|
422
|
+
generateRandom16BytesString: BeiDouBluetoothModule.generateRandom16BytesString,
|
|
423
|
+
writeData: BeiDouBluetoothModule.writeData,
|
|
424
|
+
writeInfo: BeiDouBluetoothModule.writeInfo,
|
|
425
|
+
writeValueInfo: BeiDouBluetoothModule.writeValueInfo,
|
|
426
|
+
disConnectWithDeviceUUID: BeiDouBluetoothModule.disConnectWithDeviceUUID,
|
|
427
|
+
fetchCurrentWifiName: BeiDouBluetoothModule.fetchCurrentWifiName,
|
|
428
|
+
|
|
429
|
+
// 消息数据库持久化
|
|
430
|
+
insertMsg: insertBeiDouMessage,
|
|
431
|
+
getMessagesForPhone: getMessagesForPhoneNumber,
|
|
432
|
+
setBLEKey: BeiDouBluetoothModule.setBLEKey,
|
|
433
|
+
|
|
434
|
+
// 北斗AIDL服务绑定方法
|
|
435
|
+
bindBeidouServiceMethod: BeiDouBluetoothModule.bindBeidouServiceMethod,
|
|
436
|
+
unbindBeidouServiceMethod: BeiDouBluetoothModule.unbindBeidouServiceMethod,
|
|
437
|
+
|
|
438
|
+
// 北斗AIDL服务方法
|
|
439
|
+
BDAuthenticate: BeiDouBluetoothModule.BDAuthenticate,
|
|
440
|
+
getBDMsgStatus: BeiDouBluetoothModule.getBDMsgStatus,
|
|
441
|
+
checkValidatedKey: BeiDouBluetoothModule.checkValidatedKey,
|
|
442
|
+
commonBDMsgEncrypt: BeiDouBluetoothModule.commonBDMsgEncrypt,
|
|
443
|
+
positionBDMsgEncrypt: BeiDouBluetoothModule.positionBDMsgEncrypt,
|
|
444
|
+
BDMailboxQueryEncrypt: BeiDouBluetoothModule.BDMailboxQueryEncrypt,
|
|
445
|
+
BDMsgDecrypt: BeiDouBluetoothModule.BDMsgDecrypt,
|
|
446
|
+
DLEphemerisFile: BeiDouBluetoothModule.DLEphemerisFile,
|
|
447
|
+
getGpsLocation: (): Promise<{
|
|
448
|
+
latitude: number;
|
|
449
|
+
longitude: number;
|
|
450
|
+
provider: string;
|
|
451
|
+
accuracy: number;
|
|
452
|
+
timestamp: number;
|
|
453
|
+
} | null> => BeiDouBluetoothModule.getGpsLocation(),
|
|
454
|
+
},
|
|
282
455
|
};
|
|
456
|
+
|
|
457
|
+
export default BeiDouModule;
|
|
458
|
+
export { default as Compass } from './Compass';
|
|
459
|
+
|
|
460
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BDTCompassViewManager.h
|
|
3
|
+
// IntegrateSingleIecmIot
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/8/25.
|
|
6
|
+
//
|
|
7
|
+
#import <React/RCTViewManager.h>
|
|
8
|
+
|
|
9
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
10
|
+
|
|
11
|
+
@interface BDTCompassViewManager : RCTViewManager
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BDTCompassViewManager.m
|
|
3
|
+
// IntegrateSingleIecmIot
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/8/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import "BDTCompassViewManager.h"
|
|
9
|
+
#import "CompassView.h"
|
|
10
|
+
#import <React/RCTBridge.h>
|
|
11
|
+
#import <React/RCTUIManager.h>
|
|
12
|
+
|
|
13
|
+
@implementation BDTCompassViewManager
|
|
14
|
+
|
|
15
|
+
RCT_EXPORT_MODULE(CompassView)
|
|
16
|
+
|
|
17
|
+
// 导出属性给 RN 使用
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(onHeadingChange, RCTBubblingEventBlock)
|
|
19
|
+
|
|
20
|
+
- (UIView *)view {
|
|
21
|
+
return [[CompassView alloc] init];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BeiDouBluetoothModule.h
|
|
3
|
+
// IntegrateSingleIecmIot
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/9/4.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#import <React/RCTEventEmitter.h>
|
|
10
|
+
#import <React/RCTBridgeModule.h>
|
|
11
|
+
|
|
12
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
13
|
+
|
|
14
|
+
@interface BeiDouBluetoothModule : RCTEventEmitter<RCTBridgeModule>
|
|
15
|
+
|
|
16
|
+
+ (BeiDouBluetoothModule *)defaultModule;
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
NS_ASSUME_NONNULL_END
|