From a570766dc61bbed223c8851a267c0f5ac5fbd4b1 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Wed, 21 Dec 2022 15:18:57 +0100 Subject: [PATCH] FIX: fixed track class bugs --- include/SimCore/Entity.hpp | 1 + include/SimCore/Messages/Track.hpp | 69 +++++++++++++++++++++++++----- src/SimCore/Messages/Track.cpp | 22 +++++++--- tests/test_TrackClass.cpp | 9 ++-- 4 files changed, 81 insertions(+), 20 deletions(-) diff --git a/include/SimCore/Entity.hpp b/include/SimCore/Entity.hpp index 1bde05a..7210fde 100644 --- a/include/SimCore/Entity.hpp +++ b/include/SimCore/Entity.hpp @@ -8,6 +8,7 @@ namespace SimCore { class Entity { public: Entity(); + private: diff --git a/include/SimCore/Messages/Track.hpp b/include/SimCore/Messages/Track.hpp index bd9865c..bef2619 100644 --- a/include/SimCore/Messages/Track.hpp +++ b/include/SimCore/Messages/Track.hpp @@ -22,40 +22,89 @@ namespace SimCore { class Track : public WHISPER::Message { private: + /// message object from google protobuf + messages::track::Track trackMessage_; - messages::track::Track trackMessage_; - + /// position of the track Position position_; + /// speed the track double speed_ = 0; + /// course of the track double course_ = 0; + /// indicates if track is from an external source bool external_ = false; + /// function that packs all information to a protobuf message void packToMessage(); - + /// the unique tracknumber for now + std::uint32_t trackNo_; public: - std::uint32_t trackNo_; - + /** + * @brief a cuntructor that builds the object from a received message + * @param std::string the received thring from the line + */ Track(std::string receivedMessage); - Track(std::uint32_t deviceID, WHISPER::SourceType src,std::uint32_t trackNo,Position pos, bool external); + /** + * @brief constructor for building a track which is also the trackmessage to send + * @param uint32_t deviceID the id of the sending device + * @param WHISPER::SourceType sourcetype of the sending device + * @param uint32_t internal tracknumber + * @param bool external indicates if track is from an external source e.g. dis + * + * @return + */ + Track(std::uint32_t deviceID, WHISPER::SourceType src,std::uint32_t trackNo, bool external); + /** + * @brief set the position of the track + * @param Position object of the position class + * + */ void setPosition(Position pos); + + /** + * @brief set the position of the track + * @param 3x double set the x,y,z coordinates direkt which causes that an object of position class is created + */ void setPosition(double x,double y,double z); + + /** + * @brief returns the position + * @return object of position class + * + */ Position getPostion(); + /// sets speed void setSpeed(double speed); + + /// set speed in knots + void setSpeedinKnots(double knots); + + /// return sspeed + double getSpeed(); + + /// returns speed as knots + double getSpeedinKnots(); + + /// set course void setCourse(double course); + + ///returns course + double getCourse(); + + /// set external indicator void setExternal(bool val); - double getSpeed(); - double getSpeedinKnots(); - void setSpeedinKnots(double knots); - double getCourse(); + /// return true if is external bool isExternal(); + + }; } \ No newline at end of file diff --git a/src/SimCore/Messages/Track.cpp b/src/SimCore/Messages/Track.cpp index fda4702..f54bb93 100644 --- a/src/SimCore/Messages/Track.cpp +++ b/src/SimCore/Messages/Track.cpp @@ -2,9 +2,11 @@ #include "SimCore/SimCore.hpp" #include "WHISPER/Messages/Message.hpp" #include "google/protobuf/message.h" +#include "google/protobuf/timestamp.pb.h" #include #include #include +#include @@ -20,7 +22,6 @@ namespace SimCore { msgType_ = msg.msgtype(); auto trackMessage = messages::track::Track(); - if ( msg.payload_size() == 1) { if (msg.payload().begin()->Is()) { msg.payload().begin()->UnpackTo(&trackMessage); @@ -31,9 +32,9 @@ namespace SimCore { speed_ = trackMessage.speed(); course_ = trackMessage.course(); external_ = trackMessage.external(); + messages::track::Track_EntityGeocentricPosition pos_temp = trackMessage.geocentricposition(); position_.setGeocentricPos(pos_temp.x(), pos_temp.y(),pos_temp.z()); - } catch (const std::exception& e) { @@ -43,8 +44,8 @@ namespace SimCore { } - Track::Track(std::uint32_t deviceID, WHISPER::SourceType src,std::uint32_t trackNo,Position pos, bool external): - Message(deviceID,WHISPER::MsgTopics::TRACK,WHISPER::RAW_TRACK,src),trackNo_(trackNo), position_(pos),external_(external) + Track::Track(std::uint32_t deviceID, WHISPER::SourceType src,std::uint32_t trackNo, bool external): + Message(deviceID,WHISPER::MsgTopics::TRACK,WHISPER::RAW_TRACK,src),trackNo_(trackNo), external_(external) { @@ -54,12 +55,21 @@ namespace SimCore { void Track::packToMessage() { - + + + + trackMessage_.mutable_geocentricposition()->set_x(position_.getGeocentricPos()(SimCore::X)); + trackMessage_.mutable_geocentricposition()->set_y(position_.getGeocentricPos()(SimCore::Y)); + trackMessage_.mutable_geocentricposition()->set_z(position_.getGeocentricPos()(SimCore::Z)); + trackMessage_.set_trackno(trackNo_); trackMessage_.set_speed(speed_); trackMessage_.set_course(course_); trackMessage_.set_external(external_); - LOG_S(INFO) << trackMessage_.speed() << " "<< trackMessage_.course(); + + trackMessage_.mutable_timestamp()->set_seconds(time(NULL)); + + auto payloadMessage = std::make_shared(); diff --git a/tests/test_TrackClass.cpp b/tests/test_TrackClass.cpp index 56fd109..91ffd8e 100644 --- a/tests/test_TrackClass.cpp +++ b/tests/test_TrackClass.cpp @@ -1,5 +1,5 @@ -#include "SimCore/Messages/Track.hpp" -#include "WHISPER/Messages/Message.hpp" +#include +#include #include #include #define CATCH_CONFIG_MAIN @@ -37,9 +37,10 @@ SCENARIO("Testing the SimCore Track") { SimCore::Position pos( GeocentPos1(SimCore::GeocentricPosition::X), GeocentPos1(SimCore::GeocentricPosition::Y), GeocentPos1(SimCore::GeocentricPosition::Z)); - SimCore::Track track(1,WHISPER::SourceType::SHIP,10,pos,false); + SimCore::Track track(1,WHISPER::SourceType::SHIP,10,false); track.setCourse(course); track.setSpeed(speed); + track.setPosition(GeocentPos1(SimCore::X),GeocentPos1(SimCore::Y),GeocentPos1(SimCore::Z)); if (track.getPostion() == pos) { testOperator = true; @@ -49,7 +50,6 @@ SCENARIO("Testing the SimCore Track") if (msg.get()->msgType_ == WHISPER::RAW_TRACK) { trackPtr = std::make_shared(serializedMSG); - LOG_S(INFO)<< trackPtr->getSpeed(); } @@ -63,6 +63,7 @@ SCENARIO("Testing the SimCore Track") REQUIRE(msg.get()->msgType_ == WHISPER::RAW_TRACK); REQUIRE(trackPtr->getSpeed() == speed); + REQUIRE(trackPtr->getPostion().getGeocentricPos() == GeocentPos1);