From 074e2d8517af6aa7db24c18062c77cf1820b21d8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Apr 2022 16:05:40 +0200 Subject: [PATCH 01/10] update cp script --- scripts/q7s-cp.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/q7s-cp.py b/scripts/q7s-cp.py index 9bc18201..c9680b0d 100755 --- a/scripts/q7s-cp.py +++ b/scripts/q7s-cp.py @@ -11,16 +11,27 @@ def main(): print(f"Running command: {cmd}") result = os.system(cmd) if result != 0: - print("") - print("Removing problematic SSH key and trying again..") - remove_ssh_key_cmd = ( - 'ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "[localhost]:1535"' - ) - os.system(remove_ssh_key_cmd) + prompt_ssh_key_removal() print(f'Running command "{cmd}"') result = os.system(cmd) +def prompt_ssh_key_removal(): + do_remove_key = input("Do you want to remove problematic keys on localhost ([Y]/n)?: ") + if not do_remove_key.lower() in ["y", "yes", "1", ""]: + sys.exit(1) + port = 0 + while True: + port = input("Enter port to remove: ") + if not port.isdecimal(): + print("Invalid port detected") + else: + break + cmd = f'ssh-keygen -f "$ {{HOME}}/.ssh/known_hosts" -R "[localhost]:{port}"' + print(f"Removing problematic SSH key with command {cmd}..") + os.system(cmd) + + def handle_args(): help_string = ( "This script copies files to the Q7S as long as port forwarding is active.\n" @@ -58,8 +69,7 @@ def handle_args(): ) # Positional argument(s) parser.add_argument( - "source", help="Source files to copy or target files to copy back to host", - nargs="+" + "source", help="Source files to copy or target files to copy back to host" ) return parser.parse_args() @@ -72,10 +82,6 @@ def build_cmd(args): address = "" port_args = "" target = args.target - if args.invert and len(args.source) > 1: - print("Multiple source files not allowed for inverse copying") - sys.exit(1) - source_files = " ".join(args.source) if args.flatsat: address = "eive@flatsat.eive.absatvirt.lw" else: @@ -92,9 +98,9 @@ def build_cmd(args): else: target = args.target if args.invert: - cmd += f"{port_args} {address}:{source_files} {target}" + cmd += f"{port_args} {address}:{args.source} {target}" else: - cmd += f"{port_args} {source_files} {address}:{target}" + cmd += f"{port_args} {args.source} {address}:{target}" return cmd From 5f6a8fa37d1a774be75987b5e840c1b1da03fd52 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 2 May 2022 13:50:44 +0200 Subject: [PATCH 02/10] bugfix pcdu handler command queue reading --- mission/devices/PCDUHandler.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index 10d12cf8..260c99c2 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -100,14 +100,10 @@ void PCDUHandler::readCommandQueue() { for (result = commandQueue->receiveMessage(&command); result == RETURN_OK; result = commandQueue->receiveMessage(&command)) { - result = commandQueue->receiveMessage(&command); - if (result != RETURN_OK) { - return; - } - result = poolManager.handleHousekeepingMessage(&command); + sif::debug << "PCDUHandler: Received message" << std::endl; if (result == RETURN_OK) { - return; + continue; } } } From 2f90c3e9374f075defa2a37737ff1b25d2f1b5a3 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 2 May 2022 13:51:56 +0200 Subject: [PATCH 03/10] removed debug print --- mission/devices/PCDUHandler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mission/devices/PCDUHandler.cpp b/mission/devices/PCDUHandler.cpp index 260c99c2..8e9f1918 100644 --- a/mission/devices/PCDUHandler.cpp +++ b/mission/devices/PCDUHandler.cpp @@ -101,7 +101,6 @@ void PCDUHandler::readCommandQueue() { for (result = commandQueue->receiveMessage(&command); result == RETURN_OK; result = commandQueue->receiveMessage(&command)) { result = poolManager.handleHousekeepingMessage(&command); - sif::debug << "PCDUHandler: Received message" << std::endl; if (result == RETURN_OK) { continue; } From 10d0bf1550d57b5b5a748c86b7c068ed052edbd2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 2 May 2022 23:51:39 +0200 Subject: [PATCH 04/10] mini fix --- scripts/q7s-cp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/q7s-cp.py b/scripts/q7s-cp.py index c9680b0d..a189e3e6 100755 --- a/scripts/q7s-cp.py +++ b/scripts/q7s-cp.py @@ -27,7 +27,7 @@ def prompt_ssh_key_removal(): print("Invalid port detected") else: break - cmd = f'ssh-keygen -f "$ {{HOME}}/.ssh/known_hosts" -R "[localhost]:{port}"' + cmd = f'ssh-keygen -f "${{HOME}}/.ssh/known_hosts" -R "[localhost]:${port}"' print(f"Removing problematic SSH key with command {cmd}..") os.system(cmd) From c1d754d8ffaefadd17f7e4c6779f6adcbc4edf1c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 2 May 2022 23:52:53 +0200 Subject: [PATCH 05/10] gps improvements --- fsfw | 2 +- linux/devices/GPSHyperionLinuxController.cpp | 65 ++++++++++---------- linux/devices/GPSHyperionLinuxController.h | 1 + tmtc | 2 +- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/fsfw b/fsfw index d61fe7db..7f6c8b8b 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit d61fe7db93b37dd6652dbfee5b7c93f400ac5a11 +Subproject commit 7f6c8b8b123a63546de0d73f0de35900d6c806bf diff --git a/linux/devices/GPSHyperionLinuxController.cpp b/linux/devices/GPSHyperionLinuxController.cpp index 5a7d9808..1c740f58 100644 --- a/linux/devices/GPSHyperionLinuxController.cpp +++ b/linux/devices/GPSHyperionLinuxController.cpp @@ -107,6 +107,7 @@ 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 @@ -125,45 +126,45 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { } // Stopwatch watch; gps_data_t *gps = nullptr; - gps = gpsmm.stream(WATCH_ENABLE | WATCH_JSON); + gpsmm.stream(WATCH_ENABLE | WATCH_JSON); + if(not gpsmm.waiting(50000000)) { + return; + } + gps = gpsmm.read(); if (gps == nullptr) { - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd:: Setting GPSD watch " - "policy failed" - << std::endl; - } - while (gpsmm.waiting(2000)) { - gps = gpsmm.read(); - if (gps == nullptr) { - if (gpsReadFailedSwitch) { - gpsReadFailedSwitch = false; - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: 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 << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be " - "read for 10 consecutive reads" - << std::endl; - noModeSetCntr = -1; - } - return; - } else { - noModeSetCntr = 0; + if (gpsReadFailedSwitch) { + gpsReadFailedSwitch = false; + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed" + << std::endl; } + return; } - gps = gpsmm.stream(WATCH_DISABLE); + if (MODE_SET != (MODE_SET & gps->set)) { + if (noModeSetCntr >= 0) { + noModeSetCntr++; + } + if (noModeSetCntr == 10) { + // TODO: Trigger event here + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be " + "read for 10 consecutive reads" + << std::endl; + noModeSetCntr = -1; + } + return; + } else { + noModeSetCntr = 0; + } + handleGpsRead(gps); +} + + +ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t* gps) { 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; @@ -292,5 +293,7 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { std::tm tm = *std::gmtime(&t); std::cout << "C Time: " << std::put_time(&tm, "%c") << std::endl; } + return RETURN_OK; } + #endif diff --git a/linux/devices/GPSHyperionLinuxController.h b/linux/devices/GPSHyperionLinuxController.h index 8d0ec0cd..bb9eef09 100644 --- a/linux/devices/GPSHyperionLinuxController.h +++ b/linux/devices/GPSHyperionLinuxController.h @@ -47,6 +47,7 @@ class GPSHyperionLinuxController : public ExtendedControllerBase { ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; + ReturnValue_t handleGpsRead(gps_data_t* gps); private: GpsPrimaryDataset gpsSet; Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000); diff --git a/tmtc b/tmtc index 168b6622..0a47c17f 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 168b662288175f9db77a5796a02f38cb66911092 +Subproject commit 0a47c17fa699dc571d2d3e63ec08c9f4cf513f65 From cce0d5448dc14f7873d2ea97413fa6fd39377c53 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 May 2022 00:55:01 +0200 Subject: [PATCH 06/10] support both SHM and socket read --- bsp_q7s/boardtest/Q7STestTask.cpp | 104 +++++++++++++++++-- bsp_q7s/boardtest/Q7STestTask.h | 11 +- linux/devices/GPSHyperionLinuxController.cpp | 85 +++++++++------ linux/devices/GPSHyperionLinuxController.h | 4 + 4 files changed, 161 insertions(+), 43 deletions(-) diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp index c3eb37ca..847c3fa5 100644 --- a/bsp_q7s/boardtest/Q7STestTask.cpp +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -23,8 +23,9 @@ Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) { doTestSdCard = false; doTestScratchApi = false; - doTestGps = false; - doTestXadc = true; + doTestGpsShm = true; + 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,90 @@ void Q7STestTask::testGpsDaemon() { sif::info << "Speed(m/s): " << gps->fix.speed << std::endl; } +void Q7STestTask::testGpsDaemonSocket() { + 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 << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | " + << "Error " << errno << " | " << gps_errstr(errno) << std::endl; +#endif + + gpsNotOpenSwitch = false; + } + return; + } + for (;;) { + struct gps_data_t* gps; + + if (!gpsmm.waiting(50000000)) continue; + + if ((gps = gpsmm.read()) == NULL) { + std::cerr << "Read error.\n"; + } else { + 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; + } + } + // // Stopwatch watch; + // gps_data_t *gps = nullptr; + // gpsmm.stream(WATCH_ENABLE | WATCH_JSON); + // if(not gpsmm.waiting(50000000)) { + // return; + // } + // gps = gpsmm.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(objects::FILE_SYSTEM_HANDLER); if (fsHandler == nullptr) { diff --git a/bsp_q7s/boardtest/Q7STestTask.h b/bsp_q7s/boardtest/Q7STestTask.h index ebef1fad..95ee3997 100644 --- a/bsp_q7s/boardtest/Q7STestTask.h +++ b/bsp_q7s/boardtest/Q7STestTask.h @@ -14,14 +14,21 @@ 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; + CoreController* coreController = nullptr; ReturnValue_t performOneShotAction() override; ReturnValue_t performPeriodicAction() override; - void testGpsDaemon(); + void testGpsDaemonShm(); + void testGpsDaemonSocket(); void testSdCard(); void fileTests(); diff --git a/linux/devices/GPSHyperionLinuxController.cpp b/linux/devices/GPSHyperionLinuxController.cpp index 1c740f58..9290ae18 100644 --- a/linux/devices/GPSHyperionLinuxController.cpp +++ b/linux/devices/GPSHyperionLinuxController.cpp @@ -109,56 +109,73 @@ 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()) { + gps_data_t *gps = nullptr; + auto openError = [&](const char *type) { if (gpsNotOpenSwitch) { // Opening failed #if FSFW_VERBOSE_LEVEL >= 1 - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM failed | " - << "Error " << errno << " | " << gps_errstr(errno) << std::endl; + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM " << type + << " failed | Error " << errno << " | " << gps_errstr(errno) << std::endl; #endif - gpsNotOpenSwitch = false; } - return; - } - // Stopwatch watch; - gps_data_t *gps = nullptr; - gpsmm.stream(WATCH_ENABLE | WATCH_JSON); - if(not gpsmm.waiting(50000000)) { - return; - } - gps = gpsmm.read(); - if (gps == nullptr) { + }; + auto readError = [&]() { if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed" - << std::endl; + << std::endl; } - return; - } - if (MODE_SET != (MODE_SET & gps->set)) { - if (noModeSetCntr >= 0) { - noModeSetCntr++; + }; + if (readMode == ReadModes::SOCKET) { + 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()) { + return openError("Socket"); } - if (noModeSetCntr == 10) { - // TODO: Trigger event here - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be " - "read for 10 consecutive reads" - << std::endl; - noModeSetCntr = -1; + // Stopwatch watch; + gpsmm.stream(WATCH_ENABLE | WATCH_JSON); + if (not gpsmm.waiting(50000000)) { + return; + } + gps = gpsmm.read(); + if (gps == nullptr) { + readError(); + return; + } + if (MODE_SET != (MODE_SET & gps->set)) { + if (noModeSetCntr >= 0) { + noModeSetCntr++; + } + if (noModeSetCntr == 10) { + // TODO: Trigger event here + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be " + "read for 10 consecutive reads" + << std::endl; + noModeSetCntr = -1; + } + return; + } else { + noModeSetCntr = 0; } - return; } else { - noModeSetCntr = 0; + gpsmm gpsmm(GPSD_SHARED_MEMORY, ""); + if (not gpsmm.is_open()) { + return openError("SHM"); + } + gps = gpsmm.read(); + if (gps == nullptr) { + readError(); + return; + } + } + if (gps != nullptr) { + handleGpsRead(gps); } - handleGpsRead(gps); } - -ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t* gps) { +ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) { PoolReadGuard pg(&gpsSet); if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 diff --git a/linux/devices/GPSHyperionLinuxController.h b/linux/devices/GPSHyperionLinuxController.h index bb9eef09..e7340c7f 100644 --- a/linux/devices/GPSHyperionLinuxController.h +++ b/linux/devices/GPSHyperionLinuxController.h @@ -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(); @@ -48,8 +50,10 @@ class GPSHyperionLinuxController : public ExtendedControllerBase { LocalDataPoolManager& poolManager) override; ReturnValue_t handleGpsRead(gps_data_t* gps); + private: GpsPrimaryDataset gpsSet; + ReadModes readMode = ReadModes::SHM; Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000); bool modeCommanded = true; bool timeInit = true; From 456dac6afdaca057935ff986a2dae65c4d0bafb5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 May 2022 11:33:07 +0200 Subject: [PATCH 07/10] SHM and socket readout working now --- CHANGELOG.md | 5 +- linux/devices/GPSHyperionLinuxController.cpp | 141 ++++++++++--------- linux/devices/GPSHyperionLinuxController.h | 6 +- 3 files changed, 78 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde62562..78f6f248 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,9 @@ list yields a list of all related PRs for each release. ## 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 +26,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] diff --git a/linux/devices/GPSHyperionLinuxController.cpp b/linux/devices/GPSHyperionLinuxController.cpp index 9290ae18..dee3c9af 100644 --- a/linux/devices/GPSHyperionLinuxController.cpp +++ b/linux/devices/GPSHyperionLinuxController.cpp @@ -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; } @@ -109,42 +133,27 @@ ReturnValue_t GPSHyperionLinuxController::handleCommandMessage(CommandMessage *m #ifdef FSFW_OSAL_LINUX void GPSHyperionLinuxController::readGpsDataFromGpsd() { - gps_data_t *gps = nullptr; - auto openError = [&](const char *type) { - if (gpsNotOpenSwitch) { - // Opening failed -#if FSFW_VERBOSE_LEVEL >= 1 - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM " << type - << " failed | Error " << errno << " | " << gps_errstr(errno) << std::endl; -#endif - gpsNotOpenSwitch = false; - } - }; - auto readError = [&]() { + 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) { - 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()) { - return openError("Socket"); - } - // Stopwatch watch; - gpsmm.stream(WATCH_ENABLE | WATCH_JSON); - if (not gpsmm.waiting(50000000)) { + 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; } - gps = gpsmm.read(); - if (gps == nullptr) { - readError(); + int result = gps_read(&gps); + if (result == -1) { + readError(result); return; } - if (MODE_SET != (MODE_SET & gps->set)) { + if (MODE_SET != (MODE_SET & gps.set)) { if (noModeSetCntr >= 0) { noModeSetCntr++; } @@ -155,27 +164,19 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { << std::endl; noModeSetCntr = -1; } - return; - } else { - noModeSetCntr = 0; } - } else { - gpsmm gpsmm(GPSD_SHARED_MEMORY, ""); - if (not gpsmm.is_open()) { - return openError("SHM"); - } - gps = gpsmm.read(); - if (gps == nullptr) { - readError(); + noModeSetCntr = 0; + } else if (readMode == ReadModes::SHM) { + int result = gps_read(&gps); + if (result == -1) { + readError(result); return; } } - if (gps != nullptr) { - handleGpsRead(gps); - } + handleGpsRead(); } -ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) { +ReturnValue_t GPSHyperionLinuxController::handleGpsRead() { PoolReadGuard pg(&gpsSet); if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { #if FSFW_VERBOSE_LEVEL >= 1 @@ -187,7 +188,7 @@ ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) { bool validFix = false; static_cast(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; } @@ -195,7 +196,7 @@ ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) { 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) { @@ -204,51 +205,51 @@ ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) { 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) { @@ -289,23 +290,23 @@ ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) { 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; diff --git a/linux/devices/GPSHyperionLinuxController.h b/linux/devices/GPSHyperionLinuxController.h index e7340c7f..94e82023 100644 --- a/linux/devices/GPSHyperionLinuxController.h +++ b/linux/devices/GPSHyperionLinuxController.h @@ -49,11 +49,13 @@ class GPSHyperionLinuxController : public ExtendedControllerBase { ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; - ReturnValue_t handleGpsRead(gps_data_t* gps); + ReturnValue_t handleGpsRead(); private: GpsPrimaryDataset gpsSet; - ReadModes readMode = ReadModes::SHM; + 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; From 08d7b3b859d821d5fe79536f12553885ee1f2b2b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 May 2022 11:34:47 +0200 Subject: [PATCH 08/10] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f6f248..74d88604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ 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 From c131c685a42b1e60fb2fba5654fdaa76130be3dc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 May 2022 11:39:12 +0200 Subject: [PATCH 09/10] fix test task --- bsp_q7s/boardtest/Q7STestTask.cpp | 335 ++++++++++++++---------------- bsp_q7s/boardtest/Q7STestTask.h | 2 + 2 files changed, 159 insertions(+), 178 deletions(-) diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp index 847c3fa5..a9721619 100644 --- a/bsp_q7s/boardtest/Q7STestTask.cpp +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -23,7 +23,7 @@ Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) { doTestSdCard = false; doTestScratchApi = false; - doTestGpsShm = true; + doTestGpsShm = false; doTestGpsSocket = false; doTestXadc = false; } @@ -156,13 +156,13 @@ void Q7STestTask::testDummyParams() { result = param.getValue(DummyParameter::DUMMY_KEY_PARAM_1, test); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 - << " does not exist" << std::endl; + << " does not exist" << std::endl; } std::string test2; result = param.getValue(DummyParameter::DUMMY_KEY_PARAM_2, test2); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 - << " does not exist" << std::endl; + << " does not exist" << std::endl; } sif::info << "Test value (3 expected): " << test << std::endl; sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl; @@ -172,7 +172,7 @@ ReturnValue_t Q7STestTask::initialize() { coreController = ObjectManager::instance()->get(objects::CORE_CONTROLLER); if (coreController == nullptr) { sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object" - << std::endl; + << std::endl; } return TestTask::initialize(); } @@ -182,14 +182,14 @@ void Q7STestTask::testProtHandler() { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; // If any chips are unlocked, lock them here result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } // unlock own copy result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -203,7 +203,7 @@ void Q7STestTask::testProtHandler() { // lock own copy result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -217,7 +217,7 @@ void Q7STestTask::testProtHandler() { // unlock specific copy result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -231,7 +231,7 @@ void Q7STestTask::testProtHandler() { // lock specific copy result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -273,94 +273,73 @@ void Q7STestTask::testGpsDaemonShm() { } void Q7STestTask::testGpsDaemonSocket() { - gpsmm gpsmm("localhost", DEFAULT_GPSD_PORT); + if(gpsmmPtr == nullptr) { + gpsmmPtr = 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 gpsmm.is_open()) { + if (not gpsmmPtr->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; + << "Error " << errno << " | " << gps_errstr(errno) << std::endl; #endif gpsNotOpenSwitch = false; } return; } - for (;;) { - struct gps_data_t* gps; - - if (!gpsmm.waiting(50000000)) continue; - - if ((gps = gpsmm.read()) == NULL) { - std::cerr << "Read error.\n"; - } else { - 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; - } + // Stopwatch watch; + gps_data_t *gps = nullptr; + gpsmmPtr->stream(WATCH_ENABLE | WATCH_JSON); + if(not gpsmmPtr->waiting(50000000)) { + return; } - // // Stopwatch watch; - // gps_data_t *gps = nullptr; - // gpsmm.stream(WATCH_ENABLE | WATCH_JSON); - // if(not gpsmm.waiting(50000000)) { - // return; - // } - // gps = gpsmm.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; + gps = gpsmmPtr->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(objects::FILE_SYSTEM_HANDLER); if (fsHandler == nullptr) { sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.." - << std::endl; + << std::endl; } FileSystemHandler::FsCommandCfg cfg = {}; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; @@ -387,115 +366,115 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) { }; switch (opCode) { - case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - sif::info << "Creating empty file in /tmp folder" << std::endl; - // Do not delete file, user can check existence in shell + case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + sif::info << "Creating empty file in /tmp folder" << std::endl; + // Do not delete file, user can check existence in shell + fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + break; + } + case (FsOpCodes::REMOVE_TMP_FILE): { + sif::info << "Deleting /tmp/test.txt sample file" << std::endl; + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (not std::filesystem::exists("/tmp/test.txt")) { + // Creating sample file + sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl; fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - break; } - case (FsOpCodes::REMOVE_TMP_FILE): { - sif::info << "Deleting /tmp/test.txt sample file" << std::endl; - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (not std::filesystem::exists("/tmp/test.txt")) { - // Creating sample file - sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl; - fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - } - result = fsHandler->removeFile("/tmp", "test.txt", &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "File removed successfully" << std::endl; - } else { - sif::warning << "File removal failed!" << std::endl; - } - break; + result = fsHandler->removeFile("/tmp", "test.txt", &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "File removed successfully" << std::endl; + } else { + sif::warning << "File removal failed!" << std::endl; } - case (FsOpCodes::CREATE_DIR_IN_TMP): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - sif::info << "Creating empty file in /tmp folder" << std::endl; - // Do not delete file, user can check existence in shell - ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory created successfully" << std::endl; - } else { - sif::warning << "Directory creation failed!" << std::endl; - } - break; + break; + } + case (FsOpCodes::CREATE_DIR_IN_TMP): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + sif::info << "Creating empty file in /tmp folder" << std::endl; + // Do not delete file, user can check existence in shell + ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory created successfully" << std::endl; + } else { + sif::warning << "Directory creation failed!" << std::endl; } - case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (not std::filesystem::exists("/tmp/test")) { - result = fsHandler->createDirectory("/tmp", "test", false, &cfg); - } else { - // Delete any leftover files to regular dir removal works - std::remove("/tmp/test/*"); - } - result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory removed successfully" << std::endl; - } else { - sif::warning << "Directory removal failed!" << std::endl; - } - break; + break; + } + case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (not std::filesystem::exists("/tmp/test")) { + result = fsHandler->createDirectory("/tmp", "test", false, &cfg); + } else { + // Delete any leftover files to regular dir removal works + std::remove("/tmp/test/*"); } - case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): { - result = createNonEmptyTmpDir(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; - } - result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory removed recursively successfully" << std::endl; - } else { - sif::warning << "Recursive directory removal failed!" << std::endl; - } - break; + result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory removed successfully" << std::endl; + } else { + sif::warning << "Directory removal failed!" << std::endl; } - case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): { - result = createNonEmptyTmpDir(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; - } - result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory removal attempt failed as expected" << std::endl; - } else { - sif::warning << "Directory removal worked when it should not have!" << std::endl; - } - break; + break; + } + case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): { + result = createNonEmptyTmpDir(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; } - case (FsOpCodes::RENAME_FILE): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (std::filesystem::exists("/tmp/test.txt")) { - fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - } - sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl; - // Do not delete file, user can check existence in shell - fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg); - break; + result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory removed recursively successfully" << std::endl; + } else { + sif::warning << "Recursive directory removal failed!" << std::endl; } - case (FsOpCodes::APPEND_TO_FILE): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (std::filesystem::exists("/tmp/test.txt")) { - fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - } - if (std::filesystem::exists("/tmp/test.txt")) { - fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - } - sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl; - std::string content = "Hello World\n"; - // Do not delete file, user can check existence in shell - fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast(content.data()), - content.size(), 0, &cfg); + break; + } + case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): { + result = createNonEmptyTmpDir(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; } + result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory removal attempt failed as expected" << std::endl; + } else { + sif::warning << "Directory removal worked when it should not have!" << std::endl; + } + break; + } + case (FsOpCodes::RENAME_FILE): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (std::filesystem::exists("/tmp/test.txt")) { + fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + } + sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl; + // Do not delete file, user can check existence in shell + fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg); + break; + } + case (FsOpCodes::APPEND_TO_FILE): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (std::filesystem::exists("/tmp/test.txt")) { + fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + } + if (std::filesystem::exists("/tmp/test.txt")) { + fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + } + sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl; + std::string content = "Hello World\n"; + // Do not delete file, user can check existence in shell + fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast(content.data()), + content.size(), 0, &cfg); + } } } diff --git a/bsp_q7s/boardtest/Q7STestTask.h b/bsp_q7s/boardtest/Q7STestTask.h index 95ee3997..f8394784 100644 --- a/bsp_q7s/boardtest/Q7STestTask.h +++ b/bsp_q7s/boardtest/Q7STestTask.h @@ -1,6 +1,7 @@ #ifndef BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ #define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ +#include #include "test/testtasks/TestTask.h" class CoreController; @@ -22,6 +23,7 @@ class Q7STestTask : public TestTask { bool gpsNotOpenSwitch = false; bool gpsReadFailedSwitch = false; int32_t noModeSetCntr = 0; + gpsmm* gpsmmPtr = nullptr; CoreController* coreController = nullptr; ReturnValue_t performOneShotAction() override; From 51bcdafe33f17df412fb96a55ac5ae85ca531b4f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 May 2022 11:39:49 +0200 Subject: [PATCH 10/10] renaming --- bsp_q7s/boardtest/Q7STestTask.cpp | 12 ++++++------ bsp_q7s/boardtest/Q7STestTask.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp index a9721619..0f6734b6 100644 --- a/bsp_q7s/boardtest/Q7STestTask.cpp +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -273,12 +273,12 @@ void Q7STestTask::testGpsDaemonShm() { } void Q7STestTask::testGpsDaemonSocket() { - if(gpsmmPtr == nullptr) { - gpsmmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT); + 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 gpsmmPtr->is_open()) { + if (not gpsmmShmPtr->is_open()) { if (gpsNotOpenSwitch) { // Opening failed #if FSFW_VERBOSE_LEVEL >= 1 @@ -292,11 +292,11 @@ void Q7STestTask::testGpsDaemonSocket() { } // Stopwatch watch; gps_data_t *gps = nullptr; - gpsmmPtr->stream(WATCH_ENABLE | WATCH_JSON); - if(not gpsmmPtr->waiting(50000000)) { + gpsmmShmPtr->stream(WATCH_ENABLE | WATCH_JSON); + if(not gpsmmShmPtr->waiting(50000000)) { return; } - gps = gpsmmPtr->read(); + gps = gpsmmShmPtr->read(); if (gps == nullptr) { if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; diff --git a/bsp_q7s/boardtest/Q7STestTask.h b/bsp_q7s/boardtest/Q7STestTask.h index f8394784..ad58889f 100644 --- a/bsp_q7s/boardtest/Q7STestTask.h +++ b/bsp_q7s/boardtest/Q7STestTask.h @@ -23,7 +23,7 @@ class Q7STestTask : public TestTask { bool gpsNotOpenSwitch = false; bool gpsReadFailedSwitch = false; int32_t noModeSetCntr = 0; - gpsmm* gpsmmPtr = nullptr; + gpsmm* gpsmmShmPtr = nullptr; CoreController* coreController = nullptr; ReturnValue_t performOneShotAction() override;