@leonardojc/capacitor-ioboard 2.0.12 → 2.0.14
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.
|
@@ -18,7 +18,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
18
18
|
|
|
19
19
|
// Debug mode control
|
|
20
20
|
// Set to false for production to minimize logs
|
|
21
|
-
private static final boolean DEBUG_MODE =
|
|
21
|
+
private static final boolean DEBUG_MODE = false;
|
|
22
22
|
|
|
23
23
|
private SerialConnectionManager serialManager;
|
|
24
24
|
private IOBoardManager ioBoardManager;
|
|
@@ -168,6 +168,57 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Send raw command bytes directly to the serial port
|
|
173
|
+
* Useful for OTA updates and custom protocol commands
|
|
174
|
+
*/
|
|
175
|
+
@PluginMethod
|
|
176
|
+
public void sendRawCommand(PluginCall call) {
|
|
177
|
+
logDebug("📤 sendRawCommand called");
|
|
178
|
+
|
|
179
|
+
if (serialManager == null) {
|
|
180
|
+
logError("Serial connection not initialized");
|
|
181
|
+
call.reject("Serial connection not initialized");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!serialManager.isConnected()) {
|
|
186
|
+
logError("Not connected to serial port");
|
|
187
|
+
call.reject("Not connected to serial port");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
JSArray dataArray = call.getArray("data");
|
|
193
|
+
if (dataArray == null) {
|
|
194
|
+
call.reject("data parameter is required");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Convert JSArray to byte[]
|
|
199
|
+
byte[] frame = new byte[dataArray.length()];
|
|
200
|
+
for (int i = 0; i < dataArray.length(); i++) {
|
|
201
|
+
frame[i] = (byte) dataArray.getInt(i);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
logDebug("📤 Sending raw frame: " + bytesToHex(frame));
|
|
205
|
+
|
|
206
|
+
// Send frame directly via serial port
|
|
207
|
+
serialManager.sendData(frame);
|
|
208
|
+
|
|
209
|
+
JSObject result = new JSObject();
|
|
210
|
+
result.put("success", true);
|
|
211
|
+
result.put("bytesSent", frame.length);
|
|
212
|
+
result.put("hexFrame", bytesToHex(frame));
|
|
213
|
+
|
|
214
|
+
call.resolve(result);
|
|
215
|
+
|
|
216
|
+
} catch (Exception e) {
|
|
217
|
+
logError("Error sending raw command: " + e.getMessage(), e);
|
|
218
|
+
call.reject("Error sending raw command: " + e.getMessage());
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
171
222
|
@PluginMethod
|
|
172
223
|
public void getStatus(PluginCall call) {
|
|
173
224
|
logDebug("📊 getStatus called");
|
|
@@ -506,7 +557,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
506
557
|
boolean sent = serialManager.writeData(commandBytes);
|
|
507
558
|
|
|
508
559
|
if (sent) {
|
|
509
|
-
|
|
560
|
+
// Log.i(TAG, "✅ Command successfully written to serial port");
|
|
510
561
|
Log.i(TAG, "HEX sent: " + bytesToHex(commandBytes));
|
|
511
562
|
} else {
|
|
512
563
|
Log.e(TAG, "❌ Failed to write command to serial port");
|
|
@@ -535,7 +586,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
535
586
|
@Override
|
|
536
587
|
public void onDataReceived(byte[] data) {
|
|
537
588
|
String dataString = new String(data);
|
|
538
|
-
Log.d(TAG, "Data received: " + dataString);
|
|
589
|
+
//Log.d(TAG, "Data received: " + dataString);
|
|
539
590
|
|
|
540
591
|
// Store response for getStatus() waiting
|
|
541
592
|
synchronized (responseLock) {
|
|
@@ -662,7 +713,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
662
713
|
|
|
663
714
|
// Obtener longitud del payload (incluye LEN + ADDRESS + TYPE + DATA + CRC + EOI)
|
|
664
715
|
int payloadLength = response[1] & 0xFF;
|
|
665
|
-
|
|
716
|
+
// Log.d(TAG, String.format("📏 Payload length: %d bytes (includes LEN byte itself)", payloadLength));
|
|
666
717
|
|
|
667
718
|
// Calcular el tamaño del frame válido según documentación: SOI + payload
|
|
668
719
|
// El payloadLength ya incluye todo desde LEN hasta EOI
|
|
@@ -705,10 +756,11 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
705
756
|
|
|
706
757
|
// Verificar EOI al final del frame (según documentación debe ser 0x0A)
|
|
707
758
|
int eoiPos = validFrameLength - 1;
|
|
708
|
-
if ((validFrame[eoiPos] & 0xFF) != 0x0A) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
759
|
+
// if ((validFrame[eoiPos] & 0xFF) != 0x0A) {
|
|
760
|
+
|
|
761
|
+
// Log.w(TAG, String.format("❌ Invalid EOI: expected 0x0A at position %d, got 0x%02X",
|
|
762
|
+
// eoiPos, validFrame[eoiPos] & 0xFF));
|
|
763
|
+
// }
|
|
712
764
|
|
|
713
765
|
// Extraer campos del payload (saltando SOI y LEN)
|
|
714
766
|
result.address = validFrame[2] & 0xFF;
|
|
@@ -725,8 +777,8 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
725
777
|
System.arraycopy(validFrame, 4, result.data, 0, dataLength);
|
|
726
778
|
}
|
|
727
779
|
|
|
728
|
-
Log.d(TAG, String.format("🔍 Parsed - Address: %d, Type: %d, Data length: %d",
|
|
729
|
-
|
|
780
|
+
// Log.d(TAG, String.format("🔍 Parsed - Address: %d, Type: %d, Data length: %d",
|
|
781
|
+
// result.address, result.type, dataLength));
|
|
730
782
|
|
|
731
783
|
// Verificar CRC (antes del EOI final)
|
|
732
784
|
// Frame estructura: [SOI][LEN][ADDR][TYPE][DATA][CRC_LOW][CRC_HIGH][EOI]
|
|
@@ -764,11 +816,11 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
764
816
|
StringBuilder crc3Hex = new StringBuilder();
|
|
765
817
|
for (byte b : frameForCRC3) { crc3Hex.append(String.format("%02X ", b & 0xFF)); }
|
|
766
818
|
|
|
767
|
-
Log.d(TAG, String.format("🔍 CRC V1 (LEN+): %s = 0x%04X", crc1Hex.toString().trim(), calculatedCRC1));
|
|
768
|
-
Log.d(TAG, String.format("🔍 CRC V2 (ADDR+): %s = 0x%04X", crc2Hex.toString().trim(), calculatedCRC2));
|
|
769
|
-
Log.d(TAG, String.format("🔍 CRC V3 (SOI+): %s = 0x%04X", crc3Hex.toString().trim(), calculatedCRC3));
|
|
770
|
-
Log.d(TAG, String.format("🔍 CRC Debug - CRC bytes: 0x%02X 0x%02X at positions %d,%d",
|
|
771
|
-
|
|
819
|
+
// Log.d(TAG, String.format("🔍 CRC V1 (LEN+): %s = 0x%04X", crc1Hex.toString().trim(), calculatedCRC1));
|
|
820
|
+
// Log.d(TAG, String.format("🔍 CRC V2 (ADDR+): %s = 0x%04X", crc2Hex.toString().trim(), calculatedCRC2));
|
|
821
|
+
// Log.d(TAG, String.format("🔍 CRC V3 (SOI+): %s = 0x%04X", crc3Hex.toString().trim(), calculatedCRC3));
|
|
822
|
+
// Log.d(TAG, String.format("🔍 CRC Debug - CRC bytes: 0x%02X 0x%02X at positions %d,%d",
|
|
823
|
+
// validFrame[crcPos] & 0xFF, validFrame[crcPos + 1] & 0xFF, crcPos, crcPos + 1));
|
|
772
824
|
|
|
773
825
|
// También probar interpretando el CRC como byte único
|
|
774
826
|
int receivedCRC_Single = validFrame[crcPos] & 0xFF; // Solo el primer byte del "CRC"
|
|
@@ -826,8 +878,8 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
826
878
|
}
|
|
827
879
|
|
|
828
880
|
if (!crcValid) {
|
|
829
|
-
Log.w(TAG, "❌ CRC/Checksum mismatch in all variants and formats!");
|
|
830
|
-
Log.i(TAG, "ℹ️ IOBoard may use proprietary checksum algorithm - data parsing will continue");
|
|
881
|
+
//Log.w(TAG, "❌ CRC/Checksum mismatch in all variants and formats!");
|
|
882
|
+
//Log.i(TAG, "ℹ️ IOBoard may use proprietary checksum algorithm - data parsing will continue");
|
|
831
883
|
} else {
|
|
832
884
|
Log.i(TAG, String.format("🎯 IOBoard CRC/Checksum format identified: %s", validVariant));
|
|
833
885
|
}
|
|
@@ -841,7 +893,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
841
893
|
}
|
|
842
894
|
|
|
843
895
|
result.isValid = true;
|
|
844
|
-
Log.d(TAG, String.format("✅ Valid IOBoard response parsed: %s", result.toString()));
|
|
896
|
+
//Log.d(TAG, String.format("✅ Valid IOBoard response parsed: %s", result.toString()));
|
|
845
897
|
|
|
846
898
|
return result;
|
|
847
899
|
}
|
|
@@ -864,7 +916,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
864
916
|
if (response.data.length >= 6) {
|
|
865
917
|
int systemInfo1 = response.data[4] & 0xFF;
|
|
866
918
|
int systemInfo2 = response.data[5] & 0xFF;
|
|
867
|
-
|
|
919
|
+
// Log.d(TAG, String.format("🔧 System Info: 0x%02X 0x%02X", systemInfo1, systemInfo2));
|
|
868
920
|
}
|
|
869
921
|
}
|
|
870
922
|
}
|
|
@@ -233,7 +233,7 @@ public class SerialConnectionManager {
|
|
|
233
233
|
if (available > 0) {
|
|
234
234
|
Log.w(TAG, "⚠️ DATA AVAILABLE AFTER WRITE! " + available + " bytes - reader thread should pick this up");
|
|
235
235
|
} else {
|
|
236
|
-
|
|
236
|
+
// Log.d(TAG, "🔍 No immediate response detected - this is normal for some IOBoard operations");
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -360,7 +360,7 @@ public class SerialConnectionManager {
|
|
|
360
360
|
try {
|
|
361
361
|
CapacitorIoboardPlugin.IOBoardResponse response = CapacitorIoboardPlugin.parseIOBoardResponse(data);
|
|
362
362
|
if (response.isValid) {
|
|
363
|
-
|
|
363
|
+
// logDebug(String.format("🎯 IOBoard Response Parsed Successfully: %s", response.toString()));
|
|
364
364
|
|
|
365
365
|
// Logging específico según tipo de respuesta
|
|
366
366
|
if (response.type == 0x00) { // Status Response
|
|
@@ -400,7 +400,7 @@ public class SerialConnectionManager {
|
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
|
|
403
|
+
// Log.d(TAG, "=== END RECEIVED DATA ===");
|
|
404
404
|
|
|
405
405
|
notifyDataReceived(data);
|
|
406
406
|
}
|
|
@@ -451,7 +451,7 @@ public class SerialConnectionManager {
|
|
|
451
451
|
|
|
452
452
|
private void notifyDataReceived(byte[] data) {
|
|
453
453
|
if (listener != null) {
|
|
454
|
-
|
|
454
|
+
// Log.d(TAG, "Notifying listener of received data: " + bytesToHex(data));
|
|
455
455
|
mainHandler.post(() -> listener.onDataReceived(data));
|
|
456
456
|
} else {
|
|
457
457
|
Log.w(TAG, "No listener set for received data: " + bytesToHex(data));
|
|
@@ -42,6 +42,19 @@ export interface CapacitorIoboardPlugin {
|
|
|
42
42
|
hexSent?: string;
|
|
43
43
|
error?: string;
|
|
44
44
|
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Send raw command bytes directly to IOBoard
|
|
47
|
+
* Used for OTA updates and custom protocol commands
|
|
48
|
+
* @param options Raw command data as byte array
|
|
49
|
+
*/
|
|
50
|
+
sendRawFrame(options: {
|
|
51
|
+
data: number[];
|
|
52
|
+
}): Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
bytesSent?: number;
|
|
55
|
+
hexFrame?: string;
|
|
56
|
+
error?: string;
|
|
57
|
+
}>;
|
|
45
58
|
/**
|
|
46
59
|
* Query the status of an IOBOARD device
|
|
47
60
|
* @param options Device address and timeout
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.14",
|
|
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",
|