fix: support for adding custom services in bus

This commit is contained in:
pelikhan 2023-02-22 11:42:36 -08:00
Родитель 14a2fb989f
Коммит 33e1fc114b
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -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,