jooby-codec 1.4.0 → 1.5.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/dist/CommandBinaryBuffer.d.ts +40 -23
- package/dist/CommandBinaryBuffer.js +93 -58
- package/dist/CommandBinaryBuffer.js.map +1 -1
- package/dist/commands/downlink/ExAbsArchiveDaysMC.d.ts +2 -2
- package/dist/commands/downlink/ExAbsArchiveDaysMC.js +6 -6
- package/dist/commands/downlink/ExAbsArchiveDaysMC.js.map +1 -1
- package/dist/commands/downlink/ExAbsArchiveHoursMC.d.ts +2 -2
- package/dist/commands/downlink/ExAbsArchiveHoursMC.js +6 -6
- package/dist/commands/downlink/ExAbsArchiveHoursMC.js.map +1 -1
- package/dist/commands/downlink/ExAbsCurrentMC.d.ts +30 -0
- package/dist/commands/downlink/ExAbsCurrentMC.js +43 -0
- package/dist/commands/downlink/ExAbsCurrentMC.js.map +1 -0
- package/dist/commands/downlink/GetArchiveDaysMC.d.ts +2 -2
- package/dist/commands/downlink/GetArchiveDaysMC.js +6 -6
- package/dist/commands/downlink/GetArchiveDaysMC.js.map +1 -1
- package/dist/commands/downlink/GetArchiveHoursMC.d.ts +2 -2
- package/dist/commands/downlink/GetArchiveHoursMC.js +6 -6
- package/dist/commands/downlink/GetArchiveHoursMC.js.map +1 -1
- package/dist/commands/downlink/SetParameter.d.ts +7 -1
- package/dist/commands/downlink/SetParameter.js +11 -0
- package/dist/commands/downlink/SetParameter.js.map +1 -1
- package/dist/commands/downlink/index.d.ts +1 -0
- package/dist/commands/downlink/index.js +1 -0
- package/dist/commands/downlink/index.js.map +1 -1
- package/dist/commands/uplink/DataDayMC.d.ts +2 -2
- package/dist/commands/uplink/DataDayMC.js +8 -8
- package/dist/commands/uplink/DataDayMC.js.map +1 -1
- package/dist/commands/uplink/DataHourMC.d.ts +10 -4
- package/dist/commands/uplink/DataHourMC.js +13 -35
- package/dist/commands/uplink/DataHourMC.js.map +1 -1
- package/dist/commands/uplink/ExAbsArchiveDaysMC.d.ts +9 -38
- package/dist/commands/uplink/ExAbsArchiveDaysMC.js +16 -38
- package/dist/commands/uplink/ExAbsArchiveDaysMC.js.map +1 -1
- package/dist/commands/uplink/ExAbsArchiveHoursMC.d.ts +13 -7
- package/dist/commands/uplink/ExAbsArchiveHoursMC.js +24 -60
- package/dist/commands/uplink/ExAbsArchiveHoursMC.js.map +1 -1
- package/dist/commands/uplink/ExAbsCurrentMC.d.ts +15 -0
- package/dist/commands/uplink/ExAbsCurrentMC.js +30 -0
- package/dist/commands/uplink/ExAbsCurrentMC.js.map +1 -0
- package/dist/commands/uplink/ExAbsDayMC.d.ts +8 -3
- package/dist/commands/uplink/ExAbsDayMC.js +10 -36
- package/dist/commands/uplink/ExAbsDayMC.js.map +1 -1
- package/dist/commands/uplink/ExAbsHourMC.d.ts +58 -6
- package/dist/commands/uplink/ExAbsHourMC.js +45 -50
- package/dist/commands/uplink/ExAbsHourMC.js.map +1 -1
- package/dist/commands/uplink/GetArchiveDaysMC.d.ts +5 -29
- package/dist/commands/uplink/GetArchiveDaysMC.js +11 -37
- package/dist/commands/uplink/GetArchiveDaysMC.js.map +1 -1
- package/dist/commands/uplink/GetArchiveHoursMC.d.ts +47 -7
- package/dist/commands/uplink/GetArchiveHoursMC.js +43 -23
- package/dist/commands/uplink/GetArchiveHoursMC.js.map +1 -1
- package/dist/commands/uplink/GetCurrentMC.d.ts +2 -8
- package/dist/commands/uplink/GetCurrentMC.js +3 -3
- package/dist/commands/uplink/GetCurrentMC.js.map +1 -1
- package/dist/commands/uplink/index.d.ts +1 -0
- package/dist/commands/uplink/index.js +1 -0
- package/dist/commands/uplink/index.js.map +1 -1
- package/dist/constants/deviceParameters.d.ts +5 -1
- package/dist/constants/deviceParameters.js +5 -1
- package/dist/constants/deviceParameters.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,93 +1,57 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
5
1
|
import Command from '../../Command.js';
|
|
6
|
-
import GetCurrentMC from './GetCurrentMC.js';
|
|
7
2
|
import { getSecondsFromDate, getDateFromSeconds } from '../../utils/time.js';
|
|
8
3
|
import CommandBinaryBuffer from '../../CommandBinaryBuffer.js';
|
|
9
|
-
import roundNumber from '../../utils/roundNumber.js';
|
|
10
4
|
import { UPLINK } from '../../constants/directionTypes.js';
|
|
11
5
|
// TODO: rework extended headers detection
|
|
12
6
|
const COMMAND_ID = 0x0c1f;
|
|
13
|
-
const COMMAND_TITLE = '
|
|
7
|
+
const COMMAND_TITLE = 'EX_ABS_ARCHIVE_HOUR_MC';
|
|
14
8
|
// date 2 bytes, hour 1 byte (max hours: 7), channelList 1 byte (max channelList: 4)
|
|
15
9
|
// 4 + (4 channelList * 1 byte pulse coefficient) + (4 channelList * 5 bytes of hour values) + (4 * 5 bytes of diff * 7 max hours diff)
|
|
16
10
|
const COMMAND_BODY_MAX_SIZE = 168;
|
|
17
|
-
class
|
|
18
|
-
// TODO: add interface for parameters
|
|
11
|
+
class ExAbsArchiveHoursMC extends Command {
|
|
19
12
|
constructor(parameters) {
|
|
20
|
-
super(
|
|
13
|
+
super();
|
|
21
14
|
this.parameters = parameters;
|
|
15
|
+
this.parameters.channelList = this.parameters.channelList.sort((a, b) => a.index - b.index);
|
|
22
16
|
}
|
|
23
17
|
static fromBytes(data) {
|
|
24
18
|
const buffer = new CommandBinaryBuffer(data);
|
|
25
19
|
const date = buffer.getDate();
|
|
26
20
|
const { hour, hours } = buffer.getHours();
|
|
27
|
-
const
|
|
28
|
-
const maxChannel = Math.max.apply(null, channelArray);
|
|
29
|
-
date.setUTCHours(hour);
|
|
30
|
-
const counterDate = new Date(date);
|
|
31
|
-
let hourAmount = hours;
|
|
21
|
+
const channels = buffer.getChannels();
|
|
32
22
|
const channelList = [];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
for (let channelIndex = 0; channelIndex <= maxChannel; ++channelIndex) {
|
|
38
|
-
// IPK_${channelIndex}
|
|
39
|
-
const pulseCoefficient = buffer.getUint8();
|
|
40
|
-
// decode hour value for channel
|
|
41
|
-
const pulseValue = buffer.getExtendedValue();
|
|
23
|
+
date.setUTCHours(hour);
|
|
24
|
+
channels.forEach(channelIndex => {
|
|
25
|
+
const value = buffer.getExtendedValue();
|
|
42
26
|
const diff = [];
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const value = buffer.getExtendedValue();
|
|
46
|
-
counterDate.setUTCHours(counterDate.getUTCHours() + hourIndex);
|
|
47
|
-
diff.push({
|
|
48
|
-
value,
|
|
49
|
-
pulseCoefficient,
|
|
50
|
-
seconds: getSecondsFromDate(counterDate),
|
|
51
|
-
meterValue: roundNumber((value + pulseValue) / pulseCoefficient)
|
|
52
|
-
});
|
|
27
|
+
for (let hourIndex = 0; hourIndex < hours; ++hourIndex) {
|
|
28
|
+
diff.push(buffer.getExtendedValue());
|
|
53
29
|
}
|
|
54
30
|
channelList.push({
|
|
55
31
|
diff,
|
|
56
|
-
|
|
57
|
-
index: channelIndex
|
|
58
|
-
value: pulseValue,
|
|
59
|
-
seconds: getSecondsFromDate(date),
|
|
60
|
-
meterValue: roundNumber(pulseValue / pulseCoefficient)
|
|
32
|
+
value,
|
|
33
|
+
index: channelIndex
|
|
61
34
|
});
|
|
62
|
-
}
|
|
63
|
-
return new
|
|
35
|
+
});
|
|
36
|
+
return new ExAbsArchiveHoursMC({ channelList, hours, startTime: getSecondsFromDate(date) });
|
|
64
37
|
}
|
|
65
38
|
toBytes() {
|
|
66
39
|
const buffer = new CommandBinaryBuffer(COMMAND_BODY_MAX_SIZE);
|
|
67
|
-
const { channelList } = this.parameters;
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
let hours = channelList[0].diff.length;
|
|
72
|
-
// TODO: add link to doc
|
|
73
|
-
if (hours === 1) {
|
|
74
|
-
hours = 0;
|
|
75
|
-
}
|
|
76
|
-
buffer.setDate(seconds);
|
|
40
|
+
const { channelList, startTime, hours } = this.parameters;
|
|
41
|
+
const date = getDateFromSeconds(startTime);
|
|
42
|
+
const hour = date.getUTCHours();
|
|
43
|
+
buffer.setDate(date);
|
|
77
44
|
buffer.setHours(hour, hours);
|
|
78
45
|
buffer.setChannels(channelList);
|
|
79
|
-
for (const { value, diff
|
|
80
|
-
buffer.setUint8(pulseCoefficient);
|
|
46
|
+
for (const { value, diff } of channelList) {
|
|
81
47
|
buffer.setExtendedValue(value);
|
|
82
|
-
|
|
83
|
-
buffer.setExtendedValue(diffValue);
|
|
84
|
-
}
|
|
48
|
+
diff.forEach(diffValue => buffer.setExtendedValue(diffValue));
|
|
85
49
|
}
|
|
86
50
|
return Command.toBytes(COMMAND_ID, buffer.getBytesToOffset());
|
|
87
51
|
}
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
export default
|
|
53
|
+
ExAbsArchiveHoursMC.id = COMMAND_ID;
|
|
54
|
+
ExAbsArchiveHoursMC.directionType = UPLINK;
|
|
55
|
+
ExAbsArchiveHoursMC.title = COMMAND_TITLE;
|
|
56
|
+
export default ExAbsArchiveHoursMC;
|
|
93
57
|
//# sourceMappingURL=ExAbsArchiveHoursMC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExAbsArchiveHoursMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsArchiveHoursMC.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"ExAbsArchiveHoursMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsArchiveHoursMC.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAC,kBAAkB,EAAE,kB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from '../../Command.js';
|
|
2
|
+
import { IChannelAbsoluteValue } from '../../CommandBinaryBuffer.js';
|
|
3
|
+
interface IUplinkExAbsCurrentMCParameters {
|
|
4
|
+
channelList: Array<IChannelAbsoluteValue>;
|
|
5
|
+
}
|
|
6
|
+
declare class ExAbsCurrentMC extends Command {
|
|
7
|
+
parameters: IUplinkExAbsCurrentMCParameters;
|
|
8
|
+
constructor(parameters: IUplinkExAbsCurrentMCParameters);
|
|
9
|
+
static id: number;
|
|
10
|
+
static readonly directionType = 2;
|
|
11
|
+
static title: string;
|
|
12
|
+
static fromBytes(data: Uint8Array): ExAbsCurrentMC;
|
|
13
|
+
toBytes(): Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
export default ExAbsCurrentMC;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Command from '../../Command.js';
|
|
2
|
+
import CommandBinaryBuffer from '../../CommandBinaryBuffer.js';
|
|
3
|
+
import { UPLINK } from '../../constants/directionTypes.js';
|
|
4
|
+
const COMMAND_ID = 0x0f1f;
|
|
5
|
+
const COMMAND_TITLE = 'EX_ABS_CURRENT_MC';
|
|
6
|
+
// channelList 3 byte (max channelList: 14)
|
|
7
|
+
// 3 + (14 * (1 byte IPK + 5 bytes of day values))
|
|
8
|
+
const COMMAND_BODY_MAX_SIZE = 87;
|
|
9
|
+
class ExAbsCurrentMC extends Command {
|
|
10
|
+
constructor(parameters) {
|
|
11
|
+
super();
|
|
12
|
+
this.parameters = parameters;
|
|
13
|
+
this.parameters.channelList = this.parameters.channelList.sort((a, b) => a.index - b.index);
|
|
14
|
+
}
|
|
15
|
+
static fromBytes(data) {
|
|
16
|
+
const buffer = new CommandBinaryBuffer(data);
|
|
17
|
+
return new ExAbsCurrentMC({ channelList: buffer.getChannelsWithAbsoluteValues() });
|
|
18
|
+
}
|
|
19
|
+
toBytes() {
|
|
20
|
+
const buffer = new CommandBinaryBuffer(COMMAND_BODY_MAX_SIZE);
|
|
21
|
+
const { channelList } = this.parameters;
|
|
22
|
+
buffer.setChannelsWithAbsoluteValues(channelList);
|
|
23
|
+
return Command.toBytes(COMMAND_ID, buffer.getBytesToOffset());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
ExAbsCurrentMC.id = COMMAND_ID;
|
|
27
|
+
ExAbsCurrentMC.directionType = UPLINK;
|
|
28
|
+
ExAbsCurrentMC.title = COMMAND_TITLE;
|
|
29
|
+
export default ExAbsCurrentMC;
|
|
30
|
+
//# sourceMappingURL=ExAbsCurrentMC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExAbsCurrentMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsCurrentMC.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,mBAA4C,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAQzD,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAE1C,2CAA2C;AAC3C,kDAAkD;AAClD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAGjC,MAAM,cAAe,SAAQ,OAAO;IAChC,YAAqB,UAA2C;QAC5D,KAAK,EAAE,CAAC;QADS,eAAU,GAAV,UAAU,CAAiC;QAG5D,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAChG,CAAC;IAQD,MAAM,CAAC,SAAS,CAAG,IAAgB;QAC/B,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAE7C,OAAO,IAAI,cAAc,CAAC,EAAC,WAAW,EAAE,MAAM,CAAC,6BAA6B,EAAE,EAAC,CAAC,CAAC;IACrF,CAAC;IAED,OAAO;QACH,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;QAC9D,MAAM,EAAC,WAAW,EAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAEtC,MAAM,CAAC,6BAA6B,CAAC,WAAW,CAAC,CAAC;QAElD,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAClE,CAAC;;AAnBM,iBAAE,GAAG,UAAU,CAAC;AAEP,4BAAa,GAAG,MAAM,CAAC;AAEhC,oBAAK,GAAG,aAAa,CAAC;AAmBjC,eAAe,cAAc,CAAC"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import GetCurrentMC from './GetCurrentMC.js';
|
|
2
|
+
import { IChannelAbsoluteValue } from '../../CommandBinaryBuffer.js';
|
|
3
|
+
interface IExAbsDayMCParameters {
|
|
4
|
+
channelList: Array<IChannelAbsoluteValue>;
|
|
5
|
+
startTime: number;
|
|
6
|
+
}
|
|
2
7
|
declare class ExAbsDayMC extends GetCurrentMC {
|
|
3
|
-
parameters:
|
|
4
|
-
constructor(parameters:
|
|
8
|
+
parameters: IExAbsDayMCParameters;
|
|
9
|
+
constructor(parameters: IExAbsDayMCParameters);
|
|
5
10
|
static id: number;
|
|
6
11
|
static readonly directionType = 2;
|
|
7
12
|
static title: string;
|
|
8
|
-
static fromBytes(data: Uint8Array):
|
|
13
|
+
static fromBytes(data: Uint8Array): ExAbsDayMC;
|
|
9
14
|
toBytes(): Uint8Array;
|
|
10
15
|
}
|
|
11
16
|
export default ExAbsDayMC;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
5
1
|
import Command from '../../Command.js';
|
|
6
2
|
import GetCurrentMC from './GetCurrentMC.js';
|
|
7
3
|
import CommandBinaryBuffer from '../../CommandBinaryBuffer.js';
|
|
8
|
-
import roundNumber from '../../utils/roundNumber.js';
|
|
9
|
-
import { getSecondsFromDate } from '../../utils/time.js';
|
|
10
4
|
import { UPLINK } from '../../constants/directionTypes.js';
|
|
5
|
+
import { getSecondsFromDate } from '../../utils/time.js';
|
|
11
6
|
const COMMAND_ID = 0x0b1f;
|
|
12
|
-
const COMMAND_TITLE = '
|
|
13
|
-
// date 2 bytes, channelList
|
|
14
|
-
//
|
|
15
|
-
const COMMAND_BODY_MAX_SIZE =
|
|
7
|
+
const COMMAND_TITLE = 'EX_ABS_DAY_MC';
|
|
8
|
+
// date 2 bytes, channelList 3 bytes (max channelList: 14)
|
|
9
|
+
// 5 + (14 channelList * (1 byte IPK + 5 bytes of day values))
|
|
10
|
+
const COMMAND_BODY_MAX_SIZE = 89;
|
|
16
11
|
class ExAbsDayMC extends GetCurrentMC {
|
|
17
12
|
constructor(parameters) {
|
|
18
13
|
super(parameters);
|
|
@@ -21,35 +16,14 @@ class ExAbsDayMC extends GetCurrentMC {
|
|
|
21
16
|
static fromBytes(data) {
|
|
22
17
|
const buffer = new CommandBinaryBuffer(data);
|
|
23
18
|
const date = buffer.getDate();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
let value;
|
|
27
|
-
const channelList = [];
|
|
28
|
-
for (let channelIndex = 0; channelIndex <= maxChannel; ++channelIndex) {
|
|
29
|
-
// IPK_${channelIndex}
|
|
30
|
-
const pulseCoefficient = buffer.getUint8();
|
|
31
|
-
// day value
|
|
32
|
-
value = buffer.getExtendedValue();
|
|
33
|
-
channelList.push({
|
|
34
|
-
value,
|
|
35
|
-
pulseCoefficient,
|
|
36
|
-
index: channelIndex,
|
|
37
|
-
seconds: getSecondsFromDate(date),
|
|
38
|
-
meterValue: roundNumber(value / pulseCoefficient)
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return new ExAbsDayMC({ channelList, date });
|
|
19
|
+
const channelList = buffer.getChannelsWithAbsoluteValues();
|
|
20
|
+
return new ExAbsDayMC({ channelList, startTime: getSecondsFromDate(date) });
|
|
42
21
|
}
|
|
43
22
|
toBytes() {
|
|
44
23
|
const buffer = new CommandBinaryBuffer(COMMAND_BODY_MAX_SIZE);
|
|
45
|
-
const { channelList } = this.parameters;
|
|
46
|
-
|
|
47
|
-
buffer.
|
|
48
|
-
buffer.setChannels(channelList);
|
|
49
|
-
for (const { value, pulseCoefficient } of channelList) {
|
|
50
|
-
buffer.setUint8(pulseCoefficient);
|
|
51
|
-
buffer.setExtendedValue(value);
|
|
52
|
-
}
|
|
24
|
+
const { channelList, startTime } = this.parameters;
|
|
25
|
+
buffer.setDate(startTime);
|
|
26
|
+
buffer.setChannelsWithAbsoluteValues(channelList);
|
|
53
27
|
return Command.toBytes(COMMAND_ID, buffer.getBytesToOffset());
|
|
54
28
|
}
|
|
55
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExAbsDayMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsDayMC.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ExAbsDayMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsDayMC.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,mBAA4C,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AACzD,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AASvD,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC,0DAA0D;AAC1D,8DAA8D;AAC9D,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAGjC,MAAM,UAAW,SAAQ,YAAY;IACjC,YAAqB,UAAiC;QAClD,KAAK,CAAC,UAAU,CAAC,CAAC;QADD,eAAU,GAAV,UAAU,CAAuB;IAEtD,CAAC;IAQD,MAAM,CAAC,SAAS,CAAG,IAAgB;QAC/B,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAC9B,MAAM,WAAW,GAAG,MAAM,CAAC,6BAA6B,EAAE,CAAC;QAE3D,OAAO,IAAI,UAAU,CAAC,EAAC,WAAW,EAAE,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO;QACH,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;QAC9D,MAAM,EAAC,WAAW,EAAE,SAAS,EAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAEjD,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1B,MAAM,CAAC,6BAA6B,CAAC,WAAW,CAAC,CAAC;QAElD,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAClE,CAAC;;AAtBM,aAAE,GAAG,UAAU,CAAC;AAEP,wBAAa,GAAG,MAAM,CAAC;AAEhC,gBAAK,GAAG,aAAa,CAAC;AAsBjC,eAAe,UAAU,CAAC"}
|
|
@@ -1,11 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import Command from '../../Command.js';
|
|
2
|
+
import { IChannelHourAbsoluteValue } from '../../CommandBinaryBuffer.js';
|
|
3
|
+
/**
|
|
4
|
+
* GetArchiveHoursMC command parameters
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // archive hours values from 001-03-10T12:00:00.000Z with 1-hour diff
|
|
8
|
+
*
|
|
9
|
+
* {
|
|
10
|
+
* startTime: 731764800,
|
|
11
|
+
* hours: 1,
|
|
12
|
+
* channelList: [
|
|
13
|
+
* {
|
|
14
|
+
* pulseCoefficient: 100,
|
|
15
|
+
* index: 0,
|
|
16
|
+
* value: 342457,
|
|
17
|
+
* diff: [128]
|
|
18
|
+
* }
|
|
19
|
+
* ]
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
interface IUplinkExAbsHourMCParameters {
|
|
24
|
+
channelList: Array<IChannelHourAbsoluteValue>;
|
|
25
|
+
startTime: number;
|
|
26
|
+
hours: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Uplink command
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```js
|
|
33
|
+
* import ExAbsHourMC from 'jooby-codec/commands/uplink/GetArchiveHoursMC';
|
|
34
|
+
*
|
|
35
|
+
* const command = new ExAbsHourMC({
|
|
36
|
+
* startTime: 731764800,
|
|
37
|
+
* hours: 1,
|
|
38
|
+
* channelList: [
|
|
39
|
+
* {
|
|
40
|
+
* pulseCoefficient: 100,
|
|
41
|
+
* index: 0,
|
|
42
|
+
* value: 342457,
|
|
43
|
+
* diff: [128]
|
|
44
|
+
* }
|
|
45
|
+
* ]
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // output command binary in hex representation
|
|
49
|
+
* console.log(command.toHex());
|
|
50
|
+
* // 1a 0d 2f 97 0c 0f 83 01 0a 08 0a 08 0a 0c 0a
|
|
51
|
+
* ```
|
|
52
|
+
* [Command format documentation](https://github.com/jooby-dev/jooby-docs/blob/main/docs/commands/uplink/ExAbsHourMC.md)
|
|
53
|
+
*/
|
|
54
|
+
declare class ExAbsHourMC extends Command {
|
|
55
|
+
parameters: IUplinkExAbsHourMCParameters;
|
|
56
|
+
constructor(parameters: IUplinkExAbsHourMCParameters);
|
|
5
57
|
static readonly id = 2591;
|
|
6
58
|
static readonly directionType = 2;
|
|
7
|
-
static readonly title = "
|
|
8
|
-
static fromBytes(data: Uint8Array):
|
|
59
|
+
static readonly title = "EX_ABS_HOUR_MC";
|
|
60
|
+
static fromBytes(data: Uint8Array): ExAbsHourMC;
|
|
9
61
|
toBytes(): Uint8Array;
|
|
10
62
|
}
|
|
11
63
|
export default ExAbsHourMC;
|
|
@@ -1,86 +1,81 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
5
1
|
import Command from '../../Command.js';
|
|
6
|
-
import GetCurrentMC from './GetCurrentMC.js';
|
|
7
2
|
import { getSecondsFromDate, getDateFromSeconds } from '../../utils/time.js';
|
|
8
3
|
import CommandBinaryBuffer from '../../CommandBinaryBuffer.js';
|
|
9
|
-
import roundNumber from '../../utils/roundNumber.js';
|
|
10
4
|
import { UPLINK } from '../../constants/directionTypes.js';
|
|
11
5
|
const COMMAND_ID = 0x0a1f;
|
|
12
|
-
const COMMAND_TITLE = '
|
|
6
|
+
const COMMAND_TITLE = 'EX_ABS_HOUR_MC';
|
|
13
7
|
// date 2 bytes, hour 1 byte, channelList - 1 byte (max channelList: 4)
|
|
14
8
|
// max hours diff - 7 (3 bit value)
|
|
15
9
|
// 4 + (4 channelList * (1 byte IPK + 5 bytes of hour value)) + (4 * 2 bytes of diff * 7 max hours diff)
|
|
16
10
|
const COMMAND_BODY_MAX_SIZE = 84;
|
|
17
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Uplink command
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* import ExAbsHourMC from 'jooby-codec/commands/uplink/GetArchiveHoursMC';
|
|
17
|
+
*
|
|
18
|
+
* const command = new ExAbsHourMC({
|
|
19
|
+
* startTime: 731764800,
|
|
20
|
+
* hours: 1,
|
|
21
|
+
* channelList: [
|
|
22
|
+
* {
|
|
23
|
+
* pulseCoefficient: 100,
|
|
24
|
+
* index: 0,
|
|
25
|
+
* value: 342457,
|
|
26
|
+
* diff: [128]
|
|
27
|
+
* }
|
|
28
|
+
* ]
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // output command binary in hex representation
|
|
32
|
+
* console.log(command.toHex());
|
|
33
|
+
* // 1a 0d 2f 97 0c 0f 83 01 0a 08 0a 08 0a 0c 0a
|
|
34
|
+
* ```
|
|
35
|
+
* [Command format documentation](https://github.com/jooby-dev/jooby-docs/blob/main/docs/commands/uplink/ExAbsHourMC.md)
|
|
36
|
+
*/
|
|
37
|
+
class ExAbsHourMC extends Command {
|
|
18
38
|
constructor(parameters) {
|
|
19
|
-
super(
|
|
39
|
+
super();
|
|
20
40
|
this.parameters = parameters;
|
|
41
|
+
this.parameters.channelList = this.parameters.channelList.sort((a, b) => a.index - b.index);
|
|
21
42
|
}
|
|
22
43
|
static fromBytes(data) {
|
|
23
44
|
const buffer = new CommandBinaryBuffer(data);
|
|
24
45
|
const date = buffer.getDate();
|
|
25
46
|
const { hour, hours } = buffer.getHours();
|
|
26
|
-
const
|
|
27
|
-
const maxChannel = Math.max.apply(null, channelArray);
|
|
28
|
-
date.setUTCHours(hour);
|
|
29
|
-
const counterDate = new Date(date);
|
|
30
|
-
let hourAmount = hours;
|
|
47
|
+
const channels = buffer.getChannels();
|
|
31
48
|
const channelList = [];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
for (let channelIndex = 0; channelIndex <= maxChannel; ++channelIndex) {
|
|
37
|
-
// IPK_${channelIndex}
|
|
49
|
+
const hourAmount = hours === 0 ? 1 : hours;
|
|
50
|
+
date.setUTCHours(hour);
|
|
51
|
+
channels.forEach(channelIndex => {
|
|
38
52
|
const pulseCoefficient = buffer.getUint8();
|
|
39
|
-
|
|
40
|
-
const pulseValue = buffer.getExtendedValue();
|
|
41
|
-
counterDate.setTime(date.getTime());
|
|
53
|
+
const value = buffer.getExtendedValue();
|
|
42
54
|
const diff = [];
|
|
43
55
|
for (let hourIndex = 0; hourIndex < hourAmount; ++hourIndex) {
|
|
44
|
-
|
|
45
|
-
counterDate.setUTCHours(counterDate.getUTCHours() + hourIndex);
|
|
46
|
-
diff.push({
|
|
47
|
-
value,
|
|
48
|
-
pulseCoefficient,
|
|
49
|
-
seconds: getSecondsFromDate(counterDate),
|
|
50
|
-
meterValue: roundNumber((value + pulseValue) / pulseCoefficient)
|
|
51
|
-
});
|
|
56
|
+
diff.push(buffer.getExtendedValue());
|
|
52
57
|
}
|
|
53
58
|
channelList.push({
|
|
54
59
|
diff,
|
|
60
|
+
value,
|
|
55
61
|
pulseCoefficient,
|
|
56
|
-
index: channelIndex
|
|
57
|
-
value: pulseValue,
|
|
58
|
-
seconds: getSecondsFromDate(date),
|
|
59
|
-
meterValue: roundNumber(pulseValue / pulseCoefficient)
|
|
62
|
+
index: channelIndex
|
|
60
63
|
});
|
|
61
|
-
}
|
|
62
|
-
return new ExAbsHourMC({ channelList, date });
|
|
64
|
+
});
|
|
65
|
+
return new ExAbsHourMC({ channelList, hours: hourAmount, startTime: getSecondsFromDate(date) });
|
|
63
66
|
}
|
|
64
67
|
toBytes() {
|
|
65
68
|
const buffer = new CommandBinaryBuffer(COMMAND_BODY_MAX_SIZE);
|
|
66
|
-
const { channelList } = this.parameters;
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
let hours = channelList[0].diff.length;
|
|
71
|
-
// TODO: add link to doc
|
|
72
|
-
if (hours === 1) {
|
|
73
|
-
hours = 0;
|
|
74
|
-
}
|
|
75
|
-
buffer.setDate(seconds);
|
|
69
|
+
const { hours, startTime, channelList } = this.parameters;
|
|
70
|
+
const date = getDateFromSeconds(startTime);
|
|
71
|
+
const hour = date.getUTCHours();
|
|
72
|
+
buffer.setDate(startTime);
|
|
76
73
|
buffer.setHours(hour, hours);
|
|
77
74
|
buffer.setChannels(channelList);
|
|
78
75
|
for (const { value, diff, pulseCoefficient } of channelList) {
|
|
79
76
|
buffer.setUint8(pulseCoefficient);
|
|
80
77
|
buffer.setExtendedValue(value);
|
|
81
|
-
|
|
82
|
-
buffer.setExtendedValue(diffValue);
|
|
83
|
-
}
|
|
78
|
+
diff.forEach(diffValue => buffer.setExtendedValue(diffValue));
|
|
84
79
|
}
|
|
85
80
|
return Command.toBytes(COMMAND_ID, buffer.getBytesToOffset());
|
|
86
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExAbsHourMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsHourMC.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ExAbsHourMC.js","sourceRoot":"","sources":["../../../src/commands/uplink/ExAbsHourMC.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AAC3E,OAAO,mBAAgD,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AA8BzD,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAEvC,uEAAuE;AACvE,mCAAmC;AACnC,wGAAwG;AACxG,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAGjC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAY,SAAQ,OAAO;IAC7B,YAAqB,UAAwC;QACzD,KAAK,EAAE,CAAC;QADS,eAAU,GAAV,UAAU,CAA8B;QAGzD,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC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AAE,SAAS,EAAE,WAAW,EAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAExD,MAAM,IAAI,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEhC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC7B,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAEhC,KAAM,MAAM,EAAC,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAC,IAAI,WAAW,EAAG;YACzD,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;YAClC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;SACjE;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAClE,CAAC;;AAvDe,cAAE,GAAG,UAAU,CAAC;AAEhB,yBAAa,GAAG,MAAM,CAAC;AAEvB,iBAAK,GAAG,aAAa,CAAC;AAuD1C,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Command from '../../Command.js';
|
|
2
|
+
import { IChannelDays } from '../../CommandBinaryBuffer.js';
|
|
2
3
|
/**
|
|
3
4
|
* GetArchiveDaysMC command parameters
|
|
4
5
|
*
|
|
@@ -11,34 +12,9 @@ import Command from '../../Command.js';
|
|
|
11
12
|
* }
|
|
12
13
|
*/
|
|
13
14
|
interface IUplinkGetArchiveDaysMCParameters {
|
|
14
|
-
channelList: Array<
|
|
15
|
-
|
|
16
|
-
days: number
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* channel value by day
|
|
20
|
-
*/
|
|
21
|
-
export interface IArchiveDayValue {
|
|
22
|
-
value: number;
|
|
23
|
-
day: number;
|
|
24
|
-
seconds: number;
|
|
25
|
-
date: Date;
|
|
26
|
-
}
|
|
27
|
-
interface IArchiveChannel {
|
|
28
|
-
/**
|
|
29
|
-
* channel number
|
|
30
|
-
*/
|
|
31
|
-
index: number;
|
|
32
|
-
/**
|
|
33
|
-
* values by days
|
|
34
|
-
*/
|
|
35
|
-
dayList: Array<IArchiveDayValue>;
|
|
36
|
-
/** time */
|
|
37
|
-
seconds: number;
|
|
38
|
-
/**
|
|
39
|
-
* Normal date in UTC.
|
|
40
|
-
*/
|
|
41
|
-
date: Date;
|
|
15
|
+
channelList: Array<IChannelDays>;
|
|
16
|
+
startTime: number;
|
|
17
|
+
days: number;
|
|
42
18
|
}
|
|
43
19
|
/**
|
|
44
20
|
* Uplink command
|
|
@@ -66,7 +42,7 @@ declare class GetArchiveDaysMC extends Command {
|
|
|
66
42
|
constructor(parameters: IUplinkGetArchiveDaysMCParameters);
|
|
67
43
|
static readonly id = 27;
|
|
68
44
|
static readonly directionType = 2;
|
|
69
|
-
static readonly title = "
|
|
45
|
+
static readonly title = "GET_ARCHIVE_DAYS_MC";
|
|
70
46
|
static fromBytes(data: Uint8Array): GetArchiveDaysMC;
|
|
71
47
|
toBytes(): Uint8Array;
|
|
72
48
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Command from '../../Command.js';
|
|
2
2
|
import CommandBinaryBuffer from '../../CommandBinaryBuffer.js';
|
|
3
3
|
import { UPLINK } from '../../constants/directionTypes.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getSecondsFromDate } from '../../utils/time.js';
|
|
5
5
|
const COMMAND_ID = 0x1b;
|
|
6
|
-
const COMMAND_TITLE = '
|
|
6
|
+
const COMMAND_TITLE = 'GET_ARCHIVE_DAYS_MC';
|
|
7
7
|
// date 2 bytes, channelList 1 byte (max channelList: 4), days 1 byte (max days - 255)
|
|
8
8
|
// 4 + (4 channelList * 5 bytes of day values * 255 max days)
|
|
9
9
|
const COMMAND_BODY_MAX_SIZE = 5104;
|
|
@@ -33,59 +33,33 @@ class GetArchiveDaysMC extends Command {
|
|
|
33
33
|
super();
|
|
34
34
|
this.parameters = parameters;
|
|
35
35
|
this.parameters.channelList = this.parameters.channelList.sort((a, b) => a.index - b.index);
|
|
36
|
-
const { date, days, channelList } = this.parameters;
|
|
37
|
-
if (date === undefined) {
|
|
38
|
-
const [{ seconds }] = channelList;
|
|
39
|
-
if (seconds) {
|
|
40
|
-
this.parameters.date = getDateFromSeconds(seconds);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
throw new Error(`${GetArchiveDaysMC.getName()} can't recognize time`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else if (typeof date === 'string') {
|
|
47
|
-
this.parameters.date = new Date(date);
|
|
48
|
-
}
|
|
49
|
-
if (days === undefined) {
|
|
50
|
-
this.parameters.days = channelList[0].dayList.length;
|
|
51
|
-
}
|
|
52
36
|
}
|
|
53
37
|
static fromBytes(data) {
|
|
54
38
|
const buffer = new CommandBinaryBuffer(data);
|
|
55
39
|
const date = buffer.getDate();
|
|
56
|
-
const
|
|
40
|
+
const channels = buffer.getChannels();
|
|
57
41
|
const days = buffer.getUint8();
|
|
58
|
-
const maxChannel = Math.max.apply(null, channelArray);
|
|
59
42
|
const channelList = [];
|
|
60
|
-
|
|
61
|
-
let value;
|
|
62
|
-
for (let channelIndex = 0; channelIndex <= maxChannel; ++channelIndex) {
|
|
43
|
+
channels.forEach(channelIndex => {
|
|
63
44
|
const dayList = [];
|
|
64
|
-
counterDate.setTime(date.getTime());
|
|
65
45
|
channelList.push({
|
|
66
46
|
dayList,
|
|
67
|
-
index: channelIndex
|
|
68
|
-
seconds: getSecondsFromDate(counterDate),
|
|
69
|
-
date: new Date(counterDate)
|
|
47
|
+
index: channelIndex
|
|
70
48
|
});
|
|
71
49
|
for (let day = 0; day < days; ++day) {
|
|
72
|
-
|
|
73
|
-
counterDate.setTime(date.getTime());
|
|
74
|
-
counterDate.setUTCHours(counterDate.getUTCHours() + (day * 24));
|
|
75
|
-
dayList.push({ value, day, date: new Date(counterDate), seconds: getSecondsFromDate(counterDate) });
|
|
50
|
+
dayList.push(buffer.getExtendedValue());
|
|
76
51
|
}
|
|
77
|
-
}
|
|
78
|
-
return new GetArchiveDaysMC({ channelList,
|
|
52
|
+
});
|
|
53
|
+
return new GetArchiveDaysMC({ channelList, days, startTime: getSecondsFromDate(date) });
|
|
79
54
|
}
|
|
80
55
|
toBytes() {
|
|
81
56
|
const buffer = new CommandBinaryBuffer(COMMAND_BODY_MAX_SIZE);
|
|
82
|
-
const { days,
|
|
83
|
-
buffer.setDate(
|
|
57
|
+
const { days, startTime, channelList } = this.parameters;
|
|
58
|
+
buffer.setDate(startTime);
|
|
84
59
|
buffer.setChannels(channelList);
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
86
60
|
buffer.setUint8(days);
|
|
87
61
|
channelList.forEach(({ dayList }) => {
|
|
88
|
-
dayList.forEach(
|
|
62
|
+
dayList.forEach(value => buffer.setExtendedValue(value));
|
|
89
63
|
});
|
|
90
64
|
return Command.toBytes(COMMAND_ID, buffer.getBytesToOffset());
|
|
91
65
|
}
|