2023-11-18 15:53:54 +00:00
|
|
|
import { settingsStore as settings } from "../store/settingsStore.js";
|
2023-11-09 18:46:29 +00:00
|
|
|
|
2023-11-20 13:24:45 +00:00
|
|
|
function buildURL(params, endpoint) {
|
|
|
|
const url = "http://" + params.host + ":" + params.port + endpoint;
|
2023-11-18 15:53:54 +00:00
|
|
|
return url;
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 15:53:54 +00:00
|
|
|
async function apiGet(endpoint) {
|
2023-11-26 06:07:04 +00:00
|
|
|
try {
|
2023-11-20 13:24:45 +00:00
|
|
|
const response = await fetch(buildURL(settings.local, endpoint));
|
2023-11-18 15:53:54 +00:00
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`REST response not ok: ${response.statusText}`);
|
|
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
2023-11-26 06:07:04 +00:00
|
|
|
} catch(error) {
|
|
|
|
console.error("Error getting from REST:", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-18 15:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function apiPost(endpoint, payload = {}) {
|
|
|
|
try {
|
2023-11-20 13:24:45 +00:00
|
|
|
const response = await fetch(buildURL(settings.local, endpoint), {
|
2023-11-18 15:53:54 +00:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`REST response not ok: ${response.statusText}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error posting to REST:", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-23 06:04:04 +00:00
|
|
|
export async function getVersion() {
|
2023-11-23 06:31:28 +00:00
|
|
|
let data = await apiGet("/version").then((res) => {
|
|
|
|
return res;
|
|
|
|
});
|
2023-11-23 06:04:04 +00:00
|
|
|
return data.version;
|
|
|
|
//return data["version"];
|
2023-11-18 15:56:39 +00:00
|
|
|
}
|
|
|
|
|
2023-11-23 06:04:04 +00:00
|
|
|
export async function getConfig() {
|
2023-11-18 15:53:54 +00:00
|
|
|
return apiGet("/config");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setConfig(config) {
|
|
|
|
return apiPost("/config", config);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAudioDevices() {
|
|
|
|
return apiGet("/devices/audio");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSerialDevices() {
|
|
|
|
return apiGet("/devices/serial");
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 15:56:39 +00:00
|
|
|
export function setModemBeacon(enabled = false) {
|
|
|
|
return apiPost("/modem/beacon", { enabled: enabled });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function sendModemCQ() {
|
|
|
|
return apiPost("/modem/cqcqcq");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function sendModemPing(dxcall) {
|
2023-11-18 17:14:23 +00:00
|
|
|
return apiPost("/modem/ping_ping", { dxcall: dxcall });
|
2023-11-18 15:56:39 +00:00
|
|
|
}
|
|
|
|
|
2023-11-19 13:03:48 +00:00
|
|
|
export function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
|
|
|
return apiPost("/modem/send_arq_raw", {
|
2023-11-19 13:04:10 +00:00
|
|
|
mycallsign: mycall,
|
|
|
|
dxcallsign: dxcall,
|
|
|
|
data: data,
|
|
|
|
uuid: uuid,
|
|
|
|
});
|
2023-11-19 13:03:48 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 18:06:29 +00:00
|
|
|
export function sendModemTestFrame() {
|
|
|
|
return apiPost("/modem/send_test_frame");
|
|
|
|
}
|
|
|
|
|
2023-11-09 21:11:53 +00:00
|
|
|
export function startModem() {
|
2023-11-18 15:53:54 +00:00
|
|
|
return apiPost("/modem/start");
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 21:11:53 +00:00
|
|
|
export function stopModem() {
|
2023-11-18 15:53:54 +00:00
|
|
|
return apiPost("/modem/stop");
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
2023-11-13 17:50:46 +00:00
|
|
|
|
2023-11-18 16:10:01 +00:00
|
|
|
export function getModemState() {
|
2023-11-18 17:05:57 +00:00
|
|
|
return apiGet("/modem/state");
|
2023-11-17 21:36:37 +00:00
|
|
|
}
|