Skip to content

Commit

Permalink
removed unneeded CommandProcessor_Enqueue stmts
Browse files Browse the repository at this point in the history
  • Loading branch information
christof.strackSAG authored and christof.strackSAG committed Mar 1, 2020
1 parent 4d8fa9a commit 1505601
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 74 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
58 changes: 11 additions & 47 deletions source/MQTTButton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}
}


Expand Down
59 changes: 35 additions & 24 deletions source/MQTTOperation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"));
Expand All @@ -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
*
Expand Down

0 comments on commit 1505601

Please sign in to comment.