Skip to content

Commit f047529

Browse files
robertsipkayichoi
authored andcommitted
Support more debugger protocol in IoT.js (#1876)
Adding new options to select serial protocol and rawpacket communcation channel. IoT.js-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
1 parent 7a6bb83 commit f047529

File tree

4 files changed

+115
-4
lines changed

4 files changed

+115
-4
lines changed

docs/devs/Use-JerryScript-Debugger.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,26 @@ The file argument is ignored in this case, therefore doesn't need to be specifie
2323
thus, there's no need to restart the environment if the remote source is changed.
2424
**Important note**: Remote sources must be sent in correct order! IoT.js compiles them in the order they are received, so file(s) used with `require` should be sent first, and the file(s) using them after.
2525

26+
#### Select Channel and Protocol
27+
28+
There are two available extension-provided channels, websocket and rawpacket, and two protocols, tcp and serial. Each initializes the debugger and blocks until a client connects. If you want to specify the debugger channel (default: websocket) or protocol (default: tcp) over the communication you can do with the `--debug-channel [websocket|rawpacket]` and `--debug-protocol [tcp|serial]` options:
29+
30+
`<iotjs binary> --start-debug-server --debugger-channel rawpacket --debug-protocol tcp test.js`
31+
2632
#### Setting the debugger port
2733

28-
If you want to specify the port number of the debugger-server (default: 5001),
34+
If you want to specify the port number of the debugger-server with tcp connection (default: 5001),
2935
you can do so with the `--debugger-port <PORT>` option:
36+
3037
`<iotjs binary> --start-debug-server --debugger-port 8080 test.js`
3138

39+
#### Configure the serial port
40+
41+
If you want to configure parameters for serial port (default: /dev/ttyS0,115200,8,N,1), you can do with `--debug-serial-config CONFIG` option:
42+
43+
`<iotjs binary> --start-debug-server --debug-channel rawpacket --debug-protocol serial --debug-serial-config "/dev/ttyUSB0,115200,8,N,1" test.js`
44+
45+
3246
#### Available Clients
3347

3448
* [JerryScript console debugger client](https://github.com/pando-project/jerryscript/blob/master/jerry-debugger/jerry-client-ws.py)

src/iotjs.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,27 @@ static bool jerry_initialize(iotjs_environment_t* env) {
5757

5858
#ifdef JERRY_DEBUGGER
5959
if (iotjs_environment_config(env)->debugger != NULL) {
60-
uint16_t port = iotjs_environment_config(env)->debugger->port;
61-
jerryx_debugger_after_connect(jerryx_debugger_tcp_create(port) &&
62-
jerryx_debugger_ws_create());
60+
bool protocol_created = false;
61+
char* debug_protocol = iotjs_environment_config(env)->debugger->protocol;
62+
char* debug_channel = iotjs_environment_config(env)->debugger->channel;
63+
64+
if (!strcmp(debug_protocol, "tcp")) {
65+
uint16_t port = iotjs_environment_config(env)->debugger->port;
66+
protocol_created = jerryx_debugger_tcp_create(port);
67+
} else {
68+
IOTJS_ASSERT(!strcmp(debug_protocol, "serial"));
69+
char* config = iotjs_environment_config(env)->debugger->serial_config;
70+
protocol_created = jerryx_debugger_serial_create(config);
71+
}
72+
73+
if (!strcmp(debug_channel, "rawpacket")) {
74+
jerryx_debugger_after_connect(protocol_created &&
75+
jerryx_debugger_rp_create());
76+
} else {
77+
IOTJS_ASSERT(!strcmp(debug_channel, "websocket"));
78+
jerryx_debugger_after_connect(protocol_created &&
79+
jerryx_debugger_ws_create());
80+
}
6381

6482
if (!jerry_debugger_is_connected()) {
6583
DLOG("jerry debugger connection failed");

src/iotjs_env.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ typedef enum {
2828
OPT_DEBUG_SERVER,
2929
OPT_DEBUGGER_WAIT_SOURCE,
3030
OPT_DEBUG_PORT,
31+
OPT_DEBUG_CHANNEL,
32+
OPT_DEBUG_PROTOCOL,
33+
OPT_DEBUG_SERIAL_CONFIG,
3134
#endif
3235
NUM_OF_OPTIONS
3336
} cli_option_id_t;
@@ -133,6 +136,24 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env,
133136
.more = 1,
134137
.help = "debug server port (default: 5001)",
135138
},
139+
{
140+
.id = OPT_DEBUG_CHANNEL,
141+
.longopt = "debug-channel",
142+
.help = "specify the debugger transmission channel"
143+
" (default: websocket)",
144+
},
145+
{
146+
.id = OPT_DEBUG_PROTOCOL,
147+
.longopt = "debug-protocol",
148+
.help = "Specify the transmission protocol over the communication"
149+
" channel (default: tcp)",
150+
},
151+
{
152+
.id = OPT_DEBUG_SERIAL_CONFIG,
153+
.longopt = "debug-serial-config",
154+
.help = "configure parameters for serial port"
155+
" (default: /dev/ttyS0,115200,8,N,1)",
156+
},
136157
#endif
137158
};
138159

@@ -187,12 +208,67 @@ bool iotjs_environment_parse_command_line_arguments(iotjs_environment_t* env,
187208
env->config.debugger->context_reset = false;
188209
env->config.debugger->wait_source =
189210
cur_opt->id == OPT_DEBUGGER_WAIT_SOURCE;
211+
char default_channel[] = "websocket";
212+
char default_protocol[] = "tcp";
213+
char default_serial_config[] = "/dev/ttyS0,115200,8,N,1";
214+
memcpy(env->config.debugger->channel, default_channel,
215+
strlen(default_channel) + 1);
216+
memcpy(env->config.debugger->protocol, default_protocol,
217+
strlen(default_protocol) + 1);
218+
memcpy(env->config.debugger->serial_config, default_serial_config,
219+
strlen(default_serial_config) + 1);
190220
} break;
191221
case OPT_DEBUG_PORT: {
192222
if (env->config.debugger) {
193223
char* pos = NULL;
194224
env->config.debugger->port = (uint16_t)strtoul(argv[i + 1], &pos, 10);
195225
}
226+
i++;
227+
} break;
228+
case OPT_DEBUG_CHANNEL: {
229+
if (env->config.debugger) {
230+
memset(env->config.debugger->channel, 0,
231+
strlen(env->config.debugger->channel) + 1);
232+
memcpy(env->config.debugger->channel, argv[i + 1],
233+
strlen(argv[i + 1]) + 1);
234+
235+
if (strcmp(env->config.debugger->channel, "websocket") &&
236+
strcmp(env->config.debugger->channel, "rawpacket")) {
237+
fprintf(stderr,
238+
"Debug channel %s is not supported."
239+
" Only websocket or rawpacket is allowed\n",
240+
env->config.debugger->channel);
241+
return false;
242+
}
243+
}
244+
i++;
245+
} break;
246+
case OPT_DEBUG_PROTOCOL: {
247+
if (env->config.debugger) {
248+
memset(env->config.debugger->protocol, 0,
249+
strlen(env->config.debugger->protocol) + 1);
250+
memcpy(env->config.debugger->protocol, argv[i + 1],
251+
strlen(argv[i + 1]) + 1);
252+
253+
if (strcmp(env->config.debugger->protocol, "tcp") &&
254+
strcmp(env->config.debugger->protocol, "serial")) {
255+
fprintf(stderr,
256+
"Debug protocol %s is not supported."
257+
" Only tcp or serial is allowed\n",
258+
env->config.debugger->protocol);
259+
return false;
260+
}
261+
}
262+
i++;
263+
} break;
264+
case OPT_DEBUG_SERIAL_CONFIG: {
265+
if (env->config.debugger) {
266+
memset(env->config.debugger->serial_config, 0,
267+
strlen(env->config.debugger->serial_config) + 1);
268+
memcpy(env->config.debugger->serial_config, argv[i + 1],
269+
strlen(argv[i + 1]) + 1);
270+
}
271+
i++;
196272
} break;
197273
#endif
198274
default:

src/iotjs_env.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ typedef struct {
2323
bool wait_source;
2424
bool context_reset;
2525
uint16_t port;
26+
char channel[16];
27+
char protocol[16];
28+
char serial_config[64];
2629
} DebuggerConfig;
2730
#endif
2831

0 commit comments

Comments
 (0)