From 317664677d98fd71d1f2eef1ac0d8f315860b3fb Mon Sep 17 00:00:00 2001 From: cheetah Date: Thu, 24 Nov 2022 20:11:04 +0000 Subject: [PATCH] direct identifiers for the eMessage network --- index.js | 8 +++- types/connectors/eCityrufConnector.js | 2 - types/connectors/eMessageConnector.js | 40 ++++++++++++++++--- .../connectors/eMessagePuppeteerConnector.js | 37 +++++++++++++++-- types/connectors/index.js | 22 +++++++++- 5 files changed, 94 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 685a4ca..a1bb843 100644 --- a/index.js +++ b/index.js @@ -22,10 +22,14 @@ if (!!config.connectors.ecityruf && config.connectors.ecityruf.enabled === true) types.ConnectorRegistry.register(new types.Connectors.eCityrufConnector(connection)) } if (!!config.connectors.emessage && config.connectors.emessage.enabled === true) { - types.ConnectorRegistry.register(new types.Connectors.eMessageConnector(connection)) + types.ConnectorRegistry.register(new types.Connectors.eMessageAlertManagerConnectorBase(connection)) + types.ConnectorRegistry.register(new types.Connectors.eMessageAlertManagerConnectorCityruf(connection)) + types.ConnectorRegistry.register(new types.Connectors.eMessageAlertManagerConnectorTwoWays(connection)) } if (!!config.connectors.emPuppettering && config.connectors.emPuppettering.enabled === true) { - types.ConnectorRegistry.register(new types.Connectors.eMessagePuppeteerConnector(connection)) + types.ConnectorRegistry.register(new types.Connectors.eMessagePuppeteerConnectorBase(connection)) + types.ConnectorRegistry.register(new types.Connectors.eMessagePuppeteerConnectorCityruf(connection)) + types.ConnectorRegistry.register(new types.Connectors.eMessagePuppeteerConnectorTwoWays(connection)) } diff --git a/types/connectors/eCityrufConnector.js b/types/connectors/eCityrufConnector.js index c6c9517..025f99d 100644 --- a/types/connectors/eCityrufConnector.js +++ b/types/connectors/eCityrufConnector.js @@ -15,7 +15,6 @@ class eCityrufConnector extends Connector { const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) if (params.length !== 1) return false - const $device = msg.routingParams.device let payloadBuffer = Buffer.from(msg.payload) const boskryptSupport = require("../DeviceRegistry").Devices[ $device ].supportBOSkrypt || false @@ -28,7 +27,6 @@ class eCityrufConnector extends Connector { } } - const cityrufRequest = require('querystring').stringify({ service: 1, class: 7, diff --git a/types/connectors/eMessageConnector.js b/types/connectors/eMessageConnector.js index a1c5280..5405998 100644 --- a/types/connectors/eMessageConnector.js +++ b/types/connectors/eMessageConnector.js @@ -3,19 +3,22 @@ const config = require('../../config.json') const md5 = require('md5') const axios = require('axios') // [ "ecityruf", "123456789" ] -class eCityrufConnector extends Connector { +class eMessageAlertManagerConnectorBase extends Connector { constructor (amqpConnMngr) { super(amqpConnMngr) this.name = "emessage" + this.defaultServiceName = "" this.duplexCapable = true this.supportBOSkrypt = true } async transmitMessage(msg, params) { const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) const target = params[0] - if (target.split('#').length !== 2) throw 'No valid eMessage Parameter ' - const serviceName = target.split('#')[ 0 ], identifier = target.split('#')[ 1 ] - // eCityruf#8907737 + + const overwriteIdentifier = target.indexOf('#') > -1 + //if (target.split('#').length !== 2) throw 'No valid eMessage Parameter ' + const serviceName = overwriteIdentifier ? target.split('#')[ 0 ] : this.defaultServiceName, + identifier = overwriteIdentifier ? target.split('#')[ 1 ] : target const $device = msg.routingParams.device let payloadBuffer = Buffer.from(msg.payload) @@ -152,4 +155,31 @@ class eCityrufConnector extends Connector { } } -module.exports = eCityrufConnector \ No newline at end of file + + +class eMessageAlertManagerConnectorCityruf extends eMessageAlertManagerConnectorBase { + constructor (amqpConnMngr) { + super(amqpConnMngr) + this.name = "em-a-cityruf" + this.defaultServiceName = "eCityruf" + this.duplexCapable = true + this.supportBOSkrypt = true + } +} +class eMessageAlertManagerConnectorTwoWays extends eMessageAlertManagerConnectorBase { + constructor (amqpConnMngr) { + super(amqpConnMngr) + this.name = "em-a-twoways" + this.defaultServiceName = "2wayS" + this.duplexCapable = true + this.supportBOSkrypt = true + } +} + + + +module.exports = { + eMessageAlertManagerConnectorBase, + eMessageAlertManagerConnectorCityruf, + eMessageAlertManagerConnectorTwoWays +} \ No newline at end of file diff --git a/types/connectors/eMessagePuppeteerConnector.js b/types/connectors/eMessagePuppeteerConnector.js index e8c199e..da433ef 100644 --- a/types/connectors/eMessagePuppeteerConnector.js +++ b/types/connectors/eMessagePuppeteerConnector.js @@ -6,18 +6,22 @@ const axios = require('axios') const puppeteer = require('puppeteer') function sleep(ms) { return new Promise(r=>setTimeout(r, ms))} // [ "ecityruf", "123456789" ] -class eMessagePuppeteerConnector extends Connector { +class eMessagePuppeteerConnectorBase extends Connector { constructor (amqpConnMngr) { super(amqpConnMngr) this.name = "em-puppet" + this.defaultServiceName = "" this.duplexCapable = true this.supportBOSkrypt = true } async transmitMessage(msg, params) { const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) const target = params[0] - if (target.split('#').length !== 2) throw 'No valid eMessage Parameter ' - const serviceName = target.split('#')[ 0 ], identifier = target.split('#')[ 1 ] + + const overwriteIdentifier = target.indexOf('#') > -1 + //if (target.split('#').length !== 2) throw 'No valid eMessage Parameter ' + const serviceName = overwriteIdentifier ? target.split('#')[ 0 ] : this.defaultServiceName, + identifier = overwriteIdentifier ? target.split('#')[ 1 ] : target const $device = msg.routingParams.device let payloadBuffer = Buffer.from(msg.payload) @@ -116,4 +120,29 @@ class eMessagePuppeteerConnector extends Connector { } } } -module.exports = eMessagePuppeteerConnector \ No newline at end of file + +class eMessagePuppeteerConnectorCityruf extends eMessagePuppeteerConnectorBase { + constructor (amqpConnMngr) { + super(amqpConnMngr) + this.name = "em-p-cityruf" + this.defaultServiceName = "1" + this.duplexCapable = true + this.supportBOSkrypt = true + } +} +class eMessagePuppeteerConnectorTwoWays extends eMessageAlertManagerConnectorBase { + constructor (amqpConnMngr) { + super(amqpConnMngr) + this.name = "em-p-twoways" + this.defaultServiceName = "7" + this.duplexCapable = true + this.supportBOSkrypt = true + } +} + + +module.exports = { + eMessagePuppeteerConnectorBase, + eMessagePuppeteerConnectorCityruf, + eMessagePuppeteerConnectorTwoWays +} \ No newline at end of file diff --git a/types/connectors/index.js b/types/connectors/index.js index d3a5118..1ef641d 100644 --- a/types/connectors/index.js +++ b/types/connectors/index.js @@ -1,8 +1,26 @@ +const { + eMessageAlertManagerConnectorBase, + eMessageAlertManagerConnectorCityruf, + eMessageAlertManagerConnectorTwoWays +} = require('./eMessageConnector') +const { + eMessagePuppeteerConnectorBase, + eMessagePuppeteerConnectorCityruf, + eMessagePuppeteerConnectorTwoWays +} = require('./eMessagePuppeteerConnector') + module.exports = { DAPNETConnector: require("./DAPNETConnector"), eCityrufConnector: require('./eCityrufConnector'), - eMessageConnector: require('./eMessageConnector'), - eMessagePuppeteerConnector: require('./eMessagePuppeteerConnector'), + + eMessageAlertManagerConnectorBase, + eMessageAlertManagerConnectorCityruf, + eMessageAlertManagerConnectorTwoWays, + + eMessagePuppeteerConnectorBase, + eMessagePuppeteerConnectorCityruf, + eMessagePuppeteerConnectorTwoWays, + LoRaWANConnector: require("./LoRaWANConnector"), POCSAGConnector: require("./POCSAGConnector"), DummyConnector: require("./DummyConnector"),