test code
parent
a591f39d81
commit
9a738d41cd
@ -0,0 +1,14 @@
|
||||
const amqp = require('amqp-connection-manager')
|
||||
|
||||
// Create a connetion manager
|
||||
const connection = amqp.connect(['amqp://daemon:daemon@10.13.37.37:5672/'])
|
||||
connection.on('connect', () => console.log('Connected!'))
|
||||
connection.on('disconnect', err => console.log('Disconnected.', err.stack))
|
||||
|
||||
const types = require('./types') // also initalized the CentralEventEmitter
|
||||
types.ConnectorRegistry.register(new types.Connectors.POCSAGConnector(connection)) // activate POCSAG
|
||||
|
||||
types.ConnectorRegistry.transmit("pocsag", {
|
||||
ric: '133701',
|
||||
body: "AAAA"
|
||||
})
|
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "pocsag-daemon",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/smartpager-network/pocsag-daemon.git"
|
||||
},
|
||||
"author": "catSIXe",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/smartpager-network/pocsag-daemon/issues"
|
||||
},
|
||||
"homepage": "https://github.com/smartpager-network/pocsag-daemon#readme",
|
||||
"dependencies": {
|
||||
"amqp-connection-manager": "^3.2.2",
|
||||
"amqplib": "^0.7.0"
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
const { POCSAGConnector } = require("./connectors")
|
||||
|
||||
class ConnectorRegistry {
|
||||
constructor() {
|
||||
this.Connectors = {}
|
||||
}
|
||||
register(connector) {
|
||||
this.Connectors[ connector.name ] = connector
|
||||
}
|
||||
transmit(name, message) {
|
||||
if (!this.Connectors[ name ]) throw "not registred"
|
||||
this.Connectors[ name ].transmitMessage(message)
|
||||
}
|
||||
}
|
||||
const registry = new ConnectorRegistry()
|
||||
module.exports = registry
|
@ -0,0 +1,14 @@
|
||||
const { GenericPager, BirdySlim } = require("./devices")
|
||||
|
||||
class DeviceRegistry {
|
||||
constructor() {
|
||||
this.Devices = {}
|
||||
}
|
||||
register(device) {
|
||||
this.Devices[ device.name ] = device
|
||||
}
|
||||
}
|
||||
const registry = new DeviceRegistry()
|
||||
registry.register(new GenericPager())
|
||||
registry.register(new BirdySlim())
|
||||
module.exports = registry
|
@ -0,0 +1,12 @@
|
||||
class Message {
|
||||
ID
|
||||
Type
|
||||
RoutingMask
|
||||
Content
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Message
|
@ -0,0 +1,6 @@
|
||||
class RouteablePage {
|
||||
id
|
||||
|
||||
constructor() {
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
class Connector {
|
||||
constructor (amqpConnMngr) {
|
||||
this.amqpConnMngr = amqpConnMngr
|
||||
this.name = "_base"
|
||||
}
|
||||
transmitMessage(msg) {
|
||||
throw "not implemented"
|
||||
}
|
||||
}
|
||||
module.exports = Connector
|
@ -0,0 +1,9 @@
|
||||
const Connector = require("./Connector")
|
||||
|
||||
class DAPNETConnector extends Connector {
|
||||
constructor (amqpConnMngr) {
|
||||
super(amqpConnMngr)
|
||||
this.name = "dapnet"
|
||||
}
|
||||
}
|
||||
module.exports = DAPNETConnector
|
@ -0,0 +1,9 @@
|
||||
const Connector = require("./Connector")
|
||||
|
||||
class LoRaWANConnector extends Connector {
|
||||
constructor (amqpConnMngr) {
|
||||
super(amqpConnMngr)
|
||||
this.name = "lorawan"
|
||||
}
|
||||
}
|
||||
module.exports = LoRaWANConnector
|
@ -0,0 +1,41 @@
|
||||
const Connector = require("./Connector")
|
||||
|
||||
class POCSAGConnector extends Connector {
|
||||
constructor (amqpConnMngr) {
|
||||
super(amqpConnMngr)
|
||||
this.name = "pocsag"
|
||||
|
||||
this.channelWrapper = this.amqpConnMngr.createChannel({
|
||||
json: false,
|
||||
setup: function(channel) {
|
||||
return channel.assertQueue('tx_pocsag', { durable: true })
|
||||
}
|
||||
})
|
||||
}
|
||||
transmitMessage(msg) {
|
||||
if (!msg.ric) return false
|
||||
const RIC = msg.ric
|
||||
const lastChar = RIC[RIC.length - 1].charCodeAt(0) - 65
|
||||
const addressPart = lastChar >= 0 && lastChar <= 3 ? RIC.substring(0, RIC.length - 1) : RIC
|
||||
const functionBits = lastChar >= 0 && lastChar <= 3 ? lastChar : 0
|
||||
this.channelWrapper.sendToQueue('tx_pocsag', Buffer.from(msg.body), {
|
||||
headers: {
|
||||
ric: {
|
||||
'!': 'int64',
|
||||
value: addressPart
|
||||
},
|
||||
function: {
|
||||
'!': 'int64',
|
||||
value: functionBits
|
||||
},
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
return console.log("Message was sent! Hooray!")
|
||||
}).catch(function(err) {
|
||||
return console.log(err,"Message was rejected... Boo!")
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
module.exports = POCSAGConnector
|
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
DAPNETConnector: require("./DAPNETConnector"),
|
||||
LoRaWANConnector: require("./LoRaWANConnector"),
|
||||
POCSAGConnector: require("./POCSAGConnector"),
|
||||
Connector: require("./Connector"),
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
const PagerDevice = require("./Device")
|
||||
|
||||
// Birdy Slim (IoT) Device
|
||||
class BirdySlim extends PagerDevice {
|
||||
constructor () {
|
||||
super()
|
||||
this.name = "birdyslim"
|
||||
}
|
||||
formatTX(msg) {
|
||||
}
|
||||
}
|
||||
module.exports = BirdySlim
|
@ -0,0 +1,8 @@
|
||||
class PagerDevice {
|
||||
constructor () {
|
||||
this.name = "_base"
|
||||
}
|
||||
formatTX(msg) {
|
||||
}
|
||||
}
|
||||
module.exports = PagerDevice
|
@ -0,0 +1,11 @@
|
||||
const PagerDevice = require("./Device")
|
||||
|
||||
class GenericPager extends PagerDevice {
|
||||
constructor () {
|
||||
super()
|
||||
this.name = "generic"
|
||||
}
|
||||
transmit(msg) {
|
||||
}
|
||||
}
|
||||
module.exports = GenericPager
|
@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
GenericPager: require("./GenericPager"),
|
||||
BirdySlim: require("./BirdySlim"),
|
||||
Device: require("./Device"),
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
const events = require('events')
|
||||
|
||||
module.exports = {
|
||||
CentralEventEmitter: new events.EventEmitter(),
|
||||
Connectors: require("./connectors"),
|
||||
devices: require("./devices"),
|
||||
Message: require("./Message"),
|
||||
RouteablePage: require("./RouteablePage"),
|
||||
DeviceRegistry: require("./DeviceRegistry"),
|
||||
ConnectorRegistry: require("./ConnectorRegistry"),
|
||||
}
|
Loading…
Reference in New Issue