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 3, 2020
1 parent a21da3b commit d6302ac
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 46 deletions.
69 changes: 36 additions & 33 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "XDK_SNTP.h"
#include "XDK_ServalPAL.h"
#include "XDK_Storage.h"
#include "XDK_TimeStamp.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
Expand All @@ -58,13 +59,12 @@

/* local variables ********************************************************** */

static WLAN_Setup_T WLANSetupInfo = { .IsEnterprise = false, .IsHostPgmEnabled =
false, .SSID = WLAN_SSID, .Username = WLAN_PSK, .Password = WLAN_PSK,
.IsStatic = WLAN_STATIC_IP, .IpAddr = WLAN_IP_ADDR, .GwAddr =
WLAN_GW_ADDR, .DnsAddr = WLAN_DNS_ADDR, .Mask = WLAN_MASK, };/**< WLAN setup parameters */
static WLAN_Setup_T WLANSetupInfo = { .IsEnterprise = false, .IsHostPgmEnabled = false,
.SSID = WLAN_SSID, .Username = WLAN_PSK, .Password = WLAN_PSK,
.IsStatic = WLAN_STATIC_IP, .IpAddr = WLAN_IP_ADDR, .GwAddr = WLAN_GW_ADDR,
.DnsAddr = WLAN_DNS_ADDR, .Mask = WLAN_MASK, };

static SNTP_Setup_T SNTPSetupInfo = { .ServerUrl = SNTP_SERVER_URL,
.ServerPort = SNTP_SERVER_PORT, };/**< SNTP setup parameters */
static SNTP_Setup_T SNTPSetupInfo;/**< SNTP setup parameters */

static CmdProcessor_T * AppCmdProcessor;/**< Handle to store the main Command processor handle to be used by run-time event driven threads */

