Skip to content

Commit a910b03

Browse files
authored
Merge pull request #56 from RAMLABNL/8bit-support
8bit support
2 parents a7e88cf + 9b6e59a commit a910b03

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

src/MessageRouter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace eipScanner {
2222
using eip::EncapsPacket;
2323
using eip::EncapsPacketFactory;
2424

25-
MessageRouter::MessageRouter() = default;
25+
MessageRouter::MessageRouter(bool use_8_bit_path_segments)
26+
: _use_8_bit_path_segments(use_8_bit_path_segments)
27+
{};
2628

2729
MessageRouter::~MessageRouter() = default;
2830

@@ -41,7 +43,7 @@ namespace eipScanner {
4143
Logger(LogLevel::INFO) << "Send request: service=0x" << std::hex << static_cast<int>(service)
4244
<< " epath=" << path.toString();
4345

44-
MessageRouterRequest request{service, path, data};
46+
MessageRouterRequest request{service, path, data, _use_8_bit_path_segments};
4547

4648
CommonPacketItemFactory commonPacketItemFactory;
4749
CommonPacket commonPacket;

src/MessageRouter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ namespace eipScanner {
2222
public:
2323
using SPtr = std::shared_ptr<MessageRouter>;
2424

25+
static constexpr bool USE_8_BIT_PATH_SEGMENTS = true;
26+
2527
/**
2628
* @brief Default constructor
2729
*/
28-
MessageRouter();
30+
MessageRouter(bool use_8_bit_path_segments=false);
2931

3032
/**
3133
* @brief Default destructor
@@ -72,6 +74,8 @@ namespace eipScanner {
7274
virtual cip::MessageRouterResponse sendRequest(SessionInfoIf::SPtr si, cip::CipUsint service,
7375
const cip::EPath& path) const;
7476

77+
private:
78+
bool _use_8_bit_path_segments;
7579
};
7680
}
7781

src/cip/EPath.cpp

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,45 @@ namespace cip {
4949
, _size{3} {
5050
}
5151

52-
std::vector<uint8_t> EPath::packPaddedPath() const {
53-
Buffer buffer(_size*4);
54-
55-
auto classSegment = static_cast<CipUint>(EPathSegmentTypes::CLASS_16_BITS);
56-
buffer << classSegment << _classId;
57-
58-
if (_size > 1) {
59-
auto instanceSegment = static_cast<CipUint>(EPathSegmentTypes::INSTANCE_16_BITS);
60-
buffer << instanceSegment << _objectId;
61-
62-
if (_size > 2) {
63-
auto attributeSegment = static_cast<CipUint>(EPathSegmentTypes::ATTRIBUTE_16_BITS);
64-
buffer << attributeSegment << _attributeId;
65-
}
66-
}
67-
68-
return buffer.data();
52+
std::vector<uint8_t> EPath::packPaddedPath(bool use_8_bit_path_segments) const {
53+
if (use_8_bit_path_segments)
54+
{
55+
Buffer buffer(_size*2);
56+
57+
auto classSegment = static_cast<CipUsint>(EPathSegmentTypes::CLASS_8_BITS);
58+
buffer << classSegment << static_cast<CipUsint>(_classId);
59+
60+
if (_size > 1) {
61+
auto instanceSegment = static_cast<CipUsint>(EPathSegmentTypes::INSTANCE_8_BITS);
62+
buffer << instanceSegment << static_cast<CipUsint>(_objectId);
63+
64+
if (_size > 2) {
65+
auto attributeSegment = static_cast<CipUsint>(EPathSegmentTypes::ATTRIBUTE_8_BITS);
66+
buffer << attributeSegment << static_cast<CipUsint>(_attributeId);
67+
}
68+
}
69+
70+
return buffer.data();
71+
}
72+
else
73+
{
74+
Buffer buffer(_size*4);
75+
76+
auto classSegment = static_cast<CipUint>(EPathSegmentTypes::CLASS_16_BITS);
77+
buffer << classSegment << _classId;
78+
79+
if (_size > 1) {
80+
auto instanceSegment = static_cast<CipUint>(EPathSegmentTypes::INSTANCE_16_BITS);
81+
buffer << instanceSegment << _objectId;
82+
83+
if (_size > 2) {
84+
auto attributeSegment = static_cast<CipUint>(EPathSegmentTypes::ATTRIBUTE_16_BITS);
85+
buffer << attributeSegment << _attributeId;
86+
}
87+
}
88+
89+
return buffer.data();
90+
}
6991
}
7092

7193
CipUint EPath::getClassId() const {
@@ -80,8 +102,13 @@ namespace cip {
80102
return _attributeId;
81103
}
82104

83-
CipUsint EPath::getSizeInWords() const {
84-
return _size*2;
105+
CipUsint EPath::getSizeInWords(bool use_8_bit_path_segments) const {
106+
if (use_8_bit_path_segments) {
107+
return _size;
108+
}
109+
else {
110+
return _size*2;
111+
}
85112
}
86113

87114
std::string EPath::toString() const {

src/cip/EPath.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ namespace cip {
1919
explicit EPath(CipUint classId);
2020
EPath(CipUint classId, CipUint objectId);
2121
EPath(CipUint classId, CipUint objectId, CipUint attributeId);
22-
std::vector<uint8_t> packPaddedPath() const;
22+
std::vector<uint8_t> packPaddedPath(bool use_8_bit_path_segments=false) const;
2323
void expandPaddedPath(const std::vector<uint8_t>& data);
2424

2525
CipUint getClassId() const;
2626
CipUint getObjectId() const;
2727
CipUint getAttributeId() const;
28-
CipUsint getSizeInWords() const;
28+
CipUsint getSizeInWords(bool use_8_bit_path_segments=false) const;
2929

3030
std::string toString() const;
3131
bool operator==(const EPath& other) const;

src/cip/MessageRouterRequest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ namespace cip {
1111
using utils::Buffer;
1212

1313
MessageRouterRequest::MessageRouterRequest(CipUsint serviceCode,
14-
const EPath& ePath, const std::vector<uint8_t> data)
14+
const EPath& ePath, const std::vector<uint8_t> data, bool use_8_bit_path_segments)
1515
: _serviceCode{serviceCode}
1616
, _ePath{ePath}
17-
, _data(data) {
17+
, _data(data)
18+
, _use_8_bit_path_segments(use_8_bit_path_segments) {
1819
}
1920

2021
MessageRouterRequest::~MessageRouterRequest() = default;
2122

2223
std::vector<uint8_t> MessageRouterRequest::pack() const {
2324
Buffer buffer;
2425
buffer << _serviceCode
25-
<< _ePath.getSizeInWords()
26-
<< _ePath.packPaddedPath()
26+
<< _ePath.getSizeInWords(_use_8_bit_path_segments)
27+
<< _ePath.packPaddedPath(_use_8_bit_path_segments)
2728
<< _data;
2829

2930
return buffer.data();

src/cip/MessageRouterRequest.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ namespace eipScanner {
1515
namespace cip {
1616
class MessageRouterRequest {
1717
public:
18-
MessageRouterRequest(CipUsint serviceCode, const EPath& ePath, const std::vector<uint8_t> data);
18+
MessageRouterRequest(CipUsint serviceCode, const EPath& ePath, const std::vector<uint8_t> data, bool use_8_bit_path_segments=false);
1919
~MessageRouterRequest();
2020

2121
std::vector<uint8_t> pack() const;
2222
private:
2323
CipUsint _serviceCode;
2424
EPath _ePath;
2525
std::vector<uint8_t> _data;
26+
bool _use_8_bit_path_segments;
2627
};
2728

2829
}

0 commit comments

Comments
 (0)