| | |
| | | #else |
| | | #define SCPIDEFINE_strtoll(n, p, b) strtoll((n), (p), (b)) |
| | | #define SCPIDEFINE_strtoull(n, p, b) strtoull((n), (p), (b)) |
| | | extern long long int strtoll(const char *nptr, char **endptr, int base); |
| | | extern unsigned long long int strtoull(const char *nptr, char **endptr, int base); |
| | | //这里注释是为了消除警告 |
| | | //extern long long int strtoll(const char *nptr, char **endptr, int base); |
| | | //extern unsigned long long int strtoull(const char *nptr, char **endptr, int base); |
| | | |
| | | /* TODO: implement OUR_strtoll and OUR_strtoull */ |
| | | /* #warning "64bit string to int conversion not implemented" */ |
| | | #endif |
| | |
| | | int segments_count; |
| | | } CPatternResult; |
| | | |
| | | static CPatternResult *GetInstance(); |
| | | |
| | | int match_segments_global(const char* input, int pattern_index); |
| | | void parse_pattern_global(const char* pattern); |
| | |
| | | } |
| | | |
| | | static bool match_all_segments(const std::vector<std::string>& stringList, |
| | | const std::vector<Segment>& vecSegment) |
| | | const std::vector<Segment>& vecSegment) { |
| | | size_t currentIndex = 0; |
| | | for (const auto& segment : vecSegment) |
| | | { |
| | | int currentIndex = 0; |
| | | for (size_t i = 0; i < vecSegment.size(); i++) |
| | | { |
| | | auto currentSegment = vecSegment[i]; |
| | | |
| | | if (currentSegment.is_required) { |
| | | for (const auto& option : currentSegment.options) |
| | | { |
| | | //当索引index超过输入参数的词组大小 则表示命令不匹配 |
| | | if(currentIndex >= stringList.size()) |
| | | { |
| | | return false; |
| | | } |
| | | if (stringList[currentIndex] != option) |
| | | if (segment.is_required) |
| | | { |
| | | return false; |
| | | } else { |
| | | currentIndex += 1; |
| | | } |
| | | bool matched = false; |
| | | for (const auto& option : segment.options) |
| | | { |
| | | if (stringList[currentIndex] == option) |
| | | { |
| | | matched = true; |
| | | break; |
| | | } |
| | | } |
| | | else if (currentSegment.is_variable) |
| | | { |
| | | if (stringList.size() == vecSegment.size()) |
| | | { |
| | | auto vecTempSegments = currentSegment.options; |
| | | for (const auto& option : vecTempSegments) |
| | | { |
| | | if (stringList[currentIndex] != option) |
| | | if (!matched) |
| | | { |
| | | return false; |
| | | } else { |
| | | currentIndex += 1; |
| | | } |
| | | break; |
| | | currentIndex++; |
| | | } |
| | | else if (segment.is_variable) |
| | | { |
| | | // 可变参数:直接跳过 |
| | | currentIndex++; |
| | | } else |
| | | { |
| | | |
| | | if (segment.options.empty() || stringList[currentIndex] != segment.options[0]) { |
| | | return false; |
| | | } |
| | | currentIndex++; |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | currentIndex += 1; |
| | | } |
| | | } |
| | | return true; |
| | | return currentIndex == stringList.size(); |
| | | } |
| | | |
| | | static std::vector<Segment> extract_all_segments(const std::string& pattern) |
| | |
| | | } |
| | | |
| | | return PatternParser::match_all_segments(inputList, segments) ? 1 : 0; |
| | | } |
| | | |
| | | CPatternResult *GetInstance() |
| | | { |
| | | return g_pattern_results; |
| | | } |
| | |
| | | enable = 0xFFFF; |
| | | } |
| | | |
| | | scpi_bool_t summary = val & enable; |
| | | scpi_bool_t summary = (scpi_bool_t)val & enable; |
| | | |
| | | name = register_group.parent_reg; |
| | | val = SCPI_RegGet(context, register_group.parent_reg); |
| | |
| | | { |
| | | if (context->idn[i]) |
| | | { |
| | | char* outPut = "IDNS响应"; |
| | | // context->interface->write(context,context->idn[i],0); |
| | | SCPI_ResultMnemonic(context, context->idn[i]); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | |
| | | if (iseos(state)) { |
| | | return (state->pos - startPos) * SKIP_INCOMPLETE; |
| | | } else { |
| | | return (state->pos - startPos) * SKIP_OK; |
| | | } |
| | | ptrdiff_t diff = state->pos - startPos; |
| | | long long result = diff * (iseos(state) ? SKIP_INCOMPLETE : SKIP_OK); |
| | | |
| | | return (int)result; |
| | | } |
| | | |
| | | /* tokens */ |
| | |
| | | */ |
| | | |
| | | //负命令回调的执行、参数处理和错误管理 |
| | | static scpi_bool_t processCommand(scpi_t * context) { |
| | | //这个地方修改为 读comdlist->pattern |
| | | static scpi_bool_t processCommand(scpi_t * context) |
| | | { |
| | | const scpi_command_t * cmd = context->param_list.cmd; |
| | | //const scpi_command_t * cmd = context->cmdlist->pattern; |
| | | lex_state_t * state = &context->param_list.lex_state; |
| | | scpi_bool_t result = TRUE; |
| | | // 先检测是否为查询命令(以?结尾) |
| | |
| | | */ |
| | | scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len) |
| | | { |
| | | //参数已经在前面部分解析完成,匹配命令时就不再需要参数部分 将命令拆除即可 |
| | | char *header_copy = strdup(header); |
| | | char *first_part = strtok(header_copy, " "); |
| | | |
| | | for(int i=0;i<get_pattern_count();i++) |
| | | { |
| | | if( match_segments_global(header,i) ) |
| | | if( match_segments_global(first_part,i) ) |
| | | { |
| | | context->param_list.cmd = &context->cmdlist[i]; |
| | | free(header_copy); |
| | | return TRUE; |
| | | } |
| | | } |
| | |
| | | chanlst_idx = 0; /* call first index */ |
| | | arr_idx = 0; /* set arr_idx to 0 */ |
| | | do { /* if valid, iterate over channel_list_param index while res == valid (do-while cause we have to do it once) */ |
| | | res = SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions); |
| | | res = (scpi_expr_result_t)SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions); |
| | | if (is_range == FALSE) { /* still can have multiple dimensions */ |
| | | if (dimensions == 1) { |
| | | /* here we have our values |
| | |
| | | * row == n |
| | | * col == m |
| | | * call a function or something */ |
| | | array[arr_idx].row = n; |
| | | array[arr_idx].col = m; |
| | | array[arr_idx].row =(int32_t) n; |
| | | array[arr_idx].col = (int32_t)m; |
| | | arr_idx++; |
| | | if (arr_idx >= MAXROW * MAXCOL) { |
| | | return SCPI_RES_ERR; |
| | |
| | | |
| | | int SCPI_Error(scpi_t * context, int_fast16_t err) { |
| | | (void) context; |
| | | std::cerr << "**ERROR: " << err << ", \"" << SCPI_ErrorTranslate(err) << "\"" << std::endl; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | |
| | | if (value->special) { |
| | | if (SCPI_ChoiceToName(special, value->content.tag, &type)) { |
| | | strncpy(str, type, len); |
| | | memcpy(str, type, len); |
| | | result = SCPIDEFINE_strnlen(str, len - 1); |
| | | str[result] = '\0'; |
| | | return result; |
| | |
| | | */ |
| | | size_t strToFloat(const char * str, float * val) { |
| | | char * endptr; |
| | | *val = SCPIDEFINE_strtof(str, &endptr); |
| | | *val = (float)SCPIDEFINE_strtof(str, &endptr); |
| | | return endptr - str; |
| | | } |
| | | |
| | |
| | | if ((pattern_len > 0) && pattern[pattern_len - 1] == '#') { |
| | | size_t new_pattern_len = pattern_len - 1; |
| | | |
| | | pattern_sep_pos_short = patternSeparatorShortPos(pattern, new_pattern_len); |
| | | pattern_sep_pos_short = (int)patternSeparatorShortPos(pattern, new_pattern_len); |
| | | |
| | | return compareStrAndNum(pattern, new_pattern_len, str, str_len, num) || |
| | | compareStrAndNum(pattern, pattern_sep_pos_short, str, str_len, num); |
| | | } else { |
| | | |
| | | pattern_sep_pos_short = patternSeparatorShortPos(pattern, pattern_len); |
| | | pattern_sep_pos_short = (int)patternSeparatorShortPos(pattern, pattern_len); |
| | | |
| | | return compareStr(pattern, pattern_len, str, str_len) || |
| | | compareStr(pattern, pattern_sep_pos_short, str, str_len); |
| | |
| | | int32_t *number_ptr = NULL; |
| | | |
| | | const char * pattern_ptr = pattern; |
| | | int pattern_len = strlen(pattern); |
| | | int pattern_len = (int)strlen(pattern); |
| | | |
| | | const char * cmd_ptr = cmd; |
| | | size_t cmd_len = SCPIDEFINE_strnlen(cmd, len); |
| | |
| | | } |
| | | |
| | | while (1) { |
| | | int pattern_sep_pos = patternSeparatorPos(pattern_ptr, pattern_len); |
| | | int pattern_sep_pos = (int)patternSeparatorPos(pattern_ptr, pattern_len); |
| | | |
| | | cmd_sep_pos = cmdSeparatorPos(cmd_ptr, cmd_len); |
| | | cmd_sep_pos = (int)cmdSeparatorPos(cmd_ptr, cmd_len); |
| | | |
| | | if ((pattern_sep_pos > 0) && pattern_ptr[pattern_sep_pos - 1] == '#') { |
| | | if (numbers && (numbers_idx < numbers_len)) { |
| | |
| | | if (cmd_len == 0) { |
| | | /* verify all subsequent pattern parts are also optional */ |
| | | while (pattern_len) { |
| | | pattern_sep_pos = patternSeparatorPos(pattern_ptr, pattern_len); |
| | | pattern_sep_pos = (int)patternSeparatorPos(pattern_ptr, pattern_len); |
| | | switch (pattern_ptr[pattern_sep_pos]) { |
| | | case '[': |
| | | brackets++; |
| | |
| | | |
| | | //组合复合SCPI命令 |
| | | scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) { |
| | | size_t i; |
| | | int i; |
| | | |
| | | /* Invalid input */ |
| | | if (current == NULL || current->ptr == NULL || current->len == 0) |
| | |
| | | unsigned char c1, c2; |
| | | |
| | | for (; n != 0; n--) { |
| | | c1 = tolower((unsigned char) *s1++); |
| | | c2 = tolower((unsigned char) *s2++); |
| | | c1 = (unsigned char)tolower((unsigned char) *s1++); |
| | | c2 = (unsigned char)tolower((unsigned char) *s2++); |
| | | if (c1 != c2) { |
| | | return c1 - c2; |
| | | } |
| | |
| | | |
| | | if (fi != 0) { |
| | | r1 = r1 * 308 / 1024 - ndigits; |
| | | w2 = bufsize; |
| | | w2 = (int)bufsize; |
| | | while (r1 > 0) { |
| | | fj = modf(fi / 10, &fi); |
| | | r2++; |
| | |
| | | } |
| | | while (fi != 0) { |
| | | fj = modf(fi / 10, &fi); |
| | | buf[--w2] = (int) ((fj + .03) * 10) + '0'; |
| | | buf[--w2] = (char) ((fj + .03) * 10) + '0'; |
| | | r2++; |
| | | } |
| | | while (w2 < (int) bufsize) buf[w1++] = buf[w2++]; |
| | |
| | | while (w1 <= w2 && w1 < (int) bufsize) { |
| | | arg *= 10; |
| | | arg = modf(arg, &fj); |
| | | buf[w1++] = (int) fj + '0'; |
| | | buf[w1++] = (char) fj + '0'; |
| | | } |
| | | if (w2 >= (int) bufsize) { |
| | | buf[bufsize - 1] = '\0'; |