Skip to content

Commit ef4a10a

Browse files
Apps247Jng468lross03adambrett40
authored
User/Apps247/764-check-iridium-connection-strength (#797)
* ros service set up and potentially working * Changed ros service to use debugSend function * Changed ros service to use debugSendAT * Add ros user to dialout group in container * Separated debug_send_data ros service from regular send_data. Also added ros parameter debug_data_to_send to set the data to send. Untested. * Commented out \r character check * Switched from cout/cerr to ros logging in debugSendAT * Clear incoming serial buffer before attempting send or debugSendAT * Added skeleton for clearSerialBuffer * Fixed clearSerialBuffer * Added clearSerialBuffer calls to send() * Commented out temporary logging * Cleaned code * Changed cout calls to logging callbacks so they can show on ros2 logs * Remove sudo * Remove commented-out AT::Line Removed commented-out code for AT::Line('\r') in rcvRsps calls. * Added virtual iridium test terminal (dev tool) * Added checkIridiumSignalQuality function * Added ROS service to check signal quality * Added test for checkIridiumSignalQuality * Made sailbot_db connection failure non-blocking for other project tests * Added signal quality checking before attempting to send * Switched to INFO ros logging * Fixed serial read timeout not working * Increased timeout, raised signal threshold Co-authored-by: Apps247 <aprameyaithal@gmail.com> * Added constant * Added debugSendAT() Tested Fixes to send() * shorten comment line to pass linter * fix comment to pass linter again --------- Co-authored-by: Jing <128339540+Jng468@users.noreply.github.com> Co-authored-by: lross03 <136214176+lross03@users.noreply.github.com> Co-authored-by: adambrett40 <adambrett40@gmail.com>
1 parent ff17891 commit ef4a10a

File tree

13 files changed

+682
-22
lines changed

13 files changed

+682
-22
lines changed

.devcontainer/docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ services:
88
network_mode: host
99
privileged: true
1010
user: ros
11+
group_add:
12+
- dialout
13+
devices:
14+
- /dev/ttyS0:/dev/ttyS0
1115
# ports:
1216
# website
1317
#### We do not use anymore. We pulled website development out of docker in PR #614

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if [[ "$PACKAGE" == "network_systems" || "$PACKAGE" == "" ]]; then
4848

4949
NET_DIR=src/network_systems
5050
if [ -d $NET_DIR ]; then
51-
./scripts/run_virtual_iridium.sh &> /dev/null &
51+
./scripts/run_virtual_iridium.sh &> /tmp/virtual_iridium.log &
5252
pushd $NET_DIR
5353
./scripts/sailbot_db sailbot_db --clear
5454
./scripts/sailbot_db sailbot_db --populate

src/network_systems/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(ROS_DEPS
3535
rclcpp
3636
std_msgs
3737
custom_interfaces
38+
std_srvs
3839
)
3940
find_package(ament_cmake REQUIRED)
4041
foreach(dep IN LISTS ROS_DEPS)

src/network_systems/lib/cmn_hdrs/shared_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace SYSTEM_MODE
1616
{
1717
static const std::string PROD = "production";
1818
static const std::string DEV = "development";
19+
static const std::string TEST_SAT = "test_satellite";
1920
}; // namespace SYSTEM_MODE
2021

2122
constexpr unsigned int MAX_LOCAL_TO_REMOTE_PAYLOAD_SIZE_BYTES = 340;

src/network_systems/lib/sailbot_db/src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ int main(int argc, char ** argv)
9292

9393
if (!db.testConnection()) {
9494
std::cerr << "Failed to establish connection to DB \"" << db_name << "\"" << std::endl;
95-
return -1;
95+
// Return 0 so test script continues running other tests
96+
return 0;
9697
}
9798

9899
if (vm.count(to_string(CLIOpt::Clear)) != 0) {

src/network_systems/projects/local_transceiver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(module local_transceiver)
22

33
set(link_libs
44
${PROTOBUF_LINK_LIBS}
5+
CURL::libcurl
56
)
67

78
set(inc_dirs

src/network_systems/projects/local_transceiver/inc/at_cmds.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ namespace AT
1414
const std::string DELIMITER = "\r\n";
1515
const std::string STATUS_OK = "OK";
1616
const std::string RSP_READY = "READY";
17+
const std::string CSQ = "READY";
1718
const std::string GARBAGE = "\n";
1819

19-
const std::string CHECK_CONN = "AT";
20-
const std::string SBD_SESSION = "AT+SBDIX"; // 5.144
21-
const std::string DSBL_CTRLFLOW = "AT&K0";
22-
const std::string DNLD_TO_QUEUE = "AT+SBDRB";
20+
const std::string CHECK_CONN = "AT";
21+
const std::string SBD_SESSION = "AT+SBDIX"; // 5.144
22+
const std::string DSBL_CTRLFLOW = "AT&K0";
23+
const std::string DNLD_TO_QUEUE = "AT+SBDRB";
24+
const std::string CHECK_SIG_QUALITY = "AT+CSQ";
2325

2426
namespace write_bin // 5.154
2527
{
@@ -34,6 +36,16 @@ const std::string WRONG_SIZE = "3";
3436
} // namespace rsp
3537
} // namespace write_bin
3638

39+
namespace signal_quality
40+
{
41+
const int NOSIGNAL = 0;
42+
const int POOR = 1;
43+
const int MARGINAL = 2;
44+
const int GOOD = 3;
45+
const int VERYGOOD = 4;
46+
const int EXCELLENT = 5;
47+
} // namespace signal_quality
48+
3749
/**
3850
* @brief Simple Line struct to help enforce DRY when dealing with strings while performing reads and writes
3951
*

src/network_systems/projects/local_transceiver/inc/local_transceiver.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <boost/asio/streambuf.hpp>
4+
#include <functional>
45
#include <string>
56

67
#include "at_cmds.h"
@@ -29,6 +30,17 @@ class LocalTransceiver
2930
friend class TestLocalTransceiver_checkCache_Test;
3031

3132
public:
33+
// Logging callback types
34+
using LogCallback = std::function<void(const std::string &)>;
35+
36+
/**
37+
* @brief Set logging callbacks for debug and error messages
38+
*
39+
* @param debug_cb Callback for debug messages
40+
* @param error_cb Callback for error messages
41+
*/
42+
void setLogCallbacks(LogCallback debug_cb, LogCallback error_cb);
43+
3244
/**
3345
* @brief Update the sensor with new GPS data
3446
*
@@ -104,6 +116,23 @@ class LocalTransceiver
104116
*/
105117
bool send();
106118

119+
/**
120+
* @brief Debug helper that sends a small payload through the same
121+
* flow used by `send()` but using the provided bytes. Useful for
122+
* testing without serializing the full sensors protobuf.
123+
* ticket #714
124+
*
125+
* @param data payload to send
126+
* @return true on success, false on failure
127+
*/
128+
bool debugSendAT(const std::string & data);
129+
130+
/**
131+
* @brief Checks Iridium satellite connection strength via AT+CSQ
132+
* @return signal strength value from 0-5, or -1 if an error occurs
133+
*/
134+
int checkIridiumSignalQuality();
135+
107136
/**
108137
* @brief Send a debug command and return the output
109138
*
@@ -139,17 +168,27 @@ class LocalTransceiver
139168

140169
private:
141170
// Serial port read/write timeout
171+
// * This 'TIMEOUT' timeout is used for the socket - it doesn't work with the actual hardware modem
142172
constexpr static const struct timeval TIMEOUT
143173
{
144174
0, // seconds
145175
200000 // microseconds
146176
};
177+
// * This 'SERIAL_TIMEOUT' timeout actually works for the serial port, both on hardware and virtual
178+
static constexpr std::chrono::milliseconds SERIAL_TIMEOUT{std::chrono::seconds(15)};
179+
180+
static constexpr std::chrono::seconds SMALL_WAIT{std::chrono::seconds(2)};
181+
static constexpr std::chrono::seconds MEDIUM_WAIT{std::chrono::seconds(2)};
182+
147183
// boost io service - required for boost::asio operations
148184
boost::asio::io_service io_;
149185
// serial port data where is sent and received
150186
boost::asio::serial_port serial_;
151187
// underlying sensors object
152188
Polaris::Sensors sensors_;
189+
// Logging callbacks
190+
LogCallback log_debug_;
191+
LogCallback log_error_;
153192

154193
/**
155194
* @brief Send a command to the serial port
@@ -170,6 +209,13 @@ class LocalTransceiver
170209

171210
std::optional<std::string> readRsp();
172211

212+
/**
213+
* @brief Drain/clear any pending data in the serial buffer to remove stale data
214+
* from previous iterations or operations. This helps prevent stale data from one attempt/operation
215+
* from interfering with subsequent reads.
216+
*/
217+
void clearSerialBuffer();
218+
173219
/**
174220
* @brief Parse the message received from the remote server
175221
*
@@ -197,4 +243,7 @@ class LocalTransceiver
197243
* @return checksum value
198244
*/
199245
static std::string checksum(const std::string & data);
246+
247+
template <typename AsyncReadOp>
248+
bool runWithTimeout(AsyncReadOp && op, boost::system::error_code & out_ec);
200249
};

0 commit comments

Comments
 (0)