Skip to content

Commit 6e34cfb

Browse files
author
Bence Gabor Kis
committed
Support Bluetooth communcation JerryScript debugger
Documentation can be found in 07.DEBUGGER.md JerryScript-DCO-1.0-Signed-off-by: Bence Gabor Kis [email protected]
1 parent f02de7a commit 6e34cfb

File tree

9 files changed

+366
-17
lines changed

9 files changed

+366
-17
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ matrix:
1414
- name: "Checks"
1515
env:
1616
- OPTS="--check-signed-off=travis --check-cppcheck --check-doxygen --check-vera --check-license --check-magic-strings --check-pylint"
17-
install: pip install --user pylint==1.6.5
17+
install:
18+
- pip install --user pylint==1.6.5
19+
- pip install --user pybluez
1820
addons:
1921
apt:
20-
packages: [doxygen, cppcheck, vera++]
22+
packages: [doxygen, cppcheck, vera++, libbluetooth-dev, python-dev]
2123

2224
- name: "Linux/x86-64 Build & Correctness Tests"
2325
env:

docs/07.DEBUGGER.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This simple application demonstrates the communication protocol
99
between the client and server, and can be reused by integrated
1010
development environments.
1111

12-
## Setting up the debugger server
12+
## Setting up TCP/IP debugger server
1313

1414
The following arguments must be passed to `tools/build.py`:
1515

@@ -21,7 +21,23 @@ JerryScript extension, which transmits messages over TCP/IP networks.
2121
If necessary/implemented, any reliable stream or datagram based
2222
protocol can be used for transmitting debugger messages.
2323

24-
## Debugging JavaScript applications
24+
## Setting up Bluetooth debugger server
25+
26+
The following arguments must be passed to `tools/build.py`:
27+
28+
`--jerry-bt-debugger=on`
29+
30+
The transport layer of the communication protocol is pluggable.
31+
At the moment, a WebSocket-based implementation is provided as a
32+
JerryScript extension, which transmits messages over Bluetooth network.
33+
34+
The following library is needed to build JerryScript
35+
- libbluetooth-dev
36+
37+
The following python commands needed to run jerry-client.py
38+
- sudo apt-get install -q python-dev
39+
- pip install --user pylint==1.6.5 pybluez
40+
2541

2642
The debugger client must be connected to the server before the
2743
JavaScript application runs. On-the-fly attachment is supported
@@ -43,6 +59,12 @@ source code:
4359

4460
`--debugger-wait-source`
4561

62+
The following argument makes JerryScript create a server with
63+
the given type. There are two choices, tcp or bluetooth.
64+
(default: tcp)
65+
66+
`--server-type bluetooth`
67+
4668
It is also recommended to increase the log level to see
4769
the *Waiting for client connection* message:
4870

jerry-debugger/jerry_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
from cmd import Cmd
1919
from pprint import pprint
2020
import math
21-
import socket
2221
import sys
2322
import logging
2423
import time
24+
import re
2525
import jerry_client_ws
2626

2727
def write(string):
@@ -291,8 +291,14 @@ def main():
291291
if __name__ == "__main__":
292292
try:
293293
main()
294-
except socket.error as error_msg:
294+
except IOError as error_msg:
295295
ERRNO = error_msg.errno
296+
if not ERRNO:
297+
# if there is no ERRNO then try to get it from the error arguments
298+
MATCH = re.search(r"(\d+)", error_msg.args[0])
299+
if MATCH:
300+
ERRNO = int(MATCH.group(1))
301+
296302
MSG = str(error_msg)
297303
if ERRNO == 111:
298304
sys.exit("Failed to connect to the JerryScript debugger.")

jerry-debugger/jerry_client_ws.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,24 @@ def get_text(self):
266266

267267

268268
class JerryDebugger(object):
269-
# pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use
269+
# pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use,too-many-branches
270270
def __init__(self, address):
271-
271+
temp = address.split(":")
272272
if ":" not in address:
273273
self.host = address
274274
self.port = 5001 # use default port
275+
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
276+
elif len(temp) == 2:
277+
self.host = temp[0]
278+
self.port = int(temp[1])
279+
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
280+
elif len(temp) == 6:
281+
import bluetooth
282+
self.host = address
283+
self.port = 1 # use default port
284+
self.client_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
275285
else:
276-
self.host, self.port = address.split(":")
277-
self.port = int(self.port)
286+
raise Exception("Wrong address type")
278287

279288
print("Connecting to: %s:%s" % (self.host, self.port))
280289

@@ -303,7 +312,6 @@ def __init__(self, address):
303312
self.nocolor = ''
304313
self.src_offset = 0
305314
self.src_offset_diff = 0
306-
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
307315
self.client_socket.connect((self.host, self.port))
308316
self.non_interactive = False
309317
self.current_out = b""
@@ -385,7 +393,11 @@ def __init__(self, address):
385393
self.message_data = result[len_expected:]
386394

387395
def __del__(self):
388-
self.client_socket.close()
396+
try:
397+
self.client_socket.close()
398+
except AttributeError:
399+
pass
400+
389401

390402
def _exec_command(self, command_id):
391403
self.send_command(command_id)

jerry-ext/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ project (${JERRY_EXT_NAME} C)
1818

1919
# Optional features
2020
set(FEATURE_INIT_FINI OFF CACHE BOOL "Enable init/fini arrays?")
21+
set(FEATURE_BT_DEBUGGER OFF CACHE BOOL "Enable JerryScript bluetooth?")
22+
2123

2224
# Status messages
2325
message(STATUS "FEATURE_INIT_FINI " ${FEATURE_INIT_FINI})
26+
message(STATUS "FEATURE_BT_DEBUGGER " ${FEATURE_BT_DEBUGGER})
27+
2428

2529
# Include directories
2630
set(INCLUDE_EXT_PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
@@ -32,6 +36,10 @@ if(FEATURE_INIT_FINI)
3236
set(DEFINES_EXT ${DEFINES_EXT} ENABLE_INIT_FINI)
3337
endif()
3438

39+
if(FEATURE_BT_DEBUGGER AND FEATURE_DEBUGGER)
40+
set(DEFINES_EXT ${DEFINES_EXT} JERRY_BT_DEBUGGER)
41+
endif()
42+
3543
# Source directories
3644
file(GLOB SOURCE_EXT
3745
arg/*.c
@@ -49,3 +57,7 @@ target_link_libraries(${JERRY_EXT_NAME} jerry-core)
4957

5058
install(TARGETS ${JERRY_EXT_NAME} DESTINATION lib)
5159
install(DIRECTORY ${INCLUDE_EXT_PUBLIC}/ DESTINATION include)
60+
61+
if(FEATURE_BT_DEBUGGER)
62+
target_link_libraries(${JERRY_EXT_NAME} -lbluetooth)
63+
endif()

0 commit comments

Comments
 (0)