##// END OF EJS Templates
Testing frame transfer without colon.
imanay -
r91:92
parent child
Show More
@@ -1,75 +1,92
1 import socket No newline at end of file
1 import socket
2 import string No newline at end of file
2 import string
3 #import time No newline at end of file
3 #import time
4 No newline at end of file
4
5 def int2bin(n): No newline at end of file
5 def int2bin(n):
6 n_hex = "%x" %n No newline at end of file
6 n_hex = "%x" %n
7 ln = len(n_hex) No newline at end of file
7 ln = len(n_hex)
8 if ln == 1: No newline at end of file
8 if ln == 1:
9 n_hex = "00000" + n_hex No newline at end of file
9 n_hex = "00000" + n_hex
10 elif ln == 2: No newline at end of file
10 elif ln == 2:
11 n_hex = "0000" + n_hex No newline at end of file
11 n_hex = "0000" + n_hex
12 elif ln == 3: No newline at end of file
12 elif ln == 3:
13 n_hex = "000" + n_hex No newline at end of file
13 n_hex = "000" + n_hex
14 elif ln == 4: No newline at end of file
14 elif ln == 4:
15 n_hex = "00" + n_hex No newline at end of file
15 n_hex = "00" + n_hex
16 elif ln == 5: No newline at end of file
16 elif ln == 5:
17 n_hex = "0" + n_hex No newline at end of file
17 n_hex = "0" + n_hex
18 No newline at end of file
18
19 byte1 = n_hex[0:2] No newline at end of file
19 byte1 = n_hex[0:2]
20 byte2 = n_hex[2:4] No newline at end of file
20 byte2 = n_hex[2:4]
21 byte3 = n_hex[4:6] No newline at end of file
21 byte3 = n_hex[4:6]
22 str_len = "" No newline at end of file
22 str_len = ""
23 str_len += "%c" % string.atoi(byte1,16) No newline at end of file
23 str_len += "%c" % string.atoi(byte1,16)
24 str_len += "%c" % string.atoi(byte2,16) No newline at end of file
24 str_len += "%c" % string.atoi(byte2,16)
25 str_len += "%c" % string.atoi(byte3,16) No newline at end of file
25 str_len += "%c" % string.atoi(byte3,16)
26 No newline at end of file
26
27 return str_len No newline at end of file
27 return str_len
28 No newline at end of file
28
29 def int2str(n):
No newline at end of file
30 str_n = str(n)
No newline at end of file
31 l_n = len(str_n)
No newline at end of file
32 if l_n == 1:
No newline at end of file
33 str_n = "00000" + str_n
No newline at end of file
34 elif l_n == 2:
No newline at end of file
35 str_n = "0000" + str_n
No newline at end of file
36 elif l_n == 3:
No newline at end of file
37 str_n = "000" + str_n
No newline at end of file
38 elif l_n == 4:
No newline at end of file
39 str_n = "00" + str_n
No newline at end of file
40 elif l_n == 5:
No newline at end of file
41 str_n = "0" + str_n
No newline at end of file
42 return str_n
No newline at end of file
43
No newline at end of file
44 No newline at end of file
29 #ini = time.time() No newline at end of file
45 #ini = time.time()
30 #sum = 0 No newline at end of file
46 #sum = 0
31 No newline at end of file
47
32 #for i in range(11,15): No newline at end of file
48 #for i in range(11,15):
33 i=117 No newline at end of file
49 i=117
34 #ini1 = time.time() No newline at end of file
50 #ini1 = time.time()
35 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) No newline at end of file
51 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
36 host = "192.168.1." + str(i) No newline at end of file
52 host = "192.168.1." + str(i)
37 s.connect((host, 5500)) No newline at end of file
53 s.connect((host, 5500))
38
54
No newline at end of file
55 fd = open("experimento2.abs","r") No newline at end of file
39 fd = open("experimento1.abs","r") No newline at end of file
40 FileList = fd.readlines() No newline at end of file
56 FileList = fd.readlines()
41 data = "".join(FileList) No newline at end of file
57 data = "".join(FileList)
42 No newline at end of file
58
43 dfl = 0
59 dfl = 0
No newline at end of file
60 #lng = int2bin(dfl)
44 lng = int2bin(dfl) No newline at end of file
No newline at end of file
61 lng = int2str(dfl) No newline at end of file
45 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" # No newline at end of file
62 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
46 print len(msg) No newline at end of file
63 print len(msg)
47 print msg No newline at end of file
64 print msg
48 No newline at end of file
65
49 lmsg = len(msg)
66 lmsg = len(msg)
No newline at end of file
67 #lng = int2bin(lmsg)
50 lng = int2bin(lmsg) No newline at end of file
No newline at end of file
68 lng = int2str(lmsg) No newline at end of file
51 No newline at end of file
69
52 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" # No newline at end of file
70 msg = "jro" + "abs" + "src" + "cm1" + lng + "cmd" + data + "crc" #
53 print len(msg)
71 print len(msg)
No newline at end of file
72 #print msg No newline at end of file
54 print msg No newline at end of file
55
73
No newline at end of file
56 total_len = len(msg) + 3 No newline at end of file
57
74
No newline at end of file
75 s.send(msg) No newline at end of file
58 s.send(mensaje) No newline at end of file
59 #recibido = s.recv(512) No newline at end of file
76 #recibido = s.recv(512)
60
77
No newline at end of file
78 #print recibido No newline at end of file
61 print recibido No newline at end of file
62 No newline at end of file
79
63 s.close() No newline at end of file
80 s.close()
64 No newline at end of file
81
65 No newline at end of file
82
66 # delay = time.time() - ini1 No newline at end of file
83 # delay = time.time() - ini1
67 # sum += delay No newline at end of file
84 # sum += delay
68 # print delay No newline at end of file
85 # print delay
69 # time.sleep(0.1) No newline at end of file
86 # time.sleep(0.1)
70 No newline at end of file
87
71 #print sum No newline at end of file
88 #print sum
72 No newline at end of file
89
73 No newline at end of file
90
74 No newline at end of file
91
75 No newline at end of file
92
@@ -1,40 +1,40
1 import socket No newline at end of file
1 import socket
2 import time No newline at end of file
2 import time
3 No newline at end of file
3
4 host = "192.168.1.117" No newline at end of file
4 host = "192.168.1.117"
5 s = socket.socket() No newline at end of file
5 s = socket.socket()
6 s.bind((host, 5500)) No newline at end of file
6 s.bind((host, 5500))
7 No newline at end of file
7
8 while True: No newline at end of file
8 while True:
9 print "waiting client..." No newline at end of file
9 print "waiting client..."
10 s.listen(1) No newline at end of file
10 s.listen(1)
11 No newline at end of file
11
12 sc, addr = s.accept() No newline at end of file
12 sc, addr = s.accept()
13 No newline at end of file
13
14 all = ""
14 all = ""
No newline at end of file
15
15 # while True:
No newline at end of file
No newline at end of file
16 # i=0 #to avoid infinit loop No newline at end of file
16 # recibido = sc.recv(1024)
No newline at end of file
17 # all = all + recibido
No newline at end of file
18 # if all[-4:] == "quit":
No newline at end of file
19 # break No newline at end of file
20 cnt = 0; No newline at end of file
17 cnt = 0;
18 first = 0; No newline at end of file
21 while True: No newline at end of file
19 while True:
22 recibido = sc.recv(1024)
20 recibido = sc.recv(1024)
No newline at end of file
23 if len(recibido) == 1024: No newline at end of file
24 all = all + recibido
21 all = all + recibido
No newline at end of file
22 cnt = len(all)
25 else:
No newline at end of file
No newline at end of file
23 if first == 0:
26 all = recibido No newline at end of file
No newline at end of file
24 first = 1;
No newline at end of file
25 lng = int(all[12:18]) # 6 bytes to get the frame size No newline at end of file
27
26
No newline at end of file
27 # i = i + 1
28 cnt = cnt + len(all)
No newline at end of file
No newline at end of file
28 # if cnt == lng or i == 30:
29 if cnt == 1024: No newline at end of file
No newline at end of file
29 if cnt == lng: No newline at end of file
30 break No newline at end of file
30 break
31 No newline at end of file
31
32 No newline at end of file
32
33
33
No newline at end of file
34 print "\nSize of frame:" + str(lng)
34 print "\nTotal:", all
No newline at end of file
No newline at end of file
35 print "\nNumber of bytes received:" + str(cnt) No newline at end of file
35 print "\nLongitud:", len(all) No newline at end of file
36 No newline at end of file
36
37 sc.close() No newline at end of file
37 sc.close()
38 s.close() No newline at end of file
38 s.close()
39 No newline at end of file
39
40 #print len(recibido) No newline at end of file
40 #print len(recibido)
General Comments 0
You need to be logged in to leave comments. Login now