diff --git a/Makefile b/Makefile index 7eafd63..66d97e7 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,16 @@ HDRS+= source/scpi_regs.h HDRS+= source/scpi_builtins.h HDRS+= source/scpi_errors.h +CFLAGS += -std=gnu99 +CFLAGS += -Wall -Wextra -Wshadow +CFLAGS += -Wwrite-strings -Wold-style-definition -Winline +CFLAGS += -Wredundant-decls -Wfloat-equal -Wsign-compare -Wunused-function + +# gcc bug? +CFLAGS += -Wno-missing-braces + all: $(SRC) $(HDRS) - gcc $(SRC) -o main.elf + gcc $(CFLAGS) $(SRC) -o main.elf run: all ./main.elf diff --git a/main.c b/main.c index 58e2890..7e945df 100644 --- a/main.c +++ b/main.c @@ -12,7 +12,7 @@ static void send_cmd(const char *cmd) scpi_handle_string(cmd); } -int main() +int main(void) { send_cmd("*IDN?\n"); // builtin commands.. send_cmd("*SRE 4\n"); // enable SRQ on error @@ -93,6 +93,8 @@ void cmd_DATA_BLOB_data(const uint8_t *bytes) void cmd_USRERR_cb(const SCPI_argval_t *args) { + (void) args; + printf("cb USRERR - raising user error 10.\n"); scpi_add_error(10, "Custom error message..."); } diff --git a/scpi b/scpi new file mode 100755 index 0000000..939e605 Binary files /dev/null and b/scpi differ diff --git a/scpi.pro.user b/scpi.pro.user index f2d5683..bf950fc 100644 --- a/scpi.pro.user +++ b/scpi.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -70,21 +70,9 @@ 0 0 - /home/ondra/stm32/build-scpi-Desktop-Debug + /home/ondra/stm32/scpi_ - true - qmake - - QtProjectManager.QMakeBuildStep - false - true - - false - false - false - - true Make @@ -97,7 +85,7 @@ - 2 + 1 Build ProjectExplorer.BuildSteps.Build diff --git a/source/scpi_builtins.c b/source/scpi_builtins.c index fa97e1f..a597a28 100644 --- a/source/scpi_builtins.c +++ b/source/scpi_builtins.c @@ -16,6 +16,8 @@ static char sbuf[256]; static void builtin_CLS(const SCPI_argval_t *args) { + (void)args; + // clear the registers SCPI_REG_SESR.u8 = 0; SCPI_REG_OPER.u16 = 0; @@ -32,6 +34,8 @@ static void builtin_CLS(const SCPI_argval_t *args) static void builtin_RST(const SCPI_argval_t *args) { + (void)args; + if (scpi_user_RST) { scpi_user_RST(); } @@ -40,6 +44,8 @@ static void builtin_RST(const SCPI_argval_t *args) static void builtin_TSTq(const SCPI_argval_t *args) { + (void)args; + if (scpi_user_TSTq) { scpi_user_TSTq(); } @@ -48,6 +54,8 @@ static void builtin_TSTq(const SCPI_argval_t *args) static void builtin_IDNq(const SCPI_argval_t *args) { + (void)args; + scpi_send_string(scpi_device_identifier()); } @@ -61,6 +69,8 @@ static void builtin_ESE(const SCPI_argval_t *args) static void builtin_ESEq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", SCPI_REG_SESR_EN.u8); scpi_send_string(sbuf); } @@ -68,6 +78,8 @@ static void builtin_ESEq(const SCPI_argval_t *args) static void builtin_ESRq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", SCPI_REG_SESR.u8); scpi_send_string(sbuf); @@ -78,6 +90,8 @@ static void builtin_ESRq(const SCPI_argval_t *args) static void builtin_OPC(const SCPI_argval_t *args) { + (void)args; + // implementation for instruments with no overlapping commands. // Can be overridden in the user commands. SCPI_REG_SESR.OPC = 1; @@ -87,6 +101,8 @@ static void builtin_OPC(const SCPI_argval_t *args) static void builtin_OPCq(const SCPI_argval_t *args) { + (void)args; + // implementation for instruments with no overlapping commands. // Can be overridden in the user commands. // (would be): sprintf(sbuf, "%d", SCPI_REG_SESR.OPC); @@ -104,6 +120,8 @@ static void builtin_SRE(const SCPI_argval_t *args) static void builtin_SREq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", SCPI_REG_SRE.u8); scpi_send_string(sbuf); } @@ -111,6 +129,8 @@ static void builtin_SREq(const SCPI_argval_t *args) static void builtin_STBq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", SCPI_REG_STB.u8); scpi_send_string(sbuf); } @@ -118,12 +138,16 @@ static void builtin_STBq(const SCPI_argval_t *args) static void builtin_WAI(const SCPI_argval_t *args) { + (void)args; + // no-op } static void builtin_SYST_ERR_NEXTq(const SCPI_argval_t *args) { + (void)args; + scpi_read_error(sbuf); scpi_send_string(sbuf); } @@ -132,6 +156,8 @@ static void builtin_SYST_ERR_NEXTq(const SCPI_argval_t *args) // optional static void builtin_SYST_ERR_ALLq(const SCPI_argval_t *args) { + (void)args; + int cnt = 0; while (scpi_error_count()) { scpi_read_error(sbuf); @@ -145,6 +171,8 @@ static void builtin_SYST_ERR_ALLq(const SCPI_argval_t *args) static void builtin_SYST_ERR_CODE_NEXTq(const SCPI_argval_t *args) { + (void)args; + scpi_read_error(sbuf); // end at comma @@ -162,6 +190,8 @@ static void builtin_SYST_ERR_CODE_NEXTq(const SCPI_argval_t *args) // optional static void builtin_SYST_ERR_CODE_ALLq(const SCPI_argval_t *args) { + (void)args; + int cnt = 0; while (scpi_error_count()) { scpi_read_error(sbuf); @@ -185,6 +215,8 @@ static void builtin_SYST_ERR_CODE_ALLq(const SCPI_argval_t *args) // optional static void builtin_SYST_ERR_COUNq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", scpi_error_count()); scpi_send_string(sbuf); } @@ -193,18 +225,24 @@ static void builtin_SYST_ERR_COUNq(const SCPI_argval_t *args) // optional, custom static void builtin_SYST_ERR_CLEAR(const SCPI_argval_t *args) { + (void)args; + scpi_clear_errors(); } static void builtin_SYST_VERSq(const SCPI_argval_t *args) { + (void)args; + scpi_send_string("1999.0"); // implemented SCPI version } static void builtin_STAT_OPER_EVENq(const SCPI_argval_t *args) { + (void)args; + // read and clear sprintf(sbuf, "%d", SCPI_REG_OPER.u16); SCPI_REG_OPER.u16 = 0x0000; @@ -215,6 +253,8 @@ static void builtin_STAT_OPER_EVENq(const SCPI_argval_t *args) static void builtin_STAT_OPER_CONDq(const SCPI_argval_t *args) { + (void)args; + // read and keep sprintf(sbuf, "%d", SCPI_REG_OPER.u16); scpi_send_string(sbuf); @@ -230,6 +270,8 @@ static void builtin_STAT_OPER_ENAB(const SCPI_argval_t *args) static void builtin_STAT_OPER_ENABq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", SCPI_REG_OPER_EN.u16); scpi_send_string(sbuf); } @@ -237,6 +279,8 @@ static void builtin_STAT_OPER_ENABq(const SCPI_argval_t *args) static void builtin_STAT_QUES_EVENq(const SCPI_argval_t *args) { + (void)args; + // read and clear sprintf(sbuf, "%d", SCPI_REG_QUES.u16); SCPI_REG_QUES.u16 = 0x0000; @@ -247,6 +291,8 @@ static void builtin_STAT_QUES_EVENq(const SCPI_argval_t *args) static void builtin_STAT_QUES_CONDq(const SCPI_argval_t *args) { + (void)args; + // read and keep sprintf(sbuf, "%d", SCPI_REG_QUES.u16); scpi_send_string(sbuf); @@ -262,6 +308,8 @@ static void builtin_STAT_QUES_ENAB(const SCPI_argval_t *args) static void builtin_STAT_QUES_ENABq(const SCPI_argval_t *args) { + (void)args; + sprintf(sbuf, "%d", SCPI_REG_QUES_EN.u16); scpi_send_string(sbuf); } @@ -269,6 +317,8 @@ static void builtin_STAT_QUES_ENABq(const SCPI_argval_t *args) static void builtin_STAT_PRES(const SCPI_argval_t *args) { + (void)args; + // Command required by SCPI spec, useless for this SCPI implementation. // This is meant to preset transition and filter registers, which are not used here. diff --git a/source/scpi_errors.c b/source/scpi_errors.c index 7ce33bb..6cd968d 100644 --- a/source/scpi_errors.c +++ b/source/scpi_errors.c @@ -23,11 +23,9 @@ static struct { void scpi_add_error(int16_t errno, const char *extra) { - bool added = true; if (erq.count >= ERR_QUEUE_LEN) { errno = E_DEV_QUEUE_OVERFLOW; extra = NULL; - added = false; // replaced only // backtrack erq.w_pos--; diff --git a/source/scpi_parser.c b/source/scpi_parser.c index 0849095..f27af77 100644 --- a/source/scpi_parser.c +++ b/source/scpi_parser.c @@ -16,7 +16,7 @@ // Char matching #define INRANGE(c, a, b) ((c) >= (a) && (c) <= (b)) -#define IS_WHITESPACE(c) (INRANGE((c), 0, 9) || INRANGE((c), 11, 32)) +#define IS_WHITESPACE(c) ((c) <= 9 || INRANGE((c), 11, 32)) #define IS_LCASE_CHAR(c) INRANGE((c), 'a', 'z') #define IS_UCASE_CHAR(c) INRANGE((c), 'A', 'Z') @@ -135,7 +135,7 @@ void scpi_send_string(const char *message) // ------- Error shortcuts ---------- -static void err_no_such_command() +static void err_no_such_command(void) { char *b = ebuf; for (int i = 0; i < pst.cur_level_i; i++) { @@ -147,7 +147,7 @@ static void err_no_such_command() } -static void err_no_such_command_partial() +static void err_no_such_command_partial(void) { char *b = ebuf; for (int i = 0; i < pst.cur_level_i; i++) {