Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Protos
Nomad 3D
nomad-3d-viewer
Commits
886491d3
Commit
886491d3
authored
Oct 27, 2022
by
legoc
Browse files
Removed nomad positions addon and use zeromq directly
parent
d4199401
Changes
8
Hide whitespace changes
Inline
Side-by-side
binding.gyp
View file @
886491d3
...
...
@@ -5,28 +5,6 @@
},
"targets": [
{
"target_name": "addonnomad3dposition",
'cflags_cc': [ '-std=c++17', '-fexceptions' ],
'conditions': [
['nomad=="true"', {
"sources": [
"nomad-positions/nomad-positions.cc",
],
"conditions": [
['OS=="mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
},
}]
],
"libraries": [
"-lcameo-api-cpp -lzmq"
]
}]
]
},
{
"target_name": "addonnomad3dcollision",
'cflags_cc': [ '-std=c++17', '-fexceptions' ],
...
...
js/client/main/nomad-server.js
View file @
886491d3
...
...
@@ -51,11 +51,6 @@ class NomadServer {
return
;
}
// Reset the addon.
await
this
.
NomadPositions
.
reset
(
0
);
console
.
log
(
"
Nomad positions reset
"
)
// Get the current simulated server list.
this
.
resetServerIdMap
();
this
.
_currentServerId
=
this
.
_controller
.
Server
[
0
];
...
...
@@ -63,10 +58,8 @@ class NomadServer {
async
reset
(
nomadServerId
)
{
console
.
log
(
"
Resetting Nomad server to
"
+
nomadServerId
+
"
...
"
)
// Reset the addon.
await
this
.
NomadPositions
.
reset
(
nomadServerId
);
// Set the simulated server id.
this
.
NomadPositions
.
reset
(
nomadServerId
);
console
.
log
(
"
Reset Nomad server to
"
+
nomadServerId
)
}
...
...
js/common/link/nomad-3d-controller.js
View file @
886491d3
...
...
@@ -82,7 +82,7 @@ class Nomad3DController {
// Update if the value has changed.
// At first call, actual position is undefined so that the condition is evaluated to true.
if
(
this
.
_actualPosition
!=
position
)
{
console
.
info
(
"
Updating
"
+
this
.
name
+
"
to
"
+
position
+
"
at
"
+
new
Date
().
toISOString
());
//
console.info("Updating " + this.name + " to " + position + " at " + new Date().toISOString());
this
.
_actualPosition
=
position
;
this
.
component
.
axis
.
value
=
this
.
_actualPosition
;
...
...
js/common/link/nomad-3d-positions.js
View file @
886491d3
...
...
@@ -26,9 +26,6 @@ class Nomad3DPositions {
// Memorize the current nomad server id.
this
.
_nomadServerId
=
nomadServerId
;
// Reset Nomad.
return
this
.
_requester
.
request
(
'
ResetNomadPosition
'
,
this
.
_nomadServerId
);
}
getSimulatedServerIds
()
{
...
...
js/server/com/nomad-positions.js
View file @
886491d3
const
config
=
require
(
"
../config
"
);
const
CameoServer
=
require
(
"
./cameo-server
"
);
const
zmq
=
require
(
"
zeromq
"
);
/**
* Class managing the link with the addon.
* There is only one instance of the class.
*
*/
class
NomadPositions
{
constructor
()
{
this
.
_addon
=
null
;
}
// Get the list of instruments.
this
.
_models
=
config
.
models
;
init
(
localEndpoint
,
nomadEndpoint
)
{
// Get the addon.
this
.
_addon
=
require
(
'
../../../build/Release/addonnomad3dposition
'
);
// Create the subscriber to all the instruments.
this
.
_subscriber
=
new
zmq
.
Subscriber
;
//
Init with the endpoi
nts.
this
.
_
addon
.
init
([
localEndpoint
,
nomadEndpoint
,
"
nomad-3d-viewer
"
])
;
//
Positions of all the instrume
nts.
this
.
_
positions
=
{}
;
}
getSimulatedServerIds
()
{
return
this
.
_addon
.
getSimulatedServerIds
();
}
getPositions
(
nomadServerId
)
{
return
this
.
_addon
.
getPositions
(
nomadServerId
);
async
_positionsLoop
()
{
// Wait for a new message.
const
[
identity
,
type
,
message
]
=
await
this
.
_subscriber
.
receive
();
//console.log('Received positions', message.toString());
// Decode the message.
const
instrumentPositions
=
JSON
.
parse
(
message
.
toString
());
const
instrument
=
instrumentPositions
[
"
instrument
"
];
const
id
=
instrumentPositions
[
"
id
"
];
const
positions
=
instrumentPositions
[
"
positions
"
];
if
(
!
(
instrument
in
this
.
_positions
))
{
this
.
_positions
[
instrument
]
=
{};
}
this
.
_positions
[
instrument
][
id
]
=
positions
;
// Continue the loop.
setTimeout
(()
=>
{
this
.
_positionsLoop
();
});
}
pause
(
nomadServerId
)
{
return
this
.
_addon
.
pause
(
nomadServerId
);
async
init
()
{
// Subscribe to all the instruments.
for
(
let
instrument
in
this
.
_models
)
{
const
endpoint
=
this
.
_models
[
instrument
][
"
endpoint
"
];
const
server
=
new
CameoServer
(
endpoint
);
try
{
const
publisherProxyPort
=
await
server
.
getPublisherProxyPort
();
console
.
log
(
'
Instrument
'
+
instrument
+
'
at
'
+
endpoint
+
'
with publisher proxy port
'
+
publisherProxyPort
);
let
publisherEndpoint
=
endpoint
.
substring
(
0
,
endpoint
.
lastIndexOf
(
"
:
"
)
+
1
);
publisherEndpoint
+=
publisherProxyPort
;
console
.
log
(
'
Connecting
'
+
publisherEndpoint
);
this
.
_subscriber
.
connect
(
publisherEndpoint
);
const
topic
=
'
publisher-55845880-56e9-4ad6-bea1-e84395c90b32-nomad3d_positions
'
;
this
.
_subscriber
.
subscribe
(
topic
);
}
catch
(
error
)
{
console
.
log
(
'
Instrument
'
+
instrument
+
'
at
'
+
endpoint
+
'
unreachable
'
);
}
}
// Start the message loop.
this
.
_positionsLoop
();
}
restart
(
nomadServerId
)
{
return
this
.
_addon
.
restart
(
nomadServerId
);
async
getSimulatedServerIds
(
instrument
)
{
const
endpoint
=
this
.
_models
[
instrument
][
"
endpoint
"
];
const
server
=
new
CameoServer
(
endpoint
);
let
result
=
[];
try
{
const
apps
=
await
server
.
getApplicationInfos
();
for
(
let
app
of
apps
)
{
if
(
app
[
"
name
"
]
===
'
nssim
'
)
{
result
.
push
(
app
[
"
id
"
]);
}
}
return
result
;
}
catch
(
error
)
{
console
.
log
(
'
Instrument
'
+
instrument
+
'
at
'
+
endpoint
+
'
unreachable
'
);
}
}
reset
(
nomadServerId
)
{
return
this
.
_
addon
.
reset
(
nomadServerId
)
;
getPositions
(
instrument
,
nomadServerId
)
{
return
this
.
_
positions
[
instrument
][
nomadServerId
]
;
}
}
module
.
exports
=
new
NomadPositions
();
\ No newline at end of file
module
.
exports
=
NomadPositions
;
\ No newline at end of file
js/server/com/nomad-positions2.js
deleted
100644 → 0
View file @
d4199401
const
config
=
require
(
"
../config
"
);
const
CameoServer
=
require
(
"
./cameo-server
"
);
const
zmq
=
require
(
"
zeromq
"
);
/**
*
*/
class
NomadPositions2
{
constructor
()
{
// Get the list of instruments.
this
.
_models
=
config
.
models
;
// Create the subscriber to all the instruments.
this
.
_subscriber
=
new
zmq
.
Subscriber
;
// Positions of all the instruments.
this
.
_positions
=
{};
}
async
_positionsLoop
()
{
// Wait for a new message.
const
[
identity
,
type
,
message
]
=
await
this
.
_subscriber
.
receive
();
// Decode the message.
const
instrumentPositions
=
JSON
.
parse
(
message
.
toString
());
const
instrument
=
instrumentPositions
[
"
instrument
"
];
const
id
=
instrumentPositions
[
"
id
"
];
const
positions
=
instrumentPositions
[
"
positions
"
];
if
(
!
(
instrument
in
this
.
_positions
))
{
this
.
_positions
[
instrument
]
=
{};
}
this
.
_positions
[
instrument
][
id
]
=
positions
;
// Continue the loop.
setTimeout
(()
=>
{
this
.
_positionsLoop
();
});
}
async
init
()
{
// Subscribe to all the instruments.
for
(
let
instrument
in
this
.
_models
)
{
const
endpoint
=
this
.
_models
[
instrument
][
"
endpoint
"
];
const
server
=
new
CameoServer
(
endpoint
);
try
{
const
publisherProxyPort
=
await
server
.
getPublisherProxyPort
();
console
.
log
(
'
Instrument
'
+
instrument
+
'
at
'
+
endpoint
+
'
with publisher proxy port
'
+
publisherProxyPort
);
let
publisherEndpoint
=
endpoint
.
substring
(
0
,
endpoint
.
lastIndexOf
(
"
:
"
)
+
1
);
publisherEndpoint
+=
publisherProxyPort
;
console
.
log
(
'
Connecting
'
+
publisherEndpoint
);
this
.
_subscriber
.
connect
(
publisherEndpoint
);
const
topic
=
'
publisher-55845880-56e9-4ad6-bea1-e84395c90b32-nomad3d_positions
'
;
this
.
_subscriber
.
subscribe
(
topic
);
}
catch
(
error
)
{
console
.
log
(
'
Instrument
'
+
instrument
+
'
at
'
+
endpoint
+
'
unreachable
'
);
}
}
// Start the message loop.
this
.
_positionsLoop
();
}
async
getSimulatedServerIds
(
instrument
)
{
const
endpoint
=
this
.
_models
[
instrument
][
"
endpoint
"
];
const
server
=
new
CameoServer
(
endpoint
);
let
result
=
[];
try
{
const
apps
=
await
server
.
getApplicationInfos
();
for
(
let
app
of
apps
)
{
if
(
app
[
"
name
"
]
===
'
nssim
'
)
{
result
.
push
(
app
[
"
id
"
]);
}
}
return
result
;
}
catch
(
error
)
{
console
.
log
(
'
Instrument
'
+
instrument
+
'
at
'
+
endpoint
+
'
unreachable
'
);
}
}
getPositions
(
instrument
,
nomadServerId
)
{
return
this
.
_positions
[
instrument
][
nomadServerId
];
}
}
module
.
exports
=
NomadPositions2
;
\ No newline at end of file
js/server/com/positions-responder.js
View file @
886491d3
...
...
@@ -3,8 +3,6 @@ class PositionsResponder {
constructor
(
responder
,
nomadPositions
)
{
// Register the handlers.
this
.
NomadPositions
=
require
(
'
./nomad-positions
'
);
responder
.
onRequestAsync
(
'
GetSimulatedServerIds
'
,
(
instrument
)
=>
{
return
nomadPositions
.
getSimulatedServerIds
(
instrument
);
});
...
...
@@ -14,15 +12,13 @@ class PositionsResponder {
});
responder
.
onRequest
(
'
PausePositionsRequest
'
,
(
nomadServerId
)
=>
{
return
this
.
NomadPositions
.
pause
(
nomadServerId
)
// To be implemented.
return
{};
});
responder
.
onRequest
(
'
RestartPositionsRequest
'
,
(
nomadServerId
)
=>
{
return
this
.
NomadPositions
.
restart
(
nomadServerId
)
});
responder
.
onRequest
(
'
ResetNomadPosition
'
,
(
nomadServerId
)
=>
{
return
this
.
NomadPositions
.
reset
(
nomadServerId
)
// To be implemented.
return
{};
});
}
...
...
js/server/main/main-server.js
View file @
886491d3
...
...
@@ -18,25 +18,22 @@ const WebSocket = require('ws');
const
Responder
=
require
(
'
../../external/com/responder
'
);
const
config
=
require
(
'
../config
'
);
const
nomadPositions
=
require
(
'
../com/nomad-positions
'
);
const
AssetResponder
=
require
(
"
../com/asset-responder
"
);
const
PositionsResponder
=
require
(
"
../com/positions-responder
"
);
const
CollisionsResponder
=
require
(
"
../com/collisions-responder
"
);
const
NomadPositions2
=
require
(
'
../com/nomad-positions2
'
);
nomadPositions
.
init
(
config
.
endpoints
.
localEndpoint
,
config
.
endpoints
.
nomadEndpoint
);
const
NomadPositions
=
require
(
'
../com/nomad-positions
'
);
const
wss
=
new
WebSocket
.
Server
({
port
:
8080
});
const
responder
=
new
Responder
(
wss
);
const
nomadPositions
2
=
new
NomadPositions
2
();
const
positionsResponder
=
new
PositionsResponder
(
responder
,
nomadPositions
2
);
const
nomadPositions
=
new
NomadPositions
();
const
positionsResponder
=
new
PositionsResponder
(
responder
,
nomadPositions
);
const
collisionsResponder
=
new
CollisionsResponder
(
responder
);
const
assetResponder
=
new
AssetResponder
(
responder
);
nomadPositions
2
.
init
();
nomadPositions
.
init
();
const
app
=
express
();
...
...
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment