Skip to content

Commit

Permalink
Merge pull request #88 from RI-SE/feature_reportStateLessFrequently
Browse files Browse the repository at this point in the history
Reduced period between object control state transmissions
  • Loading branch information
LukasWikander authored Jul 5, 2019
2 parents c5d2213 + 51283ca commit 2aa4e10
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions server/src/objectcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdlib.h>
#include <sys/time.h>
#include "timecontrol.h"
#include "maestroTime.h"


/*------------------------------------------------------------
Expand All @@ -49,12 +50,16 @@
#define OC_SLEEP_TIME_NONEMPTY_MQ_S 0
#define OC_SLEEP_TIME_NONEMPTY_MQ_NS 0


#define TASK_PERIOD_MS 1
#define HEARTBEAT_TIME_MS 10
#define OBJECT_CONTROL_CONTROL_MODE 0
#define OBJECT_CONTROL_REPLAY_MODE 1
#define OBJECT_CONTROL_ABORT_MODE 1

#define OC_STATE_REPORT_PERIOD_S 1
#define OC_STATE_REPORT_PERIOD_US 0

#define COMMAND_MESSAGE_HEADER_LENGTH sizeof(HeaderType)
#define COMMAND_MESSAGE_FOOTER_LENGTH sizeof(FooterType)
#define COMMAND_CODE_INDEX 0
Expand Down Expand Up @@ -247,6 +252,8 @@ void objectcontrol_task(TimeType *GPSTime, GSDType *GSD, LOG_LEVEL logLevel)
struct timespec sleep_time, ref_time;
const struct timespec mqEmptyPollPeriod = {OC_SLEEP_TIME_EMPTY_MQ_S, OC_SLEEP_TIME_EMPTY_MQ_NS};
const struct timespec mqNonEmptyPollPeriod = {OC_SLEEP_TIME_NONEMPTY_MQ_S, OC_SLEEP_TIME_NONEMPTY_MQ_NS};
const struct timeval stateReportPeriod = {OC_STATE_REPORT_PERIOD_S, OC_STATE_REPORT_PERIOD_US};
struct timeval currentTime, nextStateReportTime;
int iForceObjectToLocalhost = 0;

FILE *fd;
Expand Down Expand Up @@ -362,6 +369,10 @@ void objectcontrol_task(TimeType *GPSTime, GSDType *GSD, LOG_LEVEL logLevel)
if (iCommInit())
util_error("Unable to connect to message queue bus");

// Initialize timer for sending state
TimeSetToCurrentSystemTime(&currentTime);
nextStateReportTime = currentTime;

while(!iExit)
{
if(OBCState == OBC_STATE_ERROR)
Expand Down Expand Up @@ -1183,15 +1194,23 @@ void objectcontrol_task(TimeType *GPSTime, GSDType *GSD, LOG_LEVEL logLevel)
++uiTimeCycle;
if(uiTimeCycle >= HEARTBEAT_TIME_MS/TASK_PERIOD_MS)
{
uiTimeCycle = 0;
}

// Periodically send state to signal aliveness (TODO: replace with supervisor process health check)
TimeSetToCurrentSystemTime(&currentTime);
if (timercmp(&currentTime, &nextStateReportTime, >))
{
timeradd(&nextStateReportTime, &stateReportPeriod, &nextStateReportTime);

bzero(Buffer2, SMALL_BUFFER_SIZE_1);
Buffer2[0] = OBCState;
if(iCommSend(COMM_OBC_STATE,Buffer2,SMALL_BUFFER_SIZE_1) < 0)
if (iCommSend(COMM_OBC_STATE, Buffer2, SMALL_BUFFER_SIZE_1) < 0)
{
LogMessage(LOG_LEVEL_ERROR,"Fatal communication fault when sending OBC_STATE command - entering error state");
vSetState(&OBCState,OBC_STATE_ERROR);
ObjectControlServerStatus = COMMAND_HEAB_OPT_SERVER_STATUS_ABORT;
}
uiTimeCycle = 0;
}

(void)nanosleep(&sleep_time,&ref_time);
Expand Down

0 comments on commit 2aa4e10

Please sign in to comment.