Commit c0b82b60 authored by Swann Perarnau's avatar Swann Perarnau
Browse files

Move sensor management to separate module

Create a `sensor` module that will handle the interaction with coolr and
return updated machine information regularly.

The code code is as dumb as the previous one, but the structure is
improved, which should help for the next round of updates with coolr.
parent 1a8707f2
......@@ -6,6 +6,7 @@ import re
import signal
import zmq
from zmq.eventloop import ioloop, zmqstream
import sensor
application_fsm_table = {'stable': {'i': 's_ask_i', 'd': 's_ask_d'},
's_ask_i': {'done': 'stable', 'max': 'max'},
......@@ -70,7 +71,6 @@ class Daemon(object):
self.applications = {}
self.buf = ''
self.logger = logging.getLogger(__name__)
self.current = 1 = 1
def do_application_receive(self, parts):
......@@ -97,19 +97,20 @@ class Daemon(object):
def do_sensor(self):
self.current = random.randrange(0, 34)"current measure: " + str(self.current))
self.sensor_state = self.sensor.do_update()"current state: %r" % self.sensor_state)
def do_control(self):
total_power = self.sensor_state['total_power'] = random.randrange(0, 34)"target measure: " + str(
for identity, application in self.applications.iteritems():
if self.current <
if total_power <
if 'i' in application.get_allowed_requests():[identity, 'i'])
elif self.current >
elif total_power >
if 'd' in application.get_allowed_requests():[identity, 'd'])
......@@ -137,8 +138,13 @@ class Daemon(object): = zmqstream.ZMQStream(socket)
self.sensor = ioloop.PeriodicCallback(self.do_sensor, 1000)
# create sensor manager and make first measurement
self.sensor = sensor.SensorManager()
self.sensor_state = self.sensor.do_update()
# setup periodic sensor updates
self.sensor_cb = ioloop.PeriodicCallback(self.do_sensor, 1000)
self.control = ioloop.PeriodicCallback(self.do_control, 1000)
"""Sensor Module:
provide the core functionalities related to measuring power, energy,
temperature and other information about the local node, using our internal
version of the coolr code.
This module should be the only one interfacing with coolr.
import random
class SensorManager:
"""Performs sensor reading and basic data aggregation."""
def __init__(self):
def do_update(self):
return {'total_power': random.randrange(0, 34)}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment