forked from ubnt-marty/eng_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafhttp_tom.py
2271 lines (2110 loc) · 103 KB
/
afhttp_tom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# A Selenium WebDriver program to interface with AirFiber radios.
import sys
import time
import argparse
import re
import itertools
import ast
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
class Http(object):
ObjCount = 0 # Init Class Variable
def __init__(self, ipaddress, username, password, quiet):
#print "afhttp07" ######### UPDATE THIS FOR ANY NEW CHANGES TO THIS FILE #########
Http.ObjCount += 1 # Class Variable
self.objid = Http.ObjCount
self.address = ipaddress
self.username = username
self.password = password
self.width = 900
self.height = 800
self.browser = None
self.firmware_version = ''
self.radiotype = ''
self.buildnumber = ''
self.version = ''
self.versionnumber = ''
self.devicename = ''
self.loggedin = False
self.quiet = quiet
self.new_browser()
def __del__(self):
Http.ObjCount -= 1
def new_browser(self):
# Create a new instance of the Firefox driver
self.browser = webdriver.Firefox()
self.browser.set_window_size(self.width, self.height)
self.browser.implicitly_wait(30) # seconds
def login(self):
# Gets: self.firmware_version, self.radiotype, self.buildnumber, self.version, self.versionnumber
if self.quiet == False:
print 'login() with retries.'
# Go to the radio's home page
self.available = False
self.retries = 180
while (self.available == False) and (self.retries > 0):
try:
if self.quiet == False:
print 'try: Wait.until(EC.presence_of_element_located((By.ID, "username")))'
self.browser.get("http://%s" % self.address)
self.usernameElement = WebDriverWait(self.browser, 1).until(EC.presence_of_element_located((By.ID, "username")))
self.available = True
time.sleep(5)
except:
self.retries -= 1
if self.quiet == False:
print 'exception: Wait.until(EC.presence_of_element_located((By.ID, "username"))), Retries left: %s' % self.retries
time.sleep(1)
pass
if self.available == False:
print 'WEB PAGE LOGIN FAILURE.'
sys.exit(1)
self.usernameElement.clear()
time.sleep(.5)
self.usernameElement.send_keys(self.username)
time.sleep(1)
self.passwordElement = self.browser.find_element_by_id("password")
self.passwordElement.clear()
time.sleep(.5)
self.passwordElement.send_keys(self.password)
time.sleep(1)
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.loginElement = self.browser.find_element_by_css_selector("input[type=\"submit\"]")
self.loginElement.click()
WebDriverWait(self.browser, 30).until(EC.title_contains("Main"))
self.loggedin = True
self.click_main_tab() # to gain focus on main page
self.firmware_version = self.get_system_fw_version()
self.radiotype = self.get_system_radio_type()
self.buildnumber = self.get_system_build_number()
self.version = self.get_main_version()
self.versionnumber = self.get_version_number()
if self.quiet == False:
print ' firmwareversion = %s' % self.firmware_version
print ' radiotype = %s' % self.radiotype
print ' build # = %s' % self.buildnumber
print ' version # = %s' % self.version
print ' version number # = %s' % self.versionnumber
print
print 'Done with log in.'
def logout(self):
if self.quiet == False:
print 'logout()'
try:
self.browser.find_element_by_css_selector("input[type=\"button\"]").click()
except:
if self.quiet == False:
print 'Failed to find Logout button. Go to main tab and try again.'
self.goto_main_tab()
self.browser.find_element_by_css_selector("input[type=\"button\"]").click()
WebDriverWait(self.browser, 30).until(EC.title_contains("Login"))
self.loggedin = False
self.browser.quit()
if self.quiet == False:
print 'Done with log out.'
def load_fw(self, image_pathname):
""" Will attempt to run a firmware update. Requires login first. Will leave in logged out state. """
self.fw_image = image_pathname
if self.quiet == False:
print 'load_fw()'
self.tabname = 'system'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
#self.goto_main_tab()
self.click_system_tab()
time.sleep(2)
self.fwfileElement = self.browser.find_element_by_id("fwfile")
self.fwfileElement.send_keys("%s" % self.fw_image)
time.sleep(1)
self.btn_fwuploadElement = WebDriverWait(self.browser, 60).until(EC.presence_of_element_located((By.ID, "btn_fwupload")))
self.btn_fwuploadElement.click()
self.btn_fwupdateElement = WebDriverWait(self.browser, 200).until(EC.presence_of_element_located((By.ID, "btn_fwupdate")))
self.btn_fwupdateElement.click()
time.sleep(120)
WebDriverWait(self.browser, 600).until(EC.title_contains("Login"))
time.sleep(5)
if self.quiet == False:
print 'Done executing load FW image.'
self.login()
def goto_main_tab(self):
if self.quiet == False:
print 'goto_main_tab()'
try:
self.browser.get("http://%s/index.cgi" % self.address)
except:
if self.quiet == False:
print 'goto_main_tab() exception, re-login to webpage at %s' % self.address
time.sleep(2)
self.login()
time.sleep(2)
self.browser.get("http://%s/index.cgi" % self.address)
time.sleep(1)
def goto_wireless_tab(self):
if self.quiet == False:
print 'goto_wireless_tab()'
try:
self.browser.get("http://%s/link.cgi" % self.address)
except:
if self.quiet == False:
print 'goto_wireless_tab() exception, re-login to webpage at %s' % self.address
time.sleep(2)
self.login()
time.sleep(2)
self.browser.get("http://%s/link.cgi" % self.address)
time.sleep(1)
def goto_network_tab(self):
if self.quiet == False:
print 'goto_network_tab()'
try:
self.browser.get("http://%s/network.cgi" % self.address)
except:
if self.quiet == False:
print 'goto_network_tab() exception, re-login to webpage at %s' % self.address
time.sleep(2)
self.login()
time.sleep(2)
self.browser.get("http://%s/network.cgi" % self.address)
time.sleep(1)
def goto_advanced_tab(self):
if self.quiet == False:
print 'goto_advanced_tab()'
try:
self.browser.get("http://%s/advanced.cgi" % self.address)
except:
if self.quiet == False:
print 'goto_advanced_tab() exception, re-login to webpage at %s' % self.address
time.sleep(2)
self.login()
time.sleep(2)
self.browser.get("http://%s/advanced.cgi" % self.address)
time.sleep(1)
def goto_services_tab(self):
if self.quiet == False:
print 'goto_services_tab()'
try:
self.browser.get("http://%s/services.cgi" % self.address)
except:
if self.quiet == False:
print 'goto_services_tab() exception, re-login to webpage at %s' % self.address
time.sleep(2)
self.login()
time.sleep(2)
self.browser.get("http://%s/services.cgi" % self.address)
time.sleep(1)
def goto_system_tab(self):
if self.quiet == False:
print 'goto_system_tab()'
try:
self.browser.get("http://%s/system.cgi" % self.address)
except:
if self.quiet == False:
print 'goto_system_tab() exception, re-login to webpage at %s' % self.address
time.sleep(2)
self.login()
time.sleep(2)
self.browser.get("http://%s/system.cgi" % self.address)
time.sleep(1)
def click_main_tab(self):
if self.quiet == False:
print 'click_main_tab() -> goto_main_tab().'
self.goto_main_tab()
def click_wireless_tab(self):
if self.quiet == False:
print 'click_wireless_tab() -> goto_wireless_tab().'
self.goto_wireless_tab()
def click_network_tab(self):
if self.quiet == False:
print 'click_network_tab() -> goto_network_tab().'
self.goto_network_tab()
def click_advanced_tab(self):
if self.quiet == False:
print 'click_advanced_tab() -> goto_advanced_tab().'
self.goto_advanced_tab()
def click_services_tab(self):
if self.quiet == False:
print 'click_services_tab() -> goto_services_tab().'
self.goto_services_tab()
def click_system_tab(self):
if self.quiet == False:
print 'click_system_tab() -> goto_system_tab().'
self.goto_system_tab()
def get_tab_title(self):
self.title = self.browser.title
if self.quiet == False:
print 'get_tab_title().'
print "Title: ", self.title
return self.title
def get_main_device_name(self):
if self.quiet == False:
print 'get_main_device_name().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.devicename = self.browser.find_element_by_id("hostname").text
if self.quiet == False:
print "Device Name: %s" % self.devicename
return self.devicename
def get_main_operating_mode(self):
if self.quiet == False:
print 'get_main_operating_mode().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
self.opmode = self.browser.find_element_by_id("linkmode").text.encode('ascii','ignore').strip()
while self.opmode =='':
time.sleep(1)
self.opmode = self.browser.find_element_by_id("linkmode").text.encode('ascii','ignore').strip()
if self.quiet == False:
print " Operating Mode: ", self.opmode
return self.opmode
def get_main_rf_link_status(self):
if self.quiet == False:
print 'get_main_rf_link_status().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.rflinkstatus = self.browser.find_element_by_id("linkstate").text
if self.quiet == False:
print "RF Link Status: ", self.rflinkstatus
return self.rflinkstatus
def wait_main_rf_link_status_operational(self):
if self.quiet == False:
print 'wait_main_rf_link_status_operational().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.link_status = ''
while self.link_status.lower() != 'operational':
time.sleep(1)
self.link_status = self.get_main_rf_link_status()
if self.quiet == False:
print 'main_rf_link_status = ', self.link_status
return self.link_status
def wait_main_rf_link_status_operational_retry(self, retries):
self.retries = retries
if self.quiet == False:
print 'wait_main_rf_link_status_operational_retry().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.link_status = ''
while (self.link_status.lower() != 'operational') and (self.retries > 0):
time.sleep(1)
self.link_status = self.get_main_rf_link_status()
self.retries -= 1
if self.quiet == False:
print 'main_rf_link_status = ', self.link_status
return self.link_status
def get_main_link_name(self):
if self.quiet == False:
print 'get_main_link_name().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.linkname = self.browser.find_element_by_id("linkname").text.encode('ascii','ignore').strip()
while self.linkname == '':
time.sleep(1)
self.linkname = self.browser.find_element_by_id("linkname").text.encode('ascii','ignore').strip()
if self.quiet == False:
print "Link Name: ", self.linkname
return self.linkname
def get_main_security(self):
if self.quiet == False:
print 'get_main_security().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.security = self.browser.find_element_by_id("security").text
if self.quiet == False:
print "Security: ", self.security
return self.security
def get_main_version(self):
# Returns: v2.1-dev.21845
if self.quiet == False:
print 'get_main_version().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.version = self.browser.find_element_by_id("fwversion").text
if self.quiet == False:
print "Version: ", self.version
return self.version
def get_version_number(self):
# Returns: 2.1
if self.quiet == False:
print 'get_version_number()'
try:
self.versionstr = self.get_main_version()
self.dashindex = self.versionstr.find('-')
if self.dashindex != -1:
self.versionnumber = self.versionstr[1:self.dashindex]
else:
self.versionnumber = self.versionstr[1:]
if self.quiet == False:
print ' %s' % (self.versionnumber)
except:
print ' get_version_number() Exception'
self.versionnumber = ''
return self.versionnumber
def get_main_uptime(self):
if self.quiet == False:
print 'get_main_uptime().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.uptime = self.browser.find_element_by_id("uptime").text
if self.quiet == False:
print "Uptime: ", self.uptime
return self.uptime
def get_main_link_uptime(self):
if self.quiet == False:
print 'get_main_link_uptime().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.linkuptime = self.browser.find_element_by_id("linkuptime").text
if self.quiet == False:
print "Link Uptime: ", self.linkuptime
return self.linkuptime
def get_main_remote_mac(self):
if self.quiet == False:
print 'get_main_remote_mac().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
try:
self.remotemac = self.browser.find_element_by_id("remotemac").text
except:
self.remotemac = ''
if self.quiet == False:
print "Remote MAC: ", self.remotemac
return self.remotemac
def get_main_remote_ip(self):
if self.quiet == False:
print 'get_main_remote_ip().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
try:
self.remoteip = self.browser.find_element_by_id("remoteip").text
except:
self.remoteip = ''
if self.quiet == False:
print "Remote IP: ", self.remoteip
return self.remoteip
def get_main_date(self):
if self.quiet == False:
print 'get_main_date().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.date = self.browser.find_element_by_id("date").text
if self.quiet == False:
print "Date: ", self.date
return self.date
def get_main_duplex(self):
if self.quiet == False:
print 'get_main_duplex().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.duplex = self.browser.find_element_by_id("af_duplex").text.split()[0]
if self.quiet == False:
print "Duplex: ", self.duplex
return self.duplex
def get_main_tx_frequency(self, display_units=False):
self.displayunits = display_units
if self.quiet == False:
print 'get_main_tx_frequency().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.tx_frequency = self.browser.find_element_by_id("tx_frequency").text
if self.displayunits == False:
self.tx_frequency = ''.join(self.tx_frequency.split()[:-1])
if self.quiet == False:
print "Tx Frequency: ", self.tx_frequency
return self.tx_frequency
def get_main_rx_frequency(self, display_units=False):
self.displayunits = display_units
if self.quiet == False:
print 'get_main_rx_frequency().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.rx_frequency = self.browser.find_element_by_id("rx_frequency").text
if self.displayunits == False:
self.rx_frequency = ''.join(self.rx_frequency.split()[:-1])
if self.quiet == False:
print "Rx Frequency: ", self.rx_frequency
return self.rx_frequency
def get_main_channel_width(self, direction=None, display_units=False):
self.direction = direction
self.displayunits = display_units
if self.quiet == False:
print 'get_main_channel_width(%s).' % self.direction
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
if self.direction == None:
self.channel_width = self.browser.find_element_by_id("chanwidth").text
self.direction = ''
if self.direction.lower() == 'tx':
self.channel_width = self.browser.find_element_by_id("txchanwidth").text
else:
self.channel_width = self.browser.find_element_by_id("rxchanwidth").text
if self.displayunits == False:
self.channel_width = ''.join(self.channel_width.split()[:-1])
if self.quiet == False:
print "Channel Width (%s): %s" % (self.direction, self.channel_width)
return self.channel_width
def get_main_regulatory_domain(self):
if self.quiet == False:
print 'get_main_regulatory_domain().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.regulatory_domain = self.browser.find_element_by_id("regdomain").text
if self.quiet == False:
print "Regulatory Domain: ", self.regulatory_domain
return self.regulatory_domain
def get_main_signal_strength(self, chain, remote=False, wait=False, wait_count=1, display_units=False):
self.chain = chain # 0 or 1
self.remote = remote
self.displayunits = display_units
self.wait = wait
self.wait_count = wait_count # seconds if wait=True
if self.quiet == False:
print 'get_main_signal_strength(chain=%s, remote=%s).' % (self.chain, self.remote)
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
if self.remote == True:
chain_id = 'remote_signal%s_value' % self.chain
else:
chain_id = 'signal%s_value' % self.chain
self.signal_strength = self.browser.find_element_by_id(chain_id).text
if self.signal_strength == None or self.signal_strength == '':
self.signal_strength = '-'
if self.wait == True:
while (self.signal_strength.strip() == '-') and (self.wait_count > 0):
time.sleep(1)
self.signal_strength = self.browser.find_element_by_id(chain_id).text
self.wait_count -= 1
if self.displayunits == False:
self.signal_strength = ''.join(self.signal_strength.split()[:-1])
if self.quiet == False:
print "%s: %s" % (self.chain_id, self.signal_strength)
return self.signal_strength
def get_main_current_modulation_rate(self):
if self.quiet == False:
print 'get_main_current_modulation_rate().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.speed = self.browser.find_element_by_id("speed").text.split()[0]
if self.quiet == False:
print "Speed: ", self.speed
return self.speed
def get_main_remote_modulation_rate(self):
if self.quiet == False:
print 'get_main_remote_modulation_rate().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
try:
self.remote_speed = self.browser.find_element_by_id("remote_speed").text.split()[0]
except: # not available if no link between master and slave
self.remote_speed = ''
if self.quiet == False:
print "Remote Speed: ", self.remote_speed
return self.remote_speed
def get_main_tx_capacity(self, display_units=False):
self.displayunits = display_units
if self.quiet == False:
print 'get_main_tx_capacity().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.tx_capacity = self.browser.find_element_by_id("txcapacity").text
self.tx_capacity = ''.join(self.tx_capacity.split(','))
if self.displayunits == False:
self.tx_capacity = ''.join(self.tx_capacity.split()[:-1])
if self.quiet == False:
print "Tx Capacity: ", self.tx_capacity
return self.tx_capacity
def get_main_rx_capacity(self, display_units=False):
self.displayunits = display_units
if self.quiet == False:
print 'get_main_rx_capacity().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.rx_capacity = self.browser.find_element_by_id("rxcapacity").text
self.rx_capacity = ''.join(self.rx_capacity.split(','))
if self.displayunits == False:
self.rx_capacity = ''.join(self.rx_capacity.split()[:-1])
if self.quiet == False:
print "Rx Capacity: ", self.rx_capacity
return self.rx_capacity
def get_main_tx_power(self, display_units=False):
self.displayunits = display_units
if self.quiet == False:
print 'get_main_tx_power().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.tx_power = self.browser.find_element_by_id("txpowerdisp").text
if self.displayunits == False:
self.tx_power = ''.join(self.tx_power.split()[:-1])
if self.quiet == False:
print "Tx Power: ", self.tx_power
return self.tx_power
def get_main_remote_tx_power(self, display_units=False):
self.displayunits = display_units
if self.quiet == False:
print 'get_main_remote_tx_power().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
try:
self.remote_tx_power = self.browser.find_element_by_id("remote_txpower").text
if self.displayunits == False:
self.remote_tx_power = ''.join(self.remote_tx_power.split()[:-1])
except: # not available if no link between master and slave
self.remote_tx_power = ''
if self.quiet == False:
print "Remote Tx Power: ", self.remote_tx_power
return self.remote_tx_power
def get_main_rx_gain(self): # 24G radios only
if self.quiet == False:
print 'get_main_rx_gain().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
try:
self.rx_gain = self.browser.find_element_by_id("rxgaindisp").text
except:
self.rx_gain = ''
if self.quiet == False:
print "Rx Gain: ", self.rx_gain
return self.rx_gain
def get_main_remote_rx_gain(self): #24G radios only
if self.quiet == False:
print 'get_main_remote_rx_gain().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
try:
self.remote_rx_gain = self.browser.find_element_by_id("remote_rxgain").text
except: # not available if no link between master and slave
self.remote_rx_gain = ''
if self.quiet == False:
print "Remote Rx Gain: ", self.remote_rx_gain
return self.remote_rx_gain
def get_main_distance(self):
if self.quiet == False:
print 'get_main_distance().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.distance = self.browser.find_element_by_id("distance").text
if self.quiet == False:
print "Distance: ", self.distance
return self.distance
def get_main_gps_signal_quality(self):
if self.quiet == False:
print 'get_main_gps_signal_quality().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.gps_signal_quality = self.browser.find_element_by_id("gps_qual").text
if self.quiet == False:
print "Gps Signal Quality: ", self.gps_signal_quality
return self.gps_signal_quality
def get_main_latitude_longitude(self):
if self.quiet == False:
print 'get_main_latitude_longitude().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.latitude_longitude = self.browser.find_element_by_id("gps_coord").text
if self.quiet == False:
print "Latitude/Longitude: ", self.latitude_longitude
return self.latitude_longitude
def get_main_altitude(self):
if self.quiet == False:
print 'get_main_altitude().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.altitude = self.browser.find_element_by_id("gps_alt").text
if self.quiet == False:
print "Altitude: ", self.altitude
return self.altitude
def get_main_synchronization(self):
if self.quiet == False:
print 'get_main_synchronization().'
self.tabname = 'main'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_main_tab()
time.sleep(1)
self.synchronization = self.browser.find_element_by_id("gps_sync").text
if self.quiet == False:
print "Synchronization: ", self.synchronization
return self.synchronization
def click_change_button(self):
if self.quiet == False:
print 'click_change_button()'
self.btn_changeElement = self.browser.find_element_by_css_selector("input[type=\"submit\"]")
time.sleep(1)
self.btn_changeElement.click()
if self.quiet == False:
print 'click_change_button() clicked'
time.sleep(1)
def apply_settings(self):
if self.quiet == False:
print 'apply_settings()'
try:
self.browser.find_element_by_id("apply_button").click()
except:
self.btn_applyElement = WebDriverWait(self.browser, 60).until(EC.presence_of_element_located((By.ID, "apply_button")))
self.btn_applyElement.click()
if self.quiet == False:
print 'apply_settings() clicked'
time.sleep(1)
def set_wireless_link_name(self, link_name):
# No apply
self.link_name = link_name
if self.quiet == False:
print 'set_wireless_link_name(%s)' % self.link_name
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_wireless_tab()
self.browser.find_element_by_id("essid").clear()
self.browser.find_element_by_id("essid").send_keys(self.link_name)
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.click_change_button()
def set_wireless_country_code(self, country_code): # Applies the setting when selected.
self.country_code = str(country_code)
if self.quiet == False:
print 'set_wireless_country_code(%s)' % self.country_code
self.opmode = self.get_main_operating_mode()
if self.quiet == False:
print 'Operating Mode: %s' % self.opmode
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_wireless_tab()
self.country_code_dict = {'32': 'argentina', '36': 'australia', '48': 'bahrain', '52': 'barbados', '84': 'belize', '68': 'bolivia', '76': 'brazil', '96': 'brunei darussalam', '124': 'canada', '152': 'chile', '156': 'china', '170': 'colombia', '188': 'costa rica', '208': 'denmark', '214': 'dominican republic', '218': 'ecuador', '222': 'el salvador', '8191': 'engineering', '246': 'finland', '276': 'germany', '300': 'greece', '308': 'grenada', '316': 'guam', '320': 'guatemala', '340': 'honduras', '344': 'hong kong', '352': 'iceland', '356': 'india', '360': 'indonesia', '368': 'iraq', '372': 'ireland', '388': 'jamaica', '404': 'kenya', '410': 'korea republic', '422': 'lebanon', '438': 'liechtenstein', '446': 'macau', '458': 'malaysia', '484': 'mexico', '504': 'morocco', '524': 'nepal', '554': 'new zealand', '566': 'nigeria', '578': 'norway', '512': 'oman', '586': 'pakistan', '591': 'panama', '598': 'papua new guinea', '604': 'peru', '608': 'philippines', '620': 'portugal', '630': 'puerto rico', '634': 'qatar', '643': 'russia', '682': 'saudi arabia', '702': 'singapore', '710': 'south africa', '724': 'spain', '144': 'sri lanka', '158': 'taiwan', '764': 'thailand', '780': 'trinidad and tobago', '804': 'ukraine', '826': 'united kingdom', '840': 'united states', '858': 'uruguay', '860': 'uzbekistan', '862': 'venezuela'}
if self.country_code.isdigit():
self.countryname = self.country_code_dict[self.country_code]
else:
for self.code, self.name in self.country_code_dict.items():
if self.name == self.country_code:
self.countryname = self.name
if self.quiet == False:
print 'self.countryname = %s' % self.countryname
self.countrycode = self.browser.find_element_by_id("change_ccode").click()
self.countrycode = self.browser.find_element_by_id("country_select") # Pulldown
for self.option in self.countrycode.find_elements_by_tag_name('option'):
if self.quiet == False:
print 'self.option.text = %s' % self.option.text
if self.option.text.lower() == self.countryname:
if self.quiet == False:
print '%s == %s' % (self.option.text.lower(), self.countryname)
self.option.click()
if self.quiet == False:
print 'self.option clicked'
self.browser.find_element_by_id("agreed").click()
if self.quiet == False:
print 'agreed clicked'
self.browser.find_element_by_xpath("//button[@type='button'][1]").click()
if self.quiet == False:
print 'Accept clicked'
self.valid_freqs = self.browser.find_element_by_id("tx_freq_rng").text
self.valid_freq_lower = self.valid_freqs.split()[-4][1:]
self.valid_freq_upper = self.valid_freqs.split()[-2]
self.tx_freq = self.browser.find_element_by_id("tx_chan_freq").get_attribute("value")
self.rx_freq = self.browser.find_element_by_id("rx_chan_freq").get_attribute("value")
if self.quiet == False:
print 'Valid Frequencies: %s' % self.valid_freqs
print 'Valid Lower Frequency: %s' % self.valid_freq_lower
print 'Valid Upper Frequency: %s' % self.valid_freq_upper
print 'TX Frequency: %s' % self.tx_freq
print 'RX Frequency: %s' % self.rx_freq
#if self.browser.find_element_by_id("error"):
if (self.tx_freq < self.valid_freq_lower or self.tx_freq > self.valid_freq_upper) or (self.rx_freq < self.valid_freq_lower or self.rx_freq > self.valid_freq_upper):
print 'WARNING FREQUENCY CHANGED TO ALLOW COUNTRY CODE SETTING!'
self.browser.find_element_by_id("tx_chan_freq").clear()
self.browser.find_element_by_id("rx_chan_freq").clear()
if self.opmode.lower() == 'master':
self.browser.find_element_by_id("tx_chan_freq").send_keys(self.valid_freq_lower)
self.browser.find_element_by_id("rx_chan_freq").send_keys(self.valid_freq_upper)
else:
self.browser.find_element_by_id("tx_chan_freq").send_keys(self.valid_freq_upper)
self.browser.find_element_by_id("rx_chan_freq").send_keys(self.valid_freq_lower)
#print 'WARNING COUNTRY CODE SETTING NOT CHANGED BECAUSE OF INVALID FREQUENCY SETTINGS!'
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.browser.find_element_by_css_selector("input[type=\"submit\"]").click()
if self.quiet == False:
print 'Change clicked'
self.apply_settings()
if self.quiet == False:
self.tx_freq = self.browser.find_element_by_id("tx_chan_freq").get_attribute("value")
self.rx_freq = self.browser.find_element_by_id("rx_chan_freq").get_attribute("value")
print 'TX Frequency: %s' % self.tx_freq
print 'RX Frequency: %s' % self.rx_freq
time.sleep(5)
break
else:
print 'WARNING: set_wireless_country_code(%s) not found in list.' % self.country_code
self.click_change_button() # MIGNT NOT BE NEEDED SINCE THE COMMENT ABOVE SAYS SETTING IS APPLIED WHEN SELECTED.
def set_wireless_wireless_mode(self, mode):
# No apply
self.mode = mode
if self.quiet == False:
print 'set_wireless_wireless_mode(%s)' % self.mode
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
#self.goto_main_tab()
self.click_wireless_tab()
self.wirelessmode = self.browser.find_element_by_id('wmode') # Pulldown
for self.option in self.wirelessmode.find_elements_by_tag_name('option'): # Master="ap", Slave="sta"
if self.quiet == False:
print 'self.option.text = %s' % self.option.text
if self.option.text.lower() == self.mode.lower():
self.option.click()
break
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.click_change_button()
def set_wireless_duplex(self, duplex):
# No apply
self.duplex = duplex # "half" | "full"
if (self.duplex.lower() == 'full') or (self.duplex.lower() == 'fdd') or (self.duplex.lower() == 'full duplex'):
self.dplx = 'Full Duplex'
else:
self.dplx = 'Half Duplex'
if self.quiet == False:
print 'set_wireless_duplex(%s)' % self.duplex
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
#self.goto_main_tab()
self.click_wireless_tab()
self.duplex_element = self.browser.find_element_by_id('af_duplex_select') # Pulldown
for self.option in self.duplex_element.find_elements_by_tag_name('option'): # "Half Duplex" | "Full Duplex"
if self.quiet == False:
print 'self.option.text = %s' % self.option.text
if self.option.text == self.dplx:
self.option.click()
break
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.click_change_button()
def set_wireless_channel_bandwidth(self, channel_bandwidth, direction=None):
# direction == 'rx' | 'tx' or None
# AF cmd not available before 19206
# GUI not available before 19233
if self.radiotype == 'AF02':
self.direction = direction
self.channelbandwidth = str(channel_bandwidth) # "50" | "40" | "20" | "10"
if '50' in self.channelbandwidth.lower():
self.chbw = '50MHz'
elif '40' in self.channelbandwidth.lower():
self.chbw = '40MHz'
elif '30' in self.channelbandwidth.lower():
self.chbw = '30MHz'
elif '20' in self.channelbandwidth.lower():
self.chbw = '20MHz'
else:
self.chbw = '10MHz'
if self.quiet == False:
print 'set_wireless_channel_bandwidth(%s)' % self.channelbandwidth
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
#self.goto_main_tab()
self.click_wireless_tab()
if self.direction == None:
self.chbw_element = self.browser.find_element_by_id('tx_chan_bw_select') # Pulldown
elif self.direction.lower() == 'tx':
self.chbw_element = self.browser.find_element_by_id('tx_chan_bw_select') # Pulldown
else:
self.chbw_element = self.browser.find_element_by_id('rx_chan_bw_select') # Pulldown
for self.option in self.chbw_element.find_elements_by_tag_name('option'): # "50 MHz" | "40 MHz" | "20 MHz" | "10 MHz"
if self.quiet == False:
print 'self.option.text = %s' % self.option.text
if self.option.text == self.chbw:
self.option.click()
break
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.click_change_button()
def set_wireless_output_power(self, output_power):
# No apply
self.output_power = output_power
if self.quiet == False:
print 'set_wireless_output_power(%s)' % self.output_power
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_wireless_tab()
self.browser.find_element_by_id("txpower").clear()
self.browser.find_element_by_id("txpower").send_keys(self.output_power)
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.click_change_button()
def set_wireless_master_tx_duty_cycle(self, dutycycle):
# No apply
self.dutycycle = dutycycle
if self.quiet == False:
print 'set_wireless_wireless_master_tx_duty_cycle(%s)' % self.dutycycle
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_wireless_tab()
self.wirelessdutycycle = self.browser.find_element_by_id('m_duty_cycle') # Pulldown
for self.option in self.wirelessdutycycle.find_elements_by_tag_name('option'): # "25","33","50","67","75"
if self.quiet == False:
print 'self.option.text = %s' % self.option.text
if self.option.text.lower() == self.dutycycle.lower():
self.option.click()
break
time.sleep(1) # added to prevent NoSuchElementException for "input[type=\\"submit\\"]"
self.click_change_button()
def set_wireless_maximum_modulation_rate(self, maximum_modulation_rate):
# No apply
self.maximum_modulation_rate = maximum_modulation_rate # "10" | "10x" | "8" | "8x ..| "0" | "0x"
if self.maximum_modulation_rate.lower() in ['10', '10x']:
self.modrate = '10x (1024QAM MIMO)'
elif self.maximum_modulation_rate.lower() in ['8', '8x']:
self.modrate = '8x (256QAM MIMO)'
elif self.maximum_modulation_rate.lower() in ['6', '6x']:
self.modrate = '6x (64QAM MIMO)'
elif self.maximum_modulation_rate.lower() in ['4', '4x']:
self.modrate = '4x (16QAM MIMO)'
elif self.maximum_modulation_rate.lower() in ['2', '2x']:
self.modrate = '2x (QPSK MIMO)'
elif self.maximum_modulation_rate.lower() in ['1', '1x']:
self.modrate = '1x (QPSK SISO)'
else:
self.modrate = '1/4x (QPSK SISO)'
if self.quiet == False:
print 'set_wireless_maximum_modulation_rate(%s)' % self.maximum_modulation_rate
self.tabname = 'wireless'
if self.browser.title.lower().find(self.tabname.lower()) < 0:
self.click_wireless_tab()
self.max_modrate_element = self.browser.find_element_by_id('rate') # Pulldown