@leonardojc/capacitor-ioboard 1.2.4 → 1.2.6
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.
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/CapacitorIoboardPlugin.java +1 -1
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/IOBoardManager.java +1 -1
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/IOBoardProtocolUtils.java +20 -0
- package/package.json +1 -1
|
@@ -47,7 +47,7 @@ public class CapacitorIoboardPlugin extends Plugin implements IOBoardManager.Ser
|
|
|
47
47
|
|
|
48
48
|
@Override
|
|
49
49
|
public void sendData(byte[] data, IOBoardManager.SerialPortCallback callback) {
|
|
50
|
-
Log.d(TAG, "SerialPortInterface: Sending data: " + IOBoardProtocolUtils.
|
|
50
|
+
Log.d(TAG, "SerialPortInterface: Sending data: " + IOBoardProtocolUtils.frameToHex(data));
|
|
51
51
|
|
|
52
52
|
JSObject result = new JSObject();
|
|
53
53
|
result.put("success", true);
|
|
@@ -285,7 +285,7 @@ public class IOBoardManager {
|
|
|
285
285
|
String dataHex = result.optString("data", "");
|
|
286
286
|
if (!dataHex.isEmpty()) {
|
|
287
287
|
// Convert hex to byte array and then to string
|
|
288
|
-
byte[] responseData = IOBoardProtocolUtils.
|
|
288
|
+
byte[] responseData = IOBoardProtocolUtils.hexStringToBytes(dataHex);
|
|
289
289
|
String response = new String(responseData, java.nio.charset.StandardCharsets.ISO_8859_1);
|
|
290
290
|
Log.d(TAG, "Received response: " + dataHex);
|
|
291
291
|
future.complete(response);
|
|
@@ -105,6 +105,26 @@ public class IOBoardProtocolUtils {
|
|
|
105
105
|
return result.toString();
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Convert hexadecimal string to byte array
|
|
110
|
+
*/
|
|
111
|
+
public static byte[] hexStringToBytes(String hex) {
|
|
112
|
+
if (hex == null || hex.length() % 2 != 0) {
|
|
113
|
+
return new byte[0];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Remove spaces if present
|
|
117
|
+
hex = hex.replaceAll("\\s+", "");
|
|
118
|
+
|
|
119
|
+
int len = hex.length();
|
|
120
|
+
byte[] data = new byte[len / 2];
|
|
121
|
+
for (int i = 0; i < len; i += 2) {
|
|
122
|
+
data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
|
|
123
|
+
+ Character.digit(hex.charAt(i+1), 16));
|
|
124
|
+
}
|
|
125
|
+
return data;
|
|
126
|
+
}
|
|
127
|
+
|
|
108
128
|
/**
|
|
109
129
|
* Create status query frame
|
|
110
130
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "A Capacitor plugin for controlling custom IOBOARD devices via RS485 serial communication with full native protocol implementation",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|