Skip to content

Commit

Permalink
changed variables to global scope, too save space: assetBuffer, MQTTC…
Browse files Browse the repository at this point in the history
…onnectionInfo, ...
  • Loading branch information
christof.strackSAG authored and christof.strackSAG committed Feb 15, 2020
1 parent 3055b4d commit 8995796
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 97 deletions.
134 changes: 78 additions & 56 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,58 +63,9 @@ 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 Sensor_Setup_T SensorSetup = {
.CmdProcessorHandle = NULL,
.Enable = {
.Accel = false,
.Mag = false,
.Gyro = false,
.Humidity = false,
.Temp = false,
.Pressure = false,
.Light = false,
.Noise = false, },
.Config = {
.Accel = {
.Type = SENSOR_ACCEL_BMA280,
.IsRawData = false,
.IsInteruptEnabled = false,
.Callback = NULL, },
.Gyro = {
.Type = SENSOR_GYRO_BMG160,
.IsRawData = false, },
.Mag = {
.IsRawData = false },
.Light = {
.IsInteruptEnabled = false,
.Callback = NULL, },
.Temp = {
.OffsetCorrection = APP_TEMPERATURE_OFFSET_CORRECTION,
},
},
};/**< Sensor setup parameters */

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

static MQTT_Setup_TZ MqttSetupInfo = { .IsSecure = APP_MQTT_SECURE_ENABLE, };/**< MQTT setup parameters */

static MQTT_Connect_TZ MqttConnectInfo = { .ClientId = APP_MQTT_CLIENT_ID,
.BrokerURL = MQTT_BROKER_HOST_NAME, .BrokerPort =
MQTT_BROKER_HOST_PORT, .CleanSession = true, .KeepAliveInterval =
100, };/**< MQTT connect parameters */

static MQTT_Credentials_TZ MqttCredentials = { .Username = APP_MQTT_USERNAME,
.Password = APP_MQTT_PASSWORD, .Anonymous = false,

};/**< MQTT connect parameters */

static Storage_Setup_T StorageSetup =
{
.SDCard = true,
.WiFiFileSystem = true,
};/**< Storage setup parameters */

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

/* initalize boot progress */
Expand All @@ -126,13 +77,23 @@ static void AppController_SetClientId(void);
static void AppController_StartLEDBlinkTimer(int);

static char clientId[] = WIFI_DEFAULT_MAC_CLIENTID;
char deviceId[] = DEVICE_ID;

xTaskHandle AppControllerHandle = NULL;/**< OS thread handle for Application controller to be used by run-time blocking threads */

/* global variables ********************************************************* */
APP_STATUS app_status;
APP_STATUS cmd_status;
char deviceId[] = DEVICE_ID;
uint16_t connectAttemps = 0UL;
SensorDataBuffer sensorStreamBuffer;
AssetDataBuffer assetStreamBuffer;

xTaskHandle AppControllerHandle = NULL;/**< OS thread handle for Application controller to be used by run-time blocking threads */
MQTT_Setup_TZ MqttSetupInfo;
MQTT_Connect_TZ MqttConnectInfo;
MQTT_Credentials_TZ MqttCredentials;
Storage_Setup_T StorageSetup;
Sensor_Setup_T SensorSetup;

/* inline functions ********************************************************* */

/* local functions ********************************************************** */
Expand Down Expand Up @@ -321,12 +282,19 @@ static void AppController_Fire(void* pvParameters)
MqttConnectInfo.KeepAliveInterval = 100;

if (rc_Boot_Mode == APP_RESULT_OPERATION_MODE) {
MqttCredentials.Username = MQTTCfgParser_GetMqttUser();
MqttCredentials.Password = MQTTCfgParser_GetMqttPassword();
MqttCredentials.Anonymous = MQTTCfgParser_IsMqttAnonymous();
MQTTOperation_Init(MqttSetupInfo, MqttConnectInfo, MqttCredentials, SensorSetup);
MqttCredentials = (MQTT_Credentials_TZ) {
.Username = MQTTCfgParser_GetMqttUser(),
.Password = MQTTCfgParser_GetMqttPassword(),
.Anonymous = MQTTCfgParser_IsMqttAnonymous()
};
MQTTOperation_Init();
} else {
MQTTRegistration_Init(MqttSetupInfo, MqttConnectInfo);
MqttCredentials = (MQTT_Credentials_TZ) {
.Username = MQTT_REGISTRATION_USERNAME,
.Password = MQTT_REGISTRATION_PASSWORD,
.Anonymous = FALSE
};
MQTTRegistration_Init();
}
}

