本文整理汇总了Python中packet.Packet.create方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.create方法的具体用法?Python Packet.create怎么用?Python Packet.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_state
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def get_state(self, *args):
"""
Respond to an incoming get_state request
:param args: not applicable to this command
:return:
"""
log.msg('get_state: %r %d' % (self.connections, self.num_connections))
if len(self.connections) == self.num_connections:
return Packet.create('CONNECTED', PacketType.PA_STATUS)
return Packet.create('DISCONNECTED', PacketType.PA_STATUS)
示例2: fileRetrieved
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def fileRetrieved(self, write_result):
file_obj, file_attributes, file_size = write_result
# Remove '.part' from the end of the file name now that the download is complete
new_file_path = file_obj.name[:-5]
os.rename(file_obj.name, new_file_path)
new_filename = os.path.basename(new_file_path)
log.msg('File downloaded: ', new_filename)
orig_filename = new_filename.split('_')[1]
self.retrieved_file_queue.append(orig_filename)
file_obj.close()
# Send a message to the driver indicating that a new image has been retrieved
# The driver will then associate metadata with the image file name
packets = Packet.create('New Image:' + str(new_filename), PacketType.FROM_INSTRUMENT)
self.router.got_data(packets)
reactor.callLater(0, self.fetch_file)
示例3: _set_select
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _set_select(self, command, *args):
if len(args) == 0:
num_sources = self.orb.select('')
else:
num_sources = self.orb.select(args[0])
msg = 'Orb select(%s) yielded num_sources: %d' % (args[:1], num_sources)
return Packet.create(msg + NEWLINE, PacketType.PA_STATUS)
示例4: get_version
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def get_version(self, *args):
"""
Respond to an incoming get_version request
:param args: not applicable to this command
:return:
"""
return Packet.create(ooi_port_agent.__version__, PacketType.PA_CONFIG)
示例5: get_config
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def get_config(self, *args):
"""
Respond to an incoming get_config request
:param args: not applicable to this command
:return:
"""
return Packet.create(json.dumps(self.config), PacketType.PA_CONFIG)
示例6: handle_command
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def handle_command(self, command_line):
log.msg('handle_command: %s' % command_line)
parts = command_line.split()
if len(parts) > 0:
command = parts[0]
args = parts[1:]
if command in self.callbacks:
packets = self.callbacks[command](command, *args)
else:
packets = Packet.create('Received bad command on command port: %r' % command, PacketType.PA_FAULT)
else:
packets = Packet.create('Received empty command on command port', PacketType.PA_FAULT)
if packets:
self.port_agent.router.got_data(packets)
示例7: notify_disconnected
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def notify_disconnected(self):
"""
Send a disconnect notification to the instrument driver
:return:
"""
log.msg('Notifying driver we are DISCONNECTED')
self.disconnect_notification_id = None
self.router.got_data(Packet.create('DISCONNECTED', PacketType.PA_STATUS))
示例8: _orb_stop
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _orb_stop(self, *args):
self.keep_going = False
if self.orb_thread is not None:
self.orb_thread.join()
self.orb_thread = None
msg = 'Stopped orb thread'
else:
msg = 'Orb thread not running!'
return Packet.create(msg + NEWLINE, PacketType.PA_STATUS)
示例9: _set_seek
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _set_seek(self, command, *args):
if len(args) == 0:
seek = ORBOLDEST
else:
seek = int(args[0])
self.orb.seek(seek)
msg = 'Orb seek set to %s' % seek
return Packet.create(msg + NEWLINE, PacketType.PA_STATUS)
示例10: _orb_start
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _orb_start(self, *args):
self._pause = False
if self.orb_thread is None:
self.keep_going = True
self.orb_thread = OrbThread(self.orb, self)
self.orb_thread.start()
msg = 'Started orb thread'
else:
msg = 'Orb already running!'
return Packet.create(msg + NEWLINE, PacketType.PA_STATUS)
示例11: _heartbeat
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _heartbeat(self):
packets = Packet.create('HB', PacketType.PA_HEARTBEAT)
self.router.got_data(packets)
# Set TTL Check Status
check_string = self._agent + 'check/pass/service:'
for port_id in [self.data_port_id, self.command_port_id, self.sniffer_port_id]:
d = get(check_string + port_id)
d.addCallback(self.done, caller='TTL check status: %s' % port_id)
d.addErrback(log.msg, 'Error sending check: %s' % port_id)
reactor.callLater(HEARTBEAT_INTERVAL, self._heartbeat)
示例12: _handle_digi_command
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _handle_digi_command(self, command, *args):
"""
Request a protocol object connected to the DIGI command port, then
produce the packets corresponding to a requested digi command
:param command: command
:param args: arguments
:return: List of packets representing this command.
"""
command = [command] + list(args)
command = ' '.join(command) + NEWLINE
protocol = yield self._start_inst_command_connection()
protocol.write(command)
returnValue(Packet.create(command, PacketType.DIGI_CMD))
示例13: _heartbeat
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _heartbeat(self):
packets = Packet.create('HB', PacketType.PA_HEARTBEAT)
self.router.got_data(packets)
# Set TTL Check Status
check_string = self._agent + 'check/pass/service:'
get(check_string + self.data_port_id).addCallback(
self.done, caller='%s TTL check status: ' % self.data_port_id)
get(check_string + self.command_port_id).addCallback(
self.done, caller='%s TTL check status: ' % self.command_port_id)
get(check_string + self.sniffer_port_id).addCallback(
self.done, caller='%s TTL check status: ' % self.sniffer_port_id)
reactor.callLater(HEARTBEAT_INTERVAL, self._heartbeat)
示例14: _heartbeat
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def _heartbeat(self):
"""
Send a heartbeat packet and set our Consul status to PASS
:return:
"""
packets = Packet.create('HB', PacketType.PA_HEARTBEAT)
self.router.got_data(packets)
# Set TTL Check Status
check_string = self._agent + 'check/pass/service:'
for service in self.config['ports']:
name, service_id = self.get_service_name_id(service)
yield get(check_string + service_id)
示例15: filesListed
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import create [as 别名]
def filesListed(self, results):
for img_name in results:
file_name = img_name.filename
if all([
file_name.endswith('png'),
file_name not in self.retrieved_file_queue,
file_name not in self.pending_file_queue
]):
# Queue up pending files for download
self.pending_file_queue.append(file_name)
# Send a message to the driver indicating that a new image has been listed
# The driver will then associate metadata with the image file name
packets = Packet.create('New Image:' + str(file_name), PacketType.FROM_INSTRUMENT)
self.router.got_data(packets)
reactor.callLater(0, self.fetch_file)