本文整理汇总了Python中obci.control.common.message.OBCIMessageTool.decode_msg方法的典型用法代码示例。如果您正苦于以下问题:Python OBCIMessageTool.decode_msg方法的具体用法?Python OBCIMessageTool.decode_msg怎么用?Python OBCIMessageTool.decode_msg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obci.control.common.message.OBCIMessageTool
的用法示例。
在下文中一共展示了OBCIMessageTool.decode_msg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OBCIConnection
# 需要导入模块: from obci.control.common.message import OBCIMessageTool [as 别名]
# 或者: from obci.control.common.message.OBCIMessageTool import decode_msg [as 别名]
class OBCIConnection(object):
"""
Synchronous OBCI connection.
"""
def __init__(self, address):
templates = launcher_messages.message_templates
self.msg_factory = OBCIMessageTool(msg_templates=templates)
self.netstring_codec = NetstringCodec()
self.address = address
self.experiment_uuid = None
def close(self):
self.connection.close()
def open(self):
self.connection = socket.create_connection(self.address, timeout=30)
def send_recv(self, message_name, **kwargs):
message_json = self.msg_factory.fill_msg(message_name, **kwargs)
message_netstring = self.netstring_codec.encode(message_json)
self.open()
self.connection.send(message_netstring)
response_json = self.netstring_codec.decode(self.connection)
self.close()
response_dict = self.msg_factory.decode_msg(response_json)
return response_dict
def get_amp_list(self):
message = self.msg_factory.fill_msg("find_eeg_amplifiers")
message = self.netstring_codec.encode(message)
self.open()
self.connection.send(message)
response_text = self.netstring_codec.decode(self.connection)
response = self.msg_factory.decode_msg(response_text)
self.close()
amp_list = response["amplifier_list"]
return amp_list
def start_eeg_signal(self, name, launch_file, amplifier_params):
message = self.msg_factory.fill_msg("start_eeg_signal", launch_file=launch_file, amplifier_params=amplifier_params, name=name)
message_text = self.netstring_codec.encode(message)
self.open()
self.connection.send(message_text)
response_text = self.netstring_codec.decode(self.connection)
response = self.msg_factory.decode_msg(response_text)
self.close()
return response["sender"]
def get_experiment_contact(self, name):
response = self.send_recv("get_experiment_contact", strname=name)
self.experiment_uuid = response["uuid"]
return self.experiment_uuid
def stop_experiment(self, experiment_uuid=None):
if not experiment_uuid:
experiment_uuid = self.experiment_uuid
message = self.msg_factory.fill_msg("kill_experiment", strname=experiment_uuid)
message_text = self.netstring_codec.encode(message)
self.open()
self.connection.send(message_text)
response_text = self.netstring_codec.decode(self.connection)
self.close()
response = self.msg_factory.decode_msg(response_text)
return response
def create_experiment(self, name="unnamed"):
message = self.msg_factory.fill_msg("create_experiment", name=name)
message_text = self.netstring_codec.encode(message)
self.open()
self.connection.send(message_text)
response_text = self.netstring_codec.decode(self.connection)
self.close()
return self.msg_factory.decode_msg(response_text)
def set_experiment_scenario(self, launch_file_path="", scenario=""):
return self.send_recv("set_experiment_scenario", launch_file_path=launch_file_path, scenario=scenario)
def start_experiment(self):
return self.send_recv("start_experiment")
def get_nearby_servers(self):
response = self.send_recv("list_nearby_machines")
return response