source: ResearchApps/Measurement/warpnet_coprocessors/phy_logger/examples/twoNode_cfoLogging.py

Last change on this file was 1605, checked in by murphpo, 14 years ago
File size: 6.0 KB
Line 
1from warpnet_framework.warpnet_client import *
2from warpnet_framework.warpnet_common_params import *
3from warpnet_experiment_structs import *
4from twisted.internet import reactor
5from datetime import *
6from numpy import log10, linspace
7import time
8import sys
9
10mods = [[2,2,2100,78-1]]
11
12pktLens = [1412]; #range(1412, 91, -240) #[1440:-120:120]-28
13
14time_on = 5*60
15time_off = 0
16numItrs = 1
17fileName_offset = 50
18#cfo = 2**20
19cfo = 2**17
20
21txGain = 55
22minChanMag_D = 20
23
24
25class ScriptMaster:
26    def startup(self):
27   
28        stderr_log = open("exp_err.log", "a")
29        stderr_log.write("\r\n####################################################################\r\n")
30        stderr_log.write("%s started at %s\r\n" % (sys.argv[0], datetime.now()))
31        stderr_log.write("####################################################################\r\n\r\n")
32        stderr_log.flush()
33        sys.stderr = stderr_log
34
35        er_log = MyDataLogger('results/twoNode_realCFO_v%d_logging.txt' % (fileName_offset))
36
37        er_log.log("%s" % (datetime.now()) )
38        er_log.log("CFO: %d, Time on: %d, time off: %d, numIttrs: %d, fn_offset: %d\r\n" % (cfo, time_on, time_off, numItrs, fileName_offset))
39        er_log.log("Continuous test of actual CFO on emulator kits\r\n")
40
41        registerWithServer()
42   
43        nodes = dict()
44       
45        #WARP Nodes
46        createNode(nodes, Node(0, NODE_PCAP))
47        createNode(nodes, Node(2, NODE_PCAP))
48
49        #BER processor "node"
50        createNode(nodes, Node(98, NODE_PCAP)) #PHY logger
51
52        connectToServer(nodes)
53
54        controlStruct = ControlStruct()
55        nodes[0].addStruct('controlStruct', controlStruct)
56        nodes[2].addStruct('controlStruct', controlStruct)
57       
58        phyCtrl0 = PHYctrlStruct()
59        phyCtrl1 = PHYctrlStruct()
60        nodes[0].addStruct('phyCtrlStruct', phyCtrl0)
61        nodes[2].addStruct('phyCtrlStruct', phyCtrl1)
62
63        cmdStructStart = CommandStruct(COMMANDID_STARTTRIAL, 0)
64        nodes[0].addStruct('cmdStructStart', cmdStructStart)
65       
66        cmdStructStop = CommandStruct(COMMANDID_STOPTRIAL, 0)
67        nodes[0].addStruct('cmdStructStop', cmdStructStop)
68
69        cmdStructResetPER = CommandStruct(COMMANDID_RESET_PER, 0)
70        nodes[0].addStruct('cmdStructResetPER', cmdStructResetPER)
71        nodes[2].addStruct('cmdStructResetPER', cmdStructResetPER)
72
73        perStruct0 = ObservePERStruct()
74        perStruct1 = ObservePERStruct()
75        nodes[0].addStruct('perStruct', perStruct0)
76        nodes[2].addStruct('perStruct', perStruct1)
77
78        logParams = LogParams()
79        nodes[98].addStruct('logParams', logParams)
80
81        sendRegistrations(nodes)
82
83        controlStruct.packetGeneratorPeriod = mods[0][2]
84        controlStruct.packetGeneratorLength = pktLens[0]
85        controlStruct.channel = 9
86        controlStruct.txPower = txGain
87        controlStruct.modOrderHeader = mods[0][0]
88        controlStruct.modOrderPayload = mods[0][1]
89       
90        #PHYCtrol params:
91        #param0: txStartOut delay
92        #param1: artificial txCFO
93        #param2: minPilotChanMag
94        #param3:
95        # [0-0x01]: PHYCTRL_BER_EN: enable BER reporting
96        # [1-0x02]: PHYCTRL_CFO_EN: enable CFO reporting
97        # [2-0x04]: PHYCTRL_PHYDUMP_EN: enable Rx PHY dumping
98        # [3-0x08]: PHYTRCL_EXTPKTDET_EN: use only ext pkt det
99        # [4-0x10]: PHYCTRL_COOP_EN: 0=nonCoop, 1=coopMode
100        # [5-0x20]: PHYCTRL_CFO_CORR_EN: 0=bypass CFO correction, 1=enable CFO correction
101        # [6-0x40]: PHYCTRL_SWAP_ANT: 0=AntA, 1=AntA_Swapped
102        #param4:
103        # [ 7:0]: src re-Tx delay
104        # [ 7:0]: relay AF Tx delay (only used when in COOP_TESTING)
105        # [15:8]: relay DF Tx delay (only used when in COOP_TESTING)
106        #param5: (0 ignores)
107        # [17: 0]: AGC IIR coef FB
108        #param6: (0 ignores)
109        # [31:16]: H_BA minEstMag (UFix16_15)
110        # [15: 0]: H_AA minEstMag (UFix16_15)
111        #param7: (0 ignores)
112        # [27:16]: AF blank stop
113        # [11: 0]: AF blank start
114        #param8: (0 ignores)
115        # [17: 0]: AGC IIR coef Gain
116        #param9: (Tx pkt types)
117        # [31: 0]: OR'd combination of PHYCTRL_TX_*
118
119       
120        phyCtrl0.param0 = 32+12
121        phyCtrl0.param1 = cfo #(2**19 ~ 1.2e-4)
122        phyCtrl0.param2 = 0xFFF
123#       phyCtrl0.param3 = (PHYCTRL_COOP_EN | PHYCTRL_BER_EN)
124        phyCtrl0.param3 = (0) #PHYCTRL_COOP_EN)
125#       phyCtrl0.param4 = (251-2) #v21 timing; #######reTxDly/FFToffset: 251/12, 249/10
126        phyCtrl0.param4 = 255 #v22 timing
127        phyCtrl0.param5 = 0
128        phyCtrl0.param6 = 0
129        phyCtrl0.param7 = 0
130        phyCtrl0.param8 = 0
131#       phyCtrl0.param9 = (PHYCTRL_TX_NC | PHYCTRL_TX_DF | PHYCTRL_TX_AF | PHYCTRL_TX_AFGH | PHYCTRL_TX_DFGH | PHYCTRL_TX_NCMHOP)
132        phyCtrl0.param9 = (PHYCTRL_TX_NC)
133       
134        phyCtrl1.param0 = 0
135        phyCtrl1.param1 = 0
136        phyCtrl1.param2 = minChanMag_D
137#       phyCtrl1.param3 = (PHYCTRL_CFO_CORR_EN | PHYCTRL_PHYDUMP_EN)
138        phyCtrl1.param3 = (PHYCTRL_PHYDUMP_EN)
139        phyCtrl1.param4 = 0
140        phyCtrl1.param5 = 0x20000
141        phyCtrl1.param6 = 1000 | (1000<<16)
142        phyCtrl1.param7 = 0
143        phyCtrl1.param8 = 0x20000
144        phyCtrl1.param9 = 0
145
146        nodes[0].sendToNode('phyCtrlStruct')
147        nodes[2].sendToNode('phyCtrlStruct')
148
149        nodes[0].sendToNode('controlStruct')
150        nodes[2].sendToNode('controlStruct')
151
152        nodes[0].sendToNode('cmdStructResetPER')
153        nodes[2].sendToNode('cmdStructResetPER')
154
155        trialInd = -1 #Increment before first trial, which should be trialNum=0
156       
157        pktLen = pktLens[0];
158       
159        #Experiment Loops
160        for ittr in range(1,numItrs+1):
161            print("Starting iteration %d of %d at %s" % (ittr, numItrs, datetime.now().strftime("%H:%M:%S")))
162           
163            trialInd += 1
164
165            #Stop any traffic that might be running
166            nodes[0].sendToNode('cmdStructStop')
167
168            logParams.fileSuffix = fileName_offset+trialInd
169            logParams.param0 = ittr
170            logParams.param1 = 0
171            logParams.param2 = 0
172            logParams.param3 = 0
173            nodes[98].sendToNode('logParams')
174
175            #Reset the PER counters at all nodes
176            nodes[0].sendToNode('cmdStructResetPER')
177            nodes[2].sendToNode('cmdStructResetPER')
178
179            #Start the trial
180            nodes[0].sendToNode('cmdStructStart')
181
182            #Run until minTime elapses
183            time.sleep(time_on)
184
185            nodes[0].sendToNode('cmdStructStop')
186
187            time.sleep(time_off)
188
189            if not reactor.running:
190                return
191
192        print("############################################")
193        print("############# Experiment Done! #############")
194        print("############################################")
195        reactor.callFromThread(reactor.stop)
196       
197sm = ScriptMaster()
198stdio.StandardIO(CmdReader()) #if interactive shell is needed
199factory = WARPnetClient(sm.startup);
200reactor.connectTCP('localhost', 10101, factory)
201reactor.run()
Note: See TracBrowser for help on using the repository browser.