From 9b9bc8a81ad303ffb1e5eef12f34702b2aceef60 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周三, 22 4月 2015 03:52:29 +0800 Subject: [PATCH] Support RESPONSE MESSAGE UNIT SEPARATOR, issue #21 --- libscpi/src/parser.c | 26 +++++++++++++++++++++++--- libscpi/test/test_lib.c | 13 +++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index 49080ff..f437018 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -192,6 +192,19 @@ } /** + * 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 */ @@ -199,6 +212,10 @@ const scpi_command_t * cmd = context->paramlist.cmd; context->cmd_error = FALSE; + + /* conditionaly write ; */ + writeSemicolon(context); + context->output_count = 0; context->input_count = 0; @@ -209,9 +226,6 @@ SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); } } - - /* conditionaly write new line */ - writeNewLine(context); /* skip all whitespaces */ paramSkipWhitespace(context); @@ -266,6 +280,8 @@ return -1; } + context->output_count = 0; + while (cmdline_ptr < cmdline_end) { result = 0; cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr); @@ -285,6 +301,10 @@ cmdline_ptr += skipCmdLine(cmdline_ptr, cmdline_end - cmdline_ptr); cmdline_ptr += skipWhitespace(cmdline_ptr, cmdline_end - cmdline_ptr); } + + /* conditionaly write new line */ + writeNewLine(context); + return result; } diff --git a/libscpi/test/test_lib.c b/libscpi/test/test_lib.c index 186cecd..2834582 100644 --- a/libscpi/test/test_lib.c +++ b/libscpi/test/test_lib.c @@ -213,6 +213,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"); @@ -224,7 +230,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;\"PARAM2\"\r\n"); output_buffer_clear(); CU_ASSERT_EQUAL(err_buffer_pos, 0); @@ -279,7 +288,7 @@ TEST_IEEE4882("*SRE 0xFF\r\n", ""); TEST_IEEE4882("*SRE?\r\n", "255\r\n"); - TEST_IEEE4882("*STB?\r\n", "0\r\n"); + TEST_IEEE4882("*STB?\r\n", "0\r\n"); TEST_IEEE4882("*ESR?\r\n", "1\r\n"); srq_val = 0; -- Gitblit v1.9.1