本文整理汇总了Python中link.Link.add_rx方法的典型用法代码示例。如果您正苦于以下问题:Python Link.add_rx方法的具体用法?Python Link.add_rx怎么用?Python Link.add_rx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类link.Link
的用法示例。
在下文中一共展示了Link.add_rx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _simulate_link
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import add_rx [as 别名]
def _simulate_link(self, link, payload, error_tables):
for ii in range(len(payload)):
link.tx['data'][10 + 12 + ii] = payload[ii]
new_link = Link(link.tx)
corrupted_payload = self._corrupt_payload(payload, error_tables)
for rx in link.valid_rx:
# print "origi:", "".join(map((lambda d: bin(d)[2:].zfill(8)), rx['xor'])), rx['bit_errors']
for ii in range(len(corrupted_payload)):
rx['data'][10 + 12 + ii] = corrupted_payload[ii]
new_link.add_rx(rx)
for rx in link.timeout_rx:
new_link.add_rx(rx)
for rx in link.invalid_rx:
new_link.add_rx(rx)
return new_link
示例2: MessageVisualizer
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import add_rx [as 别名]
class MessageVisualizer(Process, object):
def __init__(self, nodes=5, messages=100):
super(MessageVisualizer, self).__init__()
self.nodes = nodes if nodes > 0 else 1
self.link = None
self.fig = plt.figure(num=None, figsize=(16, 12), dpi=80, facecolor='w', edgecolor='k')
self.fig.subplots_adjust(top=0.8)
self.temperature = self.fig.add_axes([0.05, 0.7, 0.9, 0.2], label='temperature')
self.temperature.axes.get_xaxis().set_visible(False)
self.temperature.set_ylim(20, 100)
self.temperature.set_ylabel('Temperature')
self.errors = self.fig.add_axes([0.05, 0.5, 0.9, 0.2], label='errors')
self.errors.axes.get_xaxis().set_visible(False)
self.errors.set_ylim(0, 100)
self.errors.set_ylabel('rx bit errors')
self.lqi = self.fig.add_axes([0.05, 0.3, 0.9, 0.2], label='lqi')
self.lqi.axes.get_xaxis().set_visible(False)
self.lqi.set_ylim(40, 120)
self.lqi.set_ylabel('LQI')
self.rssi = self.fig.add_axes([0.05, 0.1, 0.9, 0.2], label='rssi')
self.rssi.set_ylim(-100, -60)
self.rssi.set_ylabel('RSSI in dB')
self.rssi.set_xlabel('messages')
# colors
self.colors = ['r', 'b', 'g', 'c', 'm', 'b']
self.lw = 1.5
self.messages = messages if messages >= 10 else 10
# reserve the values
self.x_values = np.arange(0.0, self.messages, 1.0)
self.temperature_values = []
self.rssi_values = []
self.error_values = []
self.lqi_values = []
for node in range(self.nodes):
self.temperature_values.append(np.zeros(self.messages))
self.rssi_values.append(np.zeros(self.messages))
self.lqi_values.append(np.zeros(self.messages))
self.error_values.append(np.zeros(self.messages))
self.errors_plot = []
self.temperature_plot = []
self.rssi_plot = []
self.lqi_plot = []
for node in range(self.nodes):
self.errors_plot.append(self.errors.plot(self.x_values, self.error_values[node], color=self.colors[node], lw=self.lw)[0])
self.rssi_plot.append(self.rssi.plot(self.x_values, self.rssi_values[node], color=self.colors[node], lw=self.lw)[0])
self.lqi_plot.append(self.lqi.plot(self.x_values, self.lqi_values[node], color=self.colors[node], lw=self.lw)[0])
self.temperature_plot.append(self.temperature.plot(self.x_values, self.temperature_values[node], color=self.colors[node], lw=self.lw)[0])
plt.ion()
plt.show()
# multiprocessing support
self._tx_message = Array('c', 2000)
self._rx_message = Array('c', 2000)
self._add_rx = Value('b', False)
self._add_tx = Value('b', False)
self.start()
def add_tx_message(self, message):
while(self._add_tx.value):
time.sleep(0)
self._tx_message.value = message
self._add_tx.value = True
def add_rx_message(self, message):
while (self._add_rx.value):
time.sleep(0)
self._rx_message.value = message
self._add_rx.value = True
def add_link(self, link):
for node in range(self.nodes):
if node == link.tx['id']:
continue
# left shift all values
self.temperature_values[node] = np.roll(self.temperature_values[node], 1)
self.error_values[node] = np.roll(self.error_values[node], 1)
self.rssi_values[node] = np.roll(self.rssi_values[node], 1)
self.lqi_values[node] = np.roll(self.lqi_values[node], 1)
# for every received message in the link
for rx in link.rx:
rx_id = rx['id']
#.........这里部分代码省略.........
示例3: read_all
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import add_rx [as 别名]
def read_all(self):
print "Reading entire LinkFile, please wait..."
messages = []
print "Parsing messages..."
start1 = time.time()
with open(self.filename, 'r') as linkfile:
for i, line in enumerate(linkfile):
try:
message = StringMessage(line)
messages.append(message)
except:
print i + 1,
if (i + 1) % 1000 == 0:
print i + 1
elif (i + 1) % 10 == 0:
sys.stdout.write('.')
print "\nDone in {}s".format(time.time() - start1)
links = []
link = None
print "Linking messages..."
start = time.time()
for i, msg in enumerate(messages):
try:
if msg.is_transmission:
if self._coder == None:
self._coder = self._create_coder_from_message(msg)
link = Link(msg, self._coder)
links.append(link)
elif msg.is_reception:
if link != None:
link.add_rx(msg)
except:
print i+1,
if (i + 1) % 100 == 0:
print i + 1
else:
sys.stdout.write('.')
print "\nDone in {}s".format(time.time() - start)
self.id_a = links[0].tx['id']
print "Separating links by ids..."
start = time.time()
for link in links:
if link.tx['id'] == self.id_a:
for rx in link.valid_rx:
self.id_b = rx['id']
break
self._links_ab = []
self._links_ba = []
for link in links:
if link.tx['id'] == self.id_a:
# transmitting from 0 to 1
self._links_ab.append(link)
else:
self._links_ba.append(link)
print "Done in {}s".format(time.time() - start)
print "Done reading LinkFile in {}s".format(time.time() - start1)
示例4: open
# 需要导入模块: from link import Link [as 别名]
# 或者: from link.Link import add_rx [as 别名]
for arg in sys.argv[1:]:
with open(arg, 'r') as linkfile:
for line in linkfile:
try:
if 'errors=0' not in line:
message = StringMessage(line)
if message.is_transmission:
if new_link:
new_link = False
tx_id = link.tx['id']
for rx in link.get_messages_with_errors():
rx_id = rx['id']
results = []
results.append("xor={}".format(" ".join(["0x%x" % b for b in rx['xor']])))
results.append("rssi={}".format(rx['rssi']))
results.append("lqi={}".format(rx['lqi']))
# print tx_id, rx_id, files[tx_id][rx_id].name
files[tx_id][rx_id].write("\t".join(results) + "\n")
link = Link(message)
elif message.is_reception:
link.add_rx(message)
new_link = True
except:
print line