From c88388b415d38be346c9f6fda2cea94f9aec1779 Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Mon, 5 Dec 2022 18:53:22 +0100 Subject: [PATCH] renamed application to challenge_app, implemented basic shell commands for challenge application, --- ADIS_ESP32_Eclipse/main/Shell.c | 6 ++ ADIS_ESP32_Eclipse/main/application.c | 59 -------------- ADIS_ESP32_Eclipse/main/application.h | 13 --- ADIS_ESP32_Eclipse/main/challenge_app.c | 101 ++++++++++++++++++++++++ ADIS_ESP32_Eclipse/main/challenge_app.h | 27 +++++++ ADIS_ESP32_Eclipse/main/platform.c | 6 +- ADIS_ESP32_Eclipse/main/platform.h | 3 +- 7 files changed, 140 insertions(+), 75 deletions(-) delete mode 100644 ADIS_ESP32_Eclipse/main/application.c delete mode 100644 ADIS_ESP32_Eclipse/main/application.h create mode 100644 ADIS_ESP32_Eclipse/main/challenge_app.c create mode 100644 ADIS_ESP32_Eclipse/main/challenge_app.h diff --git a/ADIS_ESP32_Eclipse/main/Shell.c b/ADIS_ESP32_Eclipse/main/Shell.c index 18642e9..c5e8b85 100644 --- a/ADIS_ESP32_Eclipse/main/Shell.c +++ b/ADIS_ESP32_Eclipse/main/Shell.c @@ -41,6 +41,9 @@ #include "McuLog.h" #include "driver/uart.h" #include "driver/gpio.h" +#if PL_CONFIG_CHALLENGE_APP_ACTIVATED + #include "challenge_app.h" +#endif #define SHELL_ESP32_UART_DEVICE (UART_NUM_0) /* Uart for bootloader and connection to robot */ @@ -74,6 +77,9 @@ static const McuShell_ParseCommandCallback CmdParserTable[] = McuTimeDate_ParseCommand, #if PL_CONFIG_USE_BLINKY LED_ParseCommand, +#endif +#if PL_CONFIG_CHALLENGE_APP_ACTIVATED + Challenge_ParseCommand, #endif NULL /* Sentinel */ }; diff --git a/ADIS_ESP32_Eclipse/main/application.c b/ADIS_ESP32_Eclipse/main/application.c deleted file mode 100644 index 1a1c4cc..0000000 --- a/ADIS_ESP32_Eclipse/main/application.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * application.s - * - * Created on: 25.11.2022 - * Author: jonas - */ - -#include "application.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "myMqtt.h" -#include "wifi.h" - -static TaskHandle_t appTaskHandle; - -static void appTask(void *pv){ - if(pv != NULL){ - printf("task argument: %s\n", (char*)pv); - } - - printf("Application was started"); - fflush(stdout); - - while(WiFi_isConnected() == false){ - vTaskDelay(pdMS_TO_TICKS(1000)); - } - - // wifi now connected - printf("Application task detected that WiFi is connected\n"); - if(MyMqtt_Init()){ - vTaskDelay(pdMS_TO_TICKS(1000)); - printf("5s done\n"); - - MyMqtt_Subscribe("scada/status"); - - printf("Application endless task was started\n"); - fflush(stdout); - - // endless loop - for(;;){ - MyMqtt_Publish("scada/status", "Testmessage from ESP"); - - vTaskDelay(pdMS_TO_TICKS(10000)); - } - } else { - printf("Init of MyMqtt failed! Quitting application task.\n"); - } - -} - -BaseType_t res; - -void Application_Start(void){ - res = xTaskCreate(appTask, "task1", 4096/sizeof(StackType_t), (void*)"ARG_0", tskIDLE_PRIORITY, &appTaskHandle); - if(res != pdPASS){ - printf("creating myTask failed!\r\n"); - } -} - diff --git a/ADIS_ESP32_Eclipse/main/application.h b/ADIS_ESP32_Eclipse/main/application.h deleted file mode 100644 index 6d0383b..0000000 --- a/ADIS_ESP32_Eclipse/main/application.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * application.h - * - * Created on: 25.11.2022 - * Author: jonas - */ - -#ifndef MAIN_APPLICATION_H_ -#define MAIN_APPLICATION_H_ - -void Application_Start(void); - -#endif /* MAIN_APPLICATION_H_ */ diff --git a/ADIS_ESP32_Eclipse/main/challenge_app.c b/ADIS_ESP32_Eclipse/main/challenge_app.c new file mode 100644 index 0000000..1fab1df --- /dev/null +++ b/ADIS_ESP32_Eclipse/main/challenge_app.c @@ -0,0 +1,101 @@ +/* + * application.s + * + * Created on: 25.11.2022 + * Author: jonas + */ + + +#include "challenge_app.h" +#include "platform.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "myMqtt.h" +#include "wifi.h" + +/* LOCAL Var */ +// identifies robot Mode for the challenge: true = robot is stationary, false = robot is moveable +static bool robotModeStationary = false; +// task handle +static TaskHandle_t appTaskHandle; + + + +static void appTask(void *pv){ + if(pv != NULL){ + printf("task argument: %s\n", (char*)pv); + } + + printf("Application was started"); + fflush(stdout); + + while(WiFi_isConnected() == false){ + vTaskDelay(pdMS_TO_TICKS(1000)); + } + + // wifi now connected + printf("Application task detected that WiFi is connected\n"); + if(MyMqtt_Init()){ + vTaskDelay(pdMS_TO_TICKS(1000)); + printf("5s done\n"); + + MyMqtt_Subscribe("scada/status"); + + printf("Application endless task was started\n"); + fflush(stdout); + + // endless loop + for(;;){ + MyMqtt_Publish("scada/status", "Testmessage from ESP"); + + vTaskDelay(pdMS_TO_TICKS(10000)); + } + } else { + printf("Init of MyMqtt failed! Quitting application task.\n"); + } + +} + + +BaseType_t res; +void Challenge_App_Init(void){ + res = xTaskCreate(appTask, "ChallengeAppTask", 4096/sizeof(StackType_t), (void*)"ARG_0", tskIDLE_PRIORITY, &appTaskHandle); + if(res != pdPASS){ + printf("creating appTask failed!\r\n"); + } +} + +/*********/ +/* SHELL */ +/*********/ +#if PL_CONFIG_USE_SHELL +static uint8_t PrintStatus(const McuShell_StdIOType *io) { + McuShell_SendStatusStr((unsigned char*)"challenge", (unsigned char*)"ESP32 Challenge status\r\n", io->stdOut); + McuShell_SendStatusStr((unsigned char*)" robotMode", robotModeStationary?(unsigned char*)"stationary\r\n":(unsigned char*)"mobile\r\n", io->stdOut); + return ERR_OK; +} + +static uint8_t PrintHelp(const McuShell_StdIOType *io) { + McuShell_SendHelpStr((unsigned char*)"challenge", (unsigned char*)"Group of ESP32 Challenge commands\r\n", io->stdOut); + McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Shows Challenge help or status\r\n", io->stdOut); + return ERR_OK; +} + +uint8_t Challenge_ParseCommand(const unsigned char* cmd, bool *handled, const McuShell_StdIOType *io) { + if (McuUtility_strcmp((char*)cmd, (char*)McuShell_CMD_HELP)==0 || McuUtility_strcmp((char*)cmd, (char*)"challenge help")==0) { + *handled = TRUE; + return PrintHelp(io); + } else if (McuUtility_strcmp((char*)cmd, (char*)McuShell_CMD_STATUS)==0 || McuUtility_strcmp((char*)cmd, (char*)"challenge status")==0) { + *handled = TRUE; + return PrintStatus(io); + } + /*else if (McuUtility_strcmp((char*)cmd, (char*)"led suspend")==0) { + *handled = TRUE; + LED_Suspend(); + } else if (McuUtility_strcmp((char*)cmd, (char*)"led resume")==0) { + *handled = TRUE; + LED_Resume(); + }*/ + return ERR_OK; +} +#endif /* PL_CONFIG_USE_SHELL */ diff --git a/ADIS_ESP32_Eclipse/main/challenge_app.h b/ADIS_ESP32_Eclipse/main/challenge_app.h new file mode 100644 index 0000000..92eb31b --- /dev/null +++ b/ADIS_ESP32_Eclipse/main/challenge_app.h @@ -0,0 +1,27 @@ +/* + * application.h + * + * Created on: 25.11.2022 + * Author: jonas + */ + +#ifndef MAIN_CHALLENGE_APP_H_ +#define MAIN_CHALLENGE_APP_H_ + +/*! \brief Module initialization, start app task */ +void Challenge_App_Init(void); + +#if PL_CONFIG_USE_SHELL + #include "McuShell.h" + + /*! + * \brief Command line and shell handler + * \param cmd The command to be parsed + * \param handled If command has been recognized and handled + * \param io I/O handler to be used + * \return error code, otherwise ERR_OK + */ + uint8_t Challenge_ParseCommand(const unsigned char* cmd, bool *handled, const McuShell_StdIOType *io); +#endif + +#endif /* MAIN_CHALLENGE_APP_H_ */ diff --git a/ADIS_ESP32_Eclipse/main/platform.c b/ADIS_ESP32_Eclipse/main/platform.c index a260af0..9a5137f 100644 --- a/ADIS_ESP32_Eclipse/main/platform.c +++ b/ADIS_ESP32_Eclipse/main/platform.c @@ -53,7 +53,9 @@ #include "McuCriticalSection.h" #include "esp32_mac.h" #include "rs485.h" -#include "application.c" +#if PL_CONFIG_CHALLENGE_APP_ACTIVATED + #include "challenge_app.h" +#endif void PL_Init(void) { McuLib_Init(); @@ -105,7 +107,7 @@ void PL_Init(void) { #if PL_CONFIG_USE_ROBO_REMOTE ROBOT_Init(); #endif -#if PL_CONFIG_APPLICATION_ACTIVATED +#if PL_CONFIG_CHALLENGE_APP_ACTIVATED Application_Start(); #endif } diff --git a/ADIS_ESP32_Eclipse/main/platform.h b/ADIS_ESP32_Eclipse/main/platform.h index 001429f..55e495e 100644 --- a/ADIS_ESP32_Eclipse/main/platform.h +++ b/ADIS_ESP32_Eclipse/main/platform.h @@ -21,7 +21,8 @@ #define PL_CONFIG_USE_TIME_DATE (1) /*!< if using Time and Date information */ #define PL_CONFIG_USE_ROBO_REMOTE (1 && PL_CONFIG_USE_UDP_SERVER) /* UDP Remote controller for robot */ -#define PL_CONFIG_APPLICATION_ACTIVATED (1) +/* challenge config */ +#define PL_CONFIG_CHALLENGE_APP_ACTIVATED (1) /*! \brief Module and platform initialization */ void PL_Init(void);