diff --git a/Makefile b/Makefile index 10f3d4e..ac454c8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SRC = main.c +SRC = example.c SRC+= source/scpi_parser.c SRC+= source/scpi_regs.c SRC+= source/scpi_builtins.c @@ -16,14 +16,12 @@ CFLAGS += -Wredundant-decls -Wfloat-equal -Wsign-compare -Wunused-function all: $(SRC) $(HDRS) - gcc $(CFLAGS) $(SRC) -o main.elf + gcc $(CFLAGS) $(SRC) -o example.elf run: all - ./main.elf + ./example.elf clean: rm -f *.o *.d *.so *.elf *.bin *.hex cd source rm -f *.o *.d *.so *.elf *.bin *.hex - - diff --git a/README.md b/README.md index bb09938..e1d40b5 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,70 @@ The implementation is not 100% complete, but it's sufficient for basic SCPI comm Built-in commands can be overriden in user command array. +## How to use + See main.c for example of how to use the library. +Here's an overview of stubs you have to implement (at the time of writingthis readme): + +```c +#include "scpi_parser.h" + +const SCPI_error_desc scpi_user_errors[] = { + {10, "Custom error"}, // add your custom errors here + {/*END*/} +}; + + +void scpi_send_byte_impl(uint8_t b) +{ + // send the byte to master (over UART?) +} + + +const char *scpi_device_identifier(void) +{ + // fill in your device info + // possible to eg. read a serial # from EEPROM + return ",,,"; +} + +/* OPTIONAL callback */ +void scpi_service_request_impl(void) +{ + // called when the SRQ flag in Status Byte is set. + // device should somehow send the request to master + // (can be left unimplemented) +} + +/* Custom commands */ +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 = {"DISPlay", "TEXT"}, + .params = {SCPI_DT_STRING}, + .callback = cmd_DISP_TEXT_cb // <-- your callback function + }, + { + .levels = {"DATA", "BLOB"}, + .params = {SCPI_DT_BLOB}, + .callback = cmd_DATA_BLOB_cb, // <-- command callback + .blob_chunk = 4, + .blob_callback = cmd_DATA_BLOB_data // <-- data callback + }, + {/*END*/} +}; + +// See the header files for more info. + +``` + ## What is missing -- Setting error type flags in the ESR when error is added to queue -- There may be some bugs in the status registers (not tested much) -- Character data argument ("string without quotes", enum-like) - Number units and metric suffixes (k,M,G,m,u,n) - DEF, MIN, MAX, INF, NINF argument values for numbers diff --git a/main.c b/example.c similarity index 97% rename from main.c rename to example.c index f6f2c02..6d8409a 100644 --- a/main.c +++ b/example.c @@ -105,7 +105,7 @@ void cmd_USRERR_cb(const SCPI_argval_t *args) void cmd_CHARD_cb(const SCPI_argval_t *args) { - printf("CHARData cb: %s, arg2 = %d", args[0].CHARDATA, args[1].INT); + printf("CHARData cb: %s, arg2 = %d\n", args[0].CHARDATA, args[1].INT); } diff --git a/scpi.pro.user b/scpi.pro.user deleted file mode 100644 index 27cb714..0000000 --- a/scpi.pro.user +++ /dev/null @@ -1,264 +0,0 @@ - - - - - - EnvironmentId - {dfe3cb4a-0f3e-4da9-9c52-5d2c464adafb} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - true - 80 - true - true - 1 - true - false - 0 - true - 0 - 8 - true - 1 - true - true - true - true - - - - ProjectExplorer.Project.PluginSettings - - - - 1 - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop - {ee748544-c6c0-4f44-9cef-fbb65dc2525a} - 0 - 0 - 0 - - /home/ondra/stm32/scpi_ - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/ondra/stm32/build-scpi-Desktop-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 2 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - scpi - - Qt4ProjectManager.Qt4RunConfiguration:/home/ondra/stm32/scpi_/scpi.pro - - scpi.pro - false - true - - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - -