зеркало из https://github.com/microsoft/jacdac-ts.git
fix: support for adding custom services in bus
This commit is contained in:
Родитель
14a2fb989f
Коммит
33e1fc114b
|
@ -185,6 +185,11 @@ export interface BusOptions {
|
|||
* Additional serial connection vendor ids
|
||||
*/
|
||||
serialVendorIds?: number[]
|
||||
|
||||
/**
|
||||
* Custom services
|
||||
*/
|
||||
services?: jdspec.ServiceSpec[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,6 +281,7 @@ export class JDBus extends JDNode {
|
|||
serviceProviderIdSalt,
|
||||
resetIn,
|
||||
serialVendorIds,
|
||||
services,
|
||||
} = options || {}
|
||||
|
||||
this._roleManagerClient = undefined
|
||||
|
@ -292,7 +298,6 @@ export class JDBus extends JDNode {
|
|||
|
||||
// some transport may be undefined
|
||||
transports?.filter(tr => !!tr).map(tr => this.addTransport(tr))
|
||||
|
||||
// tell loggers to send data, every now and then
|
||||
// send resetin packets
|
||||
this.on(SELF_ANNOUNCE, this.handleSelfAnnounce.bind(this))
|
||||
|
@ -301,7 +306,8 @@ export class JDBus extends JDNode {
|
|||
// grab the default role manager
|
||||
if (!disableRoleManager)
|
||||
this.on(DEVICE_CHANGE, this.handleRoleManager.bind(this))
|
||||
|
||||
// extra services
|
||||
if (services?.length) loadServiceSpecifications(services)
|
||||
// start all timers
|
||||
this.start()
|
||||
}
|
||||
|
|
|
@ -53,6 +53,11 @@ export function loadServiceSpecifications(
|
|||
const shortIds = new Set<string>(specs.map(s => s.shortId))
|
||||
for (const spec of specifications) {
|
||||
if (serviceClasses.has(spec.classIdentifier)) {
|
||||
const existingSpec = specs.find(
|
||||
s => s.classIdentifier === spec.classIdentifier
|
||||
)
|
||||
if (JSON.stringify(existingSpec) === JSON.stringify(spec))
|
||||
continue // inserting a duplicate, ignore
|
||||
errors.push({
|
||||
message: "classIdentifier already in use",
|
||||
spec,
|
||||
|
|
Загрузка…
Ссылка в новой задаче