source: ResearchApps/Measurement/examples/TxPower_vs_PER/TxPower_vs_PER.py

Last change on this file was 1566, checked in by murphpo, 14 years ago
File size: 3.6 KB
Line 
1from warpnet_client import *
2from warpnet_common_params import *
3from warpnet_experiment_structs import *
4from twisted.internet import reactor
5from datetime import *
6import time
7
8minTime = 10
9pktLen = 1412
10pktPeriod = 2000
11mod_hdr = 2
12mod_payload = 2
13txGains = [30, 45, 60];
14
15class ScriptMaster:
16    def startup(self):
17   
18        er_log = DataLogger('twoNode_PER_Test_v0.m', flushTime=0)
19        er_log.log("%%WARPnet PER Test Example - %s\r\n" % datetime.now())
20
21        registerWithServer()
22   
23        nodes = dict()
24       
25        #WARP Nodes
26        createNode(nodes, Node(0, NODE_PCAP))
27        createNode(nodes, Node(1, NODE_PCAP))
28
29        connectToServer(nodes)
30
31        controlStruct = ControlStruct()
32        nodes[0].addStruct('controlStruct', controlStruct)
33        nodes[1].addStruct('controlStruct', controlStruct)
34       
35        cmdStructStart = CommandStruct(COMMANDID_STARTTRIAL, 0)
36        nodes[0].addStruct('cmdStructStart', cmdStructStart)
37       
38        cmdStructStop = CommandStruct(COMMANDID_STOPTRIAL, 0)
39        nodes[0].addStruct('cmdStructStop', cmdStructStop)
40
41        cmdStructResetPER = CommandStruct(COMMANDID_RESET_PER, 0)
42        nodes[0].addStruct('cmdStructResetPER', cmdStructResetPER)
43        nodes[1].addStruct('cmdStructResetPER', cmdStructResetPER)
44
45        perStruct0 = ObservePERStruct()
46        perStruct1 = ObservePERStruct()
47        nodes[0].addStruct('perStruct', perStruct0)
48        nodes[1].addStruct('perStruct', perStruct1)
49
50        sendRegistrations(nodes)
51
52        controlStruct.packetGeneratorPeriod = pktPeriod
53        controlStruct.packetGeneratorLength = pktLen
54        controlStruct.channel = 9
55        controlStruct.txPower = 63
56        controlStruct.modOrderHeader = mod_hdr
57        controlStruct.modOrderPayload = mod_payload
58       
59        nodes[0].sendToNode('controlStruct')
60        nodes[1].sendToNode('controlStruct')
61
62        nodes[0].sendToNode('cmdStructResetPER')
63        nodes[1].sendToNode('cmdStructResetPER')
64
65        #Experiment loop
66        for ii, txGain in enumerate(txGains):
67            print("Starting trial %d with TxGain %d at %s" % (ii, txGain, datetime.now()))
68   
69            #Stop any traffic that might be running
70            nodes[0].sendToNode('cmdStructStop')
71   
72            #Reset the PER counters at all nodes
73            nodes[0].sendToNode('cmdStructResetPER')
74            nodes[1].sendToNode('cmdStructResetPER')
75   
76            controlStruct.txPower = txGain
77            nodes[0].sendToNode('controlStruct')
78
79            #Let things settle
80            time.sleep(0.25)
81           
82            #Start the trial
83            nodes[0].sendToNode('cmdStructStart')
84   
85            #Run until minTime elapses
86            time.sleep(minTime)
87   
88            nodes[0].sendToNode('cmdStructStop')
89   
90            #Give the nodes and server time to process any final structs
91            time.sleep(1)
92   
93            #Request 3 PER struts from each node, verifying the response matches this request
94            perStruct0.reqNum = 0
95            perStruct1.reqNum = 0
96            perStruct0.reqType = 0
97            perStruct1.reqType = 0
98           
99            nodes[0].sendToNode('perStruct')
100            nodes[1].sendToNode('perStruct')
101           
102            if (perStruct0.reqNum != 0) or (perStruct1.reqNum != 0) or \
103                (perStruct0.reqType != 0) or (perStruct1.reqType != 0):
104                print("BAD STATE! Out-of-order PER Struct Received")
105       
106            #Record the results
107            er_log.log("n0_txGain(%d) = %d;\t" % (ii+1, txGain))
108            er_log.log("n0_txPkts(%d) = %d;\t" % (ii+1, perStruct0.numPkts_tx))
109   
110            er_log.log("n1_rxPkts_good(%d) = %d;\t" %   (ii+1, perStruct1.numPkts_rx_good))
111            er_log.log("n1_rxPkts_GhBp(%d) = %d;\t" %   (ii+1, perStruct1.numPkts_rx_goodHdrBadPyld))
112            er_log.log("n1_rxPkts_BadHdr(%d) = %d;\r\n" %   (ii+1, perStruct1.numPkts_rx_badHdr))
113   
114       
115        print("############################################")
116        print("############# Experiment Done! #############")
117        print("############################################")
118        reactor.callFromThread(reactor.stop)
119       
120sm = ScriptMaster()
121stdio.StandardIO(CmdReader())
122factory = WARPnetClient(sm.startup);
123reactor.connectTCP('localhost', 10101, factory)
124reactor.run()
Note: See TracBrowser for help on using the repository browser.