Skip to content

Commit ea877a7

Browse files
Apps247Jng468lross03
authored
627 - Updated local transceiver to use new specific sensors (#709)
* Replaced Generic Sensors with Specific sensors in local transceiver implementation & test. Added specific sensors to Protofile * Replaced generic sensors (data sensors) functions with specific temp, pH, salinity, and pressure sensor functions * Added specific sensor tests * Fixed bug in updateSensor for temperature * Added serialization tests * Fixed Serialization tests for Temp, Salinity, Pressure, pH * Uncommented sendData for temp, pressure, salinity, pH * Changed temp, pH, salinity, pressure protobuf to use packed array of float instead of respective complex objects * Removed pressure upload in sendData test * Added logging for bytes being sent * Replaced magic numbers with constants * Added a test for checking that echo server received data correctly (Currently FAILING) * ROS2.distro auto entry * Undid comment out * Changed calls to specific data sensors * Setup specific data sensor ROS topics and MongoDB collections * Removed duplicate * Commented out pressure sensor code (as we aren't using pressure sensors anymore) * Commented out pressure sensor topics * fix docs string for updateSensor functions --------- Co-authored-by: Jing <128339540+Jng468@users.noreply.github.com> Co-authored-by: lross03 <136214176+lross03@users.noreply.github.com>
1 parent cfc899b commit ea877a7

File tree

17 files changed

+900
-175
lines changed

17 files changed

+900
-175
lines changed

diagrams/src/custom_interfaces/external_interfaces.puml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ note right of desired_heading
4545
simulation and
4646
deployment
4747
end note
48+
' TODO: Should split into specific data sensors
4849
State data_sensors<<Topic>> : GenericSensors
4950
State gps<<Topic>> : GPS
5051
State mock_gps<<SimTopic>> : GPS
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"LBND"
4+
]
5+
}

src/network_systems/lib/cmn_hdrs/shared_constants.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515
namespace SYSTEM_MODE
1616
{
17-
static const std::string PROD = "production";
18-
static const std::string DEV = "development";
17+
static const std::string PROD = "production";
18+
static const std::string DEV = "development";
1919
static const std::string TEST_SAT = "test_satellite";
2020
}; // namespace SYSTEM_MODE
2121

@@ -63,12 +63,12 @@ constexpr int NUM_PH_SENSORS = []() constexpr
6363
return sizeof(ph_sensors_arr) / sizeof(custom_interfaces::msg::PhSensor);
6464
}
6565
();
66-
constexpr int NUM_PRESSURE_SENSORS = []() constexpr
67-
{
68-
using pressure_sensors_arr = custom_interfaces::msg::PressureSensors::_pressure_sensors_type;
69-
return sizeof(pressure_sensors_arr) / sizeof(custom_interfaces::msg::PressureSensor);
70-
}
71-
();
66+
// constexpr int NUM_PRESSURE_SENSORS = []() constexpr
67+
// {
68+
// using pressure_sensors_arr = custom_interfaces::msg::PressureSensors::_pressure_sensors_type;
69+
// return sizeof(pressure_sensors_arr) / sizeof(custom_interfaces::msg::PressureSensor);
70+
// }
71+
// ();
7272
constexpr int NUM_SALINITY_SENSORS = []() constexpr
7373
{
7474
using salinity_sensors_arr = custom_interfaces::msg::SalinitySensors::_salinity_sensors_type;

src/network_systems/lib/protofiles/sensors.proto

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,37 @@ message Sensors
4444
uint64 data = 2;
4545
}
4646

47+
// Commented out in favor of using packed arrays
48+
49+
// message Temp {
50+
// float temp = 1;
51+
// }
52+
53+
// message Ph {
54+
// float ph = 1;
55+
// }
56+
57+
// message Salinity {
58+
// float salinity = 1;
59+
// }
60+
61+
// message Pressure {
62+
// float pressure = 1;
63+
// }
64+
4765
message Path
4866
{
4967
repeated Waypoint waypoints = 1;
5068
// Will be expanded in the future
5169
}
5270

53-
Gps gps = 1;
54-
repeated Wind wind_sensors = 2;
55-
repeated Battery batteries = 3;
56-
repeated Ais ais_ships = 4;
57-
repeated Generic data_sensors = 5;
58-
Path local_path_data = 6;
71+
Gps gps = 1;
72+
repeated Wind wind_sensors = 2;
73+
repeated Battery batteries = 3;
74+
repeated Ais ais_ships = 4;
75+
repeated float temp_sensors = 5;
76+
repeated float ph_sensors = 6;
77+
repeated float salinity_sensors = 7;
78+
repeated float pressure_sensors = 8;
79+
Path local_path_data = 9;
5980
}

