You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.8 KiB
101 lines
2.8 KiB
/*
|
|
* 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 */
|
|
|