Format and trailing space cleanup
| | |
| | | // do something, if parameter not present |
| | | } |
| | | |
| | | |
| | | |
| | | SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m1, bf, 15); |
| | | fprintf(stderr, "\tP1=%s\r\n", bf); |
| | | |
| | | |
| | | |
| | | SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m2, bf, 15); |
| | | fprintf(stderr, "\tP2=%s\r\n", bf); |
| | | |
| | | SCPI_ResultDouble(context, 0); |
| | | |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | |
| | | static scpi_result_t DMM_MeasureVoltageAcQ(scpi_t * context) { |
| | | scpi_number_t param1, param2; |
| | |
| | | // do something, if parameter not present |
| | | } |
| | | |
| | | |
| | | |
| | | SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m1, bf, 15); |
| | | fprintf(stderr, "\tP1=%s\r\n", bf); |
| | | |
| | | |
| | | |
| | | SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m2, bf, 15); |
| | | fprintf(stderr, "\tP2=%s\r\n", bf); |
| | | |
| | | SCPI_ResultDouble(context, 0); |
| | | |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | SCPI_CHOICE_LIST_END /* termination of option list */ |
| | | }; |
| | | |
| | | |
| | | static scpi_result_t TEST_ChoiceQ(scpi_t * context) { |
| | | |
| | | int32_t param; |
| | | const char * name; |
| | | |
| | | |
| | | if (!SCPI_ParamChoice(context, trigger_source, ¶m, TRUE)) { |
| | | return SCPI_RES_ERR; |
| | | } |
| | | |
| | | |
| | | SCPI_ChoiceToName(trigger_source, param, &name); |
| | | fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long int)param); |
| | | |
| | | fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long int) param); |
| | | |
| | | SCPI_ResultInt32(context, param); |
| | | |
| | | return SCPI_RES_OK; |
| | |
| | | char buffer[100]; |
| | | size_t copy_len; |
| | | |
| | | if (!SCPI_ParamCopyText(context, buffer, sizeof(buffer), ©_len, FALSE)) { |
| | | if (!SCPI_ParamCopyText(context, buffer, sizeof (buffer), ©_len, FALSE)) { |
| | | buffer[0] = '\0'; |
| | | } |
| | | |
| | |
| | | |
| | | scpi_t scpi_context = { |
| | | .cmdlist = scpi_commands, |
| | | .buffer = { |
| | | .buffer = |
| | | { |
| | | .length = SCPI_INPUT_BUFFER_LENGTH, |
| | | .data = scpi_input_buffer, |
| | | }, |
| | | .interface = &scpi_interface, |
| | | .registers = scpi_regs, |
| | | .units = scpi_units_def, |
| | | .idn = {"MANUFACTURE", "INSTR2013", NULL, "01-02"}, |
| | | .idn = |
| | | {"MANUFACTURE", "INSTR2013", NULL, "01-02"}, |
| | | }; |
| | | |
| | |
| | | // do something, if parameter not present |
| | | } |
| | | |
| | | |
| | | |
| | | SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m1, bf, 15); |
| | | fprintf(stderr, "\tP1=%s\r\n", bf); |
| | | |
| | | |
| | | |
| | | SCPI_NumberToStr(context, scpi_special_numbers_def, ¶m2, bf, 15); |
| | | fprintf(stderr, "\tP2=%s\r\n", bf); |
| | | |
| | | SCPI_ResultDouble(context, 0); |
| | | |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | |
| | | scpi_result_t DMM_MeasureVoltageAcQ(scpi_t * context) { |
| | | scpi_number_t param1, param2; |
| | |
| | | SCPI_CHOICE_LIST_END /* termination of option list */ |
| | | }; |
| | | |
| | | |
| | | scpi_result_t TEST_ChoiceQ(scpi_t * context) { |
| | | |
| | | int32_t param; |
| | |
| | | } |
| | | |
| | | SCPI_ChoiceToName(trigger_source, param, &name); |
| | | fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long int)param); |
| | | fprintf(stderr, "\tP1=%s (%ld)\r\n", name, (long int) param); |
| | | |
| | | SCPI_ResultInt32(context, param); |
| | | |
| | |
| | | |
| | | scpi_result_t TEST_Numbers(scpi_t * context) { |
| | | |
| | | fprintf(stderr, "RAW CMD %.*s\r\n", (int)context->param_list.cmd_raw.length, context->param_list.cmd_raw.data); |
| | | fprintf(stderr, "RAW CMD %.*s\r\n", (int) context->param_list.cmd_raw.length, context->param_list.cmd_raw.data); |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | |
| | | char buffer[100]; |
| | | size_t copy_len; |
| | | |
| | | if(!SCPI_ParamCopyText(context, buffer, sizeof(buffer), ©_len, false)) { |
| | | if (!SCPI_ParamCopyText(context, buffer, sizeof (buffer), ©_len, false)) { |
| | | buffer[0] = '\0'; |
| | | } |
| | | |
| | |
| | | |
| | | scpi_t scpi_context = { |
| | | /* cmdlist */ scpi_commands, |
| | | /* buffer */ { /* length */ SCPI_INPUT_BUFFER_LENGTH, /* position */ 0, /* data */ scpi_input_buffer}, |
| | | /* param_list */ { /* cmd */ NULL, /* lex_state */ {NULL, NULL, 0}, /* cmd_raw */ {0, 0, NULL}}, |
| | | /* buffer */ |
| | | { /* length */ SCPI_INPUT_BUFFER_LENGTH, /* position */ 0, /* data */ scpi_input_buffer}, |
| | | /* param_list */ |
| | | { /* cmd */ NULL, /* lex_state */ |
| | | {NULL, NULL, 0}, /* cmd_raw */ |
| | | {0, 0, NULL}}, |
| | | /* interface */ &scpi_interface, |
| | | /* output_count */ 0, |
| | | /* input_count */ 0, |
| | |
| | | /* registers */ scpi_regs, |
| | | /* units */ scpi_units_def, |
| | | /* user_context */ NULL, |
| | | /* parser_state */ { /* programHeader */ {SCPI_TOKEN_UNKNOWN, NULL, 0}, /* programData */ {SCPI_TOKEN_UNKNOWN, NULL, 0}, /* numberOfParameters */ 0, /* termination */ SCPI_MESSAGE_TERMINATION_NONE}, |
| | | /* idn */ {"MANUFACTURE", "INSTR2013", NULL, "01-02"}, |
| | | /* parser_state */ |
| | | { /* programHeader */ |
| | | {SCPI_TOKEN_UNKNOWN, NULL, 0}, /* programData */ |
| | | {SCPI_TOKEN_UNKNOWN, NULL, 0}, /* numberOfParameters */ 0, /* termination */ SCPI_MESSAGE_TERMINATION_NONE |
| | | }, |
| | | /* idn */ |
| | | {"MANUFACTURE", "INSTR2013", NULL, "01-02"}, |
| | | }; |
| | | |
| | |
| | | #include <userint.h> |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | extern "C" { |
| | | #endif |
| | | |
| | | /* Panels and Controls: */ |
| | | /* Panels and Controls: */ |
| | | |
| | | #define PANEL 1 |
| | | #define PANEL_OUTPUTDEBUG 2 /* control type: textBox, callback function: (none) */ |
| | |
| | | #define PANEL_LEDSRQ 59 /* control type: LED, callback function: (none) */ |
| | | |
| | | |
| | | /* Control Arrays: */ |
| | | /* Control Arrays: */ |
| | | |
| | | /* (no control arrays in the resource file) */ |
| | | /* (no control arrays in the resource file) */ |
| | | |
| | | |
| | | /* Menu Bars, Menus, and Menu Items: */ |
| | | /* Menu Bars, Menus, and Menu Items: */ |
| | | |
| | | /* (no menu bars in the resource file) */ |
| | | /* (no menu bars in the resource file) */ |
| | | |
| | | |
| | | /* Callback Prototypes: */ |
| | | /* Callback Prototypes: */ |
| | | |
| | | int CVICALLBACK cb_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
| | | int CVICALLBACK cb_scpi_input(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
| | | int CVICALLBACK cb_quit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
| | | int CVICALLBACK cb_scpi_input(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
| | | |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | } |
| | | #endif |
| | |
| | | |
| | | /* helper function to remove <LF> and <CR> from the end of a string */ |
| | | /* this is needed only here for the GUI, there is a 'insert line to a text box' function */ |
| | | |
| | | /* that automatically adds a new line, so this prohibits double line feeds for the GUI */ |
| | | void removeTrailingEndcodes(char *buf) |
| | | { |
| | | int len; |
| | | len = strlen(buf); |
| | | |
| | | while(len > 0) |
| | | { |
| | | len--; |
| | | switch(buf[len]) |
| | | { |
| | | case '\n' : |
| | | case '\r' : |
| | | buf[len] = '\0'; |
| | | break; |
| | | default : |
| | | len = 0; // stop loop |
| | | break; |
| | | } |
| | | } |
| | | void removeTrailingEndcodes(char *buf) { |
| | | int len; |
| | | len = strlen(buf); |
| | | |
| | | while (len > 0) { |
| | | len--; |
| | | switch (buf[len]) { |
| | | case '\n': |
| | | case '\r': |
| | | buf[len] = '\0'; |
| | | break; |
| | | default: |
| | | len = 0; // stop loop |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /* wrapper for debugging output, collects debug output until a <LF> */ |
| | | |
| | | /* is received, then removes the <LF> and outputs the line on the GUI */ |
| | | void debug_output(char *buf) |
| | | { |
| | | static char pbuf[512]; |
| | | static int pos = 0; |
| | | int len; |
| | | |
| | | len = strlen(buf); |
| | | if(buf[len-1] == '\n') |
| | | { |
| | | buf[len-1] == '\0'; |
| | | len--; |
| | | memcpy(&pbuf[pos], buf, len); |
| | | pos = 0; |
| | | InsertTextBoxLine (panelHandle, PANEL_OUTPUTDEBUG, -1, pbuf); |
| | | } |
| | | else |
| | | { |
| | | memcpy(&pbuf[pos], buf, len); |
| | | pos += len; |
| | | } |
| | | |
| | | void debug_output(char *buf) { |
| | | static char pbuf[512]; |
| | | static int pos = 0; |
| | | int len; |
| | | |
| | | len = strlen(buf); |
| | | if (buf[len - 1] == '\n') { |
| | | buf[len - 1] == '\0'; |
| | | len--; |
| | | memcpy(&pbuf[pos], buf, len); |
| | | pos = 0; |
| | | InsertTextBoxLine(panelHandle, PANEL_OUTPUTDEBUG, -1, pbuf); |
| | | } else { |
| | | memcpy(&pbuf[pos], buf, len); |
| | | pos += len; |
| | | } |
| | | |
| | | } |
| | | |
| | | size_t SCPI_Write(scpi_t * context, const char * data, size_t len) |
| | | { |
| | | if((SCPI_outputBuffer_idx + len) > (SCPI_OUPUT_BUFFER_SIZE-1)) |
| | | { |
| | | len = (SCPI_OUPUT_BUFFER_SIZE-1) - SCPI_outputBuffer_idx; // limit length to left over space |
| | | // apparently there is no mechanism to cope with buffers that are too small |
| | | } |
| | | memcpy(&SCPI_outputBuffer[SCPI_outputBuffer_idx], data, len); |
| | | SCPI_outputBuffer_idx += len; |
| | | |
| | | SCPI_outputBuffer[SCPI_outputBuffer_idx] = '\0'; |
| | | // return fwrite(data, 1, len, stdout); |
| | | return len; |
| | | size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
| | | if ((SCPI_outputBuffer_idx + len) > (SCPI_OUPUT_BUFFER_SIZE - 1)) { |
| | | len = (SCPI_OUPUT_BUFFER_SIZE - 1) - SCPI_outputBuffer_idx; // limit length to left over space |
| | | // apparently there is no mechanism to cope with buffers that are too small |
| | | } |
| | | memcpy(&SCPI_outputBuffer[SCPI_outputBuffer_idx], data, len); |
| | | SCPI_outputBuffer_idx += len; |
| | | |
| | | SCPI_outputBuffer[SCPI_outputBuffer_idx] = '\0'; |
| | | // return fwrite(data, 1, len, stdout); |
| | | return len; |
| | | } |
| | | |
| | | scpi_result_t SCPI_Flush(scpi_t * context) |
| | | { |
| | | // fwrite(SCPI_outputBuffer, 1, SCPI_outputBuffer_idx, stdout); |
| | | removeTrailingEndcodes(SCPI_outputBuffer); |
| | | InsertTextBoxLine (panelHandle, PANEL_OUTPUT, -1, SCPI_outputBuffer); |
| | | SCPI_outputBuffer_idx = 0; |
| | | return SCPI_RES_OK; |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | // fwrite(SCPI_outputBuffer, 1, SCPI_outputBuffer_idx, stdout); |
| | | removeTrailingEndcodes(SCPI_outputBuffer); |
| | | InsertTextBoxLine(panelHandle, PANEL_OUTPUT, -1, SCPI_outputBuffer); |
| | | SCPI_outputBuffer_idx = 0; |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | int SCPI_Error(scpi_t * context, int_fast16_t err) |
| | | { |
| | | char buf[512]; |
| | | |
| | | // fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (int16_t) err, SCPI_ErrorTranslate(err)); |
| | | sprintf(buf, "**ERROR: %d, \"%s\"", (int16_t) err, SCPI_ErrorTranslate(err)); |
| | | InsertTextBoxLine (panelHandle, PANEL_OUTPUTERR, -1, buf); |
| | | return 0; |
| | | int SCPI_Error(scpi_t * context, int_fast16_t err) { |
| | | char buf[512]; |
| | | |
| | | // fprintf(stderr, "**ERROR: %d, \"%s\"\r\n", (int16_t) err, SCPI_ErrorTranslate(err)); |
| | | sprintf(buf, "**ERROR: %d, \"%s\"", (int16_t) err, SCPI_ErrorTranslate(err)); |
| | | InsertTextBoxLine(panelHandle, PANEL_OUTPUTERR, -1, buf); |
| | | return 0; |
| | | } |
| | | |
| | | scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { |
| | |
| | | } |
| | | |
| | | scpi_result_t SCPI_Reset(scpi_t * context) { |
| | | char buf[256]; |
| | | // fprintf(stderr, "**Reset\r\n"); |
| | | sprintf(buf, "**Reset\r\n"); |
| | | debug_output(buf); |
| | | char buf[256]; |
| | | // fprintf(stderr, "**Reset\r\n"); |
| | | sprintf(buf, "**Reset\r\n"); |
| | | debug_output(buf); |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | return SCPI_RES_ERR; |
| | | } |
| | | |
| | | |
| | | /* |
| | | * |
| | | */ |
| | | int main(int argc, char** argv) |
| | | { |
| | | int result; |
| | | int main(int argc, char** argv) { |
| | | int result; |
| | | |
| | | SCPI_Init(&scpi_context); |
| | | SCPI_Init(&scpi_context); |
| | | |
| | | if (InitCVIRTE (0, argv, 0) == 0) |
| | | return -1; /* out of memory */ |
| | | if ((panelHandle = LoadPanel (0, "TestLibscpi.uir", PANEL)) < 0) |
| | | return -1; |
| | | DisplayPanel (panelHandle); |
| | | if (InitCVIRTE(0, argv, 0) == 0) |
| | | return -1; /* out of memory */ |
| | | if ((panelHandle = LoadPanel(0, "TestLibscpi.uir", PANEL)) < 0) |
| | | return -1; |
| | | DisplayPanel(panelHandle); |
| | | |
| | | updateSSCPIRegister(); |
| | | updateSSCPIRegister(); |
| | | |
| | | RunUserInterface (); |
| | | DiscardPanel (panelHandle); |
| | | RunUserInterface(); |
| | | DiscardPanel(panelHandle); |
| | | |
| | | return (EXIT_SUCCESS); |
| | | return (EXIT_SUCCESS); |
| | | } |
| | | |
| | | |
| | | void updateSSCPIRegister(void) |
| | | { |
| | | updateSTB(); |
| | | updateSRE(); |
| | | updateESR(); |
| | | updateESE(); |
| | | void updateSSCPIRegister(void) { |
| | | updateSTB(); |
| | | updateSRE(); |
| | | updateESR(); |
| | | updateESE(); |
| | | } |
| | | |
| | | void updateSTB(void) |
| | | { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_STB); |
| | | void updateSTB(void) { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | gui_updateSTB((uint8_t)(0x00FF & regVal)); |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_STB); |
| | | |
| | | gui_updateSTB((uint8_t) (0x00FF & regVal)); |
| | | } |
| | | |
| | | void updateESR(void) |
| | | { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_ESR); |
| | | void updateESR(void) { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | gui_updateESR((uint8_t)(0x00FF & regVal)); |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_ESR); |
| | | |
| | | gui_updateESR((uint8_t) (0x00FF & regVal)); |
| | | } |
| | | |
| | | void updateESE(void) |
| | | { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_ESE); |
| | | void updateESE(void) { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | gui_updateESE((uint8_t)(0x00FF & regVal)); |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_ESE); |
| | | |
| | | gui_updateESE((uint8_t) (0x00FF & regVal)); |
| | | } |
| | | |
| | | void updateSRE(void) |
| | | { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_SRE); |
| | | void updateSRE(void) { |
| | | scpi_reg_val_t regVal; |
| | | |
| | | gui_updateSRE((uint8_t)(0x00FF & regVal)); |
| | | regVal = SCPI_RegGet(&scpi_context, SCPI_REG_SRE); |
| | | |
| | | gui_updateSRE((uint8_t) (0x00FF & regVal)); |
| | | } |
| | | |
| | | |
| | | /* |
| | | * The CALLBACK functions below are called from the CVI runtime engine when |
| | | * user clicks on buttons, inputs data on the GUI etc. |
| | | */ |
| | | int CVICALLBACK cb_scpi_input (int panel, int control, int event, |
| | | void *callbackData, int eventData1, int eventData2) |
| | | { |
| | | char buf[256]; |
| | | int len; |
| | | |
| | | switch (event) |
| | | { |
| | | case EVENT_COMMIT: |
| | | GetCtrlVal(panel, control, buf); |
| | | /* we have to add a endcode to make SCPI accept the string, here a <LF> is added */ |
| | | len = strlen(buf); |
| | | buf[len] = '\n'; |
| | | len++; |
| | | SCPI_Input(&scpi_context, buf, len); |
| | | |
| | | updateSSCPIRegister(); |
| | | break; |
| | | } |
| | | return 0; |
| | | int CVICALLBACK cb_scpi_input(int panel, int control, int event, |
| | | void *callbackData, int eventData1, int eventData2) { |
| | | char buf[256]; |
| | | int len; |
| | | |
| | | switch (event) { |
| | | case EVENT_COMMIT: |
| | | GetCtrlVal(panel, control, buf); |
| | | /* we have to add a endcode to make SCPI accept the string, here a <LF> is added */ |
| | | len = strlen(buf); |
| | | buf[len] = '\n'; |
| | | len++; |
| | | SCPI_Input(&scpi_context, buf, len); |
| | | |
| | | updateSSCPIRegister(); |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | int CVICALLBACK cb_quit (int panel, int control, int event, |
| | | void *callbackData, int eventData1, int eventData2) |
| | | { |
| | | switch (event) |
| | | { |
| | | case EVENT_COMMIT: |
| | | QuitUserInterface (0); |
| | | break; |
| | | } |
| | | return 0; |
| | | int CVICALLBACK cb_quit(int panel, int control, int event, |
| | | void *callbackData, int eventData1, int eventData2) { |
| | | switch (event) { |
| | | case EVENT_COMMIT: |
| | | QuitUserInterface(0); |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | /* |
| | | * Helper functions for GUI |
| | | */ |
| | | void gui_updateSTB(uint8_t newSTB) |
| | | { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newSTB); |
| | | SetCtrlVal(panelHandle, PANEL_STBHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_STB0, (newSTB & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_STB1, (newSTB & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_STB2, (newSTB & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_STB3, (newSTB & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_STB4, (newSTB & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_STB5, (newSTB & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_STB6, (newSTB & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_STB7, (newSTB & 0x80)); |
| | | |
| | | if(0x00 == (newSTB & 0x40)) SetCtrlVal(panelHandle, PANEL_LEDSRQ, 0); |
| | | void gui_updateSTB(uint8_t newSTB) { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newSTB); |
| | | SetCtrlVal(panelHandle, PANEL_STBHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_STB0, (newSTB & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_STB1, (newSTB & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_STB2, (newSTB & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_STB3, (newSTB & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_STB4, (newSTB & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_STB5, (newSTB & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_STB6, (newSTB & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_STB7, (newSTB & 0x80)); |
| | | |
| | | if (0x00 == (newSTB & 0x40)) SetCtrlVal(panelHandle, PANEL_LEDSRQ, 0); |
| | | |
| | | } |
| | | |
| | | void gui_updateESR(uint8_t newESR) |
| | | { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newESR); |
| | | SetCtrlVal(panelHandle, PANEL_ESRHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_ESR0, (newESR & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR1, (newESR & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR2, (newESR & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR3, (newESR & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR4, (newESR & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR5, (newESR & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR6, (newESR & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR7, (newESR & 0x80)); |
| | | void gui_updateESR(uint8_t newESR) { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newESR); |
| | | SetCtrlVal(panelHandle, PANEL_ESRHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_ESR0, (newESR & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR1, (newESR & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR2, (newESR & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR3, (newESR & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR4, (newESR & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR5, (newESR & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR6, (newESR & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_ESR7, (newESR & 0x80)); |
| | | } |
| | | |
| | | void gui_updateESE(uint8_t newESE) |
| | | { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newESE); |
| | | SetCtrlVal(panelHandle, PANEL_ESEHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_ESE0, (newESE & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE1, (newESE & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE2, (newESE & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE3, (newESE & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE4, (newESE & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE5, (newESE & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE6, (newESE & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE7, (newESE & 0x80)); |
| | | void gui_updateESE(uint8_t newESE) { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newESE); |
| | | SetCtrlVal(panelHandle, PANEL_ESEHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_ESE0, (newESE & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE1, (newESE & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE2, (newESE & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE3, (newESE & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE4, (newESE & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE5, (newESE & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE6, (newESE & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_ESE7, (newESE & 0x80)); |
| | | } |
| | | |
| | | void gui_updateSRE(uint8_t newSRE) |
| | | { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newSRE); |
| | | SetCtrlVal(panelHandle, PANEL_SREHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_SRE0, (newSRE & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE1, (newSRE & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE2, (newSRE & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE3, (newSRE & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE4, (newSRE & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE5, (newSRE & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE6, (newSRE & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE7, (newSRE & 0x80)); |
| | | void gui_updateSRE(uint8_t newSRE) { |
| | | char buf[5]; |
| | | |
| | | sprintf(buf, "0x%02X", newSRE); |
| | | SetCtrlVal(panelHandle, PANEL_SREHEX, buf); |
| | | |
| | | SetCtrlVal(panelHandle, PANEL_SRE0, (newSRE & 0x01)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE1, (newSRE & 0x02)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE2, (newSRE & 0x04)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE3, (newSRE & 0x08)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE4, (newSRE & 0x10)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE5, (newSRE & 0x20)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE6, (newSRE & 0x40)); |
| | | SetCtrlVal(panelHandle, PANEL_SRE7, (newSRE & 0x80)); |
| | | } |
| | |
| | | //fd_set fds; |
| | | } user_data_t; |
| | | |
| | | struct _queue_event_t |
| | | { |
| | | struct _queue_event_t { |
| | | uint8_t cmd; |
| | | uint8_t param1; |
| | | int16_t param2; |
| | | } __attribute__ ((__packed__)); |
| | | } __attribute__((__packed__)); |
| | | typedef struct _queue_event_t queue_event_t; |
| | | |
| | | |
| | |
| | | |
| | | size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *)(context->user_context); |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->io) { |
| | | return (netconn_write(u->io, data, len, NETCONN_NOCOPY) == ERR_OK) ? len : 0; |
| | | } |
| | |
| | | |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *)(context->user_context); |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->io) { |
| | | /* flush not implemented */ |
| | | return SCPI_RES_OK; |
| | |
| | | // BEEP |
| | | iprintf("**ERROR: %ld, \"%s\"\r\n", (int32_t) err, SCPI_ErrorTranslate(err)); |
| | | if (err != 0) { |
| | | /* New error */ |
| | | /* New error */ |
| | | /* Beep */ |
| | | /* Error LED ON */ |
| | | /* Error LED ON */ |
| | | } else { |
| | | /* No more errors in the queue */ |
| | | /* No more errors in the queue */ |
| | | /* Error LED OFF */ |
| | | } |
| | | return 0; |
| | |
| | | } else { |
| | | iprintf("**CTRL %02x: 0x%X (%d)\r\n", ctrl, val, val); |
| | | } |
| | | |
| | | |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *)(context->user_context); |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->control_io) { |
| | | snprintf(b, sizeof(b), "SRQ%d\r\n", val); |
| | | snprintf(b, sizeof (b), "SRQ%d\r\n", val); |
| | | return netconn_write(u->control_io, b, strlen(b), NETCONN_NOCOPY) == ERR_OK ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | } |
| | | } |
| | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | |
| | | static void setEseReq(void) { |
| | | SCPI_RegSetBits(&scpi_context, SCPI_REG_ESR, ESR_REQ); |
| | | } |
| | |
| | | void SCPI_RequestControl(void) { |
| | | queue_event_t msg; |
| | | msg.cmd = SCPI_MSG_SET_ESE_REQ; |
| | | |
| | | /* Avoid sending evtQueue message if ESR_REQ is already set |
| | | if((SCPI_RegGet(&scpi_context, SCPI_REG_ESR) & ESR_REQ) == 0) { |
| | | xQueueSend(user_data.evtQueue, &msg, 1000); |
| | | } |
| | | */ |
| | | |
| | | xQueueSend(user_data.evtQueue, &msg, 1000); |
| | | /* Avoid sending evtQueue message if ESR_REQ is already set |
| | | if((SCPI_RegGet(&scpi_context, SCPI_REG_ESR) & ESR_REQ) == 0) { |
| | | xQueueSend(user_data.evtQueue, &msg, 1000); |
| | | } |
| | | */ |
| | | |
| | | xQueueSend(user_data.evtQueue, &msg, 1000); |
| | | } |
| | | |
| | | void SCPI_AddError(int16_t err) { |
| | |
| | | msg.cmd = SCPI_MSG_SET_ERROR; |
| | | msg.param2 = err; |
| | | |
| | | xQueueSend(user_data.evtQueue, &msg, 1000); |
| | | xQueueSend(user_data.evtQueue, &msg, 1000); |
| | | } |
| | | |
| | | void scpi_netconn_callback(struct netconn * conn, enum netconn_evt evt, u16_t len) { |
| | |
| | | static void scpi_server_thread(void *arg) { |
| | | queue_event_t evt; |
| | | |
| | | (void)arg; |
| | | (void) arg; |
| | | |
| | | user_data.evtQueue = xQueueCreate(10, sizeof(queue_event_t)); |
| | | user_data.evtQueue = xQueueCreate(10, sizeof (queue_event_t)); |
| | | |
| | | // user_context will be pointer to socket |
| | | scpi_context.user_context = &user_data; |
| | |
| | | user_data.io_listen = createServer(DEVICE_PORT); |
| | | user_data.control_io_listen = createServer(CONTROL_PORT); |
| | | |
| | | while(1) { |
| | | while (1) { |
| | | waitServer(&user_data, &evt); |
| | | |
| | | if (evt.cmd == SCPI_MSG_TIMEOUT) { // timeout |
| | |
| | | if (evt.cmd == SCPI_MSG_SET_ESE_REQ) { |
| | | setEseReq(); |
| | | } |
| | | |
| | | |
| | | if (evt.cmd == SCPI_MSG_SET_ERROR) { |
| | | setError(evt.param2); |
| | | } |
| | |
| | | return fwrite(data, 1, len, stdout); |
| | | } |
| | | |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | scpi_result_t SCPI_SystemCommTcpipControlQ(scpi_t * context) { |
| | | return SCPI_RES_ERR; |
| | | } |
| | | |
| | | /* |
| | | * |
| | | */ |
| | |
| | | printf("SCPI Interactive demo\r\n"); |
| | | char smbuffer[10]; |
| | | while (1) { |
| | | if (NULL == fgets(smbuffer, 10, stdin)) { |
| | | break; |
| | | } |
| | | SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); |
| | | if (NULL == fgets(smbuffer, 10, stdin)) { |
| | | break; |
| | | } |
| | | SCPI_Input(&scpi_context, smbuffer, strlen(smbuffer)); |
| | | } |
| | | |
| | | |
| | |
| | | return fwrite(data, 1, len, stdout); |
| | | } |
| | | |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | TEST_SCPI_INPUT("*ESE\r\n"); // cause error -109, missing parameter |
| | | TEST_SCPI_INPUT("*ESE #H20\r\n"); |
| | | |
| | | TEST_SCPI_INPUT("*SRE #HFF\r\n"); |
| | | |
| | | TEST_SCPI_INPUT("*SRE #HFF\r\n"); |
| | | |
| | | TEST_SCPI_INPUT("IDN?\r\n"); // cause error -113, undefined header |
| | | |
| | | TEST_SCPI_INPUT("SYST:ERR?\r\n"); |
| | |
| | | |
| | | #define CONTROL_PORT 5026 |
| | | |
| | | |
| | | |
| | | typedef struct { |
| | | int io; |
| | | int io_listen; |
| | |
| | | |
| | | size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *)(context->user_context); |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->fio) { |
| | | return fwrite(data, 1, len, u->fio); |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *)(context->user_context); |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->fio) { |
| | | return fflush(u->fio) == 0 ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | } |
| | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { |
| | | char b[16]; |
| | | |
| | |
| | | } else { |
| | | fprintf(stderr, "**CTRL %02x: 0x%X (%d)\r\n", ctrl, val, val); |
| | | } |
| | | |
| | | |
| | | if (context->user_context != NULL) { |
| | | user_data_t * u = (user_data_t *)(context->user_context); |
| | | user_data_t * u = (user_data_t *) (context->user_context); |
| | | if (u->control_io >= 0) { |
| | | snprintf(b, sizeof(b), "SRQ%d\r\n", val); |
| | | snprintf(b, sizeof (b), "SRQ%d\r\n", val); |
| | | return write(u->control_io, b, strlen(b)) > 0 ? SCPI_RES_OK : SCPI_RES_ERR; |
| | | } |
| | | } |
| | | } |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | int rc; |
| | | int on = 1; |
| | | struct sockaddr_in servaddr; |
| | | |
| | | |
| | | /* Configure TCP Server */ |
| | | bzero(&servaddr, sizeof(servaddr)); |
| | | bzero(&servaddr, sizeof (servaddr)); |
| | | servaddr.sin_family = AF_INET; |
| | | servaddr.sin_addr.s_addr=htonl(INADDR_ANY); |
| | | servaddr.sin_port=htons(port); |
| | | |
| | | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); |
| | | servaddr.sin_port = htons(port); |
| | | |
| | | /* Create socket */ |
| | | fd = socket(AF_INET,SOCK_STREAM, 0); |
| | | if (fd < 0) |
| | | { |
| | | fd = socket(AF_INET, SOCK_STREAM, 0); |
| | | if (fd < 0) { |
| | | perror("socket() failed"); |
| | | exit(-1); |
| | | } |
| | | |
| | | } |
| | | |
| | | /* Set address reuse enable */ |
| | | rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); |
| | | if (rc < 0) |
| | | { |
| | | rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)); |
| | | if (rc < 0) { |
| | | perror("setsockopt() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | /* Set non blocking */ |
| | | rc = ioctl(fd, FIONBIO, (char *)&on); |
| | | if (rc < 0) |
| | | { |
| | | rc = ioctl(fd, FIONBIO, (char *) &on); |
| | | if (rc < 0) { |
| | | perror("ioctl() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | } |
| | | |
| | | /* Bind to socket */ |
| | | rc = bind(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)); |
| | | if (rc < 0) |
| | | { |
| | | rc = bind(fd, (struct sockaddr *) &servaddr, sizeof (servaddr)); |
| | | if (rc < 0) { |
| | | perror("bind() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | /* Listen on socket */ |
| | | listen(fd, 1); |
| | | if (rc < 0) |
| | | { |
| | | if (rc < 0) { |
| | | perror("listen() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | return fd; |
| | | } |
| | | |
| | | static int waitServer(user_data_t * user_data) { |
| | | struct timeval timeout; |
| | | int rc; |
| | | |
| | | |
| | | FD_ZERO(&user_data->fds); |
| | | |
| | | if (user_data->io >= 0) { |
| | | FD_SET(user_data->io, &user_data->fds); |
| | | } |
| | | |
| | | |
| | | if (user_data->io_listen >= 0) { |
| | | FD_SET(user_data->io_listen, &user_data->fds); |
| | | } |
| | | |
| | | |
| | | if (user_data->control_io >= 0) { |
| | | FD_SET(user_data->control_io, &user_data->fds); |
| | | } |
| | | |
| | | |
| | | if (user_data->control_io_listen >= 0) { |
| | | FD_SET(user_data->control_io_listen, &user_data->fds); |
| | | } |
| | | |
| | | timeout.tv_sec = 5; |
| | | |
| | | timeout.tv_sec = 5; |
| | | timeout.tv_usec = 0; |
| | | |
| | | |
| | | rc = select(FD_SETSIZE, &user_data->fds, NULL, NULL, &timeout); |
| | | |
| | | |
| | | return rc; |
| | | } |
| | | |
| | | |
| | | static int processIoListen(user_data_t * user_data) { |
| | | struct sockaddr_in cliaddr; |
| | | socklen_t clilen; |
| | | clilen = sizeof(cliaddr); |
| | | |
| | | user_data->io = accept(user_data->io_listen, (struct sockaddr *)&cliaddr, &clilen); |
| | | clilen = sizeof (cliaddr); |
| | | |
| | | user_data->io = accept(user_data->io_listen, (struct sockaddr *) &cliaddr, &clilen); |
| | | user_data->fio = fdopen(user_data->io, "r+"); |
| | | |
| | | |
| | | printf("Connection established %s\r\n", inet_ntoa(cliaddr.sin_addr)); |
| | | } |
| | | |
| | | static int processSrqIoListen(user_data_t * user_data) { |
| | | struct sockaddr_in cliaddr; |
| | | socklen_t clilen; |
| | | clilen = sizeof(cliaddr); |
| | | clilen = sizeof (cliaddr); |
| | | |
| | | user_data->control_io = accept(user_data->control_io_listen, (struct sockaddr *)&cliaddr, &clilen); |
| | | user_data->control_io = accept(user_data->control_io_listen, (struct sockaddr *) &cliaddr, &clilen); |
| | | printf("Control Connection established %s\r\n", inet_ntoa(cliaddr.sin_addr)); |
| | | } |
| | | |
| | |
| | | static int processIo(user_data_t * user_data) { |
| | | int rc; |
| | | char smbuffer[10]; |
| | | rc = recv(user_data->io, smbuffer, sizeof(smbuffer), 0); |
| | | rc = recv(user_data->io, smbuffer, sizeof (smbuffer), 0); |
| | | if (rc < 0) { |
| | | if (errno != EWOULDBLOCK) { |
| | | closeIo(user_data); |
| | |
| | | |
| | | static int processSrqIo(user_data_t * user_data) { |
| | | int rc; |
| | | char smbuffer[10]; |
| | | rc = recv(user_data->control_io, smbuffer, sizeof(smbuffer), 0); |
| | | char smbuffer[10]; |
| | | rc = recv(user_data->control_io, smbuffer, sizeof (smbuffer), 0); |
| | | if (rc < 0) { |
| | | if (errno != EWOULDBLOCK) { |
| | | closeSrqIo(user_data); |
| | |
| | | (void) argc; |
| | | (void) argv; |
| | | int rc; |
| | | |
| | | |
| | | user_data_t user_data = { |
| | | .io_listen = -1, |
| | | .io = -1, |
| | |
| | | |
| | | // user_context will be pointer to socket |
| | | scpi_context.user_context = &user_data; |
| | | |
| | | |
| | | SCPI_Init(&scpi_context); |
| | | |
| | | user_data.io_listen = createServer(5025); |
| | | user_data.control_io_listen = createServer(CONTROL_PORT); |
| | | |
| | | while(1) { |
| | | |
| | | while (1) { |
| | | rc = waitServer(&user_data); |
| | | |
| | | |
| | | if (rc < 0) { // failed |
| | | perror("select failed"); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | if (rc == 0) { // timeout |
| | | SCPI_Input(&scpi_context, NULL, 0); |
| | | } |
| | | |
| | | |
| | | if ((user_data.io_listen >= 0) && FD_ISSET(user_data.io_listen, &user_data.fds)) { |
| | | processIoListen(&user_data); |
| | | } |
| | |
| | | if ((user_data.control_io_listen >= 0) && FD_ISSET(user_data.control_io_listen, &user_data.fds)) { |
| | | processSrqIoListen(&user_data); |
| | | } |
| | | |
| | | |
| | | if ((user_data.io >= 0) && FD_ISSET(user_data.io, &user_data.fds)) { |
| | | processIo(&user_data); |
| | | } |
| | | |
| | | |
| | | if ((user_data.control_io >= 0) && FD_ISSET(user_data.control_io, &user_data.fds)) { |
| | | processSrqIo(&user_data); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | return (EXIT_SUCCESS); |
| | | } |
| | | |
| | |
| | | |
| | | size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
| | | if (context->user_context != NULL) { |
| | | int fd = *(int *)(context->user_context); |
| | | int fd = *(int *) (context->user_context); |
| | | return write(fd, data, len); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | scpi_result_t SCPI_Flush(scpi_t * context) { |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | int rc; |
| | | int on = 1; |
| | | struct sockaddr_in servaddr; |
| | | |
| | | |
| | | /* Configure TCP Server */ |
| | | bzero(&servaddr, sizeof(servaddr)); |
| | | bzero(&servaddr, sizeof (servaddr)); |
| | | servaddr.sin_family = AF_INET; |
| | | servaddr.sin_addr.s_addr=htonl(INADDR_ANY); |
| | | servaddr.sin_port=htons(port); |
| | | |
| | | servaddr.sin_addr.s_addr = htonl(INADDR_ANY); |
| | | servaddr.sin_port = htons(port); |
| | | |
| | | /* Create socket */ |
| | | fd = socket(AF_INET,SOCK_STREAM, 0); |
| | | if (fd < 0) |
| | | { |
| | | fd = socket(AF_INET, SOCK_STREAM, 0); |
| | | if (fd < 0) { |
| | | perror("socket() failed"); |
| | | exit(-1); |
| | | } |
| | | |
| | | } |
| | | |
| | | /* Set address reuse enable */ |
| | | rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); |
| | | if (rc < 0) |
| | | { |
| | | rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)); |
| | | if (rc < 0) { |
| | | perror("setsockopt() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | /* Set non blocking */ |
| | | rc = ioctl(fd, FIONBIO, (char *)&on); |
| | | if (rc < 0) |
| | | { |
| | | rc = ioctl(fd, FIONBIO, (char *) &on); |
| | | if (rc < 0) { |
| | | perror("ioctl() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | } |
| | | |
| | | /* Bind to socket */ |
| | | rc = bind(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)); |
| | | if (rc < 0) |
| | | { |
| | | rc = bind(fd, (struct sockaddr *) &servaddr, sizeof (servaddr)); |
| | | if (rc < 0) { |
| | | perror("bind() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | /* Listen on socket */ |
| | | listen(fd, 1); |
| | | if (rc < 0) |
| | | { |
| | | if (rc < 0) { |
| | | perror("listen() failed"); |
| | | close(fd); |
| | | exit(-1); |
| | | } |
| | | |
| | | |
| | | return fd; |
| | | } |
| | | |
| | |
| | | struct timeval timeout; |
| | | int rc; |
| | | int max_fd; |
| | | |
| | | |
| | | FD_ZERO(&fds); |
| | | max_fd = fd; |
| | | FD_SET(fd, &fds); |
| | | |
| | | timeout.tv_sec = 5; |
| | | |
| | | timeout.tv_sec = 5; |
| | | timeout.tv_usec = 0; |
| | | |
| | | |
| | | rc = select(max_fd + 1, &fds, NULL, NULL, &timeout); |
| | | |
| | | |
| | | return rc; |
| | | } |
| | | |
| | |
| | | |
| | | // user_context will be pointer to socket |
| | | scpi_context.user_context = NULL; |
| | | |
| | | |
| | | SCPI_Init(&scpi_context); |
| | | |
| | | listenfd = createServer(5025); |
| | | |
| | | while(1) { |
| | | |
| | | while (1) { |
| | | int clifd; |
| | | struct sockaddr_in cliaddr; |
| | | socklen_t clilen; |
| | | |
| | | clilen = sizeof(cliaddr); |
| | | clifd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen); |
| | | |
| | | clilen = sizeof (cliaddr); |
| | | clifd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen); |
| | | |
| | | if (clifd < 0) continue; |
| | | |
| | | printf("Connection established %s\r\n", inet_ntoa(cliaddr.sin_addr)); |
| | | |
| | | scpi_context.user_context = &clifd; |
| | | |
| | | while(1) { |
| | | while (1) { |
| | | rc = waitServer(clifd); |
| | | if (rc < 0) { // failed |
| | | perror(" recv() failed"); |
| | |
| | | SCPI_Input(&scpi_context, NULL, 0); |
| | | } |
| | | if (rc > 0) { // something to read |
| | | rc = recv(clifd, smbuffer, sizeof(smbuffer), 0); |
| | | rc = recv(clifd, smbuffer, sizeof (smbuffer), 0); |
| | | if (rc < 0) { |
| | | if (errno != EWOULDBLOCK) { |
| | | perror(" recv() failed"); |
| | | break; |
| | | } |
| | | } else if (rc == 0) { |
| | | } else if (rc == 0) { |
| | | printf("Connection closed\r\n"); |
| | | break; |
| | | } else { |
| | |
| | | |
| | | close(clifd); |
| | | } |
| | | |
| | | |
| | | return (EXIT_SUCCESS); |
| | | } |
| | | |
| | |
| | | #endif |
| | | |
| | | |
| | | /* 4.1.3.6 *IDN? */ |
| | | /* 4.1.3.6 *IDN? */ |
| | | |
| | | #define SCPI_DEFAULT_1_MANUFACTURE "CTU FEE" |
| | | #define SCPI_DEFAULT_2_MODEL "TSI3225" |
| | | #define SCPI_DEFAULT_3 "0" |
| | | #define SCPI_DEFAULT_4_REVISION "01-01" |
| | | |
| | | /* 21.21 :VERSion? |
| | | * YYYY.V |
| | | * YYYY = SCPI year |
| | | * V = SCPI revision |
| | | */ |
| | | /* 21.21 :VERSion? |
| | | * YYYY.V |
| | | * YYYY = SCPI year |
| | | * V = SCPI revision |
| | | */ |
| | | #define SCPI_STD_VERSION_REVISION "1999.0" |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | const char * SCPI_ErrorTranslate(int16_t err); |
| | | |
| | | |
| | | /* Using X-Macro technique to define everything once |
| | | * http://en.wikipedia.org/wiki/X_Macro |
| | | * |
| | | * X macro is for minimal set of errors for library itself |
| | | * XE macro is for full set of SCPI errors available to user application |
| | | */ |
| | | /* Using X-Macro technique to define everything once |
| | | * http://en.wikipedia.org/wiki/X_Macro |
| | | * |
| | | * X macro is for minimal set of errors for library itself |
| | | * XE macro is for full set of SCPI errors available to user application |
| | | */ |
| | | #define LIST_OF_ERRORS \ |
| | | XE(SCPI_ERROR_COMMAND, -100, "Command error") \ |
| | | X(SCPI_ERROR_INVALID_CHARACTER, -101, "Invalid character") \ |
| | |
| | | XE(SCPI_ERROR_REQUEST_CONTROL, -700, "Request control") \ |
| | | XE(SCPI_ERROR_OPERATION_COMPLETE, -800, "Operation complete") \ |
| | | |
| | | enum { |
| | | |
| | | enum { |
| | | #define X(def, val, str) def = val, |
| | | #if USE_FULL_ERROR_LIST |
| | | #define XE X |
| | | #else |
| | | #define XE(def, val, str) |
| | | #endif |
| | | LIST_OF_ERRORS |
| | | LIST_OF_ERRORS |
| | | |
| | | #if USE_USER_ERROR_LIST |
| | | LIST_OF_USER_ERRORS |
| | | LIST_OF_USER_ERRORS |
| | | #endif |
| | | #undef X |
| | | #undef XE |
| | | }; |
| | | }; |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | | |
| | | |
| | | enum _scpi_expr_result_t { |
| | | SCPI_EXPR_OK = 0, |
| | | SCPI_EXPR_ERROR, |
| | |
| | | extern "C" { |
| | | #endif |
| | | |
| | | scpi_result_t SCPI_CoreCls(scpi_t * context); |
| | | scpi_result_t SCPI_CoreEse(scpi_t * context); |
| | | scpi_result_t SCPI_CoreEseQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreEsrQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreIdnQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreOpc(scpi_t * context); |
| | | scpi_result_t SCPI_CoreOpcQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreRst(scpi_t * context); |
| | | scpi_result_t SCPI_CoreSre(scpi_t * context); |
| | | scpi_result_t SCPI_CoreSreQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreStbQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreTstQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreWai(scpi_t * context); |
| | | scpi_result_t SCPI_CoreCls(scpi_t * context); |
| | | scpi_result_t SCPI_CoreEse(scpi_t * context); |
| | | scpi_result_t SCPI_CoreEseQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreEsrQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreIdnQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreOpc(scpi_t * context); |
| | | scpi_result_t SCPI_CoreOpcQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreRst(scpi_t * context); |
| | | scpi_result_t SCPI_CoreSre(scpi_t * context); |
| | | scpi_result_t SCPI_CoreSreQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreStbQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreTstQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreWai(scpi_t * context); |
| | | |
| | | |
| | | #define STB_R01 0x01 /* Not used */ |
| | |
| | | #define ESR_PON 0x80 /* Power On */ |
| | | |
| | | |
| | | scpi_reg_val_t SCPI_RegGet(scpi_t * context, scpi_reg_name_t name); |
| | | void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val); |
| | | void SCPI_RegSetBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits); |
| | | void SCPI_RegClearBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits); |
| | | scpi_reg_val_t SCPI_RegGet(scpi_t * context, scpi_reg_name_t name); |
| | | void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val); |
| | | void SCPI_RegSetBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits); |
| | | void SCPI_RegClearBits(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t bits); |
| | | |
| | | void SCPI_EventClear(scpi_t * context); |
| | | void SCPI_EventClear(scpi_t * context); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | |
| | | int SCPI_Input(scpi_t * context, const char * data, int len); |
| | | int SCPI_Parse(scpi_t * context, char * data, int len); |
| | | |
| | | |
| | | size_t SCPI_ResultCharacters(scpi_t * context, const char * data, size_t len); |
| | | #define SCPI_ResultMnemonic(context, data) SCPI_ResultCharacters((context), (data), strlen(data)) |
| | | size_t SCPI_ResultUInt32Base(scpi_t * context, uint32_t val, int8_t base); |
| | |
| | | size_t SCPI_ResultText(scpi_t * context, const char * data); |
| | | size_t SCPI_ResultArbitraryBlock(scpi_t * context, const char * data, size_t len); |
| | | size_t SCPI_ResultBool(scpi_t * context, scpi_bool_t val); |
| | | |
| | | |
| | | scpi_bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamIsValid(scpi_parameter_t * parameter); |
| | |
| | | scpi_bool_t SCPI_ParamToDouble(scpi_t * context, scpi_parameter_t * parameter, double * value); |
| | | scpi_bool_t SCPI_ParamToChoice(scpi_t * context, scpi_parameter_t * parameter, const scpi_choice_def_t * options, int32_t * value); |
| | | scpi_bool_t SCPI_ChoiceToName(const scpi_choice_def_t * options, int32_t tag, const char ** text); |
| | | |
| | | |
| | | scpi_bool_t SCPI_ParamInt32(scpi_t * context, int32_t * value, scpi_bool_t mandatory); |
| | | scpi_bool_t SCPI_ParamUInt32(scpi_t * context, uint32_t * value, scpi_bool_t mandatory); |
| | |
| | | int32_t SCPI_CmdTag(scpi_t * context); |
| | | scpi_bool_t SCPI_Match(const char * pattern, const char * value, size_t len); |
| | | scpi_bool_t SCPI_CommandNumbers(scpi_t * context, int32_t * numbers, size_t len, int32_t default_value); |
| | | |
| | | |
| | | // deprecated finction, should be removed later |
| | | #define SCPI_ResultIntBase(context, val, base) SCPI_ResultInt32Base ((context), (val), (base), TRUE) |
| | |
| | | #include "scpi/utils.h" |
| | | #include "scpi/expression.h" |
| | | |
| | | |
| | | #endif /* SCPI_H */ |
| | | |
| | |
| | | #endif |
| | | |
| | | #if !HAVE_STDBOOL |
| | | typedef unsigned char bool; |
| | | typedef unsigned char bool; |
| | | #endif |
| | | |
| | | #ifndef FALSE |
| | | #define FALSE 0 |
| | | #define FALSE 0 |
| | | #endif |
| | | #ifndef TRUE |
| | | #define TRUE (!FALSE) |
| | | #define TRUE (!FALSE) |
| | | #endif |
| | | |
| | | /* basic data types */ |
| | |
| | | |
| | | struct _scpi_number_parameter_t { |
| | | scpi_bool_t special; |
| | | |
| | | union { |
| | | double value; |
| | | int32_t tag; |
| | |
| | | /* basic FIFO */ |
| | | static scpi_fifo_t local_error_queue; |
| | | |
| | | |
| | | /** |
| | | * Initialize error queue |
| | | * @param context - scpi context |
| | |
| | | */ |
| | | |
| | | /* basic FIFO */ |
| | | context->error_queue = (scpi_error_queue_t)&local_error_queue; |
| | | fifo_init((scpi_fifo_t *)context->error_queue); |
| | | context->error_queue = (scpi_error_queue_t) & local_error_queue; |
| | | fifo_init((scpi_fifo_t *) context->error_queue); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | |
| | | /* basic FIFO */ |
| | | fifo_clear((scpi_fifo_t *)context->error_queue); |
| | | fifo_clear((scpi_fifo_t *) context->error_queue); |
| | | |
| | | SCPI_ErrorEmitEmpty(context); |
| | | } |
| | |
| | | */ |
| | | |
| | | /* basic FIFO */ |
| | | fifo_remove((scpi_fifo_t *)context->error_queue, &result); |
| | | fifo_remove((scpi_fifo_t *) context->error_queue, &result); |
| | | |
| | | SCPI_ErrorEmitEmpty(context); |
| | | |
| | |
| | | */ |
| | | |
| | | /* basic FIFO */ |
| | | fifo_count((scpi_fifo_t *)context->error_queue, &result); |
| | | fifo_count((scpi_fifo_t *) context->error_queue, &result); |
| | | |
| | | return result; |
| | | } |
| | |
| | | */ |
| | | |
| | | /* basic FIFO */ |
| | | fifo_add((scpi_fifo_t *)context->error_queue, err); |
| | | fifo_add((scpi_fifo_t *) context->error_queue, err); |
| | | } |
| | | |
| | | struct error_reg { |
| | |
| | | {-100, -199, ESR_CER}, /* Command error (e.g. syntax error) ch 21.8.9 */ |
| | | {-200, -299, ESR_EER}, /* Execution Error (e.g. range error) ch 21.8.10 */ |
| | | {-300, -399, ESR_DER}, /* Device specific error -300, -399 ch 21.8.11 */ |
| | | { 1,32767, ESR_DER}, /* Device designer provided specific error 1, 32767 ch 21.8.11 */ |
| | | { 1, 32767, ESR_DER}, /* Device designer provided specific error 1, 32767 ch 21.8.11 */ |
| | | {-400, -499, ESR_QER}, /* Query error -400, -499 ch 21.8.12 */ |
| | | {-500, -599, ESR_PON}, /* Power on event -500, -599 ch 21.8.13 */ |
| | | {-600, -699, ESR_URQ}, /* User Request Event -600, -699 ch 21.8.14 */ |
| | |
| | | |
| | | SCPI_ErrorAddInternal(context, err); |
| | | |
| | | for(i = 0; i < ERROR_DEFS_N; i++) { |
| | | for (i = 0; i < ERROR_DEFS_N; i++) { |
| | | if ((err <= errs[i].from) && (err >= errs[i].to)) { |
| | | SCPI_RegSetBits(context, SCPI_REG_ESR, errs[i].bit); |
| | | } |
| | |
| | | #else |
| | | #define XE(def, val, str) |
| | | #endif |
| | | LIST_OF_ERRORS |
| | | LIST_OF_ERRORS |
| | | |
| | | #if USE_USER_ERROR_LIST |
| | | LIST_OF_USER_ERRORS |
| | | LIST_OF_USER_ERRORS |
| | | #endif |
| | | #undef X |
| | | #undef XE |
| | | default: return "Unknown error"; |
| | | default: return "Unknown error"; |
| | | } |
| | | } |
| | | |
| | |
| | | * SCPI_EXPR_ERROR - parser error |
| | | * SCPI_EXPR_NO_MORE - no more data |
| | | */ |
| | | static scpi_expr_result_t numericRange(lex_state_t * state, scpi_bool_t * isRange, scpi_token_t * valueFrom, scpi_token_t * valueTo) |
| | | { |
| | | static scpi_expr_result_t numericRange(lex_state_t * state, scpi_bool_t * isRange, scpi_token_t * valueFrom, scpi_token_t * valueTo) { |
| | | if (scpiLex_DecimalNumericProgramData(state, valueFrom)) { |
| | | if (scpiLex_Colon(state, valueTo)) { |
| | | *isRange = TRUE; |
| | |
| | | * SCPI_EXPR_NO_MORE - no more data |
| | | * @see SCPI_ExprNumericListEntryInt, SCPI_ExprNumericListEntryDouble |
| | | */ |
| | | scpi_expr_result_t SCPI_ExprNumericListEntry(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, scpi_parameter_t * valueFrom, scpi_parameter_t * valueTo) |
| | | { |
| | | scpi_expr_result_t SCPI_ExprNumericListEntry(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, scpi_parameter_t * valueFrom, scpi_parameter_t * valueTo) { |
| | | lex_state_t lex; |
| | | int i; |
| | | scpi_expr_result_t res = SCPI_EXPR_OK; |
| | |
| | | * SCPI_EXPR_NO_MORE - no more data |
| | | * @see SCPI_ExprNumericListEntry, SCPI_ExprNumericListEntryDouble |
| | | */ |
| | | scpi_expr_result_t SCPI_ExprNumericListEntryInt(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, int32_t * valueFrom, int32_t * valueTo) |
| | | { |
| | | scpi_expr_result_t SCPI_ExprNumericListEntryInt(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, int32_t * valueFrom, int32_t * valueTo) { |
| | | scpi_expr_result_t res; |
| | | scpi_bool_t range = FALSE; |
| | | scpi_parameter_t paramFrom; |
| | |
| | | * SCPI_EXPR_NO_MORE - no more data |
| | | * @see SCPI_ExprNumericListEntry, SCPI_ExprNumericListEntryInt |
| | | */ |
| | | scpi_expr_result_t SCPI_ExprNumericListEntryDouble(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, double * valueFrom, double * valueTo) |
| | | { |
| | | scpi_expr_result_t SCPI_ExprNumericListEntryDouble(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, double * valueFrom, double * valueTo) { |
| | | scpi_expr_result_t res; |
| | | scpi_bool_t range = FALSE; |
| | | scpi_parameter_t paramFrom; |
| | |
| | | * @param length length of values array |
| | | * @param dimensions real number of dimensions |
| | | */ |
| | | static scpi_expr_result_t channelSpec(scpi_t * context, lex_state_t * state, int32_t * values, size_t length, size_t * dimensions) |
| | | { |
| | | static scpi_expr_result_t channelSpec(scpi_t * context, lex_state_t * state, int32_t * values, size_t length, size_t * dimensions) { |
| | | scpi_parameter_t param; |
| | | size_t i = 0; |
| | | while(scpiLex_DecimalNumericProgramData(state, ¶m)) { |
| | | while (scpiLex_DecimalNumericProgramData(state, ¶m)) { |
| | | if (i < length) { |
| | | SCPI_ParamToInt(context, ¶m, &values[i]); |
| | | } |
| | |
| | | * @param length length of values arrays |
| | | * @param dimensions real number of dimensions |
| | | */ |
| | | static scpi_expr_result_t channelRange(scpi_t * context, lex_state_t * state, scpi_bool_t * isRange, int32_t * valuesFrom, int32_t * valuesTo, size_t length, size_t * dimensions) |
| | | { |
| | | static scpi_expr_result_t channelRange(scpi_t * context, lex_state_t * state, scpi_bool_t * isRange, int32_t * valuesFrom, int32_t * valuesTo, size_t length, size_t * dimensions) { |
| | | scpi_token_t token; |
| | | scpi_expr_result_t err; |
| | | size_t fromDimensions; |
| | |
| | | * @param length length of values arrays |
| | | * @param dimensions real number of dimensions |
| | | */ |
| | | scpi_expr_result_t SCPI_ExprChannelListEntry(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, int32_t * valuesFrom, int32_t * valuesTo, size_t length, size_t * dimensions) |
| | | { |
| | | scpi_expr_result_t SCPI_ExprChannelListEntry(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, int32_t * valuesFrom, int32_t * valuesTo, size_t length, size_t * dimensions) { |
| | | lex_state_t lex; |
| | | int i; |
| | | scpi_expr_result_t res = SCPI_EXPR_OK; |
| | |
| | | return FALSE; |
| | | } |
| | | |
| | | if(value) { |
| | | if (value) { |
| | | *value = fifo->data[fifo->rd]; |
| | | } |
| | | |
| | |
| | | if ((name >= SCPI_REG_COUNT) || (context->registers == NULL)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | /* store old register value */ |
| | | old_val = context->registers[name]; |
| | | |
| | |
| | | case SCPI_REG_OPERE: |
| | | regUpdate(context, SCPI_REG_OPER); |
| | | break; |
| | | |
| | | |
| | | |
| | | |
| | | case SCPI_REG_COUNT: |
| | | /* nothing to do */ |
| | | break; |
| | |
| | | scpi_result_t SCPI_CoreEse(scpi_t * context) { |
| | | int32_t new_ESE; |
| | | if (SCPI_ParamInt32(context, &new_ESE, TRUE)) { |
| | | SCPI_RegSet(context, SCPI_REG_ESE, (scpi_reg_val_t)new_ESE); |
| | | SCPI_RegSet(context, SCPI_REG_ESE, (scpi_reg_val_t) new_ESE); |
| | | } |
| | | return SCPI_RES_OK; |
| | | } |
| | |
| | | */ |
| | | scpi_result_t SCPI_CoreIdnQ(scpi_t * context) { |
| | | int i; |
| | | for (i = 0; i<4; i++) { |
| | | for (i = 0; i < 4; i++) { |
| | | if (context->idn[i]) { |
| | | SCPI_ResultMnemonic(context, context->idn[i]); |
| | | } else { |
| | |
| | | scpi_result_t SCPI_CoreSre(scpi_t * context) { |
| | | int32_t new_SRE; |
| | | if (SCPI_ParamInt32(context, &new_SRE, TRUE)) { |
| | | SCPI_RegSet(context, SCPI_REG_SRE, (scpi_reg_val_t)new_SRE); |
| | | SCPI_RegSet(context, SCPI_REG_SRE, (scpi_reg_val_t) new_SRE); |
| | | } |
| | | return SCPI_RES_OK; |
| | | } |
| | |
| | | scpi_result_t SCPI_StatusQuestionableEnable(scpi_t * context) { |
| | | int32_t new_QUESE; |
| | | if (SCPI_ParamInt32(context, &new_QUESE, TRUE)) { |
| | | SCPI_RegSet(context, SCPI_REG_QUESE, (scpi_reg_val_t)new_QUESE); |
| | | SCPI_RegSet(context, SCPI_REG_QUESE, (scpi_reg_val_t) new_QUESE); |
| | | } |
| | | return SCPI_RES_OK; |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | static size_t resultUInt32BaseSign(scpi_t * context, uint32_t val, int8_t base, scpi_bool_t sign) { |
| | | char buffer[32+1]; |
| | | char buffer[32 + 1]; |
| | | const char * basePrefix; |
| | | size_t result = 0; |
| | | size_t len; |
| | |
| | | * @return |
| | | */ |
| | | static size_t resultUInt64BaseSign(scpi_t * context, uint64_t val, int8_t base, scpi_bool_t sign) { |
| | | char buffer[64+1]; |
| | | char buffer[64 + 1]; |
| | | const char * basePrefix; |
| | | size_t result = 0; |
| | | size_t len; |
| | |
| | | SCPI_UInt32ToStrBase((uint32_t) len, block_header + 2, 10, 10); |
| | | |
| | | header_len = strlen(block_header + 2); |
| | | block_header[1] = (char)(header_len + '0'); |
| | | block_header[1] = (char) (header_len + '0'); |
| | | |
| | | result += writeData(context, block_header, header_len + 2); |
| | | result += writeData(context, data, len); |
| | |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: |
| | | if (sign) { |
| | | return strBaseToInt32(parameter->ptr, (int32_t *)value, 10) > 0 ? TRUE : FALSE; |
| | | return strBaseToInt32(parameter->ptr, (int32_t *) value, 10) > 0 ? TRUE : FALSE; |
| | | } else { |
| | | return strBaseToUInt32(parameter->ptr, value, 10) > 0 ? TRUE : FALSE; |
| | | } |
| | |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: |
| | | if (sign) { |
| | | return strBaseToInt64(parameter->ptr, (int64_t *)value, 10) > 0 ? TRUE : FALSE; |
| | | return strBaseToInt64(parameter->ptr, (int64_t *) value, 10) > 0 ? TRUE : FALSE; |
| | | } else { |
| | | return strBaseToUInt64(parameter->ptr, value, 10) > 0 ? TRUE : FALSE; |
| | | } |
| | |
| | | * @return TRUE if succesful |
| | | */ |
| | | scpi_bool_t SCPI_ParamToInt32(scpi_t * context, scpi_parameter_t * parameter, int32_t * value) { |
| | | return ParamSignToUInt32(context, parameter, (uint32_t *)value, TRUE); |
| | | return ParamSignToUInt32(context, parameter, (uint32_t *) value, TRUE); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param value result |
| | | * @return TRUE if succesful |
| | | */ |
| | | scpi_bool_t SCPI_ParamToUInt32(scpi_t * context, scpi_parameter_t * parameter, uint32_t * value) { |
| | | scpi_bool_t SCPI_ParamToUInt32(scpi_t * context, scpi_parameter_t * parameter, uint32_t * value) { |
| | | return ParamSignToUInt32(context, parameter, value, FALSE); |
| | | } |
| | | |
| | |
| | | * @return TRUE if succesful |
| | | */ |
| | | scpi_bool_t SCPI_ParamToInt64(scpi_t * context, scpi_parameter_t * parameter, int64_t * value) { |
| | | return ParamSignToUInt64(context, parameter, (uint64_t *)value, TRUE); |
| | | return ParamSignToUInt64(context, parameter, (uint64_t *) value, TRUE); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param value result |
| | | * @return TRUE if succesful |
| | | */ |
| | | scpi_bool_t SCPI_ParamToUInt64(scpi_t * context, scpi_parameter_t * parameter, uint64_t * value) { |
| | | scpi_bool_t SCPI_ParamToUInt64(scpi_t * context, scpi_parameter_t * parameter, uint64_t * value) { |
| | | return ParamSignToUInt64(context, parameter, value, FALSE); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | scpi_bool_t SCPI_ParamInt32(scpi_t * context, int32_t * value, scpi_bool_t mandatory) { |
| | | return ParamSignUInt32(context, (uint32_t *)value, mandatory, TRUE); |
| | | return ParamSignUInt32(context, (uint32_t *) value, mandatory, TRUE); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | scpi_bool_t SCPI_ParamInt64(scpi_t * context, int64_t * value, scpi_bool_t mandatory) { |
| | | return ParamSignUInt64(context, (uint64_t *)value, mandatory, TRUE); |
| | | return ParamSignUInt64(context, (uint64_t *) value, mandatory, TRUE); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | result = SCPI_Parameter(context, ¶m, mandatory); |
| | | if (result) { |
| | | switch(param.type) { |
| | | switch (param.type) { |
| | | case SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA: |
| | | case SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA: |
| | | *value = param.ptr + 1; |
| | |
| | | } |
| | | |
| | | pattern = context->param_list.cmd->pattern; |
| | | return matchCommand (pattern, cmd, strlen (cmd), NULL, 0, 0); |
| | | return matchCommand(pattern, cmd, strlen(cmd), NULL, 0, 0); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | scpi_bool_t SCPI_Match(const char * pattern, const char * value, size_t len) { |
| | | return matchCommand (pattern, value, len, NULL, 0, 0); |
| | | return matchCommand(pattern, value, len, NULL, 0, 0); |
| | | } |
| | | |
| | | scpi_bool_t SCPI_CommandNumbers(scpi_t * context, int32_t * numbers, size_t len, int32_t default_value) { |
| | | return matchCommand (context->param_list.cmd->pattern, context->param_list.cmd_raw.data, context->param_list.cmd_raw.length, numbers, len, default_value); |
| | | return matchCommand(context->param_list.cmd->pattern, context->param_list.cmd_raw.data, context->param_list.cmd_raw.length, numbers, len, default_value); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param parameter |
| | | * @return |
| | | */ |
| | | scpi_bool_t SCPI_ParamIsValid(scpi_parameter_t * parameter) |
| | | { |
| | | scpi_bool_t SCPI_ParamIsValid(scpi_parameter_t * parameter) { |
| | | return parameter->type == SCPI_TOKEN_UNKNOWN ? FALSE : TRUE; |
| | | } |
| | | |
| | |
| | | * @param context |
| | | * @return |
| | | */ |
| | | scpi_bool_t SCPI_ParamErrorOccurred(scpi_t * context) |
| | | { |
| | | scpi_bool_t SCPI_ParamErrorOccurred(scpi_t * context) { |
| | | return context->cmd_error; |
| | | } |
| | |
| | | * @param mandatory if the parameter is mandatory |
| | | * @return |
| | | */ |
| | | scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory) |
| | | { |
| | | scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory) { |
| | | scpi_token_t token; |
| | | lex_state_t state; |
| | | scpi_parameter_t param; |
| | |
| | | state.pos = state.buffer; |
| | | state.len = param.len; |
| | | |
| | | switch(param.type) { |
| | | switch (param.type) { |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: |
| | | case SCPI_TOKEN_HEXNUM: |
| | | case SCPI_TOKEN_OCTNUM: |
| | |
| | | break; |
| | | } |
| | | |
| | | switch(param.type) { |
| | | switch (param.type) { |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: |
| | | case SCPI_TOKEN_PROGRAM_MNEMONIC: |
| | |
| | | break; |
| | | } |
| | | |
| | | switch(param.type) { |
| | | switch (param.type) { |
| | | case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: |
| | | SCPI_ParamToDouble(context, ¶m, &(value->value)); |
| | | break; |
| | |
| | | * Copyright (c) 2012 Jan Breuer |
| | | * |
| | | * All Rights Reserved |
| | | * |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are |
| | | * met: |
| | |
| | | * 2. Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * |
| | | * |
| | | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| | | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| | | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| | |
| | | /** |
| | | * @file scpi_utils.c |
| | | * @date Thu Nov 15 10:58:45 UTC 2012 |
| | | * |
| | | * |
| | | * @brief Conversion routines and string manipulation routines |
| | | * |
| | | * |
| | | * |
| | | * |
| | | */ |
| | | |
| | | #include <stdio.h> |
| | |
| | | * @param str |
| | | * @param size |
| | | * @param set |
| | | * @return |
| | | * @return |
| | | */ |
| | | char * strnpbrk(const char *str, size_t size, const char *set) { |
| | | const char *scanp; |
| | |
| | | * @param str converted textual representation |
| | | * @param len string buffer length |
| | | * @param base output base |
| | | * @param sign |
| | | * @param sign |
| | | * @return number of bytes written to str (without '\0') |
| | | */ |
| | | size_t UInt32ToStrBaseSign(uint32_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) { |
| | |
| | | * @param str converted textual representation |
| | | * @param len string buffer length |
| | | * @param base output base |
| | | * @param sign |
| | | * @param sign |
| | | * @return number of bytes written to str (without '\0') |
| | | */ |
| | | size_t UInt64ToStrBaseSign(uint64_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) { |
| | |
| | | * @param pattern_len |
| | | * @param str |
| | | * @param str_len |
| | | * @return |
| | | * @return |
| | | */ |
| | | scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) { |
| | | int pattern_sep_pos_short; |
| | |
| | | #endif |
| | | |
| | | #if defined(__GNUC__) && (__GNUC__ >= 4) |
| | | #define LOCAL __attribute__((visibility ("hidden"))) |
| | | #define LOCAL __attribute__((visibility ("hidden"))) |
| | | #else |
| | | #define LOCAL |
| | | #define LOCAL |
| | | #endif |
| | | |
| | | char * strnpbrk(const char *str, size_t size, const char *set) LOCAL; |
| | |
| | | #endif |
| | | |
| | | #ifndef min |
| | | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
| | | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
| | | #endif |
| | | |
| | | #ifndef max |
| | | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
| | | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
| | | #endif |
| | | |
| | | #if 0 |
| | |
| | | CU_ASSERT_TRUE(fifo_remove(&fifo, &value)); |
| | | CU_ASSERT_EQUAL(value, 5); |
| | | TEST_FIFO_COUNT(0); |
| | | |
| | | |
| | | CU_ASSERT_FALSE(fifo_remove(&fifo, &value)); |
| | | TEST_FIFO_COUNT(0); |
| | | } |
| | |
| | | if (len != token.len) printToken(&token); \ |
| | | } while(0) |
| | | |
| | | |
| | | static void testWhiteSpace(void) { |
| | | TEST_TOKEN(" \t MEAS", scpiLex_WhiteSpace, 0, 4, SCPI_TOKEN_WS); |
| | | TEST_TOKEN("MEAS", scpiLex_WhiteSpace, 0, 0, SCPI_TOKEN_UNKNOWN); |
| | |
| | | TEST_TOKEN("'ah\"oj' ", scpiParser_parseProgramData, 0, 7, SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA); |
| | | TEST_TOKEN("\"ah\"\"oj\" ", scpiParser_parseProgramData, 0, 8, SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA); |
| | | TEST_TOKEN("\"\"", scpiParser_parseProgramData, 0, 2, SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA); |
| | | |
| | | |
| | | TEST_TOKEN("abc_213as564 , ", scpiLex_CharacterProgramData, 0, 12, SCPI_TOKEN_PROGRAM_MNEMONIC); |
| | | |
| | | |
| | | TEST_TOKEN("1.5E12 V", scpiParser_parseProgramData, 0, 8, SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX); |
| | | } |
| | | |
| | |
| | | else \ |
| | | if (len != token.len) printToken(&token); \ |
| | | } while(0) |
| | | |
| | | |
| | | static void testAllProgramData(void) { |
| | | TEST_ALL_TOKEN("1.5E12 V", scpiParser_parseAllProgramData, 0, 8, SCPI_TOKEN_ALL_PROGRAM_DATA, 1); |
| | |
| | | } |
| | | |
| | | scpi_t scpi_context; |
| | | |
| | | static void error_buffer_clear(void) { |
| | | err_buffer[0] = 0; |
| | | err_buffer_pos = 0; |
| | |
| | | err_buffer[err_buffer_pos] = err; |
| | | err_buffer_pos++; |
| | | } |
| | | |
| | | |
| | | static size_t SCPI_Write(scpi_t * context, const char * data, size_t len) { |
| | | (void) context; |
| | |
| | | } |
| | | |
| | | scpi_reg_val_t srq_val = 0; |
| | | |
| | | static scpi_result_t SCPI_Control(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { |
| | | (void) context; |
| | | |
| | |
| | | |
| | | scpi_t scpi_context = { |
| | | .cmdlist = scpi_commands, |
| | | .buffer = { |
| | | .buffer = |
| | | { |
| | | .length = SCPI_INPUT_BUFFER_LENGTH, |
| | | .data = scpi_input_buffer, |
| | | }, |
| | | .interface = &scpi_interface, |
| | | .registers = scpi_regs, |
| | | .units = scpi_units_def, |
| | | .idn = {"MA", "IN", NULL, "VER"}, |
| | | .idn = |
| | | {"MA", "IN", NULL, "VER"}, |
| | | }; |
| | | |
| | | |
| | | static int init_suite(void) { |
| | | SCPI_Init(&scpi_context); |
| | |
| | | TEST_ChannelList("(@1,2:3)", 2, 1, FALSE, 0, (0), (0), SCPI_EXPR_NO_MORE, 0); |
| | | |
| | | TEST_ChannelList("(@1,2!5:3!6)", 0, 2, FALSE, 1, (1), (0), SCPI_EXPR_OK, 0); |
| | | TEST_ChannelList("(@1,2!5:3!6)", 1, 2, TRUE, 2, (2,5), (3,6), SCPI_EXPR_OK, 0); |
| | | TEST_ChannelList("(@1,2!5:3!6)", 1, 2, TRUE, 2, (2, 5), (3, 6), SCPI_EXPR_OK, 0); |
| | | TEST_ChannelList("(@1,2!5:3!6)", 2, 2, FALSE, 0, (0), (0), SCPI_EXPR_NO_MORE, 0); |
| | | |
| | | TEST_ChannelList("(@1,2!5:3!6)", 0, 1, FALSE, 1, (1), (0), SCPI_EXPR_OK, 0); |
| | |
| | | } |
| | | |
| | | static void test_Int32ToStr() { |
| | | const size_t max=32+1; |
| | | const size_t max = 32 + 1; |
| | | int32_t val[] = {0, 1, -1, INT32_MIN, INT32_MAX, 0x01234567, 0x89abcdef}; |
| | | int N = sizeof(val) / sizeof(int32_t); |
| | | int N = sizeof (val) / sizeof (int32_t); |
| | | int i; |
| | | char str[max]; |
| | | char ref[max]; |
| | | size_t len; |
| | | |
| | | // test signed conversion to decimal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_Int32ToStr(val[i], str, max); |
| | | snprintf(ref, max, "%"PRIi32, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | static void test_UInt32ToStrBase() { |
| | | const size_t max=32+1; |
| | | const size_t max = 32 + 1; |
| | | uint32_t val[] = {0, 1, -1, INT32_MIN, INT32_MAX, 0x01234567, 0x89abcdef}; |
| | | int N = sizeof(val) / sizeof(uint32_t); |
| | | int N = sizeof (val) / sizeof (uint32_t); |
| | | int i; |
| | | char str[max]; |
| | | char ref[max]; |
| | | size_t len; |
| | | |
| | | // test conversion to decimal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_UInt32ToStrBase(val[i], str, max, 10); |
| | | snprintf(ref, max, "%"PRIu32, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | // test conversion to hexadecimal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_UInt32ToStrBase(val[i], str, max, 16); |
| | | snprintf(ref, max, "%"PRIX32, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | // test conversion to octal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_UInt32ToStrBase(val[i], str, max, 8); |
| | | snprintf(ref, max, "%"PRIo32, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | static void test_Int64ToStr() { |
| | | const size_t max=64+1; |
| | | const size_t max = 64 + 1; |
| | | int64_t val[] = {0, 1, -1, INT64_MIN, INT64_MAX, 0x0123456789abcdef, 0xfedcba9876543210}; |
| | | int N = sizeof(val) / sizeof(int64_t); |
| | | int N = sizeof (val) / sizeof (int64_t); |
| | | int i; |
| | | char str[max]; |
| | | char ref[max]; |
| | | size_t len; |
| | | |
| | | // test conversion to decimal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_Int64ToStr(val[i], str, max); |
| | | snprintf(ref, max, "%"PRIi64, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | static void test_UInt64ToStrBase() { |
| | | const size_t max=64+1; |
| | | const size_t max = 64 + 1; |
| | | uint64_t val[] = {0, 1, -1, INT64_MIN, INT64_MAX, 0x0123456789abcdef, 0xfedcba9876543210}; |
| | | int N = sizeof(val) / sizeof(uint64_t); |
| | | int N = sizeof (val) / sizeof (uint64_t); |
| | | int i; |
| | | char str[max]; |
| | | char ref[max]; |
| | | size_t len; |
| | | |
| | | // test conversion to decimal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_UInt64ToStrBase(val[i], str, max, 10); |
| | | snprintf(ref, max, "%"PRIu64, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | // test conversion to hexadecimal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_UInt64ToStrBase(val[i], str, max, 16); |
| | | snprintf(ref, max, "%"PRIX64, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | // test conversion to octal numbers |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_UInt64ToStrBase(val[i], str, max, 8); |
| | | snprintf(ref, max, "%"PRIo64, val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | static void test_floatToStr() { |
| | | const size_t max=49+1; |
| | | const size_t max = 49 + 1; |
| | | float val[] = {1, -1, 1.1, -1.1, 1e3, 1e30, -1.3e30, -1.3e-30}; |
| | | int N = sizeof(val) / sizeof(float); |
| | | int N = sizeof (val) / sizeof (float); |
| | | int i; |
| | | char str[max]; |
| | | char ref[max]; |
| | | size_t len; |
| | | |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_FloatToStr(val[i], str, max); |
| | | snprintf(ref, max, "%g", val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | } |
| | | |
| | | static void test_doubleToStr() { |
| | | const size_t max=49+1; |
| | | const size_t max = 49 + 1; |
| | | double val[] = {1, -1, 1.1, -1.1, 1e3, 1e30, -1.3e30, -1.3e-30}; |
| | | int N = sizeof(val) / sizeof(double); |
| | | int N = sizeof (val) / sizeof (double); |
| | | int i; |
| | | char str[max]; |
| | | char ref[max]; |
| | | size_t len; |
| | | |
| | | for (i=0; i<N; i++) { |
| | | for (i = 0; i < N; i++) { |
| | | len = SCPI_DoubleToStr(val[i], str, max); |
| | | snprintf(ref, max, "%lg", val[i]); |
| | | CU_ASSERT(len == strlen(ref)); |
| | |
| | | scpi_bool_t result; |
| | | int32_t values[20]; |
| | | |
| | | #define TEST_MATCH_COMMAND(p, s, r) \ |
| | | #define TEST_MATCH_COMMAND(p, s, r) \ |
| | | do { \ |
| | | result = matchCommand(p, s, strlen(s), NULL, 0, 0); \ |
| | | CU_ASSERT_EQUAL(result, r); \ |
| | | } while(0) \ |
| | | |
| | | #define NOPAREN(...) __VA_ARGS__ |
| | | #define NOPAREN(...) __VA_ARGS__ |
| | | |
| | | #define TEST_MATCH_COMMAND2(p, s, r, v) \ |
| | | #define TEST_MATCH_COMMAND2(p, s, r, v) \ |
| | | do { \ |
| | | int32_t evalues[] = {NOPAREN v}; \ |
| | | unsigned int cnt = (sizeof(evalues)/4); \ |