src/network_systems/lib/sailbot_db/inc/sailbot_db.h

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
// >>>>IMPORTANT<<<<<
1515
// BSON document formats from: https://ubcsailbot.atlassian.net/wiki/spaces/prjt22/pages/1907589126/Database+Schemas:
1616

17-
const std::string COLLECTION_AIS_SHIPS = "ais_ships";
18-
const std::string COLLECTION_BATTERIES = "batteries";
19-
const std::string COLLECTION_DATA_SENSORS = "data_sensors";
17+
const std::string COLLECTION_AIS_SHIPS = "ais_ships";
18+
const std::string COLLECTION_BATTERIES = "batteries";
19+
// const std::string COLLECTION_DATA_SENSORS = "data_sensors";
20+
const std::string COLLECTION_TEMP_SENSORS = "temp_sensors";
21+
const std::string COLLECTION_PH_SENSORS = "ph_sensors";
22+
const std::string COLLECTION_SALINITY_SENSORS = "salinity_sensors";
23+
// const std::string COLLECTION_PRESSURE_SENSORS = "pressure_sensors";
2024
const std::string COLLECTION_GPS = "gps";
2125
const std::string COLLECTION_WIND_SENSORS = "wind_sensors";
2226
const std::string COLLECTION_LOCAL_PATH = "local_path";
@@ -26,7 +30,11 @@ const std::string COLLECTION_IRIDIUM_RESPONSE = "iridium_response";
2630

2731
template <typename T>
2832
using ProtoList = google::protobuf::RepeatedPtrField<T>;
29-
using DocVal = bsoncxx::document::view_or_value;
33+
34+
template <typename T>
35+
using ProtoPrimitiveList = google::protobuf::RepeatedField<T>;
36+
37+
using DocVal = bsoncxx::document::view_or_value;
3038

3139
/**
3240
* Thread-safe class that encapsulates a Sailbot MongoDB database
@@ -213,10 +221,58 @@ class SailbotDB
213221
const ProtoList<Polaris::Sensors::Generic> & generic_pb, const std::string & timestamp,
214222
mongocxx::client & client);
215223

224+
/**
225+
* @brief Adds temperature sensors to the database
226+
*
227+
* @param temp_pb Protobuf list of temperature sensor objects, where the size of the list is the number of sensors
228+
* @param timestamp transmission time <year - 2000>-<month>-<day> <hour>:<minute>:<second>
229+
* @param client mongocxx::client instance for the current thread
230+
*
231+
* @return True if sensor is added, false otherwise
232+
*/
233+
bool storeTempSensors(
234+
const ProtoPrimitiveList<float> & temp_pb, const std::string & timestamp, mongocxx::client & client);
235+
236+
/**
237+
* @brief Adds pH sensors to the database
238+
*
239+
* @param ph_pb Protobuf list of pH sensor objects, where the size of the list is the number of sensors
240+
* @param timestamp transmission time <year - 2000>-<month>-<day> <hour>:<minute>:<second>
241+
* @param client mongocxx::client instance for the current thread
242+
*
243+
* @return True if sensor is added, false otherwise
244+
*/
245+
bool storePhSensors(
246+
const ProtoPrimitiveList<float> & ph_pb, const std::string & timestamp, mongocxx::client & client);
247+
248+
/**
249+
* @brief Adds salinity sensors to the database
250+
*
251+
* @param salinity_pb Protobuf list of salinity sensor objects, where the size of the list is the number of sensors
252+
* @param timestamp transmission time <year - 2000>-<month>-<day> <hour>:<minute>:<second>
253+
* @param client mongocxx::client instance for the current thread
254+
*
255+
* @return True if sensor is added, false otherwise
256+
*/
257+
bool storeSalinitySensors(
258+
const ProtoPrimitiveList<float> & salinity_pb, const std::string & timestamp, mongocxx::client & client);
259+
260+
/**
261+
* @brief Adds pressure sensors to the database
262+
*
263+
* @param pressure_pb Protobuf list of pressure sensor objects, where the size of the list is the number of sensors
264+
* @param timestamp transmission time <year - 2000>-<month>-<day> <hour>:<minute>:<second>
265+
* @param client mongocxx::client instance for the current thread
266+
*
267+
* @return True if sensor is added, false otherwise
268+
*/
269+
bool storePressureSensors(
270+
const ProtoPrimitiveList<float> & pressure_pb, const std::string & timestamp, mongocxx::client & client);
271+
216272
/**
217273
* @brief Adds a battery sensors to the database
218274
*
219-
* @param generic_pb Protobuf list of battery objects
275+
* @param battery_pb Protobuf list of battery objects
220276
* @param timestamp transmission time <year - 2000>-<month>-<day> <hour>:<minute>:<second>
221277
* @param client mongocxx::client instance for the current thread
222278
*

src/network_systems/lib/sailbot_db/inc/util_db.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
class UtilDB : public SailbotDB
1111
{
1212
public:
13-
static constexpr int NUM_AIS_SHIPS = 15; // arbitrary number
14-
static constexpr int NUM_GENERIC_SENSORS = 5; // arbitrary number
15-
static constexpr int NUM_PATH_WAYPOINTS = 5; // arbitrary number
13+
static constexpr int NUM_AIS_SHIPS = 15; // arbitrary number
14+
// static constexpr int NUM_GENERIC_SENSORS = 5; // arbitrary number
15+
static constexpr int NUM_PATH_WAYPOINTS = 5; // arbitrary number
1616

1717
/**
1818
* @brief Construct a UtilDB, which has debug utilities for SailbotDB
@@ -136,11 +136,41 @@ class UtilDB : public SailbotDB
136136
void genRandAisData(Polaris::Sensors::Ais & ais_ship);
137137

138138
/**
139-
* @brief generate random generic sensor data
139+
// * @brief generate random generic sensor data
140+
// *
141+
// * @param generic_sensor Generic sensor data to modify
142+
// */
143+
// void genRandGenericSensorData(Polaris::Sensors::Generic & generic_sensor);
144+
145+
/**
146+
* @brief
147+
*
148+
*
149+
*
150+
* @param temp_sensor Temperature sensor data to modify
151+
*/
152+
void genRandTempSensorData(float & temp_sensor);
153+
154+
/**
155+
* @brief generate random pH sensor data
156+
*
157+
* @param ph_sensor pH sensor data to modify
158+
*/
159+
void genRandPhSensorData(float & ph_sensor);
160+
161+
// /**
162+
// * @brief generate random pressure sensor data
163+
// *
164+
// * @param pressure_sensor Pressure sensor data to modify
165+
// */
166+
// void genRandPressureSensorData(float & pressure_sensor);
167+
168+
/**
169+
* @brief generate random salinity sensor data
140170
*
141-
* @param generic_sensor Generic sensor data to modify
171+
* @param salinity_sensor Salinity sensor data to modify
142172
*/
143-
void genRandGenericSensorData(Polaris::Sensors::Generic & generic_sensor);
173+
void genRandSalinitySensorData(float & salinity_sensor);
144174

