mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-20 22:55:00 +08:00
Update discovery.py
fixd
This commit is contained in:
committed by
Samuel Sadok
parent
f7eadfeb3b
commit
4fc9f7e3fe
@@ -71,49 +71,50 @@ def find_all(path, serial_number,
|
||||
temp_dir = tempfile.gettempdir()
|
||||
|
||||
cache_miss = True
|
||||
json_crc16 = 0
|
||||
|
||||
# Fetching the json crc to check cache
|
||||
try:
|
||||
json_crc16 = channel.remote_endpoint_operation(0, struct.pack("<I", 0xffffffff), True, 2)
|
||||
json_crc16 = struct.unpack("<H", json_crc16)[0]
|
||||
logger.debug("Device JSON checksum: 0x{:02X} 0x{:02X}".format(json_crc16 & 0xff, (json_crc16 >> 8) & 0xff))
|
||||
|
||||
cache_path = temp_dir + '/fibre_schema_cache_' + str(json_crc16)
|
||||
|
||||
try:
|
||||
json_cache = open(cache_path, 'r+')
|
||||
logger.debug("Found cache file with crc")
|
||||
cache_miss = False
|
||||
|
||||
except:
|
||||
logger.debug("Cache miss, there is no cache file")
|
||||
cache_miss = True
|
||||
|
||||
# Download the JSON data
|
||||
if(cache_miss == True):
|
||||
try:
|
||||
logger.debug("Getting json schema from USB... this is slow...")
|
||||
json_bytes = channel.remote_endpoint_read_buffer(0)
|
||||
json_cache = open(cache_path, 'w+')
|
||||
json_cache.write(json_bytes.decode("ascii"))
|
||||
logger.debug("saved json_bytes to file")
|
||||
|
||||
except (TimeoutError, ChannelBrokenException):
|
||||
logger.debug("no response - probably incompatible")
|
||||
return
|
||||
else:
|
||||
try:
|
||||
json_bytes = json_cache.read().encode("ascii")
|
||||
logger.debug("loaded json_bytes from " + cache_path)
|
||||
|
||||
except (TimeoutError, ChannelBrokenException):
|
||||
logger.debug("could not read cache file")
|
||||
return
|
||||
|
||||
except Exception as error:
|
||||
logger.debug("Error fetching JSON CRC, falling back to downloading full JSON")
|
||||
#logger.debug(traceback.format_exc())
|
||||
|
||||
cache_path = temp_dir + '/fibre_schema_cache_' + str(json_crc16)
|
||||
|
||||
try:
|
||||
json_cache = open(cache_path, 'r+')
|
||||
logger.debug("Found cache file with crc")
|
||||
cache_miss = False
|
||||
except:
|
||||
logger.debug("Cache miss, there is no cache file")
|
||||
cache_miss = True
|
||||
|
||||
if (cache_miss):
|
||||
# Download the JSON data
|
||||
try:
|
||||
logger.debug("Getting json schema from USB... this is slow...")
|
||||
json_bytes = channel.remote_endpoint_read_buffer(0)
|
||||
json_cache = open(cache_path, 'w+')
|
||||
json_cache.write(json_bytes.decode("ascii"))
|
||||
logger.debug("saved json_bytes to file")
|
||||
|
||||
except (TimeoutError, ChannelBrokenException):
|
||||
logger.debug("no response - probably incompatible")
|
||||
return
|
||||
else:
|
||||
try:
|
||||
json_bytes = json_cache.read().encode("ascii")
|
||||
logger.debug("loaded json_bytes from " + cache_path)
|
||||
|
||||
except (TimeoutError, ChannelBrokenException):
|
||||
logger.debug("could not read cache file")
|
||||
return
|
||||
|
||||
json_crc16 = fibre.protocol.calc_crc16(fibre.protocol.PROTOCOL_VERSION, json_bytes)
|
||||
logger.debug("Getting json schema from USB... this is slow...")
|
||||
json_bytes = channel.remote_endpoint_read_buffer(0)
|
||||
json_crc16 = fibre.protocol.calc_crc16(fibre.protocol.PROTOCOL_VERSION, json_bytes)
|
||||
|
||||
channel._interface_definition_crc = json_crc16
|
||||
|
||||
|
||||
Reference in New Issue
Block a user