Skip to content

Commit

Permalink
moved variable declaration out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
christof.strackSAG authored and christof.strackSAG committed Mar 14, 2020
1 parent e9eea0e commit a989ac5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
41 changes: 21 additions & 20 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ static void AppController_Setup(void * param1, uint32_t param2) {
BCDS_UNUSED(param1);
BCDS_UNUSED(param2);

// prepare storage
Retcode_T retcode = Storage_Setup(&StorageSetup);
retcode = Storage_Enable();

if ((Retcode_T) RETCODE_STORAGE_SDCARD_NOT_AVAILABLE
== Retcode_GetCode(retcode)) {
/* This is only a warning error. So we will raise and proceed */
Expand All @@ -121,36 +121,38 @@ static void AppController_Setup(void * param1, uint32_t param2) {
retcode = RETCODE_OK; /* SD card was not inserted */
}

/* Initialize variables from flash */
if (MQTTStorage_Init() != RETCODE_OK) {
assert(0);
}

/* Initialize Buttons */
// initialize Buttons
retcode = MQTTButton_Init(AppCmdProcessor);
if (retcode != RETCODE_OK) {
LOG_AT_ERROR(("AppController_Setup: Boot error!\r\n"));
assert(0);
}

//test if button 2 is pressed

// read boot status from flash. If boot status file does not exits create this file
if (MQTTStorage_Init() != RETCODE_OK) {
assert(0);
}

// in case button 2 is pressed delete the configuration files
if (BSP_Button_GetState((uint32_t) BSP_XDK_BUTTON_2) == 1) {
LOG_AT_INFO(
("AppController_Setup: Button 2 was pressed at startup, deleting config stored on WIFI chip!\r\n"));
MQTTStorage_Flash_DeleteConfig();
BSP_Board_SoftReset();
}

// initialize parameters from flash and inserted SD card
retcode = MQTTCfgParser_Init();

// set boot mode: operation or registration
boot_mode = MQTTCfgParser_GetMode();
if (retcode != RETCODE_OK) {
LOG_AT_ERROR(
("AppController_Setup: Boot error. Inconsistent configuration!\r\n"));
assert(0);
}

// set boot mode: operation or registration
boot_mode = MQTTCfgParser_GetMode();
if (boot_mode == APP_STATUS_OPERATION_MODE) {
MqttCredentials.Username = MQTTCfgParser_GetMqttUser();
MqttCredentials.Password = MQTTCfgParser_GetMqttPassword();
Expand All @@ -161,19 +163,17 @@ static void AppController_Setup(void * param1, uint32_t param2) {
MqttCredentials.Anonymous = FALSE;
}

if (RETCODE_OK == retcode) {
// set cfg parameter for WIFI access
WLANSetupInfo.SSID = MQTTCfgParser_GetWlanSSID();
WLANSetupInfo.Username = MQTTCfgParser_GetWlanPassword();
WLANSetupInfo.Password = MQTTCfgParser_GetWlanPassword();

retcode = WLAN_Setup(&WLANSetupInfo);
if (RETCODE_OK == retcode) {
retcode = ServalPAL_Setup(AppCmdProcessor);
}
// set cfg parameter for WIFI access
WLANSetupInfo.SSID = MQTTCfgParser_GetWlanSSID();
WLANSetupInfo.Username = MQTTCfgParser_GetWlanPassword();
WLANSetupInfo.Password = MQTTCfgParser_GetWlanPassword();

retcode = WLAN_Setup(&WLANSetupInfo);
if (RETCODE_OK == retcode) {
retcode = ServalPAL_Setup(AppCmdProcessor);
}

// initialize time from SNTP server
MqttSetupInfo.IsSecure = MQTTCfgParser_IsMqttSecureEnabled();
if (MqttSetupInfo.IsSecure == true) {
if (RETCODE_OK == retcode) {
Expand All @@ -191,6 +191,7 @@ static void AppController_Setup(void * param1, uint32_t param2) {
retcode = MQTT_Setup_Z(&MqttSetupInfo);
}

// enable/disable relevant sensors
if (RETCODE_OK == retcode && boot_mode == APP_STATUS_OPERATION_MODE) {
SensorSetup.CmdProcessorHandle = AppCmdProcessor;
SensorSetup.Enable.Accel = MQTTCfgParser_IsAccelEnabled();
Expand Down
9 changes: 6 additions & 3 deletions source/MQTTOperation.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ static void MQTTOperation_ClientPublish(void) {


uint32_t measurementCounter = 0;
char commandBuffer[SIZE_XSMALL_BUF] = { 0 };
BaseType_t semaphoreResult;
/* A function that implements a task must not exit or attempt to return to
its caller function as there is nothing to return to. */
while (1) {
Expand All @@ -454,7 +456,7 @@ static void MQTTOperation_ClientPublish(void) {
retcode = MQTTOperation_ValidateWLANConnectivity();
if (assetStreamBuffer.length > NUMBER_UINT32_ZERO) {
if (RETCODE_OK == retcode) {
BaseType_t semaphoreResult = xSemaphoreTake(
semaphoreResult = xSemaphoreTake(
semaphoreAssetBuffer, pdMS_TO_TICKS(SEMAPHORE_TIMEOUT));
if (pdPASS == semaphoreResult) {
LOG_AT_DEBUG(
Expand Down Expand Up @@ -496,7 +498,7 @@ static void MQTTOperation_ClientPublish(void) {
if (sensorStreamBuffer.length > NUMBER_UINT32_ZERO) {
AppController_SetAppStatus(APP_STATUS_OPERATING_STARTED);
if (RETCODE_OK == retcode) {
BaseType_t semaphoreResult = xSemaphoreTake(
semaphoreResult = xSemaphoreTake(
semaphoreSensorBuffer,
pdMS_TO_TICKS(SEMAPHORE_TIMEOUT));
if (pdPASS == semaphoreResult) {
Expand Down Expand Up @@ -534,10 +536,11 @@ static void MQTTOperation_ClientPublish(void) {
}
}

char commandBuffer[SIZE_XSMALL_BUF] = { 0 };

// test if some commands are pending
if (uxQueueMessagesWaiting(commandQueue) > 0
&& commandProgress == DEVICE_OPERATION_WAITING) {
memset(commandBuffer, 0x00, SIZE_XSMALL_BUF);
if (xQueueReceive(commandQueue, &commandBuffer, 0) != pdTRUE)
LOG_AT_ERROR(
("MQTTOperation: Could read command from buffer!\r\n"));
Expand Down

0 comments on commit a989ac5

Please sign in to comment.