Exemple #1
0
    def __init__(self, auto_parse: bool = False):

        if ReportManager.__instance != None:
            raise Exception(
                __name__, '::__init__ an object of the class already exists.')
        else:
            ReportManager.__instance = self

        # Initialize the config manager
        ConfigManager.instance()

        # If auto parsing is enabled, parse the reports according to the .JSON source
        if auto_parse:
            self._parse_reports()
Exemple #2
0
    def run(self, *args: List, **kwargs: Dict) -> bool:
        config = ConfigManager.instance().get_config(ConfigType.SMTP)
        
        if config is None:
            print(__name__,'::run() could not retrieve SMTP configuration, ', kwargs)
            return kwargs
        
        file_name: str = kwargs.get('attachment_name')
        sender: str = kwargs.get('sender')
        recipient: List[str] = kwargs.get('recipient')
        subject: str = kwargs.get('subject')
        body: str = kwargs.get('body')

        
        smtp_server: str = config.get('server')
        smtp_user: str = config.get('user')
        smtp_pwd: str = config.get('password')
        
        if smtp_server is None:
            print(__name__,'::run() no SMTP server name provided, ', kwargs)
            return kwargs
                
        server: smtplib.SMTP = smtplib.SMTP(smtp_server)
        server.login(smtp_user, smtp_pwd)
        
        server.sendmail(sender, recepient, body)
        
        server.quit()
                
        return True
Exemple #3
0
    def _parse_reports(self) -> None:
        reports_full_path: str = ConfigManager.instance().get_config(
            ConfigType.Reports, 'location')

        if reports_full_path is None:
            print(
                __name__,
                '::_parse_reports() could not retrieve report JSON definition, ',
                reports_full_path)

            return

        if path.exists(reports_full_path):

            with open(reports_full_path, 'r') as reports_source:
                file: AnyStr = reports_source.read()

                if file is not None:
                    data = loads(file)

                    if data is not None:
                        for department in data:
                            for report_data in data[department]:

                                report_instance: Report = Report()
                                report_instance.from_json(report_data)

                                if report_instance is not None:
                                    self.append(department, report_instance)
        else:
            print(__name__, "::parse_reports() invalid reports source.")
            return
Exemple #4
0
def command(websocket):
    x = 0
    y = 0
    w = 0

    for buf in log_queue:
        websocket.send(buf)

    game_config = ConfigManager.instance("game")

    def get_game_options():
        return [
            ("field_id", [game_config.get_value("global", "field_id"),"A","B","Z"]),
            ("robot_id", [game_config.get_value("global", "robot_id"),"A","B"]),
            ("target goal color", [game_config.get_value("global", "target goal color"),"yellow","blue"]),
            ("gameplay status", [game_config.get_value("global", "gameplay status"),"disabled", "enabled"]),
        ]
    
    game_options = get_game_options()

    settings_packet = json.dumps(dict(
        action = "settings-packet",
        sliders = ConfigManager.as_list("imgrec"),
        options = game_options
    ))
    websocket.send(settings_packet)

    while not websocket.closed:
        websockets.add(websocket)

        gevent.sleep(0.01)

        msg = websocket.receive()

        if not msg:
            websockets.remove(websocket)
            logger.info("WebSocket connection presumably closed, %d left connected" % len(websockets))
            break

        response = json.loads(msg)
        action = response.pop("action", None)
        if not action:
            logger.info("Unknown action")
            continue


        if action == "gamepad":
            controls = response.pop("data")
            x = controls.pop("controller0.axis0", x) * 0.99
            y = controls.pop("controller0.axis1", y) * 0.99
            w = controls.pop("controller0.axis2", w) * 0.7

            # Kick the ball
            if controls.get("controller0.button7", None):
                gameplay.arduino.kick()

            # Toggle autonomy
            if controls.get("controller0.button4", None):
                gameplay.toggle()

            # Manual control of the robot
            if not gameplay.alive:
                gameplay.arduino.set_xyw(x,-y,-w)

        # TODO: slders
        elif action == "record_toggle":
            print("TOGGLING RECORDER")
            recorder.toggle()
        elif action == "record_enable":
            recorder.enable()
        elif action == "record_disable":
            recorder.disable()
        elif action == "set_settings":
            for k, v in response.items():
                ConfigManager.set_config_value(k, v)
            print(response.items())
        elif action == "set_options":
            for k, v in response.items():
                game_config.get_option("global", k).set_value(v)
                game_config.save()
            print(response.items())
        else:
            logger.error("Unhandled action: %s", action)
    websockets.remove(websocket)
    logger.info("WebSocket connection closed, %d left connected", len(websockets))
    return b""