master 0.2.0
Ondřej Hruška 9 years ago
parent 5766800a0a
commit 14c7ec1c04
  1. 2
      Makefile
  2. 13
      example/example.c
  3. 4
      source/scpi_parser.c

@ -34,7 +34,7 @@ CFLAGS += -fno-common -ffunction-sections -fdata-sections -Wunused-function
CFLAGS += -I$(INCL_DIR)
CFLAGS += -DSCPI_FINE_ERRORS
CFLAGS += -DSCPI_WEIRD_ERRORS
#CFLAGS += -DSCPI_WEIRD_ERRORS
###############################################################################

@ -35,6 +35,7 @@ int main(void)
// test chardata
send_cmd("CHARD FOOBAR123_MOO_abcdef_HELLO, 12\n");
send_cmd("SINGLE_STR_ARG \n");
send_cmd("SYST:ERR:ALL?\n");
}
@ -132,6 +133,13 @@ void cmd_ERROR_FALLBACK_cb(const SCPI_argval_t *args)
}
void cmd_SINGLE_STR_ARG_cb(const SCPI_argval_t *args)
{
(void) args;
printf("Single str arg = %s", args[0].STRING);
}
// Command definition (mandatory commands are built-in)
const SCPI_command_t scpi_commands[] = {
{
@ -159,6 +167,11 @@ const SCPI_command_t scpi_commands[] = {
.levels = {"ERROR_FALLBACK"},
.callback = cmd_ERROR_FALLBACK_cb
},
{
.levels = {"SINGLE_STR_ARG"},
.params = {SCPI_DT_STRING},
.callback = cmd_SINGLE_STR_ARG_cb
},
{
.levels = {"CHARData"},
.params = {SCPI_DT_CHARDATA, SCPI_DT_INT},

@ -791,12 +791,12 @@ static void pars_arg_eol_do(bool keep_levels)
{
int req_cnt = cmd_param_count(pst.matched_cmd);
if (pst.arg_i < req_cnt) {
if (pst.arg_i + (pst.charbuf_i ? 1 : 0) < req_cnt) {
// not the last arg yet - fail
if (pst.charbuf_i > 0) pst.arg_i++; // acknowledge the last arg
sprintf(ebuf, "Required %d, got %d.", req_cnt, pst.arg_i);
sprintf(ebuf, "Required %d arg, got %d.", req_cnt, pst.arg_i);
scpi_add_error(E_CMD_MISSING_PARAMETER, ebuf);
pst.state = PARS_DISCARD_LINE;

Loading…
Cancel
Save