@leonardojc/capacitor-ioboard 2.0.5 → 2.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.
|
@@ -14,6 +14,11 @@ import java.util.ArrayList;
|
|
|
14
14
|
public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionManager.SerialDataListener {
|
|
15
15
|
|
|
16
16
|
private static final String TAG = "CapacitorIoboard";
|
|
17
|
+
|
|
18
|
+
// Debug mode control
|
|
19
|
+
// Set to false for production to minimize logs
|
|
20
|
+
private static final boolean DEBUG_MODE = BuildConfig.DEBUG;
|
|
21
|
+
|
|
17
22
|
private SerialConnectionManager serialManager;
|
|
18
23
|
private IOBoardManager ioBoardManager;
|
|
19
24
|
private boolean isConnected = false;
|
|
@@ -23,6 +28,33 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
23
28
|
// For response waiting in getStatus()
|
|
24
29
|
private volatile byte[] pendingResponse = null;
|
|
25
30
|
private final Object responseLock = new Object();
|
|
31
|
+
|
|
32
|
+
// Helper methods for conditional logging
|
|
33
|
+
private void logDebug(String message) {
|
|
34
|
+
if (DEBUG_MODE) {
|
|
35
|
+
Log.d(TAG, message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private void logInfo(String message) {
|
|
40
|
+
// Always log INFO level (important events)
|
|
41
|
+
Log.i(TAG, message);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private void logWarning(String message) {
|
|
45
|
+
// Always log warnings
|
|
46
|
+
Log.w(TAG, message);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private void logError(String message) {
|
|
50
|
+
// Always log errors
|
|
51
|
+
Log.e(TAG, message);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private void logError(String message, Throwable throwable) {
|
|
55
|
+
// Always log errors with exceptions
|
|
56
|
+
Log.e(TAG, message, throwable);
|
|
57
|
+
}
|
|
26
58
|
|
|
27
59
|
// Helper method to convert bytes to hex string for debugging
|
|
28
60
|
private String bytesToHex(byte[] bytes) {
|
|
@@ -122,14 +154,16 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
122
154
|
|
|
123
155
|
@PluginMethod
|
|
124
156
|
public void getStatus(PluginCall call) {
|
|
125
|
-
|
|
157
|
+
logDebug("📊 getStatus called");
|
|
126
158
|
|
|
127
159
|
if (serialManager == null) {
|
|
160
|
+
logError("Serial connection not initialized");
|
|
128
161
|
call.reject("Serial connection not initialized");
|
|
129
162
|
return;
|
|
130
163
|
}
|
|
131
164
|
|
|
132
165
|
if (!serialManager.isConnected()) {
|
|
166
|
+
logError("Not connected to serial port");
|
|
133
167
|
call.reject("Not connected to serial port");
|
|
134
168
|
return;
|
|
135
169
|
}
|
|
@@ -206,13 +240,13 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
206
240
|
}
|
|
207
241
|
result.put("doorStatusText", doorStatusText.toString());
|
|
208
242
|
|
|
209
|
-
|
|
243
|
+
logInfo(String.format("✅ IOBoard Status - Firmware: %s, Door Status: 0x%02X (%s)",
|
|
210
244
|
parsedResponse.firmware, parsedResponse.doorStatus, doorStatusText.toString()));
|
|
211
245
|
|
|
212
246
|
call.resolve(result);
|
|
213
247
|
|
|
214
248
|
} catch (InterruptedException e) {
|
|
215
|
-
|
|
249
|
+
logError("Thread interrupted while waiting for status: " + e.getMessage(), e);
|
|
216
250
|
call.reject("Status query interrupted: " + e.getMessage());
|
|
217
251
|
} catch (Exception e) {
|
|
218
252
|
Log.e(TAG, "Error in getStatus: " + e.getMessage(), e);
|
|
@@ -19,6 +19,9 @@ import java.util.concurrent.Executors;
|
|
|
19
19
|
public class SerialConnectionManager {
|
|
20
20
|
private static final String TAG = "SerialConnectionManager";
|
|
21
21
|
|
|
22
|
+
// Debug mode control - matches CapacitorIoboardPlugin
|
|
23
|
+
private static final boolean DEBUG_MODE = BuildConfig.DEBUG;
|
|
24
|
+
|
|
22
25
|
public interface SerialDataListener {
|
|
23
26
|
void onDataReceived(byte[] data);
|
|
24
27
|
void onConnectionStateChanged(boolean connected);
|
|
@@ -37,7 +40,30 @@ public class SerialConnectionManager {
|
|
|
37
40
|
public SerialConnectionManager() {
|
|
38
41
|
mainHandler = new Handler(Looper.getMainLooper());
|
|
39
42
|
executorService = Executors.newSingleThreadExecutor();
|
|
40
|
-
|
|
43
|
+
logDebug("SerialConnectionManager initialized");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Helper methods for conditional logging
|
|
47
|
+
private void logDebug(String message) {
|
|
48
|
+
if (DEBUG_MODE) {
|
|
49
|
+
Log.d(TAG, message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private void logInfo(String message) {
|
|
54
|
+
Log.i(TAG, message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private void logWarning(String message) {
|
|
58
|
+
Log.w(TAG, message);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private void logError(String message) {
|
|
62
|
+
Log.e(TAG, message);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private void logError(String message, Throwable throwable) {
|
|
66
|
+
Log.e(TAG, message, throwable);
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
public void setDataListener(SerialDataListener listener) {
|
|
@@ -166,32 +192,35 @@ public class SerialConnectionManager {
|
|
|
166
192
|
}
|
|
167
193
|
|
|
168
194
|
try {
|
|
169
|
-
// Enhanced logging with hex dump
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
195
|
+
// Enhanced logging with hex dump (DEBUG only)
|
|
196
|
+
logDebug("=== WRITING TO SERIAL PORT ===");
|
|
197
|
+
logDebug("Port: " + currentPortPath);
|
|
198
|
+
logDebug("Data length: " + data.length + " bytes");
|
|
199
|
+
logDebug("HEX data: " + bytesToHex(data));
|
|
200
|
+
logDebug("Raw bytes: " + java.util.Arrays.toString(data));
|
|
175
201
|
|
|
176
202
|
// Clear any pending input first
|
|
177
203
|
if (serialInputStream != null && serialInputStream.available() > 0) {
|
|
178
204
|
int available = serialInputStream.available();
|
|
179
205
|
byte[] discarded = new byte[available];
|
|
180
206
|
serialInputStream.read(discarded);
|
|
181
|
-
|
|
207
|
+
logDebug("Discarded " + available + " pending bytes before write");
|
|
182
208
|
}
|
|
183
209
|
|
|
184
210
|
long startTime = System.currentTimeMillis();
|
|
185
211
|
|
|
186
212
|
// Write entire frame at once (IOBoard expects complete frame)
|
|
187
|
-
|
|
213
|
+
logDebug("Sending complete frame as single write operation...");
|
|
188
214
|
serialOutputStream.write(data);
|
|
189
215
|
serialOutputStream.flush();
|
|
190
216
|
|
|
191
217
|
long endTime = System.currentTimeMillis();
|
|
192
218
|
|
|
193
|
-
|
|
194
|
-
|
|
219
|
+
// Only log summary in production
|
|
220
|
+
if (DEBUG_MODE) {
|
|
221
|
+
logInfo("✅ Successfully wrote " + data.length + " bytes in " + (endTime - startTime) + "ms");
|
|
222
|
+
logInfo("HEX written: " + bytesToHex(data));
|
|
223
|
+
}
|
|
195
224
|
|
|
196
225
|
// Wait longer for IOBoard response (some devices need more processing time)
|
|
197
226
|
Thread.sleep(200); // Increased from 50ms to 200ms
|
|
@@ -320,38 +349,42 @@ public class SerialConnectionManager {
|
|
|
320
349
|
byte[] data = new byte[bytesRead];
|
|
321
350
|
System.arraycopy(buffer, 0, data, 0, bytesRead);
|
|
322
351
|
|
|
323
|
-
// Enhanced logging for received data
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
352
|
+
// Enhanced logging for received data (DEBUG only for detailed hex)
|
|
353
|
+
logDebug("=== 📥 RECEIVED FROM IOBOARD ===");
|
|
354
|
+
logDebug("Port: " + currentPortPath);
|
|
355
|
+
logDebug("Received " + bytesRead + " bytes");
|
|
356
|
+
logDebug("HEX received: " + bytesToHex(data));
|
|
357
|
+
logDebug("Raw bytes: " + java.util.Arrays.toString(data));
|
|
329
358
|
|
|
330
359
|
// Parser automático de respuesta del IOBoard
|
|
331
360
|
try {
|
|
332
361
|
CapacitorIoboardPlugin.IOBoardResponse response = CapacitorIoboardPlugin.parseIOBoardResponse(data);
|
|
333
362
|
if (response.isValid) {
|
|
334
|
-
|
|
363
|
+
logDebug(String.format("🎯 IOBoard Response Parsed Successfully: %s", response.toString()));
|
|
335
364
|
|
|
336
365
|
// Logging específico según tipo de respuesta
|
|
337
366
|
if (response.type == 0x00) { // Status Response
|
|
338
|
-
|
|
367
|
+
logInfo(String.format("📊 IOBoard Status - Firmware: %s, Door Status: 0x%02X",
|
|
339
368
|
response.firmware, response.doorStatus));
|
|
340
369
|
|
|
341
|
-
// Interpretar door status
|
|
342
|
-
|
|
343
|
-
|
|
370
|
+
// Interpretar door status (DEBUG only)
|
|
371
|
+
if (DEBUG_MODE) {
|
|
372
|
+
String doorStatusDesc = interpretDoorStatus(response.doorStatus);
|
|
373
|
+
logInfo(String.format("🚪 Door Status: %s", doorStatusDesc));
|
|
374
|
+
}
|
|
344
375
|
}
|
|
345
376
|
} else {
|
|
346
|
-
|
|
377
|
+
logWarning("⚠️ Received invalid IOBoard response - trying ASCII interpretation");
|
|
347
378
|
|
|
348
|
-
// Try to interpret as ASCII if printable
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
379
|
+
// Try to interpret as ASCII if printable (DEBUG only)
|
|
380
|
+
if (DEBUG_MODE) {
|
|
381
|
+
String ascii = new String(data);
|
|
382
|
+
boolean isPrintable = ascii.chars().allMatch(c -> c >= 32 && c <= 126);
|
|
383
|
+
if (isPrintable) {
|
|
384
|
+
logDebug("ASCII: '" + ascii + "'");
|
|
385
|
+
} else {
|
|
386
|
+
logDebug("Binary data (non-ASCII)");
|
|
387
|
+
}
|
|
355
388
|
}
|
|
356
389
|
}
|
|
357
390
|
} catch (Exception e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "A comprehensive Capacitor plugin for IOBoard devices with integrated serial communication and complete MTC3P08L protocol support including OTA updates",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|