FIX: fixed track class bugs
This commit is contained in:
@@ -8,6 +8,7 @@ namespace SimCore {
|
|||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
Entity();
|
Entity();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -22,40 +22,89 @@ namespace SimCore {
|
|||||||
class Track : public WHISPER::Message
|
class Track : public WHISPER::Message
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
/// message object from google protobuf
|
||||||
|
messages::track::Track trackMessage_;
|
||||||
|
|
||||||
messages::track::Track trackMessage_;
|
/// position of the track
|
||||||
|
|
||||||
Position position_;
|
Position position_;
|
||||||
|
/// speed the track
|
||||||
double speed_ = 0;
|
double speed_ = 0;
|
||||||
|
/// course of the track
|
||||||
double course_ = 0;
|
double course_ = 0;
|
||||||
|
/// indicates if track is from an external source
|
||||||
bool external_ = false;
|
bool external_ = false;
|
||||||
|
|
||||||
|
/// function that packs all information to a protobuf message
|
||||||
void packToMessage();
|
void packToMessage();
|
||||||
|
|
||||||
|
/// the unique tracknumber for now
|
||||||
|
std::uint32_t trackNo_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
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::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);
|
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);
|
void setPosition(double x,double y,double z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief returns the position
|
||||||
|
* @return object of position class
|
||||||
|
*
|
||||||
|
*/
|
||||||
Position getPostion();
|
Position getPostion();
|
||||||
|
|
||||||
|
/// sets speed
|
||||||
void setSpeed(double 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);
|
void setCourse(double course);
|
||||||
|
|
||||||
|
///returns course
|
||||||
|
double getCourse();
|
||||||
|
|
||||||
|
/// set external indicator
|
||||||
void setExternal(bool val);
|
void setExternal(bool val);
|
||||||
|
|
||||||
double getSpeed();
|
/// return true if is external
|
||||||
double getSpeedinKnots();
|
|
||||||
void setSpeedinKnots(double knots);
|
|
||||||
double getCourse();
|
|
||||||
bool isExternal();
|
bool isExternal();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,11 @@
|
|||||||
#include "SimCore/SimCore.hpp"
|
#include "SimCore/SimCore.hpp"
|
||||||
#include "WHISPER/Messages/Message.hpp"
|
#include "WHISPER/Messages/Message.hpp"
|
||||||
#include "google/protobuf/message.h"
|
#include "google/protobuf/message.h"
|
||||||
|
#include "google/protobuf/timestamp.pb.h"
|
||||||
#include <SimCore/Messages/Protos/Track.pb.h>
|
#include <SimCore/Messages/Protos/Track.pb.h>
|
||||||
#include <SimCore/Messages/Track.hpp>
|
#include <SimCore/Messages/Track.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +22,6 @@ namespace SimCore {
|
|||||||
msgType_ = msg.msgtype();
|
msgType_ = msg.msgtype();
|
||||||
|
|
||||||
auto trackMessage = messages::track::Track();
|
auto trackMessage = messages::track::Track();
|
||||||
|
|
||||||
if ( msg.payload_size() == 1) {
|
if ( msg.payload_size() == 1) {
|
||||||
if (msg.payload().begin()->Is<messages::track::Track>()) {
|
if (msg.payload().begin()->Is<messages::track::Track>()) {
|
||||||
msg.payload().begin()->UnpackTo(&trackMessage);
|
msg.payload().begin()->UnpackTo(&trackMessage);
|
||||||
@@ -31,9 +32,9 @@ namespace SimCore {
|
|||||||
speed_ = trackMessage.speed();
|
speed_ = trackMessage.speed();
|
||||||
course_ = trackMessage.course();
|
course_ = trackMessage.course();
|
||||||
external_ = trackMessage.external();
|
external_ = trackMessage.external();
|
||||||
|
|
||||||
messages::track::Track_EntityGeocentricPosition pos_temp = trackMessage.geocentricposition();
|
messages::track::Track_EntityGeocentricPosition pos_temp = trackMessage.geocentricposition();
|
||||||
position_.setGeocentricPos(pos_temp.x(), pos_temp.y(),pos_temp.z());
|
position_.setGeocentricPos(pos_temp.x(), pos_temp.y(),pos_temp.z());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} 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):
|
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), position_(pos),external_(external)
|
Message(deviceID,WHISPER::MsgTopics::TRACK,WHISPER::RAW_TRACK,src),trackNo_(trackNo), external_(external)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -54,12 +55,21 @@ namespace SimCore {
|
|||||||
|
|
||||||
void Track::packToMessage()
|
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_trackno(trackNo_);
|
||||||
trackMessage_.set_speed(speed_);
|
trackMessage_.set_speed(speed_);
|
||||||
trackMessage_.set_course(course_);
|
trackMessage_.set_course(course_);
|
||||||
trackMessage_.set_external(external_);
|
trackMessage_.set_external(external_);
|
||||||
LOG_S(INFO) << trackMessage_.speed() << " "<< trackMessage_.course();
|
|
||||||
|
trackMessage_.mutable_timestamp()->set_seconds(time(NULL));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto payloadMessage = std::make_shared<google::protobuf::Any>();
|
auto payloadMessage = std::make_shared<google::protobuf::Any>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "SimCore/Messages/Track.hpp"
|
#include <SimCore/Messages/Track.hpp>
|
||||||
#include "WHISPER/Messages/Message.hpp"
|
#include <WHISPER/Messages/Message.hpp>
|
||||||
#include <SimCore/SimCore.hpp>
|
#include <SimCore/SimCore.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#define CATCH_CONFIG_MAIN
|
#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::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.setCourse(course);
|
||||||
track.setSpeed(speed);
|
track.setSpeed(speed);
|
||||||
|
track.setPosition(GeocentPos1(SimCore::X),GeocentPos1(SimCore::Y),GeocentPos1(SimCore::Z));
|
||||||
|
|
||||||
if (track.getPostion() == pos) {
|
if (track.getPostion() == pos) {
|
||||||
testOperator = true;
|
testOperator = true;
|
||||||
@@ -49,7 +50,6 @@ SCENARIO("Testing the SimCore Track")
|
|||||||
|
|
||||||
if (msg.get()->msgType_ == WHISPER::RAW_TRACK) {
|
if (msg.get()->msgType_ == WHISPER::RAW_TRACK) {
|
||||||
trackPtr = std::make_shared<SimCore::Track>(serializedMSG);
|
trackPtr = std::make_shared<SimCore::Track>(serializedMSG);
|
||||||
LOG_S(INFO)<< trackPtr->getSpeed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,6 +63,7 @@ SCENARIO("Testing the SimCore Track")
|
|||||||
|
|
||||||
REQUIRE(msg.get()->msgType_ == WHISPER::RAW_TRACK);
|
REQUIRE(msg.get()->msgType_ == WHISPER::RAW_TRACK);
|
||||||
REQUIRE(trackPtr->getSpeed() == speed);
|
REQUIRE(trackPtr->getSpeed() == speed);
|
||||||
|
REQUIRE(trackPtr->getPostion().getGeocentricPos() == GeocentPos1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user