Major update
- Working client server interactions - Can create radio config - Needs radio testing
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user