@cutos/core 0.0.16 → 0.0.18

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/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # Introduction
2
+
3
+ The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. The module is designed to facilitate communication between edge devices, edge gateways, and the cloud. Key features include platform information accessing, edge database operations, IPC (Inter-Process Communication), logging, heartbeat monitoring, and device management, etc. The API is designed to be modular and extensible.
4
+
5
+ ## Core API Modules Components
6
+
7
+ ### Platform
8
+ - The CoreAPI class is the main entry point for interacting with the CUTOS Core API.
9
+ - It provides methods for connecting to the platform, accessing information, and obtaining instances of other classes such as Database, IPC, Logger, etc.
10
+
11
+ ### IPC Implementation
12
+ - IPC (Inter-Process Communication) is implemented for communication between processes on the same machine or between processes on different machines within the same network segment.
13
+ - The IPC class allows sending messages to a specific channel and registering listeners for incoming messages.
14
+
15
+ ### Database Operations
16
+ - The Database class facilitates database operations, including table creation, insertion, updating, querying, and synchronization.
17
+ - Provides a structured interface for managing edge databases.
18
+
19
+ ### Device and Driver Management
20
+ - The Device and Driver classes represent edge devices and drivers, respectively. The Device can also refer to external devices or modules, such as NFC, fingerprint modules, ID card readers, printers, sensors, GPIO and so on.
21
+ - Devices and drivers communicate for data transmission, command reception, and status updates.
22
+ - Heartbeat monitoring is implemented for drivers to ensure continuous communication.
23
+
24
+ ### Notification
25
+ - The Notification class provides functionality for registering, unregistering, and emitting events.
26
+
27
+ ### Logging
28
+ - The Logger class enables logging of information, warnings, errors, and debug messages.
29
+ - Logs are sent and saved to the CUTOS Cloud. In the CUSOS Cloud administration web page, the logs can be queried for a specified device.
30
+
31
+ # Conclusion
32
+
33
+ The CUTOS Core API provides a comprehensive set of classes for interacting with the CUTOS platform. Developers can use these classes to build applications, manage databases, communicate with devices, and handle various aspects of the CUTOS ecosystem. The modular design allows for flexibility and extensibility, making it suitable for a wide range of use cases within the IoT and smart device domain.
34
+
35
+ # Table of Contents
36
+
37
+ 1.Quick Start
38
+
39
+ - Installation
40
+ - Initialization
41
+
42
+ 2.PlatformAPI
43
+
44
+ - Version
45
+ - Platform Information
46
+ - Configuration
47
+ - Box Information
48
+ - Shell Command Execution
49
+ - Volume Control
50
+
51
+ 3.IPC (Inter-Process Communication)
52
+
53
+ 4.Database
54
+
55
+ 5.Device & Driver
56
+
57
+ 6.Notification
58
+
59
+ 7.Logger
60
+
61
+
62
+ # Quick Start
63
+
64
+ ##### Install
65
+
66
+ `
67
+ npm install @cutos/core
68
+ `
69
+
70
+ ##### Initialize
71
+
72
+ ```js
73
+ // Initialize the CUTOS Core module
74
+ import { CoreAPI } from '@cutos/core';
75
+ CoreAPI.init();
76
+ ```
77
+
78
+ # Platform API
79
+
80
+ ### CoreAPI.getVersion
81
+ ##### Get platform version information
82
+ ```js
83
+ CoreAPI.getVersion();
84
+ ```
85
+ - Return result example:
86
+
87
+ ```json
88
+ 0.0.17
89
+ ```
90
+
91
+ ### CoreAPI.getPlatform
92
+ ##### Get platform information
93
+
94
+ ```js
95
+ CoreAPI.getPlatform(callback);
96
+ ```
97
+ - callback: callback function
98
+
99
+ ##### Example:
100
+
101
+ ```js
102
+ CoreAPI.getPlatform(result => {
103
+ console.log(result)
104
+ });
105
+ ```
106
+
107
+ - Return result example:
108
+
109
+ ```json
110
+ {
111
+ "arch": "x64",
112
+ "type": "Windows_NT"
113
+ }
114
+ ```
115
+
116
+ ### CoreAPI.getConfig
117
+ ##### Get configuration information
118
+ ```js
119
+ CoreAPI.getConfig(callback);
120
+ ```
121
+ - callback: callback function
122
+
123
+ ##### Example:
124
+
125
+ ```js
126
+ CoreAPI.getConfig(result => {
127
+ console.log(result)
128
+ });
129
+ ```
130
+
131
+ - Return result example:
132
+
133
+ ```json
134
+ {
135
+ "srvAddress": "www.cut-os.com",
136
+ "srvRestProtocol": "https",
137
+ "enableTimeSync": true,
138
+ "playReport": false,
139
+ "language": "Chinese",
140
+ "debug": false
141
+ }
142
+ ```
143
+ ### CoreAPI.getSignInfo
144
+ ##### Get device information
145
+
146
+ ```js
147
+ CoreAPI.getSignInfo(callback);
148
+ ```
149
+ - callback: callback function
150
+
151
+ ##### Example:
152
+
153
+ ```js
154
+ CoreAPI.getSignInfo(result => {
155
+ console.log(result)
156
+ })
157
+ ```
158
+ ### CoreAPI.getBoxInfo
159
+ ##### Get host information
160
+
161
+ ```js
162
+ CoreAPI.getBoxInfo(callback);
163
+ ```
164
+ - callback: callback function
165
+
166
+ ##### Example:
167
+
168
+ ```js
169
+ CoreAPI.getBoxInfo(result => {
170
+ console.log(result)
171
+ })
172
+ ```
173
+ - Return result example:
174
+
175
+ ```json
176
+ {
177
+ "id": 1004,
178
+ "macAddress": "54-48-10-D9-BB-27_D8-9C-67-6D-DA-B3_D8-9C-67-6D-DA-B4",
179
+ "ipAddress": "192.168.1.136",
180
+ "masterIpAddress": "",
181
+ "status": 1
182
+ }
183
+ ```
184
+ -Return results:
185
+ - `macAddress`: Host MAC address
186
+ - `ipAddress`: host IP address
187
+ - `masterIpAddress`: Master IP address, used when multiple hosts form a host group
188
+ - `status`: 1 means online, 0 means offline
189
+
190
+ ### CoreAPI.getVolume
191
+ ##### Get the volume
192
+
193
+ ```js
194
+ CoreAPI.getVolume(callback);
195
+ ```
196
+ - callback: callback function
197
+
198
+ ##### Example:
199
+
200
+ ```js
201
+ CoreAPI.getVolume(result => {
202
+ console.log(result)
203
+ })
204
+ ```
205
+ - Return result example:
206
+
207
+ ```js
208
+ 10
209
+ ```
210
+
211
+ ### CoreAPI.setVolume
212
+ ##### Set the volume
213
+
214
+ ```js
215
+ CoreAPI.setVolume(value,callback)
216
+ ```
217
+ - value: volume (0-100)
218
+ - callback: callback function
219
+
220
+ ##### Example:
221
+
222
+ ```js
223
+ CoreAPI.setVolume(70,result => {
224
+ console.log(result)
225
+ })
226
+ ```
227
+
228
+ - Return result example:
229
+
230
+ ```js
231
+ success
232
+ ```
233
+ ### CoreAPI.shell
234
+ ##### Shell command execution
235
+
236
+ ```js
237
+ CoreAPI.shell(command, callback)
238
+ ```
239
+ - command: command
240
+ - callback: callback function
241
+
242
+ ##### Example:
243
+
244
+ ```js
245
+ CoreAPI.shell('sudo reboot', null) //Restart the system
246
+ ```
package/dist/cutos.cjs.js CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var crypto = require('crypto');
6
6
  var require$$1 = require('mqtt');
