From 11ffa4398643ff42bd5a1b9d887992cc789a3468 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周二, 27 11月 2012 19:56:26 +0800 Subject: [PATCH] Refactor: rename scpi_context_t to scpi_t --- scpi/scpi_units.h | 4 scpi/scpi.h | 32 ++++---- scpi/scpi_ieee488.h | 26 +++--- test-parser.c | 8 +- scpi/scpi_error.h | 6 scpi/scpi_minimal.h | 16 ++-- scpi/scpi_error.c | 6 scpi/scpi_minimal.c | 16 ++-- scpi/scpi.c | 42 +++++----- scpi/scpi_units.c | 4 scpi/scpi_ieee488.c | 26 +++--- 11 files changed, 93 insertions(+), 93 deletions(-) diff --git a/scpi/scpi.c b/scpi/scpi.c index 19487a0..ad45d8c 100644 --- a/scpi/scpi.c +++ b/scpi/scpi.c @@ -51,9 +51,9 @@ static const char * cmdlineNext(const char * cmd, size_t len); static bool_t cmdMatch(const char * pattern, const char * cmd, size_t len); -static void paramSkipBytes(scpi_context_t * context, size_t num); -static void paramSkipWhitespace(scpi_context_t * context); -static bool_t paramNext(scpi_context_t * context, bool_t mandatory); +static void paramSkipBytes(scpi_t * context, size_t num); +static void paramSkipWhitespace(scpi_t * context); +static bool_t paramNext(scpi_t * context, bool_t mandatory); /* int _strnicmp(const char* s1, const char* s2, size_t len) { @@ -240,7 +240,7 @@ * @param len - lenght of data to be written * @return number of bytes written */ -static inline size_t writeData(scpi_context_t * context, const char * data, size_t len) { +static inline size_t writeData(scpi_t * context, const char * data, size_t len) { return context->interface->write(context, data, len); } @@ -249,7 +249,7 @@ * @param context * @return number of bytes written */ -static inline size_t writeDelimiter(scpi_context_t * context) { +static inline size_t writeDelimiter(scpi_t * context) { if (context->output_count > 0) { return writeData(context, ", ", 2); } else { @@ -262,7 +262,7 @@ * @param context * @return pocet zapsanych znaku */ -static inline size_t writeNewLine(scpi_context_t * context) { +static inline size_t writeNewLine(scpi_t * context) { if (context->output_count > 0) { return writeData(context, "\r\n", 2); } else { @@ -277,7 +277,7 @@ * @param len - command line length * @return 1 if the last evaluated command was found */ -int SCPI_Parse(scpi_context_t * context, const char * data, size_t len) { +int SCPI_Parse(scpi_t * context, const char * data, size_t len) { int32_t i; int result = 0; const char * cmdline_end = data + len; @@ -334,7 +334,7 @@ * @param buffer * @param interface */ -void SCPI_Init(scpi_context_t * context, scpi_command_t * command_list, scpi_buffer_t * buffer, scpi_interface_t * interface) { +void SCPI_Init(scpi_t * context, scpi_command_t * command_list, scpi_buffer_t * buffer, scpi_interface_t * interface) { context->cmdlist = command_list; context->buffer.data = buffer->data; context->buffer.length = buffer->length; @@ -352,7 +352,7 @@ * @param len - length of data * @return */ -int SCPI_Input(scpi_context_t * context, const char * data, size_t len) { +int SCPI_Input(scpi_t * context, const char * data, size_t len) { int result = 0; size_t buffer_free; char * cmd_term; @@ -388,7 +388,7 @@ * @param context * @return */ -bool_t SCPI_DebugCommand(scpi_context_t * context) { +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); @@ -406,7 +406,7 @@ * @param data * @return */ -size_t SCPI_ResultString(scpi_context_t * context, const char * data) { +size_t SCPI_ResultString(scpi_t * context, const char * data) { size_t len = strlen(data); size_t result = 0; result += writeDelimiter(context); @@ -421,7 +421,7 @@ * @param val * @return */ -size_t SCPI_ResultInt(scpi_context_t * context, int32_t val) { +size_t SCPI_ResultInt(scpi_t * context, int32_t val) { char buffer[12]; size_t result = 0; size_t len = longToStr(val, buffer, sizeof (buffer)); @@ -437,7 +437,7 @@ * @param val * @return */ -size_t SCPI_ResultDouble(scpi_context_t * context, double val) { +size_t SCPI_ResultDouble(scpi_t * context, double val) { char buffer[32]; size_t result = 0; size_t len = doubleToStr(val, buffer, sizeof (buffer)); @@ -454,7 +454,7 @@ * @param data * @return */ -size_t SCPI_ResultText(scpi_context_t * context, const char * data) { +size_t SCPI_ResultText(scpi_t * context, const char * data) { size_t result = 0; result += writeDelimiter(context); result += writeData(context, "\"", 1); @@ -471,7 +471,7 @@ * @param context * @param num */ -void paramSkipBytes(scpi_context_t * context, size_t num) { +void paramSkipBytes(scpi_t * context, size_t num) { if (context->paramlist.length < num) { num = context->paramlist.length; } @@ -483,7 +483,7 @@ * Skip white spaces from the beggining of parameters * @param context */ -void paramSkipWhitespace(scpi_context_t * context) { +void paramSkipWhitespace(scpi_t * context) { size_t ws = skipWhitespace(context->paramlist.parameters, context->paramlist.length); paramSkipBytes(context, ws); } @@ -494,7 +494,7 @@ * @param mandatory * @return */ -bool_t paramNext(scpi_context_t * context, bool_t mandatory) { +bool_t paramNext(scpi_t * context, bool_t mandatory) { paramSkipWhitespace(context); if (context->paramlist.length == 0) { if (mandatory) { @@ -523,7 +523,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamInt(scpi_context_t * context, int32_t * value, bool_t mandatory) { +bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory) { char * param; size_t param_len; size_t num_len; @@ -553,7 +553,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamDouble(scpi_context_t * context, double * value, bool_t mandatory) { +bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory) { char * param; size_t param_len; size_t num_len; @@ -584,7 +584,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamString(scpi_context_t * context, char ** value, size_t * len, bool_t mandatory) { +bool_t SCPI_ParamString(scpi_t * context, char ** value, size_t * len, bool_t mandatory) { size_t length; if (!value || !len) { @@ -615,7 +615,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamText(scpi_context_t * context, char ** value, size_t * len, bool_t mandatory) { +bool_t SCPI_ParamText(scpi_t * context, char ** value, size_t * len, bool_t mandatory) { size_t length; if (!value || !len) { diff --git a/scpi/scpi.h b/scpi/scpi.h index 1f9f4c3..8181502 100644 --- a/scpi/scpi.h +++ b/scpi/scpi.h @@ -50,14 +50,14 @@ typedef bool bool_t; //typedef enum { FALSE = 0, TRUE } bool_t; - typedef struct _scpi_context_t scpi_context_t; + typedef struct _scpi_t scpi_t; typedef struct _scpi_param_list_t scpi_param_list_t; typedef struct _scpi_command_t scpi_command_t; typedef struct _scpi_buffer_t scpi_buffer_t; typedef struct _scpi_interface_t scpi_interface_t; - typedef int (*scpi_command_callback_t)(scpi_context_t *); - typedef size_t(*scpi_write_t)(scpi_context_t * context, const char * data, size_t len); - typedef int (*scpi_error_callback_t)(scpi_context_t * context, int_fast16_t error); + typedef int (*scpi_command_callback_t)(scpi_t *); + typedef size_t(*scpi_write_t)(scpi_t * context, const char * data, size_t len); + typedef int (*scpi_error_callback_t)(scpi_t * context, int_fast16_t error); struct _scpi_param_list_t { const scpi_command_t * cmd; @@ -83,7 +83,7 @@ scpi_command_callback_t test; }; - struct _scpi_context_t { + struct _scpi_t { const scpi_command_t * cmdlist; scpi_buffer_t buffer; scpi_param_list_t paramlist; @@ -98,22 +98,22 @@ #define SCPI_CMD_LIST_END {.pattern = NULL, .callback = NULL, } - void SCPI_Init(scpi_context_t * context, scpi_command_t * command_list, scpi_buffer_t * buffer, scpi_interface_t * interface); + void SCPI_Init(scpi_t * context, scpi_command_t * command_list, scpi_buffer_t * buffer, scpi_interface_t * interface); - int SCPI_Input(scpi_context_t * context, const char * data, size_t len); - int SCPI_Parse(scpi_context_t * context, const char * data, size_t len); + int SCPI_Input(scpi_t * context, const char * data, size_t len); + int SCPI_Parse(scpi_t * context, const char * data, size_t len); - size_t SCPI_ResultString(scpi_context_t * context, const char * data); - size_t SCPI_ResultInt(scpi_context_t * context, int32_t val); - size_t SCPI_ResultDouble(scpi_context_t * context, double val); - size_t SCPI_ResultText(scpi_context_t * context, const char * data); + size_t SCPI_ResultString(scpi_t * context, const char * data); + size_t SCPI_ResultInt(scpi_t * context, int32_t val); + size_t SCPI_ResultDouble(scpi_t * context, double val); + size_t SCPI_ResultText(scpi_t * context, const char * data); - bool_t SCPI_ParamInt(scpi_context_t * context, int32_t * value, bool_t mandatory); - bool_t SCPI_ParamDouble(scpi_context_t * context, double * value, bool_t mandatory); - bool_t SCPI_ParamString(scpi_context_t * context, char ** value, size_t * len, bool_t mandatory); + bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory); + bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory); + bool_t SCPI_ParamString(scpi_t * context, char ** value, size_t * len, bool_t mandatory); - bool_t SCPI_DebugCommand(scpi_context_t * context); + bool_t SCPI_DebugCommand(scpi_t * context); //#define SCPI_DEBUG_COMMAND(a) scpi_debug_command(a) #define SCPI_DEBUG_COMMAND(a) diff --git a/scpi/scpi_error.c b/scpi/scpi_error.c index ca80239..8b2aa9e 100644 --- a/scpi/scpi_error.c +++ b/scpi/scpi_error.c @@ -45,7 +45,7 @@ * Clear error queue * @param context - scpi context */ -void SCPI_ErrorClear(scpi_context_t * context) { +void SCPI_ErrorClear(scpi_t * context) { (void) context; scpi_err = 0; } @@ -55,7 +55,7 @@ * @param context - scpi context * @param err - error number */ -void SCPI_ErrorPush(scpi_context_t * context, int16_t err) { +void SCPI_ErrorPush(scpi_t * context, int16_t err) { scpi_err = err; // Command error (e.g. syntax error) @@ -87,7 +87,7 @@ * @param context - scpi context * @return error number */ -int16_t SCPI_ErrorPop(scpi_context_t * context) { +int16_t SCPI_ErrorPop(scpi_t * context) { (void) context; int16_t result = scpi_err; scpi_err = 0; diff --git a/scpi/scpi_error.h b/scpi/scpi_error.h index b5da831..9643054 100644 --- a/scpi/scpi_error.h +++ b/scpi/scpi_error.h @@ -41,9 +41,9 @@ extern "C" { #endif - void SCPI_ErrorClear(scpi_context_t * context); - int16_t SCPI_ErrorPop(scpi_context_t * context); - void SCPI_ErrorPush(scpi_context_t * context, int16_t err); + void SCPI_ErrorClear(scpi_t * context); + int16_t SCPI_ErrorPop(scpi_t * context); + void SCPI_ErrorPush(scpi_t * context, int16_t err); const char * SCPI_ErrorTranslate(int16_t err); #define SCPI_ERROR_SYNTAX -102 diff --git a/scpi/scpi_ieee488.c b/scpi/scpi_ieee488.c index 7474643..809ae33 100644 --- a/scpi/scpi_ieee488.c +++ b/scpi/scpi_ieee488.c @@ -162,7 +162,7 @@ * @param context * @return */ -int SCPI_CoreCls(scpi_context_t * context) { +int SCPI_CoreCls(scpi_t * context) { (void) context; SCPI_EventClear(); SCPI_ErrorClear(context); @@ -176,7 +176,7 @@ * @param context * @return */ -int SCPI_CoreEse(scpi_context_t * context) { +int SCPI_CoreEse(scpi_t * context) { int32_t new_ESE; if (SCPI_ParamInt(context, &new_ESE, TRUE)) { SCPI_RegSet(SCPI_REG_ESE, new_ESE); @@ -189,7 +189,7 @@ * @param context * @return */ -int SCPI_CoreEseQ(scpi_context_t * context) { +int SCPI_CoreEseQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_ESE)); return 0; @@ -200,7 +200,7 @@ * @param context * @return */ -int SCPI_CoreEsrQ(scpi_context_t * context) { +int SCPI_CoreEsrQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_ESR)); SCPI_RegSet(SCPI_REG_ESR, 0); @@ -212,7 +212,7 @@ * @param context * @return */ -int SCPI_CoreIdnQ(scpi_context_t * context) { +int SCPI_CoreIdnQ(scpi_t * context) { (void) context; SCPI_ResultString(context, SCPI_MANUFACTURE); SCPI_ResultString(context, SCPI_DEV_NAME); @@ -225,7 +225,7 @@ * @param context * @return */ -int SCPI_CoreOpc(scpi_context_t * context) { +int SCPI_CoreOpc(scpi_t * context) { (void) context; SCPI_RegSetBits(SCPI_REG_ESR, ESR_OPC); return 0; @@ -236,7 +236,7 @@ * @param context * @return */ -int SCPI_CoreOpcQ(scpi_context_t * context) { +int SCPI_CoreOpcQ(scpi_t * context) { (void) context; // Operation is always completed SCPI_ResultInt(context, 1); @@ -248,7 +248,7 @@ * @param context * @return */ -int SCPI_CoreRst(scpi_context_t * context) { +int SCPI_CoreRst(scpi_t * context) { if (context && context->interface && context->interface->reset) { return context->interface->reset(context); } @@ -260,7 +260,7 @@ * @param context * @return */ -int SCPI_CoreSre(scpi_context_t * context) { +int SCPI_CoreSre(scpi_t * context) { int32_t new_SRE; if (SCPI_ParamInt(context, &new_SRE, TRUE)) { SCPI_RegSet(SCPI_REG_SRE, new_SRE); @@ -273,7 +273,7 @@ * @param context * @return */ -int SCPI_CoreSreQ(scpi_context_t * context) { +int SCPI_CoreSreQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_SRE)); return 0; @@ -284,7 +284,7 @@ * @param context * @return */ -int SCPI_CoreStbQ(scpi_context_t * context) { +int SCPI_CoreStbQ(scpi_t * context) { (void) context; SCPI_ResultInt(context, SCPI_RegGet(SCPI_REG_STB)); return 0; @@ -295,7 +295,7 @@ * @param context * @return */ -int SCPI_CoreTstQ(scpi_context_t * context) { +int SCPI_CoreTstQ(scpi_t * context) { (void) context; int result = 0; if (context && context->interface && context->interface->test) { @@ -310,7 +310,7 @@ * @param context * @return */ -int SCPI_CoreWai(scpi_context_t * context) { +int SCPI_CoreWai(scpi_t * context) { (void) context; // NOP return 0; diff --git a/scpi/scpi_ieee488.h b/scpi/scpi_ieee488.h index 71fcc96..845d88e 100644 --- a/scpi/scpi_ieee488.h +++ b/scpi/scpi_ieee488.h @@ -56,19 +56,19 @@ SCPI_REG_COUNT, } scpi_reg_name_t; -int SCPI_CoreCls(scpi_context_t * context); -int SCPI_CoreEse(scpi_context_t * context); -int SCPI_CoreEseQ(scpi_context_t * context); -int SCPI_CoreEsrQ(scpi_context_t * context); -int SCPI_CoreIdnQ(scpi_context_t * context); -int SCPI_CoreOpc(scpi_context_t * context); -int SCPI_CoreOpcQ(scpi_context_t * context); -int SCPI_CoreRst(scpi_context_t * context); -int SCPI_CoreSre(scpi_context_t * context); -int SCPI_CoreSreQ(scpi_context_t * context); -int SCPI_CoreStbQ(scpi_context_t * context); -int SCPI_CoreTstQ(scpi_context_t * context); -int SCPI_CoreWai(scpi_context_t * context); +int SCPI_CoreCls(scpi_t * context); +int SCPI_CoreEse(scpi_t * context); +int SCPI_CoreEseQ(scpi_t * context); +int SCPI_CoreEsrQ(scpi_t * context); +int SCPI_CoreIdnQ(scpi_t * context); +int SCPI_CoreOpc(scpi_t * context); +int SCPI_CoreOpcQ(scpi_t * context); +int SCPI_CoreRst(scpi_t * context); +int SCPI_CoreSre(scpi_t * context); +int SCPI_CoreSreQ(scpi_t * context); +int SCPI_CoreStbQ(scpi_t * context); +int SCPI_CoreTstQ(scpi_t * context); +int SCPI_CoreWai(scpi_t * context); #define STB_R01 0x01 // Not used diff --git a/scpi/scpi_minimal.c b/scpi/scpi_minimal.c index d998b02..79f6bec 100644 --- a/scpi/scpi_minimal.c +++ b/scpi/scpi_minimal.c @@ -46,7 +46,7 @@ * @param context * @return */ -int SCPI_Stub(scpi_context_t * context) { +int SCPI_Stub(scpi_t * context) { (void) context; return 0; } @@ -56,7 +56,7 @@ * @param context * @return */ -int SCPI_StubQ(scpi_context_t * context) { +int SCPI_StubQ(scpi_t * context) { (void) context; SCPI_ResultString(context, ""); return 0; @@ -67,7 +67,7 @@ * @param context * @return */ -int SCPI_SystemVersionQ(scpi_context_t * context) { +int SCPI_SystemVersionQ(scpi_t * context) { (void) context; SCPI_ResultString(context, SCPI_DEV_VERSION); return 0; @@ -78,7 +78,7 @@ * @param context * @return */ -int SCPI_SystemErrorNextQ(scpi_context_t * context) { +int SCPI_SystemErrorNextQ(scpi_t * context) { (void) context; int16_t err = SCPI_ErrorPop(context); @@ -94,7 +94,7 @@ * @param context * @return */ -int SCPI_StatusQuestionableEventQ(scpi_context_t * context) { +int SCPI_StatusQuestionableEventQ(scpi_t * context) { (void) context; // return value @@ -111,7 +111,7 @@ * @param context * @return */ -int SCPI_StatusQuestionableEnableQ(scpi_context_t * context) { +int SCPI_StatusQuestionableEnableQ(scpi_t * context) { (void) context; // return value @@ -125,7 +125,7 @@ * @param context * @return */ -int SCPI_StatusQuestionableEnable(scpi_context_t * context) { +int SCPI_StatusQuestionableEnable(scpi_t * context) { int32_t new_QUESE; if (SCPI_ParamInt(context, &new_QUESE, TRUE)) { SCPI_RegSet(SCPI_REG_QUESE, new_QUESE); @@ -138,7 +138,7 @@ * @param context * @return */ -int SCPI_StatusPreset(scpi_context_t * context) { +int SCPI_StatusPreset(scpi_t * context) { (void) context; // clear STATUS:... SCPI_RegSet(SCPI_REG_QUES, 0); diff --git a/scpi/scpi_minimal.h b/scpi/scpi_minimal.h index 9afa829..f993bbb 100644 --- a/scpi/scpi_minimal.h +++ b/scpi/scpi_minimal.h @@ -41,15 +41,15 @@ extern "C" { #endif - int SCPI_Stub(scpi_context_t * context); - int SCPI_StubQ(scpi_context_t * context); + int SCPI_Stub(scpi_t * context); + int SCPI_StubQ(scpi_t * context); - int SCPI_SystemVersionQ(scpi_context_t * context); - int SCPI_SystemErrorNextQ(scpi_context_t * context); - int SCPI_StatusQuestionableEventQ(scpi_context_t * context); - int SCPI_StatusQuestionableEnableQ(scpi_context_t * context); - int SCPI_StatusQuestionableEnable(scpi_context_t * context); - int SCPI_StatusPreset(scpi_context_t * context); + int SCPI_SystemVersionQ(scpi_t * context); + int SCPI_SystemErrorNextQ(scpi_t * context); + int SCPI_StatusQuestionableEventQ(scpi_t * context); + int SCPI_StatusQuestionableEnableQ(scpi_t * context); + int SCPI_StatusQuestionableEnable(scpi_t * context); + int SCPI_StatusPreset(scpi_t * context); #ifdef __cplusplus diff --git a/scpi/scpi_units.c b/scpi/scpi_units.c index 723e0d9..591d6e3 100644 --- a/scpi/scpi_units.c +++ b/scpi/scpi_units.c @@ -186,7 +186,7 @@ * @param mandatory if the parameter is mandatory * @return */ -bool_t SCPI_ParamNumber(scpi_context_t * context, scpi_number_t * value, bool_t mandatory) { +bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory) { bool_t result; char * param; size_t len; @@ -231,7 +231,7 @@ } -size_t SCPI_NumberToStr(scpi_context_t * context, scpi_number_t * value, char * str, size_t len) { +size_t SCPI_NumberToStr(scpi_t * context, scpi_number_t * value, char * str, size_t len) { const char * type; const char * unit; size_t result; diff --git a/scpi/scpi_units.h b/scpi/scpi_units.h index 072eb18..d50fdcc 100644 --- a/scpi/scpi_units.h +++ b/scpi/scpi_units.h @@ -93,8 +93,8 @@ #define SCPI_SPECIAL_NUMBERS_LIST_END {.name = NULL, .type = SCPI_NUM_NUMBER} - bool_t SCPI_ParamNumber(scpi_context_t * context, scpi_number_t * value, bool_t mandatory); - size_t SCPI_NumberToStr(scpi_context_t * context, scpi_number_t * value, char * str, size_t len); + bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory); + size_t SCPI_NumberToStr(scpi_t * context, scpi_number_t * value, char * str, size_t len); #ifdef __cplusplus } diff --git a/test-parser.c b/test-parser.c index 2bc38dc..685fc65 100644 --- a/test-parser.c +++ b/test-parser.c @@ -45,7 +45,7 @@ #include "scpi/scpi_utils.h" #include "scpi/scpi_units.h" -int DMM_MeasureVoltageDcQ(scpi_context_t * context) { +int DMM_MeasureVoltageDcQ(scpi_t * context) { scpi_number_t param1, param2; char bf[15]; fprintf(stderr, "meas:volt:dc\r\n"); // debug command name @@ -115,12 +115,12 @@ SCPI_CMD_LIST_END }; -size_t SCPI_Write(scpi_context_t * context, const char * data, size_t len) { +size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { (void) context; return fwrite(data, 1, len, stdout); } -int SCPI_Error(scpi_context_t * context, int_fast16_t err) { +int SCPI_Error(scpi_t * context, int_fast16_t err) { (void) context; fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); @@ -143,7 +143,7 @@ // .data = (char[SCPI_BUFFER_LENGTH]){}, }; -scpi_context_t scpi_context; +scpi_t scpi_context; /* * -- Gitblit v1.9.1