From 3c63d81d7acb8c5cc68297b4a9b3e51979852096 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 28 Mar 2024 18:38:58 +0100 Subject: [PATCH 1/5] Drop support for connection to Senso on port 55568 Trying to connect to this port adds a lot of noise in the logs. Sensos with FW this old should be paired with an outdated PC, not PlayOS, so would not get a driver update we release through PlayOS. --- src/dividat-driver/senso/main.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/dividat-driver/senso/main.go b/src/dividat-driver/senso/main.go index 5064f0b..b83ab8e 100644 --- a/src/dividat-driver/senso/main.go +++ b/src/dividat-driver/senso/main.go @@ -3,8 +3,6 @@ package senso import ( "context" "sync" - "time" - "github.com/cskr/pubsub" "github.com/sirupsen/logrus" ) @@ -67,8 +65,6 @@ func (handle *Handle) Connect(address string) { handle.broker.TryPub(data, "rx") } - go connectTCP(ctx, handle.log.WithField("channel", "data"), address+":55568", handle.broker.Sub("noTx"), onReceive) - time.Sleep(1000 * time.Millisecond) go connectTCP(ctx, handle.log.WithField("channel", "control"), address+":55567", handle.broker.Sub("tx"), onReceive) handle.cancelCurrentConnection = cancel From 49966eda6661554abf657869ae56fe45f8170c80 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 28 Mar 2024 18:41:35 +0100 Subject: [PATCH 2/5] Add changelog entry --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 9417d9e..ad1dcf1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ ### Changed - Let firmware update command look for bootloader if no Senso in regular mode is found +- Drop support for connecting to Sensos on port 55568 ## [2.3.0] - 2022-10-01 From 348b4427c44bba6ac0177acd35c45b56a1fa1c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Kerekes?= Date: Sat, 30 Mar 2024 14:59:11 +0100 Subject: [PATCH 3/5] Remove Senso data channel from tests --- test/senso/index.js | 51 ++++++++++++++------------------------------- test/senso/mock.js | 14 +++++-------- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/test/senso/index.js b/test/senso/index.js index 1fea225..0f99270 100644 --- a/test/senso/index.js +++ b/test/senso/index.js @@ -9,7 +9,7 @@ const mock = require('./mock') describe('Basic functionality', () => { var driver - var senso = {} + var senso beforeEach(async () => { // Start driver @@ -23,15 +23,12 @@ describe('Basic functionality', () => { driver.removeAllListeners() // start a mock Senso - senso.data = mock.dataChannel() - senso.control = mock.controlChannel() + senso = mock() }) afterEach(() => { driver.kill() - - senso.data.close() - senso.control.close() + senso.close() }) // Sends a command to Driver (over WS) to connect with the mock senso @@ -44,7 +41,7 @@ describe('Basic functionality', () => { ws.send(cmd) // wait until mock senso has a connection - await Promise.all([getConnection(senso.data), getConnection(senso.control)]) + await getConnection(senso) return ws } @@ -70,17 +67,9 @@ describe('Basic functionality', () => { ws.send(cmd) - var dataConnection = await getConnection(senso.data) - var controlConnection = await getConnection(senso.control) - - var dataConnectionCloses = new Promise((resolve, reject) => { - dataConnection.on('close', () => { - resolve() - }) - }) - - var controlConnectionCloses = new Promise((resolve, reject) => { - controlConnection.on('close', () => { + var connection = await getConnection(senso) + var connectionCloses = new Promise((resolve, reject) => { + connection.on('close', () => { resolve() }) }) @@ -91,7 +80,7 @@ describe('Basic functionality', () => { ws.send(cmd) - return Promise.all([dataConnectionCloses, controlConnectionCloses]) + return connectionCloses }) it('Disconnect on multiple Connects.', async function () { @@ -107,17 +96,9 @@ describe('Basic functionality', () => { ws.send(cmd) - var dataConnection = await getConnection(senso.data) - var controlConnection = await getConnection(senso.control) - - var dataConnectionCloses = new Promise((resolve, reject) => { - dataConnection.on('close', () => { - resolve() - }) - }) - - var controlConnectionCloses = new Promise((resolve, reject) => { - controlConnection.on('close', () => { + var connection = await getConnection(senso) + var connectionCloses = new Promise((resolve, reject) => { + connection.on('close', () => { resolve() }) }) @@ -129,7 +110,7 @@ describe('Basic functionality', () => { ws.send(cmd) - return Promise.all([dataConnectionCloses, controlConnectionCloses]) + return connectionCloses; }) it('Can get connection status', async function () { @@ -151,7 +132,7 @@ describe('Basic functionality', () => { }) }) - it('Data is forwarded from Senso data channel to WS', async function () { + it('Data is forwarded from Senso to WS', async function () { const sensoWS = await connectWS('ws://127.0.0.1:8382/senso').then(connectWithMockSenso) const chunkSize = 64 @@ -171,7 +152,7 @@ describe('Basic functionality', () => { const buffer = Buffer.from(new ArrayBuffer(chunkSize)) for (var i = 0; i < n; i++) { - senso.data.stream.write(buffer) + senso.stream.write(buffer) // Give one ms time for forwarding await wait(1) } @@ -186,7 +167,7 @@ describe('Basic functionality', () => { address: '127.0.0.1' })) - const controlConnection = await getConnection(senso.control) + const connection = await getConnection(senso) const chunkSize = 64 const n = 1000 @@ -194,7 +175,7 @@ describe('Basic functionality', () => { const expectData = new Promise((resolve, reject) => { var received = 0 - controlConnection.on('data', (data) => { + connection.on('data', (data) => { received = received + data.length if (received >= chunkSize * n) { diff --git a/test/senso/mock.js b/test/senso/mock.js index 95ce5a2..ab37f00 100644 --- a/test/senso/mock.js +++ b/test/senso/mock.js @@ -5,10 +5,9 @@ const EventEmitter = require('events') const net = require('net') const HOST = '127.0.0.1' -var CONTROL_PORT = 55567 -var DATA_PORT = 55568 +const PORT = 55567 -function createChannel (port) { +function createChannel () { const channel = new EventEmitter() var closed = false @@ -27,7 +26,7 @@ function createChannel (port) { }) channel._server = net.createServer() - .listen(port, HOST) + .listen(PORT, HOST) .on('listening', () => { channel.emit('listening') }) @@ -42,7 +41,7 @@ function createChannel (port) { c.on('close', () => { channel._connection = null if (!closed) { - channel._server.listen(port, HOST) + channel._server.listen(PORT, HOST) } }) }) @@ -57,7 +56,4 @@ function createChannel (port) { return channel } -module.exports = { - dataChannel: () => createChannel(DATA_PORT), - controlChannel: () => createChannel(CONTROL_PORT) -} +module.exports = createChannel; From 44843a2822436a5d014a325f5fe8d0fbdf2f5f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Kerekes?= Date: Sat, 30 Mar 2024 15:13:18 +0100 Subject: [PATCH 4/5] Remove additional wait time from test timeouts --- test/senso/index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/senso/index.js b/test/senso/index.js index 0f99270..82880e6 100644 --- a/test/senso/index.js +++ b/test/senso/index.js @@ -47,16 +47,14 @@ describe('Basic functionality', () => { } it('Can connect to a mock Senso.', async function () { - // It takes at least 1s to connect (as driver waits one sec between data and control connection) - this.timeout(1500) + this.timeout(500) await connectWS('ws://127.0.0.1:8382/senso') .then(connectWithMockSenso) }) it('Can connect and disconnect to a mock Senso.', async function () { - // It takes at least 1s to connect (as driver waits one sec between data and control connection) - this.timeout(1500) + this.timeout(500) var ws = await connectWS('ws://127.0.0.1:8382/senso') @@ -84,8 +82,7 @@ describe('Basic functionality', () => { }) it('Disconnect on multiple Connects.', async function () { - // It takes at least 1s to connect (as driver waits one sec between data and control connection) - this.timeout(1500) + this.timeout(500) var ws = await connectWS('ws://127.0.0.1:8382/senso') @@ -137,7 +134,7 @@ describe('Basic functionality', () => { const chunkSize = 64 const n = 1000 - this.timeout(1000 + n * 4 + 500) + this.timeout(500 + n * 4 + 500) const expectOnWS = new Promise((resolve, reject) => { var received = 0 @@ -160,7 +157,7 @@ describe('Basic functionality', () => { return expectOnWS }) - it('Data is forwarded from WS to control channel', async function () { + it('Data is forwarded from WS to the Senso', async function () { const sensoWS = await connectWS('ws://127.0.0.1:8382/senso') sensoWS.send(JSON.stringify({ type: 'Connect', @@ -171,7 +168,7 @@ describe('Basic functionality', () => { const chunkSize = 64 const n = 1000 - this.timeout(1000 + n * 2 + 500) + this.timeout(500 + n * 2 + 500) const expectData = new Promise((resolve, reject) => { var received = 0 From 2efe4999497930e11e392ec5697ce23dfe88cfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Kerekes?= Date: Sat, 30 Mar 2024 15:23:48 +0100 Subject: [PATCH 5/5] Improve test code's clarity Some small touches: - Use `let` and `const` for variables - Rename some variables --- test/senso/index.js | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/test/senso/index.js b/test/senso/index.js index 82880e6..541912d 100644 --- a/test/senso/index.js +++ b/test/senso/index.js @@ -8,12 +8,12 @@ const mock = require('./mock') // TESTS describe('Basic functionality', () => { - var driver - var senso + let driver + let senso beforeEach(async () => { // Start driver - var code = 0 + let code = 0 driver = startDriver().on('exit', (c) => { code = c }) @@ -56,27 +56,27 @@ describe('Basic functionality', () => { it('Can connect and disconnect to a mock Senso.', async function () { this.timeout(500) - var ws = await connectWS('ws://127.0.0.1:8382/senso') + const ws = await connectWS('ws://127.0.0.1:8382/senso') - var cmd = JSON.stringify({ + const connectCmd = JSON.stringify({ type: 'Connect', address: '127.0.0.1' }) - ws.send(cmd) + ws.send(connectCmd) - var connection = await getConnection(senso) - var connectionCloses = new Promise((resolve, reject) => { + const connection = await getConnection(senso) + const connectionCloses = new Promise((resolve, reject) => { connection.on('close', () => { resolve() }) }) - cmd = JSON.stringify({ + const disconnectCmd = JSON.stringify({ type: 'Disconnect' }) - ws.send(cmd) + ws.send(disconnectCmd) return connectionCloses }) @@ -84,28 +84,22 @@ describe('Basic functionality', () => { it('Disconnect on multiple Connects.', async function () { this.timeout(500) - var ws = await connectWS('ws://127.0.0.1:8382/senso') - - var cmd = JSON.stringify({ + const ws = await connectWS('ws://127.0.0.1:8382/senso') + const connectCmd = JSON.stringify({ type: 'Connect', address: '127.0.0.1' }) - ws.send(cmd) + ws.send(connectCmd) - var connection = await getConnection(senso) - var connectionCloses = new Promise((resolve, reject) => { + const connection = await getConnection(senso) + const connectionCloses = new Promise((resolve, reject) => { connection.on('close', () => { resolve() }) }) - cmd = JSON.stringify({ - type: 'Connect', - address: '127.0.0.1' - }) - - ws.send(cmd) + ws.send(connectCmd) return connectionCloses; }) @@ -137,7 +131,7 @@ describe('Basic functionality', () => { this.timeout(500 + n * 4 + 500) const expectOnWS = new Promise((resolve, reject) => { - var received = 0 + let received = 0 sensoWS.on('message', (msg) => { received = received + msg.length @@ -171,7 +165,7 @@ describe('Basic functionality', () => { this.timeout(500 + n * 2 + 500) const expectData = new Promise((resolve, reject) => { - var received = 0 + let received = 0 connection.on('data', (data) => { received = received + data.length