Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cuttlefish
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
squidworks
cuttlefish
Commits
44cafc1d
Commit
44cafc1d
authored
5 years ago
by
Jake Read
Browse files
Options
Downloads
Patches
Plain Diff
commit before scuttle workers for processes
parent
572ab924
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
cf.js
+10
-0
10 additions, 0 deletions
cf.js
hunks/pipes/vfptc.js
+20
-12
20 additions, 12 deletions
hunks/pipes/vfptc.js
package-lock.json
+585
-0
585 additions, 0 deletions
package-lock.json
pipes/vfpts.js
+57
-1
57 additions, 1 deletion
pipes/vfpts.js
with
672 additions
and
13 deletions
cf.js
+
10
−
0
View file @
44cafc1d
...
@@ -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
){
...
...
This diff is collapsed.
Click to expand it.
hunks/pipes/vfptc.js
+
20
−
12
View file @
44cafc1d
...
@@ -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
(
s
tatusMessage
,
portSelect
,
r
etryButton
,
echoButton
,
bufferButton
)
this
.
states
.
push
(
pipeS
tatusMessage
,
portSelect
,
pipeRetryButton
,
serialStatusMessage
,
serialR
etryButton
,
echoButton
,
bufferButton
)
r
etryButton
.
onChange
=
(
value
)
=>
{
pipeR
etryButton
.
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
(
s
tatusMessage
.
value
===
STATUS_OPEN
||
s
tatusMessage
.
value
===
STATUS_OPENING
)
return
if
(
pipeS
tatusMessage
.
value
===
STATUS_OPEN
||
pipeS
tatusMessage
.
value
===
STATUS_OPENING
)
return
// ask the server to instantiate the reciprocal process,
// ask the server to instantiate the reciprocal process,
s
tatusMessage
.
set
(
STATUS_OPENING
)
pipeS
tatusMessage
.
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
'
)
s
tatusMessage
.
set
(
STATUS_OPEN
)
pipeS
tatusMessage
.
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
)
s
tatusMessage
.
set
(
STATUS_ERROR
)
pipeS
tatusMessage
.
set
(
STATUS_ERROR
)
}
}
ws
.
onclose
=
(
evt
)
=>
{
ws
.
onclose
=
(
evt
)
=>
{
if
(
debug
)
console
.
log
(
this
.
name
,
'
closes
'
)
if
(
debug
)
console
.
log
(
this
.
name
,
'
closes
'
)
s
tatusMessage
.
set
(
STATUS_CLOSED
)
pipeS
tatusMessage
.
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
'
)
s
tatusMessage
.
set
(
STATUS_ERROR
)
pipeS
tatusMessage
.
set
(
STATUS_ERROR
)
}
}
})
})
}
}
...
...
This diff is collapsed.
Click to expand it.
package-lock.json
+
585
−
0
View file @
44cafc1d
This diff is collapsed.
Click to expand it.
pipes/vfpts.js
+
57
−
1
View file @
44cafc1d
...
@@ -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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment