| | |
| | | "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libscpi/inc>" |
| | | ) |
| | | |
| | | target_link_libraries(scpi_static PRIVATE Qt::Core) |
| | | |
| | | |
| | | project(scpi_static LANGUAGES CXX) |
| | | |
| | |
| | | #ifndef EXTERNINTERFACE_H |
| | | #define EXTERNINTERFACE_H |
| | | |
| | | //这个类用在做SCPI命令的语法分析,会将词法匹配的结果返回给SCPI库 |
| | | #ifdef __cplusplus |
| | | extern "C" |
| | |
| | | { |
| | | CSegment* segments; |
| | | int segments_count; |
| | | char* commandData; |
| | | |
| | | } CPatternResult; |
| | | |
| | | |
| | |
| | | void parse_pattern_global(const char* pattern); |
| | | int get_pattern_count(); |
| | | void clear_global_patterns(); |
| | | void clearCurrentGroup(); |
| | | void setCurrentIndex(int index); |
| | | |
| | | char* currentPattern(); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | |
| | | #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE |
| | | void SCPI_InitHeap(scpi_t * context, char * error_info_heap, size_t error_info_heap_length); |
| | | #endif |
| | | scpi_bool_t findCommandHeader(scpi_t * context, const char * header,int len); |
| | | scpi_bool_t findCommandHeader(scpi_t * context, const char * header); |
| | | scpi_bool_t SCPI_Input(scpi_t * context, const char * data, int len); |
| | | scpi_bool_t SCPI_Parse(scpi_t * context, char * data, int len); |
| | | |
| | |
| | | int SCPIerror; |
| | | //增加了一个命令列表的长度 防止非法越界 |
| | | int cmdlistSize; |
| | | |
| | | }; |
| | | |
| | | enum _scpi_array_format_t { |
| | |
| | | #include <sstream> |
| | | |
| | | CPatternResult* g_pattern_results = new (std::nothrow) CPatternResult(); |
| | | |
| | | int g_pattern_count = 0; |
| | | |
| | | //static std::vector<std::string_view> currentCommandGroup; |
| | | |
| | | static int currentIndex; |
| | | |
| | | class Segment { |
| | | public: |
| | |
| | | } |
| | | }; |
| | | |
| | | char* currentPattern() |
| | | { |
| | | return g_pattern_results[currentIndex].commandData; |
| | | } |
| | | // 全局管理函数实现 |
| | | void add_pattern_to_global(const std::vector<Segment>& segments) |
| | | void add_pattern_to_global(const char* pattern, const std::vector<Segment>& segments) |
| | | { |
| | | // 重新分配内存 |
| | | CPatternResult* new_results = new CPatternResult[g_pattern_count + 1]; |
| | |
| | | CPatternResult& new_item = new_results[g_pattern_count]; |
| | | new_item.segments_count = static_cast<int>(segments.size()); |
| | | new_item.segments = new CSegment[segments.size()]; |
| | | |
| | | for (size_t i = 0; i < segments.size(); ++i) |
| | | { |
| | | const auto& seg = segments[i]; |
| | |
| | | |
| | | int get_pattern_count() { return g_pattern_count; } |
| | | |
| | | |
| | | void clearCurrentGroup() |
| | | { |
| | | currentIndex = -1; |
| | | //currentCommandGroup.clear(); |
| | | } |
| | | void parse_pattern_global(const char* pattern) |
| | | { |
| | | auto segments = PatternParser::extract_all_segments(pattern); |
| | | add_pattern_to_global(segments); |
| | | add_pattern_to_global(pattern,segments); |
| | | } |
| | | |
| | | void setCurrentIndex(int index) |
| | | { |
| | | currentIndex = index; |
| | | } |
| | | |
| | | //pattern_index 匹配组的下标 |
| | | int match_segments_global(const char* input, int pattern_index) |
| | | { |
| | | if (pattern_index < 0 || pattern_index >= g_pattern_count) |
| | |
| | | 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; |
| | | } |
| | |
| | | * @param context |
| | | * @result TRUE if context->paramlist is filled with correct values |
| | | */ |
| | | 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); |
| | |
| | | { |
| | | if( match_segments_global(first_part,i) ) |
| | | { |
| | | setCurrentIndex(i); |
| | | context->param_list.cmd = &context->cmdlist[i]; |
| | | free(header_copy); |
| | | return TRUE; |
| | |
| | | //命令有效开始处理 |
| | | 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) |
| | | { |
| | | clearCurrentGroup(); |
| | | scpi_bool_t result = FALSE; |
| | | size_t totcmdlen = 0; |
| | | int cmdlen = 0; |