bugfixes, todo: blob, error queue, output buffer, state registers

master
Ondřej Hruška 9 years ago
parent 8bdeb99ac9
commit b7d0a63986
  1. 21
      main.c
  2. 17
      scpi_parser.c

@ -7,9 +7,10 @@ void cmd_aIDNq_cb(const SCPI_argval_t *args);
void cmd_APPL_SIN_cb(const SCPI_argval_t *args); void cmd_APPL_SIN_cb(const SCPI_argval_t *args);
void cmd_APPL_TRI_cb(const SCPI_argval_t *args); void cmd_APPL_TRI_cb(const SCPI_argval_t *args);
void cmd_FREQ_cb(const SCPI_argval_t *args); void cmd_FREQ_cb(const SCPI_argval_t *args);
void cmd_DISP_TEXT_cb(const SCPI_argval_t *args);
const uint16_t scpi_cmd_lang_len = 4; const uint16_t scpi_cmd_lang_len = 5;
const SCPI_command_t scpi_cmd_lang[4] = { const SCPI_command_t scpi_cmd_lang[5] = {
{ {
.level_cnt = 1, .levels = {"*IDN?"}, .level_cnt = 1, .levels = {"*IDN?"},
.param_cnt = 0, .params = {}, .param_cnt = 0, .params = {},
@ -30,6 +31,11 @@ const SCPI_command_t scpi_cmd_lang[4] = {
.param_cnt = 1, .params = {SCPI_DT_INT}, .param_cnt = 1, .params = {SCPI_DT_INT},
.callback = cmd_FREQ_cb .callback = cmd_FREQ_cb
}, },
{
.level_cnt = 2, .levels = {"DISPlay", "TEXT"},
.param_cnt = 2, .params = {SCPI_DT_STRING, SCPI_DT_BOOL},
.callback = cmd_DISP_TEXT_cb
},
}; };
@ -53,15 +59,20 @@ void cmd_APPL_TRI_cb(const SCPI_argval_t *args)
void cmd_FREQ_cb(const SCPI_argval_t *args) void cmd_FREQ_cb(const SCPI_argval_t *args)
{ {
printf("cb FREQuency\n"); printf("cb FREQuency %d\n", args[0].INT);
} }
void cmd_DISP_TEXT_cb(const SCPI_argval_t *args)
{
printf("cb DISPlay:TEXT %s, %d\n", args[0].STRING, args[1].BOOL);
}
int main() int main()
{ {
//const char *inp = "*IDN?\n"; // const char *inp = "*IDN?\n";
const char *inp = "FREQ 50\n"; // const char *inp = "FREQ 50\n";
const char *inp = "DISPlay:TEXT 'banana', OFF\nFUBAR moo fuck\r\nFREQ 50\r\n";
for(int i=0;i<strlen(inp); i++) { for(int i=0;i<strlen(inp); i++) {
scpi_handle_byte(inp[i]); scpi_handle_byte(inp[i]);

@ -249,7 +249,7 @@ void scpi_handle_byte(const uint8_t b)
} }
break; break;
// TODO more states // TODO more states
} }
} }
@ -272,7 +272,7 @@ static void pars_cmd_colon(void)
} else { } else {
// internal colon - partial match // internal colon - partial match
if (pars_match_cmd(true)) { if (pars_match_cmd(true)) {
printf("OK partial cmd, last segment = %s\n", pst.cur_levels[pst.cur_level_i - 1]); // ok
} else { } else {
printf("ERROR no such command (colon).\n");//TODO error printf("ERROR no such command (colon).\n");//TODO error
pst.state = PARS_DISCARD_LINE; pst.state = PARS_DISCARD_LINE;
@ -322,7 +322,7 @@ static void pars_cmd_space(void)
pst.state = PARS_ARG; pst.state = PARS_ARG;
} }
} else { } else {
printf("ERROR no such command (space) %s.\n", pst.charbuf);//TODO error printf("ERROR no such command: %s.\n", pst.charbuf);//TODO error
pst.state = PARS_DISCARD_LINE; pst.state = PARS_DISCARD_LINE;
} }
} }
@ -485,8 +485,8 @@ static void pars_arg_char(char c)
break; break;
case SCPI_DT_INT: case SCPI_DT_INT:
if (!IS_FLOAT_CHAR(c)) { if (!IS_INT_CHAR(c)) {
printf("ERROR unexpected char '%d' in int.\n", c);//TODO error printf("ERROR unexpected char '%c' in int.\n", c);//TODO error
pst.state = PARS_DISCARD_LINE; pst.state = PARS_DISCARD_LINE;
} else { } else {
charbuf_append(c); charbuf_append(c);
@ -511,6 +511,12 @@ static void pars_arg_comma(void)
return; return;
} }
if (pst.charbuf_i == 0) {
printf("ERROR empty argument is not allowed.\n");//TODO error
pst.state = PARS_DISCARD_LINE;
return;
}
// Convert to the right type // Convert to the right type
arg_convert_value(); arg_convert_value();
@ -567,6 +573,7 @@ static void arg_convert_value(void)
case SCPI_DT_INT: case SCPI_DT_INT:
j = sscanf(pst.charbuf, "%d", &dest->INT); j = sscanf(pst.charbuf, "%d", &dest->INT);
if (j == 0) { if (j == 0) {
printf("ERROR failed to convert %s to INT\n", pst.charbuf);//TODO error printf("ERROR failed to convert %s to INT\n", pst.charbuf);//TODO error
pst.state = PARS_DISCARD_LINE; pst.state = PARS_DISCARD_LINE;

Loading…
Cancel
Save