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'
|
# BOLD = '\033[1m'
|
||||||
# UNDERLINE = '\033[4m'
|
# UNDERLINE = '\033[4m'
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
openocd_exec = "openocd.exe"
|
||||||
|
else:
|
||||||
|
openocd_exec = "openocd"
|
||||||
|
|
||||||
default_openocd_host = '127.0.0.1'
|
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_scripts_path = os.path.join("openocd", "share", "openocd", "scripts")
|
||||||
openocd_interface_path = os.path.join("interface", "ftdi", "m-link.cfg")
|
openocd_interface_path = os.path.join("interface", "ftdi", "m-link.cfg")
|
||||||
openocd_target_path = os.path.join("target", "mik32.cfg")
|
openocd_target_path = os.path.join("target", "mik32.cfg")
|
||||||
@ -129,12 +133,15 @@ def run_openocd(
|
|||||||
cmd = [openocd_exec, "-s", openocd_scripts,
|
cmd = [openocd_exec, "-s", openocd_scripts,
|
||||||
"-f", openocd_interface, "-f", openocd_target]
|
"-f", openocd_interface, "-f", openocd_target]
|
||||||
|
|
||||||
creation_flags = subprocess.SW_HIDE
|
if os.name == 'nt':
|
||||||
if is_open_console:
|
creation_flags = subprocess.SW_HIDE
|
||||||
creation_flags |= subprocess.CREATE_NEW_CONSOLE
|
if is_open_console:
|
||||||
|
creation_flags |= subprocess.CREATE_NEW_CONSOLE
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
cmd, creationflags=creation_flags)
|
cmd, creationflags=creation_flags)
|
||||||
|
else:
|
||||||
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
return proc
|
return proc
|
||||||
|
|
||||||
@ -226,7 +233,10 @@ def upload_file(
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise OpenOCDStartupException(e)
|
raise OpenOCDStartupException(e)
|
||||||
try:
|
try:
|
||||||
|
# time.sleep(0.1)
|
||||||
|
|
||||||
with OpenOcdTclRpc(host, port) as openocd:
|
with OpenOcdTclRpc(host, port) as openocd:
|
||||||
|
print('try beginning')
|
||||||
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}\"")
|
||||||
|
|||||||
19
tclrpc.py
19
tclrpc.py
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
import time
|
||||||
from typing import List
|
from typing import List
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
@ -52,9 +53,11 @@ 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(5.0)
|
|
||||||
try:
|
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:
|
except socket.timeout:
|
||||||
logger.debug("Test connection timed out, try again")
|
logger.debug("Test connection timed out, try again")
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
@ -88,6 +91,18 @@ class OpenOcdTclRpc:
|
|||||||
raise Exception('Unhandled extra bytes after %r'.format(self.SEPARATOR_BYTES))
|
raise Exception('Unhandled extra bytes after %r'.format(self.SEPARATOR_BYTES))
|
||||||
return data[:-1]
|
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):
|
def run(self, cmd):
|
||||||
"""Run a command and raise an error if it returns an error"""
|
"""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)
|
wrap = 'set _code [catch {%s} _msg];expr {"$_code $_msg"}' % tcl_quote_cmd(cmd)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user