diff --git a/src/cmnds/cmd_local.h b/src/cmnds/cmd_local.h new file mode 100644 index 000000000..1a872b20b --- /dev/null +++ b/src/cmnds/cmd_local.h @@ -0,0 +1,23 @@ + +#include "cmd_public.h" + +typedef struct command_s { + const char *name; + const char *argsFormat; + commandHandler_t handler; + const char *userDesc; + const void *context; + struct command_s *next; +} command_t; + +command_t *CMD_Find(const char *name); +// for autocompletion? +void CMD_ListAllCommands(void *userData, void (*callback)(command_t *cmd, void *userData)); +int get_cmd(const char *s, char *dest, int maxlen, int stripnum); +bool isWhiteSpace(char ch); + + + + + + diff --git a/src/new_cmd.c b/src/cmnds/cmd_main.c similarity index 90% rename from src/new_cmd.c rename to src/cmnds/cmd_main.c index 7fea65e0d..672e26fa0 100644 --- a/src/new_cmd.c +++ b/src/cmnds/cmd_main.c @@ -1,11 +1,11 @@ -#include "new_pins.h" -#include "new_cfg.h" -#include "logging/logging.h" -#include "obk_config.h" -#include -#include "new_cmd.h" +#include "../new_pins.h" +#include "../new_cfg.h" +#include "../logging/logging.h" +#include "../obk_config.h" +#include +#include "cmd_local.h" #ifdef BK_LITTLEFS - #include "littlefs/our_lfs.h" + #include "../littlefs/our_lfs.h" #endif #define HASH_SIZE 128 diff --git a/src/cmnds/newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c similarity index 99% rename from src/cmnds/newLEDDriver.c rename to src/cmnds/cmd_newLEDDriver.c index 8c63cfdf0..0503d794e 100644 --- a/src/cmnds/newLEDDriver.c +++ b/src/cmnds/cmd_newLEDDriver.c @@ -3,7 +3,7 @@ #include "../new_pins.h" #include "../obk_config.h" #include -#include "../new_cmd.h" +#include "cmd_local.h" #ifdef BK_LITTLEFS #include "../littlefs/our_lfs.h" #endif diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h new file mode 100644 index 000000000..5b2fbd383 --- /dev/null +++ b/src/cmnds/cmd_public.h @@ -0,0 +1,29 @@ + + + +typedef int (*commandHandler_t)(const void *context, const char *cmd, const char *args); + + + +// +void CMD_Init(); +void CMD_RegisterCommand(const char *name, const char *args, commandHandler_t handler, const char *userDesc, void *context); +int CMD_ExecuteCommand(const char *s); +int CMD_ExecuteCommandArgs(const char *cmd, const char *args); + + +// cmd_tokenizer.c +int Tokenizer_GetArgsCount(); +const char *Tokenizer_GetArg(int i); +const char *Tokenizer_GetArgFrom(int i); +int Tokenizer_GetArgInteger(int i); +void Tokenizer_TokenizeString(const char *s); +// cmd_repeatingEvents.c +void RepeatingEvents_Init(); +void RepeatingEvents_OnEverySecond(); +// cmd_tasmota.c +int taslike_commands_init(); +// cmd_newLEDDriver.c +int NewLED_InitCommands(); +// cmd_test.c +int fortest_commands_init(); \ No newline at end of file diff --git a/src/new_repeatingEvents.c b/src/cmnds/cmd_repeatingEvents.c similarity index 89% rename from src/new_repeatingEvents.c rename to src/cmnds/cmd_repeatingEvents.c index ecd319cb3..ed8daa163 100644 --- a/src/new_repeatingEvents.c +++ b/src/cmnds/cmd_repeatingEvents.c @@ -1,11 +1,10 @@ -#include "new_common.h" -#include "new_tokenizer.h" -#include "httpserver/new_http.h" -#include "logging/logging.h" -#include "new_pins.h" -#include "new_cfg.h" -#include "new_cmd.h" +#include "../new_common.h" +#include "cmd_local.h" +#include "../httpserver/new_http.h" +#include "../logging/logging.h" +#include "../new_pins.h" +#include "../new_cfg.h" typedef struct repeatingEvent_s { char *command; diff --git a/src/cmnds/taslike.c b/src/cmnds/cmd_tasmota.c similarity index 99% rename from src/cmnds/taslike.c rename to src/cmnds/cmd_tasmota.c index 9db79d87c..8e7ae6a6b 100644 --- a/src/cmnds/taslike.c +++ b/src/cmnds/cmd_tasmota.c @@ -3,7 +3,7 @@ #include "../new_pins.h" #include "../obk_config.h" #include -#include "../new_cmd.h" +#include "cmd_local.h" #include "../new_pins.h" #ifdef BK_LITTLEFS #include "../littlefs/our_lfs.h" diff --git a/src/cmnds/fortest.c b/src/cmnds/cmd_test.c similarity index 98% rename from src/cmnds/fortest.c rename to src/cmnds/cmd_test.c index f09f52d84..a5487612c 100644 --- a/src/cmnds/fortest.c +++ b/src/cmnds/cmd_test.c @@ -4,7 +4,7 @@ #include "../new_pins.h" #include "../obk_config.h" #include -#include "../new_cmd.h" +#include "cmd_local.h" #ifdef BK_LITTLEFS #include "../littlefs/our_lfs.h" #endif diff --git a/src/new_tokenizer.c b/src/cmnds/cmd_tokenizer.c similarity index 87% rename from src/new_tokenizer.c rename to src/cmnds/cmd_tokenizer.c index b559bae60..93450dd50 100644 --- a/src/new_tokenizer.c +++ b/src/cmnds/cmd_tokenizer.c @@ -1,8 +1,8 @@ -#include "new_common.h" -#include "httpserver/new_http.h" -#include "new_pins.h" -#include "new_cfg.h" +#include "../new_common.h" +#include "../httpserver/new_http.h" +#include "../new_pins.h" +#include "../new_cfg.h" #define MAX_CMD_LEN 512 #define MAX_ARGS 32 diff --git a/src/cmnds/fortest.h b/src/cmnds/fortest.h deleted file mode 100644 index f9da35fe9..000000000 --- a/src/cmnds/fortest.h +++ /dev/null @@ -1 +0,0 @@ -int fortest_commands_init(); \ No newline at end of file diff --git a/src/cmnds/taslike.h b/src/cmnds/taslike.h deleted file mode 100644 index 3cb438650..000000000 --- a/src/cmnds/taslike.h +++ /dev/null @@ -1,2 +0,0 @@ - -int taslike_commands_init(); \ No newline at end of file diff --git a/src/drv_bl0942.c b/src/driver/drv_bl0942.c similarity index 95% rename from src/drv_bl0942.c rename to src/driver/drv_bl0942.c index a1d0cf415..4e01584b0 100644 --- a/src/drv_bl0942.c +++ b/src/driver/drv_bl0942.c @@ -1,12 +1,13 @@ -#include "new_common.h" -#include "new_pins.h" -#include "new_cfg.h" -#include "new_cmd.h" -#include "mqtt/new_mqtt.h" -#include "logging/logging.h" +#include "../new_common.h" +#include "../new_pins.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../mqtt/new_mqtt.h" +#include "../logging/logging.h" #include "drv_bl0942.h" #include "drv_uart.h" -#include "httpserver/new_http.h" +#include "../httpserver/new_http.h" float BL0942_PREF = 598; float BL0942_UREF = 15188; diff --git a/src/drv_bl0942.h b/src/driver/drv_bl0942.h similarity index 76% rename from src/drv_bl0942.h rename to src/driver/drv_bl0942.h index fe59ca4fe..8ca04c6bf 100644 --- a/src/drv_bl0942.h +++ b/src/driver/drv_bl0942.h @@ -1,5 +1,5 @@ -#include "httpserver/new_http.h" +#include "../httpserver/new_http.h" void BL0942_Init(); void BL0942_RunFrame(); diff --git a/src/drv_config.h b/src/driver/drv_config.h similarity index 100% rename from src/drv_config.h rename to src/driver/drv_config.h diff --git a/src/drv_main.c b/src/driver/drv_main.c similarity index 86% rename from src/drv_main.c rename to src/driver/drv_main.c index 8b565e713..1d0702635 100644 --- a/src/drv_main.c +++ b/src/driver/drv_main.c @@ -1,14 +1,15 @@ -#include "new_common.h" -#include "new_pins.h" -#include "new_cfg.h" -#include "new_cmd.h" -#include "logging/logging.h" +#include "../new_common.h" +#include "../new_pins.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../logging/logging.h" #include "drv_bl0942.h" #include "drv_uart.h" #include "drv_tuyaMCU.h" -#include "drv_i2c_public.h" -#include "ntp_time.h" -#include "httpserver/new_http.h" +#include "../i2c/drv_i2c_public.h" +#include "drv_ntp.h" +#include "../httpserver/new_http.h" typedef struct driver_s { diff --git a/src/ntp_time.c b/src/driver/drv_ntp.c similarity index 94% rename from src/ntp_time.c rename to src/driver/drv_ntp.c index d08b8b6dc..cc8082074 100644 --- a/src/ntp_time.c +++ b/src/driver/drv_ntp.c @@ -2,10 +2,10 @@ // Based on my previous work here: // https://www.elektroda.pl/rtvforum/topic3712112.html -#include "new_common.h" +#include "../new_common.h" #include -#include "new_tokenizer.h" -#include "new_cmd.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" #ifdef WINDOWS @@ -24,7 +24,7 @@ #endif -#include "logging/logging.h" +#include "../logging/logging.h" #define LOG_FEATURE LOG_FEATURE_NTP diff --git a/src/ntp_time.h b/src/driver/drv_ntp.h similarity index 100% rename from src/ntp_time.h rename to src/driver/drv_ntp.h diff --git a/src/drv_public.h b/src/driver/drv_public.h similarity index 77% rename from src/drv_public.h rename to src/driver/drv_public.h index dbebc7c9d..8a03b3abe 100644 --- a/src/drv_public.h +++ b/src/driver/drv_public.h @@ -2,6 +2,6 @@ void DRV_Generic_Init(); -#include "httpserver/new_http.h" +#include "../httpserver/new_http.h" void DRV_AppendInformationToHTTPIndexPage(http_request_t *request); void DRV_OnEverySecond(); \ No newline at end of file diff --git a/src/drv_tuyaMCU.c b/src/driver/drv_tuyaMCU.c similarity index 98% rename from src/drv_tuyaMCU.c rename to src/driver/drv_tuyaMCU.c index 82f360b98..88e1a8679 100644 --- a/src/drv_tuyaMCU.c +++ b/src/driver/drv_tuyaMCU.c @@ -1,13 +1,13 @@ -#include "new_common.h" -#include "new_pins.h" -#include "new_cfg.h" -#include "new_cmd.h" -#include "logging/logging.h" +#include "../new_common.h" +#include "../new_pins.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../logging/logging.h" #include "drv_tuyaMCU.h" #include "drv_uart.h" #include -#include "ntp_time.h" -#include "new_tokenizer.h" +#include "drv_ntp.h" #define TUYA_CMD_HEARTBEAT 0x00 diff --git a/src/drv_tuyaMCU.h b/src/driver/drv_tuyaMCU.h similarity index 100% rename from src/drv_tuyaMCU.h rename to src/driver/drv_tuyaMCU.h diff --git a/src/drv_uart.c b/src/driver/drv_uart.c similarity index 91% rename from src/drv_uart.c rename to src/driver/drv_uart.c index 9fb933119..e72e41adc 100644 --- a/src/drv_uart.c +++ b/src/driver/drv_uart.c @@ -1,8 +1,9 @@ -#include "new_common.h" -#include "new_pins.h" -#include "new_cfg.h" -#include "new_cmd.h" -#include "logging/logging.h" +#include "../new_common.h" +#include "../new_pins.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../logging/logging.h" #if PLATFORM_BK7231T | PLATFORM_BK7231N diff --git a/src/drv_uart.h b/src/driver/drv_uart.h similarity index 100% rename from src/drv_uart.h rename to src/driver/drv_uart.h diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index cd3a19502..dab26f03c 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -3,10 +3,11 @@ #include "http_fns.h" #include "../new_pins.h" #include "../new_cfg.h" -#include "../ota/ota.h" -#include "../new_cmd.h" -#include "../drv_tuyaMCU.h" -#include "../drv_public.h" +#include "../ota/ota.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../driver/drv_tuyaMCU.h" +#include "../driver/drv_public.h" #include "../logging/logging.h" #ifdef WINDOWS diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index 131e80683..c6d03ab24 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -19,8 +19,9 @@ #endif #include "../new_cfg.h" #include "../flash_config/flash_vars_vars.h" -#include "../flash_config/flash_vars.h" -#include "../new_cmd.h" +#include "../flash_config/flash_vars.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" #if PLATFORM_XR809 uint32_t flash_read(uint32_t flash, uint32_t addr,void *buf, uint32_t size); diff --git a/src/i2c/drv_i2c_local.h b/src/i2c/drv_i2c_local.h index a0f5f6a5f..d7de3a69d 100644 --- a/src/i2c/drv_i2c_local.h +++ b/src/i2c/drv_i2c_local.h @@ -64,7 +64,8 @@ i2cDevice_t *DRV_I2C_FindDeviceExt(int busType,int address, int devType); // drv_i2c_mcp23017.c void DRV_I2C_MCP23017_RunDevice(i2cDevice_t *dev); -int DRV_I2C_MCP23017_MapPinToChannel(const void *context, const char *cmd, const char *args); +int DRV_I2C_MCP23017_MapPinToChannel(const void *context, const char *cmd, const char *args); +void DRV_I2C_MCP23017_OnChannelChanged(i2cDevice_t *dev, int channel, int iVal); // drv_i2c_tc74.c void DRV_I2C_TC74_RunDevice(i2cDevice_t *dev); diff --git a/src/i2c/drv_i2c_main.c b/src/i2c/drv_i2c_main.c index dfcfb9679..b71bd20fc 100644 --- a/src/i2c/drv_i2c_main.c +++ b/src/i2c/drv_i2c_main.c @@ -1,11 +1,11 @@ #include "../new_common.h" #include "../new_pins.h" #include "../new_cfg.h" -#include "../new_cmd.h" #include "../logging/logging.h" #include "drv_i2c_local.h" -#include "../drv_i2c_public.h" -#include "../new_tokenizer.h" +#include "drv_i2c_public.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" #if PLATFORM_BK7231T diff --git a/src/i2c/drv_i2c_mcp23017.c b/src/i2c/drv_i2c_mcp23017.c index b3b5eaeac..b192d8bb1 100644 --- a/src/i2c/drv_i2c_mcp23017.c +++ b/src/i2c/drv_i2c_mcp23017.c @@ -1,9 +1,9 @@ #include "../new_common.h" #include "../new_pins.h" -#include "../new_cfg.h" -#include "../new_cmd.h" -#include "../logging/logging.h" -#include "../new_tokenizer.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../logging/logging.h" #include "drv_i2c_local.h" // addresses, banks, etc, defines #include "drv_i2c_mcp23017.h" diff --git a/src/drv_i2c_public.h b/src/i2c/drv_i2c_public.h similarity index 100% rename from src/drv_i2c_public.h rename to src/i2c/drv_i2c_public.h diff --git a/src/i2c/drv_i2c_tc74.c b/src/i2c/drv_i2c_tc74.c index e27d75a68..7d6164dc6 100644 --- a/src/i2c/drv_i2c_tc74.c +++ b/src/i2c/drv_i2c_tc74.c @@ -1,7 +1,8 @@ #include "../new_common.h" #include "../new_pins.h" -#include "../new_cfg.h" -#include "../new_cmd.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" #include "../logging/logging.h" #include "drv_i2c_local.h" diff --git a/src/logging/logging.c b/src/logging/logging.c index 69d29ac14..3220c92ad 100644 --- a/src/logging/logging.c +++ b/src/logging/logging.c @@ -17,8 +17,9 @@ #include "str_pub.h" #endif -#include "../logging/logging.h" -#include "../new_cmd.h" +#include "../logging/logging.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" static char tmp[1024]; int loglevel = 4; // default to info diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index 596c114ea..16f49b5f6 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -3,8 +3,9 @@ #include "../new_pins.h" #include "../new_cfg.h" #include "../logging/logging.h" -#include -#include "../new_cmd.h" +#include +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" #undef os_printf diff --git a/src/new_cmd.h b/src/new_cmd.h deleted file mode 100644 index 152627fce..000000000 --- a/src/new_cmd.h +++ /dev/null @@ -1,39 +0,0 @@ - - -typedef int (*commandHandler_t)(const void *context, const char *cmd, const char *args); - -typedef struct command_s { - const char *name; - const char *argsFormat; - commandHandler_t handler; - const char *userDesc; - const void *context; - struct command_s *next; -} command_t; - -void CMD_Init(); -command_t *CMD_Find(const char *name); -void CMD_RegisterCommand(const char *name, const char *args, commandHandler_t handler, const char *userDesc, void *context); -int CMD_ExecuteCommand(const char *s); -int CMD_ExecuteCommandArgs(const char *cmd, const char *args); -// NOTE: argsCount includes commands name, so 1 tells "only command" -int CMD_GetArgsCount() ; -// NOTE: arg0 is command name -const char *CMD_GetArg(int i); -// for autocompletion? -void CMD_ListAllCommands(void *userData, void (*callback)(command_t *cmd, void *userData)); -int get_cmd(const char *s, char *dest, int maxlen, int stripnum); -bool isWhiteSpace(char ch); - -// -int NewLED_InitCommands(); -// - -// - -// - - - - - diff --git a/src/new_pins.c b/src/new_pins.c index c6d0946a6..099b5af5f 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -5,9 +5,9 @@ #include "new_pins.h" #include "httpserver/new_http.h" #include "logging/logging.h" -#include "new_cmd.h" -#include "new_tokenizer.h" -#include "drv_i2c_public.h" +// Commands register, execution API and cmd tokenizer +#include "cmnds/cmd_public.h" +#include "i2c/drv_i2c_public.h" //According to your need to modify the constants. diff --git a/src/new_repeatingEvents.h b/src/new_repeatingEvents.h deleted file mode 100644 index ba48dc490..000000000 --- a/src/new_repeatingEvents.h +++ /dev/null @@ -1,4 +0,0 @@ - - -void RepeatingEvents_OnEverySecond(); -void RepeatingEvents_Init(); \ No newline at end of file diff --git a/src/new_tokenizer.h b/src/new_tokenizer.h deleted file mode 100644 index d7bfbe075..000000000 --- a/src/new_tokenizer.h +++ /dev/null @@ -1,6 +0,0 @@ - -int Tokenizer_GetArgsCount(); -const char *Tokenizer_GetArg(int i); -const char *Tokenizer_GetArgFrom(int i); -int Tokenizer_GetArgInteger(int i); -void Tokenizer_TokenizeString(const char *s); \ No newline at end of file diff --git a/src/user_main.c b/src/user_main.c index ea3510553..1011eb5bb 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -17,9 +17,10 @@ #include "mem_pub.h" #include "str_pub.h" #include "ethernet_intf.h" -#include "drv_public.h" - -#include "new_repeatingEvents.h" +#include "driver/drv_public.h" + +// Commands register, execution API and cmd tokenizer +#include "cmnds/cmd_public.h" // overall config variables for app - like BK_LITTLEFS #include "obk_config.h" @@ -39,12 +40,7 @@ #include "flash_config/flash_config.h" #include "flash_config/flash_vars_vars.h" -#include "drv_tuyaMCU.h" -#include "ntp_time.h" -#include "new_cmd.h" - -#include "cmnds/taslike.h" -#include "cmnds/fortest.h" +#include "driver/drv_ntp.h" static int g_secondsElapsed = 0; diff --git a/windowsTest_msvc2008.vcproj b/windowsTest_msvc2008.vcproj index a28c725eb..9f6042eff 100644 --- a/windowsTest_msvc2008.vcproj +++ b/windowsTest_msvc2008.vcproj @@ -291,10 +291,6 @@ RelativePath=".\src\new_cfg.c" > - - @@ -335,14 +331,6 @@ RelativePath=".\src\new_pins.c" > - - - - @@ -749,6 +737,94 @@ > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +