Skip to content

Commit

Permalink
fix connection trough tunnel (#36). (#37)
Browse files Browse the repository at this point in the history
* fix connection trough tunnel (#36).

* move 'open' tunnel to a dedicated method.

* update test statement.
  • Loading branch information
Sauci authored and hkpeprah committed Jul 19, 2018
1 parent b1abd79 commit ae21abd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pylink/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def open(self, serial_no=None, ip_addr=None):
self.close()

if ip_addr is not None:
addr, port = ip_addr.split(':')
addr, port = ip_addr.rsplit(':', 1)
if serial_no is None:
result = self._dll.JLINKARM_SelectIP(addr.encode(), int(port))
if result == 1:
Expand Down Expand Up @@ -590,6 +590,19 @@ def open(self, serial_no=None, ip_addr=None):

return None

def open_tunnel(self, serial_no, port=19020):
"""Connects to the J-Link emulator (over SEGGER tunnel).
Args:
self (JLink): the ``JLink`` instance
serial_no (int): serial number of the J-Link
port (int): optional port number (default to 19020).
Returns:
``None``
"""
return self.open(ip_addr='tunnel:' + str(serial_no) + ':' + str(port))

def close(self):
"""Closes the open J-Link.
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,24 @@ def test_jlink_open_ethernet_and_serial_number(self):
self.assertEqual(0, self.dll.JLINKARM_EMU_SelectIP.call_count)
self.assertEqual(1, self.dll.JLINKARM_EMU_SelectIPBySN.call_count)

def test_jlink_open_tunnel(self):
"""Tests the J-Link ``open_tunnel()`` method over tunnel succeeding
with default port value.
Args:
self (TestJLink): the ``TestJLink`` instance
Returns:
``None``
"""
self.dll.JLNKARM_SelectIP.return_value = 0
self.dll.JLINKARM_OpenEx.return_value = 0
self.dll.JLINKARM_GetSN.return_value = 123456789

self.jlink.open_tunnel(serial_no=123456789)

self.dll.JLINKARM_SelectIP.assert_called_once_with('tunnel:123456789'.encode(), 19020)

def test_jlink_open_serial_number_failed(self):
"""Tests the J-Link ``open()`` method over USB by serial number, but
failing.
Expand Down

0 comments on commit ae21abd

Please sign in to comment.