source: ReferenceDesigns/w3_802.11/python/examples/log/live_log_proc.py

Last change on this file was 6323, checked in by murphpo, 5 years ago

Re-adding live_log_proc.py example script, accidentially omitted from 1.8.0 update of Python in svn

File size: 3.4 KB
Line 
1"""
2live_log_proc.py
3
4Template script demonstrating how to retrieve and process log data
5live without writing data to an HDF5 file for offline analysis.
6
7This script configures a single WARP v3 node as a monitor, then
8continually retrieves new data from the node's log. New log entries
9are optionally passed to callback functions defined in the
10LOG_ENTRIES_CALLBACKS dictionary. By default RX_OFDM and RX_DSSS
11entries are passed to simple methods which print the timestamp
12and addr1 fields in receied packets.
13
14Copyright (c) 2019 Mango Communications, Inc.
15"""
16
17import wlan_exp.config as config
18import wlan_exp.util as util
19import wlan_exp.log.util as log_util
20
21import time
22
23NETWORK              = '10.0.0.0'
24NODE_SERIAL_LIST     = ['W3-a-00001']
25
26# Experiment params
27RUN_TIME = 10 #seconds
28POLL_INTERVAL = 0.250 #seconds
29
30def init_experiment():
31    # Initialize the wlan_exp network config and the 802.11 Ref Design nodes
32    network_config = config.WlanExpNetworkConfiguration(network=NETWORK, jumbo_frame_support=False)
33    nodes_config   = config.WlanExpNodesConfiguration(network_config=network_config, serial_numbers=NODE_SERIAL_LIST)
34    nodes = util.init_nodes(nodes_config, network_config)
35   
36    # This script uses a single node
37    n = nodes[0]
38   
39    # Remove the node from any BSS
40    n.configure_bss(None)
41   
42    # Reset the node's state, including the log
43    n.reset_all()
44   
45    # Disbale the ETH A - Wireless bridge
46    n.enable_ethernet_portal(enable=False)
47   
48    # Tune to the required channel
49    n.set_radio_channel(1)
50   
51    # Enable wrapping in the log
52    n.log_configure(log_wrap_enable=True)
53   
54    return n
55
56def run_experiment(n):
57    END_TIME = time.time() + RUN_TIME
58   
59    while time.time() < END_TIME:
60        log_data = n.log_get_all_new(log_tail_pad=0).get_bytes()
61        if(len(log_data) > 0):
62            raw_log_index = log_util.gen_raw_log_index(log_data)
63
64            log_index = log_util.filter_log_index(raw_log_index, 
65                                                  include_only=list(LOG_ENTRIES_CALLBACKS.keys()),
66                                                   merge={'RX_OFDM': ('RX_OFDM', 'RX_OFDM_LTG')})
67
68            filt_entries = log_util.log_data_to_np_arrays(log_data, log_index)
69           
70            # Iterate over any entries in this log data that have callbacks assigned
71            for entry_type in filt_entries.keys():
72                LOG_ENTRIES_CALLBACKS[entry_type](filt_entries[entry_type])
73
74        time.sleep(POLL_INTERVAL)
75
76# Define callback functions to handle various log entry types
77#  There must be one function here for each value in the         
78#  LOG_ENTRIES_CALLBACKS dictionary
79#
80def handle_rx_dsss(entries):
81    for e in entries:
82        print('--Rx DSSS--  MAC Time: {0:11d}, MAC Time Frac: {1:3d}, Addr 1: {2:012x}'.format(
83                e['timestamp'], e['timestamp_frac'], e['addr1']))
84
85def handle_rx_ofdm(entries):
86    for e in entries:
87        print('--Rx OFDM--  MAC Time: {0:11d}, MAC Time Frac: {1:3d}, Addr 1: {2:012x}'.format(
88                e['timestamp'], e['timestamp_frac'], e['addr1']))
89
90#########################
91
92# Define mapping of log entry types and callback functions
93#  Entry types not lists here will be ignored
94LOG_ENTRIES_CALLBACKS = {'RX_DSSS': handle_rx_dsss, 'RX_OFDM': handle_rx_ofdm}
95
96n = init_experiment()
97run_experiment(n)
98
Note: See TracBrowser for help on using the repository browser.