145175
/**
146176
* @brief generate random battery data

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

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace bstream = bsoncxx::builder::stream;
2222
using Polaris::GlobalPath;
2323
using Polaris::Sensors;
2424

25-
mongocxx::instance SailbotDB::inst_{}; // staticallly initialize instance
25+
mongocxx::instance SailbotDB::inst_{}; // statically initialize instance
2626

2727
// PUBLIC
2828

@@ -96,7 +96,11 @@ bool SailbotDB::storeNewSensors(const Sensors & sensors_pb, RcvdMsgInfo new_info
9696
const std::string & timestamp = new_info.timestamp_;
9797
mongocxx::pool::entry entry = pool_->acquire();
9898
return storeGps(sensors_pb.gps(), timestamp, *entry) && storeAis(sensors_pb.ais_ships(), timestamp, *entry) &&
99-
storeGenericSensors(sensors_pb.data_sensors(), timestamp, *entry) &&
99+
// storeGenericSensors(sensors_pb.data_sensors(), timestamp, *entry) && // * Generic sensors are replaced by Temp, Salinity, pH, Pressure
100+
storeTempSensors(sensors_pb.temp_sensors(), timestamp, *entry) &&
101+
storePhSensors(sensors_pb.ph_sensors(), timestamp, *entry) &&
102+
storeSalinitySensors(sensors_pb.salinity_sensors(), timestamp, *entry) &&
103+
// storePressureSensors(sensors_pb.pressure_sensors(), timestamp, *entry) && // * We aren't using pH Sensors as of Nov 2025
100104
storeBatteries(sensors_pb.batteries(), timestamp, *entry) &&
101105
storeWindSensors(sensors_pb.wind_sensors(), timestamp, *entry) &&
102106
storePathSensors(sensors_pb.local_path_data(), timestamp, *entry);
@@ -149,21 +153,80 @@ bool SailbotDB::storeAis(
149153
return static_cast<bool>(ais_coll.insert_one(ais_ships_doc.view()));
150154
}
151155

152-
bool SailbotDB::storeGenericSensors(
153-
const ProtoList<Sensors::Generic> & generic_pb, const std::string & timestamp, mongocxx::client & client)
156+
// bool SailbotDB::storeGenericSensors(
157+
// const ProtoList<Sensors::Generic> & generic_pb, const std::string & timestamp, mongocxx::client & client)
158+
// {
159+
// mongocxx::database db = client[db_name_];
160+
// mongocxx::collection generic_coll = db[COLLECTION_DATA_SENSORS];
161+
// bstream::document doc_builder{};
162+
// auto generic_doc_arr = doc_builder << "genericSensors" << bstream::open_array;
163+
// for (const Sensors::Generic & generic : generic_pb) {
164+
// generic_doc_arr = generic_doc_arr << bstream::open_document << "id" << static_cast<int64_t>(generic.id())
165+
// << "data" << static_cast<int64_t>(generic.data()) << bstream::close_document;
166+
// }
167+
// DocVal generic_doc = generic_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize;
168+
// return static_cast<bool>(generic_coll.insert_one(generic_doc.view()));
169+
// }
170+
171+
bool SailbotDB::storeTempSensors(
172+
const ProtoPrimitiveList<float> & temp_pb, const std::string & timestamp, mongocxx::client & client)
173+
{
174+
mongocxx::database db = client[db_name_];
175+
mongocxx::collection temp_coll = db[COLLECTION_TEMP_SENSORS];
176+
bstream::document doc_builder{};
177+
auto temp_doc_arr = doc_builder << "tempSensors" << bstream::open_array;
178+
for (const float & temp_sensor : temp_pb) {
179+
temp_doc_arr = temp_doc_arr << bstream::open_document << "temperature" << temp_sensor
180+
<< bstream::close_document;
181+
}
182+
DocVal temp_doc = temp_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize;
183+
return static_cast<bool>(temp_coll.insert_one(temp_doc.view()));
184+
}
185+
186+
bool SailbotDB::storePhSensors(
187+
const ProtoPrimitiveList<float> & ph_pb, const std::string & timestamp, mongocxx::client & client)
154188
{
155-
mongocxx::database db = client[db_name_];
156-
mongocxx::collection generic_coll = db[COLLECTION_DATA_SENSORS];
189+
mongocxx::database db = client[db_name_];
190+
mongocxx::collection ph_coll = db[COLLECTION_PH_SENSORS];
157191
bstream::document doc_builder{};
158-
auto generic_doc_arr = doc_builder << "genericSensors" << bstream::open_array;
159-
for (const Sensors::Generic & generic : generic_pb) {
160-
generic_doc_arr = generic_doc_arr << bstream::open_document << "id" << static_cast<int64_t>(generic.id())
161-
<< "data" << static_cast<int64_t>(generic.data()) << bstream::close_document;
192+
auto ph_doc_arr = doc_builder << "phSensors" << bstream::open_array;
193+
for (const float & ph_sensor : ph_pb) {
194+
ph_doc_arr = ph_doc_arr << bstream::open_document << "ph" << ph_sensor << bstream::close_document;
162195
}
163-
DocVal generic_doc = generic_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize;
164-
return static_cast<bool>(generic_coll.insert_one(generic_doc.view()));
196+
DocVal ph_doc = ph_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize;
197+
return static_cast<bool>(ph_coll.insert_one(ph_doc.view()));
165198
}
166199

200+
bool SailbotDB::storeSalinitySensors(
201+
const ProtoPrimitiveList<float> & salinity_pb, const std::string & timestamp, mongocxx::client & client)
202+
{
203+
mongocxx::database db = client[db_name_];
204+
mongocxx::collection salinity_coll = db[COLLECTION_SALINITY_SENSORS];
205+
bstream::document doc_builder{};
206+
auto salinity_doc_arr = doc_builder << "salinitySensors" << bstream::open_array;
207+
for (const float & salinity_sensor : salinity_pb) {
208+
salinity_doc_arr = salinity_doc_arr << bstream::open_document << "salinity" << salinity_sensor
209+
<< bstream::close_document;
210+
}
211+
DocVal salinity_doc = salinity_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize;
212+
return static_cast<bool>(salinity_coll.insert_one(salinity_doc.view()));
213+
}
214+
215+
// bool SailbotDB::storePressureSensors(
216+
// const ProtoPrimitiveList<float> & pressure_pb, const std::string & timestamp, mongocxx::client & client)
217+
// {
218+
// mongocxx::database db = client[db_name_];
219+
// mongocxx::collection pressure_coll = db[COLLECTION_PRESSURE_SENSORS];
220+
// bstream::document doc_builder{};
221+
// auto pressure_doc_arr = doc_builder << "pressureSensors" << bstream::open_array;
222+
// for (const float & pressure_sensor : pressure_pb) {
223+
// pressure_doc_arr = pressure_doc_arr << bstream::open_document << "pressure" << pressure_sensor
224+
// << bstream::close_document;
225+
// }
226+
// DocVal pressure_doc = pressure_doc_arr << bstream::close_array << "timestamp" << timestamp << bstream::finalize;
227+
// return static_cast<bool>(pressure_coll.insert_one(pressure_doc.view()));
228+
// }
229+
167230
bool SailbotDB::storeBatteries(
168231
const ProtoList<Sensors::Battery> & battery_pb, const std::string & timestamp, mongocxx::client & client)
169232
{

0 commit comments

Comments
 (0)