Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for connection to Senso on port 55568 #128

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Let firmware update command look for bootloader if no Senso in regular mode is found
- Update build system and development environment
- Drop support for connecting to Sensos on port 55568


## [2.3.0] - 2022-10-01

Expand Down
4 changes: 0 additions & 4 deletions src/dividat-driver/senso/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package senso
import (
"context"
"sync"
"time"

"github.com/cskr/pubsub"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -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
Expand Down
98 changes: 35 additions & 63 deletions test/senso/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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
Expand All @@ -44,92 +41,67 @@ 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
}

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')
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)

var dataConnection = await getConnection(senso.data)
var controlConnection = await getConnection(senso.control)

var dataConnectionCloses = new Promise((resolve, reject) => {
dataConnection.on('close', () => {
resolve()
})
})
ws.send(connectCmd)

var controlConnectionCloses = new Promise((resolve, reject) => {
controlConnection.on('close', () => {
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 Promise.all([dataConnectionCloses, controlConnectionCloses])
return connectionCloses
})

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)

var ws = await connectWS('ws://127.0.0.1:8382/senso')
this.timeout(500)

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)

var dataConnection = await getConnection(senso.data)
var controlConnection = await getConnection(senso.control)

var dataConnectionCloses = new Promise((resolve, reject) => {
dataConnection.on('close', () => {
resolve()
})
})
ws.send(connectCmd)

var controlConnectionCloses = new Promise((resolve, reject) => {
controlConnection.on('close', () => {
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 Promise.all([dataConnectionCloses, controlConnectionCloses])
return connectionCloses;
})

it('Can get connection status', async function () {
Expand All @@ -151,15 +123,15 @@ 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
const n = 1000
this.timeout(1000 + n * 4 + 500)
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

Expand All @@ -171,30 +143,30 @@ 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)
}

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',
address: '127.0.0.1'
}))

const controlConnection = await getConnection(senso.control)
const connection = await getConnection(senso)

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
controlConnection.on('data', (data) => {
let received = 0
connection.on('data', (data) => {
received = received + data.length

if (received >= chunkSize * n) {
Expand Down
14 changes: 5 additions & 9 deletions test/senso/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +26,7 @@ function createChannel (port) {
})

channel._server = net.createServer()
.listen(port, HOST)
.listen(PORT, HOST)
.on('listening', () => {
channel.emit('listening')
})
Expand All @@ -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)
}
})
})
Expand All @@ -57,7 +56,4 @@ function createChannel (port) {
return channel
}

module.exports = {
dataChannel: () => createChannel(DATA_PORT),
controlChannel: () => createChannel(CONTROL_PORT)
}
module.exports = createChannel;