@altronix/cli 0.5.0 → 0.6.2
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/bin/atx +2 -2
- package/build/about.d.ts +3 -1
- package/build/about.js +37 -16
- package/build/about.js.map +1 -1
- package/build/cloud.d.ts +2 -2
- package/build/cloud.js +41 -19
- package/build/cloud.js.map +1 -1
- package/build/common.d.ts +5 -5
- package/build/common.js +48 -48
- package/build/common.js.map +1 -1
- package/build/confirmDevice.d.ts +5 -5
- package/build/confirmDevice.js +35 -35
- package/build/dhcp.d.ts +1 -1
- package/build/dhcp.js +9 -9
- package/build/dhcp.js.map +1 -1
- package/build/exe.d.ts +4 -0
- package/build/exe.js +43 -0
- package/build/exe.js.map +1 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +81 -78
- package/build/index.js.map +1 -1
- package/build/ip.d.ts +2 -2
- package/build/ip.js +17 -17
- package/build/ip.js.map +1 -1
- package/build/linq.d.ts +3 -3
- package/build/linq.js +5 -5
- package/build/net.d.ts +3 -0
- package/build/net.js +47 -0
- package/build/net.js.map +1 -0
- package/build/poe.d.ts +4 -3
- package/build/poe.js +28 -23
- package/build/poe.js.map +1 -1
- package/build/reboot.d.ts +1 -0
- package/build/reboot.js +16 -0
- package/build/reboot.js.map +1 -0
- package/build/site.d.ts +2 -1
- package/build/site.js +18 -13
- package/build/site.js.map +1 -1
- package/build/stress.d.ts +1 -0
- package/build/stress.js +23 -0
- package/build/stress.js.map +1 -0
- package/build/unix.d.ts +1 -1
- package/build/unix.js +13 -13
- package/build/unix.js.map +1 -1
- package/build/update.d.ts +1 -1
- package/build/update.js +82 -82
- package/build/update.js.map +1 -1
- package/jest.config.js +6 -6
- package/package.json +3 -3
- package/src/about.ts +47 -13
- package/src/cloud.ts +55 -16
- package/src/exe.ts +54 -0
- package/src/index.ts +95 -89
- package/src/net.ts +68 -0
- package/src/stress.ts +30 -0
- package/src/{update.ts → update.ts.bak} +98 -98
- package/tsconfig.json +29 -29
- package/tsconfig.lib.json +8 -8
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/src/common.ts +0 -63
- package/src/confirmDevice.ts +0 -51
- package/src/dhcp.ts +0 -6
- package/src/ip.ts +0 -14
- package/src/linq.ts +0 -9
- package/src/poe.ts +0 -22
- package/src/site.ts +0 -10
- package/src/unix.ts +0 -10
package/build/update.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runUpdate = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
/*
|
|
6
|
-
* This example will listen for the first connected device and make a get
|
|
7
|
-
* request for the about data and log the about data to the console.
|
|
8
|
-
*/
|
|
9
|
-
const device_1 = require("@altronix/device");
|
|
10
|
-
const
|
|
11
|
-
const rxjs_1 = require("rxjs");
|
|
12
|
-
const operators_1 = require("rxjs/operators");
|
|
13
|
-
const linq_1 = tslib_1.__importDefault(require("./linq"));
|
|
14
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
15
|
-
function chunks(data, size) {
|
|
16
|
-
let arr = [];
|
|
17
|
-
let remainder = data.length % size;
|
|
18
|
-
function slicer(n) {
|
|
19
|
-
for (let i = 0; i < n; i++) {
|
|
20
|
-
let idx = i * size;
|
|
21
|
-
arr.push(data.slice(idx, idx + size));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (remainder == 0) {
|
|
25
|
-
slicer(data.length / size);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
let n = Math.ceil(data.length / size);
|
|
29
|
-
let end = size * (n - 1);
|
|
30
|
-
slicer(n - 1);
|
|
31
|
-
let last = new Uint8Array(size);
|
|
32
|
-
last.set(data.slice(end));
|
|
33
|
-
arr.push(last);
|
|
34
|
-
}
|
|
35
|
-
return arr;
|
|
36
|
-
}
|
|
37
|
-
(0, device_1.installDebugLogger)();
|
|
38
|
-
const logger = (0, device_1.getLogger)();
|
|
39
|
-
// Reduce a blob of binary data and convert into an Update[]
|
|
40
|
-
function updateReducer(arr, data, idx) {
|
|
41
|
-
let update = new
|
|
42
|
-
// NOTE: Have to initialize the Uint8Array across binding this way
|
|
43
|
-
// https://gitlab.altronix.com/software-engineering/sdk/atx-zdk/-/issues/1
|
|
44
|
-
update.data = data;
|
|
45
|
-
return arr.concat(update);
|
|
46
|
-
}
|
|
47
|
-
function runUpdate(file) {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
const sub = linq_1.default
|
|
50
|
-
.listen()
|
|
51
|
-
.pipe((0, operators_1.filter)((ev) => ev.type == device_1.CONNECTED), (0, operators_1.take)(1), (0, operators_1.switchMap)(({ device }) => linq_1.default.get(device.about.sid, "/api/v1/about")), (0, operators_1.map)(
|
|
52
|
-
logger.info("found device", { serial, version: verPrj });
|
|
53
|
-
logger.info("sending update :", { file });
|
|
54
|
-
return (0, rxjs_1.from)(fs_1.default.promises.readFile(file)).pipe((0, operators_1.switchMap)((update) => {
|
|
55
|
-
// Chunk up the update file into packets and send update to device
|
|
56
|
-
const packets = chunks(update, 512).reduce(updateReducer, []);
|
|
57
|
-
const length = packets.length;
|
|
58
|
-
const urlStart = "/api/v1/update/start";
|
|
59
|
-
const urlTransfer = "/api/v1/update/transfer";
|
|
60
|
-
const urlFinish = "/api/v1/update/finish";
|
|
61
|
-
let sent = 0;
|
|
62
|
-
const start$ = (0, rxjs_1.defer)(() => linq_1.default.get(serial, urlStart));
|
|
63
|
-
const transfer$ = (0, rxjs_1.from)(packets).pipe((0, operators_1.concatMap)((u) => linq_1.default.put(serial, urlTransfer, u.cbor())), (0, operators_1.map)((meta) => ({ code: meta.json().code, sent, length })), (0, operators_1.tap)(() => sent++));
|
|
64
|
-
const finished$ = (0, rxjs_1.defer)(() => linq_1.default.get(serial, urlFinish));
|
|
65
|
-
return (0, rxjs_1.concat)(start$, transfer$, finished$);
|
|
66
|
-
}));
|
|
67
|
-
}))
|
|
68
|
-
.subscribe({
|
|
69
|
-
next: async (mesg) => {
|
|
70
|
-
logger.info("<-", { ...mesg });
|
|
71
|
-
resolve();
|
|
72
|
-
},
|
|
73
|
-
error: async (error) => (await linq_1.default.shutdown(), reject(error)),
|
|
74
|
-
complete: async () => (await linq_1.default.shutdown(), resolve()),
|
|
75
|
-
});
|
|
76
|
-
process.on("SIGINT", async () => {
|
|
77
|
-
await linq_1.default.shutdown();
|
|
78
|
-
sub.unsubscribe();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
exports.runUpdate = runUpdate;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runUpdate = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/*
|
|
6
|
+
* This example will listen for the first connected device and make a get
|
|
7
|
+
* request for the about data and log the about data to the console.
|
|
8
|
+
*/
|
|
9
|
+
const device_1 = require("@altronix/device");
|
|
10
|
+
const zdk_1 = require("@altronix/wasm/zdk");
|
|
11
|
+
const rxjs_1 = require("rxjs");
|
|
12
|
+
const operators_1 = require("rxjs/operators");
|
|
13
|
+
const linq_1 = tslib_1.__importDefault(require("./linq"));
|
|
14
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
15
|
+
function chunks(data, size) {
|
|
16
|
+
let arr = [];
|
|
17
|
+
let remainder = data.length % size;
|
|
18
|
+
function slicer(n) {
|
|
19
|
+
for (let i = 0; i < n; i++) {
|
|
20
|
+
let idx = i * size;
|
|
21
|
+
arr.push(data.slice(idx, idx + size));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (remainder == 0) {
|
|
25
|
+
slicer(data.length / size);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
let n = Math.ceil(data.length / size);
|
|
29
|
+
let end = size * (n - 1);
|
|
30
|
+
slicer(n - 1);
|
|
31
|
+
let last = new Uint8Array(size);
|
|
32
|
+
last.set(data.slice(end));
|
|
33
|
+
arr.push(last);
|
|
34
|
+
}
|
|
35
|
+
return arr;
|
|
36
|
+
}
|
|
37
|
+
(0, device_1.installDebugLogger)();
|
|
38
|
+
const logger = (0, device_1.getLogger)();
|
|
39
|
+
// Reduce a blob of binary data and convert into an Update[]
|
|
40
|
+
function updateReducer(arr, data, idx) {
|
|
41
|
+
let update = new zdk_1.Update({ data, offset: idx * 512 });
|
|
42
|
+
// NOTE: Have to initialize the Uint8Array across binding this way
|
|
43
|
+
// https://gitlab.altronix.com/software-engineering/sdk/atx-zdk/-/issues/1
|
|
44
|
+
update.data = data;
|
|
45
|
+
return arr.concat(update);
|
|
46
|
+
}
|
|
47
|
+
function runUpdate(file) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const sub = linq_1.default
|
|
50
|
+
.listen()
|
|
51
|
+
.pipe((0, operators_1.filter)((ev) => ev.type == device_1.CONNECTED), (0, operators_1.take)(1), (0, operators_1.switchMap)(({ device }) => linq_1.default.get(device.about.sid, "/api/v1/about")), (0, operators_1.map)(zdk_1.About.fromCbor), (0, operators_1.switchMap)(({ sid: serial, verPrj }) => {
|
|
52
|
+
logger.info("found device", { serial, version: verPrj });
|
|
53
|
+
logger.info("sending update :", { file });
|
|
54
|
+
return (0, rxjs_1.from)(fs_1.default.promises.readFile(file)).pipe((0, operators_1.switchMap)((update) => {
|
|
55
|
+
// Chunk up the update file into packets and send update to device
|
|
56
|
+
const packets = chunks(update, 512).reduce(updateReducer, []);
|
|
57
|
+
const length = packets.length;
|
|
58
|
+
const urlStart = "/api/v1/update/start";
|
|
59
|
+
const urlTransfer = "/api/v1/update/transfer";
|
|
60
|
+
const urlFinish = "/api/v1/update/finish";
|
|
61
|
+
let sent = 0;
|
|
62
|
+
const start$ = (0, rxjs_1.defer)(() => linq_1.default.get(serial, urlStart));
|
|
63
|
+
const transfer$ = (0, rxjs_1.from)(packets).pipe((0, operators_1.concatMap)((u) => linq_1.default.put(serial, urlTransfer, u.cbor())), (0, operators_1.map)((meta) => ({ code: meta.json().code, sent, length })), (0, operators_1.tap)(() => sent++));
|
|
64
|
+
const finished$ = (0, rxjs_1.defer)(() => linq_1.default.get(serial, urlFinish));
|
|
65
|
+
return (0, rxjs_1.concat)(start$, transfer$, finished$);
|
|
66
|
+
}));
|
|
67
|
+
}))
|
|
68
|
+
.subscribe({
|
|
69
|
+
next: async (mesg) => {
|
|
70
|
+
logger.info("<-", { ...mesg });
|
|
71
|
+
resolve();
|
|
72
|
+
},
|
|
73
|
+
error: async (error) => (await linq_1.default.shutdown(), reject(error)),
|
|
74
|
+
complete: async () => (await linq_1.default.shutdown(), resolve()),
|
|
75
|
+
});
|
|
76
|
+
process.on("SIGINT", async () => {
|
|
77
|
+
await linq_1.default.shutdown();
|
|
78
|
+
sub.unsubscribe();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
exports.runUpdate = runUpdate;
|
|
83
83
|
//# sourceMappingURL=update.js.map
|
package/build/update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,6CAK0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,6CAK0B;AAC1B,4CAAmD;AACnD,+BAA2C;AAC3C,8CAA8E;AAC9E,0DAA0B;AAC1B,oDAAoB;AAEpB,SAAS,MAAM,CAAC,IAAgB,EAAE,IAAY;IAC5C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACnC,SAAS,MAAM,CAAC,CAAS;QACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1B,IAAI,GAAG,GAAG,CAAC,GA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C,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA/CD,8BA+CC"}
|
package/jest.config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
preset: "ts-jest",
|
|
3
|
-
coverageDirectory: "coverage",
|
|
4
|
-
testEnvironment: "node",
|
|
5
|
-
testMatch: ["**/?(*.)+(spec|test).[t]s?(x)"],
|
|
6
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: "ts-jest",
|
|
3
|
+
coverageDirectory: "coverage",
|
|
4
|
+
testEnvironment: "node",
|
|
5
|
+
testMatch: ["**/?(*.)+(spec|test).[t]s?(x)"],
|
|
6
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altronix/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"bin": {
|
|
6
6
|
"atx": "./bin/atx"
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"commander": "^10.0.0",
|
|
31
31
|
"rxjs": "^7.6.0",
|
|
32
32
|
"serialport": "^10.5.0",
|
|
33
|
-
"@altronix/
|
|
34
|
-
"@altronix/
|
|
33
|
+
"@altronix/device": "0.6.1",
|
|
34
|
+
"@altronix/wasm": "1.1.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"start": "node ./build/index.js",
|
package/src/about.ts
CHANGED
|
@@ -1,13 +1,47 @@
|
|
|
1
|
-
import { About } from "@altronix/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { About } from "@altronix/wasm/zdk";
|
|
2
|
+
import Linq, { log } from "@altronix/device";
|
|
3
|
+
import { finalize, firstValueFrom, map, switchMap, take } from "rxjs";
|
|
4
|
+
import { ResponseBody, ResponseMeta } from "@altronix/device";
|
|
5
|
+
import { cborDecodeStr } from "@altronix/netway";
|
|
6
|
+
|
|
7
|
+
export async function getAbout(): Promise<void> {
|
|
8
|
+
const linq = new Linq();
|
|
9
|
+
const path = "/api/v1/about";
|
|
10
|
+
const obs = linq.connections().pipe(
|
|
11
|
+
take(1),
|
|
12
|
+
switchMap(({ about }) => linq.get<ResponseBody>(about.sid, path)),
|
|
13
|
+
map((resp) => About.fromCbor(resp.body)),
|
|
14
|
+
finalize(() => linq.shutdown())
|
|
15
|
+
);
|
|
16
|
+
return firstValueFrom(obs).then((about) => {
|
|
17
|
+
log.info(`request complete`, { ...about.toJson() });
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function getSite(): Promise<void> {
|
|
22
|
+
const linq = new Linq();
|
|
23
|
+
const path = "/api/v1/about/site";
|
|
24
|
+
const obs = linq.connections().pipe(
|
|
25
|
+
take(1),
|
|
26
|
+
switchMap(({ about }) => linq.get<ResponseBody>(about.sid, path)),
|
|
27
|
+
map((resp) => ({ site: cborDecodeStr(resp.body) })),
|
|
28
|
+
finalize(() => linq.shutdown())
|
|
29
|
+
);
|
|
30
|
+
return firstValueFrom(obs).then((site) => {
|
|
31
|
+
log.info(`request complete`, { ...site });
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function setSite(site: string): Promise<void> {
|
|
36
|
+
const linq = new Linq();
|
|
37
|
+
const path = "/api/v1/about/site";
|
|
38
|
+
const obs = linq.connections().pipe(
|
|
39
|
+
take(1),
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
switchMap(({ about }) => linq.put<ResponseMeta>(about.sid, path, site)),
|
|
42
|
+
finalize(() => linq.shutdown())
|
|
43
|
+
);
|
|
44
|
+
return firstValueFrom(obs).then(({ meta }) => {
|
|
45
|
+
log.info(`request complete`, { code: meta.code, message: meta.mesg });
|
|
46
|
+
});
|
|
47
|
+
}
|
package/src/cloud.ts
CHANGED
|
@@ -1,16 +1,55 @@
|
|
|
1
|
-
import { NetCloud } from "@altronix/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { cborDecodeNum, NetCloud } from "@altronix/netway";
|
|
2
|
+
import Linq, { log } from "@altronix/device";
|
|
3
|
+
import { ResponseBody, ResponseMeta } from "@altronix/device";
|
|
4
|
+
import {
|
|
5
|
+
concat,
|
|
6
|
+
finalize,
|
|
7
|
+
lastValueFrom,
|
|
8
|
+
map,
|
|
9
|
+
reduce,
|
|
10
|
+
switchMap,
|
|
11
|
+
take,
|
|
12
|
+
} from "rxjs";
|
|
13
|
+
|
|
14
|
+
export async function getCloud(): Promise<void> {
|
|
15
|
+
const linq = new Linq();
|
|
16
|
+
const path = "/api/v1/net/cloud";
|
|
17
|
+
const status = "/api/v1/net/cloud/status";
|
|
18
|
+
const obs = linq.connections().pipe(
|
|
19
|
+
take(1),
|
|
20
|
+
switchMap(({ about }) => {
|
|
21
|
+
const o0 = linq
|
|
22
|
+
.get<ResponseBody>(about.sid, path)
|
|
23
|
+
.pipe(map((resp) => NetCloud.fromCbor(resp.body).toJson()));
|
|
24
|
+
const o1 = linq
|
|
25
|
+
.get<ResponseBody>(about.sid, status)
|
|
26
|
+
.pipe(map((resp) => ({ status: cborDecodeNum(resp.body) })));
|
|
27
|
+
return concat(o0, o1);
|
|
28
|
+
}),
|
|
29
|
+
reduce((acc, curr) => ({ ...acc, ...curr })),
|
|
30
|
+
finalize(() => linq.shutdown())
|
|
31
|
+
);
|
|
32
|
+
return lastValueFrom(obs).then((cloud) => {
|
|
33
|
+
log.info(`request complete`, { ...cloud });
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function setCloud(endpoint: string) {
|
|
38
|
+
const [ip, port] = endpoint.split(":");
|
|
39
|
+
const body = new NetCloud({ ip, port: parseInt(port), portEn: true });
|
|
40
|
+
const path = "/api/v1/net/cloud";
|
|
41
|
+
const save = "/api/v1/exe/saveAndReboot";
|
|
42
|
+
const linq = new Linq();
|
|
43
|
+
const obs = linq.connections().pipe(
|
|
44
|
+
take(1),
|
|
45
|
+
switchMap(({ about }) => {
|
|
46
|
+
const o0 = linq.put<ResponseMeta>(about.sid, path, body);
|
|
47
|
+
const o1 = linq.get<ResponseMeta>(about.sid, save);
|
|
48
|
+
return concat(o0, o1);
|
|
49
|
+
}),
|
|
50
|
+
finalize(() => linq.shutdown())
|
|
51
|
+
);
|
|
52
|
+
return lastValueFrom(obs).then(({ meta }) => {
|
|
53
|
+
log.info(`request complete`, { code: meta.code, message: meta.mesg });
|
|
54
|
+
});
|
|
55
|
+
}
|
package/src/exe.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Linq, { log, ResponseMeta } from "@altronix/device";
|
|
2
|
+
import { finalize, firstValueFrom, switchMap, take } from "rxjs";
|
|
3
|
+
|
|
4
|
+
export async function reboot(): Promise<void> {
|
|
5
|
+
const linq = new Linq();
|
|
6
|
+
const path = "/api/v1/exe/reboot";
|
|
7
|
+
const obs = linq.connections().pipe(
|
|
8
|
+
take(1),
|
|
9
|
+
switchMap(({ about }) => linq.get<ResponseMeta>(about.sid, path)),
|
|
10
|
+
finalize(() => linq.shutdown())
|
|
11
|
+
);
|
|
12
|
+
return firstValueFrom(obs).then(({ meta }) => {
|
|
13
|
+
log.info(`request complete`, { code: meta.code, message: meta.mesg });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function save(): Promise<void> {
|
|
18
|
+
const linq = new Linq();
|
|
19
|
+
const path = "/api/v1/exe/save";
|
|
20
|
+
const obs = linq.connections().pipe(
|
|
21
|
+
take(1),
|
|
22
|
+
switchMap(({ about }) => linq.get<ResponseMeta>(about.sid, path)),
|
|
23
|
+
finalize(() => linq.shutdown())
|
|
24
|
+
);
|
|
25
|
+
return firstValueFrom(obs).then(({ meta }) => {
|
|
26
|
+
log.info(`request complete`, { code: meta.code, message: meta.mesg });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function saveAndReboot(): Promise<void> {
|
|
31
|
+
const linq = new Linq();
|
|
32
|
+
const path = "/api/v1/exe/saveAndReboot";
|
|
33
|
+
const obs = linq.connections().pipe(
|
|
34
|
+
take(1),
|
|
35
|
+
switchMap(({ about }) => linq.get<ResponseMeta>(about.sid, path)),
|
|
36
|
+
finalize(() => linq.shutdown())
|
|
37
|
+
);
|
|
38
|
+
return firstValueFrom(obs).then(({ meta }) => {
|
|
39
|
+
log.info(`request complete`, { code: meta.code, message: meta.mesg });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function erase(): Promise<void> {
|
|
44
|
+
const linq = new Linq();
|
|
45
|
+
const path = "/api/v1/exe/erase";
|
|
46
|
+
const obs = linq.connections().pipe(
|
|
47
|
+
take(1),
|
|
48
|
+
switchMap(({ about }) => linq.get<ResponseMeta>(about.sid, path)),
|
|
49
|
+
finalize(() => linq.shutdown())
|
|
50
|
+
);
|
|
51
|
+
return firstValueFrom(obs).then(({ meta }) => {
|
|
52
|
+
log.info(`request complete`, { code: meta.code, message: meta.mesg });
|
|
53
|
+
});
|
|
54
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,89 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
.action(
|
|
42
|
-
|
|
43
|
-
program
|
|
44
|
-
.command("set-
|
|
45
|
-
.description("
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
import { log } from "@altronix/device";
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import { getAbout, getSite, setSite } from "./about";
|
|
4
|
+
import { getCloud, setCloud } from "./cloud";
|
|
5
|
+
import { getNet, setDhcp, setNet } from "./net";
|
|
6
|
+
import { reboot, save, saveAndReboot } from "./exe";
|
|
7
|
+
import { stress } from "./stress";
|
|
8
|
+
|
|
9
|
+
(async function main() {
|
|
10
|
+
log.info("running cli");
|
|
11
|
+
|
|
12
|
+
program.name("atx").description("access linq device via cli").version("TODO");
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.command("get-about")
|
|
16
|
+
.description("get about data on the device")
|
|
17
|
+
.action(getAbout);
|
|
18
|
+
|
|
19
|
+
program
|
|
20
|
+
.command("get-site")
|
|
21
|
+
.description("get site id from the device")
|
|
22
|
+
.action(getSite);
|
|
23
|
+
|
|
24
|
+
program
|
|
25
|
+
.command("set-site")
|
|
26
|
+
.description("set site id from the device")
|
|
27
|
+
.argument("<site>", "new site id")
|
|
28
|
+
.action(setSite);
|
|
29
|
+
|
|
30
|
+
program
|
|
31
|
+
.command("get-net")
|
|
32
|
+
.description("get network configuration from the device")
|
|
33
|
+
.action(getNet);
|
|
34
|
+
|
|
35
|
+
program
|
|
36
|
+
.command("set-net")
|
|
37
|
+
.description("set network interface into static ip mode")
|
|
38
|
+
.argument("<ip>", "the new IP address")
|
|
39
|
+
.argument("<sn>", "the new SUBNET mask")
|
|
40
|
+
.argument("<gw>", "the new GATEWAY address")
|
|
41
|
+
.action(setNet);
|
|
42
|
+
|
|
43
|
+
program
|
|
44
|
+
.command("set-dhcp")
|
|
45
|
+
.description("set network interface into DHCP mode")
|
|
46
|
+
.action(setDhcp);
|
|
47
|
+
|
|
48
|
+
program
|
|
49
|
+
.command("get-cloud")
|
|
50
|
+
.description("get cloud endpoint on the device")
|
|
51
|
+
.action(getCloud);
|
|
52
|
+
|
|
53
|
+
program
|
|
54
|
+
.command("set-cloud")
|
|
55
|
+
.description("set cloud endpoint on the device")
|
|
56
|
+
.argument("<endpoint>", "cloud service location")
|
|
57
|
+
.action(setCloud);
|
|
58
|
+
|
|
59
|
+
program
|
|
60
|
+
.command("save")
|
|
61
|
+
.description("save data to persistant storage")
|
|
62
|
+
.action(save);
|
|
63
|
+
|
|
64
|
+
program
|
|
65
|
+
.command("save-reboot")
|
|
66
|
+
.description("save data to persistant storage and reboot the device")
|
|
67
|
+
.action(saveAndReboot);
|
|
68
|
+
|
|
69
|
+
program.command("reboot").description("reboot the device").action(reboot);
|
|
70
|
+
|
|
71
|
+
program
|
|
72
|
+
.command("erase")
|
|
73
|
+
.description("erase customer settings")
|
|
74
|
+
.action(reboot);
|
|
75
|
+
|
|
76
|
+
program
|
|
77
|
+
.command("stress")
|
|
78
|
+
.description("run a stress test on a device")
|
|
79
|
+
.argument("<count>", "how many requests to make")
|
|
80
|
+
.action(stress);
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
program
|
|
84
|
+
.command("update")
|
|
85
|
+
.description("run firmware update from file")
|
|
86
|
+
.argument("<file>", "file to update device with")
|
|
87
|
+
.action(runUpdate);
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
await program.parseAsync();
|
|
92
|
+
} catch (e) {
|
|
93
|
+
log.error(e.message, { ...e });
|
|
94
|
+
}
|
|
95
|
+
})();
|