From 931f546653132957dbcabb07d4e8cf5db804568c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Sat, 25 Mar 2023 16:25:29 +0100 Subject: [PATCH] Implement center operation modes --- main.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index c5c09d0..232be33 100644 --- a/main.js +++ b/main.js @@ -439,6 +439,14 @@ class CenterSessionStatus { static CONNECTION_PENDING = "CONNECTION_PENDING"; } +// TODO: Implement endpoint for modifying modes +// TODO: Implement mode modification on centerSession +class CenterMode { + static DEBUG = "DEBUG"; + static ECHO = "ECHO"; + static DR = "DR"; +} + class CenterSession { // TODO: Currently this center behaves as a DEBUG server, Implement ECHO and DR functionality // TODO: If the port is in use this throws an exception, catch it and log it @@ -447,6 +455,7 @@ class CenterSession { busy = false; sessions = []; nextSession = 0; + mode = CenterMode.DEBUG; disconnectingPromise = { promise: null, @@ -532,9 +541,15 @@ class CenterSession { } sessionPdu(session, pdu) { - // TODO: Implement ECHO and DR functionality if (pdu.command === 'submit_sm') { session.send(pdu.response()); + if (this.mode === CenterMode.ECHO) { + this.notify(pdu.source_addr, pdu.destination_addr, pdu.short_message); + } + // TODO: Figure out how DRs work + // if (this.mode === CenterMode.DR) { + // this.notify(pdu.source_addr, pdu.destination_addr, pdu.short_message); + // } } if (pdu.command === 'enquire_link') { session.send(pdu.response()); @@ -639,7 +654,8 @@ class CenterSession { username: this.username, password: this.password, status: this.status, - activeSessions: this.sessions.length + activeSessions: this.sessions.length, + mode: this.mode } } @@ -1135,6 +1151,7 @@ centerSessionManager.startup(); let session = clientSessionManager.getSession(0); let server = centerSessionManager.getSession(0); + // session.connect() // .then(() => { // session.bind().then(() => { @@ -1149,12 +1166,12 @@ let server = centerSessionManager.getSession(0); // console.log(pdu); // }); -session.on(ClientSession.ANY_PDU_EVENT, (pdu) => { - if (pdu.command.includes('enquire')) { - return; - } - console.log(pdu); -}); +// session.on(ClientSession.ANY_PDU_EVENT, (pdu) => { +// if (pdu.command.includes('enquire')) { +// return; +// } +// console.log(pdu); +// }); new WSServer(); new HTTPServer();