@zimo-elektronik/zcan 1.0.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 (202) hide show
  1. package/.dockerignore +7 -0
  2. package/.editorconfig +15 -0
  3. package/.eslintignore +7 -0
  4. package/.eslintrc.cjs +17 -0
  5. package/.gitattributes +1 -0
  6. package/.github/workflows/docs.yml +46 -0
  7. package/.github/workflows/library.yml +59 -0
  8. package/.nvmrc +1 -0
  9. package/.prettierignore +14 -0
  10. package/.prettierrc.json +8 -0
  11. package/LICENSE.md +21 -0
  12. package/README.md +8 -0
  13. package/__tests__/connection.test.ts +58 -0
  14. package/__tests__/dataGroup.test.ts +98 -0
  15. package/__tests__/infoGroup.test.ts +30 -0
  16. package/__tests__/lanDataGroup.test.ts +82 -0
  17. package/__tests__/lanInfoGroup.test.ts +41 -0
  18. package/__tests__/systemControlGroup.test.ts +42 -0
  19. package/__tests__/trackCfgGroup.test.ts +43 -0
  20. package/__tests__/util/index.ts +14 -0
  21. package/__tests__/vehicleGroup.test.ts +128 -0
  22. package/dist/@types/communication.d.ts +30 -0
  23. package/dist/@types/communication.js +2 -0
  24. package/dist/@types/communication.js.map +1 -0
  25. package/dist/@types/models.d.ts +172 -0
  26. package/dist/@types/models.js +2 -0
  27. package/dist/@types/models.js.map +1 -0
  28. package/dist/MX10.d.ts +45 -0
  29. package/dist/MX10.js +233 -0
  30. package/dist/MX10.js.map +1 -0
  31. package/dist/docs_entrypoint.d.ts +6 -0
  32. package/dist/docs_entrypoint.js +7 -0
  33. package/dist/docs_entrypoint.js.map +1 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.js +7 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/internal/bites.d.ts +9 -0
  38. package/dist/internal/bites.js +10 -0
  39. package/dist/internal/bites.js.map +1 -0
  40. package/dist/internal/speedUtils.d.ts +9 -0
  41. package/dist/internal/speedUtils.js +29 -0
  42. package/dist/internal/speedUtils.js.map +1 -0
  43. package/dist/internal/utils.d.ts +1 -0
  44. package/dist/internal/utils.js +4 -0
  45. package/dist/internal/utils.js.map +1 -0
  46. package/dist/util/enums.d.ts +113 -0
  47. package/dist/util/enums.js +137 -0
  48. package/dist/util/enums.js.map +1 -0
  49. package/dist/util/extended-ascii.d.ts +7 -0
  50. package/dist/util/extended-ascii.js +162 -0
  51. package/dist/util/extended-ascii.js.map +1 -0
  52. package/dist/zcan/accessoryCommandGroup.d.ts +6 -0
  53. package/dist/zcan/accessoryCommandGroup.js +9 -0
  54. package/dist/zcan/accessoryCommandGroup.js.map +1 -0
  55. package/dist/zcan/dataGroup.d.ts +31 -0
  56. package/dist/zcan/dataGroup.js +233 -0
  57. package/dist/zcan/dataGroup.js.map +1 -0
  58. package/dist/zcan/fileControlGroup.d.ts +7 -0
  59. package/dist/zcan/fileControlGroup.js +9 -0
  60. package/dist/zcan/fileControlGroup.js.map +1 -0
  61. package/dist/zcan/fileTransferGroup.d.ts +7 -0
  62. package/dist/zcan/fileTransferGroup.js +9 -0
  63. package/dist/zcan/fileTransferGroup.js.map +1 -0
  64. package/dist/zcan/index.d.ts +18 -0
  65. package/dist/zcan/index.js +19 -0
  66. package/dist/zcan/index.js.map +1 -0
  67. package/dist/zcan/infoGroup.d.ts +15 -0
  68. package/dist/zcan/infoGroup.js +64 -0
  69. package/dist/zcan/infoGroup.js.map +1 -0
  70. package/dist/zcan/lanDataGroup.d.ts +23 -0
  71. package/dist/zcan/lanDataGroup.js +226 -0
  72. package/dist/zcan/lanDataGroup.js.map +1 -0
  73. package/dist/zcan/lanInfoGroup.d.ts +11 -0
  74. package/dist/zcan/lanInfoGroup.js +58 -0
  75. package/dist/zcan/lanInfoGroup.js.map +1 -0
  76. package/dist/zcan/lanNetworkGroup.d.ts +11 -0
  77. package/dist/zcan/lanNetworkGroup.js +37 -0
  78. package/dist/zcan/lanNetworkGroup.js.map +1 -0
  79. package/dist/zcan/lanZimoProgrammableScriptGroup.d.ts +7 -0
  80. package/dist/zcan/lanZimoProgrammableScriptGroup.js +9 -0
  81. package/dist/zcan/lanZimoProgrammableScriptGroup.js.map +1 -0
  82. package/dist/zcan/networkGroup.d.ts +10 -0
  83. package/dist/zcan/networkGroup.js +38 -0
  84. package/dist/zcan/networkGroup.js.map +1 -0
  85. package/dist/zcan/propertyConfigGroup.d.ts +7 -0
  86. package/dist/zcan/propertyConfigGroup.js +9 -0
  87. package/dist/zcan/propertyConfigGroup.js.map +1 -0
  88. package/dist/zcan/railwayControlGroup.d.ts +7 -0
  89. package/dist/zcan/railwayControlGroup.js +9 -0
  90. package/dist/zcan/railwayControlGroup.js.map +1 -0
  91. package/dist/zcan/systemControlGroup.d.ts +13 -0
  92. package/dist/zcan/systemControlGroup.js +35 -0
  93. package/dist/zcan/systemControlGroup.js.map +1 -0
  94. package/dist/zcan/trackCfgGroup.d.ts +16 -0
  95. package/dist/zcan/trackCfgGroup.js +77 -0
  96. package/dist/zcan/trackCfgGroup.js.map +1 -0
  97. package/dist/zcan/trainControlGroup.d.ts +8 -0
  98. package/dist/zcan/trainControlGroup.js +19 -0
  99. package/dist/zcan/trainControlGroup.js.map +1 -0
  100. package/dist/zcan/vehicleGroup.d.ts +26 -0
  101. package/dist/zcan/vehicleGroup.js +145 -0
  102. package/dist/zcan/vehicleGroup.js.map +1 -0
  103. package/dist/zcan/zimoProgrammableScriptGroup.d.ts +7 -0
  104. package/dist/zcan/zimoProgrammableScriptGroup.js +9 -0
  105. package/dist/zcan/zimoProgrammableScriptGroup.js.map +1 -0
  106. package/gulpfile.js +37 -0
  107. package/jest.config.js +26 -0
  108. package/package.json +50 -0
  109. package/protocol_docs/README.md +41 -0
  110. package/protocol_docs/babel.config.js +3 -0
  111. package/protocol_docs/docs/command-groups/_category_.json +4 -0
  112. package/protocol_docs/docs/command-groups/accessories/_category_.json +4 -0
  113. package/protocol_docs/docs/command-groups/accessories/accessory-state.md +7 -0
  114. package/protocol_docs/docs/command-groups/command-groups.md +50 -0
  115. package/protocol_docs/docs/command-groups/data/_category_.json +4 -0
  116. package/protocol_docs/docs/command-groups/data/data-name-extended.md +60 -0
  117. package/protocol_docs/docs/command-groups/data/group-count.md +52 -0
  118. package/protocol_docs/docs/command-groups/data/item-fx-info.md +27 -0
  119. package/protocol_docs/docs/command-groups/data/item-image-config.md +44 -0
  120. package/protocol_docs/docs/command-groups/data/item-list-by-index.md +45 -0
  121. package/protocol_docs/docs/command-groups/data/item-list-by-nid.md +43 -0
  122. package/protocol_docs/docs/command-groups/data/remove-train.md +33 -0
  123. package/protocol_docs/docs/command-groups/info/_category_.json +4 -0
  124. package/protocol_docs/docs/command-groups/info/bidi-info.md +34 -0
  125. package/protocol_docs/docs/command-groups/lan-data/_category_.json +4 -0
  126. package/protocol_docs/docs/command-groups/lan-data/data-value-extended.md +65 -0
  127. package/protocol_docs/docs/command-groups/lan-data/loco-gui-extended.md +48 -0
  128. package/protocol_docs/docs/command-groups/lan-info/_category_.json +4 -0
  129. package/protocol_docs/docs/command-groups/lan-info/module-power-info.md +26 -0
  130. package/protocol_docs/docs/command-groups/lan-network/_category_.json +4 -0
  131. package/protocol_docs/docs/command-groups/lan-network/open-port.md +47 -0
  132. package/protocol_docs/docs/command-groups/network/_category_.json +4 -0
  133. package/protocol_docs/docs/command-groups/network/ping.md +49 -0
  134. package/protocol_docs/docs/command-groups/system/_category_.json +4 -0
  135. package/protocol_docs/docs/command-groups/system/system-state.md +59 -0
  136. package/protocol_docs/docs/command-groups/track/_category_.json +4 -0
  137. package/protocol_docs/docs/command-groups/track/tse-prog-read.md +37 -0
  138. package/protocol_docs/docs/command-groups/track/tse-prog-write.md +35 -0
  139. package/protocol_docs/docs/command-groups/train/_category_.json +4 -0
  140. package/protocol_docs/docs/command-groups/train/train-part-find.md +33 -0
  141. package/protocol_docs/docs/command-groups/vehicles/_category_.json +4 -0
  142. package/protocol_docs/docs/command-groups/vehicles/vehicle-function.md +36 -0
  143. package/protocol_docs/docs/command-groups/vehicles/vehicle-mode.md +143 -0
  144. package/protocol_docs/docs/command-groups/vehicles/vehicle-special-function-switch.md +35 -0
  145. package/protocol_docs/docs/command-groups/vehicles/vehicle-speed.md +55 -0
  146. package/protocol_docs/docs/description.md +4 -0
  147. package/protocol_docs/docs/introduction/_category_.json +4 -0
  148. package/protocol_docs/docs/introduction/how-it-works.md +61 -0
  149. package/protocol_docs/docs/introduction/implementation.md +39 -0
  150. package/protocol_docs/docs/introduction/interface.md +62 -0
  151. package/protocol_docs/docs/introduction/introduction.md +82 -0
  152. package/protocol_docs/docusaurus.config.js +111 -0
  153. package/protocol_docs/package-lock.json +25611 -0
  154. package/protocol_docs/package.json +47 -0
  155. package/protocol_docs/sidebars.js +22 -0
  156. package/protocol_docs/src/components/CommandAndGroup/index.tsx +16 -0
  157. package/protocol_docs/src/components/CommandAndGroup/styles.module.css +12 -0
  158. package/protocol_docs/src/components/HomepageFeatures/index.tsx +70 -0
  159. package/protocol_docs/src/components/HomepageFeatures/styles.module.css +11 -0
  160. package/protocol_docs/src/css/custom.css +76 -0
  161. package/protocol_docs/src/pages/index.module.css +23 -0
  162. package/protocol_docs/src/pages/index.tsx +41 -0
  163. package/protocol_docs/src/pages/markdown-page.md +7 -0
  164. package/protocol_docs/static/.nojekyll +0 -0
  165. package/protocol_docs/static/img/docusaurus.png +0 -0
  166. package/protocol_docs/static/img/favicon.ico +0 -0
  167. package/protocol_docs/static/img/undraw_docusaurus_mountain.svg +171 -0
  168. package/protocol_docs/static/img/undraw_docusaurus_react.svg +170 -0
  169. package/protocol_docs/static/img/undraw_docusaurus_tree.svg +40 -0
  170. package/protocol_docs/static/typedoc/index.html +10 -0
  171. package/protocol_docs/tsconfig.json +7 -0
  172. package/src/@types/communication.ts +73 -0
  173. package/src/@types/models.ts +215 -0
  174. package/src/MX10.ts +351 -0
  175. package/src/docs_entrypoint.ts +34 -0
  176. package/src/index.ts +8 -0
  177. package/src/internal/bites.ts +11 -0
  178. package/src/internal/speedUtils.ts +36 -0
  179. package/src/internal/utils.ts +3 -0
  180. package/src/util/enums.ts +147 -0
  181. package/src/util/extended-ascii.ts +179 -0
  182. package/src/zcan/accessoryCommandGroup.ts +24 -0
  183. package/src/zcan/dataGroup.ts +342 -0
  184. package/src/zcan/fileControlGroup.ts +25 -0
  185. package/src/zcan/fileTransferGroup.ts +25 -0
  186. package/src/zcan/index.ts +37 -0
  187. package/src/zcan/infoGroup.ts +90 -0
  188. package/src/zcan/lanDataGroup.ts +361 -0
  189. package/src/zcan/lanInfoGroup.ts +86 -0
  190. package/src/zcan/lanNetworkGroup.ts +70 -0
  191. package/src/zcan/lanZimoProgrammableScriptGroup.ts +25 -0
  192. package/src/zcan/networkGroup.ts +71 -0
  193. package/src/zcan/propertyConfigGroup.ts +25 -0
  194. package/src/zcan/railwayControlGroup.ts +25 -0
  195. package/src/zcan/systemControlGroup.ts +62 -0
  196. package/src/zcan/trackCfgGroup.ts +109 -0
  197. package/src/zcan/trainControlGroup.ts +48 -0
  198. package/src/zcan/vehicleGroup.ts +267 -0
  199. package/src/zcan/zimoProgrammableScriptGroup.ts +25 -0
  200. package/tsconfig.build.json +12 -0
  201. package/tsconfig.json +49 -0
  202. package/tsconfig.test.json +9 -0
package/.dockerignore ADDED
@@ -0,0 +1,7 @@
1
+ .vscode/
2
+ .git/
3
+ .idea/
4
+ dist/
5
+ node_modules
6
+ .docusaurus
7
+ build/
package/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
13
+
14
+ [Makefile]
15
+ indent_style = tab
package/.eslintignore ADDED
@@ -0,0 +1,7 @@
1
+ dist/
2
+ scripts/
3
+ cmd/
4
+ tools/
5
+ docs
6
+ protocol_docs
7
+ *.d.ts
package/.eslintrc.cjs ADDED
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint/eslint-plugin', 'import', 'eslint-plugin-tsdoc'],
5
+ extends: ['plugin:@typescript-eslint/recommended'],
6
+ env: {
7
+ jest: true,
8
+ node: true,
9
+ },
10
+ rules: {
11
+ 'no-console': 'error',
12
+ '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
13
+ '@typescript-eslint/no-dupe-class-members': ['error'],
14
+ '@typescript-eslint/no-useless-constructor': ['error'],
15
+ '@typescript-eslint/no-inferrable-types': ['off'],
16
+ },
17
+ }
package/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto
@@ -0,0 +1,46 @@
1
+ name: docs
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
8
+ permissions:
9
+ contents: read
10
+ pages: write
11
+ id-token: write
12
+
13
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
14
+ concurrency:
15
+ group: "pages"
16
+ cancel-in-progress: true
17
+
18
+ jobs:
19
+ deploy:
20
+ runs-on: ubuntu-latest
21
+
22
+ environment:
23
+ name: github-pages
24
+ url: ${{ steps.deployment.outputs.page_url }}
25
+
26
+ steps:
27
+ - uses: actions/checkout@v4.1.6
28
+ with:
29
+ fetch-depth: 0
30
+ - uses: actions/setup-node@v4
31
+ with:
32
+ node-version: '20.11.0'
33
+
34
+ - run: npm ci --ignore-scripts
35
+ - run: cd protocol_docs && npm ci --ignore-scripts
36
+ - run: npm run docs
37
+
38
+ - name: Setup Pages
39
+ uses: actions/configure-pages@v5
40
+ - name: Upload artifact
41
+ uses: actions/upload-pages-artifact@v3
42
+ with:
43
+ path: protocol_docs/build
44
+ - name: Deploy to GitHub Pages
45
+ id: deployment
46
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,59 @@
1
+ name: Publish Package to npmjs
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
8
+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
9
+ concurrency:
10
+ group: "library"
11
+ cancel-in-progress: false
12
+
13
+ jobs:
14
+ check:
15
+ runs-on: ubuntu-latest
16
+ outputs:
17
+ should_skip: ${{ steps.check.outputs.should_skip }}
18
+ steps:
19
+ - uses: actions/checkout@v4.1.6
20
+ with:
21
+ fetch-depth: 0
22
+ - id: check
23
+ run: echo "should_skip=no" >> $GITHUB_OUTPUT
24
+ # run: |
25
+ # PUBLISHED_VERSION=$(npm show @zimo-elektronik/zcan version)
26
+ # VERSION=$(npm pkg get version | tr -d '"')
27
+ #
28
+ # if [ "$PUBLISHED_VERSION" = "$VERSION" ];
29
+ # then
30
+ # echo "Version didn't change, skipping"
31
+ # echo "should_skip=yes" >> $GITHUB_OUTPUT
32
+ # else
33
+ # echo "should_skip=no" >> $GITHUB_OUTPUT
34
+ # fi
35
+
36
+
37
+ build:
38
+ runs-on: ubuntu-latest
39
+ needs:
40
+ - check
41
+ if: ${{needs.check.outputs.should_skip == 'no'}}
42
+ permissions:
43
+ contents: read
44
+ id-token: write
45
+
46
+ steps:
47
+ - uses: actions/checkout@v4.1.6
48
+ with:
49
+ fetch-depth: 0
50
+ - uses: actions/setup-node@v4
51
+ with:
52
+ node-version: '20.11.0'
53
+ registry-url: 'https://registry.npmjs.org'
54
+
55
+ - run: npm ci
56
+ - run: npm run build
57
+ - run: npm publish --provenance --access public
58
+ env:
59
+ NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v20.11.0
@@ -0,0 +1,14 @@
1
+ .github
2
+ .yarn
3
+ coverage
4
+ build
5
+ docs
6
+ dist
7
+ out
8
+ temp
9
+
10
+ *.yml
11
+ *.html
12
+ *.md
13
+ *.json
14
+ *.d.ts
@@ -0,0 +1,8 @@
1
+ {
2
+ "bracketSpacing": false,
3
+ "bracketSameLine": true,
4
+ "singleQuote": true,
5
+ "trailingComma": "all",
6
+ "endOfLine": "auto",
7
+ "tabWidth": 2
8
+ }
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ZIMO-Elektronik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # ZCAN js library
2
+
3
+ Project bootstrapped using [NodeJS Starter ToolKit](https://github.com/vitorsalgado/create-nodejs-ts).
4
+ Visit the repository for more details.
5
+
6
+ ## Getting Started
7
+
8
+ Review the generated code, and it's recommended to run a `npm init` to adjust basic project configurations before start.
@@ -0,0 +1,58 @@
1
+ import {createSocket} from "dgram";
2
+ import {afterAll, beforeAll, it, jest, describe, expect} from "@jest/globals";
3
+ import {createMX10, initConnection} from "./util";
4
+
5
+ describe('High level tests', () => {
6
+ const mx10 = createMX10(true);
7
+ const debug = global.console.debug;
8
+
9
+ afterEach(() => {
10
+ mx10.closeSocket()
11
+ })
12
+
13
+ beforeAll(() => {
14
+ global.console.debug = jest.fn();
15
+ })
16
+
17
+ afterAll(() => {
18
+ global.console.debug = debug;
19
+ })
20
+
21
+ it("Correct url test", async () => {
22
+ expect(mx10.connected).toBe(false);
23
+
24
+ return initConnection(mx10).then(() => {
25
+ expect(mx10.connected).toBe(true);
26
+
27
+ mx10.closeSocket();
28
+ expect(mx10.connected).toBe(false);
29
+ })
30
+ });
31
+
32
+ it("Incorrect url test", async () => {
33
+ expect(mx10.connected).toBe(false);
34
+ const res = mx10.initSocket(createSocket, "192.168.2.145");
35
+ await expect(res).rejects.toThrow('mx10.connection.timeout')
36
+
37
+ expect(mx10.connected).toBe(false);
38
+ });
39
+
40
+ it("Error logger test", (done) => {
41
+ mx10.errors.subscribe((error: string) => {
42
+ expect(error).toBe('mx10.connection.not_connected')
43
+ done();
44
+ })
45
+
46
+ mx10.network.ping();
47
+ })
48
+
49
+ it("Incorrect data format", () => {
50
+ expect(() => {
51
+ mx10.sendData(0x00, 0x00, [
52
+ {length: 1, value: 1,},
53
+ {length: 4, value: 1234,},
54
+ {length: 8, value: 0,}
55
+ ])
56
+ }).toThrow(/ELEMENT LENGTH NOT DEFINED.*/)
57
+ })
58
+ });
@@ -0,0 +1,98 @@
1
+ import {createMX10, initConnection} from './util';
2
+ import {afterAll, beforeAll, describe, expect, it} from '@jest/globals';
3
+ import {firstValueFrom} from 'rxjs';
4
+ import {FxInfoType, ImageType, NameType} from '../src';
5
+
6
+ describe('Data group tests - 0x07', () => {
7
+ const mx10 = createMX10(true);
8
+
9
+ beforeAll(async () => {
10
+ await initConnection(mx10);
11
+ });
12
+
13
+ afterAll(() => {
14
+ mx10.closeSocket();
15
+ });
16
+
17
+ it('0x00 - Group count test', (done) => {
18
+ mx10.data.groupCount();
19
+
20
+ const sub = mx10.data.onGroupCount.subscribe((data) => {
21
+ if (data.objectType === 0x0000) {
22
+ expect(data.objectType).toBe(0x000);
23
+ expect(data.number).toBeDefined();
24
+
25
+ done();
26
+ sub.unsubscribe();
27
+ }
28
+ });
29
+ });
30
+
31
+ it('0x01 - List item by index test', async () => {
32
+ mx10.data.listItemsByIndex(0x0000, 3);
33
+
34
+ const data = await firstValueFrom(mx10.data.onListItemsByIndex);
35
+
36
+ expect(data.index).toBe(3);
37
+ expect(data.nid).toBe(4);
38
+ });
39
+
40
+ it('0x02 - List item by nid test', async () => {
41
+ mx10.data.listItemsByNID(3);
42
+
43
+ const data = await firstValueFrom(mx10.data.onListItemsByNID);
44
+ expect(data.nid).toBe(65535);
45
+ expect(data.index).toBe(65535);
46
+ });
47
+
48
+ it('0x1f - Remove locomotive with nid', async () => {
49
+ mx10.data.removeLocomotive(3);
50
+
51
+ const data = await firstValueFrom(mx10.data.onRemoveLocomotive);
52
+ expect(data.nid).toBe(3);
53
+ expect(data.state).toBeDefined();
54
+ });
55
+
56
+ it('0x12 - Image config test', async () => {
57
+ const promise = firstValueFrom(mx10.data.onItemImageConfig).then((data) => {
58
+ expect(data.nid).toBe(3);
59
+ expect(data.type).toBe(ImageType.VEHICLE);
60
+ expect(data.imageId).toBe(6055);
61
+ });
62
+
63
+ mx10.data.itemImageConfig(3, ImageType.VEHICLE, 6055);
64
+
65
+ return promise;
66
+ });
67
+
68
+ test.each<{icon: number; fx: number}>([
69
+ {icon: 755, fx: 1},
70
+ {icon: 756, fx: 1},
71
+ {icon: 700, fx: 1},
72
+ ])('0x15 - Function image change test', async ({icon, fx}) => {
73
+ const promise = firstValueFrom(mx10.data.onItemFxInfo).then((data) => {
74
+ expect(data.nid).toBe(3);
75
+ expect(data.function).toBe(fx);
76
+ expect(data.type).toBe(FxInfoType.ICON);
77
+ expect(data.data).toBe(icon);
78
+ });
79
+
80
+ mx10.data.itemFxInfo(3, fx, FxInfoType.ICON, icon);
81
+
82
+ return promise;
83
+ });
84
+
85
+ test.each<{name: string}>([
86
+ {name: '---'},
87
+ {name: 'teßt Öf a näme'},
88
+ {name: 'dodo1'},
89
+ ])('0x21 - Data name extended test', async ({name}) => {
90
+ mx10.data.dataNameExtended(3, 0, name);
91
+
92
+ const data = await firstValueFrom(mx10.data.onDataNameExtended);
93
+ expect(data.nid).toBe(3);
94
+ expect(data.type).toBe(NameType.VEHICLE);
95
+ expect(data.value1).toBe(undefined);
96
+ expect(data.name).toBe(name);
97
+ });
98
+ });
@@ -0,0 +1,30 @@
1
+ import {createMX10, initConnection} from "./util";
2
+ import {afterAll, beforeAll, expect, it} from "@jest/globals";
3
+
4
+ describe('Info group tests - 0x08', () => {
5
+ const mx10 = createMX10();
6
+
7
+ beforeAll(async () => {
8
+ await initConnection(mx10)
9
+ })
10
+
11
+ afterAll(() => {
12
+ mx10.closeSocket();
13
+ })
14
+
15
+ it("0x05 - Bidi info - train speed", (done) => {
16
+
17
+ const sub = mx10.info.onBidiInfoChange.subscribe((data) => {
18
+ if (data.type === 0x0100) {
19
+
20
+ expect(data.nid).toBe(3);
21
+ expect(data.data).toBeDefined();
22
+ expect(data.data).toBeGreaterThanOrEqual(0);
23
+
24
+ done();
25
+ sub.unsubscribe();
26
+ }
27
+ });
28
+ });
29
+
30
+ });
@@ -0,0 +1,82 @@
1
+ import {createMX10, initConnection} from './util';
2
+ import {afterAll, beforeAll, describe, it, expect} from '@jest/globals';
3
+ import {firstValueFrom} from 'rxjs';
4
+ import {
5
+ DataValueExtendedData,
6
+ LocoGuiMXExtended,
7
+ LocoSpeedTabExtended,
8
+ OperatingMode,
9
+ Train,
10
+ } from '../src';
11
+
12
+ describe('LAN Data group tests - 0x17', () => {
13
+ const mx10 = createMX10();
14
+
15
+ beforeAll(async () => {
16
+ await initConnection(mx10);
17
+ });
18
+
19
+ afterAll(() => {
20
+ mx10.closeSocket();
21
+ });
22
+
23
+ it('0x27 - Loco GUI eXtended', async () => {
24
+ mx10.lanData.locoGuiExtended(211);
25
+
26
+ const train: Train = await firstValueFrom(mx10.lanData.onLocoGuiExtended);
27
+ expect(train).toBeDefined();
28
+ expect(train.nid).toBe(211);
29
+ // expect(train.name).toMatch('import loco');
30
+ expect(train.era).toBeDefined();
31
+ expect(train.functions).toBeDefined();
32
+ });
33
+
34
+ it('0x28 - Loco GUI MX eXtended', async () => {
35
+ mx10.lanData.locoGuiMXExtended(211);
36
+
37
+ const train: LocoGuiMXExtended = await firstValueFrom(
38
+ mx10.lanData.onLocoGuiMXExtended,
39
+ );
40
+ expect(train).toBeDefined();
41
+ expect(train.nid).toBe(211);
42
+ expect(train.functions).toBeDefined();
43
+ });
44
+
45
+ it('0x19 - Loco Speed Tab eXtended', async () => {
46
+ mx10.lanData.locoSpeedTapExtended(42);
47
+
48
+ const locoSpeedTab: LocoSpeedTabExtended = await firstValueFrom(
49
+ mx10.lanData.onLocoSpeedTabExtended,
50
+ );
51
+ expect(locoSpeedTab).toBeDefined();
52
+ expect(locoSpeedTab.nid).toBe(42);
53
+ expect(locoSpeedTab.dbat6).toBe(1);
54
+ if (locoSpeedTab.dbat6 === 5) {
55
+ expect(locoSpeedTab.speedTab).toBeDefined();
56
+ expect(locoSpeedTab.speedTab).toHaveLength(4);
57
+ }
58
+
59
+ // mx10.sendData(0x02, 0x01, [{value: 56, length: 2}]);
60
+ // expect(train.era).toBeDefined();
61
+ // expect(train.functions).toBeDefined();
62
+ });
63
+
64
+ it('0x8 - Data Value eXtended', async () => {
65
+ mx10.lanData.dataValueExtended(211);
66
+
67
+ const data: DataValueExtendedData = await firstValueFrom(
68
+ mx10.lanData.onDataValueExtended,
69
+ );
70
+
71
+ expect(data).toBeDefined();
72
+ expect(data.nid).toBe(211);
73
+ expect(data.functionCount).toBeDefined();
74
+ expect(data.operatingMode).toBeDefined();
75
+ expect(data.operatingMode).toBe(OperatingMode.DCC);
76
+ expect(data.speedStep).toBeDefined();
77
+ expect(data.forward).toBeDefined();
78
+ expect(data.emergencyStop).toBeDefined();
79
+ expect(data.functionsStates).toBeDefined();
80
+ expect(data.flags.deleted).toBe(false);
81
+ });
82
+ });
@@ -0,0 +1,41 @@
1
+ import {createMX10, initConnection} from "./util/";
2
+ import {afterAll, beforeAll, it, describe, expect} from "@jest/globals";
3
+ import {TrackMode} from "../src";
4
+
5
+ describe('LAN Info group tests - 0x18', () => {
6
+ const mx10 = createMX10();
7
+
8
+ beforeAll(async () => {
9
+ await initConnection(mx10)
10
+ })
11
+
12
+ afterAll(() => {
13
+ mx10.closeSocket();
14
+ })
15
+
16
+ it("0x00 - module power info", (done) => {
17
+ const sub = mx10.lanInfo.onModulePowerInfo.subscribe((data) => {
18
+ if (data.deviceNID === mx10.mx10NID) {
19
+
20
+ expect(data.port1Status).toBeDefined();
21
+ expect(data.port1Status).toBe(TrackMode.NORMAL);
22
+ expect(data.port1Voltage).toBeDefined();
23
+ expect(data.port1Amperage).toBeDefined();
24
+
25
+ expect(data.port2Status).toBeDefined();
26
+ expect(data.port2Status).toBe(TrackMode.NORMAL);
27
+ expect(data.port2Voltage).toBeDefined();
28
+ expect(data.port2Amperage).toBeDefined();
29
+
30
+ expect(data.amperage32V).toBeDefined();
31
+ expect(data.amperage12V).toBeDefined();
32
+ expect(data.voltageTotal).toBeDefined();
33
+ expect(data.temperature).toBeDefined();
34
+
35
+ sub.unsubscribe();
36
+ done();
37
+ }
38
+ })
39
+ })
40
+
41
+ });
@@ -0,0 +1,42 @@
1
+ import {afterAll, beforeAll, describe, expect, jest} from '@jest/globals';
2
+ import {createMX10, initConnection} from './util';
3
+ import {SystemStateData, SystemStateMode} from '../src';
4
+ import {delay} from '../src/internal/utils';
5
+
6
+ describe('System Control Group group tests - 0x00', () => {
7
+ const mx10 = createMX10();
8
+
9
+ beforeAll(async () => {
10
+ await initConnection(mx10);
11
+ });
12
+
13
+ afterAll(() => {
14
+ mx10.systemControl.systemState(SystemStateMode.NORMAL);
15
+
16
+ delay(1000).then(() => {
17
+ mx10.closeSocket();
18
+ });
19
+ });
20
+
21
+ test.each<{mode: number}>([
22
+ {mode: SystemStateMode.SSPe},
23
+ {mode: SystemStateMode.OFF},
24
+ {mode: SystemStateMode.SSP0},
25
+ ])('0x00 - System state test', ({mode}, done) => {
26
+ mx10.systemControl.systemState(mode);
27
+
28
+ const callback = jest.fn((data: SystemStateData) => {
29
+ if (data.nid === mx10.mx10NID) {
30
+ expect(data.port).toBeDefined();
31
+ expect(data.mode).toBe(mode);
32
+
33
+ if (callback.mock.calls.length === 3) {
34
+ sub.unsubscribe();
35
+ done();
36
+ }
37
+ }
38
+ });
39
+
40
+ const sub = mx10.systemControl.onSystemStateChange.subscribe(callback);
41
+ });
42
+ });
@@ -0,0 +1,43 @@
1
+ import {createMX10, initConnection} from './util';
2
+ import {afterAll, beforeAll, describe, it, expect} from '@jest/globals';
3
+
4
+ describe('LAN Data group tests - 0x16', () => {
5
+ const mx10 = createMX10();
6
+
7
+ beforeAll(async () => {
8
+ await initConnection(mx10);
9
+ });
10
+
11
+ afterAll(() => {
12
+ mx10.closeSocket();
13
+ });
14
+
15
+ it('0x08 - Tse Prog Read Extended', (done) => {
16
+ mx10.trackCfg.tseProgRead(211, 8);
17
+
18
+ const prog = mx10.trackCfg.onTseProgReadExtended.subscribe((data) => {
19
+ expect(data.cfgNum).toBeDefined();
20
+ expect(data.cfgNum).toBe(8);
21
+ expect(data.cvValue).toBeDefined();
22
+ expect(data.cvValue).toBe(145);
23
+
24
+ prog.unsubscribe();
25
+ done();
26
+ });
27
+ });
28
+
29
+ it('0x09 - Tse Prog Write Extended', (done) => {
30
+ // Please be sure if you want to CV write HU value on test
31
+ // mx10.trackCfg.tseProgWrite(211, 51, 20);
32
+
33
+ const prog = mx10.trackCfg.onTseProgWriteExtended.subscribe((data) => {
34
+ expect(data.cfgNum).toBeDefined();
35
+ expect(data.cfgNum).toBe(51);
36
+ expect(data.cvValue).toBeDefined();
37
+ expect(data.cvValue).toBe(20);
38
+
39
+ prog.unsubscribe();
40
+ done();
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,14 @@
1
+ import {createSocket} from 'dgram';
2
+ import MX10 from '../../src';
3
+
4
+ export function createMX10(debug?: boolean) {
5
+ return new MX10(
6
+ () => new Promise((resolve) => resolve(23)),
7
+ 1000,
8
+ debug || false,
9
+ );
10
+ }
11
+
12
+ export function initConnection(mx10: MX10) {
13
+ return mx10.initSocket(createSocket, '192.168.1.145');
14
+ }