Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LidarWebVisualization-TestBackend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VaKoEiS
LidarWebVisualization-TestBackend
Commits
11efc522
Commit
11efc522
authored
5 years ago
by
Matthias
Browse files
Options
Downloads
Patches
Plain Diff
clusters ne
parent
c6ae49f3
Branches
Branches containing commit
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data_generator.cpp
+20
-11
20 additions, 11 deletions
data_generator.cpp
index.js
+23
-37
23 additions, 37 deletions
index.js
with
43 additions
and
48 deletions
data_generator.cpp
+
20
−
11
View file @
11efc522
This diff is collapsed.
Click to expand it.
index.js
+
23
−
37
View file @
11efc522
...
...
@@ -4,8 +4,8 @@ const app = require('express')();
const
http
=
require
(
'
http
'
).
Server
(
app
);
const
socket
=
require
(
'
socket.io
'
)(
http
);
const
p2p
=
require
(
'
socket.io-p2p-server
'
).
Server
;
socket
.
use
(
p2p
);
// use webrtc
//
const p2p = require('socket.io-p2p-server').Server;
//
socket.use(p2p); // use webrtc
const
fs
=
require
(
'
fs
'
);
const
fifoPath
=
'
/tmp/nodeFIFO
'
;
...
...
@@ -21,10 +21,11 @@ function getSummary(s) {
return
s
.
substring
(
0
,
50
)
+
"
…
"
+
s
.
substring
(
s
.
length
-
50
,
s
.
length
);
}
// unecessary webserver
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
send
(
'
<h1>okcool but you
gotta go for port 3000 though
</h1>
'
);
res
.
send
(
'
<h1>okcool but you
should visit the visualization site
</h1>
'
);
});
http
.
listen
(
3000
,
()
=>
{
...
...
@@ -34,20 +35,14 @@ http.listen(3000, () => {
// named pipe anzapfen
let
fifo
;
try
{
fifo
=
fs
.
createReadStream
(
fifoPath
);
}
catch
(
e
)
{
console
.
error
(
"
fifo not readable
"
)
throw
e
;
}
const
fifo
=
fs
.
createReadStream
(
fifoPath
);
fifo
.
setEncoding
(
"
utf8
"
);
console
.
log
(
"
started listener...
"
);
// stream providing complete data packets
, not the bits and pieces returned from
// the fifo
//
create
stream providing complete data packets
//
not the bits and pieces returned from
the fifo
const
packetStream
=
new
Stream
.
Readable
({
read
()
{}
});
...
...
@@ -58,22 +53,20 @@ let buffer = ""; // buffers incoming data
let
frameNo
=
0
;
// debug
const
packetDelimiter
=
"
EOT
"
;
// string that separates packets
// buffer the FIFO stream, collect pieces of data, and turn into packet stream
fifo
.
on
(
"
data
"
,
msg
=>
{
// console.log("---")
// console.log("msg", msg)
// console.log("---")
// console.log("summary msg `" + getSummary(msg) + "`")
buffer
+=
msg
;
// console.log("summary buffer `" + getSummary(buffer) + "`")
// there could potentially be multiple packets in the buffer
// so loop until we pushed all of them to the packet stream
for
(
let
delIndex
=
buffer
.
indexOf
(
packetDelimiter
);
delIndex
!==
-
1
;
delIndex
=
buffer
.
indexOf
(
packetDelimiter
))
{
const
packet
=
buffer
.
substring
(
0
,
delIndex
)
.
replace
(
/
\0
/g
,
''
);
// dis shit null terminated boi
.
replace
(
/
\0
/g
,
''
);
// dis shit
too
null terminated boi
buffer
=
buffer
.
substring
(
delIndex
+
packetDelimiter
.
length
,
buffer
.
length
);
...
...
@@ -83,18 +76,20 @@ fifo.on("data", msg => {
}
});
let
peers
=
0
;
socket
.
on
(
"
connection
"
,
async
socket
=>
{
peers
++
;
function
logAction
(
action
,
socket
)
{
const
ip
=
socket
.
request
.
connection
.
remoteAddress
;
const
userAgent
=
socket
.
request
.
headers
[
'
user-agent
'
];
console
.
log
(
"
\n
connected
"
,
ip
,
"
(
"
+
peers
+
"
connections)
"
,
"
\n
"
+
action
,
ip
,
"
(
"
+
peers
+
"
connections)
"
,
"
\n\t
User Agent:
"
,
userAgent
,
"
\n\t
Socket ID:
"
,
socket
.
id
);
}
socket
.
on
(
"
connection
"
,
async
socket
=>
{
peers
++
;
logAction
(
"
connected
"
,
socket
);
const
myStream
=
new
Stream
.
PassThrough
();
myStream
.
setEncoding
(
'
utf8
'
);
...
...
@@ -118,21 +113,15 @@ socket.on("connection", async socket => {
console
.
error
(
"
rawData was
"
,
rawData
);
}
console
.
error
(
e
)
console
.
log
(
rawData
);
throw
e
;
return
;
}
if
(
!
data
)
throw
new
Error
(
"
data was
"
+
data
);
// console.debug("sending data to", socket.id, "("+frameNo+")");
// console.log("data type:", Object.keys(data))
// const frame = new Uint8Array(12976);
// data.frame.forEach((el, frameNo) => frame[frameNo] = el);
// console.log("sent")
// send the packet to the visualization through socket.io
socket
.
emit
(
"
data
"
,
{
frame
:
data
.
frame
,
clusters
:
data
.
clusters
,
id
:
frameNo
,
// debug
timestamps
:
{
sent
:
+
new
Date
(),
...
...
@@ -143,10 +132,7 @@ socket.on("connection", async socket => {
socket
.
on
(
'
disconnect
'
,
()
=>
{
peers
--
;
const
ip
=
socket
.
request
.
connection
.
remoteAddress
;
const
userAgent
=
socket
.
request
.
headers
[
'
user-agent
'
];
console
.
log
(
"
\n
disconnected
"
,
ip
,
"
(
"
+
peers
+
"
connections)
"
,
"
\n\t
"
,
ip
,
"
\n\t
"
,
userAgent
,
"
\n\t
"
,
socket
.
id
)
// myStream.off('readable', listener);
logAction
(
"
disconnected
"
,
socket
);
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
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