add helper function for setting advert lat lon

This commit is contained in:
liamcottle 2025-02-15 22:15:25 +13:00
parent 6469b815b1
commit e2d2ab7cf8
2 changed files with 32 additions and 1 deletions

View file

@ -292,7 +292,7 @@
const lat = Math.floor(-38.661727955271765 * 1000000);
const lon = Math.floor(178.0236810462527 * 1000000);
console.log(lat, lon);
await this.connection.sendCommandSetAdvertLatLon(lat, lon);
await this.connection.setAdvertLatLong(lat, lon);
},
async sendCommandAddUpdateContact() {
const publicKey = new Uint8Array([148, 63, 175, 162, 88, 212, 192, 40, 214, 185, 213, 140, 42, 145, 194, 186, 70, 71, 112, 68, 0, 192, 65, 4, 105, 143, 230, 50, 162, 79, 247, 192]);

View file

@ -434,6 +434,37 @@ class Connection extends EventEmitter {
});
}
setAdvertLatLong(latitude, longitude) {
return new Promise(async (resolve, reject) => {
try {
// resolve promise when we receive ok
const onOk = () => {
this.off(Constants.ResponseCodes.Ok, onOk);
this.off(Constants.ResponseCodes.Err, onErr);
resolve();
}
// reject promise when we receive err
const onErr = () => {
this.off(Constants.ResponseCodes.Ok, onOk);
this.off(Constants.ResponseCodes.Err, onErr);
reject();
}
// listen for events
this.once(Constants.ResponseCodes.Ok, onOk);
this.once(Constants.ResponseCodes.Err, onErr);
// set advert lat lon
await this.sendCommandSetAdvertLatLon(latitude, longitude);
} catch(e) {
reject(e);
}
});
}
setTxPower(txPower) {
return new Promise(async (resolve, reject) => {
try {