File was renamed from scpi/scpi.c |
| | |
| | | */ |
| | | |
| | | /** |
| | | * @file scpi.c |
| | | * @file scpi_parser.c |
| | | * @date Thu Nov 15 10:58:45 UTC 2012 |
| | | * |
| | | * @brief SCPI parser implementation |
| | |
| | | * |
| | | */ |
| | | |
| | | #include "scpi.h" |
| | | #include "scpi_utils.h" |
| | | #include "scpi_error.h" |
| | | #include <ctype.h> |
| | | #include <string.h> |
| | | #include <stdio.h> |
| | | #include <stdint.h> |
| | | |
| | | #include "scpi_parser.h" |
| | | #include "scpi_utils.h" |
| | | #include "scpi_error.h" |
| | | |
| | | |
| | | static size_t patternSeparatorPos(const char * pattern, size_t len); |
| | | static size_t cmdSeparatorPos(const char * cmd, size_t len); |
| | |
| | | for (i = 0; context->cmdlist[i].pattern != NULL; i++) { |
| | | if (cmdMatch(context->cmdlist[i].pattern, cmdline_ptr, cmd_len)) { |
| | | if (context->cmdlist[i].callback != NULL) { |
| | | context->error = FALSE; |
| | | context->cmd_error = FALSE; |
| | | context->paramlist.cmd = &context->cmdlist[i]; |
| | | context->paramlist.parameters = cmdline_ptr + cmd_len; |
| | | context->paramlist.length = cmdlineSeparatorPos(context->paramlist.parameters, cmdline_end - context->paramlist.parameters); |
| | |
| | | context->input_count = 0; |
| | | |
| | | SCPI_DEBUG_COMMAND(context); |
| | | context->cmdlist[i].callback(context); |
| | | if ((context->cmdlist[i].callback(context) != SCPI_RES_OK) && !context->cmd_error) { |
| | | SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); |
| | | } |
| | | |
| | | writeNewLine(context); // conditionaly write new line |
| | | |
| | | paramSkipWhitespace(context); |
| | | if (context->paramlist.length != 0 && !context->error) { |
| | | if (context->paramlist.length != 0 && !context->cmd_error) { |
| | | SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED); |
| | | } |
| | | |
| | |
| | | context->buffer.length = buffer->length; |
| | | context->buffer.position = 0; |
| | | context->interface = interface; |
| | | SCPI_ErrorInit(context); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * Debug function: show current command and its parameters |
| | | * @param context |
| | | * @return |
| | | */ |
| | | bool_t SCPI_DebugCommand(scpi_t * context) { |
| | | (void) context; |
| | | printf("**DEBUG: %s (\"", context->paramlist.cmd->pattern); |
| | | fwrite(context->paramlist.parameters, 1, context->paramlist.length, stdout); |
| | | printf("\" - %ld)\r\n", context->paramlist.length); |
| | | |
| | | return TRUE; |
| | | } |
| | | |
| | | |
| | | /* writing results */ |
| | | |
| | |
| | | paramSkipBytes(context, 1); |
| | | paramSkipWhitespace(context); |
| | | } else { |
| | | printf("******** :%c:\r\n", context->paramlist.parameters[0]); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SEPARATOR); |
| | | return FALSE; |
| | | } |