first version to work, for simplex
parent
9a738d41cd
commit
6114644362
@ -1,14 +1,27 @@
|
||||
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 connection = amqp.connect([
|
||||
'amqp://daemon:daemon@10.13.37.37:5672/'
|
||||
])
|
||||
connection.on('connect', () => console.log('Connected to AMQP.'))
|
||||
connection.on('disconnect', err => console.log('Disconnected from AMQP.', err.stack))
|
||||
|
||||
const types = require('./types') // also initalized the CentralEventEmitter
|
||||
const types = require('./types') // also initializes the registries, if they havent been loaded
|
||||
types.ConnectorRegistry.register(new types.Connectors.POCSAGConnector(connection)) // activate POCSAG
|
||||
|
||||
types.ConnectorRegistry.transmit("pocsag", {
|
||||
types.DeviceRegistry.register(new types.devices.GenericPager())
|
||||
types.DeviceRegistry.register(new types.devices.BirdySlim())
|
||||
|
||||
async function main() {
|
||||
let id = await types.MessageManager.New('simple', { device: null, connectors: [
|
||||
['pocsag', '133701A']
|
||||
] }, "Hallo")
|
||||
console.log('msgid', id)
|
||||
await types.MessageManager.Deliver(id)
|
||||
}
|
||||
main()
|
||||
/*types.ConnectorRegistry.transmit("pocsag", {
|
||||
ric: '133701',
|
||||
body: "AAAA"
|
||||
})
|
||||
body: "AAAAhh, ich\n\n\n\nHabe einen Sprung"
|
||||
})*/
|
@ -1,12 +1,12 @@
|
||||
class Message {
|
||||
ID
|
||||
Type
|
||||
RoutingMask
|
||||
Content
|
||||
|
||||
constructor() {
|
||||
|
||||
this.ID // get from MessageManager.New
|
||||
this.Type // "simple" or "duplex"
|
||||
this.RoutingMask // device=birdy&lora=devID:fPort&pocsag=133701B&dapnet=testID
|
||||
this.Content // Blabla
|
||||
this.Headers
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Message
|
@ -0,0 +1,45 @@
|
||||
const ConnectorRegistry = require("./ConnectorRegistry")
|
||||
|
||||
class MessageManager {
|
||||
constructor() {
|
||||
this.messages = {}
|
||||
}
|
||||
async New(type, routingParams, payload) {
|
||||
if (!routingParams.device) {
|
||||
routingParams.device = 'generic'
|
||||
}
|
||||
const msgObj = {
|
||||
type,
|
||||
routingParams,
|
||||
payload,
|
||||
}
|
||||
await require("./DeviceRegistry").Devices[ routingParams.device ].formatTX(msgObj)
|
||||
// console.log('finished msg obj is ', msgObj)
|
||||
this.messages[ msgObj.id ]._routerData = this.messages[ msgObj.id ]._routerData || {
|
||||
recvAck: false,
|
||||
readAck: false,
|
||||
response: false,
|
||||
}
|
||||
console.log('finished msg obj is ', msgObj)
|
||||
return msgObj.id
|
||||
}
|
||||
async Deliver(msgId) {
|
||||
const msg = this.messages[ msgId ]
|
||||
// Throw error, because wtf
|
||||
if (!msg._routerData) throw `No Routerdata attached to msg with id ${ msgId }`
|
||||
// attach Start Delivery Unix Timestamp if not already there
|
||||
if (!msg._routerData.startDelivery) msg._routerData.startDelivery = Math.floor(new Date().valueOf()/1e3)
|
||||
if (!msg._routerData.deliveryLog) msg._routerData.deliveryLog = []
|
||||
let logLength = msg._routerData.deliveryLog.length
|
||||
if (logLength < msg.routingParams.connectors.length) {
|
||||
let deliveryConnector = msg.routingParams.connectors[ logLength ]
|
||||
console.log('delivering with ', deliveryConnector)
|
||||
await ConnectorRegistry.transmit(deliveryConnector[0], msg, deliveryConnector.slice(1))
|
||||
msg._routerData.deliveryLog.push(deliveryConnector)
|
||||
}
|
||||
}
|
||||
async BindMsg(msg) {
|
||||
this.messages[ msg.id ] = msg
|
||||
}
|
||||
}
|
||||
module.exports = new MessageManager()
|
@ -1,8 +1,9 @@
|
||||
class PagerDevice {
|
||||
constructor () {
|
||||
this.duplex = false
|
||||
this.name = "_base"
|
||||
}
|
||||
formatTX(msg) {
|
||||
}
|
||||
async formatTX(msg) { }
|
||||
RandID() { }
|
||||
}
|
||||
module.exports = PagerDevice
|
@ -1,11 +1,26 @@
|
||||
const MessageManager = require("../MessageManager")
|
||||
const PagerDevice = require("./Device")
|
||||
const Str = require('@supercharge/strings')
|
||||
|
||||
class GenericPager extends PagerDevice {
|
||||
constructor () {
|
||||
super()
|
||||
this.name = "generic"
|
||||
}
|
||||
transmit(msg) {
|
||||
constructor () {
|
||||
super()
|
||||
this.duplex = false
|
||||
this.name = "generic"
|
||||
}
|
||||
RandID() {
|
||||
return `G${ Str.random(8) }`
|
||||
}
|
||||
async formatTX(msg) {
|
||||
msg.id = this.RandID()
|
||||
await MessageManager.BindMsg(msg)
|
||||
msg.payload = `${ msg.id }${ msg.payload }`
|
||||
msg._routerData = {
|
||||
recvAck: false,
|
||||
readAck: false,
|
||||
response: false,
|
||||
}
|
||||
// return msg
|
||||
}
|
||||
module.exports = GenericPager
|
||||
}
|
||||
module.exports = GenericPager
|
Loading…
Reference in New Issue