Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
nrm
Commits
045845c2
Commit
045845c2
authored
Sep 05, 2017
by
Srinivasan Ramesh
Browse files
Add pub-sub connection between GRM and NRM
parent
9aa153dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
045845c2
...
...
@@ -4,7 +4,7 @@ source:
$(PYTHON)
setup.py sdist
install
:
$(PYTHON)
setup.py
install
--force
$(PYTHON)
setup.py
install
--force
--prefix
/g/g91/ramesh2/ARGO/NRM
check
:
tox
nrm/daemon.py
View file @
045845c2
...
...
@@ -71,7 +71,7 @@ class Daemon(object):
self
.
applications
=
{}
self
.
buf
=
''
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
target
=
1
self
.
target
=
1
.0
def
do_application_receive
(
self
,
parts
):
self
.
logger
.
info
(
"receiving application stream: "
+
repr
(
parts
))
...
...
@@ -104,10 +104,14 @@ class Daemon(object):
total_power
=
self
.
machine_info
[
'energy'
][
'power'
][
'total'
]
# Publish the power values so that GRM can pick it up
self
.
nrm_publish_sock
.
send
(
"%f"
%
(
total_power
))
nrm_topic
=
"23.45"
self
.
nrm_publish_sock
.
send
(
"%s %s"
%
(
nrm_topic
,
str
(
total_power
)))
self
.
logger
.
info
(
"Sending power values: "
+
str
(
total_power
))
self
.
target
=
random
.
randrange
(
0
,
34
)
# Subcribe to the topic for new power allocations published by the GRM
# self.target = random.randrange(0, 34)
string
=
self
.
grm_publish_sock
.
recv
()
topic
,
self
.
target
=
string
.
split
()
self
.
logger
.
info
(
"target measure: "
+
str
(
self
.
target
))
for
identity
,
application
in
self
.
applications
.
iteritems
():
...
...
@@ -144,15 +148,21 @@ class Daemon(object):
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
STREAM
)
self
.
nrm_publish_sock
=
context
.
socket
(
zmq
.
PUB
)
self
.
grm_publish_sock
=
context
.
socket
(
zmq
.
SUB
)
bind_param
=
"tcp://%s:%d"
%
(
bind_address
,
bind_port
)
nrm_bind_param
=
"tcp://%s:%d"
%
(
bind_address
,
nrm_publish_port
)
grm_bind_param
=
"tcp://localhost:%d"
%
(
grm_publish_port
)
socket
.
bind
(
bind_param
)
self
.
nrm_publish_sock
.
bind
(
nrm_bind_param
)
self
.
grm_publish_sock
.
connect
(
grm_bind_param
)
grm_filter
=
"34.56 "
self
.
grm_publish_sock
.
setsockopt
(
zmq
.
SUBSCRIBE
,
grm_filter
)
self
.
logger
.
info
(
"socket bound to: "
+
bind_param
)
self
.
logger
.
info
(
"NRM publish socket bound to: "
+
nrm_bind_param
)
self
.
logger
.
info
(
"GRM publish socket connected to: "
+
grm_bind_param
)
self
.
stream
=
zmqstream
.
ZMQStream
(
socket
)
self
.
stream
.
on_recv
(
self
.
do_application_receive
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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