Merge pull request 'GPS controller update' (#239) from mueller/gps-tests into develop
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

Reviewed-on: #239
Reviewed-by: Jakob.Meier <meierj@irs.uni-stuttgart.de>
This commit is contained in:
Jakob Meier 2022-05-03 13:41:30 +02:00
commit e088bec582
7 changed files with 296 additions and 185 deletions

View File

@ -13,12 +13,15 @@ list yields a list of all related PRs for each release.
# [v1.11.0]
## Fixed
- Host build working again
## Added
- Custom Gomspace FDIR which disabled most of the default FDIR functionality
- Custom Syrlinks FDIR which disabled most of the default FDIR functionality
## Changed
- PCDU handler only called once in PST, but can handle multiple messages now
@ -27,6 +30,8 @@ list yields a list of all related PRs for each release.
- Add `/usr/local/bin` to PATH. All shell scripts are there now
- Rename GPS device to `/dev/gps0`
- Add Syrlinks and TMP devices to Software by default
- Update GPS Linux Hyperion Handler to use socket interface. Still allows switching
back to SHM interface, but the SHM interface is a possible cause of SW crashes
# [v1.10.1]

View File

@ -23,8 +23,9 @@
Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) {
doTestSdCard = false;
doTestScratchApi = false;
doTestGps = false;
doTestXadc = true;
doTestGpsShm = false;
doTestGpsSocket = false;
doTestXadc = false;
}
ReturnValue_t Q7STestTask::performOneShotAction() {
@ -36,15 +37,20 @@ ReturnValue_t Q7STestTask::performOneShotAction() {
}
// testJsonLibDirect();
// testDummyParams();
// testProtHandler();
if (doTestProtHandler) {
testProtHandler();
}
FsOpCodes opCode = FsOpCodes::APPEND_TO_FILE;
testFileSystemHandlerDirect(opCode);
return TestTask::performOneShotAction();
}
ReturnValue_t Q7STestTask::performPeriodicAction() {
if (doTestGps) {
testGpsDaemon();
if (doTestGpsShm) {
testGpsDaemonShm();
}
if (doTestGpsSocket) {
testGpsDaemonSocket();
}
if (doTestXadc) {
xadcTest();
@ -238,8 +244,8 @@ void Q7STestTask::testProtHandler() {
}
}
void Q7STestTask::testGpsDaemon() {
gpsmm gpsmm(GPSD_SHARED_MEMORY, 0);
void Q7STestTask::testGpsDaemonShm() {
gpsmm gpsmm(GPSD_SHARED_MEMORY, "");
gps_data_t* gps;
gps = gpsmm.read();
if (gps == nullptr) {
@ -266,6 +272,69 @@ void Q7STestTask::testGpsDaemon() {
sif::info << "Speed(m/s): " << gps->fix.speed << std::endl;
}
void Q7STestTask::testGpsDaemonSocket() {
if(gpsmmShmPtr == nullptr) {
gpsmmShmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT);
}
// The data from the device will generally be read all at once. Therefore, we
// can set all field here
if (not gpsmmShmPtr->is_open()) {
if (gpsNotOpenSwitch) {
// Opening failed
#if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | "
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl;
#endif
gpsNotOpenSwitch = false;
}
return;
}
// Stopwatch watch;
gps_data_t *gps = nullptr;
gpsmmShmPtr->stream(WATCH_ENABLE | WATCH_JSON);
if(not gpsmmShmPtr->waiting(50000000)) {
return;
}
gps = gpsmmShmPtr->read();
if (gps == nullptr) {
if (gpsReadFailedSwitch) {
gpsReadFailedSwitch = false;
sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed"
<< std::endl;
}
return;
}
if (MODE_SET != (MODE_SET & gps->set)) {
if (noModeSetCntr >= 0) {
noModeSetCntr++;
}
if (noModeSetCntr == 10) {
// TODO: Trigger event here
sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be "
"read for 10 consecutive reads"
<< std::endl;
noModeSetCntr = -1;
}
return;
} else {
noModeSetCntr = 0;
}
sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl;
#if LIBGPS_VERSION_MINOR <= 17
time_t timeRaw = gps->fix.time;
#else
time_t timeRaw = gps->fix.time.tv_sec;
#endif
std::tm* time = gmtime(&timeRaw);
sif::info << "Time: " << std::put_time(time, "%c %Z") << std::endl;
sif::info << "Visible satellites: " << gps->satellites_visible << std::endl;
sif::info << "Satellites used: " << gps->satellites_used << std::endl;
sif::info << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
sif::info << "Latitude: " << gps->fix.latitude << std::endl;
sif::info << "Longitude: " << gps->fix.longitude << std::endl;
}
void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
if (fsHandler == nullptr) {

View File

@ -1,6 +1,7 @@
#ifndef BSP_Q7S_BOARDTEST_Q7STESTTASK_H_
#define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_
#include <libgpsmm.h>
#include "test/testtasks/TestTask.h"
class CoreController;
@ -14,14 +15,22 @@ class Q7STestTask : public TestTask {
private:
bool doTestSdCard = false;
bool doTestScratchApi = false;
bool doTestGps = false;
bool doTestGpsShm = false;
bool doTestGpsSocket = false;
bool doTestProtHandler = false;
bool doTestXadc = false;
bool gpsNotOpenSwitch = false;
bool gpsReadFailedSwitch = false;
int32_t noModeSetCntr = 0;
gpsmm* gpsmmShmPtr = nullptr;
CoreController* coreController = nullptr;
ReturnValue_t performOneShotAction() override;
ReturnValue_t performPeriodicAction() override;
void testGpsDaemon();
void testGpsDaemonShm();
void testGpsDaemonSocket();
void testSdCard();
void fileTests();

2
fsfw

@ -1 +1 @@
Subproject commit d61fe7db93b37dd6652dbfee5b7c93f400ac5a11
Subproject commit 7f6c8b8b123a63546de0d73f0de35900d6c806bf

View File

@ -24,7 +24,10 @@ GPSHyperionLinuxController::GPSHyperionLinuxController(object_id_t objectId, obj
timeUpdateCd.resetTimer();
}
GPSHyperionLinuxController::~GPSHyperionLinuxController() {}
GPSHyperionLinuxController::~GPSHyperionLinuxController() {
gps_stream(&gps, WATCH_DISABLE, nullptr);
gps_close(&gps);
}
void GPSHyperionLinuxController::performControlOperation() {
#ifdef FSFW_OSAL_LINUX
@ -99,6 +102,27 @@ ReturnValue_t GPSHyperionLinuxController::initialize() {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
auto openError = [&](const char *type, int error) {
if (gpsNotOpenSwitch) {
// Opening failed
#if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM " << type
<< " failed | Error " << error << " | " << gps_errstr(error) << std::endl;
#endif
gpsNotOpenSwitch = false;
}
};
if (readMode == ReadModes::SOCKET) {
int retval = gps_open("localhost", DEFAULT_GPSD_PORT, &gps);
if (retval != 0) {
openError("Socket", retval);
}
} else if (readMode == ReadModes::SHM) {
int retval = gps_open(GPSD_SHARED_MEMORY, "", &gps);
if (retval != 0) {
openError("SHM", retval);
}
}
return result;
}
@ -107,41 +131,29 @@ ReturnValue_t GPSHyperionLinuxController::handleCommandMessage(CommandMessage *m
}
#ifdef FSFW_OSAL_LINUX
void GPSHyperionLinuxController::readGpsDataFromGpsd() {
gpsmm gpsmm("localhost", DEFAULT_GPSD_PORT);
// The data from the device will generally be read all at once. Therefore, we
// can set all field here
if (not gpsmm.is_open()) {
if (gpsNotOpenSwitch) {
// Opening failed
#if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM failed | "
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl;
#endif
gpsNotOpenSwitch = false;
}
return;
}
// Stopwatch watch;
gps_data_t *gps = nullptr;
gps = gpsmm.stream(WATCH_ENABLE | WATCH_JSON);
if (gps == nullptr) {
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd:: Setting GPSD watch "
"policy failed"
<< std::endl;
}
while (gpsmm.waiting(2000)) {
gps = gpsmm.read();
if (gps == nullptr) {
void GPSHyperionLinuxController::readGpsDataFromGpsd() {
auto readError = [&](int error) {
if (gpsReadFailedSwitch) {
gpsReadFailedSwitch = false;
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed"
<< std::endl;
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed | "
"Error "
<< error << " | " << gps_errstr(error) << std::endl;
}
};
currentClientBuf = gps_data(&gps);
if (readMode == ReadModes::SOCKET) {
gps_stream(&gps, WATCH_ENABLE | WATCH_JSON, nullptr);
// Exit if no data is seen in 2 seconds (should not happen)
if (not gps_waiting(&gps, 2000000)) {
return;
}
if (MODE_SET != (MODE_SET & gps->set)) {
int result = gps_read(&gps);
if (result == -1) {
readError(result);
return;
}
if (MODE_SET != (MODE_SET & gps.set)) {
if (noModeSetCntr >= 0) {
noModeSetCntr++;
}
@ -152,24 +164,31 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() {
<< std::endl;
noModeSetCntr = -1;
}
return;
} else {
}
noModeSetCntr = 0;
} else if (readMode == ReadModes::SHM) {
int result = gps_read(&gps);
if (result == -1) {
readError(result);
return;
}
}
gps = gpsmm.stream(WATCH_DISABLE);
handleGpsRead();
}
ReturnValue_t GPSHyperionLinuxController::handleGpsRead() {
PoolReadGuard pg(&gpsSet);
if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading dataset failed" << std::endl;
#endif
return;
return RETURN_FAILED;
}
bool validFix = false;
static_cast<void>(validFix);
// 0: Not seen, 1: No fix, 2: 2D-Fix, 3: 3D-Fix
int newFixMode = gps->fix.mode;
int newFixMode = gps.fix.mode;
if (newFixMode == 2 or newFixMode == 3) {
validFix = true;
}
@ -177,7 +196,7 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() {
triggerEvent(GpsHyperion::GPS_FIX_CHANGE, gpsSet.fixMode.value, newFixMode);
}
gpsSet.fixMode.value = newFixMode;
if (gps->fix.mode == 0 or gps->fix.mode == 1) {
if (gps.fix.mode == 0 or gps.fix.mode == 1) {
if (modeCommanded and maxTimeToReachFix.hasTimedOut()) {
// We are supposed to be on and functioning, but not fix was found
if (mode == MODE_ON or mode == MODE_NORMAL) {
@ -186,51 +205,51 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() {
modeCommanded = false;
}
gpsSet.setValidity(false, true);
} else if (gps->satellites_used > 0) {
} else if (gps.satellites_used > 0) {
gpsSet.setValidity(true, true);
}
gpsSet.satInUse.value = gps->satellites_used;
gpsSet.satInView.value = gps->satellites_visible;
gpsSet.satInUse.value = gps.satellites_used;
gpsSet.satInView.value = gps.satellites_visible;
if (std::isfinite(gps->fix.latitude)) {
if (std::isfinite(gps.fix.latitude)) {
// Negative latitude -> South direction
gpsSet.latitude.value = gps->fix.latitude;
gpsSet.latitude.value = gps.fix.latitude;
} else {
gpsSet.latitude.setValid(false);
}
if (std::isfinite(gps->fix.longitude)) {
if (std::isfinite(gps.fix.longitude)) {
// Negative longitude -> West direction
gpsSet.longitude.value = gps->fix.longitude;
gpsSet.longitude.value = gps.fix.longitude;
} else {
gpsSet.longitude.setValid(false);
}
if (std::isfinite(gps->fix.altitude)) {
gpsSet.altitude.value = gps->fix.altitude;
if (std::isfinite(gps.fix.altitude)) {
gpsSet.altitude.value = gps.fix.altitude;
} else {
gpsSet.altitude.setValid(false);
}
if (std::isfinite(gps->fix.speed)) {
gpsSet.speed.value = gps->fix.speed;
if (std::isfinite(gps.fix.speed)) {
gpsSet.speed.value = gps.fix.speed;
} else {
gpsSet.speed.setValid(false);
}
#if LIBGPS_VERSION_MINOR <= 17
gpsSet.unixSeconds.value = gps->fix.time;
gpsSet.unixSeconds.value = gps.fix.time;
#else
gpsSet.unixSeconds.value = gps->fix.time.tv_sec;
gpsSet.unixSeconds.value = gps.fix.time.tv_sec;
#endif
timeval time = {};
time.tv_sec = gpsSet.unixSeconds.value;
#if LIBGPS_VERSION_MINOR <= 17
double fractionalPart = gps->fix.time - std::floor(gps->fix.time);
double fractionalPart = gps.fix.time - std::floor(gps.fix.time);
time.tv_usec = fractionalPart * 1000.0 * 1000.0;
#else
time.tv_usec = gps->fix.time.tv_nsec / 1000;
time.tv_usec = gps.fix.time.tv_nsec / 1000;
#endif
std::time_t t = std::time(nullptr);
if (time.tv_sec == t) {
@ -271,26 +290,28 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() {
if (debugHyperionGps) {
sif::info << "-- Hyperion GPS Data --" << std::endl;
#if LIBGPS_VERSION_MINOR <= 17
time_t timeRaw = gps->fix.time;
time_t timeRaw = gps.fix.time;
#else
time_t timeRaw = gps->fix.time.tv_sec;
time_t timeRaw = gps.fix.time.tv_sec;
#endif
std::tm *time = gmtime(&timeRaw);
std::cout << "Time: " << std::put_time(time, "%c %Z") << std::endl;
std::cout << "Visible satellites: " << gps->satellites_visible << std::endl;
std::cout << "Satellites used: " << gps->satellites_used << std::endl;
std::cout << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
std::cout << "Latitude: " << gps->fix.latitude << std::endl;
std::cout << "Longitude: " << gps->fix.longitude << std::endl;
std::cout << "Visible satellites: " << gps.satellites_visible << std::endl;
std::cout << "Satellites used: " << gps.satellites_used << std::endl;
std::cout << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps.fix.mode << std::endl;
std::cout << "Latitude: " << gps.fix.latitude << std::endl;
std::cout << "Longitude: " << gps.fix.longitude << std::endl;
#if LIBGPS_VERSION_MINOR <= 17
std::cout << "Altitude(MSL): " << gps->fix.altitude << std::endl;
std::cout << "Altitude(MSL): " << gps.fix.altitude << std::endl;
#else
std::cout << "Altitude(MSL): " << gps->fix.altMSL << std::endl;
std::cout << "Altitude(MSL): " << gps.fix.altMSL << std::endl;
#endif
std::cout << "Speed(m/s): " << gps->fix.speed << std::endl;
std::cout << "Speed(m/s): " << gps.fix.speed << std::endl;
std::time_t t = std::time(nullptr);
std::tm tm = *std::gmtime(&t);
std::cout << "C Time: " << std::put_time(&tm, "%c") << std::endl;
}
return RETURN_OK;
}
#endif

View File

@ -24,6 +24,8 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
public:
static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5;
enum ReadModes { SHM = 0, SOCKET = 1 };
GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId,
bool debugHyperionGps = false);
virtual ~GPSHyperionLinuxController();
@ -47,8 +49,13 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
ReturnValue_t handleGpsRead();
private:
GpsPrimaryDataset gpsSet;
gps_data_t gps = {};
const char* currentClientBuf = nullptr;
ReadModes readMode = ReadModes::SOCKET;
Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000);
bool modeCommanded = true;
bool timeInit = true;

2
tmtc

@ -1 +1 @@
Subproject commit 168b662288175f9db77a5796a02f38cb66911092
Subproject commit 0a47c17fa699dc571d2d3e63ec08c9f4cf513f65