Expand Down Expand Up @@ -461,6 +429,60 @@ Retcode_T AppController_SyncTime() {

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

/*
* Initialialze global variables
*/

MqttSetupInfo = (MQTT_Setup_TZ) { .IsSecure = APP_MQTT_SECURE_ENABLE, };/**< MQTT setup parameters */

MqttConnectInfo = (MQTT_Connect_TZ) { .ClientId = APP_MQTT_CLIENT_ID,
.BrokerURL = MQTT_BROKER_HOST_NAME, .BrokerPort =
MQTT_BROKER_HOST_PORT, .CleanSession = true, .KeepAliveInterval =
100, };/**< MQTT connect parameters */

MqttCredentials = (MQTT_Credentials_TZ) { .Username = APP_MQTT_USERNAME,
.Password = APP_MQTT_PASSWORD, .Anonymous = false,

};/**< MQTT connect parameters */

StorageSetup =
(Storage_Setup_T) {
.SDCard = true,
.WiFiFileSystem = true,
};/**< Storage setup parameters */

SensorSetup = (Sensor_Setup_T) {
.CmdProcessorHandle = NULL,
.Enable = {
.Accel = false,
.Mag = false,
.Gyro = false,
.Humidity = false,
.Temp = false,
.Pressure = false,
.Light = false,
.Noise = false, },
.Config = {
.Accel = {
.Type = SENSOR_ACCEL_BMA280,
.IsRawData = false,
.IsInteruptEnabled = false,
.Callback = NULL, },
.Gyro = {
.Type = SENSOR_GYRO_BMG160,
.IsRawData = false, },
.Mag = {
.IsRawData = false },
.Light = {
.IsInteruptEnabled = false,
.Callback = NULL, },
.Temp = {
.OffsetCorrection = APP_TEMPERATURE_OFFSET_CORRECTION,
},
},
};/**< Sensor setup parameters */

Retcode_T retcode = RETCODE_OK;
BCDS_UNUSED(param2);

Expand Down
3 changes: 2 additions & 1 deletion source/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
* APP_MQTT_BROKER_HOST_URL is the MQTT broker host address URL.
*/
#define MQTT_BROKER_HOST_NAME "mqtt.cumulocity.com"

#define MQTT_REGISTRATION_USERNAME "management/devicebootstrap"
#define MQTT_REGISTRATION_PASSWORD "Fhdt1bb1f"
/**
* APP_MQTT_BROKER_HOST_PORT is the MQTT broker host port.
*/
Expand Down
27 changes: 7 additions & 20 deletions source/MQTTOperation.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ static int tickRateMS;
static APP_ASSET_UPDATE_STATUS assetUpdateProcess = APP_ASSET_INITIAL;
static DEVICE_OPERATION commandProgress = DEVICE_OPERATION_WAITING;
static C8Y_COMMAND command;
static SensorDataBuffer sensorStreamBuffer;
static AssetDataBuffer assetStreamBuffer;
static uint16_t connectAttemps = 0UL;
static xTimerHandle timerHandleSensor;
static xTimerHandle timerHandleAsset;
Expand All @@ -63,11 +61,13 @@ SemaphoreHandle_t semaphoreSensorBuffer;
QueueHandle_t commandQueue;

/* global variables ********************************************************* */
// Network and Client Configuration
/* global variable declarations */
extern char deviceId[];
extern xTaskHandle AppControllerHandle;
extern CmdProcessor_T MainCmdProcessor;
extern SensorDataBuffer sensorStreamBuffer;
extern AssetDataBuffer assetStreamBuffer;
extern MQTT_Setup_TZ MqttSetupInfo;
extern MQTT_Connect_TZ MqttConnectInfo;
extern MQTT_Credentials_TZ MqttCredentials;
extern Sensor_Setup_T SensorSetup;

/* inline functions ********************************************************* */

Expand Down Expand Up @@ -100,12 +100,6 @@ static MQTT_Publish_TZ MqttPublishAssetInfo = { .Topic = TOPIC_ASSET_STREAM,
static MQTT_Publish_TZ MqttPublishDataInfo = { .Topic = TOPIC_DATA_STREAM,
.QoS = MQTT_QOS_AT_MOST_ONE, .Payload = NULL, .PayloadLength = 0UL, };/**< MQTT publish parameters */

static MQTT_Setup_TZ MqttSetupInfo;
static MQTT_Connect_TZ MqttConnectInfo;
static MQTT_Credentials_TZ MqttCredentials;
static Sensor_Setup_T SensorSetup;


/**
* @brief callback function for subriptions
* toggles LEDS or sets read data flag
Expand Down Expand Up @@ -927,15 +921,8 @@ void MQTTOperation_QueueCommand(void * param1, uint32_t param2) {
*
* @return NONE
*/
void MQTTOperation_Init(MQTT_Setup_TZ MqttSetupInfo_P,
MQTT_Connect_TZ MqttConnectInfo_P,
MQTT_Credentials_TZ MqttCredentials_P, Sensor_Setup_T SensorSetup_P) {
void MQTTOperation_Init() {

/* Initialize Variables */
MqttSetupInfo = MqttSetupInfo_P;
MqttConnectInfo = MqttConnectInfo_P;
MqttCredentials = MqttCredentials_P;
SensorSetup = SensorSetup_P;

Retcode_T retcode = RETCODE_OK;
tickRateMS = (int) pdMS_TO_TICKS(MQTTCfgParser_GetStreamRate());
Expand Down
2 changes: 1 addition & 1 deletion source/MQTTOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


/* global function prototype declarations */
void MQTTOperation_Init(MQTT_Setup_TZ, MQTT_Connect_TZ, MQTT_Credentials_TZ, Sensor_Setup_T);
void MQTTOperation_Init();
void MQTTOperation_DeInit(void);
void MQTTOperation_QueueCommand(void * param1, uint32_t param2);

Expand Down
18 changes: 5 additions & 13 deletions source/MQTTRegistration.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ static xTimerHandle clientRegistrationTimerHandle = NULL; // timer handle for da
static char appIncomingMsgTopicBuffer[SIZE_SMALL_BUF];/**< Incoming message topic buffer */
static char appIncomingMsgPayloadBuffer[SIZE_LARGE_BUF];/**< Incoming message payload buffer */
static uint16_t connectAttemps = 0UL;
static AssetDataBuffer assetStreamBuffer;

/* global variables ********************************************************* */
// Network and Client Configuration
/* global variable declarations */
extern AssetDataBuffer assetStreamBuffer;
extern MQTT_Setup_TZ MqttSetupInfo;
extern MQTT_Connect_TZ MqttConnectInfo;
extern MQTT_Credentials_TZ MqttCredentials;

/* inline functions ********************************************************* */

Expand All @@ -69,10 +70,6 @@ static MQTT_Subscribe_TZ MqttSubscribeInfo = { .Topic = TOPIC_CREDENTIAL, .QoS =
static MQTT_Publish_TZ MqttPublishInfo = { .Topic = TOPIC_REGISTRATION, .QoS =
1UL, .Payload = NULL, .PayloadLength = 0UL, };/**< MQTT publish parameters */

static MQTT_Setup_TZ MqttSetupInfo;
static MQTT_Connect_TZ MqttConnectInfo;
static MQTT_Credentials_TZ MqttCredentials = { .Username = MQTT_REGISTRATION_USERNAME, .Password = MQTT_REGISTRATION_PASSWORD, };

static void MQTTRegistration_PrepareNextRegistrationMsg (xTimerHandle xTimer){
(void) xTimer;
LOG_AT_DEBUG(("MQTTRegistration: requesting credentials ...\n\r"));
Expand Down Expand Up @@ -228,12 +225,7 @@ void MQTTRegistration_StartTimer(void){
*
* @return NONE
*/
void MQTTRegistration_Init(MQTT_Setup_TZ MqttSetupInfo_P,
MQTT_Connect_TZ MqttConnectInfo_P) {

/* Initialize Variables */
MqttSetupInfo = MqttSetupInfo_P;
MqttConnectInfo = MqttConnectInfo_P;
void MQTTRegistration_Init() {

Retcode_T retcode = RETCODE_OK;

Expand Down
7 changes: 1 addition & 6 deletions source/MQTTRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@
#define TOPIC_REGISTRATION "s/ucr"
#define TOPIC_CREDENTIAL "s/dcr"


#define MQTT_REGISTRATION_PORT 8883
#define MQTT_REGISTRATION_BROKERNAME "mqtt.cumulocity.com"
#define MQTT_REGISTRATION_USERNAME "management/devicebootstrap"
#define MQTT_REGISTRATION_PASSWORD "Fhdt1bb1f"
#define MQTT_REGISTRATION_TICKRATE 2000

#define MILLISECONDS(x) ((portTickType) x / portTICK_RATE_MS)
#define SECONDS(x) ((portTickType) (x * 1000) / portTICK_RATE_MS)

/* global function prototype declarations */
void MQTTRegistration_Init(MQTT_Setup_TZ, MQTT_Connect_TZ);
void MQTTRegistration_Init();
void MQTTRegistration_DeInit(void);
void MQTTRegistration_StartTimer(void);
void MQTTRegistration_StopTimer(void);
Expand Down

0 comments on commit 8995796

Please sign in to comment.