From a5a84c429ac548eafd1d3903225a4ce72104201f Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周三, 22 4月 2015 03:50:26 +0800 Subject: [PATCH] Support RESPONSE MESSAGE UNIT SEPARATOR, issue #21 --- libscpi/src/parser.c | 24 +++++++++++++++++++++--- libscpi/test/test_parser.c | 10 ++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index ad7ebc4..4b73e3c 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -99,12 +99,28 @@ } /** + * Conditionaly write ";" + * @param context + * @return number of characters written + */ +static size_t writeSemicolon(scpi_t * context) { + if (context->output_count > 0) { + return writeData(context, ";", 1); + } else { + return 0; + } +} + +/** * Process command * @param context */ static void processCommand(scpi_t * context) { const scpi_command_t * cmd = context->param_list.cmd; lex_state_t * state = &context->param_list.lex_state; + + /* conditionaly write ; */ + writeSemicolon(context); context->cmd_error = FALSE; context->output_count = 0; @@ -117,9 +133,6 @@ SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); } } - - /* conditionaly write new line */ - writeNewLine(context); /* set error if command callback did not read all parameters */ if (state->pos < (state->buffer + state->len) && !context->cmd_error) { @@ -164,6 +177,7 @@ } state = &context->parser_state; + context->output_count = 0; while (1) { result = 0; @@ -202,6 +216,10 @@ } } + + /* conditionaly write new line */ + writeNewLine(context); + return result; } diff --git a/libscpi/test/test_parser.c b/libscpi/test/test_parser.c index 1df24e8..76a4053 100644 --- a/libscpi/test/test_parser.c +++ b/libscpi/test/test_parser.c @@ -200,6 +200,12 @@ TEST_INPUT("*IDN?\r\n*IDN?\r\n*IDN?\r\n*IDN?\r\n", "MA,IN,0,VER\r\nMA,IN,0,VER\r\nMA,IN,0,VER\r\nMA,IN,0,VER\r\n"); output_buffer_clear(); + TEST_INPUT("*IDN?;*IDN?;*IDN?;*IDN?\r\n", "MA,IN,0,VER;MA,IN,0,VER;MA,IN,0,VER;MA,IN,0,VER\r\n"); + output_buffer_clear(); + + TEST_INPUT("*IDN?;*OPC;*IDN?\r\n", "MA,IN,0,VER;MA,IN,0,VER\r\n"); + output_buffer_clear(); + /* Test one command in multiple buffers */ TEST_INPUT("*IDN?", ""); TEST_INPUT("\r\n", "MA,IN,0,VER\r\n"); @@ -211,10 +217,10 @@ output_buffer_clear(); /* Test ctree traversal */ - TEST_INPUT("TEST:TREEA?;TREEB?\r\n", "10\r\n20\r\n"); + TEST_INPUT("TEST:TREEA?;TREEB?\r\n", "10;20\r\n"); output_buffer_clear(); - TEST_INPUT("TEST:TREEA?;:TEXT? \"PARAM1\", \"PARAM2\"\r\n", "10\r\n\"PARAM2\"\r\n"); + TEST_INPUT("TEST:TREEA?;:TEXT? \"PARAM1\", \"PARAM2\"\r\n", "10;\"PARAM2\"\r\n"); output_buffer_clear(); CU_ASSERT_EQUAL(err_buffer_pos, 0); -- Gitblit v1.9.1