@leonardojc/capacitor-ioboard 2.0.11 → 2.0.13
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;
|
|
@@ -26,6 +26,21 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
26
26
|
private String currentDeviceInfo = "";
|
|
27
27
|
private String lastError = "";
|
|
28
28
|
|
|
29
|
+
// Helper class for pallet configuration
|
|
30
|
+
private static class PalletConfig {
|
|
31
|
+
String ledColor;
|
|
32
|
+
int intensity;
|
|
33
|
+
int blinkTimes;
|
|
34
|
+
int blinkSpeed;
|
|
35
|
+
|
|
36
|
+
PalletConfig(String ledColor, int intensity, int blinkTimes, int blinkSpeed) {
|
|
37
|
+
this.ledColor = ledColor;
|
|
38
|
+
this.intensity = intensity;
|
|
39
|
+
this.blinkTimes = blinkTimes;
|
|
40
|
+
this.blinkSpeed = blinkSpeed;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
29
44
|
// For response waiting in getStatus()
|
|
30
45
|
private volatile byte[] pendingResponse = null;
|
|
31
46
|
private final Object responseLock = new Object();
|
|
@@ -291,49 +306,52 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
291
306
|
}
|
|
292
307
|
|
|
293
308
|
try {
|
|
294
|
-
// Leer parámetros del call
|
|
295
309
|
int address = call.getInt("address", 1);
|
|
296
|
-
|
|
297
|
-
int
|
|
298
|
-
int blinkTimes = call.getInt("blinkTimes", 16);
|
|
299
|
-
int blinkSpeed = call.getInt("blinkSpeed", 1);
|
|
310
|
+
int lockMask = call.getInt("lockMask", 0);
|
|
311
|
+
int extendedControl = call.getInt("extendedControl", 0);
|
|
300
312
|
|
|
301
|
-
// Leer array de pallets
|
|
313
|
+
// Leer array de pallets (objetos con ledColor, intensity, blinkTimes, blinkSpeed)
|
|
302
314
|
JSArray palletsArray = call.getArray("pallets");
|
|
303
|
-
|
|
304
|
-
if (palletsArray
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
pallets.add(palletsArray.getInt(i));
|
|
308
|
-
} catch (Exception e) {
|
|
309
|
-
Log.w(TAG, "Error reading pallet at index " + i);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
315
|
+
|
|
316
|
+
if (palletsArray == null || palletsArray.length() != 8) {
|
|
317
|
+
call.reject("pallets array must contain exactly 8 pallet objects");
|
|
318
|
+
return;
|
|
312
319
|
}
|
|
313
320
|
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
321
|
+
// Parsear los 8 objetos pallet
|
|
322
|
+
List<PalletConfig> pallets = new ArrayList<>();
|
|
323
|
+
for (int i = 0; i < 8; i++) {
|
|
324
|
+
try {
|
|
325
|
+
JSONObject palletJson = palletsArray.getJSONObject(i);
|
|
326
|
+
JSObject pallet = JSObject.fromJSONObject(palletJson);
|
|
327
|
+
|
|
328
|
+
String ledColor = pallet.getString("ledColor", "OFF");
|
|
329
|
+
int intensity = pallet.getInteger("intensity", 0);
|
|
330
|
+
int blinkTimes = pallet.getInteger("blinkTimes", 0);
|
|
331
|
+
int blinkSpeed = pallet.getInteger("blinkSpeed", 1);
|
|
332
|
+
|
|
333
|
+
pallets.add(new PalletConfig(ledColor, intensity, blinkTimes, blinkSpeed));
|
|
334
|
+
|
|
335
|
+
Log.d(TAG, String.format("Pallet %d: color=%s, intensity=%d, blink=%d, speed=%d",
|
|
336
|
+
i+1, ledColor, intensity, blinkTimes, blinkSpeed));
|
|
337
|
+
} catch (Exception e) {
|
|
338
|
+
Log.e(TAG, "Error reading pallet at index " + i + ": " + e.getMessage(), e);
|
|
339
|
+
call.reject("Error parsing pallet at index " + i);
|
|
340
|
+
return;
|
|
318
341
|
}
|
|
319
342
|
}
|
|
320
343
|
|
|
321
|
-
|
|
322
|
-
address, color, intensity, blinkTimes, blinkSpeed, pallets.toString()));
|
|
323
|
-
|
|
324
|
-
byte[] frame = createMultiplePalletsFrame(address, color, intensity, blinkTimes, blinkSpeed, pallets);
|
|
344
|
+
byte[] frame = createFullPalletControlFrame(address, lockMask, extendedControl, pallets);
|
|
325
345
|
boolean success = serialManager.writeData(frame);
|
|
326
346
|
|
|
327
347
|
if (success) {
|
|
328
348
|
JSObject result = new JSObject();
|
|
329
349
|
result.put("success", true);
|
|
330
|
-
result.put("message",
|
|
331
|
-
pallets.size(), color, intensity, blinkTimes));
|
|
350
|
+
result.put("message", "Full pallet control command sent successfully");
|
|
332
351
|
result.put("address", address);
|
|
333
|
-
result.put("palletsCount", pallets.size());
|
|
334
352
|
call.resolve(result);
|
|
335
353
|
} else {
|
|
336
|
-
call.reject("Failed to send
|
|
354
|
+
call.reject("Failed to send full pallet control command");
|
|
337
355
|
}
|
|
338
356
|
|
|
339
357
|
} catch (Exception e) {
|
|
@@ -488,7 +506,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
488
506
|
boolean sent = serialManager.writeData(commandBytes);
|
|
489
507
|
|
|
490
508
|
if (sent) {
|
|
491
|
-
|
|
509
|
+
// Log.i(TAG, "✅ Command successfully written to serial port");
|
|
492
510
|
Log.i(TAG, "HEX sent: " + bytesToHex(commandBytes));
|
|
493
511
|
} else {
|
|
494
512
|
Log.e(TAG, "❌ Failed to write command to serial port");
|
|
@@ -517,7 +535,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
517
535
|
@Override
|
|
518
536
|
public void onDataReceived(byte[] data) {
|
|
519
537
|
String dataString = new String(data);
|
|
520
|
-
Log.d(TAG, "Data received: " + dataString);
|
|
538
|
+
//Log.d(TAG, "Data received: " + dataString);
|
|
521
539
|
|
|
522
540
|
// Store response for getStatus() waiting
|
|
523
541
|
synchronized (responseLock) {
|
|
@@ -707,8 +725,8 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
707
725
|
System.arraycopy(validFrame, 4, result.data, 0, dataLength);
|
|
708
726
|
}
|
|
709
727
|
|
|
710
|
-
Log.d(TAG, String.format("🔍 Parsed - Address: %d, Type: %d, Data length: %d",
|
|
711
|
-
|
|
728
|
+
// Log.d(TAG, String.format("🔍 Parsed - Address: %d, Type: %d, Data length: %d",
|
|
729
|
+
// result.address, result.type, dataLength));
|
|
712
730
|
|
|
713
731
|
// Verificar CRC (antes del EOI final)
|
|
714
732
|
// Frame estructura: [SOI][LEN][ADDR][TYPE][DATA][CRC_LOW][CRC_HIGH][EOI]
|
|
@@ -746,11 +764,11 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
746
764
|
StringBuilder crc3Hex = new StringBuilder();
|
|
747
765
|
for (byte b : frameForCRC3) { crc3Hex.append(String.format("%02X ", b & 0xFF)); }
|
|
748
766
|
|
|
749
|
-
Log.d(TAG, String.format("🔍 CRC V1 (LEN+): %s = 0x%04X", crc1Hex.toString().trim(), calculatedCRC1));
|
|
750
|
-
Log.d(TAG, String.format("🔍 CRC V2 (ADDR+): %s = 0x%04X", crc2Hex.toString().trim(), calculatedCRC2));
|
|
751
|
-
Log.d(TAG, String.format("🔍 CRC V3 (SOI+): %s = 0x%04X", crc3Hex.toString().trim(), calculatedCRC3));
|
|
752
|
-
Log.d(TAG, String.format("🔍 CRC Debug - CRC bytes: 0x%02X 0x%02X at positions %d,%d",
|
|
753
|
-
|
|
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
|
+
// validFrame[crcPos] & 0xFF, validFrame[crcPos + 1] & 0xFF, crcPos, crcPos + 1));
|
|
754
772
|
|
|
755
773
|
// También probar interpretando el CRC como byte único
|
|
756
774
|
int receivedCRC_Single = validFrame[crcPos] & 0xFF; // Solo el primer byte del "CRC"
|
|
@@ -808,8 +826,8 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
808
826
|
}
|
|
809
827
|
|
|
810
828
|
if (!crcValid) {
|
|
811
|
-
Log.w(TAG, "❌ CRC/Checksum mismatch in all variants and formats!");
|
|
812
|
-
Log.i(TAG, "ℹ️ IOBoard may use proprietary checksum algorithm - data parsing will continue");
|
|
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");
|
|
813
831
|
} else {
|
|
814
832
|
Log.i(TAG, String.format("🎯 IOBoard CRC/Checksum format identified: %s", validVariant));
|
|
815
833
|
}
|
|
@@ -823,7 +841,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
823
841
|
}
|
|
824
842
|
|
|
825
843
|
result.isValid = true;
|
|
826
|
-
Log.d(TAG, String.format("✅ Valid IOBoard response parsed: %s", result.toString()));
|
|
844
|
+
//Log.d(TAG, String.format("✅ Valid IOBoard response parsed: %s", result.toString()));
|
|
827
845
|
|
|
828
846
|
return result;
|
|
829
847
|
}
|
|
@@ -846,7 +864,7 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
846
864
|
if (response.data.length >= 6) {
|
|
847
865
|
int systemInfo1 = response.data[4] & 0xFF;
|
|
848
866
|
int systemInfo2 = response.data[5] & 0xFF;
|
|
849
|
-
|
|
867
|
+
// Log.d(TAG, String.format("🔧 System Info: 0x%02X 0x%02X", systemInfo1, systemInfo2));
|
|
850
868
|
}
|
|
851
869
|
}
|
|
852
870
|
}
|
|
@@ -1113,6 +1131,73 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
1113
1131
|
return frameArray;
|
|
1114
1132
|
}
|
|
1115
1133
|
|
|
1134
|
+
// New method for Full Pallet Control with individual pallet configurations
|
|
1135
|
+
private byte[] createFullPalletControlFrame(int address, int lockMask, int extendedControl, List<PalletConfig> pallets) {
|
|
1136
|
+
Log.d(TAG, "🎨 Creating Full Pallet Control frame with individual configs: address=" + address +
|
|
1137
|
+
", lockMask=0x" + String.format("%02X", lockMask) +
|
|
1138
|
+
", extControl=0x" + String.format("%02X", extendedControl));
|
|
1139
|
+
|
|
1140
|
+
byte soi = 0x0D;
|
|
1141
|
+
byte eoi = 0x0A;
|
|
1142
|
+
byte len = 0x39; // 57 bytes
|
|
1143
|
+
byte addr = (byte) address;
|
|
1144
|
+
byte type = 0x02;
|
|
1145
|
+
byte lockCtrl = (byte) lockMask;
|
|
1146
|
+
byte extCtrl = (byte) extendedControl;
|
|
1147
|
+
|
|
1148
|
+
// Build data for CRC
|
|
1149
|
+
List<Byte> dataForCrc = new ArrayList<>();
|
|
1150
|
+
dataForCrc.add(soi);
|
|
1151
|
+
dataForCrc.add(len);
|
|
1152
|
+
dataForCrc.add(addr);
|
|
1153
|
+
dataForCrc.add(type);
|
|
1154
|
+
dataForCrc.add(lockCtrl);
|
|
1155
|
+
dataForCrc.add(extCtrl);
|
|
1156
|
+
|
|
1157
|
+
// Add 8 LED groups (6 bytes each)
|
|
1158
|
+
for (int i = 0; i < 8; i++) {
|
|
1159
|
+
PalletConfig pallet = pallets.get(i);
|
|
1160
|
+
int[] rgb = parseColorToRGB(pallet.ledColor);
|
|
1161
|
+
|
|
1162
|
+
dataForCrc.add((byte) rgb[0]); // R
|
|
1163
|
+
dataForCrc.add((byte) rgb[1]); // G
|
|
1164
|
+
dataForCrc.add((byte) rgb[2]); // B
|
|
1165
|
+
dataForCrc.add((byte) pallet.intensity);
|
|
1166
|
+
dataForCrc.add((byte) pallet.blinkTimes);
|
|
1167
|
+
dataForCrc.add((byte) pallet.blinkSpeed);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// Calculate CRC16
|
|
1171
|
+
byte[] crcData = new byte[dataForCrc.size()];
|
|
1172
|
+
for (int i = 0; i < dataForCrc.size(); i++) {
|
|
1173
|
+
crcData[i] = dataForCrc.get(i);
|
|
1174
|
+
}
|
|
1175
|
+
int crc16 = calculateCRC16Modbus(crcData);
|
|
1176
|
+
byte crcLow = (byte) (crc16 & 0xFF);
|
|
1177
|
+
byte crcHigh = (byte) ((crc16 >> 8) & 0xFF);
|
|
1178
|
+
|
|
1179
|
+
// Build final frame
|
|
1180
|
+
List<Byte> frame = new ArrayList<>();
|
|
1181
|
+
frame.addAll(dataForCrc);
|
|
1182
|
+
frame.add(crcLow);
|
|
1183
|
+
frame.add(crcHigh);
|
|
1184
|
+
frame.add(eoi);
|
|
1185
|
+
|
|
1186
|
+
byte[] frameArray = new byte[frame.size()];
|
|
1187
|
+
for (int i = 0; i < frame.size(); i++) {
|
|
1188
|
+
frameArray[i] = frame.get(i);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// Log frame
|
|
1192
|
+
StringBuilder hexFrame = new StringBuilder();
|
|
1193
|
+
for (byte b : frameArray) {
|
|
1194
|
+
hexFrame.append(String.format("%02X ", b & 0xFF));
|
|
1195
|
+
}
|
|
1196
|
+
Log.d(TAG, "🎯 Full Pallet Control frame created: " + hexFrame.toString().trim());
|
|
1197
|
+
|
|
1198
|
+
return frameArray;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1116
1201
|
// Implementación CRC16-Modbus (x16+x15+x2+1) según documentación MTC3P08L
|
|
1117
1202
|
private static int calculateCRC16Modbus(byte[] data) {
|
|
1118
1203
|
int crc = 0xFFFF; // Initial value
|
|
@@ -194,10 +194,10 @@ public class SerialConnectionManager {
|
|
|
194
194
|
try {
|
|
195
195
|
// Enhanced logging with hex dump (DEBUG only)
|
|
196
196
|
logDebug("=== WRITING TO SERIAL PORT ===");
|
|
197
|
-
logDebug("Port: " + currentPortPath);
|
|
198
|
-
logDebug("Data length: " + data.length + " bytes");
|
|
197
|
+
//logDebug("Port: " + currentPortPath);
|
|
198
|
+
//logDebug("Data length: " + data.length + " bytes");
|
|
199
199
|
logDebug("HEX data: " + bytesToHex(data));
|
|
200
|
-
logDebug("Raw bytes: " + java.util.Arrays.toString(data));
|
|
200
|
+
//logDebug("Raw bytes: " + java.util.Arrays.toString(data));
|
|
201
201
|
|
|
202
202
|
// Clear any pending input first
|
|
203
203
|
if (serialInputStream != null && serialInputStream.available() > 0) {
|
|
@@ -351,16 +351,16 @@ public class SerialConnectionManager {
|
|
|
351
351
|
|
|
352
352
|
// Enhanced logging for received data (DEBUG only for detailed hex)
|
|
353
353
|
logDebug("=== 📥 RECEIVED FROM IOBOARD ===");
|
|
354
|
-
logDebug("Port: " + currentPortPath);
|
|
355
|
-
logDebug("Received " + bytesRead + " bytes");
|
|
354
|
+
//logDebug("Port: " + currentPortPath);
|
|
355
|
+
//logDebug("Received " + bytesRead + " bytes");
|
|
356
356
|
logDebug("HEX received: " + bytesToHex(data));
|
|
357
|
-
logDebug("Raw bytes: " + java.util.Arrays.toString(data));
|
|
357
|
+
//logDebug("Raw bytes: " + java.util.Arrays.toString(data));
|
|
358
358
|
|
|
359
359
|
// Parser automático de respuesta del IOBoard
|
|
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));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.13",
|
|
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",
|