eive-obsw/linux/acs/GpsHyperionLinuxController.h

100 lines
3.5 KiB
C
Raw Normal View History

2022-01-26 17:59:31 +01:00
#ifndef MISSION_DEVICES_GPSHYPERIONHANDLER_H_
#define MISSION_DEVICES_GPSHYPERIONHANDLER_H_
#include <common/config/eive/eventSubsystemIds.h>
#include <fsfw/FSFW.h>
#include <fsfw/controller/ExtendedControllerBase.h>
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
2024-03-18 17:20:55 +01:00
#include <linux/acs/GPSDefinitions.h>
2023-03-26 16:42:00 +02:00
#include <mission/utility/trace.h>
2023-03-26 16:13:54 +02:00
2022-01-26 17:59:31 +01:00
#ifdef FSFW_OSAL_LINUX
#include <gps.h>
#include <libgpsmm.h>
#endif
/**
* @brief Device handler for the Hyperion HT-GPS200 device
* @details
* Flight manual:
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/Hyperion_HT-GPS200
* This device handler can only be used on Linux system where the gpsd daemon with shared memory
* export is running.
*/
2023-02-05 13:13:09 +01:00
class GpsHyperionLinuxController : public ExtendedControllerBase {
2022-01-26 17:59:31 +01:00
public:
2024-04-09 13:30:22 +02:00
// 15 minutes
static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 15;
2022-04-07 17:23:50 +02:00
2022-05-03 00:55:01 +02:00
enum ReadModes { SHM = 0, SOCKET = 1 };
2023-04-04 19:18:53 +02:00
GpsHyperionLinuxController(object_id_t objectId, object_id_t parentId, bool enableHkSets,
2022-01-26 17:59:31 +01:00
bool debugHyperionGps = false);
2023-02-05 13:13:09 +01:00
virtual ~GpsHyperionLinuxController();
2022-01-26 17:59:31 +01:00
2022-05-25 10:59:20 +02:00
using gpioResetFunction_t = ReturnValue_t (*)(const uint8_t* actionData, size_t len, void* args);
2022-01-26 17:59:31 +01:00
2023-02-06 10:20:22 +01:00
ReturnValue_t performOperation(uint8_t opCode) override;
2022-01-26 17:59:31 +01:00
void setResetPinTriggerFunction(gpioResetFunction_t resetCallback, void* args);
ReturnValue_t handleCommandMessage(CommandMessage* message) override;
void performControlOperation() override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t* msToReachTheMode) override;
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override;
ReturnValue_t initialize() override;
protected:
gpioResetFunction_t resetCallback = nullptr;
void* resetCallbackArgs = nullptr;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
2023-02-05 13:13:09 +01:00
ReturnValue_t handleGpsReadData();
2023-08-04 10:50:19 +02:00
ReturnValue_t handleCoreTelemetry(bool modeIsSet);
ReturnValue_t handleSkyviewTelemetry();
2022-05-03 00:55:01 +02:00
2022-01-26 17:59:31 +01:00
private:
GpsPrimaryDataset gpsSet;
2023-08-04 10:50:19 +02:00
SkyviewDataset skyviewSet;
2022-05-03 11:33:07 +02:00
gps_data_t gps = {};
2023-04-04 19:18:53 +02:00
bool enableHkSets = false;
2022-05-03 11:33:07 +02:00
const char* currentClientBuf = nullptr;
ReadModes readMode = ReadModes::SOCKET;
2022-03-03 10:12:59 +01:00
Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000);
Countdown gainedNewFix = Countdown(60 * 2 * 1000);
uint32_t fixChangeCounter = 0;
2023-02-07 10:03:51 +01:00
bool timeInit = false;
2023-02-26 18:21:05 +01:00
uint8_t satNotSetCounter = 0;
2023-02-14 11:18:51 +01:00
#if OBSW_THREAD_TRACING == 1
uint32_t opCounter = 0;
#endif
struct OneShotSwitches {
void reset() {
gpsReadFailedSwitch = true;
cantGetFixSwitch = true;
}
bool gpsReadFailedSwitch = true;
bool cantGetFixSwitch = true;
} oneShotSwitches;
2022-01-26 17:59:31 +01:00
bool debugHyperionGps = false;
2023-02-06 10:30:17 +01:00
// Returns true if the function should be called again or false if other
// controller handling can be done.
2023-02-06 10:20:22 +01:00
bool readGpsDataFromGpsd();
2023-02-07 10:03:51 +01:00
// If the time is totally wrong (e.g. year 2000 after system reset because we do not have a RTC)
// we set it with the roughly valid time from the GPS. For some reason, NTP might only work
// if the time difference between sys time and current time is not too large
void overwriteTimeIfNotSane(timeval time, bool validFix);
void handleFixChangedEvent(uint8_t newFix);
2022-01-26 17:59:31 +01:00
};
#endif /* MISSION_DEVICES_GPSHYPERIONHANDLER_H_ */