コード例 #1
0
ファイル: SDKApplication.py プロジェクト: sycomix/pydjisdk
    def __init__(self, **kwargs):
        super(SDKApplication, self).__init__()

        with open('logconfig.yaml', 'r') as f:
            logging.config.dictConfig(yaml.load(f.read(), Loader=yaml.Loader))

        self.applogger = logging.getLogger('app')

        self.port_rx_stream_queue = Queue.Queue()
        self.parsed_message_queue = Queue.Queue()

        self.active_info = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('app_id', None),
                ('app_ver', 0x03010a00),
                ('bundle_id', '12345678901234567890123456789012'),
            ]]
        )
        if not self.active_info.get('app_id'):
            raise TypeError(
                '{}.__init__() must pass argument "app_id"!'.format(__class__))

        encrypt_param = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('crc16_init', 0x3AA3),
                ('crc16_poly', 0x18005),
                ('crc32_init', 0x3AA3),
                ('crc32_poly', 0x104C11DB7),
                ('aes256_key', None),
            ]]
        )
        if not encrypt_param.get('aes256_key'):
            raise TypeError(
                '{}.__init__() must pass argument "aes256_key"!'.format(__class__))

        EncryptCodec.initEncryptCodec(encrypt_param)

        port_param = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('port', '/dev/ttyUSB0'),
                ('baudrate', 230400),
                ('read_bytes', 12),
                ('buffer_queue', self.port_rx_stream_queue),
            ]]
        )
        self.port = SerialPort(**port_param)

        self.parser = ProtocolParser(
            self.port_rx_stream_queue, self.parsed_message_queue)

        self.sm = SessionManager(self.port.write)

        self.register_data_handle()
        self.port.open()
        self.parser.start()
コード例 #2
0
    def get(self):
        session_id = self.get_current_user()
        session = SessionManager.getSession(session_id)

        user_obj = {
            "name": session.getValue("username")
        }

        self.finish(json.dumps(user_obj))
コード例 #3
0
    def __init__(self, **kwargs):
        super(SDKApplication, self).__init__()

        with open('logconfig.yaml', 'r') as f:
            logging.config.dictConfig(yaml.load(f.read(), Loader=yaml.Loader))

        self.applogger = logging.getLogger('app')

        self.port_rx_stream_queue = Queue.Queue()
        self.parsed_message_queue = Queue.Queue()

        self.active_info = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('app_id', None),
                ('api_level', 0x02),
                ('app_ver', 0x01),
                ('bundle_id', '12345678901234567890123456789012'),
            ]]
        )
        if not self.active_info.get('app_id'):
            raise TypeError(
                '{}.__init__() must pass argument "app_id"!'.format(__class__))

        encrypt_param = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('crc16_init', 0x3AA3),
                ('crc16_poly', 0x18005),
                ('crc32_init', 0x3AA3),
                ('crc32_poly', 0x104C11DB7),
                ('aes256_key', None),
            ]]
        )
        if not encrypt_param.get('aes256_key'):
            raise TypeError(
                '{}.__init__() must pass argument "aes256_key"!'.format(__class__))

        EncryptCodec.initEncryptCodec(encrypt_param)

        port_param = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('port', '/dev/ttyUSB0'),
                ('baudrate', 230400),
                ('read_bytes', 12),
                ('buffer_queue', self.port_rx_stream_queue),
            ]]
        )
        self.port = SerialPort(**port_param)

        self.parser = ProtocolParser(
            self.port_rx_stream_queue, self.parsed_message_queue)

        self.sm = SessionManager(self.port.write)

        self.register_data_handle()
        self.port.open()
        self.parser.start()
コード例 #4
0
    def post(self):
        data = tornado.escape.json_decode(self.request.body)

        #TODO: Validate this properly
        if "username" in data:
            session_id = self.get_current_user()
            session = SessionManager.getSession(session_id)

            #Escape username
            username = tornado.escape.xhtml_escape(data["username"])

            #Set new username
            session.setValue("username", username)
コード例 #5
0
    def __init__(self, **kwargs):
        super(SDKApplication, self).__init__()

        with open("logconfig.yaml", "r") as f:
            logging.config.dictConfig(yaml.load(f.read(), Loader=yaml.Loader))

        self.applogger = logging.getLogger("app")

        self.port_rx_stream_queue = Queue.Queue()
        self.parsed_message_queue = Queue.Queue()

        self.active_info = dict(
            [
                (k, kwargs.get(k, v))
                for (k, v) in [
                    ("app_id", None),
                    ("app_ver", 0x03010A00),
                    ("bundle_id", "12345678901234567890123456789012"),
                ]
            ]
        )
        if not self.active_info.get("app_id"):
            raise TypeError('{}.__init__() must pass argument "app_id"!'.format(__class__))

        encrypt_param = dict(
            [
                (k, kwargs.get(k, v))
                for (k, v) in [
                    ("crc16_init", 0x3AA3),
                    ("crc16_poly", 0x18005),
                    ("crc32_init", 0x3AA3),
                    ("crc32_poly", 0x104C11DB7),
                    ("aes256_key", None),
                ]
            ]
        )
        if not encrypt_param.get("aes256_key"):
            raise TypeError('{}.__init__() must pass argument "aes256_key"!'.format(__class__))

        EncryptCodec.initEncryptCodec(encrypt_param)

        port_param = dict(
            [
                (k, kwargs.get(k, v))
                for (k, v) in [
                    ("port", "/dev/ttyUSB0"),
                    ("baudrate", 230400),
                    ("read_bytes", 12),
                    ("buffer_queue", self.port_rx_stream_queue),
                ]
            ]
        )
        self.port = SerialPort(**port_param)

        self.parser = ProtocolParser(self.port_rx_stream_queue, self.parsed_message_queue)

        self.sm = SessionManager(self.port.write)

        self.register_data_handle()
        self.port.open()
        self.parser.start()