Expand Down Expand Up @@ -119,7 +119,7 @@ static void AppController_Setup(void * param1, uint32_t param2) {
if ((Retcode_T) RETCODE_STORAGE_SDCARD_NOT_AVAILABLE == Retcode_GetCode((retcode)))
{
/* This is only a warning error. So we will raise and proceed */
LOG_AT_WARNING(("AppController_Setup: SD card missing trying to use config from WIFI chip!\r\n"));
LOG_AT_WARNING(("AppController_Setup: SD card missing, using config from WIFI chip!\r\n"));
//Retcode_RaiseError(retcode);
retcode = RETCODE_OK; /* SD card was not inserted */
}
Expand All @@ -137,7 +137,7 @@ static void AppController_Setup(void * param1, uint32_t param2) {

//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"));
LOG_AT_INFO(("AppController_Setup: Button 2 was pressed at startup, deleting config stored on WIFI chip!\r\n"));
MQTTFlash_FLDeleteConfig();
BSP_Board_SoftReset();
}
Expand All @@ -150,27 +150,33 @@ static void AppController_Setup(void * param1, uint32_t param2) {
if (RETCODE_OK == retcode) {
// set cfg parameter for WIFI access
WLANSetupInfo.SSID = MQTTCfgParser_GetWlanSSID();
WLANSetupInfo.Username = MQTTCfgParser_GetWlanPassword(); // not realy used
WLANSetupInfo.Username = MQTTCfgParser_GetWlanPassword();
WLANSetupInfo.Password = MQTTCfgParser_GetWlanPassword();
MqttSetupInfo.IsSecure = MQTTCfgParser_IsMqttSecureEnabled();

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

}

MqttSetupInfo.IsSecure = MQTTCfgParser_IsMqttSecureEnabled();
if (MqttSetupInfo.IsSecure == true) {
if (RETCODE_OK == retcode) {
SNTPSetupInfo.ServerUrl = MQTTCfgParser_GetSntpName();
SNTPSetupInfo.ServerPort = MQTTCfgParser_GetSntpPort();
SNTPSetupInfo = (SNTP_Setup_T) {
.ServerUrl = MQTTCfgParser_GetSntpName(),
.ServerPort = MQTTCfgParser_GetSntpPort()
};

LOG_AT_INFO(("AppController_Setup: SNTP server: [%s:%d]\r\n", SNTPSetupInfo.ServerUrl, SNTPSetupInfo.ServerPort));
retcode = SNTP_Setup(&SNTPSetupInfo);
}
}

if (RETCODE_OK == retcode) {
retcode = MQTT_Setup_Z(&MqttSetupInfo);
}

if (RETCODE_OK == retcode && rc_Boot_Mode == APP_RESULT_OPERATION_MODE) {
SensorSetup.CmdProcessorHandle = AppCmdProcessor;
SensorSetup.Enable.Accel = MQTTCfgParser_IsAccelEnabled();
Expand Down Expand Up @@ -247,9 +253,6 @@ static void AppController_Enable(void * param1, uint32_t param2) {
}





/**
* @brief Responsible for controlling the send data over MQTT application control flow.
*
Expand All @@ -267,27 +270,24 @@ static void AppController_Fire(void* pvParameters)
{
BCDS_UNUSED(pvParameters);

AppController_SetClientId();
LOG_AT_INFO(("AppController_Fire: Device id for registration in Cumulocity %s\r\n",
MqttConnectInfo.ClientId));
MqttConnectInfo.BrokerURL = MQTTCfgParser_GetMqttBrokerName();
MqttConnectInfo.BrokerPort = MQTTCfgParser_GetMqttBrokerPort();
MqttConnectInfo.CleanSession = true;
MqttConnectInfo.KeepAliveInterval = 100;
AppController_SetClientId();

LOG_AT_INFO(("AppController_Fire: Device ID for registration in Cumulocity %s\r\n.",
MqttConnectInfo.ClientId));

if (rc_Boot_Mode == APP_RESULT_OPERATION_MODE) {
MqttCredentials = (MQTT_Credentials_TZ) {
.Username = MQTTCfgParser_GetMqttUser(),
.Password = MQTTCfgParser_GetMqttPassword(),
.Anonymous = MQTTCfgParser_IsMqttAnonymous()
};
MqttCredentials.Username = MQTTCfgParser_GetMqttUser();
MqttCredentials.Password = MQTTCfgParser_GetMqttPassword();
MqttCredentials.Anonymous = MQTTCfgParser_IsMqttAnonymous();
MQTTOperation_Init();
} else {
MqttCredentials = (MQTT_Credentials_TZ) {
.Username = MQTT_REGISTRATION_USERNAME,
.Password = MQTT_REGISTRATION_PASSWORD,
.Anonymous = FALSE
};
MqttCredentials.Username = MQTT_REGISTRATION_USERNAME;
MqttCredentials.Password = MQTT_REGISTRATION_PASSWORD;
MqttCredentials.Anonymous = FALSE;
MQTTRegistration_Init();
}
}
Expand Down Expand Up @@ -380,6 +380,7 @@ Retcode_T AppController_SyncTime() {
uint64_t sntpTimeStampFromServer = 0UL;
uint16_t sntpAttemps = 0UL;
Retcode_T retcode = RETCODE_OK;

/* We Synchronize the node with the SNTP server for time-stamp.
* Since there is no point in doing a HTTPS communication without a valid time */
do {
Expand All @@ -390,16 +391,17 @@ Retcode_T AppController_SyncTime() {
("MQTTOperation: SNTP server time was not synchronized. Retrying...\r\n"));
}
sntpAttemps++;
vTaskDelay(pdMS_TO_TICKS(1000));
//vTaskDelay(pdMS_TO_TICKS(500));
} while (0UL == sntpTimeStampFromServer && sntpAttemps < 3); // only try to sync time 3 times

if (0UL == sntpTimeStampFromServer) {
//sntpTimeStampFromServer = 1572566400UL; // use default time 1. Nov 2019 00:00:00 UTC
sntpTimeStampFromServer = 1580515200UL; // use default time 1. Feb 2020 00:00:00 UTC
SNTP_SetTime(sntpTimeStampFromServer);
LOG_AT_WARNING(
("MQTTOperation: Using fixed timestamp 1. Feb 2020 00:00:00 UTC, SNTP sync not possible\r\n"));
retcode = RETCODE_OK; // clear return code
}

//uint8_t * timeBuffer = (uint8_t *) &sntpTimeStampFromServer;
//LOG_AT_TRACE(("MQTTOperation: SNTP time: %d,%d,%d,%d,%d,%d,%d,%d\r\n", timeBuffer[0], timeBuffer[1], timeBuffer[2], timeBuffer[3],timeBuffer[4],timeBuffer[5],timeBuffer[6],timeBuffer[7]));
struct tm time;
Expand All @@ -412,7 +414,9 @@ Retcode_T AppController_SyncTime() {

/* global functions ********************************************************* */

/** Refer interface header for description */
/** Initialize Application
*
*/
void AppController_Init(void * cmdProcessorHandle, uint32_t param2) {

/*
Expand Down Expand Up @@ -472,7 +476,7 @@ void AppController_Init(void * cmdProcessorHandle, uint32_t param2) {
BCDS_UNUSED(param2);

vTaskDelay(pdMS_TO_TICKS(1000));
LOG_AT_INFO(("AppController_Init: XDK System Startup\r\n"));
LOG_AT_INFO(("AppController_Init: XDK Cumulocity Agent startup ...\r\n"));

// start status LED indicator
AppController_SetStatus(APP_STATUS_STARTED);
Expand All @@ -483,7 +487,6 @@ void AppController_Init(void * cmdProcessorHandle, uint32_t param2) {
BatteryMonitor_Init();

if (cmdProcessorHandle == NULL) {
LOG_AT_ERROR(("AppController_Init: Command processor handle is NULL \r\n"));
retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NULL_POINTER);
} else if (RETCODE_OK == retcode) {
AppCmdProcessor = (CmdProcessor_T *) cmdProcessorHandle;
Expand Down
2 changes: 1 addition & 1 deletion source/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@

#define APP_TEMPERATURE_OFFSET_CORRECTION (-1403)/**< Macro for static temperature offset correction. Self heating, temperature correction factor */

#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT UINT32_C(10000)/**< Timeout for SNTP server time sync */
#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT UINT32_C(5000)/**< Timeout for SNTP server time sync */

/* public type and macro definitions */

Expand Down
6 changes: 3 additions & 3 deletions source/MQTTCfgParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ APP_RESULT MQTTCfgParser_ParseConfigFile(void) {
fileReadBuffer.length, CFG_FALSE)) {
RetValFLash = APP_RESULT_OPERATION_OK;
}
MQTTCfgParser_List("MQTTCfgParser: Parsing content from config file [config.txt] on WIFI chip:", CFG_TRUE);
MQTTCfgParser_List("MQTTCfgParser: Parsing content from config.txt on WIFI chip:", CFG_TRUE);
}

// test if config on SDCard exists and overwrite setting from config on flash
Expand All @@ -444,9 +444,9 @@ APP_RESULT MQTTCfgParser_ParseConfigFile(void) {
fileReadBuffer.length, CFG_TRUE)) {
RetVal = APP_RESULT_OPERATION_OK;
}
MQTTCfgParser_List("MQTTCfgParser: Parsing content from config file [config.txt] on SD card (potentially merged):", CFG_TRUE);
MQTTCfgParser_List("MQTTCfgParser: Parsing content from config.txt on SD card, resulting config by merging:", CFG_TRUE);
} else {
LOG_AT_ERROR(("MQTTCfgParser: Config not read from SD card!\r\n"));
LOG_AT_WARNING(("MQTTCfgParser: Config not read from SD card!\r\n"));
}

