Merge pull request 'Update package 2' (#380) from KSat/fsfw:mueller/update-package-2 into development

Reviewed-on: fsfw/fsfw#380
This commit is contained in:
Steffen Gaisser 2021-03-09 14:18:53 +01:00
commit 6d0bc26624
8 changed files with 166 additions and 156 deletions

View File

@ -46,7 +46,7 @@ void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo,
void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t commandId, void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t commandId,
ReturnValue_t result) { ReturnValue_t result) {
CommandMessage reply; CommandMessage reply;
ActionMessage::setCompletionReply(success, &reply, commandId, result); ActionMessage::setCompletionReply(&reply, commandId, success, result);
queueToUse->sendMessage(reportTo, &reply); queueToUse->sendMessage(reportTo, &reply);
} }
@ -69,7 +69,7 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
ipcStore->deleteData(dataAddress); ipcStore->deleteData(dataAddress);
if(result == HasActionsIF::EXECUTION_FINISHED) { if(result == HasActionsIF::EXECUTION_FINISHED) {
CommandMessage reply; CommandMessage reply;
ActionMessage::setCompletionReply(true, &reply, actionId, result); ActionMessage::setCompletionReply(&reply, actionId, true, result);
queueToUse->sendMessage(commandedBy, &reply); queueToUse->sendMessage(commandedBy, &reply);
} }
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -53,8 +53,8 @@ void ActionMessage::setDataReply(CommandMessage* message, ActionId_t actionId,
message->setParameter2(data.raw); message->setParameter2(data.raw);
} }
void ActionMessage::setCompletionReply(bool success, CommandMessage* message, void ActionMessage::setCompletionReply(CommandMessage* message,
ActionId_t fid, ReturnValue_t result) { ActionId_t fid, bool success, ReturnValue_t result) {
if (success) { if (success) {
message->setCommand(COMPLETION_SUCCESS); message->setCommand(COMPLETION_SUCCESS);
} }

View File

@ -38,8 +38,8 @@ public:
static ReturnValue_t getReturnCode(const CommandMessage* message ); static ReturnValue_t getReturnCode(const CommandMessage* message );
static void setDataReply(CommandMessage* message, ActionId_t actionId, static void setDataReply(CommandMessage* message, ActionId_t actionId,
store_address_t data); store_address_t data);
static void setCompletionReply(bool success, CommandMessage* message, ActionId_t fid, static void setCompletionReply(CommandMessage* message, ActionId_t fid,
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); bool success, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
static void clear(CommandMessage* message); static void clear(CommandMessage* message);
}; };

View File

@ -62,8 +62,8 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
stepCount++; stepCount++;
break; break;
case HasActionsIF::EXECUTION_FINISHED: case HasActionsIF::EXECUTION_FINISHED:
ActionMessage::setCompletionReply(true, &reply, actionId, ActionMessage::setCompletionReply(&reply, actionId,
HasReturnvaluesIF::RETURN_OK); true, HasReturnvaluesIF::RETURN_OK);
queueToUse->sendMessage(commandedBy, &reply); queueToUse->sendMessage(commandedBy, &reply);
break; break;
default: default:

View File

@ -36,7 +36,7 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
this->sid.objectId = hkOwner->getObjectId(); this->sid.objectId = hkOwner->getObjectId();
this->sid.ownerSetId = setId; this->sid.ownerSetId = setId;
// Data creators get a periodic helper for periodic HK data generation. /* Data creators get a periodic helper for periodic HK data generation. */
if(periodicHandling) { if(periodicHandling) {
periodicHelper = new PeriodicHousekeepingHelper(this); periodicHelper = new PeriodicHousekeepingHelper(this);
} }

View File

@ -98,7 +98,6 @@ inline ReturnValue_t LocalPoolVariable<T>::commitWithoutLock() {
} }
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
//ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId,
&poolEntry); &poolEntry);
if(result != RETURN_OK) { if(result != RETURN_OK) {

View File

@ -39,6 +39,9 @@ public:
sif::printError("MutexHelper: Lock of Mutex failed with code %d\n", status); sif::printError("MutexHelper: Lock of Mutex failed with code %d\n", status);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
} }
#else
/* To avoid unused variable warning */
static_cast<void>(status);
#endif /* FSFW_VERBOSE_LEVEL >= 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */
} }

View File

