react-native-beidou 1.0.6 → 1.0.8
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/LogManager.ts +280 -0
- package/README.md +1 -16
- package/android/build.gradle +19 -2
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothModule.java +143 -27
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothPackage.java +2 -2
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ByteUtil.java +2 -2
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ChatDBManager.java +46 -46
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/JsonUtil.java +4 -4
- package/android/src/main/java/com/fxzs.rnbeidou/LogManager.java +488 -0
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/StringUtils.java +1 -1
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassManager.java +1 -1
- package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassView.java +2 -2
- package/index.ts +22 -2
- package/package.json +3 -2
- package/react-native.config.js +2 -2
- package/android/src/main/libs/bluetooth-sdk.aar +0 -0
package/LogManager.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { NativeModules, Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
const { BeiDouBluetoothModule } = NativeModules;
|
|
5
|
+
/**
|
|
6
|
+
* BeiDou SDK 日志管理器
|
|
7
|
+
* 提供统一的日志管理功能,支持Debug/Release模式切换
|
|
8
|
+
*/
|
|
9
|
+
export interface LogConfig {
|
|
10
|
+
enableFileLog: boolean; // 是否启用文件日志
|
|
11
|
+
enableConsoleLog: boolean; // 是否启用控制台日志
|
|
12
|
+
maxFileSize: number; // 最大文件大小(MB)
|
|
13
|
+
maxFileCount: number; // 最大文件数量
|
|
14
|
+
encryptionKey?: string; // 加密密钥(可选)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum LogLevel {
|
|
18
|
+
VERBOSE = 'VERBOSE',
|
|
19
|
+
DEBUG = 'DEBUG',
|
|
20
|
+
INFO = 'INFO',
|
|
21
|
+
WARN = 'WARN',
|
|
22
|
+
ERROR = 'ERROR',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* BeiDou SDK 日志管理器类
|
|
27
|
+
*/
|
|
28
|
+
export class BeiDouLogManager {
|
|
29
|
+
private static instance: BeiDouLogManager;
|
|
30
|
+
private isInitialized: boolean = false;
|
|
31
|
+
private currentConfig: LogConfig = {
|
|
32
|
+
enableFileLog: true,
|
|
33
|
+
enableConsoleLog: __DEV__,
|
|
34
|
+
maxFileSize: 10, // 10MB
|
|
35
|
+
maxFileCount: 5,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
private constructor() {}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 获取单例实例
|
|
42
|
+
*/
|
|
43
|
+
public static getInstance(): BeiDouLogManager {
|
|
44
|
+
if (!BeiDouLogManager.instance) {
|
|
45
|
+
BeiDouLogManager.instance = new BeiDouLogManager();
|
|
46
|
+
}
|
|
47
|
+
return BeiDouLogManager.instance;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 初始化日志管理器
|
|
52
|
+
* @param config 日志配置
|
|
53
|
+
*/
|
|
54
|
+
public async initialize(config?: Partial<LogConfig>): Promise<void> {
|
|
55
|
+
if (this.isInitialized) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (config) {
|
|
60
|
+
this.currentConfig = { ...this.currentConfig, ...config };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
if (Platform.OS === 'android') {
|
|
65
|
+
await BeiDouBluetoothModule.configureLogger(
|
|
66
|
+
this.currentConfig.enableFileLog,
|
|
67
|
+
this.currentConfig.enableConsoleLog,
|
|
68
|
+
this.currentConfig.maxFileSize,
|
|
69
|
+
this.currentConfig.maxFileCount,
|
|
70
|
+
this.currentConfig.encryptionKey || null
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.isInitialized = true;
|
|
75
|
+
this.info('BeiDouLogManager', 'LogManager initialized successfully');
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('Failed to initialize BeiDou LogManager:', error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 更新日志配置
|
|
84
|
+
* @param config 新的配置
|
|
85
|
+
*/
|
|
86
|
+
public async updateConfig(config: Partial<LogConfig>): Promise<void> {
|
|
87
|
+
this.currentConfig = { ...this.currentConfig, ...config };
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
if (Platform.OS === 'android') {
|
|
91
|
+
await BeiDouBluetoothModule.configureLogger(
|
|
92
|
+
this.currentConfig.enableFileLog,
|
|
93
|
+
this.currentConfig.enableConsoleLog,
|
|
94
|
+
this.currentConfig.maxFileSize,
|
|
95
|
+
this.currentConfig.maxFileCount,
|
|
96
|
+
this.currentConfig.encryptionKey || null
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.info('BeiDouLogManager', 'LogManager config updated');
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error('Failed to update BeiDou LogManager config:', error);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Verbose日志
|
|
109
|
+
*/
|
|
110
|
+
public async verbose(tag: string, message: string): Promise<void> {
|
|
111
|
+
return this.writeLog(LogLevel.VERBOSE, tag, message);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Debug日志
|
|
116
|
+
*/
|
|
117
|
+
public async debug(tag: string, message: string): Promise<void> {
|
|
118
|
+
return this.writeLog(LogLevel.DEBUG, tag, message);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Info日志
|
|
123
|
+
*/
|
|
124
|
+
public async info(tag: string, message: string): Promise<void> {
|
|
125
|
+
return this.writeLog(LogLevel.INFO, tag, message);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Warning日志
|
|
130
|
+
*/
|
|
131
|
+
public async warn(tag: string, message: string): Promise<void> {
|
|
132
|
+
return this.writeLog(LogLevel.WARN, tag, message);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Error日志
|
|
137
|
+
*/
|
|
138
|
+
public async error(tag: string, message: string): Promise<void> {
|
|
139
|
+
return this.writeLog(LogLevel.ERROR, tag, message);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 写入日志
|
|
144
|
+
* @param level 日志级别
|
|
145
|
+
* @param tag 标签
|
|
146
|
+
* @param message 消息
|
|
147
|
+
*/
|
|
148
|
+
private async writeLog(level: LogLevel, tag: string, message: string): Promise<void> {
|
|
149
|
+
try {
|
|
150
|
+
// 控制台输出(根据配置)
|
|
151
|
+
if (this.currentConfig.enableConsoleLog) {
|
|
152
|
+
const timestamp = new Date().toISOString();
|
|
153
|
+
const logMessage = `[${timestamp}] [${level}] [${tag}] ${message}`;
|
|
154
|
+
|
|
155
|
+
switch (level) {
|
|
156
|
+
case LogLevel.VERBOSE:
|
|
157
|
+
case LogLevel.DEBUG:
|
|
158
|
+
console.log(logMessage);
|
|
159
|
+
break;
|
|
160
|
+
case LogLevel.INFO:
|
|
161
|
+
console.info(logMessage);
|
|
162
|
+
break;
|
|
163
|
+
case LogLevel.WARN:
|
|
164
|
+
console.warn(logMessage);
|
|
165
|
+
break;
|
|
166
|
+
case LogLevel.ERROR:
|
|
167
|
+
console.error(logMessage);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// 文件输出(通过原生模块)
|
|
173
|
+
if (Platform.OS === 'android' && this.currentConfig.enableFileLog) {
|
|
174
|
+
await BeiDouBluetoothModule.writeLog(level, tag, message);
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
// 日志写入失败时使用console作为备选
|
|
178
|
+
console.error('Failed to write log:', error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 获取日志统计信息
|
|
184
|
+
*/
|
|
185
|
+
public async getLogStats(): Promise<string> {
|
|
186
|
+
try {
|
|
187
|
+
if (Platform.OS === 'android') {
|
|
188
|
+
return await BeiDouBluetoothModule.getLogStats();
|
|
189
|
+
}
|
|
190
|
+
return 'Log stats not available on this platform';
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error('Failed to get log stats:', error);
|
|
193
|
+
return 'Failed to get log stats: ' + error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 清空所有日志文件
|
|
199
|
+
*/
|
|
200
|
+
public async clearAllLogs(): Promise<void> {
|
|
201
|
+
try {
|
|
202
|
+
if (Platform.OS === 'android') {
|
|
203
|
+
await BeiDouBluetoothModule.clearAllLogs();
|
|
204
|
+
}
|
|
205
|
+
this.info('BeiDouLogManager', 'All logs cleared');
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error('Failed to clear logs:', error);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 获取当前配置
|
|
214
|
+
*/
|
|
215
|
+
public getConfig(): LogConfig {
|
|
216
|
+
return { ...this.currentConfig };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 检查是否已初始化
|
|
221
|
+
*/
|
|
222
|
+
public isReady(): boolean {
|
|
223
|
+
return this.isInitialized;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 导出单例实例
|
|
228
|
+
export const BeiDouLogger = BeiDouLogManager.getInstance();
|
|
229
|
+
|
|
230
|
+
// 导出便捷方法
|
|
231
|
+
export const logVerbose = (tag: string, message: string) => BeiDouLogger.verbose(tag, message);
|
|
232
|
+
export const logDebug = (tag: string, message: string) => BeiDouLogger.debug(tag, message);
|
|
233
|
+
export const logInfo = (tag: string, message: string) => BeiDouLogger.info(tag, message);
|
|
234
|
+
export const logWarn = (tag: string, message: string) => BeiDouLogger.warn(tag, message);
|
|
235
|
+
export const logError = (tag: string, message: string) => BeiDouLogger.error(tag, message);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 全局日志拦截器
|
|
239
|
+
* 在Release模式下拦截console日志并重定向到文件
|
|
240
|
+
*/
|
|
241
|
+
export const setupGlobalLogInterception = () => {
|
|
242
|
+
if (!__DEV__) {
|
|
243
|
+
// 保存原始console方法
|
|
244
|
+
const originalConsole = {
|
|
245
|
+
log: console.log,
|
|
246
|
+
info: console.info,
|
|
247
|
+
warn: console.warn,
|
|
248
|
+
error: console.error,
|
|
249
|
+
debug: console.debug,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// 重写console方法
|
|
253
|
+
console.log = (...args) => {
|
|
254
|
+
BeiDouLogger.info('Console', args.join(' '));
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
console.info = (...args) => {
|
|
258
|
+
BeiDouLogger.info('Console', args.join(' '));
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
console.warn = (...args) => {
|
|
262
|
+
BeiDouLogger.warn('Console', args.join(' '));
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
console.error = (...args) => {
|
|
266
|
+
BeiDouLogger.error('Console', args.join(' '));
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
console.debug = (...args) => {
|
|
270
|
+
BeiDouLogger.debug('Console', args.join(' '));
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// 提供恢复原始console的方法(用于调试)
|
|
274
|
+
(global as any).__restoreConsole = () => {
|
|
275
|
+
Object.assign(console, originalConsole);
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
export default BeiDouLogManager;
|
package/README.md
CHANGED
|
@@ -20,21 +20,6 @@ pod 'react-native-beidou', :path => '../node_modules/react-native-beidou'
|
|
|
20
20
|
cd ios && pod install
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
注意:
|
|
24
|
-
- 本库通过 `vendored_frameworks` 引入 `BeidouBluetooth.framework`,无需额外拷贝。
|
|
25
|
-
- 最低平台版本需满足 iOS 15.6(来自 `react-native-beidou.podspec`)。
|
|
26
|
-
|
|
27
|
-
### Android
|
|
28
|
-
|
|
29
|
-
采用 RN Autolinking,无需手动修改。若出现无法自动链接,可检查本库提供的 `react-native.config.js`:
|
|
30
|
-
|
|
31
|
-
```js
|
|
32
|
-
packageImportPath: "import com.cmcc_rn_module.BeiDouBluetoothPackage;",
|
|
33
|
-
packageInstance: "new com.cmcc_rn_module.BeiDouBluetoothPackage()"
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
库内已包含 `android/libs/bluetooth-sdk.aar`,通常无需额外配置。
|
|
37
|
-
|
|
38
23
|
---
|
|
39
24
|
|
|
40
25
|
## 权限与配置
|
|
@@ -63,7 +48,7 @@ packageInstance: "new com.cmcc_rn_module.BeiDouBluetoothPackage()"
|
|
|
63
48
|
|
|
64
49
|
```proguard
|
|
65
50
|
-keep class com.beidou.bluetooth.** { *; }
|
|
66
|
-
-keep class com.
|
|
51
|
+
-keep class com.fxzs.rnbeidou.** { *; }
|
|
67
52
|
```
|
|
68
53
|
|
|
69
54
|
### iOS 权限(Info.plist)
|
package/android/build.gradle
CHANGED
|
@@ -46,12 +46,29 @@ repositories {
|
|
|
46
46
|
google()
|
|
47
47
|
mavenCentral()
|
|
48
48
|
maven { url 'https://www.jitpack.io' }
|
|
49
|
+
maven {
|
|
50
|
+
url "http://10.18.1.5:8081/repository/maven-releases/"
|
|
51
|
+
allowInsecureProtocol = true // 如果私服是HTTP而非HTTPS,需要此配置
|
|
52
|
+
credentials {
|
|
53
|
+
username = "admin" // 如果需要认证
|
|
54
|
+
password = "ZTUz-Yjg0OGRm"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
maven {
|
|
58
|
+
url 'http://117.149.10.66:38185/repository/cmcc-android-public/'
|
|
59
|
+
allowInsecureProtocol(true)
|
|
60
|
+
credentials {
|
|
61
|
+
username 'cmccit'
|
|
62
|
+
password 'RV=hyFmVnR%R)XM(FSt-'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
49
66
|
}
|
|
50
67
|
|
|
51
68
|
dependencies {
|
|
52
69
|
//noinspection GradleDynamicVersion
|
|
53
70
|
implementation "com.facebook.react:react-native:${_reactNativeVersion}"
|
|
54
|
-
|
|
71
|
+
implementation 'com.fxzs:beidousdk:1.0.3@aar' // 关键:添加 @aar 后缀
|
|
55
72
|
// Add local AAR files
|
|
56
73
|
implementation fileTree(dir: "src/main/libs", include: ["*.jar", "*.aar"])
|
|
57
|
-
}
|
|
74
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
-
package="com.
|
|
2
|
+
package="com.fxzs.rnbeidou">
|
|
3
3
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
4
4
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
5
5
|
<!-- Android 10+ 建議聲明後台定位,如不需要可去除 -->
|
package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothModule.java
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.fxzs.rnbeidou;
|
|
2
2
|
|
|
3
3
|
import android.Manifest;
|
|
4
4
|
import android.bluetooth.BluetoothAdapter;
|
|
@@ -59,6 +59,7 @@ import com.facebook.react.bridge.WritableNativeArray;
|
|
|
59
59
|
|
|
60
60
|
public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
61
61
|
private ReactContext reactContext;
|
|
62
|
+
private LogManager logger;
|
|
62
63
|
|
|
63
64
|
// 北斗AIDL服务相关字段
|
|
64
65
|
private IBeidouMsgAidlInterface beidouService;
|
|
@@ -73,10 +74,20 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
73
74
|
public BeiDouBluetoothModule(@Nullable ReactApplicationContext reactContext) {
|
|
74
75
|
super(reactContext);
|
|
75
76
|
this.reactContext = reactContext;
|
|
77
|
+
|
|
78
|
+
// 初始化日志管理器
|
|
79
|
+
this.logger = LogManager.getInstance();
|
|
80
|
+
// 默认配置:根据ApplicationInfo.FLAG_DEBUGGABLE判断是否为Debug模式
|
|
81
|
+
boolean isDebug = reactContext != null &&
|
|
82
|
+
(reactContext.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
83
|
+
logger.initialize(reactContext, isDebug, true, null);
|
|
84
|
+
|
|
85
|
+
logger.i("BeiDouBluetoothModule", "BeiDouBluetoothModule initialized - Debug: " + isDebug);
|
|
86
|
+
|
|
76
87
|
BluetoothSDK.getInstance(reactContext).setPushCallback(new BluetoothPushCallback() {
|
|
77
88
|
@Override
|
|
78
89
|
public void onDevicePush(String deviceNo, String data, int cmd) {
|
|
79
|
-
|
|
90
|
+
logger.d("BeiDouBluetoothModule", "收到设备推送消息: " + data);
|
|
80
91
|
// 处理接收到的数据
|
|
81
92
|
WritableMap writableMap = new WritableNativeMap();
|
|
82
93
|
writableMap.putInt("type", 0);
|
|
@@ -105,9 +116,9 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
105
116
|
long timeInterval = timestamp.longValue();
|
|
106
117
|
boolean send = isSend != null ? isSend : false;
|
|
107
118
|
getChatDBManager().insertMessage(content, phone, send, timeInterval);
|
|
108
|
-
|
|
119
|
+
logger.d("BeiDouBluetoothModule", String.format("插入消息成功 - 手机号: %s, 是否发送: %b", phone, send));
|
|
109
120
|
} catch (Exception e) {
|
|
110
|
-
|
|
121
|
+
logger.e("BeiDouBluetoothModule", "插入消息失败: " + e.getMessage(), e);
|
|
111
122
|
}
|
|
112
123
|
}
|
|
113
124
|
|
|
@@ -174,28 +185,28 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
174
185
|
public void connectToDeviceFromCloudDeviceNO(String deviceNO, Double a, Promise promise) {
|
|
175
186
|
if (StringUtils.isEmpty(deviceNO)) {
|
|
176
187
|
Log.e("BluetoothSDK", "connectToDeviceFromCloudDeviceNO: deviceNo isEmpty");
|
|
177
|
-
promise.resolve("
|
|
188
|
+
promise.resolve("0");
|
|
178
189
|
return;
|
|
179
190
|
}
|
|
180
191
|
BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
181
192
|
BluetoothConnectionCallback connectionCallback = new BluetoothConnectionCallback() {
|
|
182
193
|
@Override
|
|
183
194
|
public void onConnected(String deviceNo) {
|
|
184
|
-
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN:
|
|
185
|
-
promise.resolve("
|
|
195
|
+
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 1");
|
|
196
|
+
promise.resolve("1");
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
@Override
|
|
189
200
|
public void onConnectionFailed(String deviceNo, int errorCode, String errorMessage) {
|
|
190
|
-
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN:
|
|
191
|
-
promise.resolve("
|
|
201
|
+
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 0");
|
|
202
|
+
promise.resolve("0");
|
|
192
203
|
}
|
|
193
204
|
|
|
194
205
|
@Override
|
|
195
206
|
public void onDisconnected(String deviceNo) {
|
|
196
207
|
// 连接过程中意外断开
|
|
197
|
-
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN:
|
|
198
|
-
promise.resolve("
|
|
208
|
+
Log.d("BluetoothSDK", "蓝牙连接状态返回给 RN: 0");
|
|
209
|
+
promise.resolve("0");
|
|
199
210
|
}
|
|
200
211
|
|
|
201
212
|
@Override
|
|
@@ -366,7 +377,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
366
377
|
// }
|
|
367
378
|
@ReactMethod
|
|
368
379
|
public void writeData(String randomString, String deviceNo, Integer command, Integer attrType,
|
|
369
|
-
|
|
380
|
+
Callback writeCallback) {
|
|
370
381
|
BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
371
382
|
Log.d("BluetoothSDK", "收到写入请求" + command + " " + attrType + " " + randomString);
|
|
372
383
|
BluetoothDataCallback dataCallback = new BluetoothDataCallback() {
|
|
@@ -384,7 +395,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
384
395
|
@Override
|
|
385
396
|
public void onDataReceived(String deviceNo, byte[] data, int dataType) {
|
|
386
397
|
// 处理接收到的数据
|
|
387
|
-
//
|
|
398
|
+
// byte[] cipher = Arrays.copyOfRange(data, 4, data.length);
|
|
388
399
|
String message = Base64.getEncoder().encodeToString(data);
|
|
389
400
|
|
|
390
401
|
WritableMap writableMap = new WritableNativeMap();
|
|
@@ -413,7 +424,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
413
424
|
|
|
414
425
|
@ReactMethod
|
|
415
426
|
public void writeInfo(@Nullable String base64Payload, String deviceNO, Integer command, Integer opCode,
|
|
416
|
-
|
|
427
|
+
Integer attrType, Boolean encrypted, Promise promise) {
|
|
417
428
|
try {
|
|
418
429
|
BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
419
430
|
|
|
@@ -438,7 +449,8 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
438
449
|
int attrTypeValue = attrType & 0xFFFF;
|
|
439
450
|
boolean isEncrypted = encrypted != null ? encrypted : false;
|
|
440
451
|
|
|
441
|
-
Log.d("BluetoothSDK", String.format(
|
|
452
|
+
Log.d("BluetoothSDK", String.format(
|
|
453
|
+
"writeInfo - deviceNO: %s, command: 0x%02X, opCode: 0x%02X, attrType: 0x%04X, encrypted: %b",
|
|
442
454
|
deviceNO, commandValue, opCodeValue, attrTypeValue, isEncrypted));
|
|
443
455
|
|
|
444
456
|
// 设置数据回调
|
|
@@ -447,10 +459,10 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
447
459
|
public void onDataWriteSuccess(String deviceNo, byte[] data) {
|
|
448
460
|
Log.d("BluetoothSDK", "writeInfo写入成功");
|
|
449
461
|
// 返回成功结果
|
|
450
|
-
//
|
|
451
|
-
//
|
|
452
|
-
//
|
|
453
|
-
//
|
|
462
|
+
// WritableMap resDict = new WritableNativeMap();
|
|
463
|
+
// resDict.putInt("type", 1);
|
|
464
|
+
// resDict.putString("data", "");
|
|
465
|
+
// promise.resolve(resDict);
|
|
454
466
|
}
|
|
455
467
|
|
|
456
468
|
@Override
|
|
@@ -486,7 +498,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
486
498
|
|
|
487
499
|
// 调用SDK写入数据
|
|
488
500
|
String dataString = Base64.getEncoder().encodeToString(decodedData);
|
|
489
|
-
instance.writeData(dataString, deviceNO, commandValue, attrTypeValue,opCodeValue, isEncrypted);
|
|
501
|
+
instance.writeData(dataString, deviceNO, commandValue, attrTypeValue, opCodeValue, isEncrypted);
|
|
490
502
|
|
|
491
503
|
} catch (Exception e) {
|
|
492
504
|
Log.e("BluetoothSDK", "writeInfo异常: " + e.getMessage());
|
|
@@ -496,7 +508,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
496
508
|
|
|
497
509
|
@ReactMethod
|
|
498
510
|
public void writeValueInfo(String randomString, String deviceNo, Integer command, Integer attrType, Integer value,
|
|
499
|
-
|
|
511
|
+
Callback writeCallback) {
|
|
500
512
|
// BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
|
|
501
513
|
// Log.d(BluetoothSDK.TAG, "收到写入请求" + command +" "+attrType+" "+randomString);
|
|
502
514
|
// Callback callback = args -> {
|
|
@@ -532,8 +544,6 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
532
544
|
BluetoothSDK.getInstance(reactContext).disconnectDevice(deviceNo, disConnectCallback);
|
|
533
545
|
}
|
|
534
546
|
|
|
535
|
-
|
|
536
|
-
|
|
537
547
|
@ReactMethod
|
|
538
548
|
public void fetchCurrentWifiName(Callback callback) {
|
|
539
549
|
String wifiName = "未连接";
|
|
@@ -767,7 +777,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
767
777
|
|
|
768
778
|
@ReactMethod
|
|
769
779
|
public void positionBDMsgEncrypt(ReadableArray receiveList, String inputMsg, double longitude, double latitude,
|
|
770
|
-
|
|
780
|
+
Promise promise) {
|
|
771
781
|
if (!isBeidouServiceBound || beidouService == null) {
|
|
772
782
|
promise.reject("SERVICE_NOT_BOUND", "北斗服务未绑定,请先调用bindBeidouServiceMethod");
|
|
773
783
|
return;
|
|
@@ -899,10 +909,12 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
899
909
|
Location networkLocation = null;
|
|
900
910
|
try {
|
|
901
911
|
gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
|
902
|
-
} catch (Exception ignored) {
|
|
912
|
+
} catch (Exception ignored) {
|
|
913
|
+
}
|
|
903
914
|
try {
|
|
904
915
|
networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
|
905
|
-
} catch (Exception ignored) {
|
|
916
|
+
} catch (Exception ignored) {
|
|
917
|
+
}
|
|
906
918
|
|
|
907
919
|
Location bestLocation = null;
|
|
908
920
|
if (gpsLocation != null && networkLocation != null) {
|
|
@@ -927,8 +939,112 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
|
|
|
927
939
|
map.putDouble("timestamp", (double) bestLocation.getTime());
|
|
928
940
|
promise.resolve(map);
|
|
929
941
|
} catch (Exception e) {
|
|
930
|
-
|
|
942
|
+
logger.e("BeiDouBluetoothModule", "获取GPS位置失败: " + e.getMessage(), e);
|
|
931
943
|
promise.reject("LOCATION_ERROR", "获取GPS位置失败: " + e.getMessage(), e);
|
|
932
944
|
}
|
|
933
945
|
}
|
|
946
|
+
|
|
947
|
+
// ================== 日志管理相关方法 ==================
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* 配置日志管理器
|
|
951
|
+
*
|
|
952
|
+
* @param enableFileLog 是否启用文件日志
|
|
953
|
+
* @param enableConsoleLog 是否启用控制台日志
|
|
954
|
+
* @param maxFileSize 最大文件大小(MB)
|
|
955
|
+
* @param maxFileCount 最大文件数量
|
|
956
|
+
* @param encryptionKey 加密密钥(可选)
|
|
957
|
+
*/
|
|
958
|
+
@ReactMethod
|
|
959
|
+
public void configureLogger(boolean enableFileLog, boolean enableConsoleLog,
|
|
960
|
+
double maxFileSize, int maxFileCount,
|
|
961
|
+
@Nullable String encryptionKey, Promise promise) {
|
|
962
|
+
try {
|
|
963
|
+
// 重新初始化日志管理器
|
|
964
|
+
boolean isDebug = reactContext != null &&
|
|
965
|
+
(reactContext.getApplicationInfo().flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
966
|
+
|
|
967
|
+
logger.initialize(reactContext, isDebug, enableFileLog, encryptionKey);
|
|
968
|
+
logger.setLogConfig(enableFileLog, enableConsoleLog,
|
|
969
|
+
(long) (maxFileSize * 1024 * 1024), maxFileCount);
|
|
970
|
+
|
|
971
|
+
logger.i("BeiDouBluetoothModule", "Logger configured - FileLog: " + enableFileLog +
|
|
972
|
+
", ConsoleLog: " + enableConsoleLog +
|
|
973
|
+
", MaxFileSize: " + maxFileSize + "MB" +
|
|
974
|
+
", MaxFileCount: " + maxFileCount +
|
|
975
|
+
", Encryption: " + (encryptionKey != null));
|
|
976
|
+
|
|
977
|
+
promise.resolve(true);
|
|
978
|
+
} catch (Exception e) {
|
|
979
|
+
logger.e("BeiDouBluetoothModule", "配置日志管理器失败: " + e.getMessage(), e);
|
|
980
|
+
promise.reject("CONFIG_ERROR", "配置日志管理器失败: " + e.getMessage(), e);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* 获取日志统计信息
|
|
986
|
+
*/
|
|
987
|
+
@ReactMethod
|
|
988
|
+
public void getLogStats(Promise promise) {
|
|
989
|
+
try {
|
|
990
|
+
String stats = logger.getLogStats();
|
|
991
|
+
promise.resolve(stats);
|
|
992
|
+
} catch (Exception e) {
|
|
993
|
+
logger.e("BeiDouBluetoothModule", "获取日志统计失败: " + e.getMessage(), e);
|
|
994
|
+
promise.reject("STATS_ERROR", "获取日志统计失败: " + e.getMessage(), e);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* 清空所有日志文件
|
|
1000
|
+
*/
|
|
1001
|
+
@ReactMethod
|
|
1002
|
+
public void clearAllLogs(Promise promise) {
|
|
1003
|
+
try {
|
|
1004
|
+
logger.clearAllLogs();
|
|
1005
|
+
logger.i("BeiDouBluetoothModule", "所有日志文件已清空");
|
|
1006
|
+
promise.resolve(true);
|
|
1007
|
+
} catch (Exception e) {
|
|
1008
|
+
logger.e("BeiDouBluetoothModule", "清空日志失败: " + e.getMessage(), e);
|
|
1009
|
+
promise.reject("CLEAR_ERROR", "清空日志失败: " + e.getMessage(), e);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* 手动记录日志
|
|
1015
|
+
*/
|
|
1016
|
+
@ReactMethod
|
|
1017
|
+
public void writeLog(String level, String tag, String message, Promise promise) {
|
|
1018
|
+
try {
|
|
1019
|
+
switch (level.toUpperCase()) {
|
|
1020
|
+
case "VERBOSE":
|
|
1021
|
+
case "V":
|
|
1022
|
+
logger.v(tag, message);
|
|
1023
|
+
break;
|
|
1024
|
+
case "DEBUG":
|
|
1025
|
+
case "D":
|
|
1026
|
+
logger.d(tag, message);
|
|
1027
|
+
break;
|
|
1028
|
+
case "INFO":
|
|
1029
|
+
case "I":
|
|
1030
|
+
logger.i(tag, message);
|
|
1031
|
+
break;
|
|
1032
|
+
case "WARN":
|
|
1033
|
+
case "W":
|
|
1034
|
+
logger.w(tag, message);
|
|
1035
|
+
break;
|
|
1036
|
+
case "ERROR":
|
|
1037
|
+
case "E":
|
|
1038
|
+
logger.e(tag, message);
|
|
1039
|
+
break;
|
|
1040
|
+
default:
|
|
1041
|
+
logger.i(tag, message);
|
|
1042
|
+
break;
|
|
1043
|
+
}
|
|
1044
|
+
promise.resolve(true);
|
|
1045
|
+
} catch (Exception e) {
|
|
1046
|
+
logger.e("BeiDouBluetoothModule", "写入日志失败: " + e.getMessage(), e);
|
|
1047
|
+
promise.reject("LOG_ERROR", "写入日志失败: " + e.getMessage(), e);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
934
1050
|
}
|
package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothPackage.java
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.fxzs.rnbeidou;
|
|
2
2
|
|
|
3
3
|
import androidx.annotation.NonNull;
|
|
4
4
|
|
|
5
|
-
import com.
|
|
5
|
+
import com.fxzs.rnbeidou.view.CompassManager;
|
|
6
6
|
import com.facebook.react.ReactPackage;
|
|
7
7
|
import com.facebook.react.bridge.NativeModule;
|
|
8
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.fxzs.rnbeidou;
|
|
2
2
|
|
|
3
3
|
import android.util.Log;
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ public class ByteUtil {
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 重复字符生成字符串的兼容方法(替代 String.repeat())
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @param ch 要重复的字符
|
|
15
15
|
* @param count 重复次数
|
|
16
16
|
* @return 重复字符组成的字符串
|