Skip to content
Snippets Groups Projects
Commit 786a0ec2 authored by dawehr's avatar dawehr
Browse files

Merge branch 'controller-network' of git.ece.iastate.edu:danc/MicroCART_17-18...

Merge branch 'controller-network' of git.ece.iastate.edu:danc/MicroCART_17-18 into controller-network
parents 6cca0f70 42088313
No related branches found
No related tags found
1 merge request!8Controller network
...@@ -422,6 +422,13 @@ int connectToZybo() { ...@@ -422,6 +422,13 @@ int connectToZybo() {
printf("Connecting to Quad @ %s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); printf("Connecting to Quad @ %s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
status = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); status = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
int flag = 1;
int result = setsockopt(sock, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
} }
// connection failed // connection failed
......
...@@ -8,7 +8,7 @@ TCP_PORT = 8080 ...@@ -8,7 +8,7 @@ TCP_PORT = 8080
# sock.bind(('', UDP_PORT)) # sock.bind(('', UDP_PORT))
message = bytes(range(32)) message = bytes(range(36))
times_full = [] times_full = []
times_network = [] times_network = []
times = [0.0]*100 times = [0.0]*100
...@@ -19,6 +19,7 @@ recvd_data = [] ...@@ -19,6 +19,7 @@ recvd_data = []
for i in range(100): for i in range(100):
if dropped: if dropped:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
sock.settimeout(2) sock.settimeout(2)
sock.connect((TCP_IP, TCP_PORT)) sock.connect((TCP_IP, TCP_PORT))
dropped = False dropped = False
...@@ -26,9 +27,8 @@ for i in range(100): ...@@ -26,9 +27,8 @@ for i in range(100):
send_msg[0] = i send_msg[0] = i
send_msg = bytes(send_msg) send_msg = bytes(send_msg)
send_time = time.clock() send_time = time.perf_counter()
times[i] = send_time times[i] = send_time
# send_time = time.clock()
sock.send(send_msg) sock.send(send_msg)
try: try:
response = sock.recv(1024) response = sock.recv(1024)
...@@ -36,10 +36,10 @@ for i in range(100): ...@@ -36,10 +36,10 @@ for i in range(100):
except: except:
print("timed out") print("timed out")
dropped = True dropped = True
if len(recvd_data) >= 32: if len(recvd_data) >= 36:
end_time = time.clock() end_time = time.perf_counter()
response = bytes(recvd_data[0:32]) response = bytes(recvd_data[0:36])
recvd_data = recvd_data[32:] recvd_data = recvd_data[36:]
msg_id = int(response[0]) msg_id = int(response[0])
latency = end_time - times[msg_id] latency = end_time - times[msg_id]
# serial_time = int.from_bytes(response[0:4], byteorder='big') / 1000 # serial_time = int.from_bytes(response[0:4], byteorder='big') / 1000
...@@ -48,7 +48,8 @@ for i in range(100): ...@@ -48,7 +48,8 @@ for i in range(100):
times_full.append(1000 * latency) times_full.append(1000 * latency)
times_network.append(1000 * (end_time - send_time) - serial_time) times_network.append(1000 * (end_time - send_time) - serial_time)
print("received " + str(response) + " in " + str(times_full[-1]) + " from " + str(addr)) print("received " + str(response) + " in " + str(times_full[-1]) + " from " + str(addr))
time.sleep(0.1) while time.perf_counter() - send_time < 0.01:
pass
# with open("tcp_dist.csv", 'w', newline='') as f: # with open("tcp_dist.csv", 'w', newline='') as f:
# writer = csv.writer(f) # writer = csv.writer(f)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment