From f6f376f268cf36ce157642e8563d1193e44a5f4b Mon Sep 17 00:00:00 2001 From: "cheetah.cat" Date: Wed, 17 Apr 2024 17:27:51 +0200 Subject: [PATCH] added tetracontrol support --- config.json | 11 ++++- html_config/index.html | 34 ++++++++++++- index.js | 3 ++ types/connectors/TetraControlConnector.js | 58 +++++++++++++++++++++++ types/connectors/index.js | 4 +- 5 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 types/connectors/TetraControlConnector.js diff --git a/config.json b/config.json index 8bf2238..42bc122 100644 --- a/config.json +++ b/config.json @@ -50,7 +50,14 @@ "username": "test", "password": "testsucks", "duplexTimeout": 300 - } + }, + "tetracontrol": { + "enabled": true, + "endpoint": "10.13.123.123:80", + "username": "user", + "password": "password", + "duplexTimeout": 300 + } }, "pagers": { "birdyslim": { @@ -71,4 +78,4 @@ }, "deliveryPresets": { } -} \ No newline at end of file +} diff --git a/html_config/index.html b/html_config/index.html index 7e16a9f..f906516 100644 --- a/html_config/index.html +++ b/html_config/index.html @@ -141,6 +141,32 @@ + + + + TETRACONTROL + + + + + + + + + + + + + + + + + + + + + + LoRaWAN @@ -330,6 +356,7 @@ { k: 'Dummy', v: 'dummy' }, { k: 'POCSAG GW', v: 'pocsag' }, { k: 'DAPNET', v: 'dapnet' }, + { k: 'TETRAControl', v: 'tetracontrol' }, { k: 'e*Cityruf inetgw', v: 'ecityruf' }, { k: 'e*Cityruf Puppeteer', v: 'em-p-cityruf' }, @@ -366,6 +393,11 @@ dapnet: { enabled: null, duplexTimeout: null, }, + + tetracontrol: { + enabled: null, duplexTimeout: null, + }, + ecityruf: { enabled: null, duplexTimeout: null, }, @@ -452,4 +484,4 @@ - \ No newline at end of file + diff --git a/index.js b/index.js index 58de35b..e9dbef5 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,9 @@ if (!!config.connectors.emPuppettering && config.connectors.emPuppettering.enabl if (!!config.connectors.ecityruf && config.connectors.pagernetzAT.enabled === true) { types.ConnectorRegistry.register(new types.Connectors.PagernetzConnetorAT(connection)) } +if (!!config.connectors.tetracontrol && config.connectors.tetracontrol.enabled === true) { + types.ConnectorRegistry.register(new types.Connectors.TetraControlConnector(connection)) +} types.ConnectorRegistry.register(new types.Connectors.DummyConnector()) diff --git a/types/connectors/TetraControlConnector.js b/types/connectors/TetraControlConnector.js new file mode 100644 index 0000000..4bac09d --- /dev/null +++ b/types/connectors/TetraControlConnector.js @@ -0,0 +1,58 @@ +const Connector = require("./Connector") +const config = require('../../config.json') +const md5 = require('md5') +const axios = require('axios') +const WebSocket = require('ws') + +class TetraControlConnector extends Connector { + constructor (amqpConnMngr) { + super(amqpConnMngr) + this.name = "tetracontrol" + this.duplexCapable = false + } + async transmitMessage(msg, params) { + const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) + if (params.length < 1) return false + const target = params[0] + //if (target.split('#').length !== 2) throw 'No valid DAPNET Parameter ' + //const transmitterGroup = target.split('#')[ 0 ], callsign = target.split('#')[ 1 ] + /*const dapnetRequest = { + text: msg.payload, + callSignNames: [ callsign ], + transmitterGroupNames: [ transmitterGroup ] + }*/ + + const token = Buffer.from(`${ config.connectors.tetracontrol.username }:${ config.connectors.tetracontrol.password }`, 'utf8').toString('base64'); + const headers = { + Authorization: `Basic ${token}`, + } + const ws = new WebSocket(`ws://${ config.connectors.tetracontrol.endpoint }/live.json?MaxAlter=3600`, { headers }); + return new Promise((res, rej) => { + ws.on('open', function open() { + console.log('WebSocket connected'); + const jsonData = { + text: msg.payload, + destSSI: target + '', + ProtocolID: 9, + radioID: 1, + type: "sds" + } + ws.send(JSON.stringify(jsonData)) + ws.close() + }) + ws.on('close',res) + ws.on('error',rej) + + }) + .then(() => { + this.connectorRegistry.reportState(msg, UUID, 'routed') + return true + }) + .catch((err) => { + console.error(err ) + this.connectorRegistry.reportFail(msg, UUID) + return false + }) + } +} +module.exports = TetraControlConnector diff --git a/types/connectors/index.js b/types/connectors/index.js index 6f29b74..ad5e535 100644 --- a/types/connectors/index.js +++ b/types/connectors/index.js @@ -23,8 +23,10 @@ module.exports = { PagernetzConnetorAT: require('./PagernetzConnetorAT'), + TetraControlConnector: require("./TetraControlConnector"), + LoRaWANConnector: require("./LoRaWANConnector"), POCSAGConnector: require("./POCSAGConnector"), DummyConnector: require("./DummyConnector"), Connector: require("./Connector"), -} \ No newline at end of file +}