2021-06-24 11:42:40 +02:00
|
|
|
#include "GPSHyperionHandler.h"
|
2021-06-15 17:07:47 +02:00
|
|
|
#include "devicedefinitions/GPSDefinitions.h"
|
2020-12-22 00:32:11 +01:00
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
#include "fsfw/datapool/PoolReadGuard.h"
|
2021-06-24 13:55:51 +02:00
|
|
|
#include "fsfw/timemanager/Clock.h"
|
2021-06-24 11:42:40 +02:00
|
|
|
|
2021-06-16 17:19:14 +02:00
|
|
|
#include "lwgps/lwgps.h"
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
GPSHyperionHandler::GPSHyperionHandler(object_id_t objectId, object_id_t deviceCommunication,
|
2020-12-22 00:32:11 +01:00
|
|
|
CookieIF *comCookie):
|
2021-06-24 11:42:40 +02:00
|
|
|
DeviceHandlerBase(objectId, deviceCommunication, comCookie), gpsSet(this) {
|
2021-06-16 17:19:14 +02:00
|
|
|
lwgps_init(&gpsData);
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
GPSHyperionHandler::~GPSHyperionHandler() {}
|
2020-12-22 00:32:11 +01:00
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
void GPSHyperionHandler::doStartUp() {
|
2021-06-15 16:44:31 +02:00
|
|
|
if(internalState == InternalStates::NONE) {
|
|
|
|
commandExecuted = false;
|
|
|
|
internalState = InternalStates::WAIT_FIRST_MESSAGE;
|
|
|
|
}
|
2020-12-22 00:32:11 +01:00
|
|
|
|
2021-06-15 16:44:31 +02:00
|
|
|
if(internalState == InternalStates::WAIT_FIRST_MESSAGE) {
|
|
|
|
if(commandExecuted) {
|
|
|
|
internalState = InternalStates::IDLE;
|
|
|
|
setMode(MODE_ON);
|
|
|
|
commandExecuted = false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
void GPSHyperionHandler::doShutDown() {
|
2021-06-15 16:44:31 +02:00
|
|
|
internalState = InternalStates::NONE;
|
|
|
|
commandExecuted = false;
|
|
|
|
setMode(MODE_OFF);
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
ReturnValue_t GPSHyperionHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
2020-12-22 00:32:11 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
ReturnValue_t GPSHyperionHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
2020-12-22 00:32:11 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
ReturnValue_t GPSHyperionHandler::buildCommandFromCommand(
|
2020-12-22 00:32:11 +01:00
|
|
|
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
ReturnValue_t GPSHyperionHandler::scanForReply(const uint8_t *start, size_t len,
|
2020-12-22 00:32:11 +01:00
|
|
|
DeviceCommandId_t *foundId, size_t *foundLen) {
|
2021-06-16 17:19:14 +02:00
|
|
|
// Pass data to GPS library
|
2021-06-23 15:18:31 +02:00
|
|
|
if(len > 0) {
|
2021-06-24 08:50:46 +02:00
|
|
|
sif::info << "GPSHandler::scanForReply: Received " << len << " bytes" << std::endl;
|
|
|
|
if (internalState == InternalStates::WAIT_FIRST_MESSAGE) {
|
|
|
|
// TODO: Check whether data is valid by chcking whether NMEA start string is valid
|
|
|
|
commandExecuted = true;
|
|
|
|
}
|
2021-06-23 15:18:31 +02:00
|
|
|
int result = lwgps_process(&gpsData, start, len);
|
2021-06-24 08:50:46 +02:00
|
|
|
if(result != 1) {
|
2021-06-23 15:18:31 +02:00
|
|
|
sif::warning << "GPSHandler::scanForReply: Issue processing GPS data with lwgps"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2021-06-24 08:50:46 +02:00
|
|
|
else {
|
2021-06-24 11:42:40 +02:00
|
|
|
// The data from the device will generally be read all at once. Therefore, we
|
|
|
|
// can set all field here
|
|
|
|
PoolReadGuard pg(&gpsSet);
|
|
|
|
if(pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
sif::warning << "GPSHyperionHandler::scanForReply: Reading dataset failed"
|
|
|
|
<< std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2021-06-24 08:50:46 +02:00
|
|
|
// Print messages
|
2021-06-24 11:42:40 +02:00
|
|
|
if(gpsData.is_valid) {
|
|
|
|
// Set all entries valid now, set invalid on case basis if values are sanitized
|
|
|
|
gpsSet.setValidity(true, true);
|
|
|
|
}
|
2021-06-24 13:55:51 +02:00
|
|
|
// Negative latitude -> South direction
|
2021-06-24 11:42:40 +02:00
|
|
|
gpsSet.latitude.value = gpsData.latitude;
|
2021-06-24 13:55:51 +02:00
|
|
|
// Negative longitude -> West direction
|
2021-06-24 11:42:40 +02:00
|
|
|
gpsSet.longitude.value = gpsData.latitude;
|
|
|
|
gpsSet.fixMode.value = gpsData.fix_mode;
|
2021-06-24 13:55:51 +02:00
|
|
|
gpsSet.satInUse.value = gpsData.sats_in_use;
|
|
|
|
Clock::TimeOfDay_t timeStruct = {};
|
|
|
|
timeStruct.day = gpsData.date;
|
|
|
|
timeStruct.hour = gpsData.hours;
|
|
|
|
timeStruct.minute = gpsData.minutes;
|
|
|
|
timeStruct.month = gpsData.month;
|
|
|
|
timeStruct.second = gpsData.seconds;
|
|
|
|
// Convert two-digit year to full year (AD)
|
|
|
|
timeStruct.year = gpsData.year + 2000;
|
|
|
|
timeval timeval = {};
|
|
|
|
Clock::convertTimeOfDayToTimeval(&timeStruct, &timeval);
|
|
|
|
gpsSet.year = timeStruct.year;
|
|
|
|
gpsSet.month = gpsData.month;
|
|
|
|
gpsSet.day = gpsData.date;
|
|
|
|
gpsSet.hours = gpsData.hours;
|
|
|
|
gpsSet.minutes = gpsData.minutes;
|
|
|
|
gpsSet.seconds = gpsData.seconds;
|
2021-06-24 11:42:40 +02:00
|
|
|
#if FSFW_HAL_DEBUG_HYPERION_GPS == 1
|
|
|
|
sif::info << "GPS Data" << std::endl;
|
2021-06-24 08:50:46 +02:00
|
|
|
printf("Valid status: %d\n", gpsData.is_valid);
|
|
|
|
printf("Latitude: %f degrees\n", gpsData.latitude);
|
|
|
|
printf("Longitude: %f degrees\n", gpsData.longitude);
|
|
|
|
printf("Altitude: %f meters\n", gpsData.altitude);
|
2021-06-24 11:42:40 +02:00
|
|
|
#endif
|
2021-06-24 08:50:46 +02:00
|
|
|
}
|
|
|
|
*foundLen = len;
|
2021-06-16 17:19:14 +02:00
|
|
|
}
|
2020-12-22 00:32:11 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-06-16 17:19:14 +02:00
|
|
|
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
ReturnValue_t GPSHyperionHandler::interpretDeviceReply(DeviceCommandId_t id,
|
2020-12-22 00:32:11 +01:00
|
|
|
const uint8_t *packet) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
uint32_t GPSHyperionHandler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
2020-12-22 00:32:11 +01:00
|
|
|
return 5000;
|
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
ReturnValue_t GPSHyperionHandler::initializeLocalDataPool(
|
2021-01-14 11:37:32 +01:00
|
|
|
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
2021-06-24 13:55:51 +02:00
|
|
|
localDataPoolMap.emplace(GpsHyperion::ALTITUDE, new PoolEntry<double>({0.0}));
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::LONGITUDE, new PoolEntry<double>({0.0}));
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::LATITUDE, new PoolEntry<double>({0.0}));
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::YEAR, new PoolEntry<uint16_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::MONTH, new PoolEntry<uint8_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::DAY, new PoolEntry<uint8_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::HOURS, new PoolEntry<uint8_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::MINUTES, new PoolEntry<uint8_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::SECONDS, new PoolEntry<uint8_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::UNIX_SECONDS, new PoolEntry<uint32_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::SATS_IN_USE, new PoolEntry<uint8_t>());
|
|
|
|
localDataPoolMap.emplace(GpsHyperion::FIX_MODE, new PoolEntry<uint8_t>());
|
2020-12-22 00:32:11 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
void GPSHyperionHandler::fillCommandAndReplyMap() {
|
2021-06-15 17:07:47 +02:00
|
|
|
// Reply length does not matter, packets should always arrive periodically
|
|
|
|
insertInReplyMap(GpsHyperion::GPS_REPLY, 4, nullptr, 0, true);
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 11:42:40 +02:00
|
|
|
void GPSHyperionHandler::modeChanged() {
|
2021-06-15 17:07:47 +02:00
|
|
|
internalState = InternalStates::NONE;
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|