Major update

- Working client server interactions
- Can create radio config
- Needs radio testing
This commit is contained in:
Logan Cusano
2023-02-18 20:41:43 -05:00
parent c8c75e8b37
commit ce072d9287
25 changed files with 1114 additions and 39 deletions

View File

@@ -0,0 +1,161 @@
exports.P25 = class P25ConfigGenerator {
constructor({systemName, controlChannelsString, tagsFile}) {
this.channels = new channelConfig({
"systemName": systemName,
"enableAnalog": "off",
"demodType": "cqpsk",
"cqpskTracking": true,
"filterType": "rc"
});
this.devices = new deviceConfig({
"gain": "LNA:36"
});
this.trunking = new trunkingConfig({
"module": "tk_p25.py",
"systemName": systemName,
"controlChannelsString": controlChannelsString,
"tagsFile": tagsFile
});
this.audio = new audioConfig({});
this.terminal = new terminalConfig({});
}
}
exports.NBFM = class NBFMConfigGenerator {
constructor({systemName, frequency, nbfmSquelch = -70}) {
this.channels = new channelConfig({
"channelName": systemName,
"enableAnalog": "on",
"nbfmSquelch": nbfmSquelch,
"frequency": frequency,
"demodType": "fsk4",
"filterType": "widepulse"
});
this.devices = new deviceConfig({
"gain": "LNA:32"
});
this.audio = new audioConfig({});
this.terminal = new terminalConfig({});
}
}
class channelConfig {
constructor({
channelName = "Voice_ch1",
device = "sdr0",
systemName,
metaStreamName,
demodType, // cqpsk: P25; fsk4: everything else
cqpskTracking,
trackingThreshold = 120,
trackingFeedback = 0.75,
destination = "udp://127.0.0.1:23456",
excess_bw = 0.2,
filterType = "rc", // rc: P25; widepulse: analog
ifRate = 24000,
plot = "",
symbolRate = 4800,
enableAnalog, //[on, off, auto]
nbfmDeviation = 4000, // only needed if analog is enabled
nbfmSquelch = -50, // only needed if analog is enabled
frequency, // only needed if analog is enabled
blacklist,
whitelist,
cryptKeys
}){
// Core Configs
this.name = channelName;
this.device = device;
this.demod_type = demodType;
this.destination = destination;
this.excess_bw = excess_bw;
this.filter_type = filterType;
this.if_rate = ifRate;
this.plot = plot;
this.symbol_rate = symbolRate;
this.enable_analog = enableAnalog;
// P25 config
if (!enableAnalog || enableAnalog === "off" || systemName) this.trunking_sysname = systemName;
if (!enableAnalog || enableAnalog === "off" || systemName && metaStreamName) this.meta_stream_name = metaStreamName ?? "";
if (!enableAnalog || enableAnalog === "off" || systemName) this.cqpsk_tracking = cqpskTracking;
if (!enableAnalog || enableAnalog === "off" || systemName) this.tracking_threshold = trackingThreshold;
if (!enableAnalog || enableAnalog === "off" || systemName) this.tracking_feedback = trackingFeedback;
if (!enableAnalog || enableAnalog === "off" || systemName && blacklist) this.blacklist = blacklist ?? "";
if (!enableAnalog || enableAnalog === "off" || systemName && whitelist) this.whitelist = whitelist ?? "";
if (!enableAnalog || enableAnalog === "off" || systemName && cryptKeys) this.crypt_keys = cryptKeys ?? "";
// Analog config
if (enableAnalog === "on" || enableAnalog === "auto") this.nbfm_deviation = nbfmDeviation;
if (enableAnalog === "on" || enableAnalog === "auto") this.nbfm_squelch = nbfmSquelch;
if (enableAnalog === "on" || enableAnalog === "auto") this.frequency = frequency;
}
}
class deviceConfig {
constructor({args = "rtl", gain = "LNA:32", gainMode = false, name = "sdr0", offset = 0, ppm = 0.0, sampleRate = 1920000, tunable=true}) {
this.args = args
this.gains = gain
this.gain_mode = gainMode
this.name = name
this.offset = offset
this.ppm = ppm
this.rate = sampleRate
this.usable_bw_pct = 0.85
this.tunable = tunable
}
}
class trunkingConfig {
/**
*
* @param {object} *
*/
constructor({module, systemName, controlChannelsString, tagsFile = "", nac = "0x0", wacn = "0x0", cryptBehavior = 2, whitelist = "", blacklist = ""}) {
this.module = module;
this.chans = [{
"nac": nac,
"wacn": wacn,
"sysname": systemName,
"control_channel_list": controlChannelsString,
"whitelist": whitelist,
"blacklist": blacklist,
"tgid_tags_file": tagsFile,
"tdma_cc": false,
"crypt_behavior": cryptBehavior
}];
}
}
class audioConfig {
constructor({module = "sockaudio.py", port = 23456, deviceName = "default"}) {
this.module = module;
this.instances = [{
"instance_name": "audio0",
"device_name": deviceName,
"udp_port": port,
"audio_gain": 1.0,
"number_channels": 1
}];
}
}
class metadataStreamConfig {
constructor({}) {
this.module = "";
this.streams = [];
}
}
class terminalConfig {
constructor({module = "terminal.py", terminalType = "http:0.0.0.0:8080"}) {
this.module = module;
this.terminal_type = terminalType;
this.curses_plot_interval= 0.1;
this.http_plot_interval= 1.0;
this.http_plot_directory = "../www/images";
this.tuning_step_large= 1200;
this.tuning_step_small = 100;
}
}

