Skip to content

Commit

Permalink
moving bool choice definition (ON, OFF) to units.c, so it could be us…
Browse files Browse the repository at this point in the history
…ed by various applications
  • Loading branch information
jeras committed Jul 19, 2017
1 parent 06b8e46 commit a10c464
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions libscpi/inc/scpi/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern "C" {

extern const scpi_unit_def_t scpi_units_def[];
extern const scpi_choice_def_t scpi_special_numbers_def[];
extern const scpi_choice_def_t scpi_bool_def[];

scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory);

Expand Down
9 changes: 2 additions & 7 deletions libscpi/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "scpi/error.h"
#include "scpi/constants.h"
#include "scpi/utils.h"
#include "scpi/units.h"

/**
* Write data to SCPI output
Expand Down Expand Up @@ -1282,12 +1283,6 @@ scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t ma
scpi_parameter_t param;
int32_t intval;

scpi_choice_def_t bool_options[] = {
{"OFF", 0},
{"ON", 1},
SCPI_CHOICE_LIST_END /* termination of option list */
};

if (!value) {
SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR);
return FALSE;
Expand All @@ -1300,7 +1295,7 @@ scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t ma
SCPI_ParamToInt32(context, &param, &intval);
*value = intval ? TRUE : FALSE;
} else {
result = SCPI_ParamToChoice(context, &param, bool_options, &intval);
result = SCPI_ParamToChoice(context, &param, scpi_bool_def, &intval);
if (result) {
*value = intval ? TRUE : FALSE;
}
Expand Down
9 changes: 9 additions & 0 deletions libscpi/src/units.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ const scpi_choice_def_t scpi_special_numbers_def[] = {
SCPI_CHOICE_LIST_END,
};

/*
* Special number values definition
*/
const scpi_choice_def_t scpi_bool_def[] = {
{"OFF", 0},
{"ON", 1},
SCPI_CHOICE_LIST_END /* termination of option list */
};

/**
* Convert string describing unit to its representation
* @param units units patterns
Expand Down

0 comments on commit a10c464

Please sign in to comment.