@leonardojc/capacitor-ioboard 2.0.13 → 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.
@@ -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");
@@ -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
- Log.d(TAG, String.format("📏 Payload length: %d bytes (includes LEN byte itself)", payloadLength));
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
- Log.w(TAG, String.format("❌ Invalid EOI: expected 0x0A at position %d, got 0x%02X",
710
- eoiPos, validFrame[eoiPos] & 0xFF));
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;
@@ -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
- Log.d(TAG, "🔍 No immediate response detected - this is normal for some IOBoard operations");
236
+ // Log.d(TAG, "🔍 No immediate response detected - this is normal for some IOBoard operations");
237
237
  }
238
238
  }
239
239
 
@@ -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.13",
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",