2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Revision 4:de7feb458652, committed 2018-12-03
- Comitter:
- shimniok
- Date:
- Mon Dec 03 21:51:14 2018 +0000
- Parent:
- 3:4ffb1f9ba166
- Child:
- 5:eff573d4ede7
- Commit message:
- implemented part of config read/parse
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Config.cpp Mon Dec 03 21:51:14 2018 +0000 @@ -0,0 +1,50 @@ +#include "Config.h" + + +int Config::load(char *filename) +{ + char buf[MAXBUF]; + char *key; + char *value; + int status=0; + FILE *fp; + + fp = fopen(filename, "r"); + if (fp == NULL) { + status = -1; + } else { + while (!feof(fp)) { + fgets(buf, MAXBUF-1, fp); + if (buf[0] != '#') { + key = strtok(buf, ":"); + value = strtok(NULL, ":"); + if (*key && *value) { + printf("<%s>=<%s>\n", key, value); + // look for key + // parse value + // set options + } + } + } + fclose(fp); + }; + + return status; +} + + +/** Attach a setter for each key. The type of the setter's arg will be + * enforced by the parser when the config file is loaded. + */ +void Config::attach(Callback<void(char *)> set, char *key) { +} + + +void Config::attach(Callback<void(int)> set, char *key) { +} + +void Config::attach(Callback<void(float)> set, char *key) { +} + +void Config::attach(Callback<void(double)> set, char *key) { +} \ No newline at end of file
--- a/Config.h Sun Dec 02 17:48:23 2018 +0000 +++ b/Config.h Mon Dec 03 21:51:14 2018 +0000 @@ -6,10 +6,18 @@ class Config { public: int load(char *filename); - void attach(Callback<void(char *)> cb); - void attach(Callback<void(int)> cb); - void attach(Callback<void(float)> cb); - void attach(Callback<void(double)> cb); -} + + /** Attach a setter for each key. + * @param set is the setter + * @key is the key for which Config will call setter + */ + void attach(Callback<void(char *)> set, char *key); + void attach(Callback<void(int)> set, char *key); + void attach(Callback<void(float)> set, char *key); + void attach(Callback<void(double)> set, char *key); +private: + static const int MAXBUF=128; + char buf[MAXBUF]; +}; #endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/L3G4200D.lib Mon Dec 03 21:51:14 2018 +0000 @@ -0,0 +1,1 @@ +L3G4200D#9db065dfaf7d
--- a/main.cpp Sun Dec 02 17:48:23 2018 +0000 +++ b/main.cpp Mon Dec 03 21:51:14 2018 +0000 @@ -10,12 +10,13 @@ #include "SDBlockDevice.h" #include "FATFileSystem.h" #include "SimpleShell.h" +#include "Config.h" Serial pc(USBTX, USBRX); //SDBlockDevice bd(p5, p6, p7, p8); // MOSI, MISO, CLK, CS //FATFileSystem ffs("log", &bd); LocalFileSystem lfs("etc"); - +Config config; SimpleShell sh; DigitalOut led1(LED1); @@ -33,6 +34,11 @@ printf("Bootup...\n"); fflush(stdout); + printf("Loading config...\n"); + if (config.load("/etc/2018cfg.txt")) { + printf("error loading config\n"); + } + sh.attach(test, "test"); thread.start(callback(&sh, &SimpleShell::run));