コード例 #6
0
class SDKApplication(StoppableThread):

    """
    SDKApplication class for main entrance for api.

    Usage:
    >>> app = SDKApplication(app_id, aes256_key, port)
    >>> app.get_api_version()
    ...
    >>> app.active_api()
    ...
    >>> app.acquire_control()
    ...
    >>> app.release_control()
    ...
    >>> app.close()

    The following are the parameters supplied to the constructor.

    app_id -- your app id

    aes256_key -- your enc key

    port -- your serial port path

    baudrate -- your serial port baudrate

    """

    def __init__(self, **kwargs):
        super(SDKApplication, self).__init__()

        with open("logconfig.yaml", "r") as f:
            logging.config.dictConfig(yaml.load(f.read(), Loader=yaml.Loader))

        self.applogger = logging.getLogger("app")

        self.port_rx_stream_queue = Queue.Queue()
        self.parsed_message_queue = Queue.Queue()

        self.active_info = dict(
            [
                (k, kwargs.get(k, v))
                for (k, v) in [
                    ("app_id", None),
                    ("app_ver", 0x03010A00),
                    ("bundle_id", "12345678901234567890123456789012"),
                ]
            ]
        )
        if not self.active_info.get("app_id"):
            raise TypeError('{}.__init__() must pass argument "app_id"!'.format(__class__))

        encrypt_param = dict(
            [
                (k, kwargs.get(k, v))
                for (k, v) in [
                    ("crc16_init", 0x3AA3),
                    ("crc16_poly", 0x18005),
                    ("crc32_init", 0x3AA3),
                    ("crc32_poly", 0x104C11DB7),
                    ("aes256_key", None),
                ]
            ]
        )
        if not encrypt_param.get("aes256_key"):
            raise TypeError('{}.__init__() must pass argument "aes256_key"!'.format(__class__))

        EncryptCodec.initEncryptCodec(encrypt_param)

        port_param = dict(
            [
                (k, kwargs.get(k, v))
                for (k, v) in [
                    ("port", "/dev/ttyUSB0"),
                    ("baudrate", 230400),
                    ("read_bytes", 12),
                    ("buffer_queue", self.port_rx_stream_queue),
                ]
            ]
        )
        self.port = SerialPort(**port_param)

        self.parser = ProtocolParser(self.port_rx_stream_queue, self.parsed_message_queue)

        self.sm = SessionManager(self.port.write)

        self.register_data_handle()
        self.port.open()
        self.parser.start()

    def register_data_handle(self):
        self.recv_data_handler_table = CMD_SET_R

    def launch(self):
        self.start()

    def close(self):
        self.sm.close_all_sessions()
        self.port.close()
        self.stop()

    def run(self):
        while not self.stopped():
            try:
                (header, data_buf) = self.parsed_message_queue.get(block=True, timeout=3.0)
                assert isinstance(header, ProtocolHeader) and isinstance(data_buf, bytes)

                if header.ack:
                    self.sm.feed_ack(header.session, header.seq, data_buf)
                else:
                    d = ProtocolData()
                    cmd_set, cmd_id, content = d.parse(data_buf)
                    self.recv_data_handler_table[cmd_set][cmd_id](content)
                    # LOG('Data received.')
            except Queue.Empty, e:
                pass
