@corvina/device-client 1.0.10
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/CHANGELOG.md +1 -0
- package/CONTRIBUTING.md +31 -0
- package/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/common/types.d.ts +89 -0
- package/dist/common/types.js +65 -0
- package/dist/common/types.js.map +1 -0
- package/dist/device.module.d.ts +2 -0
- package/dist/device.module.js +41 -0
- package/dist/device.module.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/services/configparser.d.ts +232 -0
- package/dist/services/configparser.js +458 -0
- package/dist/services/configparser.js.map +1 -0
- package/dist/services/corvinadatainterface.d.ts +24 -0
- package/dist/services/corvinadatainterface.js +107 -0
- package/dist/services/corvinadatainterface.js.map +1 -0
- package/dist/services/device.service.d.ts +77 -0
- package/dist/services/device.service.js +464 -0
- package/dist/services/device.service.js.map +1 -0
- package/dist/services/devicerunner.interface.d.ts +3 -0
- package/dist/services/devicerunner.interface.js +3 -0
- package/dist/services/devicerunner.interface.js.map +1 -0
- package/dist/services/devicerunner.service.d.ts +8 -0
- package/dist/services/devicerunner.service.js +123 -0
- package/dist/services/devicerunner.service.js.map +1 -0
- package/dist/services/licensesaxiosinstance.d.ts +29 -0
- package/dist/services/licensesaxiosinstance.js +77 -0
- package/dist/services/licensesaxiosinstance.js.map +1 -0
- package/dist/services/logger.service.d.ts +8 -0
- package/dist/services/logger.service.js +9 -0
- package/dist/services/logger.service.js.map +1 -0
- package/dist/services/messagepublisher.d.ts +69 -0
- package/dist/services/messagepublisher.js +154 -0
- package/dist/services/messagepublisher.js.map +1 -0
- package/dist/services/messagepublisherpolicies.d.ts +222 -0
- package/dist/services/messagepublisherpolicies.js +499 -0
- package/dist/services/messagepublisherpolicies.js.map +1 -0
- package/dist/services/messagesender.d.ts +17 -0
- package/dist/services/messagesender.js +3 -0
- package/dist/services/messagesender.js.map +1 -0
- package/dist/services/messagesubscriber.d.ts +17 -0
- package/dist/services/messagesubscriber.js +32 -0
- package/dist/services/messagesubscriber.js.map +1 -0
- package/dist/services/simulation.d.ts +83 -0
- package/dist/services/simulation.js +610 -0
- package/dist/services/simulation.js.map +1 -0
- package/envs.md +67 -0
- package/package.json +105 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
RELEASE 1.0.0
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
1. [Fork it](https://help.github.com/articles/fork-a-repo/)
|
|
4
|
+
2. Install dependencies (`npm install`)
|
|
5
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
|
6
|
+
4. Commit your changes (`git commit -am 'Added some feature'`)
|
|
7
|
+
5. Test your changes (`npm test`)
|
|
8
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
|
9
|
+
7. [Create new Pull Request](https://help.github.com/articles/creating-a-pull-request/)
|
|
10
|
+
|
|
11
|
+
## Testing
|
|
12
|
+
|
|
13
|
+
We use [Jest](https://github.com/facebook/jest) to write tests. Run our test suite with this command:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm test
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Code Style
|
|
20
|
+
|
|
21
|
+
We use [Prettier](https://prettier.io/) and tslint to maintain code style and best practices.
|
|
22
|
+
Please make sure your PR adheres to the guides by running:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm run format
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
and
|
|
29
|
+
```
|
|
30
|
+
npm run lint
|
|
31
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Arrigo Zanette
|
|
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,138 @@
|
|
|
1
|
+
<h1 align="center">Corvina Device SDK</h1>
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Install the dependency:
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
yarn install @corvina/device-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Run the device using the given runner:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import 'dotenv/config'
|
|
15
|
+
import { DeviceRunnerService, DeviceService } from '@corvina/device-client';
|
|
16
|
+
|
|
17
|
+
const devRunner = new DeviceRunnerService(new DeviceService());
|
|
18
|
+
|
|
19
|
+
devRunner.run();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The `DeviceRunnerService` is responsible for translating the environment configuration to the JSON configuration to be used to init the class `DeviceService`.
|
|
23
|
+
|
|
24
|
+
### Usage in a [Nestjs](https://nestjs.com) application
|
|
25
|
+
|
|
26
|
+
In your app module, import the device client module:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { DeviceClientModule } from '@corvina/device-client/device.module';
|
|
30
|
+
|
|
31
|
+
@Module({
|
|
32
|
+
imports: [DeviceClientModule],
|
|
33
|
+
controllers: [AppController],
|
|
34
|
+
providers: [AppService],
|
|
35
|
+
})
|
|
36
|
+
export class AppModule {}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
In your `main.ts` you can start the device using the `DeviceRunner` service.
|
|
40
|
+
This service reads the configuration from a `.env` file.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { DeviceRunnerService } from '@corvina/device-client';
|
|
44
|
+
|
|
45
|
+
async function bootstrap() {
|
|
46
|
+
const app = await NestFactory.create(AppModule);
|
|
47
|
+
await app.listen(3000);
|
|
48
|
+
|
|
49
|
+
app.get(DeviceRunnerService).run();
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Sending data
|
|
54
|
+
|
|
55
|
+
> The actual sending occurs according to the configuration received from the cloud. Posting a tag not configured from the cloud will result in an error.
|
|
56
|
+
|
|
57
|
+
In order to send data the `DeviceClient` class exposes the `post` method.
|
|
58
|
+
The method allow to post a list of data points.
|
|
59
|
+
|
|
60
|
+
A data point is defined by:
|
|
61
|
+
* a `tagName`, representing the device identifier of the data point
|
|
62
|
+
* a `timestamp`, representing the UTC timestamp the value was originate
|
|
63
|
+
* a `value`
|
|
64
|
+
|
|
65
|
+
The `post` method accepts further options:
|
|
66
|
+
* `qos`, the MQTT QoS required
|
|
67
|
+
* `cb`, a function callback to catch sending errors or confirmations
|
|
68
|
+
* `forceImmediateSend`, to bypass the publish policies configured from the cloud and just send the data immediately
|
|
69
|
+
* `recurseNotifyOnlyWholeObject`, when posting a full JSON, just post the full object not every single path
|
|
70
|
+
|
|
71
|
+
#### Simulation
|
|
72
|
+
|
|
73
|
+
The device can be set up using environment variables to simulate data sending.
|
|
74
|
+
|
|
75
|
+
1. set the available tags to simulate (the list will also be published to the cloud):
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
AVAILABLE_TAGS=[{"name":"Tag1","type":"integer"},{"name":"Tag2","type":"integer"},{"name":"Tag3","type":"integer"},{"name":"PositionNow","type":"integer"},{"name":"InputTag","type":"integer"}]
|
|
79
|
+
```
|
|
80
|
+
2. enable simulation:
|
|
81
|
+
```
|
|
82
|
+
SIMULATE_TAGS=1
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The same can be done for alarms:
|
|
86
|
+
|
|
87
|
+
1. set up the alarms to simulate:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
AVAILABLE_ALARMS=[{"name":"Alarm10","severity":1,"source":"Tag1","desc":{"en":"Tag above normal : [Tag1]"},"ack_required":true,"reset_required":true,"simulation":{"f":"{ return Math.random() > 0.5 }"}}]
|
|
91
|
+
```
|
|
92
|
+
2. enable simulation:
|
|
93
|
+
```
|
|
94
|
+
SIMULATE_ALARMS=1
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Receiving data
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
> In order to receive data on a tag the tag must be configured writable in the cloud mapping
|
|
105
|
+
|
|
106
|
+
When data is written from the cloud a `write` event is emitted and can be used to handle the write request.
|
|
107
|
+
|
|
108
|
+
The event will report an object containing:
|
|
109
|
+
* `modelPath`: the written model path
|
|
110
|
+
* `v`: the written value
|
|
111
|
+
|
|
112
|
+
For example:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
app.get(DeviceService).on("write", (event) => {
|
|
116
|
+
console.log("Write event received", event);
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Environment variables
|
|
121
|
+
|
|
122
|
+
See [envs.md](envs.md) for a detailed description of environment variables.
|
|
123
|
+
|
|
124
|
+
<!-- ## Change Log
|
|
125
|
+
|
|
126
|
+
See [Changelog](CHANGELOG.md) for more information.
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
Contributions welcome! See [Contributing](CONTRIBUTING.md). -->
|
|
131
|
+
|
|
132
|
+
## Author
|
|
133
|
+
|
|
134
|
+
**Arrigo Zanette**
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Int32, Long, Binary } from "bson";
|
|
2
|
+
export declare enum NoiseSimulationType {
|
|
3
|
+
ABSOLUTE = "abs",
|
|
4
|
+
PERCENT = "%"
|
|
5
|
+
}
|
|
6
|
+
export interface NoiseSimulationProperties {
|
|
7
|
+
type: NoiseSimulationType;
|
|
8
|
+
amplitude: number;
|
|
9
|
+
}
|
|
10
|
+
export interface NullableSimulationStateMachine {
|
|
11
|
+
nullifying: boolean;
|
|
12
|
+
start: number;
|
|
13
|
+
duration: number;
|
|
14
|
+
}
|
|
15
|
+
export interface NullableSimulationProperties {
|
|
16
|
+
probability: number;
|
|
17
|
+
dt_min: number;
|
|
18
|
+
dt_max: number;
|
|
19
|
+
state?: NullableSimulationStateMachine;
|
|
20
|
+
}
|
|
21
|
+
export declare enum SimulationType {
|
|
22
|
+
SINE = "sine",
|
|
23
|
+
STEP = "step",
|
|
24
|
+
CONST = "const",
|
|
25
|
+
FUNCTION = "function"
|
|
26
|
+
}
|
|
27
|
+
export interface SimulationDesc {
|
|
28
|
+
type: SimulationType;
|
|
29
|
+
noise: NoiseSimulationProperties;
|
|
30
|
+
nullable: NullableSimulationProperties;
|
|
31
|
+
}
|
|
32
|
+
export interface TagDesc {
|
|
33
|
+
name: string;
|
|
34
|
+
type: string;
|
|
35
|
+
simulation?: SimulationDesc;
|
|
36
|
+
}
|
|
37
|
+
export interface MultiLangString {
|
|
38
|
+
[languageCode: string]: string;
|
|
39
|
+
}
|
|
40
|
+
export interface AlarmDesc {
|
|
41
|
+
name: string;
|
|
42
|
+
desc: MultiLangString;
|
|
43
|
+
source: string;
|
|
44
|
+
severity: number;
|
|
45
|
+
ack_required: boolean;
|
|
46
|
+
reset_required: boolean;
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
simulation: SimulationDesc;
|
|
49
|
+
}
|
|
50
|
+
export interface DataPoint {
|
|
51
|
+
tagName: string | undefined;
|
|
52
|
+
value: any;
|
|
53
|
+
timestamp: number;
|
|
54
|
+
}
|
|
55
|
+
export declare enum AlarmState {
|
|
56
|
+
ALARM_NONE = 0,
|
|
57
|
+
ALARM_ENABLED = 1,
|
|
58
|
+
ALARM_ACTIVE = 2,
|
|
59
|
+
ALARM_ACKED = 4,
|
|
60
|
+
ALARM_REQUIRES_ACK = 8,
|
|
61
|
+
ALARM_REQUIRES_RESET = 16
|
|
62
|
+
}
|
|
63
|
+
export interface AlarmData {
|
|
64
|
+
name: string;
|
|
65
|
+
desc: string;
|
|
66
|
+
ts: Date;
|
|
67
|
+
evTs: Date;
|
|
68
|
+
sev?: Int32;
|
|
69
|
+
state: number;
|
|
70
|
+
tag?: string;
|
|
71
|
+
v_d?: number;
|
|
72
|
+
v_i?: Int32;
|
|
73
|
+
v_b?: boolean;
|
|
74
|
+
v_s?: string;
|
|
75
|
+
v_l?: Long;
|
|
76
|
+
v_o?: Binary;
|
|
77
|
+
}
|
|
78
|
+
export interface AlarmCommand {
|
|
79
|
+
command: string;
|
|
80
|
+
comment: string;
|
|
81
|
+
evTs: number;
|
|
82
|
+
name: string;
|
|
83
|
+
user: string;
|
|
84
|
+
}
|
|
85
|
+
export declare enum PacketFormatEnum {
|
|
86
|
+
JSON = "json",
|
|
87
|
+
BSON = "bson"
|
|
88
|
+
}
|
|
89
|
+
export declare function castCorvinaType(value: any, topicType: string): any;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.castCorvinaType = exports.PacketFormatEnum = exports.AlarmState = exports.SimulationType = exports.NoiseSimulationType = void 0;
|
|
4
|
+
var NoiseSimulationType;
|
|
5
|
+
(function (NoiseSimulationType) {
|
|
6
|
+
NoiseSimulationType["ABSOLUTE"] = "abs";
|
|
7
|
+
NoiseSimulationType["PERCENT"] = "%";
|
|
8
|
+
})(NoiseSimulationType = exports.NoiseSimulationType || (exports.NoiseSimulationType = {}));
|
|
9
|
+
var SimulationType;
|
|
10
|
+
(function (SimulationType) {
|
|
11
|
+
SimulationType["SINE"] = "sine";
|
|
12
|
+
SimulationType["STEP"] = "step";
|
|
13
|
+
SimulationType["CONST"] = "const";
|
|
14
|
+
SimulationType["FUNCTION"] = "function";
|
|
15
|
+
})(SimulationType = exports.SimulationType || (exports.SimulationType = {}));
|
|
16
|
+
var AlarmState;
|
|
17
|
+
(function (AlarmState) {
|
|
18
|
+
AlarmState[AlarmState["ALARM_NONE"] = 0] = "ALARM_NONE";
|
|
19
|
+
AlarmState[AlarmState["ALARM_ENABLED"] = 1] = "ALARM_ENABLED";
|
|
20
|
+
AlarmState[AlarmState["ALARM_ACTIVE"] = 2] = "ALARM_ACTIVE";
|
|
21
|
+
AlarmState[AlarmState["ALARM_ACKED"] = 4] = "ALARM_ACKED";
|
|
22
|
+
AlarmState[AlarmState["ALARM_REQUIRES_ACK"] = 8] = "ALARM_REQUIRES_ACK";
|
|
23
|
+
AlarmState[AlarmState["ALARM_REQUIRES_RESET"] = 16] = "ALARM_REQUIRES_RESET";
|
|
24
|
+
})(AlarmState = exports.AlarmState || (exports.AlarmState = {}));
|
|
25
|
+
var PacketFormatEnum;
|
|
26
|
+
(function (PacketFormatEnum) {
|
|
27
|
+
PacketFormatEnum["JSON"] = "json";
|
|
28
|
+
PacketFormatEnum["BSON"] = "bson";
|
|
29
|
+
})(PacketFormatEnum = exports.PacketFormatEnum || (exports.PacketFormatEnum = {}));
|
|
30
|
+
function castCorvinaType(value, topicType) {
|
|
31
|
+
if (value == undefined) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (value == null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
switch (topicType) {
|
|
38
|
+
case "integer":
|
|
39
|
+
return ~~value;
|
|
40
|
+
case "boolean":
|
|
41
|
+
if (typeof value == "string") {
|
|
42
|
+
if (value == "true") {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
else if (value == "false") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return !!~~value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return !!value;
|
|
53
|
+
case "string":
|
|
54
|
+
return "" + value;
|
|
55
|
+
case "double":
|
|
56
|
+
return parseFloat(value);
|
|
57
|
+
case "struct":
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw "Unsupported data type " + topicType;
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
exports.castCorvinaType = castCorvinaType;
|
|
65
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC3B,uCAAgB,CAAA;IAChB,oCAAa,CAAA;AACjB,CAAC,EAHW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAG9B;AAoBD,IAAY,cAKX;AALD,WAAY,cAAc;IACtB,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,iCAAe,CAAA;IACf,uCAAqB,CAAA;AACzB,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAsCD,IAAY,UAOX;AAPD,WAAY,UAAU;IAClB,uDAAc,CAAA;IACd,6DAAiB,CAAA;IACjB,2DAAgB,CAAA;IAChB,yDAAe,CAAA;IACf,uEAAsB,CAAA;IACtB,4EAAyB,CAAA;AAC7B,CAAC,EAPW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAOrB;AA0BD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IACxB,iCAAa,CAAA;IACb,iCAAa,CAAA;AACjB,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED,SAAgB,eAAe,CAAC,KAAU,EAAE,SAAiB;IACzD,IAAI,KAAK,IAAI,SAAS,EAAE;QACpB,OAAO,SAAS,CAAC;KACpB;IACD,IAAI,KAAK,IAAI,IAAI,EAAE;QACf,OAAO,IAAI,CAAC;KACf;IACD,QAAQ,SAAS,EAAE;QACf,KAAK,SAAS;YACV,OAAO,CAAC,CAAC,KAAK,CAAC;QACnB,KAAK,SAAS;YACV,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE;gBAC1B,IAAI,KAAK,IAAI,MAAM,EAAE;oBACjB,OAAO,IAAI,CAAC;iBACf;qBAAM,IAAI,KAAK,IAAI,OAAO,EAAE;oBACzB,OAAO,KAAK,CAAC;iBAChB;qBAAM;oBACH,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;iBACpB;aACJ;YACD,OAAO,CAAC,CAAC,KAAK,CAAC;QACnB,KAAK,QAAQ;YACT,OAAO,EAAE,GAAG,KAAK,CAAC;QACtB,KAAK,QAAQ;YACT,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC7B,KAAK,QAAQ;YACT,MAAM;QACV;YACI,MAAM,wBAAwB,GAAG,SAAS,CAAC;KAClD;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AA/BD,0CA+BC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DeviceClientModule = void 0;
|
|
10
|
+
const device_service_1 = require("./services/device.service");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const devicerunner_service_1 = require("./services/devicerunner.service");
|
|
13
|
+
const config_1 = require("@nestjs/config");
|
|
14
|
+
const logger_service_1 = require("./services/logger.service");
|
|
15
|
+
let DeviceClientModule = class DeviceClientModule {
|
|
16
|
+
};
|
|
17
|
+
DeviceClientModule = __decorate([
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [config_1.ConfigModule.forRoot()],
|
|
20
|
+
controllers: [],
|
|
21
|
+
providers: [
|
|
22
|
+
{
|
|
23
|
+
provide: device_service_1.DeviceService,
|
|
24
|
+
useFactory: () => {
|
|
25
|
+
(0, logger_service_1.setLogger)(common_1.Logger);
|
|
26
|
+
return new device_service_1.DeviceService();
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
provide: devicerunner_service_1.DeviceRunnerService,
|
|
31
|
+
useFactory: (deviceService) => {
|
|
32
|
+
return new devicerunner_service_1.DeviceRunnerService(deviceService);
|
|
33
|
+
},
|
|
34
|
+
inject: [device_service_1.DeviceService],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
exports: [device_service_1.DeviceService, devicerunner_service_1.DeviceRunnerService],
|
|
38
|
+
})
|
|
39
|
+
], DeviceClientModule);
|
|
40
|
+
exports.DeviceClientModule = DeviceClientModule;
|
|
41
|
+
//# sourceMappingURL=device.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.module.js","sourceRoot":"","sources":["../src/device.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8DAA0D;AAC1D,2CAAgD;AAChD,0EAAsE;AACtE,2CAA8C;AAC9C,8DAAsD;AAwBtD,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;CAAG,CAAA;AAArB,kBAAkB;IAtB9B,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,qBAAY,CAAC,OAAO,EAAE,CAAC;QACjC,WAAW,EAAE,EAAE;QACf,SAAS,EAAE;YACP;gBACI,OAAO,EAAE,8BAAa;gBACtB,UAAU,EAAE,GAAG,EAAE;oBAEb,IAAA,0BAAS,EAAC,eAAM,CAAC,CAAC;oBAClB,OAAO,IAAI,8BAAa,EAAE,CAAC;gBAC/B,CAAC;aACJ;YACD;gBACI,OAAO,EAAE,0CAAmB;gBAC5B,UAAU,EAAE,CAAC,aAA4B,EAAE,EAAE;oBACzC,OAAO,IAAI,0CAAmB,CAAC,aAAa,CAAC,CAAC;gBAClD,CAAC;gBACD,MAAM,EAAE,CAAC,8BAAa,CAAC;aAC1B;SACJ;QACD,OAAO,EAAE,CAAC,8BAAa,EAAE,0CAAmB,CAAC;KAChD,CAAC;GACW,kBAAkB,CAAG;AAArB,gDAAkB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./services/device.service";
|
|
2
|
+
export * from "./services/devicerunner.service";
|
|
3
|
+
export * from "./services/messagesender";
|
|
4
|
+
export * from "./services/corvinadatainterface";
|
|
5
|
+
export * from "./common/types";
|
|
6
|
+
export { LicenseData } from "./services/licensesaxiosinstance";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./services/device.service"), exports);
|
|
18
|
+
__exportStar(require("./services/devicerunner.service"), exports);
|
|
19
|
+
__exportStar(require("./services/messagesender"), exports);
|
|
20
|
+
__exportStar(require("./services/corvinadatainterface"), exports);
|
|
21
|
+
__exportStar(require("./common/types"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,kEAAgD;AAChD,2DAAyC;AACzC,kEAAgD;AAChD,iDAA+B"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { MessagePublisher } from "./messagepublisher";
|
|
2
|
+
import { MessageSubscriber } from "./messagesubscriber";
|
|
3
|
+
import { MessagePublisherPolicy, LevelMode } from "./messagepublisherpolicies";
|
|
4
|
+
export declare type TypedObject<T> = {
|
|
5
|
+
[key: string]: T;
|
|
6
|
+
};
|
|
7
|
+
export declare type ConfigurationType = "datamodel";
|
|
8
|
+
export declare type PolicyType = "send" | "history";
|
|
9
|
+
export declare type PlatformConfigurationInterfaceType = "properties" | "datastream";
|
|
10
|
+
export declare type PlatformAggregationType = "object" | "individual";
|
|
11
|
+
export declare type OwnershipType = "device" | "server";
|
|
12
|
+
export declare type ModelBasicType = "integer" | "double" | "string" | "boolean" | "bytestring" | "integerarray" | "doublearray" | "booleanarray" | "binaryblob";
|
|
13
|
+
export declare type ModelObjectType = "object";
|
|
14
|
+
export declare type ModelArrayType = "array";
|
|
15
|
+
export declare type ModelStructType = "struct";
|
|
16
|
+
export declare type MappingModeType = "R" | "RW";
|
|
17
|
+
export interface ModelBasic {
|
|
18
|
+
type: ModelBasicType;
|
|
19
|
+
description?: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
unit?: string;
|
|
22
|
+
tags?: string[];
|
|
23
|
+
version?: string;
|
|
24
|
+
deprecated?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface ModelArray {
|
|
27
|
+
UUID?: string;
|
|
28
|
+
type: ModelArrayType;
|
|
29
|
+
length: number;
|
|
30
|
+
item: ModelObject;
|
|
31
|
+
description?: string;
|
|
32
|
+
label?: string;
|
|
33
|
+
unit?: string;
|
|
34
|
+
tags?: string[];
|
|
35
|
+
version?: string;
|
|
36
|
+
deprecated?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ModelObject {
|
|
39
|
+
UUID?: string;
|
|
40
|
+
type: ModelObjectType;
|
|
41
|
+
instanceOf: string;
|
|
42
|
+
properties: TypedObject<ModelNode>;
|
|
43
|
+
description?: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
unit?: string;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
version?: string;
|
|
48
|
+
deprecated?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface ModelStruct {
|
|
51
|
+
UUID?: string;
|
|
52
|
+
type: ModelStructType;
|
|
53
|
+
instanceOf: string;
|
|
54
|
+
properties: TypedObject<ModelBasic>;
|
|
55
|
+
description?: string;
|
|
56
|
+
label?: string;
|
|
57
|
+
unit?: string;
|
|
58
|
+
tags?: string[];
|
|
59
|
+
version?: string;
|
|
60
|
+
deprecated?: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface ModelMetadata {
|
|
63
|
+
path: string;
|
|
64
|
+
label?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
unit?: string;
|
|
67
|
+
tags?: string[];
|
|
68
|
+
type?: ModelType;
|
|
69
|
+
version?: string;
|
|
70
|
+
instanceOf?: string;
|
|
71
|
+
}
|
|
72
|
+
export declare type ModelNode = ModelBasic | ModelArray | ModelInterfaceCreatable;
|
|
73
|
+
export declare type ModelInterfaceCreatable = ModelObject | ModelStruct;
|
|
74
|
+
export declare type ModelType = ModelBasicType | ModelObjectType | ModelArrayType | ModelStructType;
|
|
75
|
+
export interface BasePolicyData {
|
|
76
|
+
type: PolicyType;
|
|
77
|
+
instanceOf?: string;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}
|
|
80
|
+
export interface MappingData {
|
|
81
|
+
device_endpoint: string;
|
|
82
|
+
server_endpoint?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface MappingHistoryPolicy {
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
limit?: string;
|
|
87
|
+
compressionStrategy?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface MappingSendPolicyTrigger {
|
|
90
|
+
type: "timer" | "onchange" | "onlevel" | "fieldchange" | "fieldlevel";
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
}
|
|
93
|
+
export interface OnChangeTrigger extends MappingSendPolicyTrigger {
|
|
94
|
+
minIntervalMs?: number;
|
|
95
|
+
tagName?: string;
|
|
96
|
+
skipFirstNChanges?: number;
|
|
97
|
+
deadband?: number;
|
|
98
|
+
deadbandPercent?: number;
|
|
99
|
+
changeMask?: "value" | "timestamp" | "value|timestamp";
|
|
100
|
+
}
|
|
101
|
+
export interface IntervalTrigger extends MappingSendPolicyTrigger {
|
|
102
|
+
intervalMs: number;
|
|
103
|
+
type: "timer";
|
|
104
|
+
}
|
|
105
|
+
export interface OnLevelTrigger extends MappingSendPolicyTrigger {
|
|
106
|
+
minIntervalMs?: number;
|
|
107
|
+
tagName?: string;
|
|
108
|
+
skipFirstNChanges?: number;
|
|
109
|
+
level?: number;
|
|
110
|
+
levelString?: string;
|
|
111
|
+
mode?: LevelMode;
|
|
112
|
+
deadband?: number;
|
|
113
|
+
deadbandPercent?: number;
|
|
114
|
+
changeMask?: "value" | "timestamp" | "value|timestamp";
|
|
115
|
+
type: "onlevel";
|
|
116
|
+
}
|
|
117
|
+
export interface OnFieldChangeTrigger extends MappingSendPolicyTrigger {
|
|
118
|
+
minIntervalMs?: number;
|
|
119
|
+
tagName?: string;
|
|
120
|
+
fieldName?: string;
|
|
121
|
+
skipFirstNChanges?: number;
|
|
122
|
+
deadband?: number;
|
|
123
|
+
deadbandPercent?: number;
|
|
124
|
+
changeMask?: "value" | "timestamp" | "value|timestamp";
|
|
125
|
+
type: "fieldchange";
|
|
126
|
+
}
|
|
127
|
+
export interface OnFieldLevelTrigger extends MappingSendPolicyTrigger {
|
|
128
|
+
minIntervalMs?: number;
|
|
129
|
+
fieldName?: string;
|
|
130
|
+
skipFirstNChanges?: number;
|
|
131
|
+
level?: number;
|
|
132
|
+
levelString?: string;
|
|
133
|
+
mode?: LevelMode;
|
|
134
|
+
deadband?: number;
|
|
135
|
+
deadbandPercent?: number;
|
|
136
|
+
changeMask?: "value" | "timestamp" | "value|timestamp";
|
|
137
|
+
type: "fieldlevel";
|
|
138
|
+
}
|
|
139
|
+
export interface MappingSendPolicyCondition {
|
|
140
|
+
type: "and" | "or" | "inband" | "outband";
|
|
141
|
+
}
|
|
142
|
+
export interface LogicCondition extends MappingSendPolicyCondition {
|
|
143
|
+
type: "and" | "or";
|
|
144
|
+
operands: MappingSendPolicyCondition[];
|
|
145
|
+
}
|
|
146
|
+
export interface InOutBandCondition extends MappingSendPolicyCondition {
|
|
147
|
+
type: "inband" | "outband";
|
|
148
|
+
low: number;
|
|
149
|
+
high: number;
|
|
150
|
+
tagName: string;
|
|
151
|
+
}
|
|
152
|
+
export interface MappingSendPolicy {
|
|
153
|
+
triggers: MappingSendPolicyTrigger[];
|
|
154
|
+
conditions?: MappingSendPolicyCondition;
|
|
155
|
+
}
|
|
156
|
+
export interface SendPolicyData extends BasePolicyData, MappingSendPolicy {
|
|
157
|
+
}
|
|
158
|
+
export interface HistoryPolicyData extends BasePolicyData, MappingHistoryPolicy {
|
|
159
|
+
}
|
|
160
|
+
export declare type PolicyData = SendPolicyData | HistoryPolicyData;
|
|
161
|
+
export interface MappingDatalink {
|
|
162
|
+
source: string;
|
|
163
|
+
}
|
|
164
|
+
export interface MappingAdditionalInfo {
|
|
165
|
+
mode?: MappingModeType;
|
|
166
|
+
historyPolicy?: MappingHistoryPolicy;
|
|
167
|
+
sendPolicy?: MappingSendPolicy;
|
|
168
|
+
datalink?: MappingDatalink;
|
|
169
|
+
}
|
|
170
|
+
export interface MappingInfo {
|
|
171
|
+
mapping?: MappingData;
|
|
172
|
+
}
|
|
173
|
+
export interface MappingBasic extends ModelBasic, MappingAdditionalInfo {
|
|
174
|
+
}
|
|
175
|
+
export interface MappingObject extends ModelObject, MappingAdditionalInfo {
|
|
176
|
+
properties: TypedObject<MappingNode>;
|
|
177
|
+
}
|
|
178
|
+
export interface MappingArray extends ModelArray, MappingAdditionalInfo {
|
|
179
|
+
item: MappingObject;
|
|
180
|
+
}
|
|
181
|
+
export interface MappingStruct extends ModelStruct, MappingAdditionalInfo {
|
|
182
|
+
properties: TypedObject<MappingBasic>;
|
|
183
|
+
}
|
|
184
|
+
export declare type MappingNode = MappingBasic | MappingArray | MappingInterfaceCreatable;
|
|
185
|
+
export declare type MappingInterfaceCreatable = MappingObject | MappingStruct;
|
|
186
|
+
export interface DeviceConfigurationBasic extends MappingBasic, MappingInfo {
|
|
187
|
+
}
|
|
188
|
+
export interface DeviceConfigurationArray extends MappingArray, MappingInfo {
|
|
189
|
+
item: DeviceConfigurationObject;
|
|
190
|
+
}
|
|
191
|
+
export interface DeviceConfigurationObject extends MappingObject, MappingInfo {
|
|
192
|
+
properties: TypedObject<DeviceConfigurationNode>;
|
|
193
|
+
}
|
|
194
|
+
export interface DeviceConfigurationStruct extends MappingStruct, MappingInfo {
|
|
195
|
+
properties: TypedObject<DeviceConfigurationBasic>;
|
|
196
|
+
}
|
|
197
|
+
export declare type DeviceConfigurationWithProperties = DeviceConfigurationObject | DeviceConfigurationStruct;
|
|
198
|
+
export declare type DeviceConfigurationNode = DeviceConfigurationBasic | DeviceConfigurationArray | DeviceConfigurationWithProperties;
|
|
199
|
+
export interface MappingsData {
|
|
200
|
+
endpoint: string;
|
|
201
|
+
type: ModelBasicType | ModelStructType;
|
|
202
|
+
explicit_timestamp?: boolean;
|
|
203
|
+
}
|
|
204
|
+
export interface InterfaceData {
|
|
205
|
+
interface_name: string;
|
|
206
|
+
version_major: number;
|
|
207
|
+
version_minor: number;
|
|
208
|
+
type: PlatformConfigurationInterfaceType;
|
|
209
|
+
ownership: OwnershipType;
|
|
210
|
+
aggregation?: PlatformAggregationType;
|
|
211
|
+
mappings: MappingsData[];
|
|
212
|
+
}
|
|
213
|
+
export interface ConfigurationData {
|
|
214
|
+
UUID: string;
|
|
215
|
+
type: ModelObjectType;
|
|
216
|
+
instanceOf: string;
|
|
217
|
+
policies?: TypedObject<PolicyData>;
|
|
218
|
+
interfaces: InterfaceData[];
|
|
219
|
+
properties: TypedObject<DeviceConfigurationNode>;
|
|
220
|
+
}
|
|
221
|
+
export interface DeviceConfigurationData {
|
|
222
|
+
type: ConfigurationType;
|
|
223
|
+
properties: TypedObject<ConfigurationData>;
|
|
224
|
+
}
|
|
225
|
+
export declare function indexTemplateApply(templateString: string, values: number[]): string;
|
|
226
|
+
export interface DeviceConfiguration {
|
|
227
|
+
interfaceNames: string[];
|
|
228
|
+
tagPublishers: Map<string, Set<MessagePublisher>>;
|
|
229
|
+
namedPolicies: Map<string, MessagePublisherPolicy>;
|
|
230
|
+
subscribedTopics: Map<string, MessageSubscriber>;
|
|
231
|
+
}
|
|
232
|
+
export default function parseDeviceConfig(config: DeviceConfigurationData): DeviceConfiguration;
|