View File

@@ -3,6 +3,8 @@ const { DebugBuilder } = require("../utilities/debugBuilder.js");
const log = new DebugBuilder("client", "updatePresets");
// Modules
const fs = require('fs');
const path = require("path");
const converter = require("convert-units");
/**
* Write the given presets to the JSON file
@@ -10,7 +12,8 @@ const fs = require('fs');
* @param {function} callback The function to be called when this wrapper completes
*/
function writePresets(presets, callback = undefined) {
fs.writeFile("../config/radioPresets.json", JSON.stringify(presets), (err) => {
log.DEBUG(`${__dirname}`);
fs.writeFile("./config/radioPresets.json", JSON.stringify(presets), (err) => {
// Error checking
if (err) throw err;
log.DEBUG("Write Complete");
@@ -37,7 +40,7 @@ function sanitizeFrequencies(frequenciesArray) {
/**
* Function to convert a string or a float into the integer type needed to be saved
* @param frequency Could be a string, number or float,
* @returns {number|number|*} Return the value to be saved in Hz format ("154875000" = 154.875MHz)
* @returns {number|number|*} Return the value to be saved in Hz format ("154.875"MHz format = "154875000")
*/
function convertFrequencyToHertz(frequency){
// check if the passed value is a number
@@ -50,18 +53,7 @@ function convertFrequencyToHertz(frequency){
else {
log.DEBUG(`${frequency} is a float value.`);
// Convert to a string to remove the decimal in place and then correct the length
frequency = frequency.toString();
// One extra digit checked for the '.' included in the string
if (frequency.length >= 8 && frequency.length <= 10) return parseInt(frequency.replace(".", ""));
else if (frequency.length <= 7) {
// Check to see if the frequency is 1s, 10s or 100s of MHz
let zerosToBeRemoved = 3 - frequency.split(".")[0].length;
// Need to add more 0s since it was in MHz format
let neededZeros = (9 - frequency.length) - zerosToBeRemoved;
frequency = frequency.replace(".", "") + '0'.repeat(neededZeros)
return parseInt(frequency);
}
return converter(frequency).from("MHz").to("Hz");
}
} else {
log.DEBUG(`${frequency} is not a number`);
@@ -76,7 +68,8 @@ function convertFrequencyToHertz(frequency){
* @returns {any} The object containing the different systems the bot is near
*/
exports.getPresets = function getPresets() {
return JSON.parse(fs.readFileSync("../config/radioPresets.json"));
log.DEBUG(`Getting presets from directory: '${__dirname}'`);
return JSON.parse(fs.readFileSync( "./config/radioPresets.json"));
}
/**