lets not forget error handling

This commit is contained in:
Robin Müller 2024-04-03 16:19:40 +02:00
parent 0cfe559b93
commit 0e2fa8dc83
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -23,7 +23,10 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
}
case Subservice::DUMP_TIME: {
timeval newTime;
Clock::getClock_timeval(&newTime);
ReturnValue_t result = Clock::getClock_timeval(&newTime);
if (result != returnvalue::OK) {
return result;
}
uint32_t subsecondMs =
static_cast<uint32_t>(std::floor(static_cast<double>(newTime.tv_usec) / 1000.0));
triggerEvent(CLOCK_DUMP, newTime.tv_sec, subsecondMs);
@ -31,15 +34,21 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
}
case Subservice::RELATIVE_TIMESHIFT: {
timeval currentTime;
Clock::getClock_timeval(&currentTime);
ReturnValue_t result = Clock::getClock_timeval(&currentTime);
if (result != returnvalue::OK) {
return result;
}
if (currentPacket.getUserDataLen() != 8) {
return AcceptsTelecommandsIF::ILLEGAL_APPLICATION_DATA;
}
size_t deserLen = 8;
int64_t timeshiftNanos = 0;
SerializeAdapter::deSerialize(&timeshiftNanos, currentPacket.getUserData(), &deserLen,
SerializeIF::Endianness::NETWORK);
result = SerializeAdapter::deSerialize(&timeshiftNanos, currentPacket.getUserData(),
&deserLen, SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
bool positiveShift = true;
if (timeshiftNanos < 0) {
positiveShift = false;
@ -54,8 +63,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
} else {
newTime = currentTime - offset;
}
Clock::setClock(&newTime);
return returnvalue::OK;
return Clock::setClock(&newTime);
}
default:
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;