@ -10,201 +10,209 @@ uint16_t Clock::leapSeconds = 0;
MutexIF* Clock::timeMutex = nullptr; MutexIF* Clock::timeMutex = nullptr;
uint32_t Clock::getTicksPerSecond(void){ uint32_t Clock::getTicksPerSecond(void){
rtems_interval ticks_per_second = rtems_clock_get_ticks_per_second(); rtems_interval ticks_per_second = rtems_clock_get_ticks_per_second();
return static_cast<uint32_t>(ticks_per_second); return static_cast<uint32_t>(ticks_per_second);
} }
ReturnValue_t Clock::setClock(const TimeOfDay_t* time) { ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
rtems_time_of_day timeRtems; rtems_time_of_day timeRtems;
timeRtems.year = time->year; timeRtems.year = time->year;
timeRtems.month = time->month; timeRtems.month = time->month;
timeRtems.day = time->day; timeRtems.day = time->day;
timeRtems.hour = time->hour; timeRtems.hour = time->hour;
timeRtems.minute = time->minute; timeRtems.minute = time->minute;
timeRtems.second = time->second; timeRtems.second = time->second;
timeRtems.ticks = time->usecond * getTicksPerSecond() / 1e6; timeRtems.ticks = time->usecond * getTicksPerSecond() / 1e6;
rtems_status_code status = rtems_clock_set(&timeRtems); rtems_status_code status = rtems_clock_set(&timeRtems);
switch(status){ switch(status){
case RTEMS_SUCCESSFUL: case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
case RTEMS_INVALID_ADDRESS: case RTEMS_INVALID_ADDRESS:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_CLOCK: case RTEMS_INVALID_CLOCK:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
default: default:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t Clock::setClock(const timeval* time) { ReturnValue_t Clock::setClock(const timeval* time) {
timespec newTime; timespec newTime;
newTime.tv_sec = time->tv_sec; newTime.tv_sec = time->tv_sec;
if(time->tv_usec < 0) { if(time->tv_usec < 0) {
// better returnvalue. // better returnvalue.
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
newTime.tv_nsec = time->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND; newTime.tv_nsec = time->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
ISR_lock_Context context; ISR_lock_Context context;
_TOD_Lock(); _TOD_Lock();
_TOD_Acquire(&context); _TOD_Acquire(&context);
Status_Control status = _TOD_Set(&newTime, &context); Status_Control status = _TOD_Set(&newTime, &context);
_TOD_Unlock(); _TOD_Unlock();
if(status == STATUS_SUCCESSFUL) { if(status == STATUS_SUCCESSFUL) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
// better returnvalue // better returnvalue
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
ReturnValue_t Clock::getClock_timeval(timeval* time) { ReturnValue_t Clock::getClock_timeval(timeval* time) {
//Callable from ISR //Callable from ISR
rtems_status_code status = rtems_clock_get_tod_timeval(time); rtems_status_code status = rtems_clock_get_tod_timeval(time);
switch(status){ switch(status){
case RTEMS_SUCCESSFUL: case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
case RTEMS_NOT_DEFINED: case RTEMS_NOT_DEFINED:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
default: default:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t Clock::getUptime(timeval* uptime) { ReturnValue_t Clock::getUptime(timeval* uptime) {
//According to docs.rtems.org for rtems 5 this method is more accurate than rtems_clock_get_ticks_since_boot //According to docs.rtems.org for rtems 5 this method is more accurate than rtems_clock_get_ticks_since_boot
timespec time; timespec time;
rtems_status_code status = rtems_clock_get_uptime(&time); rtems_status_code status = rtems_clock_get_uptime(&time);
uptime->tv_sec = time.tv_sec; uptime->tv_sec = time.tv_sec;
time.tv_nsec = time.tv_nsec / 1000; time.tv_nsec = time.tv_nsec / 1000;
uptime->tv_usec = time.tv_nsec; uptime->tv_usec = time.tv_nsec;
switch(status){ switch(status){
case RTEMS_SUCCESSFUL: case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
default: default:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
//This counter overflows after 50 days //This counter overflows after 50 days
*uptimeMs = rtems_clock_get_ticks_since_boot(); *uptimeMs = rtems_clock_get_ticks_since_boot();
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t Clock::getClock_usecs(uint64_t* time) { ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
timeval temp_time; timeval temp_time;
rtems_status_code returnValue = rtems_clock_get_tod_timeval(&temp_time); rtems_status_code returnValue = rtems_clock_get_tod_timeval(&temp_time);
*time = ((uint64_t) temp_time.tv_sec * 1000000) + temp_time.tv_usec; *time = ((uint64_t) temp_time.tv_sec * 1000000) + temp_time.tv_usec;
switch(returnValue){ switch(returnValue){
case RTEMS_SUCCESSFUL: case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
default: default:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
/* For all but the last field, the struct will be filled with the correct values */ /* For all but the last field, the struct will be filled with the correct values */
rtems_time_of_day* timeRtems = reinterpret_cast<rtems_time_of_day*>(time); rtems_time_of_day timeRtems;
rtems_status_code status = rtems_clock_get_tod(timeRtems); rtems_status_code status = rtems_clock_get_tod(&timeRtems);
/* The last field now contains the RTEMS ticks of the seconds from 0 switch (status) {
to rtems_clock_get_ticks_per_second() minus one. We calculate the microseconds accordingly */ case RTEMS_SUCCESSFUL: {
timeRtems->ticks = static_cast<float>(timeRtems->ticks) / /* The last field now contains the RTEMS ticks of the seconds from 0
rtems_clock_get_ticks_per_second() * 1e6; to rtems_clock_get_ticks_per_second() minus one.
switch (status) { We calculate the microseconds accordingly */
case RTEMS_SUCCESSFUL: time->day = timeRtems.day;
return HasReturnvaluesIF::RETURN_OK; time->hour = timeRtems.hour;
case RTEMS_NOT_DEFINED: time->minute = timeRtems.minute;
//system date and time is not set time->month = timeRtems.month;
return HasReturnvaluesIF::RETURN_FAILED; time->second = timeRtems.second;
case RTEMS_INVALID_ADDRESS: time->usecond = static_cast<float>(timeRtems.ticks) /
//time_buffer is NULL rtems_clock_get_ticks_per_second() * 1e6;
return HasReturnvaluesIF::RETURN_FAILED; time->year = timeRtems.year;
default: return HasReturnvaluesIF::RETURN_OK;
return HasReturnvaluesIF::RETURN_FAILED; }
} case RTEMS_NOT_DEFINED:
/* System date and time is not set */
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
/* time_buffer is NULL */
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
} }
ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from,
timeval* to) { timeval* to) {
//Fails in 2038.. //Fails in 2038..
rtems_time_of_day timeRtems; rtems_time_of_day timeRtems;
timeRtems.year = from->year; timeRtems.year = from->year;
timeRtems.month = from->month; timeRtems.month = from->month;
timeRtems.day = from->day; timeRtems.day = from->day;
timeRtems.hour = from->hour; timeRtems.hour = from->hour;
timeRtems.minute = from->minute; timeRtems.minute = from->minute;
timeRtems.second = from->second; timeRtems.second = from->second;
timeRtems.ticks = from->usecond * getTicksPerSecond() / 1e6; timeRtems.ticks = from->usecond * getTicksPerSecond() / 1e6;
to->tv_sec = _TOD_To_seconds(&timeRtems); to->tv_sec = _TOD_To_seconds(&timeRtems);
to->tv_usec = from->usecond; to->tv_usec = from->usecond;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) { ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) {
*JD2000 = (time.tv_sec - 946728000. + time.tv_usec / 1000000.) / 24. *JD2000 = (time.tv_sec - 946728000. + time.tv_usec / 1000000.) / 24.
/ 3600.; / 3600.;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval* tt) { ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval* tt) {
//SHOULDDO: works not for dates in the past (might have less leap seconds) //SHOULDDO: works not for dates in the past (might have less leap seconds)
if (timeMutex == nullptr) { if (timeMutex == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
uint16_t leapSeconds; uint16_t leapSeconds;
ReturnValue_t result = getLeapSeconds(&leapSeconds); ReturnValue_t result = getLeapSeconds(&leapSeconds);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
timeval leapSeconds_timeval = { 0, 0 }; timeval leapSeconds_timeval = { 0, 0 };
leapSeconds_timeval.tv_sec = leapSeconds; leapSeconds_timeval.tv_sec = leapSeconds;
//initial offset between UTC and TAI //initial offset between UTC and TAI
timeval UTCtoTAI1972 = { 10, 0 }; timeval UTCtoTAI1972 = { 10, 0 };
timeval TAItoTT = { 32, 184000 }; timeval TAItoTT = { 32, 184000 };
*tt = utc + leapSeconds_timeval + UTCtoTAI1972 + TAItoTT; *tt = utc + leapSeconds_timeval + UTCtoTAI1972 + TAItoTT;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) { ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) {
if(checkOrCreateClockMutex()!=HasReturnvaluesIF::RETURN_OK){ if(checkOrCreateClockMutex()!=HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
MutexHelper helper(timeMutex); MutexHelper helper(timeMutex);
leapSeconds = leapSeconds_; leapSeconds = leapSeconds_;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) { ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) {
if(timeMutex==nullptr){ if(timeMutex==nullptr){
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
MutexHelper helper(timeMutex); MutexHelper helper(timeMutex);
*leapSeconds_ = leapSeconds; *leapSeconds_ = leapSeconds;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t Clock::checkOrCreateClockMutex(){ ReturnValue_t Clock::checkOrCreateClockMutex(){
if(timeMutex==nullptr){ if(timeMutex==nullptr){
MutexFactory* mutexFactory = MutexFactory::instance(); MutexFactory* mutexFactory = MutexFactory::instance();
if (mutexFactory == nullptr) { if (mutexFactory == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
timeMutex = mutexFactory->createMutex(); timeMutex = mutexFactory->createMutex();
if (timeMutex == nullptr) { if (timeMutex == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }