/** * Interface to the application. Adds data to system buffer and try to search * command line termination. If the termination is found or if len=0, command * parser is called. * * @param context * @param data - data to process * @param len - length of data * @return */ int SCPI_Input(scpi_t * context, const char * data, size_t len) { int result = 0; const char * cmd_term; if (len == 0) { context->buffer.data[context->buffer.position] = 0; result = SCPI_Parse(context, context->buffer.data, context->buffer.position); context->buffer.position = 0; } else { size_t buffer_free; int ws; buffer_free = context->buffer.length - context->buffer.position; if (len > (buffer_free - 1)) { return -1; } memcpy(&context->buffer.data[context->buffer.position], data, len); context->buffer.position += len; context->buffer.data[context->buffer.position] = 0; ws = skipWhitespace(context->buffer.data, context->buffer.position); cmd_term = cmdlineTerminator(context->buffer.data + ws, context->buffer.position - ws); while (cmd_term != NULL) { int curr_len = cmd_term - context->buffer.data; result = SCPI_Parse(context, context->buffer.data + ws, curr_len - ws); memmove(context->buffer.data, cmd_term, context->buffer.position - curr_len); context->buffer.position -= curr_len; ws = skipWhitespace(context->buffer.data, context->buffer.position); cmd_term = cmdlineTerminator(context->buffer.data + ws, context->buffer.position - ws); } } return result; }
/** * Interface to the application. Adds data to system buffer and try to search * command line termination. If the termination is found or if len=0, command * parser is called. * * @param context * @param data - data to process * @param len - length of data * @return */ scpi_bool_t SCPI_Input(scpi_t * context, const char * data, int len) { scpi_bool_t result = TRUE; size_t totcmdlen = 0; int cmdlen = 0; if (len == 0) { context->buffer.data[context->buffer.position] = 0; result = SCPI_Parse(context, context->buffer.data, context->buffer.position); context->buffer.position = 0; } else { int buffer_free; buffer_free = context->buffer.length - context->buffer.position; if (len > (buffer_free - 1)) { /* Input buffer overrun - invalidate buffer */ context->buffer.position = 0; context->buffer.data[context->buffer.position] = 0; SCPI_ErrorPush(context, SCPI_ERROR_INPUT_BUFFER_OVERRUN); return FALSE; } memcpy(&context->buffer.data[context->buffer.position], data, len); context->buffer.position += len; context->buffer.data[context->buffer.position] = 0; while (1) { cmdlen = scpiParser_detectProgramMessageUnit(&context->parser_state, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen); totcmdlen += cmdlen; if (context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NL) { result = SCPI_Parse(context, context->buffer.data, totcmdlen); memmove(context->buffer.data, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen); context->buffer.position -= totcmdlen; totcmdlen = 0; } else { if (context->parser_state.programHeader.type == SCPI_TOKEN_UNKNOWN) break; if (totcmdlen >= context->buffer.position) break; } } } return result; }
/** * Interface to the application. Adds data to system buffer and try to search * command line termination. If the termination is found or if len=0, command * parser is called. * * @param context * @param data - data to process * @param len - length of data * @return */ int SCPI_Input(scpi_t * context, const char * data, int len) { int result = 0; size_t totcmdlen = 0; int cmdlen = 0; if (len == 0) { context->buffer.data[context->buffer.position] = 0; result = SCPI_Parse(context, context->buffer.data, context->buffer.position); context->buffer.position = 0; } else { int buffer_free; buffer_free = context->buffer.length - context->buffer.position; if (len > (buffer_free - 1)) { return -1; } memcpy(&context->buffer.data[context->buffer.position], data, len); context->buffer.position += len; context->buffer.data[context->buffer.position] = 0; while (1) { cmdlen = scpiParser_detectProgramMessageUnit(&context->parser_state, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen); totcmdlen += cmdlen; if (context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NL) { result = SCPI_Parse(context, context->buffer.data, totcmdlen); memmove(context->buffer.data, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen); context->buffer.position -= totcmdlen; totcmdlen = 0; } else { if (context->parser_state.programHeader.type == SCPI_TOKEN_UNKNOWN) break; if (totcmdlen >= context->buffer.position) break; } } } return result; }