mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
implement retry connection if timeout
This commit is contained in:
parent
5091d411c5
commit
51cd0c845a
@ -1,5 +1,6 @@
|
|||||||
import shlex
|
import shlex
|
||||||
import argparse
|
import argparse
|
||||||
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@ -39,7 +40,12 @@ supported_text_formats = [".hex"]
|
|||||||
def test_connection():
|
def test_connection():
|
||||||
output = ""
|
output = ""
|
||||||
with OpenOcdTclRpc() as openocd:
|
with OpenOcdTclRpc() as openocd:
|
||||||
output = openocd.run("capture \"reg\"")
|
try:
|
||||||
|
output = openocd.run("capture \"reg\"")
|
||||||
|
except OSError:
|
||||||
|
logging.debug("Test connection timed out, try again")
|
||||||
|
output = openocd.run("capture \"reg\"")
|
||||||
|
|
||||||
|
|
||||||
if output == "":
|
if output == "":
|
||||||
raise Exception("ERROR: no regs found, check MCU connection")
|
raise Exception("ERROR: no regs found, check MCU connection")
|
||||||
@ -320,10 +326,6 @@ def upload_file(
|
|||||||
raise OpenOCDStartupException(e)
|
raise OpenOCDStartupException(e)
|
||||||
try:
|
try:
|
||||||
with OpenOcdTclRpc(host, port) as openocd:
|
with OpenOcdTclRpc(host, port) as openocd:
|
||||||
test_connection()
|
|
||||||
|
|
||||||
logging.debug("OpenOCD connection tested!")
|
|
||||||
|
|
||||||
if (all(openocd_interface.find(i) == -1 for i in adapter_speed_not_supported)):
|
if (all(openocd_interface.find(i) == -1 for i in adapter_speed_not_supported)):
|
||||||
openocd.run(f"adapter speed {adapter_speed}")
|
openocd.run(f"adapter speed {adapter_speed}")
|
||||||
openocd.run(f"log_output \"{log_path}\"")
|
openocd.run(f"log_output \"{log_path}\"")
|
||||||
@ -490,7 +492,7 @@ def createParser():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
|
||||||
|
|
||||||
parser = createParser()
|
parser = createParser()
|
||||||
namespace = parser.parse_args()
|
namespace = parser.parse_args()
|
||||||
|
|||||||
11
tclrpc.py
11
tclrpc.py
@ -51,8 +51,15 @@ class OpenOcdTclRpc:
|
|||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.sock.settimeout(10.0)
|
self.sock.settimeout(5.0)
|
||||||
self.sock.connect((self.host, self.port))
|
try:
|
||||||
|
self.sock.connect((self.host, self.port))
|
||||||
|
except socket.timeout:
|
||||||
|
logger.debug("Test connection timed out, try again")
|
||||||
|
self.sock.close()
|
||||||
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.sock.settimeout(5.0)
|
||||||
|
self.sock.connect((self.host, self.port))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user