Finalizing #9
- Added service handler for system services - Control OP25 from service handler - Generate and save OP25 config file - Handlers for OP25
This commit is contained in:
@@ -1,14 +1,84 @@
|
||||
import { P25ConfigGenerator, NBFMConfigGenerator } from './modules/op25ConfigGenerators.mjs';
|
||||
import { getAllPresets } from '../modules/radioPresetHandler.mjs';
|
||||
import { startService, stopService } from '../modules/serviceHandler.mjs';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
|
||||
let currentSystem = undefined;
|
||||
|
||||
/**
|
||||
* Creates configuration based on the preset and restarts the OP25 service.
|
||||
* @param {Object} preset The preset object containing system configuration.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const createConfigAndRestartService = async (systemName, preset) => {
|
||||
const { mode, frequencies, trunkFile, whitelistFile } = preset;
|
||||
|
||||
let generator;
|
||||
if (mode === 'p25') {
|
||||
console.log("Using P25 Config Generator based on preset mode", systemName, mode);
|
||||
generator = new P25ConfigGenerator({
|
||||
systemName,
|
||||
controlChannels: frequencies,
|
||||
tagsFile: trunkFile,
|
||||
whitelistFile: whitelistFile !== 'none' ? whitelistFile : undefined
|
||||
});
|
||||
} else if (mode === 'nbfm') {
|
||||
console.log("Using NBFM Config Generator based on preset mode", systemName, mode);
|
||||
generator = new NBFMConfigGenerator({
|
||||
systemName,
|
||||
frequencies,
|
||||
tagsFile: trunkFile
|
||||
});
|
||||
} else {
|
||||
throw new Error(`Unsupported mode: ${mode}`);
|
||||
}
|
||||
|
||||
const op25FilePath = process.env.OP25_FULL_PATH || './'; // Default to current directory if OP25_FULL_PATH is not set
|
||||
const op25ConfigPath = `${op25FilePath}${op25FilePath.endsWith('/') ? 'active.cfg.json' : '/active.cfg.json'}`;
|
||||
await generator.exportToFile(op25ConfigPath);
|
||||
|
||||
// Restart the service
|
||||
await stopService('op25');
|
||||
await startService('op25');
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens the OP25 service for the specified system.
|
||||
* @param {string} systemName The name of the system to open.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const openOP25 = async (systemName) => {
|
||||
currentSystem = systemName;
|
||||
}
|
||||
|
||||
// Retrieve preset for the specified system name
|
||||
const presets = await getAllPresets();
|
||||
const preset = presets[systemName];
|
||||
|
||||
console.log("Found preset:", preset);
|
||||
|
||||
if (!preset) {
|
||||
throw new Error(`Preset for system "${systemName}" not found.`);
|
||||
}
|
||||
|
||||
await createConfigAndRestartService(systemName, preset);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Closes the OP25 service.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const closeOP25 = async () => {
|
||||
currentSystem = undefined;
|
||||
}
|
||||
await stopService('op25');
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the current system.
|
||||
* @returns {Promise<string | undefined>} The name of the current system.
|
||||
*/
|
||||
export const getCurrentSystem = async () => {
|
||||
return currentSystem;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user