| | |
| | | |
| | | #include <ctype.h> |
| | | #include <string.h> |
| | | #include "scpi/externinterface.h" |
| | | |
| | | #include "scpi/config.h" |
| | | #include "scpi/parser.h" |
| | |
| | | #include "scpi/error.h" |
| | | #include "scpi/constants.h" |
| | | #include "scpi/utils.h" |
| | | |
| | | #include "scpi/externinterface.h" |
| | | /** |
| | | * Write data to SCPI output |
| | | * @param context |
| | |
| | | static size_t writeData(scpi_t * context, const char * data, size_t len) { |
| | | if ((len > 0) && (data != NULL)) { |
| | | return 0; |
| | | // return context->interface->write(context, data, len); |
| | | return context->interface->write(context, data, len); |
| | | } else { |
| | | return 0; |
| | | } |
| | |
| | | */ |
| | | |
| | | //负命令回调的执行、参数处理和错误管理 |
| | | 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; |
| | | // 先检测是否为查询命令(以?结尾) |
| | |
| | | * @param context |
| | | * @result TRUE if context->paramlist is filled with correct values |
| | | */ |
| | | static scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len) |
| | | scpi_bool_t findCommandHeader(scpi_t * context, const char * header) |
| | | { |
| | | //参数已经在前面部分解析完成,匹配命令时就不再需要参数部分 将命令拆除即可 |
| | | char *header_copy = strdup(header); |
| | | char *first_part = strtok(header_copy, " "); |
| | | |
| | | int32_t i; |
| | | const scpi_command_t * cmd = NULL; |
| | | for (i = 0; i<context->cmdlistSize; i++) { |
| | | cmd = &context->cmdlist[i]; |
| | | |
| | | bool result =test_match(cmd->pattern, header); |
| | | if(result) |
| | | for(int i=0;i<get_pattern_count();i++) |
| | | { |
| | | if( match_segments_global(first_part,i) ) |
| | | { |
| | | context->param_list.cmd = &context->cmdlist[i]; |
| | | setCurrentIndex(i); |
| | | context->param_list.cmd = &context->cmdlist[i]; |
| | | free(header_copy); |
| | | return TRUE; |
| | | } |
| | | // if (matchCommand(cmd->pattern, header, len, NULL, 0, 0)) { |
| | | // context->param_list.cmd = cmd; |
| | | // return TRUE; |
| | | // } |
| | | } |
| | | context->SCPIerror = RETURN_NotFind; |
| | | context->SCPIerror = RETURN_NotFind; |
| | | return FALSE; |
| | | } |
| | | |
| | |
| | | //命令有效开始处理 |
| | | composeCompoundCommand(&cmd_prev, &state->programHeader); |
| | | //查找命令后并且设置解析状态并且执行命令 |
| | | if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.len)) { |
| | | if (findCommandHeader(context, state->programHeader.ptr)) { |
| | | |
| | | context->param_list.lex_state.buffer = state->programData.ptr; |
| | | context->param_list.lex_state.pos = context->param_list.lex_state.buffer; |
| | |
| | | */ |
| | | scpi_bool_t SCPI_Input(scpi_t * context, const char * data, int len) |
| | | { |
| | | scpi_bool_t result = FALSE; |
| | | clearCurrentGroup(); |
| | | scpi_bool_t result = FALSE; |
| | | size_t totcmdlen = 0; |
| | | int cmdlen = 0; |
| | | //当长度为0时 解析当前的数据 并且清空context的buff标记位 |