コード例 #7
0
class SDKApplication(StoppableThread):
    '''
    SDKApplication class for main entrance for api.

    Usage:
    >>> app = SDKApplication(app_id, aes256_key, port)
    >>> app.get_api_version()
    ...
    >>> app.active_api()
    ...
    >>> app.acquire_control()
    ...
    >>> app.release_control()
    ...
    >>> app.close()

    The following are the parameters supplied to the constructor.

    app_id -- your app id

    aes256_key -- your enc key

    port -- your serial port path

    baudrate -- your serial port baudrate

    '''
    def __init__(self, **kwargs):
        super(SDKApplication, self).__init__()

        with open('logconfig.yaml', 'r') as f:
            logging.config.dictConfig(yaml.load(f.read(), Loader=yaml.Loader))

        self.applogger = logging.getLogger('app')

        self.port_rx_stream_queue = Queue.Queue()
        self.parsed_message_queue = Queue.Queue()

        self.active_info = dict([(k, kwargs.get(k, v)) for (k, v) in [
            ('app_id', None),
            ('app_ver', 0x03010A00),
            ('bundle_id', '12345678901234567890123456789012'),
        ]])
        if not self.active_info.get('app_id'):
            raise TypeError(
                '{}.__init__() must pass argument "app_id"!'.format(__class__))

        encrypt_param = dict([(k, kwargs.get(k, v)) for (k, v) in [
            ('crc16_init', 0x3AA3),
            ('crc16_poly', 0x18005),
            ('crc32_init', 0x3AA3),
            ('crc32_poly', 0x104C11DB7),
            ('aes256_key', None),
        ]])
        if not encrypt_param.get('aes256_key'):
            raise TypeError(
                '{}.__init__() must pass argument "aes256_key"!'.format(
                    __class__))

        EncryptCodec.initEncryptCodec(encrypt_param)

        port_param = dict([(k, kwargs.get(k, v)) for (k, v) in [
            ('port', '/dev/ttyUSB0'),
            ('baudrate', 230400),
            ('read_bytes', 12),
            ('buffer_queue', self.port_rx_stream_queue),
        ]])
        self.port = SerialPort(**port_param)

        self.parser = ProtocolParser(self.port_rx_stream_queue,
                                     self.parsed_message_queue)

        self.sm = SessionManager(self.port.write)

        self.register_data_handle()
        self.port.open()
        self.parser.start()

    def register_data_handle(self):
        self.recv_data_handler_table = CMD_SET_R

    def launch(self):
        self.start()

    def close(self):
        self.sm.close_all_sessions()
        self.port.close()
        self.stop()

    def run(self):
        while (not self.stopped()):
            try:
                (header, data_buf) = self.parsed_message_queue.get(block=True,
                                                                   timeout=3.0)
                assert isinstance(header, ProtocolHeader) and isinstance(
                    data_buf, bytes)

                if header.ack:
                    self.sm.feed_ack(header.session, header.seq, data_buf)
                else:
                    d = ProtocolData()
                    cmd_set, cmd_id, content = d.parse(data_buf)
                    self.recv_data_handler_table[cmd_set][cmd_id](content)
                    # LOG('Data received.')
            except Queue.Empty, e:
                pass
コード例 #8
0
class SDKApplication(StoppableThread):

    def __init__(self, **kwargs):
        super(SDKApplication, self).__init__()

        with open('logconfig.yaml', 'r') as f:
            logging.config.dictConfig(yaml.load(f.read(), Loader=yaml.Loader))

        self.applogger = logging.getLogger('app')

        self.port_rx_stream_queue = Queue.Queue()
        self.parsed_message_queue = Queue.Queue()

        self.active_info = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('app_id', None),
                ('api_level', 0x02),
                ('app_ver', 0x01),
                ('bundle_id', '12345678901234567890123456789012'),
            ]]
        )
        if not self.active_info.get('app_id'):
            raise TypeError(
                '{}.__init__() must pass argument "app_id"!'.format(__class__))

        encrypt_param = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('crc16_init', 0x3AA3),
                ('crc16_poly', 0x18005),
                ('crc32_init', 0x3AA3),
                ('crc32_poly', 0x104C11DB7),
                ('aes256_key', None),
            ]]
        )
        if not encrypt_param.get('aes256_key'):
            raise TypeError(
                '{}.__init__() must pass argument "aes256_key"!'.format(__class__))

        EncryptCodec.initEncryptCodec(encrypt_param)

        port_param = dict(
            [(k, kwargs.get(k, v)) for (k, v) in [
                ('port', '/dev/ttyUSB0'),
                ('baudrate', 230400),
                ('read_bytes', 12),
                ('buffer_queue', self.port_rx_stream_queue),
            ]]
        )
        self.port = SerialPort(**port_param)

        self.parser = ProtocolParser(
            self.port_rx_stream_queue, self.parsed_message_queue)

        self.sm = SessionManager(self.port.write)

        self.register_data_handle()
        self.port.open()
        self.parser.start()

    def register_data_handle(self):
        self.recv_data_handler_table = CMD_SET_R

    def launch(self):
        self.start()

    def close(self):
        self.sm.close_all_sessions()
        self.port.close()
        self.stop()

    def run(self):
        while (not self.stopped()):
            try:
                (header, data_buf) = self.parsed_message_queue.get(
                    block=True, timeout=3.0)
                assert isinstance(header, ProtocolHeader) and isinstance(
                    data_buf, bytes)

                if header.ack:
                    self.sm.feed_ack(header.session, header.seq, data_buf)
                else:
                    d = ProtocolData()
                    cmd_set, cmd_id, content = d.parse(data_buf)
                    self.recv_data_handler_table[cmd_set][cmd_id](content)
                    # LOG('Data received.')
            except Queue.Empty, e:
                pass