// if any of the attemps to parse a config: Flash or SD was successful return OK
Expand Down
2 changes: 1 addition & 1 deletion source/MQTTFlash.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ APP_RESULT MQTTFlash_FLReadConfig(ConfigDataBuffer *configBuffer) {
retcode = Storage_Read(STORAGE_MEDIUM_WIFI_FILE_SYSTEM, &readCredentials);
if (retcode == RETCODE_OK) {
configBuffer->length = strlen(configBuffer->data);
LOG_AT_DEBUG(("MQTTFlash: Read config from flash success: [%lu] \r\n", configBuffer->length));
LOG_AT_DEBUG(("MQTTFlash: Read config from flash: [%lu] \r\n", configBuffer->length));
return APP_RESULT_OPERATION_OK;
}
}
Expand Down
13 changes: 6 additions & 7 deletions source/MQTTOperation.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) {
switch (token_pos) {
case 0:
if (strcmp(token, TEMPLATE_STD_RESTART) == 0) {
LOG_AT_DEBUG(("MQTTOperation: Starting restart \r\n"));
LOG_AT_TRACE(("MQTTOperation: Starting restart \r\n"));
AppController_SetStatus(APP_STATUS_REBOOT);
// set flag so that XDK acknowledges reboot command
command = CMD_RESTART;
commandComplete = true;
MQTTOperation_StartRestartTimer(REBOOT_DELAY);
LOG_AT_DEBUG(("MQTTOperation: Ending restart\r\n"));
LOG_AT_TRACE(("MQTTOperation: Ending restart\r\n"));
} else if (strcmp(token, TEMPLATE_STD_COMMAND) == 0) {
command = CMD_COMMAND;
} else if (strcmp(token, TEMPLATE_STD_FIRMWARE) == 0) {
Expand Down Expand Up @@ -414,7 +414,7 @@ static void MQTTOperation_ClientPublish(void) {
if (RETCODE_OK == retcode) {
BaseType_t semaphoreResult = xSemaphoreTake(semaphoreAssetBuffer, pdMS_TO_TICKS(SEMAPHORE_TIMEOUT));
if (pdPASS == semaphoreResult) {
LOG_AT_DEBUG(("MQTTOperation: Publishing asset data length [%ld] and content:\r\n%s",
LOG_AT_DEBUG(("MQTTOperation: Publishing asset data: length [%ld], content:\r\n%s",
assetStreamBuffer.length, assetStreamBuffer.data));
MqttPublishAssetInfo.Payload = assetStreamBuffer.data;
MqttPublishAssetInfo.PayloadLength =
Expand All @@ -439,7 +439,7 @@ static void MQTTOperation_ClientPublish(void) {
vTaskDelay(pdMS_TO_TICKS(1000));
retcode = MQTTOperation_SubscribeTopics();
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTOperation: MQTT subscription failed \r\n"));
LOG_AT_ERROR(("MQTTOperation: MQTT subscription failed!\r\n"));
retcode = MQTTOperation_ValidateWLANConnectivity();
} else {
assetUpdateProcess = APP_ASSET_COMPLETED;
Expand All @@ -459,7 +459,7 @@ static void MQTTOperation_ClientPublish(void) {
BaseType_t semaphoreResult = xSemaphoreTake(semaphoreSensorBuffer, pdMS_TO_TICKS(SEMAPHORE_TIMEOUT));
if (pdPASS == semaphoreResult) {
measurementCounter++;
LOG_AT_DEBUG(("MQTTOperation: Publishing sensor data length [%ld], message [%lu] and content:\r\n%s",
LOG_AT_DEBUG(("MQTTOperation: Publishing sensor data: length [%ld], message [%lu], content:\r\n%s",
sensorStreamBuffer.length, measurementCounter, sensorStreamBuffer.data));
MqttPublishDataInfo.Payload = sensorStreamBuffer.data;
MqttPublishDataInfo.PayloadLength = sensorStreamBuffer.length;
Expand Down Expand Up @@ -982,7 +982,6 @@ void MQTTOperation_Init(void) {
LOG_AT_DEBUG(("MQTTOperation_Init: Reading boot status: [%s]\r\n", readbuffer));

if ((strncmp(readbuffer, BOOT_PENDING, strlen(BOOT_PENDING)) == 0)) {
LOG_AT_DEBUG(("MQTTOperation_Init: Have to confirm successful reboot\r\n"));
command = CMD_RESTART;
commandProgress = DEVICE_OPERATION_PENDING;
}
Expand All @@ -997,7 +996,7 @@ void MQTTOperation_Init(void) {
retcode = MQTT_ConnectToBroker_Z(&MqttConnectInfo,
MQTT_CONNECT_TIMEOUT_IN_MS, &MqttCredentials);
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTOperation: MQTT connection to the broker failed [%hu] time, try again ... \r\n", connectAttemps ));
LOG_AT_ERROR(("MQTTOperation: MQTT connection to broker failed [%hu] time, try again ... \r\n", connectAttemps ));
connectAttemps ++;
}
} while (RETCODE_OK != retcode && connectAttemps < 10 );
Expand Down
2 changes: 1 addition & 1 deletion source/MQTTRegistration.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static Retcode_T MQTTRegistration_ValidateWLANConnectivity(void) {

// test if we have to reboot
if (connectAttemps > 10) {
LOG_AT_WARNING(("MQTTOperation: Now calling SoftReset and reboot to recover\r\n"));
LOG_AT_WARNING(("MQTTOperation: Now calling SoftReset to recover\r\n"));
// wait one minute before reboot
vTaskDelay(pdMS_TO_TICKS(30000));
BSP_Board_SoftReset();
Expand Down

0 comments on commit d6302ac

Please sign in to comment.