@leonardojc/capacitor-ioboard 2.0.11 → 2.0.12
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.
|
@@ -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) {
|
|
@@ -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,10 +351,10 @@ 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 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
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",
|