jooby-codec 3.11.0 → 3.13.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.
Files changed (159) hide show
  1. package/dist/Command.d.ts +32 -0
  2. package/dist/Command.js +31 -0
  3. package/dist/Command.js.map +1 -0
  4. package/dist/analog/Command.d.ts +3 -25
  5. package/dist/analog/Command.js +3 -20
  6. package/dist/analog/Command.js.map +1 -1
  7. package/dist/analog/CommandBinaryBuffer.d.ts +113 -5
  8. package/dist/analog/CommandBinaryBuffer.js +596 -6
  9. package/dist/analog/CommandBinaryBuffer.js.map +1 -1
  10. package/dist/analog/UnknownCommand.d.ts +2 -3
  11. package/dist/analog/UnknownCommand.js +3 -4
  12. package/dist/analog/UnknownCommand.js.map +1 -1
  13. package/dist/analog/commands/DataSegmentBase.d.ts +2 -3
  14. package/dist/analog/commands/DataSegmentBase.js +3 -4
  15. package/dist/analog/commands/DataSegmentBase.js.map +1 -1
  16. package/dist/analog/commands/downlink/GetArchiveHoursMCEx.d.ts +20 -0
  17. package/dist/analog/commands/downlink/GetArchiveHoursMCEx.js +51 -0
  18. package/dist/analog/commands/downlink/GetArchiveHoursMCEx.js.map +1 -0
  19. package/dist/analog/commands/downlink/SetParameter.js +191 -0
  20. package/dist/analog/commands/downlink/SetParameter.js.map +1 -1
  21. package/dist/analog/commands/downlink/index.d.ts +1 -0
  22. package/dist/analog/commands/downlink/index.js +1 -0
  23. package/dist/analog/commands/downlink/index.js.map +1 -1
  24. package/dist/analog/commands/uplink/GetArchiveHoursMCExResponse.d.ts +21 -0
  25. package/dist/analog/commands/uplink/GetArchiveHoursMCExResponse.js +55 -0
  26. package/dist/analog/commands/uplink/GetArchiveHoursMCExResponse.js.map +1 -0
  27. package/dist/analog/commands/uplink/GetParameterResponse.js +179 -3
  28. package/dist/analog/commands/uplink/GetParameterResponse.js.map +1 -1
  29. package/dist/analog/commands/uplink/HourMCEx.d.ts +22 -0
  30. package/dist/analog/commands/uplink/HourMCEx.js +45 -0
  31. package/dist/analog/commands/uplink/HourMCEx.js.map +1 -0
  32. package/dist/analog/commands/uplink/Status.js +1 -0
  33. package/dist/analog/commands/uplink/Status.js.map +1 -1
  34. package/dist/analog/commands/uplink/index.d.ts +2 -0
  35. package/dist/analog/commands/uplink/index.js +2 -0
  36. package/dist/analog/commands/uplink/index.js.map +1 -1
  37. package/dist/analog/constants/commandRelations.d.ts +2 -2
  38. package/dist/analog/constants/commandRelations.js +1 -0
  39. package/dist/analog/constants/commandRelations.js.map +1 -1
  40. package/dist/analog/constants/deviceParameters.d.ts +17 -0
  41. package/dist/analog/constants/deviceParameters.js +17 -0
  42. package/dist/analog/constants/deviceParameters.js.map +1 -1
  43. package/dist/analog/constants/hardwareTypes.d.ts +1 -0
  44. package/dist/analog/constants/hardwareTypes.js +1 -0
  45. package/dist/analog/constants/hardwareTypes.js.map +1 -1
  46. package/dist/analog/splitBytesToDataSegments.js +4 -1
  47. package/dist/analog/splitBytesToDataSegments.js.map +1 -1
  48. package/dist/mtx/Command.d.ts +10 -26
  49. package/dist/mtx/Command.js +7 -28
  50. package/dist/mtx/Command.js.map +1 -1
  51. package/dist/mtx/CommandBinaryBuffer.d.ts +61 -29
  52. package/dist/mtx/CommandBinaryBuffer.js +165 -71
  53. package/dist/mtx/CommandBinaryBuffer.js.map +1 -1
  54. package/dist/mtx/UnknownCommand.d.ts +2 -3
  55. package/dist/mtx/UnknownCommand.js +3 -4
  56. package/dist/mtx/UnknownCommand.js.map +1 -1
  57. package/dist/mtx/commands/downlink/GetCurrentValues.d.ts +13 -0
  58. package/dist/mtx/commands/downlink/GetCurrentValues.js +31 -0
  59. package/dist/mtx/commands/downlink/GetCurrentValues.js.map +1 -0
  60. package/dist/mtx/commands/downlink/GetEnergyCurrent.d.ts +18 -0
  61. package/dist/mtx/commands/downlink/GetEnergyCurrent.js +49 -0
  62. package/dist/mtx/commands/downlink/GetEnergyCurrent.js.map +1 -0
  63. package/dist/mtx/commands/downlink/GetEnergyDay.d.ts +20 -0
  64. package/dist/mtx/commands/downlink/GetEnergyDay.js +67 -0
  65. package/dist/mtx/commands/downlink/GetEnergyDay.js.map +1 -0
  66. package/dist/mtx/commands/downlink/GetEnergyDayPrevious.d.ts +13 -0
  67. package/dist/mtx/commands/downlink/GetEnergyDayPrevious.js +31 -0
  68. package/dist/mtx/commands/downlink/GetEnergyDayPrevious.js.map +1 -0
  69. package/dist/mtx/commands/downlink/GetExtendedCurrentValues.d.ts +13 -0
  70. package/dist/mtx/commands/downlink/GetExtendedCurrentValues.js +31 -0
  71. package/dist/mtx/commands/downlink/GetExtendedCurrentValues.js.map +1 -0
  72. package/dist/mtx/commands/downlink/GetHalfHours.d.ts +15 -0
  73. package/dist/mtx/commands/downlink/GetHalfHours.js +44 -0
  74. package/dist/mtx/commands/downlink/GetHalfHours.js.map +1 -0
  75. package/dist/mtx/commands/downlink/GetRatePlanInfo.js +3 -3
  76. package/dist/mtx/commands/downlink/GetRatePlanInfo.js.map +1 -1
  77. package/dist/mtx/commands/downlink/SetCorrectDateTime.d.ts +1 -1
  78. package/dist/mtx/commands/downlink/SetCorrectDateTime.js +2 -2
  79. package/dist/mtx/commands/downlink/SetCorrectDateTime.js.map +1 -1
  80. package/dist/mtx/commands/downlink/SetDateTime.js +7 -7
  81. package/dist/mtx/commands/downlink/SetDateTime.js.map +1 -1
  82. package/dist/mtx/commands/downlink/index.d.ts +6 -0
  83. package/dist/mtx/commands/downlink/index.js +6 -0
  84. package/dist/mtx/commands/downlink/index.js.map +1 -1
  85. package/dist/mtx/commands/uplink/GetBuildVersionResponse.d.ts +2 -4
  86. package/dist/mtx/commands/uplink/GetBuildVersionResponse.js +13 -9
  87. package/dist/mtx/commands/uplink/GetBuildVersionResponse.js.map +1 -1
  88. package/dist/mtx/commands/uplink/GetCurrentValuesResponse.d.ts +27 -0
  89. package/dist/mtx/commands/uplink/GetCurrentValuesResponse.js +88 -0
  90. package/dist/mtx/commands/uplink/GetCurrentValuesResponse.js.map +1 -0
  91. package/dist/mtx/commands/uplink/GetDateTimeResponse.js +1 -1
  92. package/dist/mtx/commands/uplink/GetDateTimeResponse.js.map +1 -1
  93. package/dist/mtx/commands/uplink/GetEnergyCurrentResponse.d.ts +16 -0
  94. package/dist/mtx/commands/uplink/GetEnergyCurrentResponse.js +83 -0
  95. package/dist/mtx/commands/uplink/GetEnergyCurrentResponse.js.map +1 -0
  96. package/dist/mtx/commands/uplink/GetEnergyDayPreviousResponse.d.ts +21 -0
  97. package/dist/mtx/commands/uplink/GetEnergyDayPreviousResponse.js +74 -0
  98. package/dist/mtx/commands/uplink/GetEnergyDayPreviousResponse.js.map +1 -0
  99. package/dist/mtx/commands/uplink/GetEnergyDayResponse.d.ts +20 -0
  100. package/dist/mtx/commands/uplink/GetEnergyDayResponse.js +95 -0
  101. package/dist/mtx/commands/uplink/GetEnergyDayResponse.js.map +1 -0
  102. package/dist/mtx/commands/uplink/GetExtendedCurrentValuesResponse.d.ts +20 -0
  103. package/dist/mtx/commands/uplink/GetExtendedCurrentValuesResponse.js +58 -0
  104. package/dist/mtx/commands/uplink/GetExtendedCurrentValuesResponse.js.map +1 -0
  105. package/dist/mtx/commands/uplink/GetHalfHoursResponse.d.ts +21 -0
  106. package/dist/mtx/commands/uplink/GetHalfHoursResponse.js +261 -0
  107. package/dist/mtx/commands/uplink/GetHalfHoursResponse.js.map +1 -0
  108. package/dist/mtx/commands/uplink/GetRatePlanInfoResponse.js +3 -3
  109. package/dist/mtx/commands/uplink/GetRatePlanInfoResponse.js.map +1 -1
  110. package/dist/mtx/commands/uplink/SetCorrectDateTimeResponse.d.ts +1 -1
  111. package/dist/mtx/commands/uplink/SetCorrectDateTimeResponse.js +2 -2
  112. package/dist/mtx/commands/uplink/SetCorrectDateTimeResponse.js.map +1 -1
  113. package/dist/mtx/commands/uplink/SetDateTimeResponse.d.ts +1 -1
  114. package/dist/mtx/commands/uplink/SetDateTimeResponse.js +2 -2
  115. package/dist/mtx/commands/uplink/SetDateTimeResponse.js.map +1 -1
  116. package/dist/mtx/commands/uplink/index.d.ts +6 -0
  117. package/dist/mtx/commands/uplink/index.js +6 -0
  118. package/dist/mtx/commands/uplink/index.js.map +1 -1
  119. package/dist/mtx/constants/commandRelations.d.ts +2 -2
  120. package/dist/mtx/constants/commandRelations.js +2 -0
  121. package/dist/mtx/constants/commandRelations.js.map +1 -1
  122. package/dist/mtx/constants/screenIds.d.ts +29 -22
  123. package/dist/mtx/constants/screenIds.js +29 -22
  124. package/dist/mtx/constants/screenIds.js.map +1 -1
  125. package/dist/mtx/constants/screenSets.js +29 -21
  126. package/dist/mtx/constants/screenSets.js.map +1 -1
  127. package/dist/mtx/message.d.ts +4 -3
  128. package/dist/mtx/message.js +8 -6
  129. package/dist/mtx/message.js.map +1 -1
  130. package/dist/mtxLora/CommandBinaryBuffer.d.ts +3 -6
  131. package/dist/mtxLora/CommandBinaryBuffer.js +18 -18
  132. package/dist/mtxLora/CommandBinaryBuffer.js.map +1 -1
  133. package/dist/mtxLora/commands/downlink/GetHalfhoursEnergies.d.ts +3 -2
  134. package/dist/mtxLora/commands/downlink/GetHalfhoursEnergies.js +3 -3
  135. package/dist/mtxLora/commands/downlink/GetHalfhoursEnergies.js.map +1 -1
  136. package/dist/mtxLora/commands/uplink/GetDayEnergies.d.ts +4 -2
  137. package/dist/mtxLora/commands/uplink/GetDayEnergies.js +42 -5
  138. package/dist/mtxLora/commands/uplink/GetDayEnergies.js.map +1 -1
  139. package/dist/mtxLora/commands/uplink/GetDayMaxPower.d.ts +4 -2
  140. package/dist/mtxLora/commands/uplink/GetDayMaxPower.js +40 -3
  141. package/dist/mtxLora/commands/uplink/GetDayMaxPower.js.map +1 -1
  142. package/dist/mtxLora/commands/uplink/GetHalfhoursEnergies.d.ts +5 -3
  143. package/dist/mtxLora/commands/uplink/GetHalfhoursEnergies.js +43 -6
  144. package/dist/mtxLora/commands/uplink/GetHalfhoursEnergies.js.map +1 -1
  145. package/dist/mtxLora/message.d.ts +5 -27
  146. package/dist/mtxLora/message.js +5 -110
  147. package/dist/mtxLora/message.js.map +1 -1
  148. package/dist/obis-observer/Command.d.ts +3 -25
  149. package/dist/obis-observer/Command.js +3 -26
  150. package/dist/obis-observer/Command.js.map +1 -1
  151. package/dist/obis-observer/UnknownCommand.d.ts +2 -3
  152. package/dist/obis-observer/UnknownCommand.js +3 -4
  153. package/dist/obis-observer/UnknownCommand.js.map +1 -1
  154. package/dist/types.d.ts +5 -0
  155. package/dist/utils/bytesConversion.d.ts +6 -1
  156. package/dist/utils/bytesConversion.js +10 -3
  157. package/dist/utils/bytesConversion.js.map +1 -1
  158. package/dist/utils/permutations.d.ts +1 -1
  159. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
