@@ -22,7 +22,7 @@ namespace bstream = bsoncxx::builder::stream;
2222using Polaris::GlobalPath;
2323using 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+
167230bool SailbotDB::storeBatteries (
168231 const ProtoList<Sensors::Battery> & battery_pb, const std::string & timestamp, mongocxx::client & client)
169232{
0 commit comments