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

Last change on this file was 1576, checked in by murphpo, 14 years ago
File size: 3.0 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        #Node entry for the BER processor app
30        createNode(nodes, Node(99, NODE_PCAP))
31
32        connectToServer(nodes)
33
34        controlStruct = ControlStruct()
35        nodes[0].addStruct('controlStruct', controlStruct)
36        nodes[1].addStruct('controlStruct', controlStruct)
37       
38        cmdStructBERen = CommandStruct(COMMANDID_ENABLE_BER_TESTING, 0)
39        nodes[0].addStruct('cmdStructBERen', cmdStructBERen)
40        nodes[1].addStruct('cmdStructBERen', cmdStructBERen)
41
42        cmdStructStart = CommandStruct(COMMANDID_STARTTRIAL, 0)
43        nodes[0].addStruct('cmdStructStart', cmdStructStart)
44       
45        cmdStructStop = CommandStruct(COMMANDID_STOPTRIAL, 0)
46        nodes[0].addStruct('cmdStructStop', cmdStructStop)
47
48        berStruct = ObserveBERStruct()
49        nodes[99].addStruct('berStruct', berStruct, handleUnrequested=True)
50
51        sendRegistrations(nodes)
52
53        controlStruct.packetGeneratorPeriod = pktPeriod
54        controlStruct.packetGeneratorLength = pktLen
55        controlStruct.channel = 9
56        controlStruct.txPower = 63
57        controlStruct.modOrderHeader = mod_hdr
58        controlStruct.modOrderPayload = mod_payload
59       
60        nodes[0].sendToNode('controlStruct')
61        nodes[1].sendToNode('controlStruct')
62
63        nodes[0].sendToNode('cmdStructBERen')
64        nodes[1].sendToNode('cmdStructBERen')
65
66        #Experiment loop
67        for ii, txGain in enumerate(txGains):
68            print("Starting trial %d with TxGain %d at %s" % (ii, txGain, datetime.now()))
69   
70            #Stop any traffic that might be running
71            nodes[0].sendToNode('cmdStructStop')
72   
73            #Update the Tx gain at the Tx node
74            controlStruct.txPower = txGain
75            nodes[0].sendToNode('controlStruct')
76
77            #Clear the internal BER counters
78            berStruct.clearBitCounts()
79
80            #Let things settle
81            time.sleep(0.25)
82           
83            #Start the trial
84            nodes[0].sendToNode('cmdStructStart')
85   
86            #Run until minTime elapses
87            time.sleep(minTime)
88   
89            nodes[0].sendToNode('cmdStructStop')
90   
91            #Give the nodes and server time to process any final structs
92            time.sleep(1)
93   
94            #Record the results
95            er_log.log("n0_txGain(%d) = %d;\t" % (ii+1, txGain))
96            er_log.log("n1_bitsRx(%d) = %d;\t" % (ii+1, berStruct.totalBitsReceived))
97            er_log.log("n1_bitErrs(%d) = %d;\r\n" % (ii+1, berStruct.totalBitErrors))
98       
99        print("############################################")
100        print("############# Experiment Done! #############")
101        print("############################################")
102        reactor.callFromThread(reactor.stop)
103       
104sm = ScriptMaster()
105stdio.StandardIO(CmdReader())
106factory = WARPnetClient(sm.startup);
107reactor.connectTCP('localhost', 10101, factory)
108reactor.run()
Note: See TracBrowser for help on using the repository browser.