@ikalogic/at1000 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/build/{at1000-B3HgANSi.d.mts → at1000-BG_IKvW8.d.mts} +10 -16
- package/build/at1000-BG_IKvW8.d.mts.map +1 -0
- package/build/at1000-BaJD2vC5.mjs +8 -0
- package/build/at1000-BaJD2vC5.mjs.map +1 -0
- package/build/{at1000-C6w5G8L4.d.cts → at1000-Bk6QeH1q.d.cts} +10 -16
- package/build/at1000-Bk6QeH1q.d.cts.map +1 -0
- package/build/at1000-DuULyDOw.cjs +8 -0
- package/build/at1000-DuULyDOw.cjs.map +1 -0
- package/build/browser.cjs +1 -1
- package/build/browser.cjs.map +1 -1
- package/build/browser.d.cts +5 -4
- package/build/browser.d.cts.map +1 -1
- package/build/browser.d.mts +5 -4
- package/build/browser.d.mts.map +1 -1
- package/build/browser.mjs +1 -1
- package/build/browser.mjs.map +1 -1
- package/build/{com-BLw4CGid.d.cts → com-B2R6yhB4.d.cts} +47 -43
- package/build/com-B2R6yhB4.d.cts.map +1 -0
- package/build/{com-BLw4CGid.d.mts → com-B2R6yhB4.d.mts} +47 -43
- package/build/com-B2R6yhB4.d.mts.map +1 -0
- package/build/com.cjs +1 -1
- package/build/com.cjs.map +1 -1
- package/build/com.d.cts +1 -1
- package/build/com.d.mts +1 -1
- package/build/com.mjs +1 -1
- package/build/com.mjs.map +1 -1
- package/build/common-BSrNhbq_.cjs +2 -0
- package/build/{common-BSabSaAU.cjs.map → common-BSrNhbq_.cjs.map} +1 -1
- package/build/{common-BY1vXz1l.d.cts → common-Cv6nZZS9.d.cts} +1 -2
- package/build/common-Cv6nZZS9.d.cts.map +1 -0
- package/build/{common-BY1vXz1l.d.mts → common-Cv6nZZS9.d.mts} +1 -2
- package/build/common-Cv6nZZS9.d.mts.map +1 -0
- package/build/{events-CBVQfojK.d.cts → events-zRq39ozC.d.cts} +5 -5
- package/build/events-zRq39ozC.d.cts.map +1 -0
- package/build/{events-CBVQfojK.d.mts → events-zRq39ozC.d.mts} +5 -5
- package/build/events-zRq39ozC.d.mts.map +1 -0
- package/build/events.cjs +1 -1
- package/build/events.d.cts +1 -1
- package/build/events.d.mts +1 -1
- package/build/events.mjs +1 -1
- package/build/{gpio-DgQHE5fr.d.mts → gpio-DThbC_mm.d.mts} +10 -11
- package/build/gpio-DThbC_mm.d.mts.map +1 -0
- package/build/{gpio-BuvDysYa.d.cts → gpio-xjqg-50L.d.cts} +10 -11
- package/build/gpio-xjqg-50L.d.cts.map +1 -0
- package/build/gpio.cjs +1 -1
- package/build/gpio.cjs.map +1 -1
- package/build/gpio.d.cts +2 -2
- package/build/gpio.d.mts +2 -2
- package/build/{hmi-BrdqKB3o.d.cts → hmi-6SM_R-VX.d.cts} +3 -4
- package/build/hmi-6SM_R-VX.d.cts.map +1 -0
- package/build/{hmi-BrdqKB3o.d.mts → hmi-6SM_R-VX.d.mts} +3 -4
- package/build/hmi-6SM_R-VX.d.mts.map +1 -0
- package/build/hmi.cjs +1 -1
- package/build/hmi.cjs.map +1 -1
- package/build/hmi.d.cts +1 -1
- package/build/hmi.d.mts +1 -1
- package/build/management.cjs +1 -1
- package/build/management.d.cts +14 -7
- package/build/management.d.cts.map +1 -1
- package/build/management.d.mts +14 -7
- package/build/management.d.mts.map +1 -1
- package/build/management.mjs +1 -1
- package/build/node.cjs +1 -1
- package/build/node.cjs.map +1 -1
- package/build/node.d.cts +16 -11
- package/build/node.d.cts.map +1 -1
- package/build/node.d.mts +16 -11
- package/build/node.d.mts.map +1 -1
- package/build/node.mjs +1 -1
- package/build/node.mjs.map +1 -1
- package/build/package-ByQuarMd.cjs +2 -0
- package/build/package-ByQuarMd.cjs.map +1 -0
- package/build/package-gaVXFnhN.mjs +2 -0
- package/build/package-gaVXFnhN.mjs.map +1 -0
- package/build/{power-FmknBUz2.d.cts → power-CUrqOTyE.d.cts} +10 -11
- package/build/power-CUrqOTyE.d.cts.map +1 -0
- package/build/{power-HWfK-Ybw.d.mts → power-SmiM6n5O.d.mts} +10 -11
- package/build/power-SmiM6n5O.d.mts.map +1 -0
- package/build/power.cjs +1 -1
- package/build/power.cjs.map +1 -1
- package/build/power.d.cts +2 -2
- package/build/power.d.mts +2 -2
- package/build/{relays-8EGNIK1T.d.cts → relays-TADiLsPk.d.cts} +1 -3
- package/build/relays-TADiLsPk.d.cts.map +1 -0
- package/build/{relays-8EGNIK1T.d.mts → relays-TADiLsPk.d.mts} +1 -3
- package/build/relays-TADiLsPk.d.mts.map +1 -0
- package/build/relays.cjs +1 -1
- package/build/relays.cjs.map +1 -1
- package/build/relays.d.cts +1 -1
- package/build/relays.d.mts +1 -1
- package/build/{session-D7TpUd6L.d.cts → session-qWW9mqWH.d.cts} +1 -2
- package/build/session-qWW9mqWH.d.cts.map +1 -0
- package/build/{session-D7TpUd6L.d.mts → session-qWW9mqWH.d.mts} +1 -2
- package/build/session-qWW9mqWH.d.mts.map +1 -0
- package/build/session.cjs +1 -1
- package/build/session.d.cts +1 -1
- package/build/session.d.mts +1 -1
- package/build/session.mjs +1 -1
- package/package.json +2 -2
- package/build/at1000-B3HgANSi.d.mts.map +0 -1
- package/build/at1000-B_udjy0I.cjs +0 -8
- package/build/at1000-B_udjy0I.cjs.map +0 -1
- package/build/at1000-BjVj0Ujk.mjs +0 -8
- package/build/at1000-BjVj0Ujk.mjs.map +0 -1
- package/build/at1000-C6w5G8L4.d.cts.map +0 -1
- package/build/com-BLw4CGid.d.cts.map +0 -1
- package/build/com-BLw4CGid.d.mts.map +0 -1
- package/build/common-BSabSaAU.cjs +0 -2
- package/build/common-BY1vXz1l.d.cts.map +0 -1
- package/build/common-BY1vXz1l.d.mts.map +0 -1
- package/build/events-CBVQfojK.d.cts.map +0 -1
- package/build/events-CBVQfojK.d.mts.map +0 -1
- package/build/gpio-BuvDysYa.d.cts.map +0 -1
- package/build/gpio-DgQHE5fr.d.mts.map +0 -1
- package/build/hmi-BrdqKB3o.d.cts.map +0 -1
- package/build/hmi-BrdqKB3o.d.mts.map +0 -1
- package/build/package-Bcvmz2Lx.cjs +0 -2
- package/build/package-Bcvmz2Lx.cjs.map +0 -1
- package/build/package-CN49oc-F.mjs +0 -2
- package/build/package-CN49oc-F.mjs.map +0 -1
- package/build/power-FmknBUz2.d.cts.map +0 -1
- package/build/power-HWfK-Ybw.d.mts.map +0 -1
- package/build/relays-8EGNIK1T.d.cts.map +0 -1
- package/build/relays-8EGNIK1T.d.mts.map +0 -1
- package/build/session-D7TpUd6L.d.cts.map +0 -1
- package/build/session-D7TpUd6L.d.mts.map +0 -1
- /package/build/{chunk-CMqjfN_6.cjs → rolldown-runtime-CMqjfN_6.cjs} +0 -0
package/build/gpio.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gpio.cjs","names":["v","analogOutputLevel","analogLevel","digitalLevel"],"sources":["../src/api/gpio.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nimport { analogLevel, type AnalogOutputLevel, analogOutputLevel, digitalLevel } from './common';\nimport type { Information } from './management';\n\nexport type { AnalogOutputLevel };\n\nconst syncAction = v.picklist(['release', 'hold'], 'Invalid sync action');\nexport const analogInputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('input'),\n});\nexport const analogOutputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('output'),\n value: v.optional(analogOutputLevel),\n});\nexport const digitalInputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('input'),\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const digitalOutputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('output'),\n value: digitalLevel,\n vol: analogOutputLevel,\n voh: analogOutputLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const openDrainConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('open_drain'),\n value: digitalLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport type AnalogInputConfiguration = v.InferOutput<typeof analogInputConfiguration>;\nexport type AnalogOutputConfiguration = v.InferOutput<typeof analogOutputConfiguration>;\nexport type DigitalInputConfiguration = v.InferOutput<typeof digitalInputConfiguration>;\nexport type DigitalOutputConfiguration = v.InferOutput<typeof digitalOutputConfiguration>;\nexport type OpenDrainConfiguration = v.InferOutput<typeof openDrainConfiguration>;\n\nconst partialAnalogOutputConfiguration = v.omit(analogOutputConfiguration, ['direction', 'mode']);\nexport type PartialAnalogOutputConfiguration = v.InferOutput<\n typeof partialAnalogOutputConfiguration\n>;\nconst partialDigitalInputConfiguration = v.omit(digitalInputConfiguration, ['direction', 'mode']);\nexport type PartialDigitalInputConfiguration = v.InferOutput<\n typeof partialDigitalInputConfiguration\n>;\nconst partialDigitalOutputConfiguration = v.partial(\n v.omit(digitalOutputConfiguration, ['direction', 'mode']),\n ['vih', 'vil'],\n);\nexport type PartialDigitalOutputConfiguration = v.InferInput<\n typeof partialDigitalOutputConfiguration\n>;\nconst partialOpenDrainConfiguration = v.omit(openDrainConfiguration, ['direction', 'mode']);\nexport type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;\n\nexport const digitalState = v.object({ value: digitalLevel });\nexport const analogState = v.object({ value: analogLevel });\n\nconst syncConfiguration = v.object({ action: syncAction });\nexport type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;\n\nexport const syncState = v.object({ hold_state: v.picklist(['held', 'released']) });\nexport type SyncState = v.InferOutput<typeof syncState>;\n\nexport const gpioConfiguration = v.union([\n digitalOutputConfiguration,\n openDrainConfiguration,\n digitalInputConfiguration,\n analogOutputConfiguration,\n analogInputConfiguration,\n]);\nexport type GpioConfiguration = v.InferOutput<typeof gpioConfiguration>;\n\n/** @hideconstructor */\nexport class GpioApi {\n private count: number;\n\n constructor(private readonly fetch: UpFetch, info: Information) {\n this.count = info.capabilities.io.count;\n }\n\n /**\n * Resets all IO configurations to default.\n */\n reset(): Promise<void> {\n return this.fetch('/gpio/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access a specific digital IO pin by id.\n * @param io The IO pin id.\n * @returns The digital IO instance.\n */\n digital(io: number): DigitalIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new DigitalIO(this.fetch, io);\n }\n\n /**\n * Access a specific analog IO pin by id.\n * @param io The IO pin id.\n * @returns The analog IO instance.\n */\n analog(io: number): AnalogIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new AnalogIO(this.fetch, io);\n }\n\n /**\n * Holds the current state of all GPIO pins.\n * @returns The applied sync state.\n */\n hold(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'hold' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Releases control of the IO pins, allowing external control.\n *\n * This also sets the device as a slave.\n *\n * @returns The applied sync state.\n */\n release(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'release' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Reads back the current configuration of a specific IO pin.\n * @param io The IO pin id.\n * @returns The pin's current configuration.\n */\n read_config(io: number): Promise<GpioConfiguration> {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}/config`,\n );\n }\n\n return this.fetch(`/gpio/${io}/config`, { schema: gpioConfiguration });\n }\n\n /**\n * Reads the current hold state of all GPIO pins.\n * @returns The current sync state.\n */\n read_sync(): Promise<SyncState> {\n return this.fetch('/gpio/sync', { schema: syncState });\n }\n}\n\n/** @hideconstructor */\nexport class DigitalIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configure the pin as a digital input.\n * @param config The digital input configuration.\n * @returns The applied configuration.\n */\n configure_input(config: PartialDigitalInputConfiguration): Promise<DigitalInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n digitalInputConfiguration,\n { ...config, mode: 'digital', direction: 'input' } satisfies DigitalInputConfiguration,\n ),\n schema: digitalInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as a digital output.\n * @param config The digital output configuration.\n * @returns The applied configuration.\n */\n configure_output(config: PartialDigitalOutputConfiguration): Promise<DigitalOutputConfiguration> {\n config = v.parse(partialDigitalOutputConfiguration, config);\n\n const fullConfig = {\n mode: 'digital' as const,\n direction: 'output' as const,\n value: config.value,\n vol: config.vol,\n voh: config.voh,\n vil: config.vil ?? config.vol + (config.voh - config.vol) / 4,\n vih: config.vih ?? config.voh - (config.voh - config.vol) / 4,\n };\n\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(digitalOutputConfiguration, fullConfig),\n schema: digitalOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: digitalState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: boolean | number): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: v.parse(digitalState, { value }),\n schema: digitalState,\n }))\n .value;\n }\n\n /**\n * Configure the pin as an open drain output.\n * @param config The open drain configuration.\n * @returns The applied configuration.\n */\n configure_open_drain(config: PartialOpenDrainConfiguration): Promise<OpenDrainConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n openDrainConfiguration,\n { ...config, mode: 'digital', direction: 'open_drain' } satisfies OpenDrainConfiguration,\n ),\n schema: openDrainConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class AnalogIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configures the pin as an analog input.\n * @returns The applied configuration.\n * @returns The applied configuration.\n */\n configure_input(): Promise<AnalogInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: { mode: 'analog', direction: 'input' } satisfies AnalogInputConfiguration,\n schema: analogInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as an analog output.\n * @param config The analog output configuration.\n * @returns The applied configuration.\n */\n configure_output(value: AnalogOutputLevel): Promise<AnalogOutputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n analogOutputConfiguration,\n { value, mode: 'analog', direction: 'output' } satisfies AnalogOutputConfiguration,\n ),\n schema: analogOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: analogState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: number): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: { value },\n schema: analogState,\n }))\n .value;\n }\n}\n"],"mappings":"kLAQA,MAAM,EAAaA,EAAE,SAAS,CAAC,UAAW,MAAM,EAAG,qBAAqB,EAC3D,EAA2BA,EAAE,OAAO,CAC/C,KAAMA,EAAE,QAAQ,QAAQ,EACxB,UAAWA,EAAE,QAAQ,OAAO,CAC9B,CAAC,EACY,EAA4BA,EAAE,OAAO,CAChD,KAAMA,EAAE,QAAQ,QAAQ,EACxB,UAAWA,EAAE,QAAQ,QAAQ,EAC7B,MAAOA,EAAE,SAASC,EAAAA,CAAiB,CACrC,CAAC,EACY,EAA4BD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KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,QAAS,CAC/C,EACA,OAAQ,CACV,CAAC,CACH,CAMA,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,CAAY,CAAC,EAAA,CAAG,KAC/E,CAOA,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,OAAM,EACd,OAAQ,CACV,CAAC,EAAA,CACE,KACL,CACF"}
|
|
1
|
+
{"version":3,"file":"gpio.cjs","names":["v","analogOutputLevel","analogLevel","digitalLevel"],"sources":["../src/api/gpio.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nimport { analogLevel, type AnalogOutputLevel, analogOutputLevel, digitalLevel } from './common';\nimport type { Information } from './management';\n\nexport type { AnalogOutputLevel };\n\nconst syncAction = v.picklist(['release', 'hold'], 'Invalid sync action');\nexport const analogInputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('input'),\n});\nexport const analogOutputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('output'),\n value: v.optional(analogOutputLevel),\n});\nexport const digitalInputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('input'),\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const digitalOutputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('output'),\n value: digitalLevel,\n vol: analogOutputLevel,\n voh: analogOutputLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const openDrainConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('open_drain'),\n value: digitalLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport type AnalogInputConfiguration = v.InferOutput<typeof analogInputConfiguration>;\nexport type AnalogOutputConfiguration = v.InferOutput<typeof analogOutputConfiguration>;\nexport type DigitalInputConfiguration = v.InferOutput<typeof digitalInputConfiguration>;\nexport type DigitalOutputConfiguration = v.InferOutput<typeof digitalOutputConfiguration>;\nexport type OpenDrainConfiguration = v.InferOutput<typeof openDrainConfiguration>;\n\nconst partialAnalogOutputConfiguration = v.omit(analogOutputConfiguration, ['direction', 'mode']);\nexport type PartialAnalogOutputConfiguration = v.InferOutput<\n typeof partialAnalogOutputConfiguration\n>;\nconst partialDigitalInputConfiguration = v.omit(digitalInputConfiguration, ['direction', 'mode']);\nexport type PartialDigitalInputConfiguration = v.InferOutput<\n typeof partialDigitalInputConfiguration\n>;\nconst partialDigitalOutputConfiguration = v.partial(\n v.omit(digitalOutputConfiguration, ['direction', 'mode']),\n ['vih', 'vil'],\n);\nexport type PartialDigitalOutputConfiguration = v.InferInput<\n typeof partialDigitalOutputConfiguration\n>;\nconst partialOpenDrainConfiguration = v.omit(openDrainConfiguration, ['direction', 'mode']);\nexport type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;\n\nexport const digitalState = v.object({ value: digitalLevel });\nexport const analogState = v.object({ value: analogLevel });\n\nconst syncConfiguration = v.object({ action: syncAction });\nexport type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;\n\nexport const syncState = v.object({ hold_state: v.picklist(['held', 'released']) });\nexport type SyncState = v.InferOutput<typeof syncState>;\n\nexport const gpioConfiguration = v.union([\n digitalOutputConfiguration,\n openDrainConfiguration,\n digitalInputConfiguration,\n analogOutputConfiguration,\n analogInputConfiguration,\n]);\nexport type GpioConfiguration = v.InferOutput<typeof gpioConfiguration>;\n\n/** @hideconstructor */\nexport class GpioApi {\n private count: number;\n\n constructor(private readonly fetch: UpFetch, info: Information) {\n this.count = info.capabilities.io.count;\n }\n\n /**\n * Resets all IO configurations to default.\n */\n reset(): Promise<void> {\n return this.fetch('/gpio/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access a specific digital IO pin by id.\n * @param io The IO pin id.\n * @returns The digital IO instance.\n */\n digital(io: number): DigitalIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new DigitalIO(this.fetch, io);\n }\n\n /**\n * Access a specific analog IO pin by id.\n * @param io The IO pin id.\n * @returns The analog IO instance.\n */\n analog(io: number): AnalogIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new AnalogIO(this.fetch, io);\n }\n\n /**\n * Holds the current state of all GPIO pins.\n * @returns The applied sync state.\n */\n hold(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'hold' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Releases control of the IO pins, allowing external control.\n *\n * This also sets the device as a slave.\n *\n * @returns The applied sync state.\n */\n release(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'release' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Reads back the current configuration of a specific IO pin.\n * @param io The IO pin id.\n * @returns The pin's current configuration.\n */\n read_config(io: number): Promise<GpioConfiguration> {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}/config`,\n );\n }\n\n return this.fetch(`/gpio/${io}/config`, { schema: gpioConfiguration });\n }\n\n /**\n * Reads the current hold state of all GPIO pins.\n * @returns The current sync state.\n */\n read_sync(): Promise<SyncState> {\n return this.fetch('/gpio/sync', { schema: syncState });\n }\n}\n\n/** @hideconstructor */\nexport class DigitalIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configure the pin as a digital input.\n * @param config The digital input configuration.\n * @returns The applied configuration.\n */\n configure_input(config: PartialDigitalInputConfiguration): Promise<DigitalInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n digitalInputConfiguration,\n { ...config, mode: 'digital', direction: 'input' } satisfies DigitalInputConfiguration,\n ),\n schema: digitalInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as a digital output.\n * @param config The digital output configuration.\n * @returns The applied configuration.\n */\n configure_output(config: PartialDigitalOutputConfiguration): Promise<DigitalOutputConfiguration> {\n config = v.parse(partialDigitalOutputConfiguration, config);\n\n const fullConfig = {\n mode: 'digital' as const,\n direction: 'output' as const,\n value: config.value,\n vol: config.vol,\n voh: config.voh,\n vil: config.vil ?? config.vol + (config.voh - config.vol) / 4,\n vih: config.vih ?? config.voh - (config.voh - config.vol) / 4,\n };\n\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(digitalOutputConfiguration, fullConfig),\n schema: digitalOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: digitalState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: boolean | number): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: v.parse(digitalState, { value }),\n schema: digitalState,\n }))\n .value;\n }\n\n /**\n * Configure the pin as an open drain output.\n * @param config The open drain configuration.\n * @returns The applied configuration.\n */\n configure_open_drain(config: PartialOpenDrainConfiguration): Promise<OpenDrainConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n openDrainConfiguration,\n { ...config, mode: 'digital', direction: 'open_drain' } satisfies OpenDrainConfiguration,\n ),\n schema: openDrainConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class AnalogIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configures the pin as an analog input.\n * @returns The applied configuration.\n * @returns The applied configuration.\n */\n configure_input(): Promise<AnalogInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: { mode: 'analog', direction: 'input' } satisfies AnalogInputConfiguration,\n schema: analogInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as an analog output.\n * @param config The analog output configuration.\n * @returns The applied configuration.\n */\n configure_output(value: AnalogOutputLevel): Promise<AnalogOutputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n analogOutputConfiguration,\n { value, mode: 'analog', direction: 'output' } satisfies AnalogOutputConfiguration,\n ),\n schema: analogOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: analogState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: number): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: { value },\n schema: analogState,\n }))\n .value;\n }\n}\n"],"mappings":"6LAQA,MAAM,EAAaA,EAAE,SAAS,CAAC,UAAW,MAAM,EAAG,qBAAqB,EAC3D,EAA2BA,EAAE,OAAO,CAC/C,KAAMA,EAAE,QAAQ,QAAQ,EACxB,UAAWA,EAAE,QAAQ,OAAO,CAC9B,CAAC,EACY,EAA4BA,EAAE,OAAO,CAChD,KAAMA,EAAE,QAAQ,QAAQ,EACxB,UAAWA,EAAE,QAAQ,QAAQ,EAC7B,MAAOA,EAAE,SAASC,EAAAA,CAAiB,CACrC,CAAC,EACY,EAA4BD,EAAE,OAAO,CAChD,KAAMA,EAAE,QAAQ,SAAS,EACzB,UAAWA,EAAE,QAAQ,OAAO,EAC5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,UAAW,QAAS,CAC/C,EACA,OAAQ,CACV,CAAC,CACH,CAMA,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,CAAY,CAAC,EAAA,CAAG,KAC/E,CAOA,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,OAAM,EACd,OAAQ,CACV,CAAC,EAAA,CACE,KACL,CACF"}
|
package/build/gpio.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as AnalogOutputLevel } from "./common-
|
|
2
|
-
import { C as openDrainConfiguration, S as gpioConfiguration, _ as analogOutputConfiguration, a as DigitalInputConfiguration, b as digitalOutputConfiguration, c as GpioConfiguration, d as PartialDigitalInputConfiguration, f as PartialDigitalOutputConfiguration, g as analogInputConfiguration, h as SyncState, i as DigitalIO, l as OpenDrainConfiguration, m as SyncConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as PartialOpenDrainConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialAnalogOutputConfiguration, v as analogState, w as syncState, x as digitalState, y as digitalInputConfiguration } from "./gpio-
|
|
1
|
+
import { t as AnalogOutputLevel } from "./common-Cv6nZZS9.cjs";
|
|
2
|
+
import { C as openDrainConfiguration, S as gpioConfiguration, _ as analogOutputConfiguration, a as DigitalInputConfiguration, b as digitalOutputConfiguration, c as GpioConfiguration, d as PartialDigitalInputConfiguration, f as PartialDigitalOutputConfiguration, g as analogInputConfiguration, h as SyncState, i as DigitalIO, l as OpenDrainConfiguration, m as SyncConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as PartialOpenDrainConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialAnalogOutputConfiguration, v as analogState, w as syncState, x as digitalState, y as digitalInputConfiguration } from "./gpio-xjqg-50L.cjs";
|
|
3
3
|
export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, type AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, GpioConfiguration, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration, SyncState, analogInputConfiguration, analogOutputConfiguration, analogState, digitalInputConfiguration, digitalOutputConfiguration, digitalState, gpioConfiguration, openDrainConfiguration, syncState };
|
package/build/gpio.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as AnalogOutputLevel } from "./common-
|
|
2
|
-
import { C as openDrainConfiguration, S as gpioConfiguration, _ as analogOutputConfiguration, a as DigitalInputConfiguration, b as digitalOutputConfiguration, c as GpioConfiguration, d as PartialDigitalInputConfiguration, f as PartialDigitalOutputConfiguration, g as analogInputConfiguration, h as SyncState, i as DigitalIO, l as OpenDrainConfiguration, m as SyncConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as PartialOpenDrainConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialAnalogOutputConfiguration, v as analogState, w as syncState, x as digitalState, y as digitalInputConfiguration } from "./gpio-
|
|
1
|
+
import { t as AnalogOutputLevel } from "./common-Cv6nZZS9.mjs";
|
|
2
|
+
import { C as openDrainConfiguration, S as gpioConfiguration, _ as analogOutputConfiguration, a as DigitalInputConfiguration, b as digitalOutputConfiguration, c as GpioConfiguration, d as PartialDigitalInputConfiguration, f as PartialDigitalOutputConfiguration, g as analogInputConfiguration, h as SyncState, i as DigitalIO, l as OpenDrainConfiguration, m as SyncConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as PartialOpenDrainConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialAnalogOutputConfiguration, v as analogState, w as syncState, x as digitalState, y as digitalInputConfiguration } from "./gpio-DThbC_mm.mjs";
|
|
3
3
|
export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, type AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, GpioConfiguration, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration, SyncState, analogInputConfiguration, analogOutputConfiguration, analogState, digitalInputConfiguration, digitalOutputConfiguration, digitalState, gpioConfiguration, openDrainConfiguration, syncState };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UpFetch } from "up-fetch";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
|
|
4
3
|
//#region src/api/hmi.d.ts
|
|
5
4
|
declare const screenText: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1024, undefined>]>;
|
|
6
5
|
type ScreenText = v.InferOutput<typeof screenText>;
|
|
@@ -49,7 +48,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
49
48
|
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
50
49
|
button_pressed: boolean;
|
|
51
50
|
rotation_delta: number;
|
|
52
|
-
}, v.
|
|
51
|
+
}, v.NumberIssue | v.BooleanIssue | v.ObjectIssue>;
|
|
53
52
|
readonly "~types"?: {
|
|
54
53
|
readonly input: {
|
|
55
54
|
button_pressed: boolean;
|
|
@@ -59,7 +58,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
59
58
|
button_pressed: boolean;
|
|
60
59
|
rotation_delta: number;
|
|
61
60
|
};
|
|
62
|
-
readonly issue: v.
|
|
61
|
+
readonly issue: v.NumberIssue | v.BooleanIssue | v.ObjectIssue;
|
|
63
62
|
} | undefined;
|
|
64
63
|
};
|
|
65
64
|
type KnobEvent = v.InferOutput<typeof knobEvent>;
|
|
@@ -149,4 +148,4 @@ declare class Knob {
|
|
|
149
148
|
}
|
|
150
149
|
//#endregion
|
|
151
150
|
export { KnobEvent as a, ProgressValue as c, color as d, internalKnobEvent as f, text as h, Knob as i, Screen as l, progress as m, Color as n, PlaybackConfiguration as o, playbackConfiguration as p, HmiApi as r, Progress as s, Audio as t, ScreenText as u };
|
|
152
|
-
//# sourceMappingURL=hmi-
|
|
151
|
+
//# sourceMappingURL=hmi-6SM_R-VX.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmi-6SM_R-VX.d.cts","names":[],"sources":["../src/api/hmi.ts"],"mappings":";;;cAGM,YAAU,EAAA,yBAAA,EAAA,yBAAA,EAAA;KACJ,aAAa,EAAE,mBAAmB;cAEjC,MAAI,EAAA;;;cAIJ,OAAK,EAAA;;;;;KAKN,QAAQ,EAAE,mBAAmB;cAEnC,eAAa,EAAA,yBAAA,EAAA,yBAAA,EAAA,sCAAA,EAAA;KACP,gBAAgB,EAAE,mBAAmB;cACpC,UAAQ,EAAA;;;KACT,WAAW,EAAE,mBAAmB;cAE/B,uBAAqB,EAAA;;;;KAOtB,wBAAwB,EAAE,mBAAmB;cAE5C,mBAAiB,EAAA;;;;;cAKxB,WAAS,KAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KACH,YAAY,EAAE,mBAAmB;;cAGhC;mBACkB;EAAA,YAAA,OAAO;;;;EAKpC,SAAS;;;;;EAQT,UAAU;;;;;EAQV,SAAS;;;;;EAQT,QAAQ;;;cAMG;mBACkB;EAAA,YAAA,OAAO;;;;;;EAO9B,MAAM,MAAM,aAAa;;;;;;EAc/B,OAAO,QAAQ,QAAQ,QAAQ;;;;;;EAazB,SAAS,MAAM,gBAAgB,QAAQ;;;;EAkB7C,SAAS;;;;EAOT,cAAc;;;cAMH;mBACkB;EAAA,YAAA,OAAO;;;;;;EAO9B,KAAK,QAAQ,wBAAwB,QAAQ;;;cAUxC;mBACkB;EAAA,YAAA,OAAO;EAEpC,kBAAU;;;;;EAEV,sBAAc;EACd,sBAAc;;;;;;EAOR,WAAW,sBAAsB,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UpFetch } from "up-fetch";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
|
|
4
3
|
//#region src/api/hmi.d.ts
|
|
5
4
|
declare const screenText: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1024, undefined>]>;
|
|
6
5
|
type ScreenText = v.InferOutput<typeof screenText>;
|
|
@@ -49,7 +48,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
49
48
|
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
50
49
|
button_pressed: boolean;
|
|
51
50
|
rotation_delta: number;
|
|
52
|
-
}, v.
|
|
51
|
+
}, v.NumberIssue | v.BooleanIssue | v.ObjectIssue>;
|
|
53
52
|
readonly "~types"?: {
|
|
54
53
|
readonly input: {
|
|
55
54
|
button_pressed: boolean;
|
|
@@ -59,7 +58,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
59
58
|
button_pressed: boolean;
|
|
60
59
|
rotation_delta: number;
|
|
61
60
|
};
|
|
62
|
-
readonly issue: v.
|
|
61
|
+
readonly issue: v.NumberIssue | v.BooleanIssue | v.ObjectIssue;
|
|
63
62
|
} | undefined;
|
|
64
63
|
};
|
|
65
64
|
type KnobEvent = v.InferOutput<typeof knobEvent>;
|
|
@@ -149,4 +148,4 @@ declare class Knob {
|
|
|
149
148
|
}
|
|
150
149
|
//#endregion
|
|
151
150
|
export { KnobEvent as a, ProgressValue as c, color as d, internalKnobEvent as f, text as h, Knob as i, Screen as l, progress as m, Color as n, PlaybackConfiguration as o, playbackConfiguration as p, HmiApi as r, Progress as s, Audio as t, ScreenText as u };
|
|
152
|
-
//# sourceMappingURL=hmi-
|
|
151
|
+
//# sourceMappingURL=hmi-6SM_R-VX.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmi-6SM_R-VX.d.mts","names":[],"sources":["../src/api/hmi.ts"],"mappings":";;;cAGM,YAAU,EAAA,yBAAA,EAAA,yBAAA,EAAA;KACJ,aAAa,EAAE,mBAAmB;cAEjC,MAAI,EAAA;;;cAIJ,OAAK,EAAA;;;;;KAKN,QAAQ,EAAE,mBAAmB;cAEnC,eAAa,EAAA,yBAAA,EAAA,yBAAA,EAAA,sCAAA,EAAA;KACP,gBAAgB,EAAE,mBAAmB;cACpC,UAAQ,EAAA;;;KACT,WAAW,EAAE,mBAAmB;cAE/B,uBAAqB,EAAA;;;;KAOtB,wBAAwB,EAAE,mBAAmB;cAE5C,mBAAiB,EAAA;;;;;cAKxB,WAAS,KAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KACH,YAAY,EAAE,mBAAmB;;cAGhC;mBACkB;EAAA,YAAA,OAAO;;;;EAKpC,SAAS;;;;;EAQT,UAAU;;;;;EAQV,SAAS;;;;;EAQT,QAAQ;;;cAMG;mBACkB;EAAA,YAAA,OAAO;;;;;;EAO9B,MAAM,MAAM,aAAa;;;;;;EAc/B,OAAO,QAAQ,QAAQ,QAAQ;;;;;;EAazB,SAAS,MAAM,gBAAgB,QAAQ;;;;EAkB7C,SAAS;;;;EAOT,cAAc;;;cAMH;mBACkB;EAAA,YAAA,OAAO;;;;;;EAO9B,KAAK,QAAQ,wBAAwB,QAAQ;;;cAUxC;mBACkB;EAAA,YAAA,OAAO;EAEpC,kBAAU;;;;;EAEV,sBAAc;EACd,sBAAc;;;;;;EAOR,WAAW,sBAAsB,QAAQ"}
|
package/build/hmi.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-CMqjfN_6.cjs");let t=require("valibot");t=e.t(t,1);const n=t.pipe(t.string(),t.maxLength(1024)),r=t.object({text:n}),i=t.optional(t.pipe(t.string(),t.length(7),t.hexColor())),a=t.object({text:i,progress:i,background:i}),o=t.pipe(t.number(),t.minValue(0),t.maxValue(100)),s=t.object({progress:o}),c=t.object({sound_id:t.picklist([`success`,`warning`,`failure`,`notification_1`,`notification_2`,`imperial_march`]),volume:t.pipe(t.number(),t.minValue(0),t.maxValue(100))}),l=t.object({button_pressed:t.boolean(),button_held:t.boolean(),rotation_delta:t.number()});t.omit(l,[`button_held`]);var u=class{fetch;constructor(e){this.fetch=e}reset(){return this.fetch(`/hmi/reset`,{method:`POST`,parseResponse:()=>{}})}screen(){return new d(this.fetch)}audio(){return new f(this.fetch)}knob(){return new p(this.fetch)}},d=class{fetch;constructor(e){this.fetch=e}async print(e){return(await this.fetch(`/hmi/screen/text`,{method:`POST`,body:t.parse(r,{text:e}),schema:r})).text}colors(e){return this.fetch(`/hmi/screen/colors`,{method:`PATCH`,body:t.parse(a,e),schema:a})}async progress(e){return e==0?await this.fetch(`/hmi/screen/progress`,{method:`DELETE`,parseResponse:()=>({progress:0})}):this.fetch(`/hmi/screen/progress`,{method:`PUT`,body:t.parse(s,{progress:e}),schema:s})}clear(){return this.fetch(`/hmi/screen/clear`,{method:`POST`,parseResponse:()=>{}})}clear_text(){return this.fetch(`/hmi/screen/text`,{method:`DELETE`,parseResponse:()=>{}})}},f=class{fetch;constructor(e){this.fetch=e}async play(e){return this.fetch(`/hmi/speaker/play`,{method:`POST`,body:t.parse(c,e),schema:c})}},p=class{fetch;constructor(e){this.fetch=e}read_event=()=>this.fetch(`/hmi/knob/get_knob_event`,{schema:l});is_button_held=async()=>(await this.read_event()).button_held;is_knob_turned=async()=>Math.abs((await this.read_event()).rotation_delta)>=4;async wait_event(e){await this.read_event();let t=0,n=Math.min(50,(e??500)/10),r=Date.now();for(;e===void 0||Date.now()-r<e;){let e=await this.read_event();if(t+=e.rotation_delta,e.button_pressed||Math.abs(t)>=4)return{button_pressed:e.button_pressed,rotation_delta:Math.sign(t)};await new Promise(e=>setTimeout(e,n))}return null}};exports.Audio=f,exports.HmiApi=u,exports.Knob=p,exports.Screen=d,exports.color=a,exports.internalKnobEvent=l,exports.playbackConfiguration=c,exports.progress=s,exports.text=r;
|
|
2
2
|
//# sourceMappingURL=hmi.cjs.map
|
package/build/hmi.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmi.cjs","names":["v"],"sources":["../src/api/hmi.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nconst screenText = v.pipe(v.string(), v.maxLength(1024));\nexport type ScreenText = v.InferOutput<typeof screenText>;\n\nexport const text = v.object({ text: screenText });\ntype Text = v.InferOutput<typeof text>;\n\nconst optionalHexColor = v.optional(v.pipe(v.string(), v.length(7), v.hexColor()));\nexport const color = v.object({\n text: optionalHexColor,\n progress: optionalHexColor,\n background: optionalHexColor,\n});\nexport type Color = v.InferOutput<typeof color>;\n\nconst progressValue = v.pipe(v.number(), v.minValue(0), v.maxValue(100));\nexport type ProgressValue = v.InferOutput<typeof progressValue>;\nexport const progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nexport const playbackConfiguration = v.object({\n sound_id: v.picklist(\n ['success', 'warning', 'failure', 'notification_1', 'notification_2',\n 'imperial_march'] as const,\n ),\n volume: v.pipe(v.number(), v.minValue(0), v.maxValue(100)),\n});\nexport type PlaybackConfiguration = v.InferOutput<typeof playbackConfiguration>;\n\nexport const internalKnobEvent = v.object({\n button_pressed: v.boolean(),\n button_held: v.boolean(),\n rotation_delta: v.number(),\n});\nconst knobEvent = v.omit(internalKnobEvent, ['button_held']);\nexport type KnobEvent = v.InferOutput<typeof knobEvent>;\n\n/** @hideconstructor */\nexport class HmiApi {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Resets the HMI.\n */\n reset(): Promise<void> {\n return this.fetch('/hmi/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access the screen API.\n * @returns The screen instance.\n */\n screen(): Screen {\n return new Screen(this.fetch);\n }\n\n /**\n * Access the audio API.\n * @returns The audio instance.\n */\n audio(): Audio {\n return new Audio(this.fetch);\n }\n\n /**\n * Access the knob API.\n * @returns The knob instance.\n */\n knob(): Knob {\n return new Knob(this.fetch);\n }\n}\n\n/** @hideconstructor */\nexport class Screen {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Prints text to the screen.\n * @param data The text to print.\n * @returns The printed text.\n */\n async print(data: ScreenText): Promise<string> {\n return (await this.fetch('/hmi/screen/text', {\n method: 'POST',\n body: v.parse(text, { text: data } satisfies Text),\n schema: text,\n }))\n .text;\n }\n\n /**\n * Sets the screen colors.\n * @param colors The colors to set.\n * @returns The updated colors.\n */\n colors(colors: Color): Promise<Color> {\n return this.fetch('/hmi/screen/colors', {\n method: 'PATCH',\n body: v.parse(color, colors satisfies Color),\n schema: color,\n });\n }\n\n /**\n * Sets the screen progress.\n * @param data The progress value to set.\n * @returns The updated progress.\n */\n async progress(data: ProgressValue): Promise<Progress> {\n if (data == 0) {\n return await this.fetch('/hmi/screen/progress', {\n method: 'DELETE',\n parseResponse: () => ({ progress: 0 }),\n });\n }\n\n return this.fetch('/hmi/screen/progress', {\n method: 'PUT',\n body: v.parse(progress, { progress: data } satisfies Progress),\n schema: progress,\n });\n }\n\n /**\n * Clears the screen.\n */\n clear(): Promise<void> {\n return this.fetch('/hmi/screen/clear', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Clears the text on the screen.\n */\n clear_text(): Promise<void> {\n return this.fetch('/hmi/screen/text', { method: 'DELETE', parseResponse: () => {} });\n }\n}\n\n/** @hideconstructor */\nexport class Audio {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Plays a sound.\n * @param config The configuration (sound_id, volume).\n * @returns The play configuration.\n */\n async play(config: PlaybackConfiguration): Promise<PlaybackConfiguration> {\n return this.fetch('/hmi/speaker/play', {\n method: 'POST',\n body: v.parse(playbackConfiguration, config),\n schema: playbackConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class Knob {\n constructor(private readonly fetch: UpFetch) {}\n\n read_event = () => this.fetch('/hmi/knob/get_knob_event', { schema: internalKnobEvent });\n\n is_button_held = async () => (await this.read_event()).button_held;\n is_knob_turned = async () => Math.abs((await this.read_event()).rotation_delta) >= 4;\n\n /**\n * Waits for a knob event and returns it.\n * @param timeout_ms The timeout in milliseconds.\n * @returns The knob event or null if the timeout was reached.\n */\n async wait_event(timeout_ms?: number): Promise<KnobEvent | null> {\n await this.read_event(); // Discard any previous events\n let delta = 0;\n\n const interval = Math.min(50, (timeout_ms ?? 500) / 10);\n\n const startTime = Date.now();\n while (timeout_ms !== undefined ? Date.now() - startTime < timeout_ms : true) {\n const knobEvent = await this.read_event();\n delta += knobEvent.rotation_delta;\n\n if (knobEvent.button_pressed || Math.abs(delta) >= 4) {\n return { button_pressed: knobEvent.button_pressed, rotation_delta: Math.sign(delta) };\n }\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n\n return null;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hmi.cjs","names":["v"],"sources":["../src/api/hmi.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nconst screenText = v.pipe(v.string(), v.maxLength(1024));\nexport type ScreenText = v.InferOutput<typeof screenText>;\n\nexport const text = v.object({ text: screenText });\ntype Text = v.InferOutput<typeof text>;\n\nconst optionalHexColor = v.optional(v.pipe(v.string(), v.length(7), v.hexColor()));\nexport const color = v.object({\n text: optionalHexColor,\n progress: optionalHexColor,\n background: optionalHexColor,\n});\nexport type Color = v.InferOutput<typeof color>;\n\nconst progressValue = v.pipe(v.number(), v.minValue(0), v.maxValue(100));\nexport type ProgressValue = v.InferOutput<typeof progressValue>;\nexport const progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nexport const playbackConfiguration = v.object({\n sound_id: v.picklist(\n ['success', 'warning', 'failure', 'notification_1', 'notification_2',\n 'imperial_march'] as const,\n ),\n volume: v.pipe(v.number(), v.minValue(0), v.maxValue(100)),\n});\nexport type PlaybackConfiguration = v.InferOutput<typeof playbackConfiguration>;\n\nexport const internalKnobEvent = v.object({\n button_pressed: v.boolean(),\n button_held: v.boolean(),\n rotation_delta: v.number(),\n});\nconst knobEvent = v.omit(internalKnobEvent, ['button_held']);\nexport type KnobEvent = v.InferOutput<typeof knobEvent>;\n\n/** @hideconstructor */\nexport class HmiApi {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Resets the HMI.\n */\n reset(): Promise<void> {\n return this.fetch('/hmi/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access the screen API.\n * @returns The screen instance.\n */\n screen(): Screen {\n return new Screen(this.fetch);\n }\n\n /**\n * Access the audio API.\n * @returns The audio instance.\n */\n audio(): Audio {\n return new Audio(this.fetch);\n }\n\n /**\n * Access the knob API.\n * @returns The knob instance.\n */\n knob(): Knob {\n return new Knob(this.fetch);\n }\n}\n\n/** @hideconstructor */\nexport class Screen {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Prints text to the screen.\n * @param data The text to print.\n * @returns The printed text.\n */\n async print(data: ScreenText): Promise<string> {\n return (await this.fetch('/hmi/screen/text', {\n method: 'POST',\n body: v.parse(text, { text: data } satisfies Text),\n schema: text,\n }))\n .text;\n }\n\n /**\n * Sets the screen colors.\n * @param colors The colors to set.\n * @returns The updated colors.\n */\n colors(colors: Color): Promise<Color> {\n return this.fetch('/hmi/screen/colors', {\n method: 'PATCH',\n body: v.parse(color, colors satisfies Color),\n schema: color,\n });\n }\n\n /**\n * Sets the screen progress.\n * @param data The progress value to set.\n * @returns The updated progress.\n */\n async progress(data: ProgressValue): Promise<Progress> {\n if (data == 0) {\n return await this.fetch('/hmi/screen/progress', {\n method: 'DELETE',\n parseResponse: () => ({ progress: 0 }),\n });\n }\n\n return this.fetch('/hmi/screen/progress', {\n method: 'PUT',\n body: v.parse(progress, { progress: data } satisfies Progress),\n schema: progress,\n });\n }\n\n /**\n * Clears the screen.\n */\n clear(): Promise<void> {\n return this.fetch('/hmi/screen/clear', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Clears the text on the screen.\n */\n clear_text(): Promise<void> {\n return this.fetch('/hmi/screen/text', { method: 'DELETE', parseResponse: () => {} });\n }\n}\n\n/** @hideconstructor */\nexport class Audio {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Plays a sound.\n * @param config The configuration (sound_id, volume).\n * @returns The play configuration.\n */\n async play(config: PlaybackConfiguration): Promise<PlaybackConfiguration> {\n return this.fetch('/hmi/speaker/play', {\n method: 'POST',\n body: v.parse(playbackConfiguration, config),\n schema: playbackConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class Knob {\n constructor(private readonly fetch: UpFetch) {}\n\n read_event = () => this.fetch('/hmi/knob/get_knob_event', { schema: internalKnobEvent });\n\n is_button_held = async () => (await this.read_event()).button_held;\n is_knob_turned = async () => Math.abs((await this.read_event()).rotation_delta) >= 4;\n\n /**\n * Waits for a knob event and returns it.\n * @param timeout_ms The timeout in milliseconds.\n * @returns The knob event or null if the timeout was reached.\n */\n async wait_event(timeout_ms?: number): Promise<KnobEvent | null> {\n await this.read_event(); // Discard any previous events\n let delta = 0;\n\n const interval = Math.min(50, (timeout_ms ?? 500) / 10);\n\n const startTime = Date.now();\n while (timeout_ms !== undefined ? Date.now() - startTime < timeout_ms : true) {\n const knobEvent = await this.read_event();\n delta += knobEvent.rotation_delta;\n\n if (knobEvent.button_pressed || Math.abs(delta) >= 4) {\n return { button_pressed: knobEvent.button_pressed, rotation_delta: Math.sign(delta) };\n }\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n\n return null;\n }\n}\n"],"mappings":"0JAGA,MAAM,EAAaA,EAAE,KAAKA,EAAE,OAAO,EAAGA,EAAE,UAAU,IAAI,CAAC,EAG1C,EAAOA,EAAE,OAAO,CAAE,KAAM,CAAW,CAAC,EAG3C,EAA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AAO,EAAE,EAEhD,EAAY,KAAK,IAAI,EAC3B,KAAO,IAAe,IAAA,IAAY,KAAK,IAAI,EAAI,EAAY,GAAmB,CAC5E,IAAM,EAAY,MAAM,KAAK,WAAW,EAGxC,GAFA,GAAS,EAAU,eAEf,EAAU,gBAAkB,KAAK,IAAI,CAAK,GAAK,EACjD,MAAO,CAAE,eAAgB,EAAU,eAAgB,eAAgB,KAAK,KAAK,CAAK,CAAE,EAEtF,MAAM,IAAI,QAAS,GAAY,WAAW,EAAS,CAAQ,CAAC,CAC9D,CAEA,OAAO,IACT,CACF"}
|
package/build/hmi.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as KnobEvent, c as ProgressValue, d as color, f as internalKnobEvent, h as text, i as Knob, l as Screen, m as progress, n as Color, o as PlaybackConfiguration, p as playbackConfiguration, r as HmiApi, s as Progress, t as Audio, u as ScreenText } from "./hmi-
|
|
1
|
+
import { a as KnobEvent, c as ProgressValue, d as color, f as internalKnobEvent, h as text, i as Knob, l as Screen, m as progress, n as Color, o as PlaybackConfiguration, p as playbackConfiguration, r as HmiApi, s as Progress, t as Audio, u as ScreenText } from "./hmi-6SM_R-VX.cjs";
|
|
2
2
|
export { Audio, Color, HmiApi, Knob, KnobEvent, PlaybackConfiguration, Progress, ProgressValue, Screen, ScreenText, color, internalKnobEvent, playbackConfiguration, progress, text };
|
package/build/hmi.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as KnobEvent, c as ProgressValue, d as color, f as internalKnobEvent, h as text, i as Knob, l as Screen, m as progress, n as Color, o as PlaybackConfiguration, p as playbackConfiguration, r as HmiApi, s as Progress, t as Audio, u as ScreenText } from "./hmi-
|
|
1
|
+
import { a as KnobEvent, c as ProgressValue, d as color, f as internalKnobEvent, h as text, i as Knob, l as Screen, m as progress, n as Color, o as PlaybackConfiguration, p as playbackConfiguration, r as HmiApi, s as Progress, t as Audio, u as ScreenText } from "./hmi-6SM_R-VX.mjs";
|
|
2
2
|
export { Audio, Color, HmiApi, Knob, KnobEvent, PlaybackConfiguration, Progress, ProgressValue, Screen, ScreenText, color, internalKnobEvent, playbackConfiguration, progress, text };
|
package/build/management.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./at1000-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./at1000-DuULyDOw.cjs");exports.CommunicationInterfaceType=e.u,exports.ManagementApi=e.d,exports.calibrationData=e.f,exports.calibrationState=e.p,exports.portMapping=e.m,exports.project=e.h,exports.projectEvent=e.g,exports.runMode=e._,exports.updateStatus=e.v;
|
package/build/management.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UpFetch } from "up-fetch";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
|
|
4
3
|
//#region src/api/management.d.ts
|
|
5
4
|
declare enum CommunicationInterfaceType {
|
|
6
5
|
Can = "can",
|
|
@@ -20,6 +19,9 @@ declare const info: v.ObjectSchema<{
|
|
|
20
19
|
readonly disk_used: v.NumberSchema<undefined>;
|
|
21
20
|
readonly disk_total: v.NumberSchema<undefined>;
|
|
22
21
|
readonly docker_used: v.NumberSchema<undefined>;
|
|
22
|
+
readonly ram_used: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
23
|
+
readonly ram_total: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
24
|
+
readonly cpu_temperature: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
23
25
|
readonly capabilities: v.ObjectSchema<{
|
|
24
26
|
readonly io: v.ObjectSchema<{
|
|
25
27
|
readonly count: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
@@ -171,7 +173,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
171
173
|
name: string;
|
|
172
174
|
is_default: boolean;
|
|
173
175
|
command: string;
|
|
174
|
-
}, v.BooleanIssue | v.
|
|
176
|
+
}, v.BooleanIssue | v.ObjectIssue | v.StringIssue>;
|
|
175
177
|
readonly "~types"?: {
|
|
176
178
|
readonly input: {
|
|
177
179
|
name: string;
|
|
@@ -183,7 +185,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
183
185
|
is_default: boolean;
|
|
184
186
|
command: string;
|
|
185
187
|
};
|
|
186
|
-
readonly issue: v.BooleanIssue | v.
|
|
188
|
+
readonly issue: v.BooleanIssue | v.ObjectIssue | v.StringIssue;
|
|
187
189
|
} | undefined;
|
|
188
190
|
}, "~types" | "~run" | "~standard" | "entries"> & {
|
|
189
191
|
readonly entries: {
|
|
@@ -204,7 +206,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
204
206
|
name?: string | undefined;
|
|
205
207
|
is_default?: boolean | undefined;
|
|
206
208
|
command?: string | undefined;
|
|
207
|
-
}, v.BooleanIssue | v.
|
|
209
|
+
}, v.BooleanIssue | v.ObjectIssue | v.StringIssue>;
|
|
208
210
|
readonly "~types"?: {
|
|
209
211
|
readonly input: {
|
|
210
212
|
name?: string | undefined;
|
|
@@ -216,7 +218,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
216
218
|
is_default?: boolean | undefined;
|
|
217
219
|
command?: string | undefined;
|
|
218
220
|
};
|
|
219
|
-
readonly issue: v.BooleanIssue | v.
|
|
221
|
+
readonly issue: v.BooleanIssue | v.ObjectIssue | v.StringIssue;
|
|
220
222
|
} | undefined;
|
|
221
223
|
};
|
|
222
224
|
type ProjectPatch = v.InferOutput<typeof projectPatch>;
|
|
@@ -320,7 +322,8 @@ type RelayTestResult = v.InferOutput<typeof relayTestResult>;
|
|
|
320
322
|
declare const usbTestResult: v.ObjectSchema<{
|
|
321
323
|
readonly port: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>;
|
|
322
324
|
readonly status: v.PicklistSchema<["pass", "fail"], undefined>;
|
|
323
|
-
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
325
|
+
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
326
|
+
/** @deprecated Legacy field; only present on calibrations from older devices. */
|
|
324
327
|
readonly current_tests: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
325
328
|
readonly load_ohms: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, number, undefined>]>;
|
|
326
329
|
readonly voltage_applied: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
@@ -407,7 +410,8 @@ declare const calibrationData: v.ObjectSchema<{
|
|
|
407
410
|
readonly usb: v.ArraySchema<v.ObjectSchema<{
|
|
408
411
|
readonly port: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>;
|
|
409
412
|
readonly status: v.PicklistSchema<["pass", "fail"], undefined>;
|
|
410
|
-
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
413
|
+
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
414
|
+
/** @deprecated Legacy field; only present on calibrations from older devices. */
|
|
411
415
|
readonly current_tests: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
412
416
|
readonly load_ohms: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, number, undefined>]>;
|
|
413
417
|
readonly voltage_applied: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
@@ -444,6 +448,9 @@ declare class ManagementApi {
|
|
|
444
448
|
disk_used: number;
|
|
445
449
|
disk_total: number;
|
|
446
450
|
docker_used: number;
|
|
451
|
+
ram_used?: number | undefined;
|
|
452
|
+
ram_total?: number | undefined;
|
|
453
|
+
cpu_temperature?: number | undefined;
|
|
447
454
|
capabilities: {
|
|
448
455
|
io: {
|
|
449
456
|
count: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management.d.cts","names":[],"sources":["../src/api/management.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"management.d.cts","names":[],"sources":["../src/api/management.ts"],"mappings":";;;aAKY;EACV;EACA;EACA;EACA;EACA;EACA;;cA+EI,MAAI,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgBE,cAAc,EAAE,mBAAmB;cAMlC,aAAW,EAAA;;;;;KACZ,cAAc,EAAE,mBAAmB;cAMlC,SAAO,EAAA;KACR,UAAU,EAAE,mBAAmB;cAErC,SAAO,EAAA;;;;KACD,UAAU,EAAE,mBAAmB;cAE9B,SAAO,EAAA;;;;;;;;;;;;;;;KAWR,UAAU,EAAE,mBAAmB;cAG9B,cAAY,EAAA,yBAAA,EAAA;;;;;;;;;;;;;KAKb,eAAe,EAAE,mBAAmB;cAE1C,cAAY,KAAA,KAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KACN,eAAe,EAAE,mBAAmB;cAE1C,iBAAe,EAAA;KACT,kBAAkB,EAAE,mBAAmB;cAE7C,eAAa,EAAA;;;;;KAKP,gBAAgB,EAAE,mBAAmB;cAE3C,YAAU,EAAA;;;;;;KAMJ,aAAa,EAAE,mBAAmB;cAExC,iBAAe,EAAA;;;;KACT,kBAAkB,EAAE,mBAAm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AAa;;;;;;;;;;;;;;;;;;;;;EAevC,cAAc,MAAM,MAAM,eAAY;;;;;;;;;;;;;;;;;;;;EAgBtC,cAAc,mBAAmB,MAAM,eAAY;;;;;;;;;;;;;;;;;;;;EAanD,WAAW,mBAAmB,OAAM,UAAkB;;;;;EAYtD,YAAY,oBAAiB;;;;;;EAY7B,gBAAgB,oBAAiB;;;;;;;;;;;EAUjC,gBAAgB,mBAAmB,OAAO,gBAAa;;;;;;;;;;;EAevD,eAAe,mBAAmB,SAAS,cAAW;;;;;;;;;;EActD,kBAAkB,mBAAmB,mBAAgB;;;;;;;EAcrD,mBAAmB,mBAAmB,mBAAgB;;;;;;EActD,yBAAyB,oBAAiB;;;;;;;EAY1C,yBAAyB,mBAAmB,iBAAc;;;;;EAa1D,cAAc,oBAAiB;;;;;;;;EAW/B,cAAc,MAAM,MAAM,oBAAyB;;;;;;;;;;EAenD,eAAW;;;;;;;;;;EAQX,kBAAc;;;;;;;;EAQd,iBAAa;;;;;;;;;;EAQb,UAAM;;;;;;;;;;;;;;;EAgBN,eAAe,mBAAmB;IAAY;MAAe;;;;;;;;;;;;;;;;;EAoB7D,kBACE,mBACA;IACE,SAAS,MAAM;IACf;IACA,WAAW;KAEb;IAAY;;IACT"}
|
package/build/management.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UpFetch } from "up-fetch";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
|
|
4
3
|
//#region src/api/management.d.ts
|
|
5
4
|
declare enum CommunicationInterfaceType {
|
|
6
5
|
Can = "can",
|
|
@@ -20,6 +19,9 @@ declare const info: v.ObjectSchema<{
|
|
|
20
19
|
readonly disk_used: v.NumberSchema<undefined>;
|
|
21
20
|
readonly disk_total: v.NumberSchema<undefined>;
|
|
22
21
|
readonly docker_used: v.NumberSchema<undefined>;
|
|
22
|
+
readonly ram_used: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
23
|
+
readonly ram_total: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
24
|
+
readonly cpu_temperature: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
23
25
|
readonly capabilities: v.ObjectSchema<{
|
|
24
26
|
readonly io: v.ObjectSchema<{
|
|
25
27
|
readonly count: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
|
|
@@ -171,7 +173,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
171
173
|
name: string;
|
|
172
174
|
is_default: boolean;
|
|
173
175
|
command: string;
|
|
174
|
-
}, v.BooleanIssue | v.
|
|
176
|
+
}, v.BooleanIssue | v.ObjectIssue | v.StringIssue>;
|
|
175
177
|
readonly "~types"?: {
|
|
176
178
|
readonly input: {
|
|
177
179
|
name: string;
|
|
@@ -183,7 +185,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
183
185
|
is_default: boolean;
|
|
184
186
|
command: string;
|
|
185
187
|
};
|
|
186
|
-
readonly issue: v.BooleanIssue | v.
|
|
188
|
+
readonly issue: v.BooleanIssue | v.ObjectIssue | v.StringIssue;
|
|
187
189
|
} | undefined;
|
|
188
190
|
}, "~types" | "~run" | "~standard" | "entries"> & {
|
|
189
191
|
readonly entries: {
|
|
@@ -204,7 +206,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
204
206
|
name?: string | undefined;
|
|
205
207
|
is_default?: boolean | undefined;
|
|
206
208
|
command?: string | undefined;
|
|
207
|
-
}, v.BooleanIssue | v.
|
|
209
|
+
}, v.BooleanIssue | v.ObjectIssue | v.StringIssue>;
|
|
208
210
|
readonly "~types"?: {
|
|
209
211
|
readonly input: {
|
|
210
212
|
name?: string | undefined;
|
|
@@ -216,7 +218,7 @@ declare const projectPatch: Omit<Omit<v.ObjectSchema<{
|
|
|
216
218
|
is_default?: boolean | undefined;
|
|
217
219
|
command?: string | undefined;
|
|
218
220
|
};
|
|
219
|
-
readonly issue: v.BooleanIssue | v.
|
|
221
|
+
readonly issue: v.BooleanIssue | v.ObjectIssue | v.StringIssue;
|
|
220
222
|
} | undefined;
|
|
221
223
|
};
|
|
222
224
|
type ProjectPatch = v.InferOutput<typeof projectPatch>;
|
|
@@ -320,7 +322,8 @@ type RelayTestResult = v.InferOutput<typeof relayTestResult>;
|
|
|
320
322
|
declare const usbTestResult: v.ObjectSchema<{
|
|
321
323
|
readonly port: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>;
|
|
322
324
|
readonly status: v.PicklistSchema<["pass", "fail"], undefined>;
|
|
323
|
-
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
325
|
+
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
326
|
+
/** @deprecated Legacy field; only present on calibrations from older devices. */
|
|
324
327
|
readonly current_tests: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
325
328
|
readonly load_ohms: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, number, undefined>]>;
|
|
326
329
|
readonly voltage_applied: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
@@ -407,7 +410,8 @@ declare const calibrationData: v.ObjectSchema<{
|
|
|
407
410
|
readonly usb: v.ArraySchema<v.ObjectSchema<{
|
|
408
411
|
readonly port: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>;
|
|
409
412
|
readonly status: v.PicklistSchema<["pass", "fail"], undefined>;
|
|
410
|
-
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
413
|
+
readonly voltage: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
414
|
+
/** @deprecated Legacy field; only present on calibrations from older devices. */
|
|
411
415
|
readonly current_tests: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
412
416
|
readonly load_ohms: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, number, undefined>]>;
|
|
413
417
|
readonly voltage_applied: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>;
|
|
@@ -444,6 +448,9 @@ declare class ManagementApi {
|
|
|
444
448
|
disk_used: number;
|
|
445
449
|
disk_total: number;
|
|
446
450
|
docker_used: number;
|
|
451
|
+
ram_used?: number | undefined;
|
|
452
|
+
ram_total?: number | undefined;
|
|
453
|
+
cpu_temperature?: number | undefined;
|
|
447
454
|
capabilities: {
|
|
448
455
|
io: {
|
|
449
456
|
count: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"management.d.mts","names":[],"sources":["../src/api/management.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"management.d.mts","names":[],"sources":["../src/api/management.ts"],"mappings":";;;aAKY;EACV;EACA;EACA;EACA;EACA;EACA;;cA+EI,MAAI,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgBE,cAAc,EAAE,mBAAmB;cAMlC,aAAW,EAAA;;;;;KACZ,cAAc,EAAE,mBAAmB;cAMlC,SAAO,EAAA;KACR,UAAU,EAAE,mBAAmB;cAErC,SAAO,EAAA;;;;KACD,UAAU,EAAE,mBAAmB;cAE9B,SAAO,EAAA;;;;;;;;;;;;;;;KAWR,UAAU,EAAE,mBAAmB;cAG9B,cAAY,EAAA,yBAAA,EAAA;;;;;;;;;;;;;KAKb,eAAe,EAAE,mBAAmB;cAE1C,cAAY,KAAA,KAAA,EAAA;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{_ as e,d as t,f as n,g as r,h as i,m as a,p as o,u as s,v as c}from"./at1000-BaJD2vC5.mjs";export{s as CommunicationInterfaceType,t as ManagementApi,n as calibrationData,o as calibrationState,a as portMapping,i as project,r as projectEvent,e as runMode,c as updateStatus};
|
package/build/node.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunk-CMqjfN_6.cjs"),t=require("./package-Bcvmz2Lx.cjs"),n=require("./at1000-B_udjy0I.cjs");let r=require("up-fetch"),i=require("node:fs"),a=require("node:os");a=e.t(a,1);let o=require("dns-packet");o=e.t(o,1);let s=require("node:events"),c=require("node:util");c=e.t(c,1);let l=require("ip-address");l=e.t(l,1);let u=require("node:dgram");u=e.t(u,1);const d=`224.0.0.251`,f=5353,p=`IPv4`,m=`IPv6`,h=[p,4,m,6];var g=class e{static getInterfaces(t){return t?e.getInterfacesFromStrings(t):e.getAllInterfaces()}static getAllInterfaces(){let e=[],t=[],n=a.default.networkInterfaces();for(let[r,i]of Object.entries(n))t.includes(r)||(t.push(r),i?.forEach(t=>{t.internal||!h.includes(t.family)||/^(2002|2001):/gi.exec(t.address)||e.push({name:r,address:t.address,family:t.family,scopeid:t.scopeid})}));if(!e.length)throw Error(`No usable network interfaces returned by OS.`);return e}static getInterfacesFromStrings(t){let n=Array.isArray(t)?t:[t],r=this.getAllInterfaces().filter(t=>n.reduce((n,r)=>n||!!(e.stringMatchesAddress(r,t.address)||t.name===r),!1));if(!r||!r.length)throw Error(`No usable network interfaces returned by OS.`);return r}static stringMatchesAddress(e,t){let n,r;try{n=new l.default.Address4(e),r=new l.default.Address4(t)}catch{try{n=new l.default.Address6(e),r=new l.default.Address6(t)}catch{return!1}}return n.bigInt()===r.bigInt()}};const _={interfaces:[],reuseAddr:!0,ttl:255,loopback:!0,onMessage:(e,t)=>{console.log(`Message `+e.toString())},socketError:e=>{console.log(`Socket error `+e.message)}};var v=class e{static validateSettings(e){if(!e.multicastAddress)throw Error(`Socket settings require multicastAddress`);if(!e.multicastPort)throw Error(`Socket settings require multicastPort`)}static createMulticastSocket(t){return new Promise((n,r)=>{let i=Object.assign({},_,t);e.validateSettings(i);let a=u.default.createSocket({type:l.default.Address4.isValid(i.multicastAddress)?`udp4`:`udp6`,reuseAddr:i.reuseAddr}),o=!1;a.on(`error`,e=>{o?i.socketError(e):(a.close(),n({success:!1,error:e}))}).on(`listening`,()=>{o=!0,a.setMulticastTTL(i.ttl??255),a.setMulticastLoopback(i.loopback??!0);let t=e.addMulticastMemberships(a,i);if(!t.memberships.length){o=!1,a.close(),n({success:!1,error:Error(`No interface memberships for multicast address `+i.multicastAddress)});return}n(Object.assign({success:!0},t,{socket:a}))}).on(`message`,(e,t)=>{i.onMessage(e,t)}),a.bind({port:i.multicastPort,exclusive:!1})})}static addMulticastMemberships(t,n){let r=[],i=[],a=l.default.Address4.isValid(n.multicastAddress)?[p,4]:[m,6];return n.interfaces.forEach(o=>{if(a.includes(o.family))try{t.addMembership(n.multicastAddress,e.interfaceAddress(o)),r.push(o)}catch{i.push(o)}}),{memberships:r,failedMemberships:i}}static async createSendSocket(t,n,r,i,a){return new Promise(o=>{let s=[`IPv4`,4].includes(t.family)?`udp4`:`udp6`,c=e.interfaceAddress(t),l=n.srcPort??0,d=!1,f=e=>{let l=u.default.createSocket({type:s,reuseAddr:!!n.reuseAddr,reusePort:!0}),p=!1;l.on(`error`,t=>{p?i(t):(l.close(),e!==0&&!d?(d=!0,a?.(`mDNS send socket bind to ${c}:${e} failed (${t.message}); falling back to ephemeral source port — discovery may be unreliable on strict firewalls.`),f(0)):o({success:!1,error:Error(t.message)}))}).on(`listening`,()=>{p=!0,o({success:!0,iface:t,socket:l,send:l.send.bind(l)})}).on(`message`,(e,n)=>{n.interface=t.name,r(e,n)}).bind(e,c)};f(l)})}static interfaceAddress(e){return[`IPv4`,4].includes(e.family)?e.address:e.scopeid?`${e.address}%${e.name}`:e.address}};const y={reuseAddr:!0,srcPort:5353,interfaces:null,ttl:255,loopback:!0,debug:!1};var b=class extends s.EventEmitter{Config;ready;receiveSockets;sendSockets;interfaces;destroyed;constructor(e){super(),this.Config=Object.assign({},y,e),this.ready=!1,this.receiveSockets=[],this.sendSockets=[]}async init(){try{this.interfaces=g.getInterfaces(this.Config.interfaces||void 0)}catch(e){throw this.emitError(e),e}return this.emitDebug(`Scanner interfaces: ${c.default.inspect(this.interfaces)}`),await this.createReceiveSockets(),await this.createSendSockets(),this.receiveSockets.length&&this.sendSockets.length&&(this.ready=!0),this.ready}async createReceiveSockets(){if(!this.interfaces)return[];let e=this.interfaces.filter(e=>[p,4].includes(e.family)),t=this.interfaces.filter(e=>[m,6].includes(e.family));if(this.emitDebug(`Create receive sockets for${e.length?` IPv4`:``}${e.length&&t.length?` and`:``}${t.length?` IPv6`:``}`),e.length){let t=await v.createMulticastSocket({multicastAddress:d,multicastPort:f,interfaces:e,onMessage:this.onMessage.bind(this),socketError:this.socketError.bind(this)});t.success?this.receiveSockets.push(t):t.error&&this.emitWarn(t.error.message)}if(t.length){let e=await v.createMulticastSocket({multicastAddress:`FF02::FB`,multicastPort:f,interfaces:t,onMessage:this.onMessage.bind(this),socketError:this.socketError.bind(this)});e.success?this.receiveSockets.push(e):e.error&&this.emitWarn(e.error.message)}return this.receiveSockets}async createSendSockets(){if(this.interfaces){this.emitDebug(`Create send sockets on ${this.interfaces.length} interfaces/addresses.`);for(let e=0;e<this.interfaces.length;e++){let t=await v.createSendSocket(this.interfaces[e],this.Config,this.onMessage.bind(this),this.socketError.bind(this),this.emitWarn.bind(this));t.success?this.sendSockets.push(t):t.error&&this.emitWarn(t.error.message)}}}onMessage(e,t){let n;try{n=o.default.decode(e)}catch(e){return this.emitWarn(e)}this.emit(`packet`,n,t)}socketError(e){e.code===`EACCES`||e.code===`EADDRINUSE`||e.code===`EADDRNOTAVAIL`?this.emitError(e):this.emitWarn(e)}query(e,t){let n;if(typeof e==`string`)n=[{name:e,type:t||`ANY`}];else if(Array.isArray(e))n=e;else throw Error(`Query questions must be an array of mDNS query questions.`);let r={type:`query`,questions:n};this.emitDebug(`Send mDNS query: ${c.default.inspect(r)}`),this.send(r)}send(e){if(this.destroyed)return;let t=o.default.encode(e);e.type===`query`&&this.setUnicastResponseBit(t);for(let e=0;e<this.sendSockets.length;e++){let n=this.sendSockets[e];if(n.send&&n.iface)try{n.send(t,0,t.length,f,[`IPv4`,4].includes(n.iface.family)?d:`FF02::FB%`+n.iface.name),this.emitDebug(`Send packet on ${n.iface.address}`)}catch{}}}setUnicastResponseBit(e){let t=e.readUInt16BE(4),n=12;for(let r=0;r<t&&n<e.length;r++){for(;n<e.length&&e[n]!==0;)n+=e[n]+1;n+=1,n+=2,n<e.length&&(e[n]|=128),n+=2}}destroy(){this.destroyed=!0,this.ready=!1,this.removeAllListeners(),this.sendSockets.forEach(e=>{try{e.socket?.close()}catch{}}),this.sendSockets=[],this.receiveSockets.forEach(e=>{try{e.socket?.close()}catch{}}),this.receiveSockets=[]}emitError(e){this.emit(`error`,e)}emitWarn(e){this.emit(`warn`,e)}emitDebug(e){this.Config.debug&&this.emit(`debug`,e)}};const x={debug:!1};var S=class extends s.EventEmitter{Config;scanner;types;namedServices;packetListener;constructor(e,t){super(),this.packetListener=this.onPacket.bind(this),this.scanner=e,this.Config=Object.assign({},x,t),this.types=[],this.namedServices={},this.forwardEvents(this.scanner),this.reset()}reset(){this.removeMDNSListener(this.scanner),this.types=[],this.namedServices={},this.listenMDNSEvents(this.scanner)}forwardEvents(e){e.on(`error`,e=>{this.emitError(e)}).on(`warn`,e=>{this.emitWarn(e)}).on(`debug`,e=>{this.emitDebug(e)})}listenMDNSEvents(e){e.on(`packet`,this.packetListener)}removeMDNSListener(e){e.removeListener(`packet`,this.packetListener)}onPacket(e,t){switch(this.emitDebug(`Received packet type ${e.type} from ${t.address}.`),e.type){case`query`:this.emit(`query`,e,t);break;case`response`:this.emitDebug(`Received response packet from ${t.address} with ${e.answers?e.answers.length:0} answers and ${e.additionals?e.additionals.length:0} additionals.`),e.answers&&this.processAnswers(e.answers,t),e.additionals&&this.processAnswers(e.additionals,t);break}}processAnswers(e,t){this.emitDebug(`Processing answers or additionals...`);let n=this.processSRVAnswers(e);this.processTXTAnswers(e),this.processAAnswers(e),this.processAAAAAnswers(e),this.processPTRAnswers(e,t),n.forEach(e=>{this.emit(`discovered`,{type:`service`,data:this.namedServices[e]})})}processSRVAnswers(e){let t=[];return e.forEach(e=>{if(e.type!==`SRV`)return;this.emitDebug(`Processing SRV answer.`);let n=e.name.toString();t.includes(n)||t.push(n),this.namedServices[n]=this.namedServices[n]||{},this.namedServices[n].service=e,this.namedServices[n].host=e.data.target.toString(),this.namedServices[n].port=e.data.port}),t}processTXTAnswers(e){e.forEach(e=>{if(e.type!==`TXT`)return;this.emitDebug(`Processing TXT answer.`);let t=e.data;if(Array.isArray(t)&&t.length>1){let n=e.name.toString();this.namedServices[n]=this.namedServices[n]||{},this.namedServices[n].txt=this.answerDataToKeyValues(Buffer.concat(t))}else if(Buffer.isBuffer(t)){let n=e.name.toString();this.namedServices[n]=this.namedServices[n]||{},this.namedServices[n].txt=this.answerDataToKeyValues(t)}})}processAAnswers(e){e.forEach(e=>{if(e.type!==`A`)return;this.emitDebug(`Processing A answer.`);let t=e.name.toString(),n=e.data.toString();for(let e in this.namedServices)this.namedServices[e].host===t&&(this.namedServices[e].addresses=this.namedServices[e].addresses||[],this.namedServices[e].addresses.reduce((e,t)=>e||t.address===n,!1)||this.namedServices[e].addresses.push({family:p,address:n}))})}processAAAAAnswers(e){e.forEach(e=>{if(e.type!==`AAAA`)return;this.emitDebug(`Processing AAAA answer.`);let t=e.name.toString(),n=e.data.toString();for(let e in this.namedServices)this.namedServices[e].host===t&&(this.namedServices[e].addresses=this.namedServices[e].addresses||[],this.namedServices[e].addresses.reduce((e,t)=>e||t.address===n,!1)||this.namedServices[e].addresses.push({family:m,address:n}))})}processPTRAnswers(e,t){e.forEach(e=>{if(e.type!==`PTR`)return;this.emitDebug(`Processing PTR answer.`);let n=this.serviceTypeFromPTR(e),r=e.data.toString();n!==r&&(this.namedServices[r]=this.namedServices[r]||{},this.namedServices[r].name=r.replace(`.`+n,``),this.namedServices[r].rinfo=t)})}serviceTypeFromPTR(e){let t=e.data,n=/(?:^|^.+?(?:\.))(_.*)$/gm.exec(t.toString()),r=n?n[1]:t.toString();return this.types.includes(r)||(this.types.push(r),this.emit(`discovered`,{type:`type`,data:r}),this.emitDebug(`Scanning service type ${r}.`),this.scanner.query(r,`ANY`)),r}answerDataToKeyValues(e){let t=[],n={},r=0,i=e[r];for(;i;){let a=e.slice(r+1,r+1+i);t.push(a.toString());let o=/^([^=]+)=([^=]*)$/.exec(a.toString());o&&(n[o[1]]=o[2]),r=r+1+i,i=e[r]}return{strings:t,keyValuePairs:n}}emitError(e){this.emit(`error`,e)}emitWarn(e){this.emit(`warn`,e)}emitDebug(e){this.Config.debug&&this.emit(`debug`,e)}};function C(e){return e.startsWith(`192.168.`)?0:e.startsWith(`169.254.`)?1:2}const w=async(e=500)=>{e<10&&(e=10);let t=new b({debug:!0}),i=new S(t);if(i.on(`error`,e=>{if(!e.includes(`bind ENOENT`))throw Error(e)}),!await t.init())throw Error(`Failed to initialize mDNS scanner`);t.query(`_at1000_server._tcp.local`),await new Promise(t=>setTimeout(t,e));let a=[...new Set(Object.values(i.namedServices).filter(e=>e.service!==void 0).filter(e=>(e.service?.name)?.endsWith(`_at1000_server._tcp.local`)).flatMap(e=>{let t=e.addresses??[],r=e.port,i=t.filter(e=>e.family===`IPv4`).map(e=>n.r(e.address,r)),a=t.filter(e=>e.family===`IPv6`).map(e=>n.r(e.address,r));return[...i,...a]}))];t.destroy();let o=(await Promise.allSettled(a.map(async e=>({host:e,info:await new n.d((0,r.up)(fetch,()=>({baseUrl:`http://${n.r(e)}/v0`,timeout:1e3,parseRejected:(e,t)=>n.a(e,t.method)})),e).info()})))).filter(e=>e.status===`fulfilled`).map(e=>e.value),s=new Map;for(let e of o){let t=s.get(e.info.hostname);t?C(e.host)<C(t.host)&&s.set(e.info.hostname,e):s.set(e.info.hostname,e)}return[...s.values()]};var T=class extends n.t{static apiVersion=t.t;static findDevices(e=500){return w(e)}static async open(e,t){let r;try{let e=(0,i.readFileSync)(`/etc/at1000/project`,`utf8`).trim();r={kind:`project`,project:e,defaultLabel:e}}catch{r={kind:`remote`,defaultLabel:(0,a.hostname)()}}return await n.t.openBase(e,t,r)}};function E(){try{return(0,i.readFileSync)(`/etc/at1000/hostname`,`utf8`).trim()}catch{return}}exports.AT1000=T,exports.ApiError=n.n,exports.format_host_for_url=n.r,exports.host_without_port=n.i,exports.readInjectedHostname=E;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-CMqjfN_6.cjs"),t=require("./package-ByQuarMd.cjs"),n=require("./at1000-DuULyDOw.cjs");let r=require("up-fetch"),i=require("node:os");i=e.t(i,1);let a=require("node:fs"),o=require("dns-packet");o=e.t(o,1);let s=require("node:events"),c=require("node:util");c=e.t(c,1);let l=require("ip-address");l=e.t(l,1);let u=require("node:dgram");u=e.t(u,1);const d=`224.0.0.251`,f=5353,p=`IPv4`,m=`IPv6`,h=[p,4,m,6];var g=class e{static getInterfaces(t){return t?e.getInterfacesFromStrings(t):e.getAllInterfaces()}static getAllInterfaces(){let e=[],t=[],n=i.default.networkInterfaces();for(let[r,i]of Object.entries(n))t.includes(r)||(t.push(r),i?.forEach(t=>{t.internal||!h.includes(t.family)||/^(2002|2001):/gi.exec(t.address)||e.push({name:r,address:t.address,family:t.family,scopeid:t.scopeid})}));if(!e.length)throw Error(`No usable network interfaces returned by OS.`);return e}static getInterfacesFromStrings(t){let n=Array.isArray(t)?t:[t],r=this.getAllInterfaces().filter(t=>n.reduce((n,r)=>n||!!(e.stringMatchesAddress(r,t.address)||t.name===r),!1));if(!r||!r.length)throw Error(`No usable network interfaces returned by OS.`);return r}static stringMatchesAddress(e,t){let n,r;try{n=new l.default.Address4(e),r=new l.default.Address4(t)}catch{try{n=new l.default.Address6(e),r=new l.default.Address6(t)}catch{return!1}}return n.bigInt()===r.bigInt()}};const _={interfaces:[],reuseAddr:!0,ttl:255,loopback:!0,onMessage:(e,t)=>{console.log(`Message `+e.toString())},socketError:e=>{console.log(`Socket error `+e.message)}};var v=class e{static validateSettings(e){if(!e.multicastAddress)throw Error(`Socket settings require multicastAddress`);if(!e.multicastPort)throw Error(`Socket settings require multicastPort`)}static createMulticastSocket(t){return new Promise((n,r)=>{let i=Object.assign({},_,t);e.validateSettings(i);let a=u.default.createSocket({type:l.default.Address4.isValid(i.multicastAddress)?`udp4`:`udp6`,reuseAddr:i.reuseAddr}),o=!1;a.on(`error`,e=>{o?i.socketError(e):(a.close(),n({success:!1,error:e}))}).on(`listening`,()=>{o=!0,a.setMulticastTTL(i.ttl??255),a.setMulticastLoopback(i.loopback??!0);let t=e.addMulticastMemberships(a,i);if(!t.memberships.length){o=!1,a.close(),n({success:!1,error:Error(`No interface memberships for multicast address `+i.multicastAddress)});return}n(Object.assign({success:!0},t,{socket:a}))}).on(`message`,(e,t)=>{i.onMessage(e,t)}),a.bind({port:i.multicastPort,exclusive:!1})})}static addMulticastMemberships(t,n){let r=[],i=[],a=l.default.Address4.isValid(n.multicastAddress)?[p,4]:[m,6];return n.interfaces.forEach(o=>{if(a.includes(o.family))try{t.addMembership(n.multicastAddress,e.interfaceAddress(o)),r.push(o)}catch{i.push(o)}}),{memberships:r,failedMemberships:i}}static async createSendSocket(t,n,r,i,a){return new Promise(o=>{let s=[`IPv4`,4].includes(t.family)?`udp4`:`udp6`,c=e.interfaceAddress(t),l=n.srcPort??0,d=!1,f=e=>{let l=u.default.createSocket({type:s,reuseAddr:!!n.reuseAddr,reusePort:!0}),p=!1;l.on(`error`,t=>{p?i(t):(l.close(),e!==0&&!d?(d=!0,a?.(`mDNS send socket bind to ${c}:${e} failed (${t.message}); falling back to ephemeral source port — discovery may be unreliable on strict firewalls.`),f(0)):o({success:!1,error:Error(t.message)}))}).on(`listening`,()=>{p=!0,o({success:!0,iface:t,socket:l,send:l.send.bind(l)})}).on(`message`,(e,n)=>{n.interface=t.name,r(e,n)}).bind(e,c)};f(l)})}static interfaceAddress(e){return[`IPv4`,4].includes(e.family)?e.address:e.scopeid?`${e.address}%${e.name}`:e.address}};const y={reuseAddr:!0,srcPort:5353,interfaces:null,ttl:255,loopback:!0,debug:!1};var b=class extends s.EventEmitter{Config;ready;receiveSockets;sendSockets;interfaces;destroyed;constructor(e){super(),this.Config=Object.assign({},y,e),this.ready=!1,this.receiveSockets=[],this.sendSockets=[]}async init(){try{this.interfaces=g.getInterfaces(this.Config.interfaces||void 0)}catch(e){throw this.emitError(e),e}return this.emitDebug(`Scanner interfaces: ${c.default.inspect(this.interfaces)}`),await this.createReceiveSockets(),await this.createSendSockets(),this.receiveSockets.length&&this.sendSockets.length&&(this.ready=!0),this.ready}async createReceiveSockets(){if(!this.interfaces)return[];let e=this.interfaces.filter(e=>[p,4].includes(e.family)),t=this.interfaces.filter(e=>[m,6].includes(e.family));if(this.emitDebug(`Create receive sockets for${e.length?` IPv4`:``}${e.length&&t.length?` and`:``}${t.length?` IPv6`:``}`),e.length){let t=await v.createMulticastSocket({multicastAddress:d,multicastPort:f,interfaces:e,onMessage:this.onMessage.bind(this),socketError:this.socketError.bind(this)});t.success?this.receiveSockets.push(t):t.error&&this.emitWarn(t.error.message)}if(t.length){let e=await v.createMulticastSocket({multicastAddress:`FF02::FB`,multicastPort:f,interfaces:t,onMessage:this.onMessage.bind(this),socketError:this.socketError.bind(this)});e.success?this.receiveSockets.push(e):e.error&&this.emitWarn(e.error.message)}return this.receiveSockets}async createSendSockets(){if(this.interfaces){this.emitDebug(`Create send sockets on ${this.interfaces.length} interfaces/addresses.`);for(let e=0;e<this.interfaces.length;e++){let t=await v.createSendSocket(this.interfaces[e],this.Config,this.onMessage.bind(this),this.socketError.bind(this),this.emitWarn.bind(this));t.success?this.sendSockets.push(t):t.error&&this.emitWarn(t.error.message)}}}onMessage(e,t){let n;try{n=o.default.decode(e)}catch(e){return this.emitWarn(e)}this.emit(`packet`,n,t)}socketError(e){e.code===`EACCES`||e.code===`EADDRINUSE`||e.code===`EADDRNOTAVAIL`?this.emitError(e):this.emitWarn(e)}query(e,t){let n;if(typeof e==`string`)n=[{name:e,type:t||`ANY`}];else if(Array.isArray(e))n=e;else throw Error(`Query questions must be an array of mDNS query questions.`);let r={type:`query`,questions:n};this.emitDebug(`Send mDNS query: ${c.default.inspect(r)}`),this.send(r)}send(e){if(this.destroyed)return;let t=o.default.encode(e);e.type===`query`&&this.setUnicastResponseBit(t);for(let e=0;e<this.sendSockets.length;e++){let n=this.sendSockets[e];if(n.send&&n.iface)try{n.send(t,0,t.length,f,[`IPv4`,4].includes(n.iface.family)?d:`FF02::FB%`+n.iface.name),this.emitDebug(`Send packet on ${n.iface.address}`)}catch{}}}setUnicastResponseBit(e){let t=e.readUInt16BE(4),n=12;for(let r=0;r<t&&n<e.length;r++){for(;n<e.length&&e[n]!==0;)n+=e[n]+1;n+=1,n+=2,n<e.length&&(e[n]|=128),n+=2}}destroy(){this.destroyed=!0,this.ready=!1,this.removeAllListeners(),this.sendSockets.forEach(e=>{try{e.socket?.close()}catch{}}),this.sendSockets=[],this.receiveSockets.forEach(e=>{try{e.socket?.close()}catch{}}),this.receiveSockets=[]}emitError(e){this.emit(`error`,e)}emitWarn(e){this.emit(`warn`,e)}emitDebug(e){this.Config.debug&&this.emit(`debug`,e)}};const x={debug:!1};var S=class extends s.EventEmitter{Config;scanner;types;namedServices;packetListener;constructor(e,t){super(),this.packetListener=this.onPacket.bind(this),this.scanner=e,this.Config=Object.assign({},x,t),this.types=[],this.namedServices={},this.forwardEvents(this.scanner),this.reset()}reset(){this.removeMDNSListener(this.scanner),this.types=[],this.namedServices={},this.listenMDNSEvents(this.scanner)}forwardEvents(e){e.on(`error`,e=>{this.emitError(e)}).on(`warn`,e=>{this.emitWarn(e)}).on(`debug`,e=>{this.emitDebug(e)})}listenMDNSEvents(e){e.on(`packet`,this.packetListener)}removeMDNSListener(e){e.removeListener(`packet`,this.packetListener)}onPacket(e,t){switch(this.emitDebug(`Received packet type ${e.type} from ${t.address}.`),e.type){case`query`:this.emit(`query`,e,t);break;case`response`:this.emitDebug(`Received response packet from ${t.address} with ${e.answers?e.answers.length:0} answers and ${e.additionals?e.additionals.length:0} additionals.`),e.answers&&this.processAnswers(e.answers,t),e.additionals&&this.processAnswers(e.additionals,t);break}}processAnswers(e,t){this.emitDebug(`Processing answers or additionals...`);let n=this.processSRVAnswers(e);this.processTXTAnswers(e),this.processAAnswers(e),this.processAAAAAnswers(e),this.processPTRAnswers(e,t),n.forEach(e=>{this.emit(`discovered`,{type:`service`,data:this.namedServices[e]})})}processSRVAnswers(e){let t=[];return e.forEach(e=>{if(e.type!==`SRV`)return;this.emitDebug(`Processing SRV answer.`);let n=e.name.toString();t.includes(n)||t.push(n),this.namedServices[n]=this.namedServices[n]||{},this.namedServices[n].service=e,this.namedServices[n].host=e.data.target.toString(),this.namedServices[n].port=e.data.port}),t}processTXTAnswers(e){e.forEach(e=>{if(e.type!==`TXT`)return;this.emitDebug(`Processing TXT answer.`);let t=e.data;if(Array.isArray(t)&&t.length>1){let n=e.name.toString();this.namedServices[n]=this.namedServices[n]||{},this.namedServices[n].txt=this.answerDataToKeyValues(Buffer.concat(t))}else if(Buffer.isBuffer(t)){let n=e.name.toString();this.namedServices[n]=this.namedServices[n]||{},this.namedServices[n].txt=this.answerDataToKeyValues(t)}})}processAAnswers(e){e.forEach(e=>{if(e.type!==`A`)return;this.emitDebug(`Processing A answer.`);let t=e.name.toString(),n=e.data.toString();for(let e in this.namedServices)this.namedServices[e].host===t&&(this.namedServices[e].addresses=this.namedServices[e].addresses||[],this.namedServices[e].addresses.reduce((e,t)=>e||t.address===n,!1)||this.namedServices[e].addresses.push({family:p,address:n}))})}processAAAAAnswers(e){e.forEach(e=>{if(e.type!==`AAAA`)return;this.emitDebug(`Processing AAAA answer.`);let t=e.name.toString(),n=e.data.toString();for(let e in this.namedServices)this.namedServices[e].host===t&&(this.namedServices[e].addresses=this.namedServices[e].addresses||[],this.namedServices[e].addresses.reduce((e,t)=>e||t.address===n,!1)||this.namedServices[e].addresses.push({family:m,address:n}))})}processPTRAnswers(e,t){e.forEach(e=>{if(e.type!==`PTR`)return;this.emitDebug(`Processing PTR answer.`);let n=this.serviceTypeFromPTR(e),r=e.data.toString();n!==r&&(this.namedServices[r]=this.namedServices[r]||{},this.namedServices[r].name=r.replace(`.`+n,``),this.namedServices[r].rinfo=t)})}serviceTypeFromPTR(e){let t=e.data,n=/(?:^|^.+?(?:\.))(_.*)$/gm.exec(t.toString()),r=n?n[1]:t.toString();return this.types.includes(r)||(this.types.push(r),this.emit(`discovered`,{type:`type`,data:r}),this.emitDebug(`Scanning service type ${r}.`),this.scanner.query(r,`ANY`)),r}answerDataToKeyValues(e){let t=[],n={},r=0,i=e[r];for(;i;){let a=e.slice(r+1,r+1+i);t.push(a.toString());let o=/^([^=]+)=([^=]*)$/.exec(a.toString());o&&(n[o[1]]=o[2]),r=r+1+i,i=e[r]}return{strings:t,keyValuePairs:n}}emitError(e){this.emit(`error`,e)}emitWarn(e){this.emit(`warn`,e)}emitDebug(e){this.Config.debug&&this.emit(`debug`,e)}};function C(e){return e.startsWith(`192.168.`)?0:e.startsWith(`169.254.`)?1:2}function w(){try{return(0,a.readFileSync)(`/etc/at1000/hostname`,`utf8`).trim()||void 0}catch{return}}function T(){try{return(0,a.readFileSync)(`/etc/at1000/project`,`utf8`).trim()||void 0}catch{return}}async function E(e){return{host:e,info:await new n.d((0,r.up)(fetch,()=>({baseUrl:`http://${n.r(e)}/v0`,timeout:1e3,parseRejected:(e,t)=>n.a(e,t.method)})),e).info()}}const D=async()=>{let e=w();if(e)for(let t of[`${e}.local`,`host.containers.internal`])try{if((await E(t)).info.hostname===e)return t}catch{}},O=async(e=500)=>{e<10&&(e=10);let t=new b({debug:!0}),r=new S(t);if(r.on(`error`,e=>{if(!e.includes(`bind ENOENT`))throw Error(e)}),!await t.init())throw Error(`Failed to initialize mDNS scanner`);t.query(`_at1000_server._tcp.local`),await new Promise(t=>setTimeout(t,e));let i=[...new Set(Object.values(r.namedServices).filter(e=>e.service!==void 0).filter(e=>(e.service?.name)?.endsWith(`_at1000_server._tcp.local`)).flatMap(e=>{let t=e.addresses??[],r=e.port,i=t.filter(e=>e.family===`IPv4`).map(e=>n.r(e.address,r)),a=t.filter(e=>e.family===`IPv6`).map(e=>n.r(e.address,r));return[...i,...a]}))];t.destroy();let a=(await Promise.allSettled(i.map(E))).filter(e=>e.status===`fulfilled`).map(e=>e.value),o=new Map;for(let e of a){let t=o.get(e.info.hostname);t?C(e.host)<C(t.host)&&o.set(e.info.hostname,e):o.set(e.info.hostname,e)}let s=[...o.values()],c=w();if(!c)return s.map(e=>e.host);let l=s.findIndex(e=>e.info.hostname===c);if(l>=0)return s.unshift(...s.splice(l,1)),s.map(e=>e.host);let u=await D();return u?[u,...s.map(e=>e.host)]:s.map(e=>e.host)};var k=class extends n.t{static apiVersion=t.t;static findDevices(e=500){return O(e)}static isStandalone(){return T()!==void 0}static findLocalDevice(){return D()}static async open(e,t){let r=T(),a=r?{kind:`project`,project:r,defaultLabel:r}:{kind:`remote`,defaultLabel:(0,i.hostname)()};return await n.t.openBase(e,t,a)}};exports.AT1000=k,exports.ApiError=n.n,exports.format_host_for_url=n.r,exports.host_without_port=n.i;
|
|
2
2
|
//# sourceMappingURL=node.cjs.map
|