Skip to content
Snippets Groups Projects
Commit 44cafc1d authored by Jake Read's avatar Jake Read
Browse files

commit before scuttle workers for processes

parent 572ab924
Branches
No related tags found
No related merge requests found
...@@ -76,6 +76,15 @@ app.post('/save/systems/:file', (req, res) => { ...@@ -76,6 +76,15 @@ app.post('/save/systems/:file', (req, res) => {
}) })
}) })
// well!
/*
(1) we can't actually do this with workers, serialport has a bug
// https://github.com/serialport/node-serialport/issues/1938
(2) doesn't need to be pipes explicitly: do '/processHookup' or something?
*/
// we also want to institute some pipes: this is a holdover for a better system // we also want to institute some pipes: this is a holdover for a better system
// more akin to nautilus, where server-side graphs are manipulated // more akin to nautilus, where server-side graphs are manipulated
// for now, we just want to dive down to a usb port, probably, so this shallow link is OK // for now, we just want to dive down to a usb port, probably, so this shallow link is OK
...@@ -88,6 +97,7 @@ app.get('/pipeHookup/:file', (req, res) => { ...@@ -88,6 +97,7 @@ app.get('/pipeHookup/:file', (req, res) => {
// to restart, // to restart,
// that way, remote clients can attempt a reset by issuing the same request // that way, remote clients can attempt a reset by issuing the same request
// and report server-down if nothing happens // and report server-down if nothing happens
console.log('req query', req.query)
const piper = new Worker(`${__dirname}/pipes/${req.params.file}`, {workerData: req.query}) const piper = new Worker(`${__dirname}/pipes/${req.params.file}`, {workerData: req.query})
piper.on('message', (msg) => { piper.on('message', (msg) => {
if(msg.startup){ if(msg.startup){
......
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
State State
} from '../hunks.js' } from '../hunks.js'
const STATUS_UNKNOWN = 'unknown...'
const STATUS_OPENING = 'opening...' const STATUS_OPENING = 'opening...'
const STATUS_OPEN = 'open' const STATUS_OPEN = 'open'
const STATUS_CLOSED = 'closed' const STATUS_CLOSED = 'closed'
...@@ -26,13 +27,19 @@ export default function VFPTC() { ...@@ -26,13 +27,19 @@ export default function VFPTC() {
let dtout = new Output('byteArray', 'data', this) let dtout = new Output('byteArray', 'data', this)
this.outputs.push(dtout) this.outputs.push(dtout)
let statusMessage = new State('string', 'status', STATUS_CLOSED) // one pipe (websocket)
let pipeStatusMessage = new State('string', 'pipe status', STATUS_CLOSED)
let portSelect = new State('number', 'port', 2042) let portSelect = new State('number', 'port', 2042)
let retryButton = new State('boolean', 'retry', false) let pipeRetryButton = new State('boolean', 'pipe reset', false)
// and serialport,
let serialStatusMessage = new State('string', 'serialport status', 'unknown')
let usbPidSelect = new State('number', 'usb PID', 8022)
let serialRetryButton = new State('boolean', 'serial reset', false)
// ok,
let echoButton = new State('boolean', 'echo', false) let echoButton = new State('boolean', 'echo', false)
let bufferButton = new State('boolean', 'buffer', false) let bufferButton = new State('boolean', 'buffer', false)
this.states.push(statusMessage, portSelect, retryButton, echoButton, bufferButton) this.states.push(pipeStatusMessage, portSelect, pipeRetryButton, serialStatusMessage, serialRetryButton, echoButton, bufferButton)
retryButton.onChange = (value) => { pipeRetryButton.onChange = (value) => {
startWsConnection() startWsConnection()
} }
echoButton.onChange = (value) => { echoButton.onChange = (value) => {
...@@ -45,7 +52,8 @@ export default function VFPTC() { ...@@ -45,7 +52,8 @@ export default function VFPTC() {
// coming merge of init and onload, however: // coming merge of init and onload, however:
this.init = () => { this.init = () => {
// force closed at startup; else program state can make us confused, // force closed at startup; else program state can make us confused,
statusMessage.set(STATUS_CLOSED) pipeStatusMessage.set(STATUS_CLOSED)
serialStatusMessage.set(STATUS_UNKNOWN)
startWsConnection() startWsConnection()
} }
...@@ -53,10 +61,10 @@ export default function VFPTC() { ...@@ -53,10 +61,10 @@ export default function VFPTC() {
let outbuffer = [] let outbuffer = []
let startWsConnection = () => { let startWsConnection = () => {
// only attempt reconnect if we're not already opening, or opened // only attempt reconnect if we're not already opening, or opened
if (statusMessage.value === STATUS_OPEN || statusMessage.value === STATUS_OPENING) return if (pipeStatusMessage.value === STATUS_OPEN || pipeStatusMessage.value === STATUS_OPENING) return
// ask the server to instantiate the reciprocal process, // ask the server to instantiate the reciprocal process,
statusMessage.set(STATUS_OPENING) pipeStatusMessage.set(STATUS_OPENING)
jQuery.get(`pipeHookup/vfpts.js?port=${portSelect.value}`, (data) => { jQuery.get(`pipeHookup/vfpts.js?port=${portSelect.value}&pid=${usbPidSelect.value}`, (data) => {
if (data.startup) { if (data.startup) {
console.log('serverside launched, starting client') console.log('serverside launched, starting client')
console.log(data) console.log(data)
...@@ -64,15 +72,15 @@ export default function VFPTC() { ...@@ -64,15 +72,15 @@ export default function VFPTC() {
ws = new WebSocket(`ws://${data.ip}:${data.port}`) ws = new WebSocket(`ws://${data.ip}:${data.port}`)
ws.onopen = (evt) => { ws.onopen = (evt) => {
if (debug) console.log(this.name, 'opens') if (debug) console.log(this.name, 'opens')
statusMessage.set(STATUS_OPEN) pipeStatusMessage.set(STATUS_OPEN)
} }
ws.onerror = (err) => { ws.onerror = (err) => {
if (debug) console.log(this.name, 'error', err) if (debug) console.log(this.name, 'error', err)
statusMessage.set(STATUS_ERROR) pipeStatusMessage.set(STATUS_ERROR)
} }
ws.onclose = (evt) => { ws.onclose = (evt) => {
if (debug) console.log(this.name, 'closes') if (debug) console.log(this.name, 'closes')
statusMessage.set(STATUS_CLOSED) pipeStatusMessage.set(STATUS_CLOSED)
} }
ws.onmessage = (msg) => { ws.onmessage = (msg) => {
if (debug) console.log(this.name, 'recvs', msg) if (debug) console.log(this.name, 'recvs', msg)
...@@ -80,7 +88,7 @@ export default function VFPTC() { ...@@ -80,7 +88,7 @@ export default function VFPTC() {
} }
} else { } else {
console.log('pipe received non-startup response from server') console.log('pipe received non-startup response from server')
statusMessage.set(STATUS_ERROR) pipeStatusMessage.set(STATUS_ERROR)
} }
}) })
} }
......
This diff is collapsed.
...@@ -10,15 +10,25 @@ const { ...@@ -10,15 +10,25 @@ const {
} = require('worker_threads') } = require('worker_threads')
const WebSocketServer = require('ws').Server const WebSocketServer = require('ws').Server
const SerialPort = require('serialport')
const Delimiter = require('@serialport/parser-delimiter')
// port to issue on,
let port let port
if(workerData.port){ if(workerData.port){
port = workerData.port port = workerData.port
} else { } else {
port = 2042 port = 2042
} }
// usb product id to look for,
let pid
if(workerData.pid){
pid = workerData.pid
} else {
pid = '8022'
}
const WSS = new WebSocketServer({port: port}, () => { const WSS = new WebSocketServer({port: port}, () => {
parentPort.postMessage({ parentPort.postMessage({
startup: true, startup: true,
...@@ -51,3 +61,49 @@ WSS.on('connection', (ws) => { ...@@ -51,3 +61,49 @@ WSS.on('connection', (ws) => {
process.exit() process.exit()
} }
}) })
// now the usb,
let serport = null
let comname = ''
let findSerialPort = () => {
let found = false
SerialPort.list((err, ports) => {
ports.forEach((serialport) => {
if (serialport.productId === pid) {
comname = serialport.comName
console.log(`found port at ${comname}, opening`)
openPort()
}
})
})
}
let openPort = () => {
/*
serport = new SerialPort(comname, {
baudRate: 3000000
})
serport.on('open', () => {
serport.on('error', (err) => {
console.log('port error', err)
})
const parser = serport.pipe(new Delimiter({delimiter: [0]}))
parser.on('data', (buf) => {
// serialport doesn't guarantee packet sized events
//console.log('serport receives: ', buf)
let op = decode(buf)
if(op[0] === 252){
console.log('LLM: ', buf.toString('utf8'))
} else {
//console.log('<- de-cobs: ', op.length)
if(WS){
WS.send(op)
}
}
})
})
*/
}
findSerialPort()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment