本文整理匯總了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