tlms_esd 0.1.0 → 0.6.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/.git-blame-ignore-revs +5 -0
- package/.gitattributes +9 -0
- package/.gitignore +41 -0
- package/.local/TODO.md +90 -0
- package/.local/data_structure2025.xlsx +0 -0
- package/.local/data_structure2026.xlsx +0 -0
- package/.local/issues/a6d39veq-actuator-emulator.md +75 -0
- package/.local/issues/v9xg9fxn-config-compile-entry.md +86 -0
- package/.local/issues/yqq38rn8-adapt-layout-data-emulator.md +74 -0
- package/.npmignore +18 -0
- package/AGENTS.md +153 -0
- package/CHANGELOG.md +192 -0
- package/cli.js +185 -263
- package/doc/design.md +691 -0
- package/doc/design.zh-cn.md +690 -0
- package/doc/spec-modbus.md +263 -0
- package/doc/spec-modbus.zh-cn.md +261 -0
- package/doc/spec.md +310 -0
- package/doc/spec.zh-cn.md +308 -0
- package/eslint.config.js +58 -0
- package/issues/yqq38rn8-adapt-layout-data-emulator.md +71 -0
- package/layouts.yaml +208 -0
- package/logs/error_2024-10-11.log +2 -0
- package/logs/error_2026-10-09.log +36 -0
- package/logs/error_2026-10-10.log +1 -0
- package/logs/error_2026-10-11.log +0 -0
- package/logs/error_2026-10-12.log +0 -0
- package/logs/error_2026-10-13.log +0 -0
- package/logs/error_2026-10-15.log +0 -0
- package/logs/error_2026-10-16.log +0 -0
- package/logs/error_2026-10-17.log +0 -0
- package/logs/error_2026-10-23.log +0 -0
- package/logs/error_2026-10-25.log +3 -0
- package/logs/error_2026-10-27.log +0 -0
- package/logs/error_2026-10-28.log +0 -0
- package/logs/error_2026-10-30.log +0 -0
- package/logs/error_2026-11-05.log +0 -0
- package/logs/error_2026-11-07.log +0 -0
- package/logs/error_2026-11-14.log +1 -0
- package/logs/error_2026-11-15.log +0 -0
- package/logs/error_2026-11-17.log +0 -0
- package/logs/error_2026-11-18.log +0 -0
- package/logs/error_2026-11-22.log +0 -0
- package/logs/info_2024-10-11.log +2 -0
- package/logs/info_2026-10-09.log +36 -0
- package/logs/info_2026-10-10.log +1 -0
- package/logs/info_2026-10-11.log +0 -0
- package/logs/info_2026-10-12.log +0 -0
- package/logs/info_2026-10-13.log +0 -0
- package/logs/info_2026-10-15.log +0 -0
- package/logs/info_2026-10-16.log +0 -0
- package/logs/info_2026-10-17.log +0 -0
- package/logs/info_2026-10-23.log +0 -0
- package/logs/info_2026-10-25.log +3 -0
- package/logs/info_2026-10-27.log +0 -0
- package/logs/info_2026-10-28.log +0 -0
- package/logs/info_2026-10-30.log +0 -0
- package/logs/info_2026-11-05.log +0 -0
- package/logs/info_2026-11-07.log +0 -0
- package/logs/info_2026-11-14.log +1 -0
- package/logs/info_2026-11-15.log +0 -0
- package/logs/info_2026-11-17.log +0 -0
- package/logs/info_2026-11-18.log +0 -0
- package/logs/info_2026-11-22.log +0 -0
- package/main.js +27852 -8191
- package/nodemon.json +9 -11
- package/package.json +24 -25
- package/rolldown.config.js +35 -0
- package/dev.js +0 -5
- package/emulator.js +0 -7768
- package/rollup.config.js +0 -41
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v0.6.0 - 2026-11-22
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- The in-tree emulator is removed: the `emu` package export and the `tlms emu`
|
|
8
|
+
subcommand are gone; use the standalone modbus-emulator package instead.
|
|
9
|
+
- Upward register map: SECTION has 20 registers (`inner_word` is removed); the
|
|
10
|
+
section bypass is removed and its word is kept as the reserved `upward_input`.
|
|
11
|
+
The line bypass and the section manual hang-up (`hangon_MF`) are renamed
|
|
12
|
+
`flow_override`. The camelCase tags are renamed to snake_case
|
|
13
|
+
(`auto_stop_cmd` / `man_stop_cmd`, `flow1_k_factor`..`flow5_k_factor`) with
|
|
14
|
+
their offsets unchanged. The HMI must follow these names.
|
|
15
|
+
- The names of controllers, lines, sections and actuators must be identifiers
|
|
16
|
+
(ASCII letters, digits and `_`, not starting with a digit); a name that is not
|
|
17
|
+
makes the controller exit at startup. The command block of an actuator is
|
|
18
|
+
named `<actuator name>_command`.
|
|
19
|
+
- Each actuator masks its commands by its configured `supported_commands`
|
|
20
|
+
instead of a fixed mask shared by all actuators. Without the field every
|
|
21
|
+
command is supported, so commands masked before (`cancel_stop`, `horn`, ...)
|
|
22
|
+
are now sent: list the supported commands of actuators that lack some.
|
|
23
|
+
- Configuration files are parsed as YAML 1.2 (merge keys are no longer
|
|
24
|
+
supported), and only the top level of the working directory is read.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- The controller runs as a scan: every main period (500 ms) and right after
|
|
29
|
+
device data, HMI writes or connection changes arrive, all rules are evaluated
|
|
30
|
+
in dependency order on one set of inputs. Summaries have no debounce any more,
|
|
31
|
+
a flow delay or countdown whose condition drops resets at once, and commands
|
|
32
|
+
are sent in the same scan.
|
|
33
|
+
- The line `flow_override` is a master switch for the flow-difference
|
|
34
|
+
protection of all its sections, without rewriting their own `flow_override`.
|
|
35
|
+
- Interlocks: the flow pre-stop notice uses the line's `pump_run`, so a leaking
|
|
36
|
+
section without pumps of its own is covered; the pressure interlock is
|
|
37
|
+
triggered only by actuators that allow it (`pressure_AH_F && pressure_SD_F`);
|
|
38
|
+
pressure and flow actions are set, reset and recorded separately.
|
|
39
|
+
- At startup the controller writes the complete description of its upward
|
|
40
|
+
service to `<controller>/emulator.yaml`. The upward server exits the
|
|
41
|
+
controller when it cannot start, and each unmapped address is logged once.
|
|
42
|
+
- Data block layouts are validated at startup, and every violation is reported.
|
|
43
|
+
- The upward server and the data layer come from the modbus-emulator 0.4.0 and
|
|
44
|
+
layout-data 0.10.1 packages; es-modbus is 0.3.2. Errors of change handlers
|
|
45
|
+
are logged under their block.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- The pressure interlock never fired: `press_alarm_F` was read from the wrong
|
|
50
|
+
object.
|
|
51
|
+
- Stopping a driver did not close its connection.
|
|
52
|
+
- Each actuator counts its own unanswered commands; the count was shared by all
|
|
53
|
+
actuators, so commands were not sent again as intended.
|
|
54
|
+
- `SInt` values were stored wrongly, and repeated `NaN` writes emitted change
|
|
55
|
+
events.
|
|
56
|
+
|
|
57
|
+
## v0.6.0 - 2026-11-22 (中文)
|
|
58
|
+
|
|
59
|
+
### 破坏性变更
|
|
60
|
+
|
|
61
|
+
- 移除项目内的模拟器:`emu` 包导出和 `tlms emu` 子命令已删除,改用独立的
|
|
62
|
+
modbus-emulator 包。
|
|
63
|
+
- 对上寄存器表:SECTION 改为 20 个寄存器(删除 `inner_word`);删除段的旁路,其字保留为
|
|
64
|
+
`upward_input`。线的旁路和段的手动挂起(`hangon_MF`)改名为 `flow_override`。驼峰命名的
|
|
65
|
+
标签改为 snake_case(`auto_stop_cmd` / `man_stop_cmd`、`flow1_k_factor`..`flow5_k_factor`),
|
|
66
|
+
偏移不变。HMI 须同步这些名称。
|
|
67
|
+
- 控制器、线、段、执行器的名称必须是标识符(ASCII 字母、数字和 `_`,不以数字开头),否则控制器启动时
|
|
68
|
+
退出。执行器的命令块改名为 `<执行器名>_command`。
|
|
69
|
+
- 每个执行器按配置的 `supported_commands` 屏蔽命令,不再用所有执行器共用的固定屏蔽字。省略该字段时
|
|
70
|
+
支持全部命令,原先被屏蔽的命令(`cancel_stop`、`horn` 等)现在会发出:请为缺少某些命令的执行器
|
|
71
|
+
列出其支持的命令。
|
|
72
|
+
- 配置文件按 YAML 1.2 解析(不再支持合并键),只读取工作目录的顶层。
|
|
73
|
+
|
|
74
|
+
### 变更
|
|
75
|
+
|
|
76
|
+
- 控制器按扫描运行:每个主周期(500 ms),以及设备数据、HMI 写入或连接状态到达后立即,按依赖顺序在
|
|
77
|
+
同一组输入上求值全部规则。汇总不再防抖,条件消失的流量延时和倒计时立即复位,命令在同一次扫描中发出。
|
|
78
|
+
- 线的 `flow_override` 是其全部段流量差保护的总开关,不改写各段自己的 `flow_override`。
|
|
79
|
+
- 联锁:流量预停泵提示改用线的 `pump_run`,没有本段泵的泄漏段也能覆盖;压力联锁只由允许它的执行器
|
|
80
|
+
触发(`pressure_AH_F && pressure_SD_F`);压力动作和流量动作分别置位、复位和记录。
|
|
81
|
+
- 控制器启动时把对上服务的完整描述写入 `<控制器名>/emulator.yaml`。对上服务无法启动时控制器退出,
|
|
82
|
+
每个未映射的地址只记录一次。
|
|
83
|
+
- 启动时校验数据块布局,报告全部违规。
|
|
84
|
+
- 对上服务和数据层改用 modbus-emulator 0.4.0 和 layout-data 0.10.1 包,es-modbus 为 0.3.2。
|
|
85
|
+
变化事件处理器的异常按其数据块记入日志。
|
|
86
|
+
|
|
87
|
+
### 修复
|
|
88
|
+
|
|
89
|
+
- 压力联锁从不触发:`press_alarm_F` 读错了对象。
|
|
90
|
+
- 停止驱动时没有关闭连接。
|
|
91
|
+
- 每个执行器单独计数未应答的命令;原先所有执行器共用一个计数,命令不能按预期重发。
|
|
92
|
+
- `SInt` 值存储错误;重复写入 `NaN` 时发出变化事件。
|
|
93
|
+
|
|
94
|
+
## v0.5.2 - 2026-11-14
|
|
95
|
+
|
|
96
|
+
It covers v0.5.1, which was never released on its own.
|
|
97
|
+
|
|
98
|
+
### Changed
|
|
99
|
+
|
|
100
|
+
- The pressure warning and pressure alarm of a section now take every node of the
|
|
101
|
+
section into account, not only its begin nodes. A pressure alarm stops the pumps
|
|
102
|
+
of its own section only.
|
|
103
|
+
- Communication delay protection: nodes and sections have a `delay_protect` flag,
|
|
104
|
+
the command block gains `delay_protect_time` (its former flow fields become
|
|
105
|
+
reserved), and communication state updates are debounced. The command block
|
|
106
|
+
layout changes accordingly.
|
|
107
|
+
- The typed data layer is split into `TData`, `TTag` and `TGroup`, and the data
|
|
108
|
+
structures of lines, sections, nodes, commands and the action record are
|
|
109
|
+
generated from shared definitions.
|
|
110
|
+
|
|
111
|
+
### Fixed
|
|
112
|
+
|
|
113
|
+
- Driver read and write errors no longer abort the program; a single read error no
|
|
114
|
+
longer resets `work_OK` immediately.
|
|
115
|
+
- Tag change event handling is reworked, and an emulator bug is fixed.
|
|
116
|
+
|
|
117
|
+
## v0.5.2 - 2026-11-14 (中文)
|
|
118
|
+
|
|
119
|
+
包含未单独发布的 v0.5.1 的内容。
|
|
120
|
+
|
|
121
|
+
### 变更
|
|
122
|
+
|
|
123
|
+
- 区段的压力预警和压力报警改为考虑区段内所有节点,而不仅是起始节点;压力报警只停本区段的泵。
|
|
124
|
+
- 通信延时保护:节点和区段增加 `delay_protect` 标志,命令块增加 `delay_protect_time`(原流量字段改为保留),通信状态更新加了防抖。命令块布局随之改变。
|
|
125
|
+
- 类型化数据层拆分为 `TData`、`TTag` 和 `TGroup`,管线、区段、节点、命令和动作记录的数据结构改由共享定义生成。
|
|
126
|
+
|
|
127
|
+
### 修复
|
|
128
|
+
|
|
129
|
+
- 驱动读写出错不再使程序异常中断;单次读取错误不再立即复位 `work_OK`。
|
|
130
|
+
- 重构标签值变化事件的处理,并修复一个模拟器缺陷。
|
|
131
|
+
|
|
132
|
+
## 2026-11-14
|
|
133
|
+
|
|
134
|
+
Versions before v0.5.2 were never tagged, and only v0.1.0 was formally released.
|
|
135
|
+
Their entries below are short summaries, one per minor series, kept for reference.
|
|
136
|
+
|
|
137
|
+
v0.5.2 之前的版本从未打标签,只正式发布过 V0.1.0,下面只按次版本系列简要记录,供参考。
|
|
138
|
+
|
|
139
|
+
## v0.5.0
|
|
140
|
+
|
|
141
|
+
- Drivers support the `LEBS` and `BEBS` device byte orders.
|
|
142
|
+
|
|
143
|
+
## v0.5.0 (中文)
|
|
144
|
+
|
|
145
|
+
- 驱动支持 `LEBS` 和 `BEBS` 设备字节序。
|
|
146
|
+
|
|
147
|
+
## v0.4.3
|
|
148
|
+
|
|
149
|
+
Covers v0.4.0 to v0.4.3.
|
|
150
|
+
|
|
151
|
+
- Section, line and node processing is reworked: a stop command goes only to
|
|
152
|
+
running pumps, and the pressure and flow actions of the action record are no
|
|
153
|
+
longer swapped.
|
|
154
|
+
- CLI: the default subcommand is `help`; the pm2 process is always named
|
|
155
|
+
`tlms_esd`, and `tlms start` removes the previous instance first.
|
|
156
|
+
- Fixed an error when the controller name is omitted.
|
|
157
|
+
|
|
158
|
+
## v0.4.3 (中文)
|
|
159
|
+
|
|
160
|
+
包含 v0.4.0 至 v0.4.3。
|
|
161
|
+
|
|
162
|
+
- 重构区段、管线和节点的处理:停泵命令只发给运行中的泵;动作记录中的压力动作和流量动作不再颠倒。
|
|
163
|
+
- CLI:默认子命令改为 `help`;pm2 进程名固定为 `tlms_esd`,`tlms start` 会先删除上一个实例。
|
|
164
|
+
- 修复省略控制器名称时的错误。
|
|
165
|
+
|
|
166
|
+
## v0.3.1
|
|
167
|
+
|
|
168
|
+
Covers v0.3.0 to v0.3.1.
|
|
169
|
+
|
|
170
|
+
- The Modbus TCP driver uses the `es-modbus` package; the driver API changes.
|
|
171
|
+
- Logging moves from winston to log4js behind a wrapping logger.
|
|
172
|
+
|
|
173
|
+
## v0.3.1 (中文)
|
|
174
|
+
|
|
175
|
+
包含 v0.3.0 至 v0.3.1。
|
|
176
|
+
|
|
177
|
+
- Modbus TCP 驱动改用 `es-modbus` 包,驱动 API 随之改变。
|
|
178
|
+
- 日志由 winston 改为 log4js,并做了封装。
|
|
179
|
+
|
|
180
|
+
## v0.2.4
|
|
181
|
+
|
|
182
|
+
Covers v0.2.0 to v0.2.4.
|
|
183
|
+
|
|
184
|
+
- Action record of pump-stop actions, and logging of controller and section actions.
|
|
185
|
+
- Modbus TCP driver API refactored; a workaround for an S7 endpoint bug.
|
|
186
|
+
|
|
187
|
+
## v0.2.4 (中文)
|
|
188
|
+
|
|
189
|
+
包含 v0.2.0 至 v0.2.4。
|
|
190
|
+
|
|
191
|
+
- 增加停泵动作记录,以及控制器和区段动作的日志。
|
|
192
|
+
- 重构 Modbus TCP 驱动 API;规避 S7 端点的一个缺陷。
|
package/cli.js
CHANGED
|
@@ -1,280 +1,202 @@
|
|
|
1
|
-
import { exec } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function mri (args, opts) {
|
|
19
|
-
args = args || [];
|
|
20
|
-
opts = opts || {};
|
|
21
|
-
|
|
22
|
-
var k, arr, arg, name, val, out={ _:[] };
|
|
23
|
-
var i=0, j=0, idx=0, len=args.length;
|
|
24
|
-
|
|
25
|
-
const alibi = opts.alias !== void 0;
|
|
26
|
-
const strict = opts.unknown !== void 0;
|
|
27
|
-
const defaults = opts.default !== void 0;
|
|
28
|
-
|
|
29
|
-
opts.alias = opts.alias || {};
|
|
30
|
-
opts.string = toArr(opts.string);
|
|
31
|
-
opts.boolean = toArr(opts.boolean);
|
|
32
|
-
|
|
33
|
-
if (alibi) {
|
|
34
|
-
for (k in opts.alias) {
|
|
35
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
36
|
-
for (i=0; i < arr.length; i++) {
|
|
37
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
// \0rolldown/runtime.js
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
40
18
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
// node_modules/.pnpm/mri@1.2.0/node_modules/mri/lib/index.js
|
|
26
|
+
var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
27
|
+
function toArr(any) {
|
|
28
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
45
29
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
30
|
+
function toVal(out, key, val, opts) {
|
|
31
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
32
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
50
33
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
module.exports = function(args, opts) {
|
|
35
|
+
args = args || [];
|
|
36
|
+
opts = opts || {};
|
|
37
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
38
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
39
|
+
const alibi = opts.alias !== void 0;
|
|
40
|
+
const strict = opts.unknown !== void 0;
|
|
41
|
+
const defaults = opts.default !== void 0;
|
|
42
|
+
opts.alias = opts.alias || {};
|
|
43
|
+
opts.string = toArr(opts.string);
|
|
44
|
+
opts.boolean = toArr(opts.boolean);
|
|
45
|
+
if (alibi) for (k in opts.alias) {
|
|
46
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
47
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
48
|
+
}
|
|
49
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
50
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
51
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
52
|
+
}
|
|
53
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
54
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
55
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
56
|
+
}
|
|
57
|
+
if (defaults) for (k in opts.default) {
|
|
54
58
|
name = typeof opts.default[k];
|
|
55
59
|
arr = opts.alias[k] = opts.alias[k] || [];
|
|
56
60
|
if (opts[name] !== void 0) {
|
|
57
61
|
opts[name].push(k);
|
|
58
|
-
for (i=0; i < arr.length; i++)
|
|
59
|
-
opts[name].push(arr[i]);
|
|
60
|
-
}
|
|
62
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (arg === '--') {
|
|
71
|
-
out._ = out._.concat(args.slice(++i));
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for (j=0; j < arg.length; j++) {
|
|
76
|
-
if (arg.charCodeAt(j) !== 45) break; // "-"
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (j === 0) {
|
|
80
|
-
out._.push(arg);
|
|
81
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
|
82
|
-
name = arg.substring(j + 3);
|
|
83
|
-
if (strict && !~keys.indexOf(name)) {
|
|
84
|
-
return opts.unknown(arg);
|
|
85
|
-
}
|
|
86
|
-
out[name] = false;
|
|
87
|
-
} else {
|
|
88
|
-
for (idx=j+1; idx < arg.length; idx++) {
|
|
89
|
-
if (arg.charCodeAt(idx) === 61) break; // "="
|
|
65
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
66
|
+
for (i = 0; i < len; i++) {
|
|
67
|
+
arg = args[i];
|
|
68
|
+
if (arg === "--") {
|
|
69
|
+
out._ = out._.concat(args.slice(++i));
|
|
70
|
+
break;
|
|
90
71
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
73
|
+
if (j === 0) out._.push(arg);
|
|
74
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
75
|
+
name = arg.substring(j + 3);
|
|
76
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
77
|
+
out[name] = false;
|
|
78
|
+
} else {
|
|
79
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
80
|
+
name = arg.substring(j, idx);
|
|
81
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
82
|
+
arr = j === 2 ? [name] : name;
|
|
83
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
84
|
+
name = arr[idx];
|
|
85
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
86
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
87
|
+
}
|
|
100
88
|
}
|
|
101
89
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (defaults) {
|
|
105
|
-
for (k in opts.default) {
|
|
106
|
-
if (out[k] === void 0) {
|
|
107
|
-
out[k] = opts.default[k];
|
|
108
|
-
}
|
|
90
|
+
if (defaults) {
|
|
91
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
109
92
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (alibi) {
|
|
113
|
-
for (k in out) {
|
|
93
|
+
if (alibi) for (k in out) {
|
|
114
94
|
arr = opts.alias[k] || [];
|
|
115
|
-
while (arr.length > 0)
|
|
116
|
-
out[arr.shift()] = out[k];
|
|
117
|
-
}
|
|
95
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
118
96
|
}
|
|
97
|
+
return out;
|
|
98
|
+
};
|
|
99
|
+
}));
|
|
100
|
+
// package.json
|
|
101
|
+
var version$1 = "0.6.0";
|
|
102
|
+
const argv = (0, (/* @__PURE__ */ __toESM(require_lib(), 1)).default)(process.argv.slice(2), {
|
|
103
|
+
boolean: ["help", "version"],
|
|
104
|
+
alias: {
|
|
105
|
+
help: ["H", "h"],
|
|
106
|
+
version: ["V", "v"],
|
|
107
|
+
path: "P"
|
|
119
108
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
license: license,
|
|
191
|
-
packageManager: packageManager
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const argv = mri(process.argv.slice(2), {
|
|
195
|
-
boolean: ['help', 'version'],
|
|
196
|
-
alias: {
|
|
197
|
-
H: 'help',
|
|
198
|
-
V: 'version',
|
|
199
|
-
P: 'path',
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
const [cmd = 'start', controller_name = 0] = argv._;
|
|
203
|
-
const acturator_names = argv._.slice(1);
|
|
204
|
-
|
|
205
|
-
const _path = argv.path ?? '.';
|
|
206
|
-
process.chdir(_path);
|
|
207
|
-
const work_path = process.cwd();
|
|
208
|
-
const module_path = import.meta.dirname;
|
|
209
|
-
const version = pkg.version;
|
|
210
|
-
|
|
211
|
-
function show_help() {
|
|
212
|
-
console.log(`usage:
|
|
213
|
-
|
|
214
|
-
tlms [subcommand] [controller_name or acturator_name_list] [options]
|
|
215
|
-
|
|
216
|
-
subcommand 子命令:
|
|
217
|
-
help 打印本帮助
|
|
218
|
-
start 以当前目录下的配置文件运行TLMS,这是默认子命令
|
|
219
|
-
stop 结束当前目录配置文件所在的TLMS
|
|
220
|
-
list 显示有多少个pm2托管的进程,包括TLMS实例
|
|
221
|
-
debug 以当前目录下的配置文件运行TLMS,但不压入后台,用于调试
|
|
222
|
-
emu 启动一个临时的管道节点仿真器用来测试
|
|
223
|
-
log 显示日志
|
|
224
|
-
flush 清空log
|
|
225
|
-
|
|
226
|
-
controller_name or acturator_name_list:
|
|
227
|
-
控制器名称或序号,或者是执行器名称列表。
|
|
228
|
-
默认为 "0",即在配置文件的第一个控制器。
|
|
229
|
-
控制器只能有一个名称,用于 start stop 子命令后。
|
|
230
|
-
执行器可以是多个名称,用空格分开,用于 emu 子命令后。
|
|
231
|
-
|
|
232
|
-
options:
|
|
233
|
-
--version | -V | -v 显示版本号,会忽略任何 subcommand 子命令
|
|
234
|
-
--help | -H 打印本帮助,会忽略任何 subcommand 子命令
|
|
235
|
-
--path | -P 指示配置文件所在的目录,默认为 "."
|
|
236
|
-
|
|
237
|
-
例子:
|
|
238
|
-
tlms 以当前目录下的配置文件运行
|
|
239
|
-
tlms start ./conf 以 ./conf 目录下的配置文件运行
|
|
240
|
-
tlms stop 停止
|
|
241
|
-
tlms emu GD8 YA1 YA1 DY8 启动指定4个节点的仿真器
|
|
242
|
-
`);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (argv.version) {
|
|
246
|
-
console.log(`V${version}`);
|
|
247
|
-
} else if (argv.help) {
|
|
248
|
-
show_help();
|
|
249
|
-
} else if (cmd === 'start') {
|
|
250
|
-
exec(
|
|
251
|
-
`pm2 start --name="tlms-${basename(work_path)}" "${join(module_path, 'main.js')}" -- ${controller_name}`,
|
|
252
|
-
{ cwd: work_path }
|
|
253
|
-
);
|
|
254
|
-
} else if (cmd === 'stop') {
|
|
255
|
-
exec(
|
|
256
|
-
`pm2 delete "tlms-${basename(work_path)}"`,
|
|
257
|
-
{ cwd: work_path }
|
|
258
|
-
);
|
|
259
|
-
} else if (cmd === 'list') {
|
|
260
|
-
exec(`pm2 list`, (error, stdout, _) => {
|
|
261
|
-
if (error) {
|
|
262
|
-
console.error(`exec error: ${error}`);
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
console.log(stdout);
|
|
266
|
-
});
|
|
267
|
-
} else if (cmd === 'debug') {
|
|
268
|
-
process.argv[2] = controller_name;
|
|
269
|
-
import('./main.js');
|
|
270
|
-
} else if (cmd === 'emu') {
|
|
271
|
-
console.log(acturator_names); // @debug
|
|
272
|
-
process.argv = [process.argv[0], process.argv[1], ...acturator_names];
|
|
273
|
-
import('./emulator.js');
|
|
274
|
-
} else if (cmd === 'log') {
|
|
275
|
-
exec(`pm2 log`);
|
|
276
|
-
} else if (cmd === 'flush') {
|
|
277
|
-
exec(`pm2 flush`);
|
|
278
|
-
} else {
|
|
279
|
-
show_help();
|
|
109
|
+
});
|
|
110
|
+
const [cmd = "help", controller_name = ""] = argv._;
|
|
111
|
+
const _path = argv.path ?? ".";
|
|
112
|
+
process.chdir(_path);
|
|
113
|
+
const work_path = process.cwd();
|
|
114
|
+
const module_path = import.meta.dirname;
|
|
115
|
+
const version = version$1;
|
|
116
|
+
function show_help() {
|
|
117
|
+
console.log(`usage:
|
|
118
|
+
|
|
119
|
+
tlms [subcommand] [controller_name] [options]
|
|
120
|
+
|
|
121
|
+
subcommand:
|
|
122
|
+
help Print this help message, this is the default subcommand
|
|
123
|
+
start Run TLMS with the configuration file in the specified directory,
|
|
124
|
+
terminating any previous TLMS instance before starting
|
|
125
|
+
restart Alias for 'start', add this subcommand to reflect the literal meaning of restart
|
|
126
|
+
stop Terminate the running TLMS instance
|
|
127
|
+
list Display the number of pm2-managed processes, including TLMS instances
|
|
128
|
+
debug Run TLMS with the configuration file in the specified directory,
|
|
129
|
+
but without pushing it to the background, used for debugging
|
|
130
|
+
flush Clear logs
|
|
131
|
+
|
|
132
|
+
controller_name:
|
|
133
|
+
Controller name or index.
|
|
134
|
+
Default is "0", i.e., the first controller in the configuration file.
|
|
135
|
+
Only one controller name can be specified, used after the 'start' or 'stop' subcommands.
|
|
136
|
+
|
|
137
|
+
options:
|
|
138
|
+
--version | -V | -v Display version number, ignores any subcommand
|
|
139
|
+
--help | -H | -h Print this help message, ignores any subcommand
|
|
140
|
+
--path | -P Specify the directory containing the configuration file, default is "."
|
|
141
|
+
|
|
142
|
+
Examples:
|
|
143
|
+
tlms start Run the first controller with the configuration file in the current directory
|
|
144
|
+
tlms start TC Run the TC controller with the configuration file in the current directory
|
|
145
|
+
tlms start --path ./conf Run using the configuration file in the ./conf directory
|
|
146
|
+
tlms start TC --path ./conf Specify both the controller name and configuration file path
|
|
147
|
+
tlms stop Stop
|
|
148
|
+
|
|
149
|
+
用法:
|
|
150
|
+
|
|
151
|
+
tlms [subcommand] [controller_name] [options]
|
|
152
|
+
|
|
153
|
+
subcommand 子命令:
|
|
154
|
+
help 打印本帮助,这是默认子命令
|
|
155
|
+
start 以指定目录下的配置文件运行TLMS,启动前会先中止上一个TLMS实例。
|
|
156
|
+
restart start 的别名,增加这个别名是为了体现重启的字面含义。
|
|
157
|
+
stop 结束正在运行的TLMS实例
|
|
158
|
+
list 显示有多少个pm2托管的进程,包括TLMS实例
|
|
159
|
+
debug 以指定目录下的配置文件运行TLMS,但不压入后台,用于调试
|
|
160
|
+
flush 清空log
|
|
161
|
+
|
|
162
|
+
controller_name:
|
|
163
|
+
控制器名称或序号。
|
|
164
|
+
默认为 "0",即在配置文件的第一个控制器。
|
|
165
|
+
控制器只能有一个名称,用于 start stop 子命令后。
|
|
166
|
+
|
|
167
|
+
options:
|
|
168
|
+
--version | -V | -v 显示版本号,会忽略任何 subcommand 子命令
|
|
169
|
+
--help | -H | -h 打印本帮助,会忽略任何 subcommand 子命令
|
|
170
|
+
--path | -P 指示配置文件所在的目录,默认为 "."
|
|
171
|
+
|
|
172
|
+
例子:
|
|
173
|
+
tlms start 以当前目录下的配置文件运行第1个控制器
|
|
174
|
+
tlms start TC 以当前目录下的配置文件运行 TC 控制器
|
|
175
|
+
tlms start --path ./conf 以 ./conf 目录下的配置文件运行
|
|
176
|
+
tlms start TC --path ./conf 同时指定控制器名称和配置文件路径
|
|
177
|
+
tlms stop 停止
|
|
178
|
+
`);
|
|
280
179
|
}
|
|
180
|
+
if (argv.version) console.log(`V${version}`);
|
|
181
|
+
else if (argv.help) show_help();
|
|
182
|
+
else if (cmd === "start" || cmd === "restart") {
|
|
183
|
+
process.env.TLMS = "controller";
|
|
184
|
+
const main_js = join(module_path, "main.js").replace(/\\/g, "/");
|
|
185
|
+
const main_para = controller_name ? `-- ${controller_name}` : "";
|
|
186
|
+
exec("pm2 delete \"tlms_esd\"", () => exec(`pm2 start --name="tlms_esd" "${main_js}" ${main_para}`, { cwd: work_path }));
|
|
187
|
+
} else if (cmd === "stop") exec("pm2 delete \"tlms_esd\"");
|
|
188
|
+
else if (cmd === "list") exec("pm2 list", (error, stdout, _) => {
|
|
189
|
+
if (error) {
|
|
190
|
+
console.error(`exec error: ${error}`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
console.log(stdout);
|
|
194
|
+
});
|
|
195
|
+
else if (cmd === "debug") {
|
|
196
|
+
process.argv[2] = controller_name;
|
|
197
|
+
process.env.LOG_LEVEL = "debug";
|
|
198
|
+
import("./main.js");
|
|
199
|
+
} else if (cmd === "log") exec("pm2 log");
|
|
200
|
+
else if (cmd === "flush") exec("pm2 flush");
|
|
201
|
+
else show_help();
|
|
202
|
+
export {};
|