- import Command, { COMMAND_HEADER_SIZE } from '../../Command.js';
2
- import CommandBinaryBuffer from '../../CommandBinaryBuffer.js';
1
+ import Command, { COMMAND_HEADER_SIZE, defaultDlmsJsonOptions } from '../../Command.js';
2
+ import CommandBinaryBuffer, { TARIFF_NUMBER } from '../../CommandBinaryBuffer.js';
3
3
  import { UPLINK } from '../../../constants/directions.js';
4
- const COMMAND_ID = 0x69;
4
+ const COMMAND_ID = 0x6f;
5
5
  const DATE_SIZE = 3;
6
6
  const MAX_HALFHOURS_ENERGY_SIZE = 5 * 3 * 4;
7
7
  const COMMAND_MAX_SIZE = DATE_SIZE + MAX_HALFHOURS_ENERGY_SIZE;
@@ -12,7 +12,7 @@ const examples = [
12
12
  date: {
13
13
  year: 21,
14
14
  month: 2,
15
- day: 3
15
+ date: 3
16
16
  },
17
17
  firstHalfhour: 1,
18
18
  halfhoursNumber: 2,
@@ -22,11 +22,35 @@ const examples = [
22
22
  }
23
23
  },
24
24
  hex: {
25
- header: '69 15',
26
- body: '2a 43 11 01 02 00 00 10 00 00 00 20 00 00 00 30 00 00 00 40 00'
25
+ header: '6f 0d',
26
+ body: '2a 43 11 01 02 10 00 20 00 30 00 40 00'
27
27
  }
