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.

138 lines
2.8 KiB

7 days ago
import { BaseInterface } from "./base";
import { Variant, interface as iface } from "dbus-next";
const { method, property, Interface } = iface;
export class BaseApplication extends BaseInterface {
services = [];
constructor(bus, path) {
super(bus, path, "org.freedesktop.DBus.ObjectManager");
}
addService(service) {
this.services.push(service);
}
@method({ outSignature: "a{oa{sa{sv}}}" })
GetManagedObjects(val) {
const reply = {};
for (const service of this.services) {
reply[service.path] = {
[service.$name]: service.getProperties(),
};
for (const char of service.characteristics) {
reply[char.path] = {
[char.$name]: char.getProperties(),
};
}
}
return reply;
}
}
7 days ago
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;
@property({ signature: "ay" })
Value = [];
7 days ago
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() {
if (this.startNotify) {
this.startNotify();
} else {
console.log("not definied");
}
7 days ago
}
@method({})
StopNotify() {
if (this.stopNotify) {
this.stopNotify();
} else {
console.log("not definied");
}
}
notify(value) {
this.Value = value;
Interface.emitPropertiesChanged(this, { Value: value });
7 days ago
}
getProperties() {
return {
Service: new Variant("o", this.Service),
UUID: new Variant("s", this.UUID),
Flags: new Variant("as", this.Flags),
Value: new Variant("ay", []),
};
}
}