(self, target_id)
| 93 | return None |
| 94 | |
| 95 | def reset_to_bootloader(self, target_id): |
| 96 | retry_counter = 5 |
| 97 | pk = CRTPPacket() |
| 98 | pk.set_header(0xFF, 0xFF) |
| 99 | pk.data = (target_id, 0xFF) |
| 100 | self.link.send_packet(pk) |
| 101 | |
| 102 | got_answer = False |
| 103 | while(not got_answer and retry_counter >= 0): |
| 104 | pk = self.link.receive_packet(1) |
| 105 | if pk and pk.header == 0xFF: |
| 106 | try: |
| 107 | data = struct.unpack('<BB', pk.data[0:2]) |
| 108 | got_answer = data == (target_id, 0xFF) |
| 109 | except struct.error: |
| 110 | # Failed unpacking, retry |
| 111 | pass |
| 112 | |
| 113 | if got_answer: |
| 114 | new_address = (0xb1,) + struct.unpack('<BBBB', pk.data[2:6][::-1]) |
| 115 | |
| 116 | # The reset packet arrival cannot be checked. |
| 117 | # Send it more than one time to increase the chances it makes it. |
| 118 | for _ in range(10): |
| 119 | pk = CRTPPacket() |
| 120 | pk.set_header(0xFF, 0xFF) |
| 121 | pk.data = (target_id, 0xF0, 0x00) |
| 122 | self.link.send_packet(pk) |
| 123 | |
| 124 | addr = int(binascii.hexlify( |
| 125 | struct.pack('B' * 5, *new_address)), 16) |
| 126 | |
| 127 | time.sleep(1) |
| 128 | self.link.close() |
| 129 | time.sleep(0.2) |
| 130 | self.link = cflib.crtp.get_link_driver( |
| 131 | 'radio://0/0/2M/{:X}'.format(addr)) |
| 132 | |
| 133 | return True |
| 134 | else: |
| 135 | return False |
| 136 | |
| 137 | def reset_to_bootloader1(self, cpu_id): |
| 138 | """ Reset to the bootloader |
no test coverage detected