initial commit
This commit is contained in:
73
RotClient.js
Normal file
73
RotClient.js
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Implementation of a simple client for simple_rotator_interface_v -- https://remoteqth.com/w/doku.php?id=simple_rotator_interface_v
|
||||
*/
|
||||
export default class RotClient {
|
||||
constructor(label, clientConfig) {
|
||||
this.label = label;
|
||||
this.ip = clientConfig.ip;
|
||||
this.bands = clientConfig.bands;
|
||||
this.startOffset = null;
|
||||
|
||||
setInterval(async () => {
|
||||
console.log(`${this.label}: azi ${await this.readAzi()}, adc ${await this.readAdc()}, status ${await this.readStatus()}`);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
hasBand(band) {
|
||||
return this.bands.includes(band);
|
||||
}
|
||||
|
||||
turn(az) {
|
||||
fetch(`http://${this.ip}:88/`, {
|
||||
"body": "ROT=" + az,
|
||||
"method": "POST",
|
||||
}).catch(() => {});
|
||||
console.log(`Turning ${this.label} to ${az}°...`);
|
||||
}
|
||||
|
||||
async readAzi() {
|
||||
try {
|
||||
if (this.startOffset === null) {
|
||||
this.startOffset = await this.readOffset();
|
||||
console.log(`${this.label} Set the initial offset to ${this.startOffset}.`);
|
||||
}
|
||||
const resp = await fetch(`http://${this.ip}:88/readAZ`);
|
||||
return this.startOffset + parseInt(await resp.text(), 10);
|
||||
} catch(ex) {
|
||||
console.error(`${this.label}: Failed to read azimuth:`, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async readAdc() {
|
||||
try {
|
||||
const resp = await fetch(`http://${this.ip}:88/readADC`);
|
||||
return parseFloat(await resp.text());
|
||||
} catch(ex) {
|
||||
console.error(`${this.label}: Failed to read ADC:`, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async readStatus() {
|
||||
try {
|
||||
const resp = await fetch(`http://${this.ip}:88/readStat`);
|
||||
return parseInt(await resp.text(), 10);
|
||||
} catch(ex) {
|
||||
console.error(`${this.label}: Failed to read status:`, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async readOffset() {
|
||||
try {
|
||||
const resp = await fetch(`http://${this.ip}:88/readStart`);
|
||||
return parseInt(await resp.text(), 10);
|
||||
} catch(ex) {
|
||||
console.error(`${this.label}: Failed to read the initial offset:`, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user