From e9f8460c51f381c5be26e7fe705a7e63eee13394 Mon Sep 17 00:00:00 2001 From: hhenry01 Date: Wed, 6 Mar 2024 20:18:39 -0800 Subject: [PATCH] temp commit to debug CI --- functions.cmake | 1 + .../src/local_transceiver.cpp | 136 +++++++++--------- .../test/test_local_transceiver.cpp | 22 ++- 3 files changed, 86 insertions(+), 73 deletions(-) diff --git a/functions.cmake b/functions.cmake index 92d0408..ef704fb 100644 --- a/functions.cmake +++ b/functions.cmake @@ -50,5 +50,6 @@ function(make_unit_test module srcs link_libs inc_dirs compile_defs) add_dependencies(${test_module} ${AUTOGEN_TARGETS}) # Make the unit test runnable with CTest (invoked via test.sh) add_test(NAME ${test_module} COMMAND ${test_module}) + set_tests_properties(${test_module} PROPERTIES TIMEOUT 60) # 1 minute per test timeout endif() endfunction() diff --git a/projects/local_transceiver/src/local_transceiver.cpp b/projects/local_transceiver/src/local_transceiver.cpp index 5bc174a..ae1087a 100644 --- a/projects/local_transceiver/src/local_transceiver.cpp +++ b/projects/local_transceiver/src/local_transceiver.cpp @@ -85,9 +85,9 @@ void LocalTransceiver::updateSensor(msg::GenericSensors msg) void LocalTransceiver::updateSensor(msg::LPathData localData) { sensors_.clear_local_path_data(); + Sensors::Path * new_local = sensors_.mutable_local_path_data(); for (const msg::HelperLatLon & local_data : localData.local_path.waypoints) { - Sensors::Path * new_local = sensors_.mutable_local_path_data(); - Polaris::Waypoint * waypoint = new_local->add_waypoints(); + Polaris::Waypoint * waypoint = new_local->add_waypoints(); waypoint->set_latitude(local_data.latitude); waypoint->set_longitude(local_data.longitude); } @@ -135,74 +135,74 @@ bool LocalTransceiver::send() throw std::length_error(err_string); } - std::string write_bin_cmd_str = AT::write_bin::CMD + std::to_string(data.size()); //according to specs + std::string write_bin_cmd_str = AT::write_bin::CMD + std::to_string(data.size()); //according to specs AT::Line at_write_cmd(write_bin_cmd_str); - static constexpr int MAX_NUM_RETRIES = 20; // allow retries because the connection is imperfect - for (int i = 0; i < MAX_NUM_RETRIES; i++) { - if (!send(at_write_cmd)) { - continue; - } - - if (!rcvRsps({ - at_write_cmd, - AT::Line(AT::DELIMITER), - AT::Line(AT::RSP_READY), - AT::Line("\n"), - })) { - continue; - } - - std::string msg_str = data + checksum(data); - AT::Line msg(msg_str); - if (!send(msg)) { - continue; - } - - if (!rcvRsps({ - AT::Line(AT::DELIMITER), - AT::Line(AT::write_bin::rsp::SUCCESS), - AT::Line("\n"), - AT::Line(AT::DELIMITER), - AT::Line(AT::STATUS_OK), - AT::Line("\n"), - })) { - continue; - } - - // Check SBD Session status to see if data was sent successfully - // NEEDS AN ACTIVE SERVER ON $WEBHOOK_SERVER_ENDPOINT OR VIRTUAL IRIDIUM WILL CRASH - static const AT::Line sbdix_cmd = AT::Line(AT::SBD_SESSION); - if (!send(sbdix_cmd)) { - continue; - } - - if (!rcvRsps({ - AT::Line("\r"), - sbdix_cmd, - AT::Line(AT::DELIMITER), - })) { - continue; - } - - auto opt_rsp = readRsp(); - if (!opt_rsp) { - continue; - } - - // This string will look something like: - // "+SBDIX:,,,,,\r\n\r\nOK\r" - // on success - // Don't bother to check for OK\r as MO status will tell us if it succeeded or not - std::string opt_rsp_val = opt_rsp.value(); - std::vector sbd_status_vec; - boost::algorithm::split(sbd_status_vec, opt_rsp_val, boost::is_any_of(AT::DELIMITER)); - - AT::SBDStatusRsp rsp(sbd_status_vec[0]); - if (rsp.MOSuccess()) { - return true; - } - } + // static constexpr int MAX_NUM_RETRIES = 20; // allow retries because the connection is imperfect + // for (int i = 0; i < MAX_NUM_RETRIES; i++) { + // if (!send(at_write_cmd)) { + // continue; + // } + + // if (!rcvRsps({ + // at_write_cmd, + // AT::Line(AT::DELIMITER), + // AT::Line(AT::RSP_READY), + // AT::Line("\n"), + // })) { + // continue; + // } + + // std::string msg_str = data + checksum(data); + // AT::Line msg(msg_str); + // if (!send(msg)) { + // continue; + // } + + // if (!rcvRsps({ + // AT::Line(AT::DELIMITER), + // AT::Line(AT::write_bin::rsp::SUCCESS), + // AT::Line("\n"), + // AT::Line(AT::DELIMITER), + // AT::Line(AT::STATUS_OK), + // AT::Line("\n"), + // })) { + // continue; + // } + + // // Check SBD Session status to see if data was sent successfully + // // NEEDS AN ACTIVE SERVER ON $WEBHOOK_SERVER_ENDPOINT OR VIRTUAL IRIDIUM WILL CRASH + // static const AT::Line sbdix_cmd = AT::Line(AT::SBD_SESSION); + // if (!send(sbdix_cmd)) { + // continue; + // } + + // if (!rcvRsps({ + // AT::Line("\r"), + // sbdix_cmd, + // AT::Line(AT::DELIMITER), + // })) { + // continue; + // } + + // auto opt_rsp = readRsp(); + // if (!opt_rsp) { + // continue; + // } + + // // This string will look something like: + // // "+SBDIX:,,,,,\r\n\r\nOK\r" + // // on success + // // Don't bother to check for OK\r as MO status will tell us if it succeeded or not + // std::string opt_rsp_val = opt_rsp.value(); + // std::vector sbd_status_vec; + // boost::algorithm::split(sbd_status_vec, opt_rsp_val, boost::is_any_of(AT::DELIMITER)); + + // AT::SBDStatusRsp rsp(sbd_status_vec[0]); + // if (rsp.MOSuccess()) { + // return true; + // } + // } std::cerr << "Failed to transmit data to satellite!" << std::endl; std::cerr << sensors.DebugString() << std::endl; return false; diff --git a/projects/local_transceiver/test/test_local_transceiver.cpp b/projects/local_transceiver/test/test_local_transceiver.cpp index c3b0002..c7c07ff 100644 --- a/projects/local_transceiver/test/test_local_transceiver.cpp +++ b/projects/local_transceiver/test/test_local_transceiver.cpp @@ -36,15 +36,25 @@ class TestLocalTransceiver : public ::testing::Test protected: static void SetUpTestSuite() { http_echo_server_proc_ = bp::child(RUN_HTTP_ECHO_SERVER_CMD); } - static void TearDownTestSuite() { http_echo_server_proc_.terminate(); } + static void TearDownTestSuite() + { + std::error_code e; + http_echo_server_proc_.terminate(e); + if (e) { + throw std::runtime_error("Failed to terminate HTTP Echo Server! " + e.message()); + } + } TestLocalTransceiver() { try { lcl_trns_ = new LocalTransceiver(LOCAL_TRANSCEIVER_TEST_PORT, SATELLITE_BAUD_RATE); - } catch (boost::system::system_error & /**/) { - std::cerr << "Failed to create Local Transceiver for tests, is only one instance of: \"" - << RUN_VIRTUAL_IRIDIUM_SCRIPT_PATH << "\" running?" << std::endl; + } catch (boost::system::system_error & e) { + std::stringstream ss; + ss << "Failed to create Local Transceiver for tests, is only one instance of: \"" + << RUN_VIRTUAL_IRIDIUM_SCRIPT_PATH << "\" running?" << std::endl; + ss << e.what() << std::endl; + throw std::runtime_error(ss.str()); } } ~TestLocalTransceiver() override @@ -162,5 +172,7 @@ TEST_F(TestLocalTransceiver, sendData) lcl_trns_->updateSensor(batteries); lcl_trns_->updateSensor(sensors); lcl_trns_->updateSensor(local_paths); - lcl_trns_->send(); + + std::cout << "Sending data" << std::endl; + EXPECT_TRUE(lcl_trns_->send()); }