Skip to content

Commit

Permalink
introduced command queuing
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 21, 2019
1 parent 6acf325 commit b188943
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 220 deletions.
6 changes: 2 additions & 4 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ Retcode_T AppController_SyncTime() {
("MQTTOperation: SNTP server time was not synchronized. Retrying...\r\n"));
}
sntpAttemps++;
vTaskDelay(pdMS_TO_TICKS(2000));
} while (0UL == sntpTimeStampFromServer && sntpAttemps < 3); // only try to sync time 5 times
vTaskDelay(pdMS_TO_TICKS(1500));
} 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
SNTP_SetTime(sntpTimeStampFromServer);
Expand Down Expand Up @@ -505,5 +505,3 @@ void AppController_SetCmdStatus( uint8_t status) {
uint8_t AppController_GetCmdStatus(void) {
return cmd_status;
}


6 changes: 3 additions & 3 deletions source/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ typedef enum {
APP_ASSET_WAITING,
APP_ASSET_PUBLISHED,
APP_ASSET_COMPLETED,
} APP_ASSET_STATUS;
} APP_ASSET_UPDATE_STATUS;

/* Default values for C8Y MQTT configuration*/
#define DEFAULT_MQTTSECURE true /**use MQTT over TLS */
Expand All @@ -259,8 +259,8 @@ typedef enum {

/* Sensor type and macro definitions */

#define SIZE_XXLARGE_BUF 550
#define SIZE_XLARGE_BUF 400
#define SIZE_XXLARGE_BUF 512
#define SIZE_XLARGE_BUF 384
#define SIZE_LARGE_BUF 256
#define SIZE_SMALL_BUF 128
#define SIZE_XSMALL_BUF 64
Expand Down
28 changes: 19 additions & 9 deletions source/MQTTButton.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
/* local variables ********************************************************** */
static CmdProcessor_T *AppCmdProcessor; /**< Application Command Processor Instance */


/* global variables ********************************************************* */

/* inline functions ********************************************************* */
Expand All @@ -57,14 +56,25 @@ static CmdProcessor_T *AppCmdProcessor; /**< Application Command Processor Insta
static void processbuttonCallback1 (void * param1, uint32_t buttonstatus)
{
BCDS_UNUSED(param1);
static TickType_t time_start = 0;

LOG_AT_TRACE(("MQTTButton: Status button %d %lu %i\r\n", AppController_GetStatus(), buttonstatus, BSP_XDK_BUTTON_PRESS));

// only use button 1 when in operation mode
if (AppController_GetStatus() == APP_STATUS_OPERATING_STARTED && BSP_XDK_BUTTON_PRESSED == buttonstatus)
CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_StopTimer, NULL, buttonstatus);
if (AppController_GetStatus() == APP_STATUS_OPERATING_STOPPED && BSP_XDK_BUTTON_PRESSED == buttonstatus)
CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_StartTimer, NULL, buttonstatus);
if (BSP_XDK_BUTTON_PRESSED == buttonstatus ) {
time_start = xTaskGetTickCountFromISR();
} else {
TickType_t time_passed = xTaskGetTickCountFromISR() - time_start;
if (time_passed > pdMS_TO_TICKS(3000)) {
CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,requestCommands", buttonstatus);
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);
} else if (AppController_GetStatus() == APP_STATUS_OPERATING_STOPPED) {
CmdProcessor_EnqueueFromIsr(AppCmdProcessor, MQTTOperation_QueueCommand, "511,DUMMY,startButton", buttonstatus);
}
}
}
}


Expand All @@ -79,7 +89,7 @@ static void processbuttonCallback2 (void * param1, uint32_t buttonstatus)
TickType_t time_passed = xTaskGetTickCountFromISR() - time_start;
if (time_passed > pdMS_TO_TICKS(3000)) {
MQTTFlash_FLWriteBootStatus((uint8_t*) NO_BOOT_PENDING);
LOG_AT_TRACE(("MQTTButton: Button pressed long: %lu\r\n", time_passed));
LOG_AT_TRACE(("MQTTButton: Button2 pressed long: %lu\r\n", time_passed));
} else {
ConfigDataBuffer localbuffer;
localbuffer.length = NUMBER_UINT32_ZERO;
Expand All @@ -91,7 +101,7 @@ static void processbuttonCallback2 (void * param1, uint32_t buttonstatus)
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));
LOG_AT_TRACE(("MQTTButton: Button pressed for: %lu\r\n", time_passed));
LOG_AT_TRACE(("MQTTButton: Button2 pressed for: %lu\r\n", time_passed));
}
}

Expand Down
Loading

0 comments on commit b188943

Please sign in to comment.