Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
7101ad22
Commit
7101ad22
authored
Jul 11, 2020
by
Valentin Platzgummer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
a15105e3
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
218 additions
and
93 deletions
+218
-93
qgroundcontrol.pro
qgroundcontrol.pro
+4
-2
GeoPoint3D.h
src/Wima/GeoPoint3D.h
+8
-8
PolygonArray.h
src/Wima/PolygonArray.h
+1
-1
QtROSJsonFactory.h
src/Wima/QtROSJsonFactory.h
+1
-1
WimaPolygonArray.h
src/Wima/WimaPolygonArray.h
+2
-2
CasePacker.h
src/comm/ros_bridge/include/CasePacker.h
+53
-0
JsonFactory.h
src/comm/ros_bridge/include/JsonFactory.h
+17
-14
JsonMethodes.h
src/comm/ros_bridge/include/JsonMethodes.h
+1
-1
MessageGroups.h
src/comm/ros_bridge/include/MessageGroups.h
+2
-2
MessageTag.cpp
src/comm/ros_bridge/include/MessageTag.cpp
+43
-0
MessageTag.h
src/comm/ros_bridge/include/MessageTag.h
+24
-0
PackageQueue.h
src/comm/ros_bridge/include/PackageQueue.h
+2
-5
ROSCommunicator.h
src/comm/ros_bridge/include/ROSCommunicator.h
+24
-9
CasePacker.cpp
src/comm/ros_bridge/src/CasePacker.cpp
+27
-4
CasePacker.h
src/comm/ros_bridge/src/CasePacker.h
+0
-42
ROSCommunicator.cpp
src/comm/ros_bridge/src/ROSCommunicator.cpp
+9
-2
No files found.
qgroundcontrol.pro
View file @
7101ad22
...
@@ -473,12 +473,13 @@ HEADERS += \
...
@@ -473,12 +473,13 @@ HEADERS += \
src
/
Wima
/
testplanimetrycalculus
.
h
\
src
/
Wima
/
testplanimetrycalculus
.
h
\
src
/
Settings
/
WimaSettings
.
h
\
src
/
Settings
/
WimaSettings
.
h
\
src
/
QmlControls
/
QmlObjectVectorModel
.
h
\
src
/
QmlControls
/
QmlObjectVectorModel
.
h
\
src
/
comm
/
ros_bridge
/
include
/
CasePacker
.
h
\
src
/
comm
/
ros_bridge
/
include
/
GenericMessages
.
h
\
src
/
comm
/
ros_bridge
/
include
/
GenericMessages
.
h
\
src
/
comm
/
ros_bridge
/
include
/
JsonMethodes
.
h
\
src
/
comm
/
ros_bridge
/
include
/
JsonMethodes
.
h
\
src
/
comm
/
ros_bridge
/
include
/
MessageTag
.
h
\
src
/
comm
/
ros_bridge
/
include
/
MessageTraits
.
h
\
src
/
comm
/
ros_bridge
/
include
/
MessageTraits
.
h
\
src
/
comm
/
ros_bridge
/
include
/
Package
Buffer
.
h
\
src
/
comm
/
ros_bridge
/
include
/
Package
Queue
.
h
\
src
/
comm
/
ros_bridge
/
include
/
TypeFactory
.
h
\
src
/
comm
/
ros_bridge
/
include
/
TypeFactory
.
h
\
src
/
comm
/
ros_bridge
/
src
/
CasePacker
.
h
\
src
/
comm
/
ros_bridge
/
src
/
PackageBuffer
.
h
\
src
/
comm
/
ros_bridge
/
src
/
PackageBuffer
.
h
\
src
/
comm
/
utilities
.
h
src
/
comm
/
utilities
.
h
SOURCES
+=
\
SOURCES
+=
\
...
@@ -487,6 +488,7 @@ SOURCES += \
...
@@ -487,6 +488,7 @@ SOURCES += \
src
/
Snake
/
snake_geometry
.
cpp
\
src
/
Snake
/
snake_geometry
.
cpp
\
src
/
Wima
/
GeoPoint3D
.
cpp
\
src
/
Wima
/
GeoPoint3D
.
cpp
\
src
/
Wima
/
PolygonArray
.
cc
\
src
/
Wima
/
PolygonArray
.
cc
\
src
/
comm
/
ros_bridge
/
include
/
MessageTag
.
cpp
\
src
/
comm
/
ros_bridge
/
src
/
CasePacker
.
cpp
\
src
/
comm
/
ros_bridge
/
src
/
CasePacker
.
cpp
\
src
/
comm
/
ros_bridge
/
src
/
ROSCommunicator
.
cpp
\
src
/
comm
/
ros_bridge
/
src
/
ROSCommunicator
.
cpp
\
src
/
Wima
/
WimaControllerDetail
.
cc
\
src
/
Wima
/
WimaControllerDetail
.
cc
\
...
...
src/Wima/GeoPoint3D.h
View file @
7101ad22
...
@@ -2,33 +2,33 @@
...
@@ -2,33 +2,33 @@
#include "ros_bridge/include/JsonMethodes.h"
#include "ros_bridge/include/JsonMethodes.h"
#include "ros_bridge/include/MessageBaseClass.h"
#include "ros_bridge/include/MessageBaseClass.h"
#include "ros_bridge/include/
MessageGroup
s.h"
#include "ros_bridge/include/
GenericMessage
s.h"
#include <QObject>
#include <QObject>
typedef
ROSBridge
::
MessageBaseClass
<
QString
>
ROSMsg
;
typedef
ROSBridge
::
MessageBaseClass
ROSMsg
;
typedef
ROSBridge
::
JsonMethodes
::
GeoPoint
::
GeoPoint
ROSGeoPoint
;
typedef
ROSBridge
::
GenericMessages
::
GeographicMsgs
::
GeoPoint
ROSGeoPoint
;
namespace
MsgGroups
=
ROSBridge
::
MessageGroups
;
namespace
MsgGroups
=
ROSBridge
::
MessageGroups
;
class
GeoPoint3D
:
public
QObject
,
public
ROS
Msg
,
public
ROS
GeoPoint
class
GeoPoint3D
:
public
QObject
,
public
ROSGeoPoint
{
{
Q_OBJECT
Q_OBJECT
public:
public:
typedef
MsgGroups
::
GeoPointGroup
Group
;
typedef
MsgGroups
::
GeoPointGroup
Group
;
explicit
GeoPoint3D
(
QObject
*
parent
=
nullptr
)
explicit
GeoPoint3D
(
QObject
*
parent
=
nullptr
)
:
QObject
(
parent
),
ROS
Msg
(),
ROS
GeoPoint
()
{}
:
QObject
(
parent
),
ROSGeoPoint
()
{}
explicit
GeoPoint3D
(
double
latitude
,
explicit
GeoPoint3D
(
double
latitude
,
double
longitude
,
double
longitude
,
double
altitude
,
double
altitude
,
QObject
*
parent
=
nullptr
)
QObject
*
parent
=
nullptr
)
:
QObject
(
parent
),
ROS
Msg
(),
ROS
GeoPoint
(
latitude
,
longitude
,
altitude
)
:
QObject
(
parent
),
ROSGeoPoint
(
latitude
,
longitude
,
altitude
)
{}
{}
explicit
GeoPoint3D
(
const
GeoPoint3D
&
p
,
explicit
GeoPoint3D
(
const
GeoPoint3D
&
p
,
QObject
*
parent
=
nullptr
)
QObject
*
parent
=
nullptr
)
:
QObject
(
parent
),
ROS
Msg
(),
ROS
GeoPoint
(
p
.
latitude
(),
p
.
longitude
(),
p
.
altitude
())
:
QObject
(
parent
),
ROSGeoPoint
(
p
.
latitude
(),
p
.
longitude
(),
p
.
altitude
())
{}
{}
explicit
GeoPoint3D
(
const
ROSGeoPoint
&
p
,
explicit
GeoPoint3D
(
const
ROSGeoPoint
&
p
,
QObject
*
parent
=
nullptr
)
QObject
*
parent
=
nullptr
)
:
QObject
(
parent
),
ROS
Msg
(),
ROS
GeoPoint
(
p
.
latitude
(),
p
.
longitude
(),
p
.
altitude
())
:
QObject
(
parent
),
ROSGeoPoint
(
p
.
latitude
(),
p
.
longitude
(),
p
.
altitude
())
{}
{}
virtual
GeoPoint3D
*
Clone
()
const
override
;
virtual
GeoPoint3D
*
Clone
()
const
override
;
...
...
src/Wima/PolygonArray.h
View file @
7101ad22
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include "ros_bridge/include/MessageBaseClass.h"
#include "ros_bridge/include/MessageBaseClass.h"
typedef
ROSBridge
::
MessageBaseClass
<
QString
>
ROSMsgBase
;
typedef
ROSBridge
::
MessageBaseClass
ROSMsgBase
;
template
<
class
PolygonType
,
template
<
class
,
class
...
>
class
ContainerType
>
template
<
class
PolygonType
,
template
<
class
,
class
...
>
class
ContainerType
>
class
PolygonArray
:
public
ROSMsgBase
,
public
ContainerType
<
PolygonType
>
{
class
PolygonArray
:
public
ROSMsgBase
,
public
ContainerType
<
PolygonType
>
{
public:
public:
...
...
src/Wima/QtROSJsonFactory.h
View file @
7101ad22
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
#include "ros_bridge/include/JsonFactory.h"
#include "ros_bridge/include/JsonFactory.h"
#include <QString>
#include <QString>
typedef
ROSBridge
::
JsonFactory
<
QString
>
QtROSJsonFactory
;
typedef
ROSBridge
::
Generic
JsonFactory
<
QString
>
QtROSJsonFactory
;
src/Wima/WimaPolygonArray.h
View file @
7101ad22
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include <QVector>
#include <QVector>
#include <QString>
#include <QString>
typedef
ROSBridge
::
MessageBaseClass
<
QString
>
ROSMsg
;
typedef
ROSBridge
::
MessageBaseClass
ROSMsg
;
namespace
MsgGroups
=
ROSBridge
::
MessageGroups
;
namespace
MsgGroups
=
ROSBridge
::
MessageGroups
;
typedef
MsgGroups
::
EmptyGroup
EmptyGroup
;
typedef
MsgGroups
::
EmptyGroup
EmptyGroup
;
template
<
class
PolygonType
,
template
<
class
,
class
...
>
class
ContainerType
=
QVector
,
typename
GroupType
=
EmptyGroup
>
template
<
class
PolygonType
,
template
<
class
,
class
...
>
class
ContainerType
=
QVector
,
typename
GroupType
=
EmptyGroup
>
...
@@ -21,7 +21,7 @@ public:
...
@@ -21,7 +21,7 @@ public:
,
_polygons
(
other
.
_polygons
),
_dirty
(
true
)
,
_polygons
(
other
.
_polygons
),
_dirty
(
true
)
{}
{}
virtual
MessageBaseClass
<
QString
>
*
Clone
()
const
override
{
virtual
WimaPolygonArray
*
Clone
()
const
override
{
return
new
WimaPolygonArray
(
*
this
);
return
new
WimaPolygonArray
(
*
this
);
}
}
...
...
src/comm/ros_bridge/include/CasePacker.h
0 → 100644
View file @
7101ad22
#pragma once
#include "ros_bridge/include/MessageBaseClass.h"
#include "ros_bridge/include/MessageTag.h"
#include "ros_bridge/include/TypeFactory.h"
#include "ros_bridge/include/JsonFactory.h"
#include <memory>
#include "rapidjson/include/rapidjson/document.h"
namespace
ROSBridge
{
class
CasePacker
{
typedef
MessageTag
Tag
;
typedef
rapidjson
::
Document
JsonDoc
;
typedef
std
::
unique_ptr
<
JsonDoc
>
JsonDocUPtr
;
public:
CasePacker
();
template
<
class
T
>
JsonDoc
*
pack
(
const
T
&
msg
,
const
std
::
string
&
topic
)
{
JsonDoc
*
docPt
(
_jsonFactory
.
create
(
msg
));
std
::
string
messageType
=
T
::
Group
::
messageType
();
_addTag
(
*
docPt
,
topic
,
messageType
.
c_str
());
return
docPt
;
}
bool
showTag
(
const
JsonDoc
&
doc
,
Tag
&
tag
);
template
<
class
T
>
bool
unpack
(
JsonDoc
&
doc
,
T
&
msg
){
_removeTag
(
doc
);
return
_typeFactory
.
create
(
doc
,
msg
);
}
static
const
char
*
topicKey
;
static
const
char
*
messageTypeKey
;
protected:
void
_addTag
(
JsonDoc
&
doc
,
const
std
::
string
&
topic
,
const
std
::
string
&
messageType
);
void
_removeTag
(
JsonDoc
&
doc
);
bool
_getTopic
(
const
JsonDoc
&
doc
,
std
::
string
&
topic
);
bool
_getMessageType
(
const
JsonDoc
&
doc
,
std
::
string
&
messageType
);
private:
TypeFactory
_typeFactory
;
JsonFactory
_jsonFactory
;
};
}
src/comm/ros_bridge/include/JsonFactory.h
View file @
7101ad22
...
@@ -23,12 +23,12 @@ class StdHeaderPolicy;
...
@@ -23,12 +23,12 @@ class StdHeaderPolicy;
//! from classes derived from \class MessageBaseClass. Each class has a group mark (typedef ... Group) which allows the
//! from classes derived from \class MessageBaseClass. Each class has a group mark (typedef ... Group) which allows the
//! JsonFactory to determine the ROS message type it will create.
//! JsonFactory to determine the ROS message type it will create.
template
<
class
HeaderPolicy
=
StdHeaderPolicy
>
template
<
class
HeaderPolicy
=
StdHeaderPolicy
>
class
JsonFactory
:
public
HeaderPolicy
class
Generic
JsonFactory
:
public
HeaderPolicy
{
{
typedef
MessageBaseClass
ROSMsg
;
typedef
MessageBaseClass
ROSMsg
;
public:
public:
JsonFactory
()
:
HeaderPolicy
()
{}
Generic
JsonFactory
()
:
HeaderPolicy
()
{}
//!
//!
//! \brief Creates a \class rapidjson::Document document containing a ROS mesage from \p msg.
//! \brief Creates a \class rapidjson::Document document containing a ROS mesage from \p msg.
...
@@ -127,7 +127,7 @@ private:
...
@@ -127,7 +127,7 @@ private:
template
<
class
U
>
template
<
class
U
>
rapidjson
::
Document
*
_createPolygonStamped
(
const
U
&
msg
,
Int2Type
<
0
>
){
// U has no member header(), generate one on the fly.
rapidjson
::
Document
*
_createPolygonStamped
(
const
U
&
msg
,
Int2Type
<
0
>
){
// U has no member header(), generate one on the fly.
using
namespace
ROSBridge
;
using
namespace
ROSBridge
;
JsonMethodes
::
Header
::
Header
header
(
HeaderPolicy
::
header
(
msg
));
GenericMessages
::
StdMsgs
::
Header
header
(
HeaderPolicy
::
header
(
msg
));
rapidjson
::
Document
*
doc
=
new
rapidjson
::
Document
(
rapidjson
::
kObjectType
);
rapidjson
::
Document
*
doc
=
new
rapidjson
::
Document
(
rapidjson
::
kObjectType
);
bool
ret
=
JsonMethodes
::
GeometryMsgs
::
PolygonStamped
::
toJson
(
msg
.
polygon
(),
header
,
*
doc
,
doc
->
GetAllocator
());
bool
ret
=
JsonMethodes
::
GeometryMsgs
::
PolygonStamped
::
toJson
(
msg
.
polygon
(),
header
,
*
doc
,
doc
->
GetAllocator
());
assert
(
ret
);
assert
(
ret
);
...
@@ -152,7 +152,7 @@ private:
...
@@ -152,7 +152,7 @@ private:
rapidjson
::
Document
*
_createPolygonArray
(
const
U
&
msg
,
Int2Type
<
k
>
){
// U has member header(), use integraded header.
rapidjson
::
Document
*
_createPolygonArray
(
const
U
&
msg
,
Int2Type
<
k
>
){
// U has member header(), use integraded header.
using
namespace
ROSBridge
;
using
namespace
ROSBridge
;
rapidjson
::
Document
*
doc
=
new
rapidjson
::
Document
(
rapidjson
::
kObjectType
);
rapidjson
::
Document
*
doc
=
new
rapidjson
::
Document
(
rapidjson
::
kObjectType
);
bool
ret
=
JsonMethodes
::
JSKRecognitionMsg
::
PolygonArray
::
toJson
(
msg
,
*
doc
,
doc
->
GetAllocator
());
bool
ret
=
JsonMethodes
::
JSKRecognitionMsg
s
::
PolygonArray
::
toJson
(
msg
,
*
doc
,
doc
->
GetAllocator
());
assert
(
ret
);
assert
(
ret
);
(
void
)
ret
;
(
void
)
ret
;
...
@@ -163,9 +163,9 @@ private:
...
@@ -163,9 +163,9 @@ private:
template
<
class
U
>
template
<
class
U
>
rapidjson
::
Document
*
_createPolygonArray
(
const
U
&
msg
,
Int2Type
<
0
>
){
// U has no member header(), generate one on the fly.
rapidjson
::
Document
*
_createPolygonArray
(
const
U
&
msg
,
Int2Type
<
0
>
){
// U has no member header(), generate one on the fly.
using
namespace
ROSBridge
;
using
namespace
ROSBridge
;
JsonMethodes
::
Header
::
Header
header
(
HeaderPolicy
::
header
(
msg
));
GenericMessages
::
StdMsgs
::
Header
header
(
HeaderPolicy
::
header
(
msg
));
rapidjson
::
Document
*
doc
=
new
rapidjson
::
Document
(
rapidjson
::
kObjectType
);
rapidjson
::
Document
*
doc
=
new
rapidjson
::
Document
(
rapidjson
::
kObjectType
);
bool
ret
=
JsonMethodes
::
JSKRecognitionMsg
::
PolygonArray
::
toJson
(
msg
,
header
,
*
doc
,
doc
->
GetAllocator
());
bool
ret
=
JsonMethodes
::
JSKRecognitionMsg
s
::
PolygonArray
::
toJson
(
msg
,
header
,
*
doc
,
doc
->
GetAllocator
());
assert
(
ret
);
assert
(
ret
);
(
void
)
ret
;
(
void
)
ret
;
...
@@ -187,8 +187,10 @@ private:
...
@@ -187,8 +187,10 @@ private:
}
}
};
};
class
StdHeaderPolicy
{
class
StdHeaderPolicy
namespace
StdMsgs
=
ROSBridge
::
GenericMessages
::
StdMsgs
;
{
typedef
ROSBridge
::
GenericMessages
::
StdMsgs
::
Header
Header
;
typedef
ROSBridge
::
GenericMessages
::
StdMsgs
::
Time
Time
;
public:
public:
StdHeaderPolicy
()
:
_seq
(
-
1
){};
StdHeaderPolicy
()
:
_seq
(
-
1
){};
...
@@ -196,24 +198,25 @@ public:
...
@@ -196,24 +198,25 @@ public:
//! \brief header Returns the header belonging to msg.
//! \brief header Returns the header belonging to msg.
//! \return Returns the header belonging to msg.
//! \return Returns the header belonging to msg.
//!
//!
template
<
typename
T
>
Header
header
(
const
ROSBridge
::
MessageBaseClass
&
msg
)
{
StdMsgs
::
Header
header
(
const
T
&
msg
)
{
return
Header
(
++
_seq
,
time
(
msg
),
"/map"
);
return
StdMsgs
::
Header
(
++
_seq
,
time
(
msg
),
"/map"
);
}
}
//!
//!
//! \brief time Returns the current time.
//! \brief time Returns the current time.
//! \return Returns the current time.
//! \return Returns the current time.
template
<
typename
T
>
Time
time
(
const
ROSBridge
::
MessageBaseClass
&
msg
)
{
StdMsgs
::
Time
time
(
const
T
&
msg
)
{
(
void
)
msg
;
(
void
)
msg
;
return
StdMsgs
::
Time
(
0
,
0
);
return
Time
(
0
,
0
);
}
}
private:
private:
long
_seq
;
long
_seq
;
};
};
typedef
GenericJsonFactory
<>
JsonFactory
;
}
// end namespace ros_bridge
}
// end namespace ros_bridge
src/comm/ros_bridge/include/JsonMethodes.h
View file @
7101ad22
...
@@ -636,7 +636,7 @@ namespace Progress {
...
@@ -636,7 +636,7 @@ namespace Progress {
progressJson
.
PushBack
(
rapidjson
::
Value
().
SetInt
(
std
::
int8_t
(
p
.
progress
()[
i
])),
allocator
);
progressJson
.
PushBack
(
rapidjson
::
Value
().
SetInt
(
std
::
int8_t
(
p
.
progress
()[
i
])),
allocator
);
}
}
value
.
AddMember
(
"progress"
,
progressJson
,
allocator
);
value
.
AddMember
(
"progress"
,
progressJson
,
allocator
);
return
true
;
}
}
template
<
class
ProgressType
>
template
<
class
ProgressType
>
...
...
src/comm/ros_bridge/include/MessageGroups.h
View file @
7101ad22
...
@@ -10,7 +10,7 @@ typedef std::string StringType;
...
@@ -10,7 +10,7 @@ typedef std::string StringType;
template
<
typename
Group
,
typename
SubGroup
,
typename
...
MoreSubGroups
>
template
<
typename
Group
,
typename
SubGroup
,
typename
...
MoreSubGroups
>
struct
MessageGroup
{
struct
MessageGroup
{
static
StringType
message
NameFull
()
{
return
_full
<
Group
,
SubGroup
,
MoreSubGroups
...
>
();}
static
StringType
message
Type
()
{
return
_full
<
Group
,
SubGroup
,
MoreSubGroups
...
>
();}
template
<
typename
G
,
typename
SubG
,
typename
...
MoreSubG
>
template
<
typename
G
,
typename
SubG
,
typename
...
MoreSubG
>
static
StringType
_full
()
{
return
G
::
label
()
+
"/"
+
_full
<
SubG
,
MoreSubG
...
>
();
}
static
StringType
_full
()
{
return
G
::
label
()
+
"/"
+
_full
<
SubG
,
MoreSubG
...
>
();
}
...
@@ -18,7 +18,7 @@ struct MessageGroup {
...
@@ -18,7 +18,7 @@ struct MessageGroup {
static
StringType
_full
()
{
return
G
::
label
();
}
static
StringType
_full
()
{
return
G
::
label
();
}
static
StringType
message
Nam
eLast
()
{
return
_last
<
Group
,
SubGroup
,
MoreSubGroups
...
>
();}
static
StringType
message
Typ
eLast
()
{
return
_last
<
Group
,
SubGroup
,
MoreSubGroups
...
>
();}
template
<
typename
G
,
typename
SubG
,
typename
...
MoreSubG
>
template
<
typename
G
,
typename
SubG
,
typename
...
MoreSubG
>
static
StringType
_last
()
{
return
_last
<
SubG
,
MoreSubG
...
>
();
}
static
StringType
_last
()
{
return
_last
<
SubG
,
MoreSubG
...
>
();
}
...
...
src/comm/ros_bridge/include/MessageTag.cpp
0 → 100644
View file @
7101ad22
#include "MessageTag.h"
MessageTag
::
MessageTag
()
{
}
MessageTag
::
MessageTag
(
const
std
::
string
&
topic
,
const
std
::
string
&
messageType
)
:
_topic
(
topic
)
,
_messagType
(
messageType
)
{
}
const
std
::
string
&
MessageTag
::
topic
()
const
{
return
_topic
;
}
const
std
::
string
&
MessageTag
::
messageType
()
const
{
return
_messagType
;
}
std
::
string
&
MessageTag
::
topic
()
{
return
_topic
;
}
std
::
string
&
MessageTag
::
messageType
()
{
return
_messagType
;
}
void
MessageTag
::
setTopic
(
const
std
::
string
&
topic
)
{
_topic
=
topic
;
}
void
MessageTag
::
setMessageType
(
const
std
::
string
&
messageType
)
{
_messagType
=
messageType
;
}
src/comm/ros_bridge/include/MessageTag.h
0 → 100644
View file @
7101ad22
#pragma once
#include <string>
class
MessageTag
{
public:
MessageTag
();
MessageTag
(
const
std
::
string
&
topic
,
const
std
::
string
&
messageType
);
const
std
::
string
&
topic
()
const
;
const
std
::
string
&
messageType
()
const
;
std
::
string
&
topic
();
std
::
string
&
messageType
();
void
setTopic
(
const
std
::
string
&
topic
);
void
setMessageType
(
const
std
::
string
&
messageType
);
private:
std
::
string
_topic
;
std
::
string
_messagType
;
};
typedef
MessageTag
Tag
;
src/comm/ros_bridge/include/Package
Buffer
.h
→
src/comm/ros_bridge/include/Package
Queue
.h
View file @
7101ad22
...
@@ -5,13 +5,12 @@
...
@@ -5,13 +5,12 @@
#include <functional>
#include <functional>
namespace
ROSBridge
{
namespace
ROSBridge
{
namespace
Bridge
{
namespace
lf
=
::
boost
::
lockfree
;
namespace
lf
=
::
boost
::
lockfree
;
template
<
class
T
>
template
<
class
T
>
class
Package
Buffer
class
Package
Queue
{
{
public:
public:
Package
Buffer
();
Package
Queue
();
void
push
(
T
t
)
{
void
push
(
T
t
)
{
buffer
.
push
(
t
);
buffer
.
push
(
t
);
...
@@ -41,7 +40,5 @@ private:
...
@@ -41,7 +40,5 @@ private:
std
::
function
<
void
(
void
)
>
_pushCallback
;
std
::
function
<
void
(
void
)
>
_pushCallback
;
};
};
}
// namespace Communicator
}
// namespace
}
// namespace
src/comm/ros_bridge/include/ROSCommunicator.h
View file @
7101ad22
#pragma once
#pragma once
#include "ros_bridge/rapidjson/include/rapidjson/document.h"
#include "ros_bridge/rapidjson/include/rapidjson/document.h"
#include "ros_bridge/include/PackageQueue.h"
#include "ros_bridge/include/CasePacker.h"
#include <memory>
#include <memory>
#include <tuple>
#include <tuple>
#include "boost/lockfree/queue.hpp"
#include "boost/lockfree/queue.hpp"
#include "ros_bridge/include/
namespace
ROSBridge
{
namespace
ROSBridge
{
namespace
lf
=
::
boost
::
lockfree
;
namespace
lf
=
::
boost
::
lockfree
;
class
Communicator
class
Communicator
:
protected
CasePacker
{
{
typedef
std
::
unique_ptr
<
rapidjson
::
Document
>
UniqueJsonPtr
;
typedef
MessageTag
Tag
;
typedef
std
::
tuple
<
UniqueJsonPtr
,
std
::
string
>
MsgTopicHashPair
;
typedef
rapidjson
::
Document
JsonDoc
;
typedef
std
::
shared_ptr
<
JsonDoc
>
JsonDocShardPtr
;
typedef
PackageQueue
<
JsonDocShardPtr
>
Buffer
;
//typedef std::tuple<UniqueJsonPtr, std::string> MsgTopicHashPair;
public:
public:
explicit
Communicator
()
{}
explicit
Communicator
()
:
CasePacker
()
{}
template
<
class
T
>
void
send
(
T
&
msg
,
std
::
string
&
topic
){
JsonDocShardPtr
docPtr
(
CasePacker
::
pack
(
msg
,
topic
));
_transmittBuffer
.
push
(
docPtr
);
}
void
send
(
UniqueJsonPtr
&
msg
);
void
start
();
void
start
();
void
stop
();
void
stop
();
virtual
UniqueJsonPtr
receive
()
=
0
;
bool
messagesAvailable
();
bool
showMessageTag
(
Tag
&
tag
);
template
<
class
T
>
void
receive
(
T
&
msg
){
}
private:
private:
lf
::
queue
<
MsgTopicPair
>
_transmittBuffer
;
Buffer
_transmittBuffer
;
lf
::
queue
<
MsgTopicPair
>
_receiveBuffer
;
Buffer
_receiveBuffer
;
JsonDocShardPtr
_stagedMessage
;
// message awaiting delivery
};
};
}
}
src/comm/ros_bridge/src/CasePacker.cpp
View file @
7101ad22
#include "CasePacker.h"
#include "
ros_bridge/include/
CasePacker.h"
const
char
*
ROSBridge
::
CasePacker
::
topicKey
=
"topic"
;
const
char
*
ROSBridge
::
CasePacker
::
topicKey
=
"topic"
;
const
char
*
ROSBridge
::
CasePacker
::
messageTypeKey
=
"messageType"
;
const
char
*
ROSBridge
::
CasePacker
::
messageTypeKey
=
"messageType"
;
...
@@ -8,7 +8,16 @@ ROSBridge::CasePacker::CasePacker()
...
@@ -8,7 +8,16 @@ ROSBridge::CasePacker::CasePacker()
}
}
void
ROSBridge
::
CasePacker
::
_addTag
(
JsonDoc
&
doc
,
const
char
*
topic
,
const
char
*
messageType
)
bool
ROSBridge
::
CasePacker
::
showTag
(
const
ROSBridge
::
CasePacker
::
JsonDoc
&
doc
,
Tag
&
tag
)
{
if
(
!
_getTopic
(
doc
,
tag
.
topic
())
)
return
false
;
if
(
!
_getMessageType
(
doc
,
tag
.
messageType
())
)
return
false
;
return
true
;
}
void
ROSBridge
::
CasePacker
::
_addTag
(
JsonDoc
&
doc
,
const
std
::
string
&
topic
,
const
std
::
string
&
messageType
)
{
{
using
namespace
ROSBridge
;
using
namespace
ROSBridge
;
using
namespace
rapidjson
;
using
namespace
rapidjson
;
...
@@ -16,13 +25,13 @@ void ROSBridge::CasePacker::_addTag(JsonDoc &doc, const char *topic, const char
...
@@ -16,13 +25,13 @@ void ROSBridge::CasePacker::_addTag(JsonDoc &doc, const char *topic, const char
{
{
// add topic
// add topic
rapidjson
::
Value
key
(
CasePacker
::
topicKey
,
doc
.
GetAllocator
());
rapidjson
::
Value
key
(
CasePacker
::
topicKey
,
doc
.
GetAllocator
());
rapidjson
::
Value
value
(
topic
,
doc
.
GetAllocator
());
rapidjson
::
Value
value
(
topic
.
c_str
()
,
doc
.
GetAllocator
());
doc
.
AddMember
(
key
,
value
,
doc
.
GetAllocator
());
doc
.
AddMember
(
key
,
value
,
doc
.
GetAllocator
());
}
}
// add messageType
// add messageType
rapidjson
::
Value
key
(
CasePacker
::
messageTypeKey
,
doc
.
GetAllocator
());
rapidjson
::
Value
key
(
CasePacker
::
messageTypeKey
,
doc
.
GetAllocator
());
rapidjson
::
Value
value
(
messageType
,
doc
.
GetAllocator
());
rapidjson
::
Value
value
(
messageType
.
c_str
()
,
doc
.
GetAllocator
());
doc
.
AddMember
(
key
,
value
,
doc
.
GetAllocator
());
doc
.
AddMember
(
key
,
value
,
doc
.
GetAllocator
());
}
}
...
@@ -36,4 +45,18 @@ void ROSBridge::CasePacker::_removeTag(JsonDoc &doc)
...
@@ -36,4 +45,18 @@ void ROSBridge::CasePacker::_removeTag(JsonDoc &doc)
doc
.
RemoveMember
(
CasePacker
::
messageTypeKey
);
doc
.
RemoveMember
(
CasePacker
::
messageTypeKey
);
}
}
bool
ROSBridge
::
CasePacker
::
_getTopic
(
const
ROSBridge
::
CasePacker
::
JsonDoc
&
doc
,
std
::
string
&
topic
)
{
if
(
!
doc
.
HasMember
(
CasePacker
::
topicKey
)
||
!
doc
[
CasePacker
::
topicKey
].
IsString
())
return
false
;
topic
=
doc
[
CasePacker
::
topicKey
].
GetString
();
return
true
;
}
bool
ROSBridge
::
CasePacker
::
_getMessageType
(
const
ROSBridge
::
CasePacker
::
JsonDoc
&
doc
,
std
::
string
&
messageType
)
{
if
(
!
doc
.
HasMember
(
CasePacker
::
messageTypeKey
)
||
!
doc
[
CasePacker
::
messageTypeKey
].
IsString
())
return
false
;
messageType
=
doc
[
CasePacker
::
messageTypeKey
].
GetString
();
return
true
;
}
src/comm/ros_bridge/src/CasePacker.h
deleted
100644 → 0
View file @
a15105e3
#pragma once
#include "ros_bridge/include/MessageBaseClass.h"
#include <memory>
#include "rapidjson/include/rapidjson/document.h"
namespace
ROSBridge
{
class
CasePacker
{
typedef
rapidjson
::
Document
JsonDoc
;
typedef
std
::
unique_ptr
<
JsonDoc
>
UniqueJsonPtr
;
public:
CasePacker
();
struct
MessageTag
{
char
*
topic
;
char
*
messagType
;
};
typedef
MessageTag
Tag
;
template
<
class
T
>
void
packAndSend
(
const
T
&
msg
,
const
char
*
topic
);
const
Tag
&
showTag
();
template
<
class
T
>
void
unpack
(
T
&
msg
);
protected:
void
_addTag
(
JsonDoc
&
doc
,
const
char
*
topic
,
const
char
*
messageType
);
void
_removeTag
(
JsonDoc
&
doc
);
static
const
char
*
topicKey
;
static
const
char
*
messageTypeKey
;
private:
Tag
_tag
;
};
}
src/comm/ros_bridge/src/ROSCommunicator.cpp
View file @
7101ad22
#include "ros_bridge/include/ROSCommunicator.h"
#include "ros_bridge/include/ROSCommunicator.h"
void
ROSBridge
::
Communicator
::
send
(
ROSBridge
::
Communicator
::
UniqueJsonPtr
&
msg
)
bool
ROSBridge
::
Communicator
::
messagesAvailable
(
)
{
{
if
(
!
msg
->
HasMember
(
""
))
return
!
_receiveBuffer
.
empty
()
||
_stagedMessage
;
}
bool
ROSBridge
::
Communicator
::
showMessageTag
(
ROSBridge
::
Communicator
::
Tag
&
tag
)
{
if
(
!
_stagedMessage
)
_stagedMessage
=
_receiveBuffer
.
pop
();
return
ROSBridge
::
Communicator
::
CasePacker
::
showTag
(
*
_stagedMessage
.
get
(),
tag
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment