-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradar_load_codebook_rx.py
150 lines (125 loc) · 4.32 KB
/
radar_load_codebook_rx.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
import socket
import json
import datetime
import traceback
import sys
import math
from scipy import io
if len(sys.argv) < 4:
sector_idx = 0
else:
sector_idx = int(sys.argv[3])
if len(sys.argv) < 3:
sector_type = 1
else:
sector_type = int(sys.argv[2])
if len(sys.argv) < 2:
rf_modules_vec = 1+128
else:
rf_modules_vec = int(sys.argv[1])
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Connect the socket to the port where the server is listening
#server_address = ('localhost',8000)
server_address = ('192.168.1.1', 8000)
print 'connecting to %s port %s' % server_address
sock.connect(server_address)
buf_len = 10240
base_phase_mat = io.loadmat('../15beam.mat')
codebook_size = 15
for beam_idx in range(0, codebook_size):
# Send data
data = {}
# data['cmd'] = 'tx_sin'
# data['args'] = {}
data['cmd'] = 'set_pattern'
data['args'] = {'sector_idx': beam_idx,
'sector_type': 0,
'rf_modules_vec': rf_modules_vec,
'mag': (''.join(base_phase_mat['beam_weight'][0][beam_idx][0][0].tolist()).encode('utf-8','ignore')),
'phase': (''.join(base_phase_mat['beam_weight'][0][beam_idx][0][1].tolist()).encode('utf-8','ignore')),
'amp': "66666666",
}
message = json.dumps(data).encode('utf-8')
print data
a = datetime.datetime.now()
while True:
# for i in range(0, 64):
sock.sendall(message)
# Look for the response
d = b''
while True:
d_tmp = sock.recv(buf_len)
d += d_tmp
if not d_tmp or d_tmp[-1] == '}' or d_tmp[-1] == ')' or d_tmp[-1] == ']':
break
if d:
response = json.loads(d.decode('utf-8'))
print(response)
# ret = str(bin(response['rf_current_status'.encode()]))[-18:]
# gain = ret[-12:-8]
# sector = ret[-7:]
# if ret[-18] == '1' and ret[-17] == '0':
# print 'tx mode, gain index {}, sector {}'.format(int(gain, 2), int(sector, 2))
# if ret[-18] == 'b' and ret[-17] == '1':
# print 'rx mode, gain index {}, sector {}'.format(int(gain, 2), int(sector, 2))
break
# time.sleep(1)
# time.sleep(20)
b = datetime.datetime.now()
delta = b - a
print delta
# Set RX sector
# sock.close()
# server_address = ('192.168.137.13', 8000)
# print 'connecting to %s port %s' % server_address
# sock.connect(server_address)
# buf_len = 10240
# data = {}
# data['cmd'] = 'tx_sin'
# data['args'] = {}
# data['cmd'] = 'set_pattern'
# data['args'] = {'sector_idx': 15,
# 'sector_type': 0,
# 'rf_modules_vec': rf_modules_vec,
# 'mag': "00000000000000000000000000600000",
# 'phase': "00000000000000000000000000000000",
# 'amp': "00000060",
# }
message = json.dumps(data).encode('utf-8')
print data
a = datetime.datetime.now()
while True:
# for i in range(0, 64):
sock.sendall(message)
# Look for the response
d = b''
while True:
d_tmp = sock.recv(buf_len)
d += d_tmp
if not d_tmp or d_tmp[-1] == '}' or d_tmp[-1] == ')' or d_tmp[-1] == ']':
break
if d:
response = json.loads(d.decode('utf-8'))
print(response)
# ret = str(bin(response['rf_current_status'.encode()]))[-18:]
# gain = ret[-12:-8]
# sector = ret[-7:]
# if ret[-18] == '1' and ret[-17] == '0':
# print 'tx mode, gain index {}, sector {}'.format(int(gain, 2), int(sector, 2))
# if ret[-18] == 'b' and ret[-17] == '1':
# print 'rx mode, gain index {}, sector {}'.format(int(gain, 2), int(sector, 2))
break
# time.sleep(1)
# time.sleep(20)
b = datetime.datetime.now()
delta = b - a
print delta
except Exception as e:
traceback.print_exc()
print e
print 'exiting'
finally:
print 'connection close'
sock.close()