Skip to content

Commit ae21abd

Browse files
Saucihkpeprah
authored andcommitted
fix connection trough tunnel (#36). (#37)
* fix connection trough tunnel (#36). * move 'open' tunnel to a dedicated method. * update test statement.
1 parent b1abd79 commit ae21abd

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pylink/jlink.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def open(self, serial_no=None, ip_addr=None):
544544
self.close()
545545

546546
if ip_addr is not None:
547-
addr, port = ip_addr.split(':')
547+
addr, port = ip_addr.rsplit(':', 1)
548548
if serial_no is None:
549549
result = self._dll.JLINKARM_SelectIP(addr.encode(), int(port))
550550
if result == 1:
@@ -590,6 +590,19 @@ def open(self, serial_no=None, ip_addr=None):
590590

591591
return None
592592

593+
def open_tunnel(self, serial_no, port=19020):
594+
"""Connects to the J-Link emulator (over SEGGER tunnel).
595+
596+
Args:
597+
self (JLink): the ``JLink`` instance
598+
serial_no (int): serial number of the J-Link
599+
port (int): optional port number (default to 19020).
600+
601+
Returns:
602+
``None``
603+
"""
604+
return self.open(ip_addr='tunnel:' + str(serial_no) + ':' + str(port))
605+
593606
def close(self):
594607
"""Closes the open J-Link.
595608

tests/unit/test_jlink.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,24 @@ def test_jlink_open_ethernet_and_serial_number(self):
610610
self.assertEqual(0, self.dll.JLINKARM_EMU_SelectIP.call_count)
611611
self.assertEqual(1, self.dll.JLINKARM_EMU_SelectIPBySN.call_count)
612612

613+
def test_jlink_open_tunnel(self):
614+
"""Tests the J-Link ``open_tunnel()`` method over tunnel succeeding
615+
with default port value.
616+
617+
Args:
618+
self (TestJLink): the ``TestJLink`` instance
619+
620+
Returns:
621+
``None``
622+
"""
623+
self.dll.JLNKARM_SelectIP.return_value = 0
624+
self.dll.JLINKARM_OpenEx.return_value = 0
625+
self.dll.JLINKARM_GetSN.return_value = 123456789
626+
627+
self.jlink.open_tunnel(serial_no=123456789)
628+
629+
self.dll.JLINKARM_SelectIP.assert_called_once_with('tunnel:123456789'.encode(), 19020)
630+
613631
def test_jlink_open_serial_number_failed(self):
614632
"""Tests the J-Link ``open()`` method over USB by serial number, but
615633
failing.

0 commit comments

Comments
 (0)