Ejemplo n.º 1
0
    def __init__(self):
        self.camera = PiCamera()

        # PiCamera Settings
        self.camera.resolution = (self.width, self.height)
        if not hasattr(self, 'framerate'):
            self.framerate = 24
        if not hasattr(self, 'frec'):
            self.frec = 0.02

        self.camera.framerate = self.framerate
        self.camera.contrast = 0
        self.camera.brightness = 50
        self.camera.video_stabilization = True
        self.camera.image_effect = 'none'
        self.camera.color_effects = None
        self.camera.rotation = 0

        self.camera.hflip = True if not hasattr(self, 'hflip') else self.hflip
        self.camera.vflip = True if not hasattr(self, 'vflip') else self.vflip

        # self.camera.sharpness = 0
        # self.camera.saturation = 0
        # self.camera.ISO = 0
        # self.camera.sure_compensation = 0
        # self.camera.exposure_mode = 'auto'
        # self.camera.meter_mode = 'average'
        # self.camera.awb_mode = 'auto'
        # self.camera.crop = (0.0, 0.0, 1.0, 1.0)

        # Stream settings
        self.buffer = BytesIO()
        self.clients = list()
        self.initPort = 9000

        self.ip = utils.get_ip_address(self.ethernet)

        self.start_worker(self.worker_read)
        self.start_thread(self.removeClosedConnections)
Ejemplo n.º 2
0
    def fix_config(self):

        # Add default frec
        if "def_frec" not in self.conf["node"]:
            self.conf["node"]["def_frec"] = 0.05

        # Add ethernet network
        if "ethernet" not in self.conf["node"]:
            self.conf["node"]["ethernet"] = utils.get_interface()

        # Add IP address
        if "ip" not in self.conf["node"]:
            self.conf["node"]["ip"] = utils.get_ip_address(
                self.conf["node"]["ethernet"])
        # add tty out and tty err
        tty_out, tty_err = utils.assing_ttys()
        self.conf["node"]["tty_default"] = utils.get_tty()
        if "tty_out" not in self.conf["node"]:
            self.conf["node"]["tty_out"] = tty_out
        if "tty_err" not in self.conf["node"]:
            self.conf["node"]["tty_err"] = tty_err

        # Add default name
        if "name" not in self.conf["node"]:
            self.conf["node"]["name"] = "default_name"

        # Add port_ns
        if "port_ns" not in self.conf["node"]:
            self.conf["node"]["port_ns"] = 9090

        # Add port_node
        if "port_node" not in self.conf["node"]:
            self.conf["node"]["port_node"] = 4040

        # Add start_port
        if "start_port" not in self.conf["node"]:
            self.conf["node"]["start_port"] = 5050

        # Add def_worker
        if "def_worker" not in self.conf["node"]:
            self.conf["node"]["def_worker"] = True

        # Add password
        if "password" not in self.conf["node"]:
            self.conf["node"]["password"] = self.conf["node"]["name"]

        # Add bigbrother password
        if "bigbrother-password" not in self.conf["node"]:
            self.conf["node"]["bigbrother-password"] = "******"

        # Services and components config
        for k, v in list(self.components.items()) + list(
                self.services.items()):
            if "worker_run" not in v:
                v["worker_run"] = True
            if "mode" not in v:
                v["mode"] = "public"
            if "frec" not in v:
                v["frec"] = self.conf["node"]["def_frec"]
            v["docstring"] = {}
            v["exposed"] = {}
        for k, v in self.services.items():
            if "mode" not in v:
                v["mode"] = "local"

        # Services configuration
        newservices = {}
        for n in self.services:
            if _classes.get(self.services[n]["cls"], None) is not None:
                if len(_classes[self.services[n]["cls"]]) > 1:
                    print("Warning: there are many modules {} for class {}".
                          format(_classes[self.services[n]["cls"]],
                                 self.services[n]["cls"]))
                self.services[n]["module"] = _classes[self.services[n]
                                                      ["cls"]][0]
                if "." not in n:
                    newservices[self.node["name"] + "." + n] = self.services[n]
                else:
                    newservices[n] = self.services[n]
            else:
                print(
                    colored(
                        "ERROR: Class {} not found or error in Modules".format(
                            self.services[n]["cls"]), "red"))
                for k_error, error in _modules_errors.items():
                    print("Module {}: {}".format(k_error, error))
                exit()
            if "-->" in self.services[n]:
                sp = [
                    self.node["name"] + "." + x
                    for x in self.services[n]["-->"] if x.find(".") < 0
                ]
                cp = [x for x in self.services[n]["-->"] if x.find(".") >= 0]
                self.services[n]["-->"] = sp + cp  # esto se puede simplificar

        self.conf["services"] = newservices

        for n in self.services:
            self.services[n]["_locals"] = []
            self.services[n]["_resolved_remote_deps"] = []
            if "-->" in self.services[n]:
                self.services[n]["_locals"], self.services[n][
                    "_resolved_remote_deps"] = self.local_remote(
                        self.services, n)
        newrobot = {}
        # Components configuration
        for n in self.components:
            if _classes.get(self.components[n]["cls"], None) is not None:
                if len(_classes[self.components[n]["cls"]]) > 1:
                    print("Warning: there are many modules {} for class {}".
                          format(_classes[self.components[n]["cls"]],
                                 self.components[n]["cls"]))
                self.components[n]["module"] = _classes[self.components[n]
                                                        ["cls"]][0]
            else:
                print(
                    colored(
                        "ERROR: Class {} not found or error in Modules".format(
                            self.components[n]["cls"]), "red"))
                for k_error, error in _modules_errors.items():
                    print("Module {}: {}".format(k_error, error))
                exit()
            self.components[n]["_services"] = list(self.services)
            if "-->" in self.components[n]:
                sp = [
                    self.node["name"] + "." + x
                    for x in self.components[n]["-->"] if x.find(".") < 0
                ]
                cp = [x for x in self.components[n]["-->"] if x.find(".") >= 0]
                self.components[n][
                    "-->"] = sp + cp  # esto se puede simplificar
            if n.find(".") == -1:
                newrobot[self.node["name"] + "." + n] = self.components[n]
            else:
                newrobot[n] = self.components[n]

        self.conf["components"] = newrobot

        for n in self.components:
            self.components[n]["_locals"] = []
            self.components[n]["_unr_remote_deps"] = []
            self.components[n]["_resolved_remote_deps"] = []
            if "-->" in self.components[n]:
                self.components[n]["_locals"], self.components[n][
                    "_resolved_remote_deps"] = self.local_remote(
                        self.components, n)
Ejemplo n.º 3
0
import node.libs.utils as ut

print(ut.get_ip_address("eth0"))
Ejemplo n.º 4
0
import node.libs.utils as ut

print ut.get_ip_address("eth0")