""" live_log_proc.py Template script demonstrating how to retrieve and process log data live without writing data to an HDF5 file for offline analysis. This script configures a single WARP v3 node as a monitor, then continually retrieves new data from the node's log. New log entries are optionally passed to callback functions defined in the LOG_ENTRIES_CALLBACKS dictionary. By default RX_OFDM and RX_DSSS entries are passed to simple methods which print the timestamp and addr1 fields in receied packets. Copyright (c) 2019 Mango Communications, Inc. """ import wlan_exp.config as config import wlan_exp.util as util import wlan_exp.log.util as log_util import time NETWORK = '10.0.0.0' NODE_SERIAL_LIST = ['W3-a-00001'] # Experiment params RUN_TIME = 10 #seconds POLL_INTERVAL = 0.250 #seconds def init_experiment(): # Initialize the wlan_exp network config and the 802.11 Ref Design nodes network_config = config.WlanExpNetworkConfiguration(network=NETWORK, jumbo_frame_support=False) nodes_config = config.WlanExpNodesConfiguration(network_config=network_config, serial_numbers=NODE_SERIAL_LIST) nodes = util.init_nodes(nodes_config, network_config) # This script uses a single node n = nodes[0] # Remove the node from any BSS n.configure_bss(None) # Reset the node's state, including the log n.reset_all() # Disbale the ETH A - Wireless bridge n.enable_ethernet_portal(enable=False) # Tune to the required channel n.set_radio_channel(1) # Enable wrapping in the log n.log_configure(log_wrap_enable=True) return n def run_experiment(n): END_TIME = time.time() + RUN_TIME while time.time() < END_TIME: log_data = n.log_get_all_new(log_tail_pad=0).get_bytes() if(len(log_data) > 0): raw_log_index = log_util.gen_raw_log_index(log_data) log_index = log_util.filter_log_index(raw_log_index, include_only=list(LOG_ENTRIES_CALLBACKS.keys()), merge={'RX_OFDM': ('RX_OFDM', 'RX_OFDM_LTG')}) filt_entries = log_util.log_data_to_np_arrays(log_data, log_index) # Iterate over any entries in this log data that have callbacks assigned for entry_type in filt_entries.keys(): LOG_ENTRIES_CALLBACKS[entry_type](filt_entries[entry_type]) time.sleep(POLL_INTERVAL) # Define callback functions to handle various log entry types # There must be one function here for each value in the # LOG_ENTRIES_CALLBACKS dictionary # def handle_rx_dsss(entries): for e in entries: print('--Rx DSSS-- MAC Time: {0:11d}, MAC Time Frac: {1:3d}, Addr 1: {2:012x}'.format( e['timestamp'], e['timestamp_frac'], e['addr1'])) def handle_rx_ofdm(entries): for e in entries: print('--Rx OFDM-- MAC Time: {0:11d}, MAC Time Frac: {1:3d}, Addr 1: {2:012x}'.format( e['timestamp'], e['timestamp_frac'], e['addr1'])) ######################### # Define mapping of log entry types and callback functions # Entry types not lists here will be ignored LOG_ENTRIES_CALLBACKS = {'RX_DSSS': handle_rx_dsss, 'RX_OFDM': handle_rx_ofdm} n = init_experiment() run_experiment(n)