src
serial
SVHSerialPacket.cpp
Go to the documentation of this file.
1
//
3
// © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
4
// © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
5
//
6
// This file is part of the Schunk SVH Library.
7
//
8
// The Schunk SVH Library is free software: you can redistribute it and/or
9
// modify it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation, either version 3 of the License, or (at your
11
// option) any later version.
12
//
13
// The Schunk SVH Library is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16
// Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License along with
19
// the Schunk SVH Library. If not, see <https://www.gnu.org/licenses/>.
20
//
22
23
//----------------------------------------------------------------------
35
//----------------------------------------------------------------------
36
#include <
schunk_svh_library/serial/SVHSerialPacket.h
>
37
38
namespace
driver_svh
{
39
40
driver_svh::ArrayBuilder
&
operator<<
(
driver_svh::ArrayBuilder
& ab,
const
SVHSerialPacket
& data)
41
{
42
ab << data.
index
<< data.
address
<<
static_cast<
uint16_t
>
(data.
data
.size()) << data.
data
;
43
return
ab;
44
}
45
46
driver_svh::ArrayBuilder
&
operator>>
(
driver_svh::ArrayBuilder
& ab,
SVHSerialPacket
& data)
47
{
48
// Disregard the size when deserializing as we get that anyway
49
uint16_t size;
50
ab >> data.
index
>> data.
address
>> size >> data.
data
;
51
return
ab;
52
}
53
54
std::ostream&
operator<<
(std::ostream& o,
const
SVHSerialPacket
& sp)
55
{
56
o <<
"index: "
<<
static_cast<
int
>
(sp.
index
) <<
" address: "
57
<<
"0x"
<< std::setw(2) << std::setfill(
'0'
) << std::hex << static_cast<int>(sp.
address
)
58
<<
" Data: "
;
59
for
(
size_t
i = 0; i < sp.
data
.size(); i++)
60
{
61
o <<
"0x"
<< std::setw(2) << std::setfill(
'0'
) << std::hex << static_cast<int>(sp.
data
[i])
62
<<
" "
;
63
}
64
// Reset Output stream to decimal output .. otherwise it may confuse people and the stream
65
// operators have the tendency to hang on to these hints
66
std::cout << std::dec;
67
return
o;
68
}
69
70
}
// namespace driver_svh
driver_svh::SVHSerialPacket
The SerialPacket holds the (non generated) header and data of one message to the SVH-Hardware.
Definition:
SVHSerialPacket.h:80
driver_svh::ArrayBuilder
Definition:
ByteOrderConversion.h:146
driver_svh::SVHSerialPacket::data
std::vector< uint8_t > data
Payload of the package.
Definition:
SVHSerialPacket.h:89
driver_svh::SVHSerialPacket::index
uint8_t index
Continuosly incremented counter per package.
Definition:
SVHSerialPacket.h:85
driver_svh
Definition:
SVHControlCommand.h:39
SVHSerialPacket.h
driver_svh::SVHSerialPacket::address
uint8_t address
Adress denotes the actual function of the package.
Definition:
SVHSerialPacket.h:87
driver_svh::operator>>
driver_svh::ArrayBuilder & operator>>(driver_svh::ArrayBuilder &ab, SVHControlCommand &data)
overload stream operator to easily deserialize control commands for one channel
Definition:
SVHControlCommand.h:143
driver_svh::operator<<
driver_svh::ArrayBuilder & operator<<(driver_svh::ArrayBuilder &ab, const SVHControlCommand &data)
Definition:
SVHControlCommand.h:134
schunk_svh_library
Author(s): Georg Heppner, Lars Pfotzer, Felix Exner, Johannes Mangler, Stefan Scherzinger, Pascal Becker
autogenerated on Fri Apr 14 2023 02:53:52