Refactor bool_t to scpi_bool_t
| | |
| | | } |
| | | |
| | | scpi_result_t TEST_Bool(scpi_t * context) { |
| | | bool_t param1; |
| | | scpi_bool_t param1; |
| | | fprintf(stderr, "TEST:BOOL\r\n"); // debug command name |
| | | |
| | | // read first parameter if present |
| | |
| | | #define SCPI_DEBUG_COMMAND(a) |
| | | |
| | | |
| | | bool_t SCPI_DebugCommand(scpi_t * context); |
| | | scpi_bool_t SCPI_DebugCommand(scpi_t * context); |
| | | |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | |
| | | void fifo_init(fifo_t * fifo); |
| | | void fifo_clear(fifo_t * fifo); |
| | | bool_t fifo_add(fifo_t * fifo, int16_t value); |
| | | bool_t fifo_remove(fifo_t * fifo, int16_t * value); |
| | | bool_t fifo_count(fifo_t * fifo, int16_t * value); |
| | | scpi_bool_t fifo_add(fifo_t * fifo, int16_t value); |
| | | scpi_bool_t fifo_remove(fifo_t * fifo, int16_t * value); |
| | | scpi_bool_t fifo_count(fifo_t * fifo, int16_t * value); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | |
| | | size_t SCPI_ResultInt(scpi_t * context, int32_t val); |
| | | size_t SCPI_ResultDouble(scpi_t * context, double val); |
| | | size_t SCPI_ResultText(scpi_t * context, const char * data); |
| | | size_t SCPI_ResultBool(scpi_t * context, bool_t val); |
| | | size_t SCPI_ResultBool(scpi_t * context, scpi_bool_t val); |
| | | |
| | | bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory); |
| | | bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory); |
| | | bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, bool_t mandatory); |
| | | bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, bool_t mandatory); |
| | | bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory); |
| | | bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, scpi_bool_t mandatory); |
| | | |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | #endif |
| | | |
| | | /* basic data types */ |
| | | typedef bool bool_t; |
| | | /* typedef enum { FALSE = 0, TRUE } bool_t; */ |
| | | typedef bool scpi_bool_t; |
| | | /* typedef enum { FALSE = 0, TRUE } scpi_bool_t; */ |
| | | |
| | | /* IEEE 488.2 registers */ |
| | | enum _scpi_reg_name_t { |
| | |
| | | scpi_interface_t * interface; |
| | | int_fast16_t output_count; |
| | | int_fast16_t input_count; |
| | | bool_t cmd_error; |
| | | scpi_bool_t cmd_error; |
| | | scpi_error_queue_t error_queue; |
| | | scpi_reg_val_t * registers; |
| | | const scpi_unit_def_t * units; |
| | |
| | | extern const scpi_unit_def_t scpi_units_def[]; |
| | | extern const scpi_special_number_def_t scpi_special_numbers_def[]; |
| | | |
| | | bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, scpi_bool_t mandatory); |
| | | size_t SCPI_NumberToStr(scpi_t * context, scpi_number_t * value, char * str, size_t len); |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | * @param context |
| | | * @return |
| | | */ |
| | | bool_t SCPI_DebugCommand(scpi_t * context) { |
| | | scpi_bool_t SCPI_DebugCommand(scpi_t * context) { |
| | | size_t res; |
| | | printf("**DEBUG: %s (\"", context->paramlist.cmd->pattern); |
| | | res = fwrite(context->paramlist.parameters, 1, context->paramlist.length, stdout); |
| | |
| | | fifo->rd = 0; |
| | | } |
| | | |
| | | bool_t fifo_add(fifo_t * fifo, int16_t value) { |
| | | scpi_bool_t fifo_add(fifo_t * fifo, int16_t value) { |
| | | /* FIFO full? */ |
| | | if (fifo->wr == ((fifo->rd + fifo->size) % (fifo->size + 1))) { |
| | | fifo_remove(fifo, NULL); |
| | |
| | | return TRUE; |
| | | } |
| | | |
| | | bool_t fifo_remove(fifo_t * fifo, int16_t * value) { |
| | | scpi_bool_t fifo_remove(fifo_t * fifo, int16_t * value) { |
| | | /* FIFO empty? */ |
| | | if (fifo->wr == fifo->rd) { |
| | | return FALSE; |
| | |
| | | return TRUE; |
| | | } |
| | | |
| | | bool_t fifo_count(fifo_t * fifo, int16_t * value) { |
| | | scpi_bool_t fifo_count(fifo_t * fifo, int16_t * value) { |
| | | *value = fifo->wr - fifo->rd; |
| | | if (*value < 0) { |
| | | *value += (fifo->size + 1); |
| | |
| | | * @param val - new value |
| | | */ |
| | | void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val) { |
| | | bool_t srq = FALSE; |
| | | scpi_bool_t srq = FALSE; |
| | | scpi_reg_val_t mask; |
| | | scpi_reg_val_t old_val; |
| | | |
| | |
| | | |
| | | static void paramSkipBytes(scpi_t * context, size_t num); |
| | | static void paramSkipWhitespace(scpi_t * context); |
| | | static bool_t paramNext(scpi_t * context, bool_t mandatory); |
| | | static scpi_bool_t paramNext(scpi_t * context, scpi_bool_t mandatory); |
| | | |
| | | /* |
| | | int _strnicmp(const char* s1, const char* s2, size_t len) { |
| | |
| | | * @param context |
| | | * @result TRUE if context->paramlist is filled with correct values |
| | | */ |
| | | static bool_t findCommand(scpi_t * context, const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) { |
| | | static scpi_bool_t findCommand(scpi_t * context, const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) { |
| | | int32_t i; |
| | | const scpi_command_t * cmd; |
| | | |
| | |
| | | * @param val |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultBool(scpi_t * context, bool_t val) { |
| | | size_t SCPI_ResultBool(scpi_t * context, scpi_bool_t val) { |
| | | return SCPI_ResultInt(context, val ? 1 : 0); |
| | | } |
| | | |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t paramNext(scpi_t * context, bool_t mandatory) { |
| | | scpi_bool_t paramNext(scpi_t * context, scpi_bool_t mandatory) { |
| | | paramSkipWhitespace(context); |
| | | if (context->paramlist.length == 0) { |
| | | if (mandatory) { |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory) { |
| | | scpi_bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, scpi_bool_t mandatory) { |
| | | const char * param; |
| | | size_t param_len; |
| | | size_t num_len; |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory) { |
| | | scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory) { |
| | | const char * param; |
| | | size_t param_len; |
| | | size_t num_len; |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, bool_t mandatory) { |
| | | scpi_bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { |
| | | size_t length; |
| | | |
| | | if (!value || !len) { |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, bool_t mandatory) { |
| | | scpi_bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { |
| | | size_t length; |
| | | |
| | | if (!value || !len) { |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory) { |
| | | scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) { |
| | | const char * param; |
| | | size_t param_len; |
| | | size_t num_len; |
| | |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, bool_t mandatory) { |
| | | scpi_bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, scpi_bool_t mandatory) { |
| | | const char * param; |
| | | size_t param_len; |
| | | size_t res; |
| | |
| | | * @param value resultin value |
| | | * @return TRUE if str matches one of specs patterns |
| | | */ |
| | | static bool_t translateSpecialNumber(const scpi_special_number_def_t * specs, const char * str, size_t len, scpi_number_t * value) { |
| | | static scpi_bool_t translateSpecialNumber(const scpi_special_number_def_t * specs, const char * str, size_t len, scpi_number_t * value) { |
| | | int i; |
| | | |
| | | value->value = 0.0; |
| | |
| | | * @param value preparsed numeric value |
| | | * @return TRUE if value parameter was converted to base units |
| | | */ |
| | | static bool_t transformNumber(scpi_t * context, const char * unit, size_t len, scpi_number_t * value) { |
| | | static scpi_bool_t transformNumber(scpi_t * context, const char * unit, size_t len, scpi_number_t * value) { |
| | | size_t s; |
| | | const scpi_unit_def_t * unitDef; |
| | | s = skipWhitespace(unit, len); |
| | |
| | | * @param mandatory if the parameter is mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory) { |
| | | bool_t result; |
| | | scpi_bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, scpi_bool_t mandatory) { |
| | | scpi_bool_t result; |
| | | const char * param; |
| | | size_t len; |
| | | size_t numlen; |
| | |
| | | * @param len2 |
| | | * @return TRUE if len1==len2 and "len" characters of both strings are equal |
| | | */ |
| | | bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) { |
| | | scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) { |
| | | if (len1 != len2) { |
| | | return FALSE; |
| | | } |
| | |
| | | /** |
| | | * Test locate text state, if it is correct final state |
| | | */ |
| | | static bool_t isFinalState(locate_text_states state) { |
| | | static scpi_bool_t isFinalState(locate_text_states state) { |
| | | return ( |
| | | ((state) == STATE_COMMA) |
| | | || ((state) == STATE_LAST_WHITESPACE) |
| | |
| | | * @param nfa stores automaton state |
| | | * @param c current char processed |
| | | */ |
| | | static bool_t locateTextAutomaton(locate_text_nfa * nfa, unsigned char c) { |
| | | static scpi_bool_t locateTextAutomaton(locate_text_nfa * nfa, unsigned char c) { |
| | | switch(nfa->state) { |
| | | /* first state locating only white spaces */ |
| | | case STATE_FIRST_WHITESPACE: |
| | |
| | | * @param len2 length of result |
| | | * @return string str1 contains text and str2 was set |
| | | */ |
| | | bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) { |
| | | scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) { |
| | | locate_text_nfa nfa; |
| | | nfa.state = STATE_FIRST_WHITESPACE; |
| | | nfa.startIdx = 0; |
| | |
| | | * @param nfa stores automaton state |
| | | * @param c current char processed |
| | | */ |
| | | static bool_t locateStrAutomaton(locate_text_nfa * nfa, unsigned char c) { |
| | | static scpi_bool_t locateStrAutomaton(locate_text_nfa * nfa, unsigned char c) { |
| | | switch(nfa->state) { |
| | | /* first state locating only white spaces */ |
| | | case STATE_FIRST_WHITESPACE: |
| | |
| | | * @param len2 length of result |
| | | * @return string str1 contains text and str2 was set |
| | | */ |
| | | bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) { |
| | | scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) { |
| | | locate_text_nfa nfa; |
| | | nfa.state = STATE_FIRST_WHITESPACE; |
| | | nfa.startIdx = 0; |
| | |
| | | * @param str_len |
| | | * @return |
| | | */ |
| | | bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) { |
| | | scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) { |
| | | int pattern_sep_pos_short = patternSeparatorShortPos(pattern, pattern_len); |
| | | return compareStr(pattern, pattern_len, str, str_len) || |
| | | compareStr(pattern, pattern_sep_pos_short, str, str_len); |
| | |
| | | * @param len - max search length |
| | | * @return TRUE if pattern matches, FALSE otherwise |
| | | */ |
| | | bool_t matchCommand(const char * pattern, const char * cmd, size_t len) { |
| | | bool_t result = FALSE; |
| | | scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len) { |
| | | scpi_bool_t result = FALSE; |
| | | int leftFlag = 0; // flag for '[' on left |
| | | int rightFlag = 0; // flag for ']' on right |
| | | int cmd_sep_pos = 0; |
| | |
| | | * |
| | | * |
| | | */ |
| | | bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, |
| | | scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, |
| | | char ** pptr, size_t * plen) { |
| | | char * ptr; |
| | | size_t len; |
| | |
| | | #endif |
| | | |
| | | const char * strnpbrk(const char *str, size_t size, const char *set) LOCAL; |
| | | bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL; |
| | | scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL; |
| | | size_t longToStr(int32_t val, char * str, size_t len) LOCAL; |
| | | size_t doubleToStr(double val, char * str, size_t len) LOCAL; |
| | | size_t strToLong(const char * str, int32_t * val) LOCAL; |
| | | size_t strToDouble(const char * str, double * val) LOCAL; |
| | | bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; |
| | | bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; |
| | | scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; |
| | | scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL; |
| | | size_t skipWhitespace(const char * cmd, size_t len) LOCAL; |
| | | size_t skipColon(const char * cmd, size_t len) LOCAL; |
| | | bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) LOCAL; |
| | | bool_t matchCommand(const char * pattern, const char * cmd, size_t len) LOCAL; |
| | | bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); |
| | | scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len) LOCAL; |
| | | scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len) LOCAL; |
| | | scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); |
| | | |
| | | #if !HAVE_STRNLEN |
| | | size_t BSD_strnlen(const char *s, size_t maxlen); |
| | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | bool_t TST_executed = FALSE; |
| | | bool_t RST_executed = FALSE; |
| | | scpi_bool_t TST_executed = FALSE; |
| | | scpi_bool_t RST_executed = FALSE; |
| | | static scpi_result_t SCPI_Test(scpi_t * context) { |
| | | TST_executed = TRUE; |
| | | return SCPI_RES_OK; |
| | |
| | | } |
| | | |
| | | void test_matchPattern() { |
| | | bool_t result; |
| | | scpi_bool_t result; |
| | | |
| | | #define TEST_MATCH_PATTERN(p, s, r) \ |
| | | do { \ |
| | |
| | | } |
| | | |
| | | void test_matchCommand() { |
| | | bool_t result; |
| | | scpi_bool_t result; |
| | | |
| | | #define TEST_MATCH_COMMAND(p, s, r) \ |
| | | do { \ |
| | |
| | | char * cmd = buffer + c2_pos; \ |
| | | size_t len_prev = c1_len; \ |
| | | size_t len = c2_len; \ |
| | | bool_t res; \ |
| | | scpi_bool_t res; \ |
| | | \ |
| | | strcpy(buffer, b); \ |
| | | res = composeCompoundCommand(cmd_prev, len_prev, &cmd, &len); \ |
| | |
| | | TEST_COMPOSE_COMMAND(":A:B;:C", 4, 5, 2, ":C", TRUE); |
| | | TEST_COMPOSE_COMMAND(":A;C", 2, 3, 1, ":C", TRUE); |
| | | |
| | | bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); |
| | | scpi_bool_t composeCompoundCommand(char * ptr_prev, size_t len_prev, char ** pptr, size_t * plen); |
| | | |
| | | } |
| | | |