def ping_check(self): # check connection is working assert self.dev.session_key, 'not encrypted?' req = b'1234 Electrum Plugin 4321' # free up to 59 bytes try: echo = self.dev.send_recv(CCProtocolPacker.ping(req)) assert echo == req except: raise RuntimeError("Communication trouble with Coldcard")
def usb_test(single): """Test USB connection (debug/dev)""" with get_device() as dev: rng = [] rng.extend(range(55, 66)) # buggy lengths are around 64 rng.extend(range(1013, 1024)) # we have 4 bytes of overhead (args) for ping cmd, so this will be max-length rng.extend(range(MAX_MSG_LEN - 10, MAX_MSG_LEN - 4)) #print(repr(rng)) for i in rng: print("Ping with length: %d" % i, end='') body = os.urandom(i) if single is None else bytes([single] * i) rb = dev.send_recv(CCProtocolPacker.ping(body)) assert rb == body, "Fail @ len: %d, got back %d bytes\n%r !=\n%r" % ( i, len(rb), b2a_hex(body), b2a_hex(rb)) print(" Okay")