@leonardojc/capacitor-ioboard 1.1.0
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/CapacitorIoboard.podspec +13 -0
- package/LICENSE +21 -0
- package/README.md +292 -0
- package/android/build.gradle +39 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/CapacitorIoboardPlugin.java +336 -0
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/IOBoardManager.java +657 -0
- package/dist/esm/definitions.d.ts +154 -0
- package/dist/esm/definitions.js +43 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/protocol.d.ts +62 -0
- package/dist/esm/protocol.js +191 -0
- package/dist/esm/web.d.ts +17 -0
- package/dist/esm/web.js +167 -0
- package/dist/plugin.cjs.js +422 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +425 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/CapacitorIoboard.swift +8 -0
- package/ios/Plugin/CapacitorIoboardPlugin.m +15 -0
- package/ios/Plugin/CapacitorIoboardPlugin.swift +142 -0
- package/package.json +97 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Pod::Spec.new do |s|
|
|
2
|
+
s.name = 'CapacitorIoboard'
|
|
3
|
+
s.version = '1.0.0'
|
|
4
|
+
s.summary = 'Capacitor plugin for controlling IOBOARD devices via RS485 serial communication'
|
|
5
|
+
s.license = 'MIT'
|
|
6
|
+
s.homepage = 'https://github.com/leonardojc/capacitor-ioboard'
|
|
7
|
+
s.author = { 'Leonardo JC' => 'leonardojc@example.com' }
|
|
8
|
+
s.source = { :git => 'https://github.com/leonardojc/capacitor-ioboard', :tag => s.version.to_s }
|
|
9
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
10
|
+
s.ios.deployment_target = '12.0'
|
|
11
|
+
s.dependency 'Capacitor'
|
|
12
|
+
s.swift_version = '5.1'
|
|
13
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Leonardo JC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# @leonardojc/capacitor-ioboard
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for controlling IOBOARD devices via RS485 serial communication.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @leonardojc/capacitor-ioboard
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
This plugin requires the [@leonardojc/capacitor-serial-port](https://www.npmjs.com/package/@leonardojc/capacitor-serial-port) plugin for serial communication.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @leonardojc/capacitor-serial-port
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Hardware Requirements
|
|
21
|
+
|
|
22
|
+
- IOBOARD MTC3P08L device
|
|
23
|
+
- Serial to RS485 adapter (transparent to the application)
|
|
24
|
+
- Android device with USB OTG support or USB-to-serial adapter
|
|
25
|
+
|
|
26
|
+
## API
|
|
27
|
+
|
|
28
|
+
### Connection Management
|
|
29
|
+
|
|
30
|
+
#### `openConnection(options)`
|
|
31
|
+
|
|
32
|
+
Opens a serial connection with the specified parameters.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { CapacitorIoboard } from '@leonardojc/capacitor-ioboard';
|
|
36
|
+
|
|
37
|
+
const result = await CapacitorIoboard.openConnection({
|
|
38
|
+
baudRate: 115200,
|
|
39
|
+
dataBits: 8,
|
|
40
|
+
stopBits: 1,
|
|
41
|
+
parity: 'none',
|
|
42
|
+
timeout: 5000
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Parameters:**
|
|
47
|
+
|
|
48
|
+
| Name | Type | Default | Description |
|
|
49
|
+
|--------------|-------------------------------|-----------|--------------------------------|
|
|
50
|
+
| baudRate | number | 115200 | Baud rate for communication |
|
|
51
|
+
| dataBits | number | 8 | Number of data bits |
|
|
52
|
+
| stopBits | number | 1 | Number of stop bits |
|
|
53
|
+
| parity | 'none' \| 'even' \| 'odd' | 'none' | Parity checking |
|
|
54
|
+
| flowControl | 'none' \| 'hardware' \| 'software' | 'none' | Flow control method |
|
|
55
|
+
| timeout | number | 5000 | Response timeout (ms) |
|
|
56
|
+
|
|
57
|
+
#### `closeConnection()`
|
|
58
|
+
|
|
59
|
+
Closes the serial connection.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const result = await CapacitorIoboard.closeConnection();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `isConnected()`
|
|
66
|
+
|
|
67
|
+
Checks if a serial connection is active.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const status = await CapacitorIoboard.isConnected();
|
|
71
|
+
console.log('Connected:', status.connected);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Device Control
|
|
75
|
+
|
|
76
|
+
#### `queryStatus(options)`
|
|
77
|
+
|
|
78
|
+
Queries the status of an IOBOARD device.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const response = await CapacitorIoboard.queryStatus({ address: 1 });
|
|
82
|
+
|
|
83
|
+
if (response.success && response.data) {
|
|
84
|
+
console.log('Door Lock Status:', response.data.doorLockStatus);
|
|
85
|
+
console.log('Software Version:', response.data.softwareVersion);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Parameters:**
|
|
90
|
+
|
|
91
|
+
| Name | Type | Description |
|
|
92
|
+
|---------|--------|------------------------------------|
|
|
93
|
+
| address | number | IOBOARD address (1-63) |
|
|
94
|
+
|
|
95
|
+
**Response:**
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
{
|
|
99
|
+
success: boolean;
|
|
100
|
+
message?: string;
|
|
101
|
+
data?: {
|
|
102
|
+
doorLockStatus: number; // 8-bit status (each bit represents a lock)
|
|
103
|
+
softwareVersion: {
|
|
104
|
+
major: number;
|
|
105
|
+
minor: number;
|
|
106
|
+
patch: number;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### `controlSinglePallet(options)`
|
|
113
|
+
|
|
114
|
+
Controls a single pallet on the IOBOARD.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const response = await CapacitorIoboard.controlSinglePallet({
|
|
118
|
+
address: 1,
|
|
119
|
+
palletNumber: 0,
|
|
120
|
+
doorLock: true, // true = unlock, false = no action
|
|
121
|
+
ledControl: {
|
|
122
|
+
red: 255,
|
|
123
|
+
green: 0,
|
|
124
|
+
blue: 0,
|
|
125
|
+
intensity: 100,
|
|
126
|
+
blinkTimes: 5,
|
|
127
|
+
blinkSpeed: 2
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Parameters:**
|
|
133
|
+
|
|
134
|
+
| Name | Type | Description |
|
|
135
|
+
|--------------|-------------------|-----------------------------------|
|
|
136
|
+
| address | number | IOBOARD address (1-63) |
|
|
137
|
+
| palletNumber | number | Pallet number (0-7) |
|
|
138
|
+
| doorLock | boolean | true = unlock, false = no action |
|
|
139
|
+
| ledControl | LEDControlOptions | LED control parameters |
|
|
140
|
+
|
|
141
|
+
#### `controlFullPallet(options)`
|
|
142
|
+
|
|
143
|
+
Controls all pallets on the IOBOARD.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const ledControls = Array(8).fill({
|
|
147
|
+
red: 0, green: 255, blue: 0,
|
|
148
|
+
intensity: 50, blinkTimes: 0, blinkSpeed: 0
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const response = await CapacitorIoboard.controlFullPallet({
|
|
152
|
+
address: 1,
|
|
153
|
+
doorLockControl: 0xFF, // 8-bit mask (unlock all)
|
|
154
|
+
extendedControl: 0x00,
|
|
155
|
+
ledControls: ledControls
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Parameters:**
|
|
160
|
+
|
|
161
|
+
| Name | Type | Description |
|
|
162
|
+
|-----------------|---------------------|--------------------------------|
|
|
163
|
+
| address | number | IOBOARD address (1-63) |
|
|
164
|
+
| doorLockControl | number | 8-bit mask for door control |
|
|
165
|
+
| extendedControl | number | Extended control byte |
|
|
166
|
+
| ledControls | LEDControlOptions[] | Array of 8 LED control configs |
|
|
167
|
+
|
|
168
|
+
### LED Control Options
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface LEDControlOptions {
|
|
172
|
+
red: number; // 0-255
|
|
173
|
+
green: number; // 0-255
|
|
174
|
+
blue: number; // 0-255
|
|
175
|
+
intensity: number; // 0-255 (0=off, 1-100=percentage, 101-255=max)
|
|
176
|
+
blinkTimes: number; // 0-255 (0=no blink, 255=infinite)
|
|
177
|
+
blinkSpeed: number; // 1-30 seconds interval
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### OTA (Over-The-Air) Updates
|
|
182
|
+
|
|
183
|
+
#### `otaNotification(options)`
|
|
184
|
+
|
|
185
|
+
Sends an OTA update notification to the IOBOARD.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const response = await CapacitorIoboard.otaNotification({
|
|
189
|
+
address: 1,
|
|
190
|
+
majorVersion: 1,
|
|
191
|
+
minorVersion: 1,
|
|
192
|
+
patchVersion: 0,
|
|
193
|
+
firmwareSize: 65536 // Size in bytes
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### `otaData(options)`
|
|
198
|
+
|
|
199
|
+
Sends an OTA data packet to the IOBOARD.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
const response = await CapacitorIoboard.otaData({
|
|
203
|
+
address: 1,
|
|
204
|
+
packetNumber: 0,
|
|
205
|
+
data: 'base64EncodedFirmwareData...' // Base64 encoded, max 128 bytes
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Protocol Details
|
|
210
|
+
|
|
211
|
+
The plugin implements the IOBOARD MTC3P08L communication protocol:
|
|
212
|
+
|
|
213
|
+
- **Baud Rate:** 115200 bps
|
|
214
|
+
- **Data Format:** 8N1 (8 data bits, no parity, 1 stop bit)
|
|
215
|
+
- **Frame Structure:** SOI (0x0D) + Address + FrameType + Data + CRC16 + EOI (0x0A)
|
|
216
|
+
- **CRC:** CRC-16 CCITT checksum
|
|
217
|
+
- **Address Range:** 1-63
|
|
218
|
+
- **Response Timeout:** Configurable (default 5000ms)
|
|
219
|
+
|
|
220
|
+
## Error Handling
|
|
221
|
+
|
|
222
|
+
All methods return a response object with a `success` boolean field:
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
const response = await CapacitorIoboard.queryStatus({ address: 1 });
|
|
226
|
+
|
|
227
|
+
if (response.success) {
|
|
228
|
+
console.log('Operation successful:', response.message);
|
|
229
|
+
// Use response.data if available
|
|
230
|
+
} else {
|
|
231
|
+
console.error('Operation failed:', response.message);
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Example Usage
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { CapacitorIoboard } from '@leonardojc/capacitor-ioboard';
|
|
239
|
+
|
|
240
|
+
class IOBoardController {
|
|
241
|
+
async initialize() {
|
|
242
|
+
// Open serial connection
|
|
243
|
+
const connection = await CapacitorIoboard.openConnection({
|
|
244
|
+
baudRate: 115200,
|
|
245
|
+
timeout: 5000
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
if (!connection.success) {
|
|
249
|
+
throw new Error('Failed to open connection');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
console.log('Connection established');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async unlockPallet(address: number, palletNumber: number) {
|
|
256
|
+
const response = await CapacitorIoboard.controlSinglePallet({
|
|
257
|
+
address,
|
|
258
|
+
palletNumber,
|
|
259
|
+
doorLock: true,
|
|
260
|
+
ledControl: {
|
|
261
|
+
red: 0, green: 255, blue: 0, // Green light
|
|
262
|
+
intensity: 100,
|
|
263
|
+
blinkTimes: 3,
|
|
264
|
+
blinkSpeed: 1
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
return response.success;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async getDeviceStatus(address: number) {
|
|
272
|
+
const response = await CapacitorIoboard.queryStatus({ address });
|
|
273
|
+
|
|
274
|
+
if (response.success && response.data) {
|
|
275
|
+
return {
|
|
276
|
+
doorStatus: response.data.doorLockStatus,
|
|
277
|
+
version: response.data.softwareVersion
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
MIT
|
|
289
|
+
|
|
290
|
+
## Author
|
|
291
|
+
|
|
292
|
+
Leonardo JC - [@leonardojc](https://github.com/leonardojc)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
android {
|
|
4
|
+
namespace 'com.leonardojc.capacitor.ioboard'
|
|
5
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
6
|
+
defaultConfig {
|
|
7
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
8
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
9
|
+
versionCode 1
|
|
10
|
+
versionName "1.0"
|
|
11
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
12
|
+
}
|
|
13
|
+
buildTypes {
|
|
14
|
+
release {
|
|
15
|
+
minifyEnabled false
|
|
16
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
lintOptions {
|
|
20
|
+
abortOnError false
|
|
21
|
+
}
|
|
22
|
+
compileOptions {
|
|
23
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
24
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
repositories {
|
|
29
|
+
google()
|
|
30
|
+
mavenCentral()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
35
|
+
implementation project(':capacitor-android')
|
|
36
|
+
testImplementation 'junit:junit:4.13.2'
|
|
37
|
+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
|
38
|
+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
|
|
4
|
+
<!-- Permissions required for serial communication -->
|
|
5
|
+
<uses-permission android:name="android.permission.USB_PERMISSION" />
|
|
6
|
+
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
|
|
7
|
+
|
|
8
|
+
</manifest>
|