Commit a513362fa803062afb9238269371b6016c835170

Authored by Brice Colombier
1 parent 5797c966eb
Exists in master

Parity check working, CONFIRM in progress, Backtracking in progress

Showing 9 changed files with 385 additions and 161 deletions

CASCADE/binary_par.py View file @ a513362
... ... @@ -10,7 +10,7 @@
10 10 import get_parities_from_indices as gpfi
11 11  
12 12  
13   -def binary_par(reference_response, blocks_to_correct, tclsh, board_manager):
  13 +def binary_par(reference_response, blocks_to_correct, tclsh, board_manager, response_length):
14 14  
15 15 """Implementation of the BINARY algorithm found in the CASCADE protocol.
16 16  
17 17  
18 18  
19 19  
20 20  
21 21  
22 22  
23 23  
... ... @@ -27,24 +27,30 @@
27 27 blocks_to_correct_first_half = [x[:int(len(x)/2)] for x in blocks_to_correct]
28 28 blocks_return = []
29 29 ref_rep = []
30   - parities = gpfi.get_parities_from_indices(blocks_to_correct_first_half, tclsh, board_manager)
  30 + parities = gpfi.get_parities_from_indices(blocks_to_correct_first_half, tclsh, board_manager, response_length*4)
  31 + print "Blocks to correct", blocks_to_correct
31 32 if len(blocks_to_correct[0]) > 2:
32 33 for i, j in enumerate(parities):
  34 + print reference_response[i][:block_size/2], j
33 35 if par.parity(reference_response[i][:block_size/2], j):
34   - # Error is in the first half of the block
  36 + print "Error is in the first half of the block"
35 37 blocks_return.append(blocks_to_correct[i][:block_size/2])
36 38 ref_rep.append(reference_response[i][:block_size/2])
37 39 else:
38   - # Error is in the second half of the block
  40 + print "Error is in the second half of the block"
39 41 blocks_return.append(blocks_to_correct[i][block_size/2:])
40 42 ref_rep.append(reference_response[i][block_size/2:])
  43 + print "Blocks return", blocks_return
41 44 return ref_rep, blocks_return
42 45 elif len(blocks_to_correct[0]) == 2:
43 46 for i, j in enumerate(parities):
44 47 if reference_response[i][0] == j:
  48 + print "Error is in the first half of the block"
45 49 blocks_return.append(blocks_to_correct[i][1])
46 50 else:
  51 + print "Error is in the second half of the block"
47 52 blocks_return.append(blocks_to_correct[i][0])
  53 + print "Blocks return", blocks_return
48 54 return ref_rep, blocks_return
49 55  
50 56 if __name__ == "__main__":
CASCADE/cascade.py View file @ a513362
... ... @@ -55,7 +55,7 @@
55 55  
56 56 split.split(reference_response, block_size)
57 57 split.split(indices, block_size)
58   - parities = gpfi.get_parities_from_indices(indices, tclsh, board_manager)
  58 + parities = gpfi.get_parities_from_indices(indices, tclsh, board_manager, len(reference_response)*4)
59 59 blocks_to_correct = []
60 60 reference_response_to_correct = []
61 61 for block_index, (reference_response_block, block_parity) in enumerate(zip(reference_response, parities)):
62 62  
63 63  
... ... @@ -69,11 +69,12 @@
69 69 else:
70 70 if passe > 0:
71 71 even_parity_blocks.append(indices[block_index])
  72 + # Validated until here
72 73 if blocks_to_correct:
73 74 while len(blocks_to_correct[0]) > 2:
74   - reference_response_to_correct, blocks_to_correct = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, tclsh, board_manager)
  75 + reference_response_to_correct, blocks_to_correct = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, tclsh, board_manager, len(reference_response)*4)
75 76 # Final BINARY execution where single PUF bits are queried from the board
76   - _, indices_to_flip = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, tclsh, board_manager)
  77 + _, indices_to_flip = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, tclsh, board_manager, len(reference_response)*4)
77 78 if passe > 0:
78 79 for index_to_flip in indices_to_flip:
79 80 # Move blocks from one group to the other if they contain the bit to flip
CASCADE/get_parities_from_indices.py View file @ a513362
... ... @@ -15,7 +15,7 @@
15 15  
16 16 from boards_management import board_commands
17 17  
18   -def get_parities_from_indices(indices, tclsh, board_manager):
  18 +def get_parities_from_indices(indices, tclsh, board_manager, response_length):
19 19  
20 20 """Get the parities of the on-board response blocks.
21 21  
... ... @@ -23,9 +23,11 @@
23 23 >>> get_parities_from_indices([[1, 5], [7, 2], [3, 6], [4, 0]])
24 24 [0, 1, 1, 0]
25 25 """
26   -
27   - parities = tclsh.eval(board_manager.command_get_parities_from_indices(indices))
28   - return [int(i) for i in list(parities.replace(" ", ""))]
  26 +
  27 + parities = tclsh.eval(board_manager.command_get_parities_from_indices(indices, response_length))
  28 + parities = [int(i) for i in list(parities.replace(" ", ""))]
  29 + print "Parities", parities
  30 + return parities
29 31  
30 32  
31 33 if __name__ == "__main__":
HECTOR_data_acq.tcl View file @ a513362
... ... @@ -25,7 +25,7 @@
25 25 set uart_check_timeout 100
26 26  
27 27 # Opens a connection to HECTOR evaluation board
28   -proc openDevice {dev {verbose 0}} {
  28 +proc openDevice {dev {baudrate 460800} {verbose 0}} {
29 29  
30 30 global tcl_platform
31 31  
... ... @@ -43,7 +43,7 @@
43 43 set ret -1
44 44 } else {
45 45 # Configure communication parameters
46   - fconfigure $fd -blocking 0 -buffering none -mode "115200,n,8,1" -translation binary -eofchar {}
  46 + fconfigure $fd -blocking 0 -buffering none -mode "$baudrate,n,8,1" -translation binary -eofchar {}
47 47  
48 48 # Update the application status
49 49 puts "Connection to '$dev' opened"
... ... @@ -76,7 +76,7 @@
76 76 # If there is something, process it
77 77 if {[string length $data] != 0} {
78 78 if {$verbose != 0} {
79   - puts "Received data: [toHEX $data]"
  79 + puts "Received data: [binToHEX $data]"
80 80 }
81 81  
82 82 # Get the MSS status packet header offset
... ... @@ -91,7 +91,7 @@
91 91 binary scan $response c1 ret(response)
92 92 binary scan $progress c1 ret(progress)
93 93 binary scan $aq_state c1 ret(aq_state)
94   - set ret(gpio) [toHEX $gpio]
  94 + set ret(gpio) [binToHEX $gpio]
95 95 return [list $ret(response) $ret(progress) $ret(aq_state) $ret(gpio)]
96 96 } else {
97 97  
... ... @@ -102,8 +102,8 @@
102 102 set fpga_data [string range $data [expr $offset + 4] [expr $offset + 7]]
103 103 set fpga_status [string range $data [expr $offset + 8] [expr $offset + 11]]
104 104  
105   - set ret(fpga_data) [toHEX $fpga_data]
106   - set ret(fpga_status) [toHEX $fpga_status]
  105 + set ret(fpga_data) [binToHEX $fpga_data]
  106 + set ret(fpga_status) [binToHEX $fpga_status]
107 107 return [list $ret(fpga_status) $ret(fpga_data)]
108 108 }
109 109 }
... ... @@ -133,7 +133,7 @@
133 133 }
134 134  
135 135 # Convert a binary string to HEX
136   -proc toHEX {in} {
  136 +proc binToHEX {in} {
137 137 set ret ""
138 138 for {set i 0} {$i < [string length $in]} {incr i} {
139 139 binary scan [string index $in $i] c1 byte
... ... @@ -180,6 +180,35 @@
180 180 return $ret
181 181 }
182 182  
  183 +# Convert DEC to HEX
  184 +proc toHEX {in} {
  185 + set ret ""
  186 + set dec $in
  187 + while { $dec > 0 } {
  188 + set rest [expr $dec % 16]
  189 + switch $rest {
  190 + 0 {set ret "0$ret"}
  191 + 1 {set ret "1$ret"}
  192 + 2 {set ret "2$ret"}
  193 + 3 {set ret "3$ret"}
  194 + 4 {set ret "4$ret"}
  195 + 5 {set ret "5$ret"}
  196 + 6 {set ret "6$ret"}
  197 + 7 {set ret "7$ret"}
  198 + 8 {set ret "8$ret"}
  199 + 9 {set ret "9$ret"}
  200 + 10 {set ret "A$ret"}
  201 + 11 {set ret "B$ret"}
  202 + 12 {set ret "C$ret"}
  203 + 13 {set ret "D$ret"}
  204 + 14 {set ret "E$ret"}
  205 + 15 {set ret "F$ret"}
  206 + }
  207 + set dec [expr $dec / 16]
  208 + }
  209 + return $ret
  210 +}
  211 +
183 212 # Function to convert HEX to DEC
184 213 proc fromHEX {in} {
185 214 set in_end [expr [string length $in] - 1]
... ... @@ -213,34 +242,6 @@
213 242 return [expr ( $decNumber & (2**$bitFieldIndex) ) >> $bitFieldIndex]
214 243 }
215 244  
216   -# Bitwise XOR of two HEX values
217   -proc xorHEX { in1 in2 } {
218   - if { [string length $in1] != [string length $in2] } {
219   - return -1
220   - } else {
221   - set ret ""
222   - for {set i 0} {$i < [string length $in1]} {incr i} {
223   - set num1 [fromHEX [string index $in1 $i]]
224   - set num2 [fromHEX [string index $in2 $i]]
225   - set xor_val [expr $num1^$num2]
226   - if {$xor_val < 10} {
227   - set hex_val $xor_val
228   - } else {
229   - switch $xor_val {
230   - "10" {set hex_val "A"}
231   - "11" {set hex_val "B"}
232   - "12" {set hex_val "C"}
233   - "13" {set hex_val "D"}
234   - "14" {set hex_val "E"}
235   - "15" {set hex_val "F"}
236   - }
237   - }
238   - set ret "$ret$hex_val"
239   - }
240   - return $ret
241   - }
242   -}
243   -
244 245 ##############
245 246 ## COMMANDS ##
246 247 ##############
... ... @@ -252,7 +253,7 @@
252 253 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07"
253 254 puts -nonewline [lindex $device 1] $data
254 255 if {$verbose != 0} {
255   - puts "Sending: [toHEX $data]"
  256 + puts "Sending: [binToHEX $data]"
256 257 }
257 258  
258 259 set resp "-1 1"
... ... @@ -269,7 +270,7 @@
269 270 set data "\x13\xFB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
270 271 puts -nonewline [lindex $device 1] $data
271 272 if {$verbose != 0} {
272   - puts "Sending: [toHEX $data]"
  273 + puts "Sending: [binToHEX $data]"
273 274 }
274 275 # Return the response of the command
275 276 set resp "-1 1"
... ... @@ -295,7 +296,7 @@
295 296 set data "\x13\xFB\x00\x00[binary format I1 $data][binary format I1 $command]"
296 297 puts -nonewline [lindex $device 1] $data
297 298 if {$verbose != 0} {
298   - puts "Sending: [toHEX $data]"
  299 + puts "Sending: [binToHEX $data]"
299 300 }
300 301 # Return the response of the command
301 302 set resp "-1 1"
... ... @@ -317,7 +318,7 @@
317 318 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"
318 319 puts -nonewline [lindex $device 1] $data
319 320 if {$verbose != 0} {
320   - puts "Sending: [toHEX $data]"
  321 + puts "Sending: [binToHEX $data]"
321 322 }
322 323 # Return the response of the command
323 324 set resp "-1 1"
... ... @@ -339,7 +340,7 @@
339 340 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05"
340 341 puts -nonewline [lindex $device 1] $data
341 342 if {$verbose != 0} {
342   - puts "Sending: [toHEX $data]"
  343 + puts "Sending: [binToHEX $data]"
343 344 }
344 345 # Return the response of the command
345 346 set resp "-1 1"
... ... @@ -361,7 +362,7 @@
361 362 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06"
362 363 puts -nonewline [lindex $device 1] $data
363 364 if {$verbose != 0} {
364   - puts "Sending: [toHEX $data]"
  365 + puts "Sending: [binToHEX $data]"
365 366 }
366 367 # Return the response of the command
367 368 set resp "-1 1"
... ... @@ -383,7 +384,7 @@
383 384 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08"
384 385 puts -nonewline [lindex $device 1] $data
385 386 if {$verbose != 0} {
386   - puts "Sending: [toHEX $data]"
  387 + puts "Sending: [binToHEX $data]"
387 388 }
388 389 # Return the response of the command
389 390 set resp "-1 1"
... ... @@ -405,7 +406,7 @@
405 406 set data "\x13\xFD\x00\x00$filename [binary format I1 $size]"
406 407 puts -nonewline [lindex $device 1] $data
407 408 if {$verbose != 0} {
408   - puts "Sending command: [toHEX $data]"
  409 + puts "Sending command: [binToHEX $data]"
409 410 }
410 411 # Return the response of the command
411 412 set resp "-1 1"
... ... @@ -427,7 +428,7 @@
427 428 set data "\x13\x3D\x00\x00$filename [binary format I1 $size]"
428 429 puts -nonewline [lindex $device 1] $data
429 430 if {$verbose != 0} {
430   - puts "Sending command: [toHEX $data]"
  431 + puts "Sending command: [binToHEX $data]"
431 432 }
432 433 # Return the response of the command
433 434 set resp "-1 1"
... ... @@ -449,7 +450,7 @@
449 450 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x09"
450 451 puts -nonewline [lindex $device 1] $data
451 452 if {$verbose != 0} {
452   - puts "Sending command: [toHEX $data]"
  453 + puts "Sending command: [binToHEX $data]"
453 454 }
454 455 # Return the response of the command
455 456 set resp "-1 1"
... ... @@ -471,7 +472,7 @@
471 472 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x0A"
472 473 puts -nonewline [lindex $device 1] $data
473 474 if {$verbose != 0} {
474   - puts "Sending command: [toHEX $data]"
  475 + puts "Sending command: [binToHEX $data]"
475 476 }
476 477 # Return the response of the command
477 478 set resp "-1 1"
... ... @@ -493,7 +494,7 @@
493 494 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0B"
494 495 puts -nonewline [lindex $device 1] $data
495 496 if {$verbose != 0} {
496   - puts "Sending command: [toHEX $data]"
  497 + puts "Sending command: [binToHEX $data]"
497 498 }
498 499 # Return the response of the command
499 500 set resp "-1 1"
... ... @@ -525,7 +526,7 @@
525 526 set data "\x13\xFB\x00\x00\x00\x00\x00\x00[binary format I1 $command]"
526 527 puts -nonewline [lindex $device 1] $data
527 528 if {$verbose != 0} {
528   - puts "Sending command: [toHEX $data]"
  529 + puts "Sending command: [binToHEX $data]"
529 530 }
530 531 # Return the response of the command
531 532 set resp "-1 1"
... ... @@ -751,5 +752,75 @@
751 752 puts "Acquired data are available in the file $filename"
752 753  
753 754 return 0
  755 +}
  756 +
  757 +proc hex2bin {hexIn {spaceSeparated 0}} {
  758 + set outStr ""
  759 +
  760 + for {set i 0} {$i < [string length $hexIn]} {incr i} {
  761 + set char [string index $hexIn $i]
  762 + switch -glob $char {
  763 + "0" {set outStr "$outStr 0000"}
  764 + "1" {set outStr "$outStr 0001"}
  765 + "2" {set outStr "$outStr 0010"}
  766 + "3" {set outStr "$outStr 0011"}
  767 + "4" {set outStr "$outStr 0100"}
  768 + "5" {set outStr "$outStr 0101"}
  769 + "6" {set outStr "$outStr 0110"}
  770 + "7" {set outStr "$outStr 0111"}
  771 + "8" {set outStr "$outStr 1000"}
  772 + "9" {set outStr "$outStr 1001"}
  773 + "A" {set outStr "$outStr 1010"}
  774 + "a" {set outStr "$outStr 1010"}
  775 + "B" {set outStr "$outStr 1011"}
  776 + "b" {set outStr "$outStr 1011"}
  777 + "C" {set outStr "$outStr 1100"}
  778 + "c" {set outStr "$outStr 1100"}
  779 + "D" {set outStr "$outStr 1101"}
  780 + "d" {set outStr "$outStr 1101"}
  781 + "E" {set outStr "$outStr 1110"}
  782 + "e" {set outStr "$outStr 1110"}
  783 + "F" {set outStr "$outStr 1111"}
  784 + "f" {set outStr "$outStr 1111"}
  785 + default {}
  786 + }
  787 + }
  788 +
  789 + if { $spaceSeparated == 0 } {
  790 + set outStr [string map {" " {}} $outStr]
  791 + }
  792 +
  793 + return $outStr
  794 +}
  795 +
  796 +proc bin2hex {binIn} {
  797 + set outStr ""
  798 +
  799 + for {set i 0} {$i < [string length $binIn]} {set i [expr $i+4]} {
  800 + set char4 [string range $binIn [expr $i] [expr $i+3] ]
  801 + switch -glob $char4 {
  802 + "0000" {set outStr "$outStr 0"}
  803 + "0001" {set outStr "$outStr 1"}
  804 + "0010" {set outStr "$outStr 2"}
  805 + "0011" {set outStr "$outStr 3"}
  806 + "0100" {set outStr "$outStr 4"}
  807 + "0101" {set outStr "$outStr 5"}
  808 + "0110" {set outStr "$outStr 6"}
  809 + "0111" {set outStr "$outStr 7"}
  810 + "1000" {set outStr "$outStr 8"}
  811 + "1001" {set outStr "$outStr 9"}
  812 + "1010" {set outStr "$outStr A"}
  813 + "1011" {set outStr "$outStr B"}
  814 + "1100" {set outStr "$outStr C"}
  815 + "1101" {set outStr "$outStr D"}
  816 + "1110" {set outStr "$outStr E"}
  817 + "1111" {set outStr "$outStr F"}
  818 + default {}
  819 + }
  820 + }
  821 +
  822 + set outStr [string map {" " {}} $outStr]
  823 +
  824 + return $outStr
754 825 }
... ... @@ -167,7 +167,7 @@
167 167 def get_PUF_response(self):
168 168 self.PUF_response_displayed.set("")
169 169 try:
170   - self.tcl_obj.eval(self.board_manager.reset_boards())
  170 + self.tcl_obj.eval(self.board_manager.reset_boards(port=2))
171 171 self.tcl_obj.eval(self.board_manager.generate_response())
172 172 temp_hex_response = self.tcl_obj.eval(self.board_manager.offload_response())
173 173 self.PUF_response = list(reversed(response_converter_to_bin_list(temp_hex_response)))
174 174  
... ... @@ -308,11 +308,11 @@
308 308 self.message_AW_saved.set(str("Activation word saved under "+filename))
309 309  
310 310 def perform_reconciliation(self):
311   - self.tcl_obj.eval(self.board_manager.reset_boards())
  311 + self.tcl_obj.eval(self.board_manager.reset_boards(port=2))
312 312 self.tcl_obj.eval(self.board_manager.generate_response())
313 313 server_before = self.server_reference_response
314 314 on_board = response_converter_to_bin_list(self.tcl_obj.eval(self.board_manager.offload_response()))
315   - print on_board
  315 + print "Differences before/on_board: ", [a for (a, (b, c)) in enumerate(zip(server_before, list(reversed(on_board)))) if b != c]
316 316 self.server_reference_response = cascade(self.server_reference_response,
317 317 0.02,
318 318 int(self.reconciliation_parameter_number_of_passes_spinbox.get()),
319 319  
... ... @@ -321,16 +321,12 @@
321 321 int(self.reconciliation_parameter_initial_block_size_spinbox.get()))
322 322 server_after = self.server_reference_response
323 323 on_board = response_converter_to_bin_list(self.tcl_obj.eval(self.board_manager.offload_response()))
324   - print server_before
325   - print server_after
326   - print on_board
327   - print "Differences before/on_board: ", [a for (a, (b, c)) in enumerate(zip(server_before, list(reversed(on_board)))) if b != c]
328 324 print "Differences after/on_board: ", [a for (a, (b, c)) in enumerate(zip(server_after, list(reversed(on_board)))) if b != c]
329 325 print "Differences before/after: ", [a for (a, (b, c)) in enumerate(zip(server_before, server_after)) if b != c]
330 326 print ("Reconciliation done")
331 327  
332   - def reset_board(self):
333   - self.tcl_obj.eval(self.board_manager.reset_boards())
  328 + def reset_board(self, port=2):
  329 + self.tcl_obj.eval(self.board_manager.reset_boards(port=2))
334 330  
335 331 def reset(self):
336 332 print ("To be implemented soon")
boards_management/HECTOR_data_acq.tcl View file @ a513362
... ... @@ -25,7 +25,7 @@
25 25 set uart_check_timeout 100
26 26  
27 27 # Opens a connection to HECTOR evaluation board
28   -proc openDevice {dev {verbose 0}} {
  28 +proc openDevice {dev {baudrate 460800} {verbose 0}} {
29 29  
30 30 global tcl_platform
31 31  
... ... @@ -43,7 +43,7 @@
43 43 set ret -1
44 44 } else {
45 45 # Configure communication parameters
46   - fconfigure $fd -blocking 0 -buffering none -mode "115200,n,8,1" -translation binary -eofchar {}
  46 + fconfigure $fd -blocking 0 -buffering none -mode "$baudrate,n,8,1" -translation binary -eofchar {}
47 47  
48 48 # Update the application status
49 49 puts "Connection to '$dev' opened"
... ... @@ -76,7 +76,7 @@
76 76 # If there is something, process it
77 77 if {[string length $data] != 0} {
78 78 if {$verbose != 0} {
79   - puts "Received data: [toHEX $data]"
  79 + puts "Received data: [binToHEX $data]"
80 80 }
81 81  
82 82 # Get the MSS status packet header offset
... ... @@ -91,7 +91,7 @@
91 91 binary scan $response c1 ret(response)
92 92 binary scan $progress c1 ret(progress)
93 93 binary scan $aq_state c1 ret(aq_state)
94   - set ret(gpio) [toHEX $gpio]
  94 + set ret(gpio) [binToHEX $gpio]
95 95 return [list $ret(response) $ret(progress) $ret(aq_state) $ret(gpio)]
96 96 } else {
97 97  
... ... @@ -102,8 +102,8 @@
102 102 set fpga_data [string range $data [expr $offset + 4] [expr $offset + 7]]
103 103 set fpga_status [string range $data [expr $offset + 8] [expr $offset + 11]]
104 104  
105   - set ret(fpga_data) [toHEX $fpga_data]
106   - set ret(fpga_status) [toHEX $fpga_status]
  105 + set ret(fpga_data) [binToHEX $fpga_data]
  106 + set ret(fpga_status) [binToHEX $fpga_status]
107 107 return [list $ret(fpga_status) $ret(fpga_data)]
108 108 }
109 109 }
... ... @@ -133,7 +133,7 @@
133 133 }
134 134  
135 135 # Convert a binary string to HEX
136   -proc toHEX {in} {
  136 +proc binToHEX {in} {
137 137 set ret ""
138 138 for {set i 0} {$i < [string length $in]} {incr i} {
139 139 binary scan [string index $in $i] c1 byte
... ... @@ -180,6 +180,35 @@
180 180 return $ret
181 181 }
182 182  
  183 +# Convert DEC to HEX
  184 +proc toHEX {in} {
  185 + set ret ""
  186 + set dec $in
  187 + while { $dec > 0 } {
  188 + set rest [expr $dec % 16]
  189 + switch $rest {
  190 + 0 {set ret "0$ret"}
  191 + 1 {set ret "1$ret"}
  192 + 2 {set ret "2$ret"}
  193 + 3 {set ret "3$ret"}
  194 + 4 {set ret "4$ret"}
  195 + 5 {set ret "5$ret"}
  196 + 6 {set ret "6$ret"}
  197 + 7 {set ret "7$ret"}
  198 + 8 {set ret "8$ret"}
  199 + 9 {set ret "9$ret"}
  200 + 10 {set ret "A$ret"}
  201 + 11 {set ret "B$ret"}
  202 + 12 {set ret "C$ret"}
  203 + 13 {set ret "D$ret"}
  204 + 14 {set ret "E$ret"}
  205 + 15 {set ret "F$ret"}
  206 + }
  207 + set dec [expr $dec / 16]
  208 + }
  209 + return $ret
  210 +}
  211 +
183 212 # Function to convert HEX to DEC
184 213 proc fromHEX {in} {
185 214 set in_end [expr [string length $in] - 1]
... ... @@ -213,34 +242,6 @@
213 242 return [expr ( $decNumber & (2**$bitFieldIndex) ) >> $bitFieldIndex]
214 243 }
215 244  
216   -# Bitwise XOR of two HEX values
217   -proc xorHEX { in1 in2 } {
218   - if { [string length $in1] != [string length $in2] } {
219   - return -1
220   - } else {
221   - set ret ""
222   - for {set i 0} {$i < [string length $in1]} {incr i} {
223   - set num1 [fromHEX [string index $in1 $i]]
224   - set num2 [fromHEX [string index $in2 $i]]
225   - set xor_val [expr $num1^$num2]
226   - if {$xor_val < 10} {
227   - set hex_val $xor_val
228   - } else {
229   - switch $xor_val {
230   - "10" {set hex_val "A"}
231   - "11" {set hex_val "B"}
232   - "12" {set hex_val "C"}
233   - "13" {set hex_val "D"}
234   - "14" {set hex_val "E"}
235   - "15" {set hex_val "F"}
236   - }
237   - }
238   - set ret "$ret$hex_val"
239   - }
240   - return $ret
241   - }
242   -}
243   -
244 245 ##############
245 246 ## COMMANDS ##
246 247 ##############
... ... @@ -252,7 +253,7 @@
252 253 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07"
253 254 puts -nonewline [lindex $device 1] $data
254 255 if {$verbose != 0} {
255   - puts "Sending: [toHEX $data]"
  256 + puts "Sending: [binToHEX $data]"
256 257 }
257 258  
258 259 set resp "-1 1"
... ... @@ -269,7 +270,7 @@
269 270 set data "\x13\xFB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
270 271 puts -nonewline [lindex $device 1] $data
271 272 if {$verbose != 0} {
272   - puts "Sending: [toHEX $data]"
  273 + puts "Sending: [binToHEX $data]"
273 274 }
274 275 # Return the response of the command
275 276 set resp "-1 1"
... ... @@ -295,7 +296,7 @@
295 296 set data "\x13\xFB\x00\x00[binary format I1 $data][binary format I1 $command]"
296 297 puts -nonewline [lindex $device 1] $data
297 298 if {$verbose != 0} {
298   - puts "Sending: [toHEX $data]"
  299 + puts "Sending: [binToHEX $data]"
299 300 }
300 301 # Return the response of the command
301 302 set resp "-1 1"
... ... @@ -317,7 +318,7 @@
317 318 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"
318 319 puts -nonewline [lindex $device 1] $data
319 320 if {$verbose != 0} {
320   - puts "Sending: [toHEX $data]"
  321 + puts "Sending: [binToHEX $data]"
321 322 }
322 323 # Return the response of the command
323 324 set resp "-1 1"
... ... @@ -339,7 +340,7 @@
339 340 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05"
340 341 puts -nonewline [lindex $device 1] $data
341 342 if {$verbose != 0} {
342   - puts "Sending: [toHEX $data]"
  343 + puts "Sending: [binToHEX $data]"
343 344 }
344 345 # Return the response of the command
345 346 set resp "-1 1"
... ... @@ -361,7 +362,7 @@
361 362 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06"
362 363 puts -nonewline [lindex $device 1] $data
363 364 if {$verbose != 0} {
364   - puts "Sending: [toHEX $data]"
  365 + puts "Sending: [binToHEX $data]"
365 366 }
366 367 # Return the response of the command
367 368 set resp "-1 1"
... ... @@ -383,7 +384,7 @@
383 384 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08"
384 385 puts -nonewline [lindex $device 1] $data
385 386 if {$verbose != 0} {
386   - puts "Sending: [toHEX $data]"
  387 + puts "Sending: [binToHEX $data]"
387 388 }
388 389 # Return the response of the command
389 390 set resp "-1 1"
... ... @@ -405,7 +406,7 @@
405 406 set data "\x13\xFD\x00\x00$filename [binary format I1 $size]"
406 407 puts -nonewline [lindex $device 1] $data
407 408 if {$verbose != 0} {
408   - puts "Sending command: [toHEX $data]"
  409 + puts "Sending command: [binToHEX $data]"
409 410 }
410 411 # Return the response of the command
411 412 set resp "-1 1"
... ... @@ -427,7 +428,7 @@
427 428 set data "\x13\x3D\x00\x00$filename [binary format I1 $size]"
428 429 puts -nonewline [lindex $device 1] $data
429 430 if {$verbose != 0} {
430   - puts "Sending command: [toHEX $data]"
  431 + puts "Sending command: [binToHEX $data]"
431 432 }
432 433 # Return the response of the command
433 434 set resp "-1 1"
... ... @@ -449,7 +450,7 @@
449 450 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x09"
450 451 puts -nonewline [lindex $device 1] $data
451 452 if {$verbose != 0} {
452   - puts "Sending command: [toHEX $data]"
  453 + puts "Sending command: [binToHEX $data]"
453 454 }
454 455 # Return the response of the command
455 456 set resp "-1 1"
... ... @@ -471,7 +472,7 @@
471 472 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x0A"
472 473 puts -nonewline [lindex $device 1] $data
473 474 if {$verbose != 0} {
474   - puts "Sending command: [toHEX $data]"
  475 + puts "Sending command: [binToHEX $data]"
475 476 }
476 477 # Return the response of the command
477 478 set resp "-1 1"
... ... @@ -493,7 +494,7 @@
493 494 set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0B"
494 495 puts -nonewline [lindex $device 1] $data
495 496 if {$verbose != 0} {
496   - puts "Sending command: [toHEX $data]"
  497 + puts "Sending command: [binToHEX $data]"
497 498 }
498 499 # Return the response of the command
499 500 set resp "-1 1"
... ... @@ -525,7 +526,7 @@
525 526 set data "\x13\xFB\x00\x00\x00\x00\x00\x00[binary format I1 $command]"
526 527 puts -nonewline [lindex $device 1] $data
527 528 if {$verbose != 0} {
528   - puts "Sending command: [toHEX $data]"
  529 + puts "Sending command: [binToHEX $data]"
529 530 }
530 531 # Return the response of the command
531 532 set resp "-1 1"
... ... @@ -751,5 +752,75 @@
751 752 puts "Acquired data are available in the file $filename"
752 753  
753 754 return 0
  755 +}
  756 +
  757 +proc hex2bin {hexIn {spaceSeparated 0}} {
  758 + set outStr ""
  759 +
  760 + for {set i 0} {$i < [string length $hexIn]} {incr i} {
  761 + set char [string index $hexIn $i]
  762 + switch -glob $char {
  763 + "0" {set outStr "$outStr 0000"}
  764 + "1" {set outStr "$outStr 0001"}
  765 + "2" {set outStr "$outStr 0010"}
  766 + "3" {set outStr "$outStr 0011"}
  767 + "4" {set outStr "$outStr 0100"}
  768 + "5" {set outStr "$outStr 0101"}
  769 + "6" {set outStr "$outStr 0110"}
  770 + "7" {set outStr "$outStr 0111"}
  771 + "8" {set outStr "$outStr 1000"}
  772 + "9" {set outStr "$outStr 1001"}
  773 + "A" {set outStr "$outStr 1010"}
  774 + "a" {set outStr "$outStr 1010"}
  775 + "B" {set outStr "$outStr 1011"}
  776 + "b" {set outStr "$outStr 1011"}
  777 + "C" {set outStr "$outStr 1100"}
  778 + "c" {set outStr "$outStr 1100"}
  779 + "D" {set outStr "$outStr 1101"}
  780 + "d" {set outStr "$outStr 1101"}
  781 + "E" {set outStr "$outStr 1110"}
  782 + "e" {set outStr "$outStr 1110"}
  783 + "F" {set outStr "$outStr 1111"}
  784 + "f" {set outStr "$outStr 1111"}
  785 + default {}
  786 + }
  787 + }
  788 +
  789 + if { $spaceSeparated == 0 } {
  790 + set outStr [string map {" " {}} $outStr]
  791 + }
  792 +
  793 + return $outStr
  794 +}
  795 +
  796 +proc bin2hex {binIn} {
  797 + set outStr ""
  798 +
  799 + for {set i 0} {$i < [string length $binIn]} {set i [expr $i+4]} {
  800 + set char4 [string range $binIn [expr $i] [expr $i+3] ]
  801 + switch -glob $char4 {
  802 + "0000" {set outStr "$outStr 0"}
  803 + "0001" {set outStr "$outStr 1"}
  804 + "0010" {set outStr "$outStr 2"}
  805 + "0011" {set outStr "$outStr 3"}
  806 + "0100" {set outStr "$outStr 4"}
  807 + "0101" {set outStr "$outStr 5"}
  808 + "0110" {set outStr "$outStr 6"}
  809 + "0111" {set outStr "$outStr 7"}
  810 + "1000" {set outStr "$outStr 8"}
  811 + "1001" {set outStr "$outStr 9"}
  812 + "1010" {set outStr "$outStr A"}
  813 + "1011" {set outStr "$outStr B"}
  814 + "1100" {set outStr "$outStr C"}
  815 + "1101" {set outStr "$outStr D"}
  816 + "1110" {set outStr "$outStr E"}
  817 + "1111" {set outStr "$outStr F"}
  818 + default {}
  819 + }
  820 + }
  821 +
  822 + set outStr [string map {" " {}} $outStr]
  823 +
  824 + return $outStr
754 825 }
boards_management/board_commands.py View file @ a513362
... ... @@ -7,6 +7,7 @@
7 7 # Date: 2016-10-27
8 8  
9 9 import Tkinter
  10 +import itertools as it
10 11  
11 12 class Board_manager():
12 13  
13 14  
14 15  
15 16  
16 17  
... ... @@ -24,29 +25,23 @@
24 25 command = "set dev [openDevice "+COM_port+"]\n"
25 26 return command
26 27  
27   - def reset_boards(self):
  28 + def reset_boards(self, port):
28 29 command = "softReset $dev\n\
29   -sendDaughterReset $dev\n\
30   -sendFabricReset $dev"
  30 +sendFabricReset $dev\n\
  31 +selectDaughterBoard $dev "+str(port)+"\n\
  32 +sendDaughterReset $dev"
31 33 return command
32   -
33   - def select_DB_connection(self, port):
34   - if port not in [1, 2]:
35   - raise Exception ("Invalid port")
36   - else:
37   - command = "selectDaughterBoard $dev "+str(port)+"\n"
38   - return command
39 34  
40 35 def generate_response(self):
41   - command = "sendFabricCommand $dev 4 7\n"
  36 + command = "sendFabricCommand $dev 6 [fromHEX \"00000001\"]\n"
42 37 return command
43 38  
44 39 def offload_response(self):
45   - command = "sendFabricCommand $dev 4 3\n\
46   -set rep \"[sendFabricCommand $dev 5 3]\
47   -[sendFabricCommand $dev 5 2]\
48   -[sendFabricCommand $dev 5 1]\
49   -[sendFabricCommand $dev 5 0]\"\n\
  40 + command = "sendFabricCommand $dev 6 [fromHEX \"00000002\"]\n\
  41 +set rep_LSB \"[lindex [sendFabricCommand $dev 9 0] 1] [lindex [sendFabricCommand $dev 10 0] 1]\"\n\
  42 +sendFabricCommand $dev 6 [fromHEX \"00000003\"]\n\
  43 +set rep_MSB \"[lindex [sendFabricCommand $dev 9 0] 1] [lindex [sendFabricCommand $dev 10 0] 1]\"\n\
  44 +set rep $rep_MSB$rep_LSB\n\
50 45 regsub -all { } $rep {} rep\n\
51 46 return $rep"
52 47 return command
53 48  
54 49  
... ... @@ -56,17 +51,75 @@
56 51 command = "getStatus $dev\n"
57 52 return command
58 53  
59   - def command_get_parities_from_indices(self, indices):
  54 + def command_get_parities_from_indices(self, indices, response_length):
60 55  
61   - command = ""
62   - command+="set parities \"\"\n"
  56 + CASCADE_code = {1:"1",
  57 + 2:"2",
  58 + 4:"3",
  59 + 8:"4",
  60 + 16:"5",
  61 + 32:"6",
  62 + 64:"7"}
  63 +
  64 + nb_blocks = len(indices)
  65 + len_each_block = [len(i) for i in indices]
  66 + len_blocks = len_each_block[0]
  67 +
  68 + if nb_blocks*[len_blocks] != len_each_block:
  69 + raise ValueError("Blocks have different length", len_blocks, " VS ", len_each_block)
  70 + if len_blocks not in [1, 2, 4, 8, 16, 32, 64]:
  71 + raise ValueError("Illegal block size")
  72 + flat_indices = []
63 73 for i in indices:
64   - command+="sendFabricCommand $dev 4 5\n\
65   -sendFabricCommand $dev 4 "+str(len(i))+"\n"
66   - command+="\n".join(["sendFabricCommand $dev 4 "+str(j) for j in i])+"\n"
67   - command+="sendFabricCommand $dev 4 6\n\
68   -lappend parities [expr [lindex [sendFabricCommand $dev 4 0] 1] & 1]\n"
69   - command+="return $parities"
  74 + flat_indices.extend(i)
  75 + if [i for i in flat_indices if i > response_length-1]:
  76 + print flat_indices
  77 + print response_length
  78 + raise ValueError("Some indexes are out of the response", i)
  79 + if sorted(flat_indices) != sorted(list(set(flat_indices))):
  80 + print flat_indices
  81 + print list(set(flat_indices))
  82 + raise ValueError("Some indices are repeated")
  83 + flat_indices = [str(hex(i))[2:] for i in flat_indices]
  84 + flat_indices = [i.zfill(2) for i in flat_indices]
  85 + flat_indices = list(reversed([str.upper(i) for i in flat_indices]))
  86 +
  87 + if nb_blocks == 1:
  88 + # CONFIRM mode
  89 + if len(flat_indices) > response_length/4:
  90 + raise ValueError("Block is too large with respect to response length")
  91 + # else:
  92 + # if nb_blocks*len_blocks != 128:
  93 + # raise ValueError("Illegal combination of block size and number of blocks")
  94 + if len(flat_indices) < 4:
  95 + command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(6)+CASCADE_code[len_blocks]+"5\"]\n"
  96 + elif len(flat_indices) < 8:
  97 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"5\"]\n"
  98 + del flat_indices[-3:]
  99 + command="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices).zfill(8)+"\"]\n"
  100 + command+=temp_command
  101 + else:
  102 + command=""
  103 + if nb_blocks == 1:
  104 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"5\"]\n"
  105 + else:
  106 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"4\"]\n"
  107 + del flat_indices[-3:]
  108 + command+="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices[-4:])+"\"]\n"
  109 + command+=temp_command
  110 + del flat_indices[-4:]
  111 + while len(flat_indices) > 4:
  112 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  113 + del flat_indices[-4:]
  114 + command+="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  115 + command+=temp_command
  116 + del flat_indices[-4:]
  117 + if flat_indices:
  118 + command+="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(8)+"\"]\n"
  119 + command+="sendFabricCommand $dev 6 [fromHEX \"00000006\"]\n"
  120 + command+="set par [hex2bin [lindex [sendFabricCommand $dev 10 0] 1]]\n"
  121 + command+="return [string reverse [string range [string reverse $par] 0 "+str(nb_blocks-1)+"]]"
  122 + # print command
70 123 return command
71 124  
72 125 def disconnect(self):
boards_management/test_scenario.py View file @ a513362
... ... @@ -5,27 +5,51 @@
5 5 board_manager = board_commands.Board_manager()
6 6  
7 7 tclsh.eval(board_manager.source_tcl_package())
8   -tclsh.eval(board_manager.connect("COM5"))
9   -tclsh.eval(board_manager.reset_boards())
  8 +tclsh.eval(board_manager.connect("COM6"))
  9 +tclsh.eval(board_manager.reset_boards(port=2))
10 10 tclsh.eval(board_manager.generate_response())
11 11 print tclsh.eval(board_manager.offload_response())
12   -print tclsh.eval(board_manager.command_get_parities_from_indices([[0, 1, 2, 3]]))
13   -print tclsh.eval(board_manager.command_get_parities_from_indices([[4, 5]]))
14   -print tclsh.eval(board_manager.command_get_parities_from_indices([[6, 7]]))
15   -print tclsh.eval(board_manager.offload_response())
16   -tclsh.eval(board_manager.generate_response())
17   -print tclsh.eval(board_manager.offload_response())
18   -tclsh.eval(board_manager.reset_boards())
19   -tclsh.eval(board_manager.generate_response())
20   -print tclsh.eval(board_manager.offload_response())
21 12  
22   -# tclsh.eval(board_manager.
23   -# tclsh.eval(board_manager.
24   -# tclsh.eval(board_manager.
25   -# tclsh.eval(board_manager.
26   -# tclsh.eval(board_manager.
27   -# tclsh.eval(board_manager.
28   -# tclsh.eval(board_manager.
29   -# tclsh.eval(board_manager.
  13 +print tclsh.eval(board_manager.command_get_parities_from_indices([[0, 1, 2, 3],
  14 + [4, 5, 6, 7],
  15 + [8, 9, 10, 11],
  16 + [12, 13, 14, 15],
  17 + [16, 17, 18, 19],
  18 + [20, 21, 22, 23],
  19 + [24, 25, 26, 27],
  20 + [28, 29, 30, 31],
  21 + [32, 33, 34, 35],
  22 + [36, 37, 38, 39],
  23 + [40, 41, 42, 43],
  24 + [44, 45, 46, 47],
  25 + [48, 49, 50, 51],
  26 + [52, 53, 54, 55],
  27 + [56, 57, 58, 59],
  28 + [60, 61, 62, 63],
  29 + [64, 65, 66, 67],
  30 + [68, 69, 70, 71],
  31 + [72, 73, 74, 75],
  32 + [76, 77, 78, 79],
  33 + [80, 81, 82, 83],
  34 + [84, 85, 86, 87],
  35 + [88, 89, 90, 91],
  36 + [92, 93, 94, 95],
  37 + [96, 97, 98, 99],
  38 + [100, 101, 102, 103],
  39 + [104, 105, 106, 107],
  40 + [108, 109, 110, 111],
  41 + [112, 113, 114, 115],
  42 + [116, 117, 118, 119],
  43 + [120, 121, 122, 123],
  44 + [124, 125, 126, 127]], 128))
  45 +print tclsh.eval(board_manager.command_get_parities_from_indices([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
  46 + [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
  47 + [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47],
  48 + [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
  49 + [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
  50 + [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95],
  51 + [96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111],
  52 + [112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]], 128))
  53 +
30 54 tclsh.eval(board_manager.disconnect())
declare_initialize_variables.py View file @ a513362
... ... @@ -24,7 +24,7 @@
24 24 self.filename = StringVar()
25 25 self.filename.set("No design loaded")
26 26 self.com_port = StringVar()
27   - self.com_port.set("COM5")
  27 + self.com_port.set("COM6")
28 28 self.masking_overhead = IntVar()
29 29 self.masking_overhead.set(5)
30 30 self.locking_overhead = IntVar()