28
28
  }
29
29
  ];
30
+ const energiesToObis = {
31
+ 'A+': '1.5.x',
32
+ 'A+R+': '3.5.x',
33
+ 'A+R-': '4.5.x',
34
+ 'A-': '2.5.x',
35
+ 'A-R+': '6.5.x',
36
+ 'A-R-': '7.5.x'
37
+ };
38
+ const convertEnergyToObis = (energy, tariff = 0) => {
39
+ const obis = energiesToObis[energy];
40
+ return obis ? obis.replace('x', tariff.toString(10)) : '';
41
+ };
42
+ const convertHalfhoursEnergiesToDlms = (energies) => {
43
+ const dlms = {};
44
+ for (const [energy, values] of Object.entries(energies)) {
45
+ for (let tariff = 0; tariff < TARIFF_NUMBER; tariff++) {
46
+ const value = values[tariff];
47
+ if (value || value === 0) {
48
+ dlms[convertEnergyToObis(energy, tariff + 1)] = value;
49
+ }
50
+ }
51
+ }
52
+ return dlms;
53
+ };
30
54
  class GetHalfhoursEnergies extends Command {
31
55
  constructor(parameters) {
32
56
  super();
@@ -59,6 +83,19 @@ class GetHalfhoursEnergies extends Command {
59
83
  ...buffer.getBytesToOffset()
60
84
  ]);
61
85
  }
