diff --git a/README.md b/README.md index 26a2bc2..f854498 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Commands can be send from the Cumulocity App Devicemanagement to change the sens Install the XDK Workbench: https://xdk.bosch-connectivity.com/software-downloads > NOTE: The installation path must not contains blanks. -> NOTE: The current version of the Workbench 3.6.0 defines a buffer size that is not sufficient for the certificate being used for Cumulocity. Therefore the buffer has to be increased. +> NOTE: The current version of the Workbench 3.6.1 defines a buffer size that is not sufficient for the certificate being used for Cumulocity. Therefore the buffer has to be increased. In order to avoid a buffer overflow, as seen in the following error message: diff --git a/source/AppController.c b/source/AppController.c index 27675e0..116a7d3 100644 --- a/source/AppController.c +++ b/source/AppController.c @@ -138,6 +138,7 @@ static void AppController_Setup(void * param1, uint32_t param2) { retcode = RETCODE(RETCODE_SEVERITY_ERROR,RETCODE_UNEXPECTED_BEHAVIOR); } + //test if button 2 is pressed if (BSP_Button_GetState((uint32_t) BSP_XDK_BUTTON_2) == 1) { LOG_AT_INFO(("AppController_Setup: Button 2 was pressed at startup and delete config stored on WIFI chip!\r\n")); MQTTFlash_FLDeleteConfig(); @@ -220,7 +221,6 @@ static void AppController_Enable(void * param1, uint32_t param2) { BCDS_UNUSED(param1); BCDS_UNUSED(param2); - Retcode_T retcode = WLAN_Enable(); if (RETCODE_OK == retcode) { retcode = ServalPAL_Enable(); @@ -502,7 +502,7 @@ void AppController_Init(void * cmdProcessorHandle, uint32_t param2) { retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NULL_POINTER); } else if (RETCODE_OK == retcode) { AppCmdProcessor = (CmdProcessor_T *) cmdProcessorHandle; - retcode = CmdProcessor_EnqueueFromIsr(AppCmdProcessor, AppController_Setup,NULL, UINT32_C(0)); + retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppController_Setup, NULL, UINT32_C(0)); } if (RETCODE_OK != retcode) { diff --git a/source/MQTTButton.c b/source/MQTTButton.c index f2bcd7e..98cf617 100644 --- a/source/MQTTButton.c +++ b/source/MQTTButton.c @@ -20,10 +20,8 @@ /* own header files */ #include "AppController.h" -#include "MQTTFlash.h" -#include "MQTTOperation.h" #include "MQTTButton.h" -#include "MQTTCfgParser.h" +#include "MQTTOperation.h" /* additional interface header files */ #include "BSP_BoardType.h" @@ -53,9 +51,9 @@ static CmdProcessor_T *AppCmdProcessor; /**< Application Command Processor Insta * @return NONE */ -static void processbuttonCallback1 (void * param1, uint32_t buttonstatus) -{ - BCDS_UNUSED(param1); + +/*Callback for Button 1 */ +void button1Callback(uint32_t buttonstatus) { static TickType_t time_start = 0; LOG_AT_TRACE(("MQTTButton: Status button %d %lu %i\r\n", AppController_GetStatus(), buttonstatus, BSP_XDK_BUTTON_PRESS)); @@ -64,69 +62,35 @@ static void processbuttonCallback1 (void * param1, uint32_t buttonstatus) } else { TickType_t time_passed = xTaskGetTickCountFromISR() - time_start; if (time_passed > pdMS_TO_TICKS(3000)) { - CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,requestCommands", buttonstatus); + CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,requestCommands", UINT32_C(0)); LOG_AT_TRACE(("MQTTButton: Button1 pressed long: %lu\r\n", time_passed)); } else { // only use button 1 when in operation mode if (AppController_GetStatus() == APP_STATUS_OPERATING_STARTED ) { - CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,stopButton", buttonstatus); + CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,stopButton", UINT32_C(0)); } else if (AppController_GetStatus() == APP_STATUS_OPERATING_STOPPED) { - CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,startButton", buttonstatus); + CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,startButton", UINT32_C(0)); } } } } - -static void processbuttonCallback2 (void * param1, uint32_t buttonstatus) -{ +/*Callback for Button 2 */ +void button2Callback(uint32_t buttonstatus) { static TickType_t time_start = 0; - BCDS_UNUSED(param1); if (BSP_XDK_BUTTON_PRESSED == buttonstatus ) { time_start = xTaskGetTickCountFromISR(); } else if (BSP_XDK_BUTTON_RELEASED == buttonstatus){ TickType_t time_passed = xTaskGetTickCountFromISR() - time_start; if (time_passed > pdMS_TO_TICKS(3000)) { - MQTTFlash_FLWriteBootStatus((uint8_t*) NO_BOOT_PENDING); + CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,resetBootstatus", UINT32_C(0)); LOG_AT_TRACE(("MQTTButton: Button2 pressed long: %lu\r\n", time_passed)); } else { - ConfigDataBuffer localbuffer; - localbuffer.length = NUMBER_UINT32_ZERO; - memset(localbuffer.data, 0x00, SIZE_XXLARGE_BUF); - MQTTFlash_FLReadConfig(&localbuffer); - LOG_AT_DEBUG(("MQTTButton: Current configuration in flash:\r\n%s\r\n", localbuffer.data)); - - localbuffer.length = NUMBER_UINT32_ZERO; - memset(localbuffer.data, 0x00, SIZE_XXLARGE_BUF); - MQTTCfgParser_GetConfig(&localbuffer, CFG_FALSE); - LOG_AT_DEBUG(("MQTTButton: Currently used configuration:\r\n%s\r\n", localbuffer.data)); + CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,printConfig", UINT32_C(0)); LOG_AT_TRACE(("MQTTButton: Button2 pressed for: %lu\r\n", time_passed)); } } - -} - - -/*Callback for Button 1 */ -void button1Callback(uint32_t data) -{ - Retcode_T returnValue = CmdProcessor_EnqueueFromIsr(AppCmdProcessor, processbuttonCallback1, NULL, data); - if (RETCODE_OK != returnValue) - { - LOG_AT_ERROR(("MQTTButton: Enqueuing for Button 1 callback failed\r\n")); - } -} - - -/*Callback for Button 2 */ -void button2Callback(uint32_t data) -{ - Retcode_T returnValue = CmdProcessor_EnqueueFromIsr(AppCmdProcessor, processbuttonCallback2, NULL, data); - if (RETCODE_OK != returnValue) - { - LOG_AT_ERROR(("MQTTButton: Enqueuing for Button 2 callback failed [%lu]\r\n", returnValue)); - } } diff --git a/source/MQTTOperation.c b/source/MQTTOperation.c index 83f067c..778c9f7 100644 --- a/source/MQTTOperation.c +++ b/source/MQTTOperation.c @@ -161,7 +161,7 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { // split payload into tokens int token_pos = 0; int config_index = -1; - bool command_complete = false; + bool commandComplete = false; char *token = strtok(commandBuffer, ",:"); while (token != NULL) { @@ -174,7 +174,7 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { AppController_SetStatus(APP_STATUS_REBOOT); // set flag so that XDK acknowledges reboot command command = CMD_RESTART; - command_complete = true; + commandComplete = true; MQTTOperation_StartRestartTimer(REBOOT_DELAY); LOG_AT_DEBUG(("MQTTOperation: Ending restart\r\n")); } else if (strcmp(token, TEMPLATE_STD_COMMAND) == 0) { @@ -198,33 +198,53 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { } else if (strcmp(token, "toggle") == 0) { BSP_LED_Switch((uint32_t) BSP_XDK_LED_Y, (uint32_t) BSP_LED_COMMAND_TOGGLE); command = CMD_TOGGLE; - command_complete = true; + commandComplete = true; // skip phase BEFORE_EXECUTING, because LED is switched on immediately commandProgress = DEVICE_OPERATION_IMMEDIATE_CMD; } else if (strcmp(token, "start") == 0) { commandProgress = DEVICE_OPERATION_IMMEDIATE_CMD; command = CMD_START; - command_complete = true; + commandComplete = true; MQTTOperation_StartTimer(); } else if (strcmp(token, "startButton") == 0) { commandProgress = DEVICE_OPERATION_IMMEDIATE_BUTTON; command = CMD_START; - command_complete = true; + commandComplete = true; MQTTOperation_StartTimer(); } else if (strcmp(token, "stop") == 0) { commandProgress = DEVICE_OPERATION_IMMEDIATE_CMD; command = CMD_STOP; - command_complete = true; + commandComplete = true; MQTTOperation_StopTimer(); } else if (strcmp(token, "stopButton") == 0) { commandProgress = DEVICE_OPERATION_IMMEDIATE_BUTTON; command = CMD_STOP; - command_complete = true; + commandComplete = true; MQTTOperation_StopTimer(); + } else if (strcmp(token, "printConfig") == 0) { + commandProgress = DEVICE_OPERATION_IMMEDIATE_BUTTON; + command = CMD_COMMAND; + commandComplete = true; + + ConfigDataBuffer localbuffer; + localbuffer.length = NUMBER_UINT32_ZERO; + memset(localbuffer.data, 0x00, SIZE_XXLARGE_BUF); + MQTTFlash_FLReadConfig(&localbuffer); + LOG_AT_DEBUG(("MQTTButton: Current configuration in flash:\r\n%s\r\n", localbuffer.data)); + + localbuffer.length = NUMBER_UINT32_ZERO; + memset(localbuffer.data, 0x00, SIZE_XXLARGE_BUF); + MQTTCfgParser_GetConfig(&localbuffer, CFG_FALSE); + LOG_AT_DEBUG(("MQTTButton: Currently used configuration:\r\n%s\r\n", localbuffer.data)); + } else if (strcmp(token, "resetBootstatus") == 0) { + commandProgress = DEVICE_OPERATION_IMMEDIATE_BUTTON; + command = CMD_COMMAND; + commandComplete = true; + MQTTFlash_FLWriteBootStatus((uint8_t*) NO_BOOT_PENDING); } else if (strcmp(token, "requestCommands") == 0) { commandProgress = DEVICE_OPERATION_IMMEDIATE_BUTTON; command = CMD_REQUEST; - command_complete = true; + commandComplete = true; } else if (strcmp(token, "sensor") == 0) { command = CMD_SENSOR; } else if (strcmp(token, "config") == 0) { @@ -239,7 +259,7 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { MQTTCfgParser_SetFirmwareName(token); } else if (command == CMD_MESSAGE) { BSP_LED_Switch((uint32_t) BSP_XDK_LED_Y, (uint32_t) BSP_LED_COMMAND_TOGGLE); - command_complete = true; + commandComplete = true; // skip phase BEFORE_EXECUTING, because LED is switched on immediately commandProgress = DEVICE_OPERATION_IMMEDIATE_CMD; } @@ -254,7 +274,7 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { MQTTCfgParser_SetStreamRate(speed); MQTTCfgParser_FLWriteConfig(); assetUpdateProcess = APP_ASSET_WAITING; - command_complete = true; + commandComplete = true; } else if (command == CMD_SENSOR) { LOG_AT_DEBUG(("MQTTOperation: Phase parse command sensor: token_pos: [%i]\r\n", token_pos)); for (int var = ATT_IDX_ACCEL; var <= ATT_IDX_NOISE; ++var) { @@ -290,19 +310,19 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { MQTTCfgParser_SetSensor(token, config_index); MQTTCfgParser_FLWriteConfig(); assetUpdateProcess = APP_ASSET_WAITING; - command_complete = true; + commandComplete = true; } else if (command == CMD_CONFIG){ LOG_AT_DEBUG(("MQTTOperation: Phase execute command config: token_pos: [%i]\r\n", token_pos)); MQTTCfgParser_SetConfig(token, config_index); MQTTCfgParser_FLWriteConfig(); assetUpdateProcess = APP_ASSET_WAITING; - command_complete = true; + commandComplete = true; } else if (command == CMD_FIRMWARE) { LOG_AT_DEBUG(("MQTTOperation: Phase parse firmware url: token_pos: [%i]\r\n", token_pos)); MQTTCfgParser_SetFirmwareURL(token); MQTTCfgParser_FLWriteConfig(); assetUpdateProcess = APP_ASSET_WAITING; - command_complete = true; + commandComplete = true; } break; default: @@ -313,7 +333,7 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { token_pos++; } // test if command was complete - if ( command_complete == false) { + if ( commandComplete == false) { commandProgress = DEVICE_OPERATION_BEFORE_FAILED; LOG_AT_ERROR(("MQTTOperation: Incomplete command!\r\n")); } @@ -412,9 +432,6 @@ static void MQTTOperation_ClientPublish(void) { LOG_AT_ERROR(("MQTTOperation: MQTT publish failed \r\n")); Retcode_RaiseError(retcode); errorCountPublish ++; - //retcode = MQTTOperation_ValidateWLANConnectivity(true); - } else { - errorCountPublish = 0; } if (assetUpdateProcess == APP_ASSET_PUBLISHED && RETCODE_OK == retcode) { @@ -463,12 +480,8 @@ static void MQTTOperation_ClientPublish(void) { LOG_AT_ERROR(("MQTTOperation: MQTT publish failed \r\n")); Retcode_RaiseError(retcode); errorCountPublish++; - //retcode = MQTTOperation_ValidateWLANConnectivity(true); - } else { - errorCountPublish = 0; } - } else { // ignore previous measurements in order to prevent buffer overrun memset(sensorStreamBuffer.data, 0x00, @@ -875,7 +888,7 @@ static void MQTTOperation_AssetUpdate(xTimerHandle xTimer) { assetStreamBuffer.length += snprintf( assetStreamBuffer.data + assetStreamBuffer.length, sizeof (assetStreamBuffer.data) - assetStreamBuffer.length, - "400,xdk_ErrorCountEvent,\"Errors: %i!\"\r\n", errorCountSemaphore); + "400,xdk_ErrorCountEvent,\"Errors: Collision Semaphore/Error Publish:%i/%i!\"\r\n", errorCountSemaphore, errorCountPublish); #if INCLUDE_uxTaskGetStackHighWaterMark uint32_t everFreeHeap = xPortGetMinimumEverFreeHeapSize(); @@ -1015,7 +1028,6 @@ static float MQTTOperation_CalcSoundPressure(float acousticRawValue){ * @return NONE */ void MQTTOperation_QueueCommand(void * param1, uint32_t param2) { - //BCDS_UNUSED(param1); BCDS_UNUSED(param2); if (xQueueSend(commandQueue,(char *) param1, 0) != pdTRUE) { LOG_AT_ERROR(("MQTTOperation_QueueCommand: Could not buffer command!\r\n")); @@ -1024,7 +1036,6 @@ void MQTTOperation_QueueCommand(void * param1, uint32_t param2) { } - /** * @brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks *