diff --git a/main.c b/main.c index bc0296f..f7480c1 100644 --- a/main.c +++ b/main.c @@ -4,163 +4,85 @@ #include "source/scpi_parser.h" +// ------- TESTING ---------- -void cmd_APPL_SIN_cb(const SCPI_argval_t *args) +int main() { - printf("cb APPLy:SINe\n"); + scpi_handle_string("*IDN?\n"); + scpi_handle_string("*SRE 4\n"); + scpi_handle_string("FOO:BAR:BAZ\n"); + scpi_handle_string("SYST:ERR:COUNT?\n"); + scpi_handle_string("SYST:ERR?\n"); + scpi_handle_string("SYST:ERR?\n"); + scpi_handle_string("DATA:BLOB #216abcdefghijklmnop\n"); + scpi_handle_string("SYST:ERR?\n"); } -void cmd_APPL_TRI_cb(const SCPI_argval_t *args) +// ---- Test device impl ---- + +void scpi_send_byte_impl(uint8_t b) { - printf("cb APPLy:TRIangle\n"); + putchar(b); // device sends a byte } -void cmd_FREQ_cb(const SCPI_argval_t *args) +const char *scpi_device_identifier(void) { - printf("cb FREQuency %d\n", args[0].INT); + return "FEL CVUT,DDS1,0,0.1"; } -void cmd_DISP_TEXT_cb(const SCPI_argval_t *args) + +void scpi_service_request_impl(void) { - printf("cb DISPlay:TEXT %s, %d\n", args[0].STRING, args[1].BOOL); + printf("[SRQ]\n"); } -void cmd_DATA_BLOB_cb(const SCPI_argval_t *args) +// ---- COMMANDS ---- + +void cmd_APPL_SIN_cb(const SCPI_argval_t *args) { - printf("cb DATA:BLOB %f, <%d>\n", args[0].FLOAT, args[1].BLOB_LEN); + printf("cb APPLy:SINe %d, %f, %f\n", args[0].INT, args[0].FLOAT, args[0].FLOAT); } -void cmd_DATA_BLOB_data(const uint8_t *bytes) -{ - printf("blob item: %s\n", bytes); -} -void cmd_STQENq_cb(const SCPI_argval_t *args) +void cmd_DISP_TEXT_cb(const SCPI_argval_t *args) { - printf("STATUS:QUEUE:ENABLE:NEXT?\n"); + printf("cb DISPlay:TEXT %s\n", args[0].STRING); } -void cmd_STQEq_cb(const SCPI_argval_t *args) + +void cmd_DATA_BLOB_cb(const SCPI_argval_t *args) { - printf("STATUS:QUEUE:ENABLE?\n"); + printf("cb DATA:BLOB <%d>\n", args[1].BLOB_LEN); } -void cmd_STQE_cb(const SCPI_argval_t *args) + +void cmd_DATA_BLOB_data(const uint8_t *bytes) { - printf("STATUS:QUEUE:ENABLE %d\n", args[0].BOOL); + printf("blob item: %s\n", bytes); } + const SCPI_command_t scpi_commands[] = { { .levels = {"APPLy", "SINe"}, .params = {SCPI_DT_INT, SCPI_DT_FLOAT, SCPI_DT_FLOAT}, .callback = cmd_APPL_SIN_cb }, - { - .levels = {"APPLy", "TRIangle"}, - .params = {SCPI_DT_BOOL, SCPI_DT_FLOAT, SCPI_DT_FLOAT}, - .callback = cmd_APPL_TRI_cb - }, - { - .levels = {"FREQuency"}, - .params = {SCPI_DT_INT}, - .callback = cmd_FREQ_cb - }, { .levels = {"DISPlay", "TEXT"}, - .params = {SCPI_DT_STRING, SCPI_DT_BOOL}, + .params = {SCPI_DT_STRING}, .callback = cmd_DISP_TEXT_cb }, { .levels = {"DATA", "BLOB"}, - .params = {SCPI_DT_FLOAT, SCPI_DT_BLOB}, + .params = {SCPI_DT_BLOB}, .callback = cmd_DATA_BLOB_cb, .blob_chunk = 4, .blob_callback = cmd_DATA_BLOB_data }, - { - .levels = {"STATus", "QUEue", "ENABle", "NEXT?"}, - .callback = cmd_STQENq_cb - }, - { - .levels = {"STATus", "QUEue", "ENABle?"}, - .callback = cmd_STQEq_cb - }, - { - .levels = {"STATus", "QUEue", "ENABle"}, - .params = {SCPI_DT_BOOL}, - .callback = cmd_STQE_cb - }, {0} // end marker }; - - - -void scpi_send_byte_impl(uint8_t b) -{ - putchar(b); -} - - -const char *scpi_device_identifier(void) -{ - return "FEL CVUT,DDS1,0,0.1"; -} - -int main() -{ - char buf[256]; - -// SCPI_REG_QUEST.CURR = 1; -// SCPI_REG_QUEST_EN.u16 = 0xFFFF; - -// printf("0x%x\n", SCPI_REG_QUEST.u16); - -// scpi_status_update(); - - -// return 0; - - -// const char *inp = "*IDN?\n"; -// const char *inp = "FREQ 50\n"; -// const char *inp = "DISP:TEXT 'ban\\\\ana', OFF\nDISP:TEXT \"dblquot!\", 1\r\nFREQ 50\r\n"; - - //const char *inp = "FOO\nDATA:BLOB 13.456, #216AbcdEfghIjklMnop\nFREQ 50\r\nAPPLY:MOO\n"; - //const char *inp = "STAT:QUE:ENAB?;ENAB \t 1;ENAB?;:*IDN?\n"; - - const char *inp = "*idn?;*sre?;*cls;"; - - for (int i = 0; i < strlen(inp); i++) { - scpi_handle_byte(inp[i]); - } - - - //scpi_error_string(buf, E_EXE_DATA_QUESTIONABLE, "The data smells fishy"); - - //scpi_read_error(buf), printf("%s\n", buf); - -// scpi_add_error(E_CMD_BLOCK_DATA_ERROR, NULL); - -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_add_error(E_CMD_DATA_TYPE_ERROR, "LOL OOPS"); -// scpi_add_error(E_CMD_CHARACTER_DATA_TOO_LONG, "Too long data very overflow such fail"); -// scpi_add_error(E_CMD_MACRO_PARAMETER_ERROR, "maaaacrooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"); -// scpi_add_error(E_CMD_EXPONENT_TOO_LARGE, NULL); -// scpi_add_error(E_DEV_CALIBRATION_FAILED, NULL); -// scpi_add_error(E_DEV_MEMORY_ERROR, NULL); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_add_error(E_DEV_MEMORY_ERROR, "lel"); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -// scpi_read_error(buf), printf("%s\n", buf); -} diff --git a/source/scpi_parser.c b/source/scpi_parser.c index 0f53346..5b4acbe 100644 --- a/source/scpi_parser.c +++ b/source/scpi_parser.c @@ -230,6 +230,14 @@ static void err_no_such_command_partial() // ----------------- INPUT PARSING ---------------- +void scpi_handle_string(const char* str) +{ + while (*str != 0) { + scpi_handle_byte(*str); + str++; + } +} + void scpi_handle_byte(const uint8_t b) { const char c = (char) b; diff --git a/source/scpi_parser.h b/source/scpi_parser.h index af279b7..3d175e3 100644 --- a/source/scpi_parser.h +++ b/source/scpi_parser.h @@ -77,6 +77,13 @@ extern void scpi_send_byte_impl(uint8_t b); */ void scpi_handle_byte(const uint8_t b); +/** + * SCPI parser - handle a string (multiple chars) at once. + * String is interpreted as is, nothing is added. Must be terminated with \0. + */ +void scpi_handle_string(const char* str); + + /** Add error to the error queue */ void scpi_add_error(SCPI_error_t errno, const char *extra);