Skip to content

Commit f1dc8d2

Browse files
committed
add debugging
1 parent fd1ffad commit f1dc8d2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

meshtastic/mesh_interface.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,13 @@ def upload_file(
794794
overwrite: bool = False,
795795
timeout: int = 120,
796796
) -> str:
797+
logger.debug(
798+
"upload_file host_src=%s device_dst=%s overwrite=%s timeout=%s",
799+
host_src,
800+
device_dst,
801+
overwrite,
802+
timeout,
803+
)
797804
host_path = Path(host_src).expanduser()
798805
if not host_path.is_file():
799806
raise MeshInterface.MeshInterfaceError(
@@ -803,6 +810,7 @@ def upload_file(
803810
dest_str = device_dst if device_dst is not None else "/"
804811
if dest_str in ("", "."):
805812
dest_str = "/"
813+
logger.debug("upload_file normalized dest_str='%s'", dest_str)
806814

807815
if dest_str.endswith("/"):
808816
remote_path = PurePosixPath(dest_str) / host_path.name
@@ -815,24 +823,28 @@ def upload_file(
815823
remote_path = PurePosixPath("/") / remote_path
816824

817825
remote_path_str = str(remote_path)
826+
logger.debug("upload_file computed remote_path='%s'", remote_path_str)
818827

819828
if not overwrite and remote_path_str in self.filesystem_entries:
820829
raise MeshInterface.MeshInterfaceError(
821830
f"Remote file '{remote_path_str}' already exists (use overwrite=True to replace it)."
822831
)
823832

824833
if overwrite:
834+
logger.debug("upload_file overwrite=True; deleting existing '%s'", remote_path_str)
825835
self._delete_remote_file(remote_path_str)
826836

827837
transfer_event = threading.Event()
828838
file_handle = open(host_path, "rb")
839+
logger.debug("upload_file opened host file '%s'", host_path)
829840

830841
with self._xmodem_lock:
831842
if self._xmodem_state and not self._xmodem_state.get("done"):
832843
file_handle.close()
833844
raise MeshInterface.MeshInterfaceError(
834845
"Another XMODEM transfer is already in progress."
835846
)
847+
logger.debug("upload_file acquired xmodem slot for '%s'", remote_path_str)
836848
self._xmodem_state = {
837849
"mode": "upload",
838850
"file": file_handle,
@@ -857,6 +869,7 @@ def upload_file(
857869
start_payload = remote_path_str.encode("utf-8")
858870
if not start_payload.endswith(b"\x00"):
859871
start_payload += b"\x00"
872+
logger.debug("upload_file sending start control packet")
860873

861874
try:
862875
self._sendXmodemControl(
@@ -866,6 +879,7 @@ def upload_file(
866879
self._crc16_ccitt(start_payload),
867880
)
868881
except Exception as ex:
882+
logger.debug("upload_file start failed: %s", ex)
869883
with self._xmodem_lock:
870884
self._complete_xmodem_locked(False, f"Failed to start XMODEM transfer: {ex}")
871885
cleanup_target = self._cleanup_xmodem_state_locked(remove_partial=True)
@@ -874,6 +888,7 @@ def upload_file(
874888
raise
875889

876890
if not transfer_event.wait(timeout):
891+
logger.debug("upload_file timed out after %s seconds; cancelling", timeout)
877892
with self._xmodem_lock:
878893
try:
879894
self._sendXmodemControl(xmodem_pb2.XModem.Control.CAN)
@@ -905,11 +920,18 @@ def upload_file(
905920
self._delete_remote_file(cleanup_target)
906921

907922
if not success:
923+
logger.debug("upload_file failed for '%s': %s", remote_path_str, error_message)
908924
raise MeshInterface.MeshInterfaceError(
909925
error_message or "XMODEM transfer failed."
910926
)
911927

912928
self.filesystem_entries[remote_path_str] = host_path.stat().st_size
929+
logger.debug(
930+
"upload_file completed %s -> %s (%s bytes)",
931+
host_path,
932+
remote_path_str,
933+
self.filesystem_entries[remote_path_str],
934+
)
913935
return remote_path_str
914936

915937
def getNode(

0 commit comments

Comments
 (0)