fixed some small style errors and warnings

master
Ondřej Hruška 9 years ago
parent 50ff6322f4
commit daf9a3c2a5
  1. 10
      Makefile
  2. 4
      main.c
  3. BIN
      scpi
  4. 18
      scpi.pro.user
  5. 50
      source/scpi_builtins.c
  6. 2
      source/scpi_errors.c
  7. 6
      source/scpi_parser.c

@ -9,8 +9,16 @@ HDRS+= source/scpi_regs.h
HDRS+= source/scpi_builtins.h HDRS+= source/scpi_builtins.h
HDRS+= source/scpi_errors.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) all: $(SRC) $(HDRS)
gcc $(SRC) -o main.elf gcc $(CFLAGS) $(SRC) -o main.elf
run: all run: all
./main.elf ./main.elf

@ -12,7 +12,7 @@ static void send_cmd(const char *cmd)
scpi_handle_string(cmd); scpi_handle_string(cmd);
} }
int main() int main(void)
{ {
send_cmd("*IDN?\n"); // builtin commands.. send_cmd("*IDN?\n"); // builtin commands..
send_cmd("*SRE 4\n"); // enable SRQ on error 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 cmd_USRERR_cb(const SCPI_argval_t *args)
{ {
(void) args;
printf("cb USRERR - raising user error 10.\n"); printf("cb USRERR - raising user error 10.\n");
scpi_add_error(10, "Custom error message..."); scpi_add_error(10, "Custom error message...");
} }

BIN
scpi

Binary file not shown.

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-12-05T19:13:04. --> <!-- Written by QtCreator 3.5.1, 2015-12-05T21:07:16. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -70,21 +70,9 @@
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/stm32/build-scpi-Desktop-Debug</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/stm32/scpi_</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
@ -97,7 +85,7 @@
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>

@ -16,6 +16,8 @@ static char sbuf[256];
static void builtin_CLS(const SCPI_argval_t *args) static void builtin_CLS(const SCPI_argval_t *args)
{ {
(void)args;
// clear the registers // clear the registers
SCPI_REG_SESR.u8 = 0; SCPI_REG_SESR.u8 = 0;
SCPI_REG_OPER.u16 = 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) static void builtin_RST(const SCPI_argval_t *args)
{ {
(void)args;
if (scpi_user_RST) { if (scpi_user_RST) {
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) static void builtin_TSTq(const SCPI_argval_t *args)
{ {
(void)args;
if (scpi_user_TSTq) { if (scpi_user_TSTq) {
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) static void builtin_IDNq(const SCPI_argval_t *args)
{ {
(void)args;
scpi_send_string(scpi_device_identifier()); 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) static void builtin_ESEq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", SCPI_REG_SESR_EN.u8); sprintf(sbuf, "%d", SCPI_REG_SESR_EN.u8);
scpi_send_string(sbuf); 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) static void builtin_ESRq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", SCPI_REG_SESR.u8); sprintf(sbuf, "%d", SCPI_REG_SESR.u8);
scpi_send_string(sbuf); 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) static void builtin_OPC(const SCPI_argval_t *args)
{ {
(void)args;
// implementation for instruments with no overlapping commands. // implementation for instruments with no overlapping commands.
// Can be overridden in the user commands. // Can be overridden in the user commands.
SCPI_REG_SESR.OPC = 1; 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) static void builtin_OPCq(const SCPI_argval_t *args)
{ {
(void)args;
// implementation for instruments with no overlapping commands. // implementation for instruments with no overlapping commands.
// Can be overridden in the user commands. // Can be overridden in the user commands.
// (would be): sprintf(sbuf, "%d", SCPI_REG_SESR.OPC); // (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) static void builtin_SREq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", SCPI_REG_SRE.u8); sprintf(sbuf, "%d", SCPI_REG_SRE.u8);
scpi_send_string(sbuf); 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) static void builtin_STBq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", SCPI_REG_STB.u8); sprintf(sbuf, "%d", SCPI_REG_STB.u8);
scpi_send_string(sbuf); 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) static void builtin_WAI(const SCPI_argval_t *args)
{ {
(void)args;
// no-op // no-op
} }
static void builtin_SYST_ERR_NEXTq(const SCPI_argval_t *args) static void builtin_SYST_ERR_NEXTq(const SCPI_argval_t *args)
{ {
(void)args;
scpi_read_error(sbuf); scpi_read_error(sbuf);
scpi_send_string(sbuf); scpi_send_string(sbuf);
} }
@ -132,6 +156,8 @@ static void builtin_SYST_ERR_NEXTq(const SCPI_argval_t *args)
// optional // optional
static void builtin_SYST_ERR_ALLq(const SCPI_argval_t *args) static void builtin_SYST_ERR_ALLq(const SCPI_argval_t *args)
{ {
(void)args;
int cnt = 0; int cnt = 0;
while (scpi_error_count()) { while (scpi_error_count()) {
scpi_read_error(sbuf); 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) static void builtin_SYST_ERR_CODE_NEXTq(const SCPI_argval_t *args)
{ {
(void)args;
scpi_read_error(sbuf); scpi_read_error(sbuf);
// end at comma // end at comma
@ -162,6 +190,8 @@ static void builtin_SYST_ERR_CODE_NEXTq(const SCPI_argval_t *args)
// optional // optional
static void builtin_SYST_ERR_CODE_ALLq(const SCPI_argval_t *args) static void builtin_SYST_ERR_CODE_ALLq(const SCPI_argval_t *args)
{ {
(void)args;
int cnt = 0; int cnt = 0;
while (scpi_error_count()) { while (scpi_error_count()) {
scpi_read_error(sbuf); scpi_read_error(sbuf);
@ -185,6 +215,8 @@ static void builtin_SYST_ERR_CODE_ALLq(const SCPI_argval_t *args)
// optional // optional
static void builtin_SYST_ERR_COUNq(const SCPI_argval_t *args) static void builtin_SYST_ERR_COUNq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", scpi_error_count()); sprintf(sbuf, "%d", scpi_error_count());
scpi_send_string(sbuf); scpi_send_string(sbuf);
} }
@ -193,18 +225,24 @@ static void builtin_SYST_ERR_COUNq(const SCPI_argval_t *args)
// optional, custom // optional, custom
static void builtin_SYST_ERR_CLEAR(const SCPI_argval_t *args) static void builtin_SYST_ERR_CLEAR(const SCPI_argval_t *args)
{ {
(void)args;
scpi_clear_errors(); scpi_clear_errors();
} }
static void builtin_SYST_VERSq(const SCPI_argval_t *args) static void builtin_SYST_VERSq(const SCPI_argval_t *args)
{ {
(void)args;
scpi_send_string("1999.0"); // implemented SCPI version scpi_send_string("1999.0"); // implemented SCPI version
} }
static void builtin_STAT_OPER_EVENq(const SCPI_argval_t *args) static void builtin_STAT_OPER_EVENq(const SCPI_argval_t *args)
{ {
(void)args;
// read and clear // read and clear
sprintf(sbuf, "%d", SCPI_REG_OPER.u16); sprintf(sbuf, "%d", SCPI_REG_OPER.u16);
SCPI_REG_OPER.u16 = 0x0000; 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) static void builtin_STAT_OPER_CONDq(const SCPI_argval_t *args)
{ {
(void)args;
// read and keep // read and keep
sprintf(sbuf, "%d", SCPI_REG_OPER.u16); sprintf(sbuf, "%d", SCPI_REG_OPER.u16);
scpi_send_string(sbuf); 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) static void builtin_STAT_OPER_ENABq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", SCPI_REG_OPER_EN.u16); sprintf(sbuf, "%d", SCPI_REG_OPER_EN.u16);
scpi_send_string(sbuf); 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) static void builtin_STAT_QUES_EVENq(const SCPI_argval_t *args)
{ {
(void)args;
// read and clear // read and clear
sprintf(sbuf, "%d", SCPI_REG_QUES.u16); sprintf(sbuf, "%d", SCPI_REG_QUES.u16);
SCPI_REG_QUES.u16 = 0x0000; 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) static void builtin_STAT_QUES_CONDq(const SCPI_argval_t *args)
{ {
(void)args;
// read and keep // read and keep
sprintf(sbuf, "%d", SCPI_REG_QUES.u16); sprintf(sbuf, "%d", SCPI_REG_QUES.u16);
scpi_send_string(sbuf); 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) static void builtin_STAT_QUES_ENABq(const SCPI_argval_t *args)
{ {
(void)args;
sprintf(sbuf, "%d", SCPI_REG_QUES_EN.u16); sprintf(sbuf, "%d", SCPI_REG_QUES_EN.u16);
scpi_send_string(sbuf); 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) static void builtin_STAT_PRES(const SCPI_argval_t *args)
{ {
(void)args;
// Command required by SCPI spec, useless for this SCPI implementation. // Command required by SCPI spec, useless for this SCPI implementation.
// This is meant to preset transition and filter registers, which are not used here. // This is meant to preset transition and filter registers, which are not used here.

@ -23,11 +23,9 @@ static struct {
void scpi_add_error(int16_t errno, const char *extra) void scpi_add_error(int16_t errno, const char *extra)
{ {
bool added = true;
if (erq.count >= ERR_QUEUE_LEN) { if (erq.count >= ERR_QUEUE_LEN) {
errno = E_DEV_QUEUE_OVERFLOW; errno = E_DEV_QUEUE_OVERFLOW;
extra = NULL; extra = NULL;
added = false; // replaced only
// backtrack // backtrack
erq.w_pos--; erq.w_pos--;

@ -16,7 +16,7 @@
// Char matching // Char matching
#define INRANGE(c, a, b) ((c) >= (a) && (c) <= (b)) #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_LCASE_CHAR(c) INRANGE((c), 'a', 'z')
#define IS_UCASE_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 ---------- // ------- Error shortcuts ----------
static void err_no_such_command() static void err_no_such_command(void)
{ {
char *b = ebuf; char *b = ebuf;
for (int i = 0; i < pst.cur_level_i; i++) { 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; char *b = ebuf;
for (int i = 0; i < pst.cur_level_i; i++) { for (int i = 0; i < pst.cur_level_i; i++) {

Loading…
Cancel
Save