You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.9 KiB

7 days ago
import { BaseInterface } from "./base";
import { Variant, interface as iface } from "dbus-next";
const { method, property } = iface;
export class BaseService extends BaseInterface {
@property({ signature: "s" })
UUID;
@property({ signature: "b" })
Primary;
@property({ signature: "ao" })
get Characteristics() {
return this.characteristics.map((c) => c.path);
}
characteristics = [];
constructor(bus, path) {
super(bus, path, "org.bluez.GattService1");
}
addCharacteristic(char) {
this.characteristics.push(char);
}
getProperties() {
return {
UUID: new Variant("s", this.UUID),
Primary: new Variant("b", this.Primary),
Characteristics: new Variant("ao", this.Characteristics),
};
}
}
export class BaseCharacteritic extends BaseInterface {
@property({ signature: "o" })
Service;
@property({ signature: "s" })
UUID;
@property({ signature: "as" })
Flags;
@property({ signature: "b" })
Notifying = false;
constructor(bus, path, service, uuid, flags) {
super(bus, path, "org.bluez.GattCharacteristic1");
this.UUID = uuid;
this.Flags = flags;
this.Service = service.path;
}
@method({ inSignature: "a{sv}", outSignature: "ay" })
ReadValue(options) {
if (this.read) {
return this.read(options);
} else {
console.log("ReadValue not definied");
}
}
@method({ inSignature: "aya{sv}" })
WriteValue(value, options) {
if (this.write) {
this.write(value, options);
} else {
console.log("WriteValue not definied");
}
}
@method({})
StartNotify() {
console.log("not definied");
}
@method({})
StopNotify() {
console.log("not definied");
}
getProperties() {
return {
Service: new Variant("o", this.Service),
UUID: new Variant("s", this.UUID),
Flags: new Variant("as", this.Flags),
Value: new Variant("ay", []),
};
}
}