7
7
  require('lodash');
8
- var require$$0$1 = require('qs');
9
8
 
10
9
  function getAugmentedNamespace(n) {
11
10
  if (n.__esModule) return n;
@@ -396,22 +395,8 @@ const cutosAPI$1 = {
396
395
  };
397
396
  var cutosApi = cutosAPI$1;
398
397
 
399
- const qs = require$$0$1;
400
- let config$1 = {};
401
- const appConfig = typeof app_config === 'undefined' ? {} : app_config.params || {};
402
- if(typeof window !== 'undefined') {
403
- let query = location.href.split("?")[1];
404
- let { params } = qs.parse(query);
405
- try {
406
- config$1 = { ...appConfig, ...JSON.parse(params) };
407
- } catch (e) {
408
- config$1 = { ...appConfig };
409
- }
410
- }
411
- var utils = config$1;
412
-
413
398
  var name = "@cutos/core";
414
- var version = "0.0.16";
399
+ var version = "0.0.17";
415
400
  var description = "";
416
401
  var main = "dist/cutos.cjs.js";
417
402
  var module$1 = "dist/cutos.esm.js";
@@ -440,7 +425,7 @@ var files = [
440
425
  "dist/cutos.esm.js",
441
426
  "package.json"
442
427
  ];
443
- var require$$5 = {
428
+ var require$$4 = {
444
429
  name: name,
445
430
  version: version,
446
431
  description: description,
@@ -462,10 +447,9 @@ var require$$5 = {
462
447
  const {v4: uuidv4} = require$$0;
463
448
  const mqtt = require$$1;
464
449
  const cutosAPI = cutosApi;
465
- const config = utils;
466
450
  const callbackMap = new Map();
467
451
  const listenerMap = new Map();
468
- const packageJson = require$$5;
452
+ const packageJson = require$$4;
469
453
 
470
454
  const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
471
455
 
@@ -813,7 +797,7 @@ class Device {
813
797
  command.args = {name: name, type: type};
814
798
  command.topicResponse = this.topicResponse;
815
799
  let defaultTopic = cutosAPI.DEVICE.CHANNEL + '-' + cutosAPI.DEVICE.DEFAULT + '-command';
816
- client.publish(defaultTopic, JSON.stringify(command));
800
+ publishRequest(defaultTopic, null, command);
817
801
 
818
802
  // response callback
819
803
  client.subscribe(this.topicResponse); // receive response from device
@@ -1040,11 +1024,9 @@ var CoreClass = cutos.CoreClass = {
1040
1024
  Device, Driver
1041
1025
  };
1042
1026
  var cutosAPI_1 = cutos.cutosAPI = cutosAPI;
1043
- var config_1 = cutos.config = config;
1044
1027
 
1045
1028
  exports.CoreAPI = CoreAPI_1;
1046
1029
  exports.CoreClass = CoreClass;
1047
1030
  exports.CoreDefine = CoreDefine;
1048
- exports.config = config_1;
1049
1031
  exports.cutosAPI = cutosAPI_1;
1050
1032
  exports.default = cutos;
package/dist/cutos.esm.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import require$$1 from 'mqtt/dist/mqtt';
2
2
  import 'lodash';
3
- import require$$0$1 from 'qs';
4
3
 
5
4
  function getAugmentedNamespace(n) {
6
5
  if (n.__esModule) return n;
@@ -688,22 +687,8 @@ const cutosAPI$1 = {
688
687
  };
689
688
  var cutosApi = cutosAPI$1;
690
689
 
691
- const qs = require$$0$1;
692
- let config$1 = {};
693
- const appConfig = typeof app_config === 'undefined' ? {} : app_config.params || {};
694
- if(typeof window !== 'undefined') {
695
- let query = location.href.split("?")[1];
696
- let { params } = qs.parse(query);
697
- try {
698
- config$1 = { ...appConfig, ...JSON.parse(params) };
699
- } catch (e) {
700
- config$1 = { ...appConfig };
701
- }
702
- }
703
- var utils = config$1;
704
-
705
690
  var name = "@cutos/core";
706
- var version = "0.0.16";
691
+ var version = "0.0.17";
707
692
  var description = "";
708
693
  var main = "dist/cutos.cjs.js";
709
694
  var module = "dist/cutos.esm.js";
@@ -732,7 +717,7 @@ var files = [
732
717
  "dist/cutos.esm.js",
733
718
  "package.json"
734
719
  ];
735
- var require$$5 = {
720
+ var require$$4 = {
736
721
  name: name,
737
722
  version: version,
738
723
  description: description,
@@ -754,10 +739,9 @@ var require$$5 = {
754
739
  const {v4: uuidv4} = require$$0;
755
740
  const mqtt = require$$1;
756
741
  const cutosAPI = cutosApi;
757
- const config = utils;
758
742
  const callbackMap = new Map();
759
743
  const listenerMap = new Map();
760
- const packageJson = require$$5;
744
+ const packageJson = require$$4;
761
745
 
762
746
  const ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
763
747
 
@@ -1105,7 +1089,7 @@ class Device {
1105
1089
  command.args = {name: name, type: type};
1106
1090
  command.topicResponse = this.topicResponse;
1107
1091
  let defaultTopic = cutosAPI.DEVICE.CHANNEL + '-' + cutosAPI.DEVICE.DEFAULT + '-command';
1108
- client.publish(defaultTopic, JSON.stringify(command));
1092
+ publishRequest(defaultTopic, null, command);
1109
1093
 
1110
1094
  // response callback
1111
1095
  client.subscribe(this.topicResponse); // receive response from device
@@ -1332,6 +1316,5 @@ var CoreClass = cutos.CoreClass = {
1332
1316
  Device, Driver
1333
1317
  };
1334
1318
  var cutosAPI_1 = cutos.cutosAPI = cutosAPI;
1335
- var config_1 = cutos.config = config;
1336
1319
 
1337
- export { CoreAPI_1 as CoreAPI, CoreClass, CoreDefine, config_1 as config, cutosAPI_1 as cutosAPI, cutos as default };
1320
+ export { CoreAPI_1 as CoreAPI, CoreClass, CoreDefine, cutosAPI_1 as cutosAPI, cutos as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "",
5
5
  "main": "dist/cutos.cjs.js",
6
6
  "module": "dist/cutos.esm.js",