generated from AMRC-FactoryPlus/acs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support @amrc-factoryplus/sparkplug-app. (#7)
* Fetch device addresses from the Directory. * Fetch full service records from the Directory. * Provide a Command Escalation service interface.
- Loading branch information
Showing
6 changed files
with
223 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Factory+ NodeJS Utilities | ||
* Command Escalation service interface. | ||
* Copyright 2023 AMRC. | ||
*/ | ||
|
||
import { Address } from "../sparkplug/util.js"; | ||
import { Service } from "../uuids.js"; | ||
|
||
import { ServiceInterface } from "./service-interface.js"; | ||
|
||
export default class CmdEsc extends ServiceInterface { | ||
constructor (fplus) { | ||
super(fplus); | ||
this.service = Service.Command_Escalation; | ||
this.log = this.debug.log.bind(this.debug, "cmdesc"); | ||
} | ||
|
||
async request_cmd ({ address, name, type, value }) { | ||
const [st] = await this.fetch({ | ||
method: "POST", | ||
url: `v1/address/${address}`, | ||
body: { name, type, value }, | ||
}); | ||
if (st != 200) | ||
this.throw(`Can't set metric ${name} of ${address}`, st); | ||
} | ||
|
||
async rebirth (address) { | ||
const ctrl = address.isDevice() ? "Device Control" : "Node Control"; | ||
await this.request_cmd({ | ||
address: address, | ||
name: `${ctrl}/Rebirth`, | ||
type: "Boolean", | ||
value: true, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.