86
+ toJson({ dlms } = defaultDlmsJsonOptions) {
87
+ const { parameters } = this;
88
+ const { date, firstHalfhour, halfhoursNumber, energies } = parameters;
89
+ const result = dlms
90
+ ? {
91
+ date,
92
+ firstHalfhour,
93
+ halfhoursNumber,
94
+ ...convertHalfhoursEnergiesToDlms(energies)
95
+ }
96
+ : parameters;
97
+ return JSON.stringify(result);
98
+ }
62
99
  }
63
100
  GetHalfhoursEnergies.id = COMMAND_ID;
64
101
  GetHalfhoursEnergies.directionType = UPLINK;
@@ -1 +1 @@
1
- {"version":3,"file":"GetHalfhoursEnergies.js","sourceRoot":"","sources":["../../../../src/mtxLora/commands/uplink/GetHalfhoursEnergies.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAsB,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AACnF,OAAO,mBAAgD,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAC,MAAM,EAAC,MAAM,kCAAkC,CAAC;AAWxD,MAAM,UA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a,CAAC,CAAC;QAC/B,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjC,MAAM,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAEtC,OAAO,IAAI,UAAU,CAAC;YAClB,UAAU;YACV,MAAM,CAAC,QAAQ;YACf,GAAG,MAAM,CAAC,gBAAgB,EAAE;SAC/B,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAG,EAAC,IAAI,KAAsB,sBAAsB;QACtD,MAAM,EAAC,UAAU,EAAC,GAAG,IAAI,CAAC;QAC1B,MAAM,EAAC,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAC,GAAG,UAAU,CAAC;QACpE,MAAM,MAAM,GAAG,IAAI;YACf,CAAC,CAAC;gBACE,IAAI;gBACJ,aAAa;gBACb,eAAe;gBACf,GAAG,8BAA8B,CAAC,QAAQ,CAAC;aAC9C;YACD,CAAC,CAAC,UAAU,CAAC;QAEjB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;;AA3De,uBAAE,GAAG,UAAU,CAAC;AAEhB,kCAAa,GAAG,MAAM,CAAC;AAEvB,6BAAQ,GAAG,QAAQ,CAAC;AAEpB,kCAAa,GAAG,IAAI,CAAC;AAErB,4BAAO,GAAG,GAAG,CAAC;AAuDlC,eAAe,oBAAoB,CAAC"}
@@ -1,27 +1,5 @@
1
- import Command from './Command.js';
2
- import { IHexFormatOptions } from '../config.js';
3
- interface IMessageCommand {
4
- data: {
5
- header: Uint8Array;
6
- body: Uint8Array;
7
- };
8
- command: Command;
9
- }
10
- export interface IMessage {
11
- messageId: number;
12
- accessLevel: number;
13
- bytes: Uint8Array;
14
- commands?: Array<IMessageCommand>;
15
- }
16
- export interface IMessageConfig {
17
- direction?: number;
18
- accessLevel?: number;
19
- aesKey?: Uint8Array;
20
- }
21
- export declare const fromBytes: (bytes: Uint8Array, config?: IMessageConfig) => IMessage;
22
- export declare const fromHex: (data: string, config?: IMessageConfig) => IMessage;
23
- export declare const fromBase64: (data: string, config?: IMessageConfig) => IMessage;
24
- export declare const toBytes: (messageId: number, commands: Array<Command>, config?: IMessageConfig) => Uint8Array;
25
- export declare const toHex: (messageId: number, commands: Array<Command>, config?: IMessageConfig, hexOptions?: IHexFormatOptions) => string;
26
- export declare const toBase64: (messageId: number, commands: Array<Command>, config?: IMessageConfig) => string;
27
- export {};
1
+ import * as mtx from '../mtx/message.js';
2
+ export declare const fromBytes: (message: Uint8Array, config?: mtx.IFromBytesOptions) => mtx.IMessage;
3
+ export declare const fromHex: (data: string, config?: mtx.IFromBytesOptions) => mtx.IMessage;
4
+ export declare const fromBase64: (data: string, config?: mtx.IFromBytesOptions) => mtx.IMessage;
5
+ export { IFromBytesOptions, IToBytesOptions, toBytes, toFrame, toHex, toBase64 } from '../mtx/message.js';
@@ -1,111 +1,6 @@
1
- import UnknownCommand from './UnknownCommand.js';
2
- import { requestById as mtxLoraRequestById, responseById as mtxLoraResponseById } from './constants/commandRelations.js';
3
- import { requestById as mtxRequestById, responseById as mtxResponseById } from '../mtx/constants/commandRelations.js';
4
- import { accessLevels } from '../mtx/constants/index.js';
5
- import getBytesFromHex from '../utils/getBytesFromHex.js';
6
- import getBytesFromBase64 from '../utils/getBytesFromBase64.js';
7
- import getHexFromBytes from '../utils/getHexFromBytes.js';
8
- import getBase64FromBytes from '../utils/getBase64FromBytes.js';
9
- import mergeUint8Arrays from '../utils/mergeUint8Arrays.js';
10
- import { aes } from '../mtx/utils/crypto.js';
11
- import * as directionTypes from '../constants/directions.js';
12
- import { AUTO, DOWNLINK, UPLINK } from '../constants/directions.js';
13
- import { UNENCRYPTED } from '../mtx/constants/accessLevels.js';
14
- const ACCESS_LEVEL_MASK = 0x03;
15
- const COMMAND_HEADER_SIZE = 2;
16
- const PROTOCOL_VERSION = 0x10;
17
- const BLOCK_SIZE = 16;
18
- const directionTypeIds = new Set(Object.values(directionTypes));
19
- const getCommand = (id, data, direction = AUTO) => {
20
- if (!directionTypeIds.has(direction)) {
21
- throw new Error('wrong direction type');
22
- }
23
- const downlinkCommand = mtxLoraRequestById.get(id) || mtxRequestById.get(id);
24
- const uplinkCommand = mtxLoraResponseById.get(id) || mtxResponseById.get(id);
25
- if ((!downlinkCommand && !uplinkCommand)
26
- || (direction === DOWNLINK && !downlinkCommand)
27
- || (direction === UPLINK && !uplinkCommand)) {
28
- return UnknownCommand.fromBytes(id, data);
29
- }
30
- try {
31
- if (direction === DOWNLINK || direction === UPLINK) {
32
- const command = direction === UPLINK ? uplinkCommand : downlinkCommand;
33
- return command.fromBytes(data);
34
- }
35
- try {
36
- return uplinkCommand.fromBytes(data);
37
- }
38
- catch {
39
- return downlinkCommand.fromBytes(data);
40
- }
41
- }
42
- catch {
43
- return UnknownCommand.fromBytes(id, data);
44
- }
45
- };
46
- export const fromBytes = (bytes, config) => {
47
- const direction = config?.direction ?? AUTO;
48
- const aesKey = config?.aesKey;
49
- const commands = [];
50
- const [messageId, accessLevel1] = bytes;
51
- let messageBody = bytes.slice(2);
52
- const result = {
53
- messageId,
54
- bytes,
55
- accessLevel: (accessLevel1 & ACCESS_LEVEL_MASK)
56
- };
57
- if (result.accessLevel !== accessLevels.UNENCRYPTED) {
58
- if (aesKey) {
59
- messageBody = aes.decrypt(aesKey, messageBody);
60
- }
61
- else {
62
- return result;
63
- }
64
- }
65
- const [accessLevel2] = messageBody;
66
- messageBody = messageBody.slice(1);
67
- if (accessLevel1 !== accessLevel2) {
68
- throw new Error('wrong access level');
69
- }
70
- result.commands = commands;
71
- let position = 0;
72
- do {
73
- const commandId = messageBody[position];
74
- const commandBodySize = messageBody[position + 1];
75
- const commandSize = COMMAND_HEADER_SIZE + commandBodySize;
76
- const commandBody = messageBody.slice(position + COMMAND_HEADER_SIZE, position + commandSize);
77
- if (!commandId) {
78
- break;
79
- }
80
- const command = getCommand(commandId, commandBody, direction);
81
- commands.push({
82
- data: { header: new Uint8Array([commandId]), body: commandBody },
83
- command
84
- });
85
- position += commandSize;
86
- } while (position <= messageBody.length);
87
- return result;
88
- };
89
- export const fromHex = (data, config) => (fromBytes(getBytesFromHex(data), config));
90
- export const fromBase64 = (data, config) => (fromBytes(getBytesFromBase64(data), config));
91
- export const toBytes = (messageId, commands, config) => {
92
- const accessLevel = config?.accessLevel || UNENCRYPTED;
93
- const aesKey = config?.aesKey;
94
- const commandBytes = commands.map(command => command.toBytes());
95
- const maskedAccessLevel = accessLevel | PROTOCOL_VERSION;
96
- const header = new Uint8Array([messageId, maskedAccessLevel]);
97
- let body = mergeUint8Arrays(new Uint8Array([maskedAccessLevel]), ...commandBytes);
98
- if (accessLevel !== accessLevels.UNENCRYPTED) {
99
- const padding = (body.length + 1) % BLOCK_SIZE;
100
- if (padding) {
101
- body = mergeUint8Arrays(body, new Uint8Array(BLOCK_SIZE - padding).fill(0));
102
- }
103
- if (aesKey) {
104
- body = aes.encrypt(aesKey, body);
105
- }
106
- }
107
- return mergeUint8Arrays(header, body);
108
- };
109
- export const toHex = (messageId, commands, config, hexOptions = {}) => (getHexFromBytes(toBytes(messageId, commands, config), hexOptions));
110
- export const toBase64 = (messageId, commands, config) => (getBase64FromBytes(toBytes(messageId, commands, config)));
1
+ import * as mtx from '../mtx/message.js';
2
+ export const fromBytes = (message, config) => (mtx.fromBytes(message, { withMtxLora: true, ...config }));
3
+ export const fromHex = (data, config) => (mtx.fromHex(data, { withMtxLora: true, ...config }));
4
+ export const fromBase64 = (data, config) => (mtx.fromBase64(data, { withMtxLora: true, ...config }));
5
+ export { toBytes, toFrame, toHex, toBase64 } from '../mtx/message.js';
111
6
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/mtxLora/message.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,WAAW,IAAI,kBAAkB,EAAE,YAAY,IAAI,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACvH,OAAO,EAAC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E,EAAC,WAAW,EAAE,IAAI,EAAE,GAAG,MAAM,EAAC,CAAC,CACvD,CAAC;AAEF,OAAO,EAGH,OAAO,EACP,OAAO,EACP,KAAK,EACL,QAAQ,EACX,MAAM,mBAAmB,CAAC"}
@@ -1,28 +1,6 @@
1
- import { IHexFormatOptions } from '../config.js';
2
- export interface ICommandExample {
3
- name: string;
4
- parameters?: object;
5
- hardwareType?: number;
6
- hex: {
7
- header: string;
8
- body: string;
9
- };
10
- }
11
- export type TCommandExampleList = Array<ICommandExample>;
12
- declare abstract class Command {
13
- static id: number;
14
- static directionType: unknown;
15
- static title: string;
16
- static examples: TCommandExampleList;
17
- static hasParameters: boolean;
18
- parameters: unknown;
19
- size: number;
20
- static getId(): string;
1
+ import BaseCommand from '../Command.js';
2
+ export { ICommandExample, TCommandExampleList, TJsonOptions, defaultJsonOptions } from '../Command.js';
3
+ declare abstract class Command extends BaseCommand {
21
4
  static toBytes(id: number, commandData?: Uint8Array): Uint8Array;
22
- getParameters(): unknown;
23
- toBytes(): Uint8Array;
24
- toHex(options?: IHexFormatOptions): string;
25
- toBase64(): string;
26
- toJson(): string;
27
5
  }
28
6
  export default Command;
@@ -1,14 +1,7 @@
1
- import getHexFromBytes from '../utils/getHexFromBytes.js';
2
- import getHexFromNumber from '../utils/getHexFromNumber.js';
3
- import getBase64FromBytes from '../utils/getBase64FromBytes.js';
1
+ import BaseCommand from '../Command.js';
4
2
  import mergeUint8Arrays from '../utils/mergeUint8Arrays.js';
5
- class Command {
6
- constructor() {
7
- this.size = 0;
8
- }
9
- static getId() {
10
- return getHexFromNumber(this.id);
11
- }
3
+ export { defaultJsonOptions } from '../Command.js';
4
+ class Command extends BaseCommand {
12
5
  static toBytes(id, commandData) {
13
6
  const commandLength = commandData?.length ?? 0;
14
7
  const headerData = new Uint8Array([id, commandLength]);
@@ -17,22 +10,6 @@ class Command {
17
10
  }
18
11
  return headerData;
19
12
  }
20
- getParameters() {
21
- return this.parameters;
22
- }
23
- toBytes() {
24
- throw new Error('not implemented!');
25
- }
26
- toHex(options = {}) {
27
- return getHexFromBytes(this.toBytes(), options);
28
- }
29
- toBase64() {
30
- return getBase64FromBytes(this.toBytes());
31
- }
32
- toJson() {
33
- return JSON.stringify(this.getParameters());
34
- }
35
13
  }
36
- Command.hasParameters = false;
37
14
  export default Command;
38
15
  //# sourceMappingURL=Command.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Command.js","sourceRoot":"","sources":["../../src/obis-observer/Command.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAC1D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,kBAAkB,MAAM,gCAAgC,CAAC;AAChE,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAmB5D,MAAe,OAAO;IAAtB;QAeI,SAAI,GAAW,CAAC,CAAC;IA2FrB,CAAC;IAvFG,MAAM,CAAC,KAAK;QACR,OAAO,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IA+CD,MAAM,CAAC,OAAO,CAAG,EAAU,EAAE,WAAwB;QACjD,MAAM,aAAa,GAAG,WAAW,EAAE,MAAM,IAAI,CAAC,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;QAEvD,IAAK,WAAW,IAAI,aAAa,EAAG,CAAC;YACjC,OAAO,gBAAgB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;QAGD,OAAO,UAAU,CAAC;IACtB,CAAC;IAGD,aAAa;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAGD,OAAO;QACH,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAG,UAA6B,EAAE;QACnC,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,QAAQ;QACJ,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,CAAC;IAOD,MAAM;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAChD,CAAC;;AAhGM,qBAAa,GAAG,KAAK,AAAR,CAAS;AAoGjC,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"Command.js","sourceRoot":"","sources":["../../src/obis-observer/Command.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAqD,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAMrG,MAAe,OAAQ,SAAQ,WAAW;IAQtC,MAAM,CAAC,OAAO,CAAG,EAAU,EAAE,WAAwB;QACjD,MAAM,aAAa,GAAG,WAAW,EAAE,MAAM,IAAI,CAAC,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;QAEvD,IAAK,WAAW,IAAI,aAAa,EAAG,CAAC;YACjC,OAAO,gBAAgB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;QAGD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAGD,eAAe,OAAO,CAAC"}
@@ -1,5 +1,4 @@
1
- import Command from './Command.js';
2
- import { TBytesConversionFormatOptions } from '../utils/bytesConversion.js';
1
+ import Command, { TJsonOptions } from './Command.js';
3
2
  interface IUnknownCommandParameters {
4
3
  id: number;
5
4
  data: Uint8Array;
@@ -9,6 +8,6 @@ declare class UnknownCommand extends Command {
9
8
  constructor(parameters: IUnknownCommandParameters);
10
9
  static fromBytes(data: Uint8Array, id: number): UnknownCommand;
11
10
  toBytes(): Uint8Array;
12
- toJson(bytesConversionFormat?: number, bytesConversionFormatOptions?: TBytesConversionFormatOptions): string;
11
+ toJson(options?: TJsonOptions): string;
13
12
  }
14
13
  export default UnknownCommand;
@@ -1,5 +1,4 @@
1
- import Command from './Command.js';
2
- import { HEX } from '../constants/bytesConversionFormats.js';
1
+ import Command, { defaultJsonOptions } from './Command.js';
3
2
  import { getStringFromBytes } from '../utils/bytesConversion.js';
4
3
  class UnknownCommand extends Command {
5
4
  constructor(parameters) {
@@ -14,11 +13,11 @@ class UnknownCommand extends Command {
14
13
  const { id, data } = this.parameters;
15
14
  return Command.toBytes(id, data);
16
15
  }
17
- toJson(bytesConversionFormat = HEX, bytesConversionFormatOptions = {}) {
16
+ toJson(options = defaultJsonOptions) {
18
17
  const { id, data } = this.parameters;
19
18
  return JSON.stringify({
20
19
  id,
21
- data: getStringFromBytes(data, bytesConversionFormat, bytesConversionFormatOptions)
20
+ data: getStringFromBytes(data, options)
22
21
  });
23
22
  }
24
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UnknownCommand.js","sourceRoot":"","sources":["../../src/obis-observer/UnknownCommand.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAC,GAAG,EAAC,MAAM,wCAAwC,CAAC;AAC3D,OAAO,EAAgC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAiB9F,MAAM,cAAe,SAAQ,OAAO;IAChC,YAAqB,UAAqC;QACtD,KAAK,EAAE,CAAC;QADS,eAAU,GAAV,UAAU,CAA2B;IAE1D,CAAC;IAGD,MAAM,CAAC,SAAS,CAAG,IAAgB,EAAE,EAAU;QAC3C,MAAM,UAAU,GAA8B,EAAC,EAAE,EAAE,IAAI,EAAC,CAAC;QAEzD,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAGD,OAAO;QACH,MAAM,EAAC,EAAE,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAEnC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACrC,C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Ac,CAAC"}
package/dist/types.d.ts CHANGED
@@ -11,3 +11,8 @@ export type TYear2000 = BrandType<number, 'year'>;
11
11
  export type TMonth = BrandType<number, 'month'>;
12
12
  export type TMonthDay = BrandType<number, 'monthDay'>;
13
13
  export type TWeekDay = BrandType<number, 'weekDay'>;
14
+ export interface IDate {
15
+ year: TYear2000;
16
+ month: TMonth;
17
+ date: TMonthDay;
18
+ }
@@ -2,6 +2,11 @@ import { IHexFormatOptions } from '../config.js';
2
2
  interface IBase64FormatOptions {
3
3
  }
4
4
  export type TBytesConversionFormatOptions = IHexFormatOptions | IBase64FormatOptions;
5
- export declare const getStringFromBytes: (bytes: Uint8Array, bytesConversionFormat?: number, bytesConversionFormatOptions?: TBytesConversionFormatOptions) => string;
5
+ export interface IBytesConversionFormatOptions {
6
+ bytesConversionFormat: number;
7
+ bytesConversionFormatOptions: TBytesConversionFormatOptions;
8
+ }
9
+ export declare const defaultFormatOptions: IBytesConversionFormatOptions;
10
+ export declare const getStringFromBytes: (bytes: Uint8Array, options?: IBytesConversionFormatOptions) => string;
6
11
  export declare const getBytesFromString: (data: string, bytesConversionFormat?: number) => Uint8Array;
7
12
  export {};
@@ -3,8 +3,15 @@ import getBase64FromBytes from './getBase64FromBytes.js';
3
3
  import getBytesFromBase64 from './getBytesFromBase64.js';
4
4
  import getBytesFromHex from './getBytesFromHex.js';
5
5
  import getHexFromBytes from './getHexFromBytes.js';
6
- export const getStringFromBytes = (bytes, bytesConversionFormat = HEX, bytesConversionFormatOptions = {}) => (bytesConversionFormat === HEX
7
- ? getHexFromBytes(bytes, bytesConversionFormatOptions)
8
- : getBase64FromBytes(bytes));
6
+ export const defaultFormatOptions = {
7
+ bytesConversionFormat: HEX,
8
+ bytesConversionFormatOptions: {}
9
+ };
10
+ export const getStringFromBytes = (bytes, options = defaultFormatOptions) => {
11
+ const { bytesConversionFormat = defaultFormatOptions.bytesConversionFormat, bytesConversionFormatOptions = defaultFormatOptions.bytesConversionFormatOptions } = options;
12
+ return bytesConversionFormat === HEX
13
+ ? getHexFromBytes(bytes, bytesConversionFormatOptions)
14
+ : getBase64FromBytes(bytes);
15
+ };
9
16
  export const getBytesFromString = (data, bytesConversionFormat = HEX) => (bytesConversionFormat === HEX ? getBytesFromHex(data) : getBytesFromBase64(data));
10
17
  //# sourceMappingURL=bytesConversion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytesConversion.js","sourceRoot":"","sources":["../../src/utils/bytesConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,wCAAwC,CAAC;AAC3D,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AASnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,KAAiB,EACjB,wBAAgC,GAAG,EACnC,+BAA8D,EAAE,EAClE,EAAE,CAAC,CACD,qBAAqB,KAAK,GAAG;IACzB,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,4BAA4B,CAAC;IACtD,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAClC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAE,IAAY,EAAE,wBAAgC,GAAG,EAAG,EAAE,CAAC,CACvF,qBAAqB,KAAK,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CACnF,CAAC"}
1
+ {"version":3,"file":"bytesConversion.js","sourceRoot":"","sources":["../../src/utils/bytesConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,wCAAwC,CAAC;AAC3D,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAcnD,MAAM,CAAC,MAAM,oBAAoB,GAAkC;IAC/D,qBAAqB,EAAE,GAAG;IAC1B,4BAA4B,EAAE,EAAE;CACnC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,KAAiB,EACjB,UAAyC,oBAAoB,EAC/D,EAAE;IACA,MAAM,EACF,qBAAqB,GAAG,oBAAoB,CAAC,qBAAqB,EAClE,4BAA4B,GAAG,oBAAoB,CAAC,4BAA4B,EACnF,GAAG,OAAO,CAAC;IAEZ,OAAO,qBAAqB,KAAK,GAAG;QAChC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,4BAA4B,CAAC;QACtD,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAE,IAAY,EAAE,wBAAgC,GAAG,EAAG,EAAE,CAAC,CACvF,qBAAqB,KAAK,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CACnF,CAAC"}
@@ -1,2 +1,2 @@
1
- declare const permutations: <T>(sequence: T[]) => T[][];
1
+ declare const permutations: <T>(sequence: Array<T>) => Array<Array<T>>;
2
2
  export default permutations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jooby-codec",
3
- "version": "3.11.0",
3
+ "version": "3.13.0",
4
4
  "description": "Jooby message encoders/decoders",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  "node": ">=18.0.0"
37
37
  },
38
38
  "dependencies": {
39
- "crypto-js": "^4.1.1"
39
+ "crypto-js": "^4.2.0"
40
40
  },
41
41
  "license": "MIT"
42
42
  }