Example #1
0
class Orchestrator(object):
    def __init__(self):
        self.modules = {}
        self.bt_controller = BtController()

    def get_modules(self):
        return self.modules.__dict__

    def module_action(self, module_id, **kwargs):
        module = self.modules[module_id]
        module.action(kwargs)

    def module_status(self, module_id):
        return self.modules[module_id].status()

    #TODO(abettadapur): Need some database to store modules on device shutdown
    def add_module(self, address, type):
        id = uuid4()
        if type == consts.FLIP_MODULE_TYPE:
            peripheral = Peripheral(address)
            module = flip.Flip(id, address, consts.FLIP_MODULE_TYPE,
                               peripheral)
            self.modules[id] = module

        elif type == consts.POKE_MODULE_TYPE:
            peripheral = Peripheral(address)
            module = poke.Poke(id, address, consts.POKE_MODULE_TYPE,
                               peripheral)
            self.modules[id] = module

        elif type == consts.ROTARY_MODULE_TYPE:
            peripheral = Peripheral(address)
            module = rotary.Rotary(id, address, consts.ROTARY_MODULE_TYPE,
                                   peripheral)
            self.modules[id] = modules

    def scan_modules(self):
        modules = self.bt_controller.discover()

    def remove_module(self, id):
        del self.modules[id]
Example #2
0
class Orchestrator(object):


    def __init__(self):
        self.modules = {}
        self.bt_controller = BtController()

    def get_modules(self):
        return self.modules.__dict__

    def module_action(self, module_id, **kwargs):
        module = self.modules[module_id]
        module.action(kwargs)

    def module_status(self, module_id):
        return self.modules[module_id].status()

    #TODO(abettadapur): Need some database to store modules on device shutdown
    def add_module(self, address, type):
        id = uuid4()
        if type == consts.FLIP_MODULE_TYPE:
            peripheral = Peripheral(address)
            module = flip.Flip(id, address, consts.FLIP_MODULE_TYPE, peripheral)
            self.modules[id] = module

        elif type == consts.POKE_MODULE_TYPE:
            peripheral = Peripheral(address)
            module = poke.Poke(id, address, consts.POKE_MODULE_TYPE, peripheral)
            self.modules[id] = module

        elif type == consts.ROTARY_MODULE_TYPE:
            peripheral = Peripheral(address)
            module = rotary.Rotary(id, address, consts.ROTARY_MODULE_TYPE, peripheral)
            self.modules[id] = modules

    def scan_modules(self):
        modules = self.bt_controller.discover()

    def remove_module(self, id):
        del self.modules[id]
Example #3
0
 def __init__(self):
     self.modules = {}
     self.bt_controller = BtController()
Example #4
0
 def __init__(self):
     self.modules = {}
     self.bt_controller = BtController()
Example #5
0
import threading
from flask import Flask
from flask_restful import Api
import time
from net import api as restapi
from bt.btcontroller import BtController
from gevent.pywsgi import WSGIServer
import gevent
from gevent import monkey

app = Flask(__name__)
Bt = BtController()
api = Api(app)

api.add_resource(restapi.System, '/system')
api.add_resource(restapi.Modules, '/modules')
api.add_resource(restapi.Module, '/module/<string:module_id>')

if __name__ == '__main__':
    http_server = WSGIServer(('0.0.0.0', 5000), app)

    http_server.serve_forever()