mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
linux support test
This commit is contained in:
parent
baf9f26a6d
commit
77ce067841
@ -26,9 +26,13 @@ import sys
|
||||
# BOLD = '\033[1m'
|
||||
# UNDERLINE = '\033[4m'
|
||||
|
||||
if os.name == 'nt':
|
||||
openocd_exec = "openocd.exe"
|
||||
else:
|
||||
openocd_exec = "openocd"
|
||||
|
||||
default_openocd_host = '127.0.0.1'
|
||||
openocd_exec_path = os.path.join("openocd", "bin", "openocd.exe")
|
||||
openocd_exec_path = os.path.join("openocd", "bin", openocd_exec)
|
||||
openocd_scripts_path = os.path.join("openocd", "share", "openocd", "scripts")
|
||||
openocd_interface_path = os.path.join("interface", "ftdi", "m-link.cfg")
|
||||
openocd_target_path = os.path.join("target", "mik32.cfg")
|
||||
@ -129,12 +133,15 @@ def run_openocd(
|
||||
cmd = [openocd_exec, "-s", openocd_scripts,
|
||||
"-f", openocd_interface, "-f", openocd_target]
|
||||
|
||||
creation_flags = subprocess.SW_HIDE
|
||||
if is_open_console:
|
||||
creation_flags |= subprocess.CREATE_NEW_CONSOLE
|
||||
if os.name == 'nt':
|
||||
creation_flags = subprocess.SW_HIDE
|
||||
if is_open_console:
|
||||
creation_flags |= subprocess.CREATE_NEW_CONSOLE
|
||||
|
||||
proc = subprocess.Popen(
|
||||
cmd, creationflags=creation_flags)
|
||||
proc = subprocess.Popen(
|
||||
cmd, creationflags=creation_flags)
|
||||
else:
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
|
||||
return proc
|
||||
|
||||
@ -226,7 +233,10 @@ def upload_file(
|
||||
except OSError as e:
|
||||
raise OpenOCDStartupException(e)
|
||||
try:
|
||||
# time.sleep(0.1)
|
||||
|
||||
with OpenOcdTclRpc(host, port) as openocd:
|
||||
print('try beginning')
|
||||
if (all(openocd_interface.find(i) == -1 for i in adapter_speed_not_supported)):
|
||||
openocd.run(f"adapter speed {adapter_speed}")
|
||||
openocd.run(f"log_output \"{log_path}\"")
|
||||
|
||||
19
tclrpc.py
19
tclrpc.py
@ -1,6 +1,7 @@
|
||||
import re
|
||||
import socket
|
||||
from logging import getLogger
|
||||
import time
|
||||
from typing import List
|
||||
logger = getLogger(__name__)
|
||||
|
||||
@ -52,9 +53,11 @@ class OpenOcdTclRpc:
|
||||
|
||||
def __enter__(self):
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.settimeout(5.0)
|
||||
try:
|
||||
self.sock.connect((self.host, self.port))
|
||||
# self.sock.connect((self.host, self.port))
|
||||
self.wait_for_port()
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
except socket.timeout:
|
||||
logger.debug("Test connection timed out, try again")
|
||||
self.sock.close()
|
||||
@ -88,6 +91,18 @@ class OpenOcdTclRpc:
|
||||
raise Exception('Unhandled extra bytes after %r'.format(self.SEPARATOR_BYTES))
|
||||
return data[:-1]
|
||||
|
||||
def wait_for_port(self, timeout: float = 5.0):
|
||||
sock = None
|
||||
start_time = time.perf_counter()
|
||||
while time.perf_counter() - start_time < timeout:
|
||||
try:
|
||||
sock = self.sock.connect((self.host, self.port))
|
||||
break
|
||||
except OSError as ex:
|
||||
time.sleep(0.01)
|
||||
if sock != None:
|
||||
self.sock = sock
|
||||
|
||||
def run(self, cmd):
|
||||
"""Run a command and raise an error if it returns an error"""
|
||||
wrap = 'set _code [catch {%s} _msg];expr {"$_code $_msg"}' % tcl_quote_cmd(cmd)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user