Program Listing for File SVHControlCommand.h
↰ Return to documentation for file (/tmp/ws/src/schunk_svh_library/include/schunk_svh_library/control/SVHControlCommand.h
)
//
// © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
// © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
//
// This file is part of the Schunk SVH Library.
//
// The Schunk SVH Library is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// The Schunk SVH Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the Schunk SVH Library. If not, see <https://www.gnu.org/licenses/>.
//
//----------------------------------------------------------------------
//----------------------------------------------------------------------
#ifndef SVHCONTROLCOMMAND_H
#define SVHCONTROLCOMMAND_H
#include <schunk_svh_library/serial/ByteOrderConversion.h>
namespace driver_svh {
struct SVHControlCommand
{
int32_t position;
SVHControlCommand(const int32_t& position = 0)
: position(position)
{
}
bool operator==(const SVHControlCommand& other) const { return (position == other.position); }
};
struct SVHControlCommandAllChannels
{
std::vector<SVHControlCommand> commands;
SVHControlCommandAllChannels(const int32_t& position0,
const int32_t& position1,
const int32_t& position2,
const int32_t& position3,
const int32_t& position4,
const int32_t& position5,
const int32_t& position6,
const int32_t& position7,
const int32_t& position8)
{
commands.push_back(SVHControlCommand(position0));
commands.push_back(SVHControlCommand(position1));
commands.push_back(SVHControlCommand(position2));
commands.push_back(SVHControlCommand(position3));
commands.push_back(SVHControlCommand(position4));
commands.push_back(SVHControlCommand(position5));
commands.push_back(SVHControlCommand(position6));
commands.push_back(SVHControlCommand(position7));
commands.push_back(SVHControlCommand(position8));
}
SVHControlCommandAllChannels(const std::vector<int32_t>& positions)
{
commands.insert(commands.begin(), positions.begin(), positions.begin() + 9);
}
SVHControlCommandAllChannels()
: commands(9, SVHControlCommand())
{
}
bool operator==(const SVHControlCommandAllChannels& other) const
{
return (commands == other.commands);
}
};
inline driver_svh::ArrayBuilder& operator<<(driver_svh::ArrayBuilder& ab,
const SVHControlCommand& data)
{
ab << data.position;
return ab;
}
inline driver_svh::ArrayBuilder& operator>>(driver_svh::ArrayBuilder& ab, SVHControlCommand& data)
{
ab >> data.position;
return ab;
}
inline std::ostream& operator<<(std::ostream& o, const SVHControlCommand& cc)
{
o << "Pos: " << cc.position << std::endl;
return o;
}
inline driver_svh::ArrayBuilder& operator<<(driver_svh::ArrayBuilder& ab,
const SVHControlCommandAllChannels& data)
{
// We could also just give the whole vector in ...
for (std::vector<SVHControlCommand>::const_iterator it = data.commands.begin();
it != data.commands.end();
++it)
{
ab << *it;
}
return ab;
}
inline driver_svh::ArrayBuilder& operator>>(driver_svh::ArrayBuilder& ab,
SVHControlCommandAllChannels& data)
{
for (std::vector<SVHControlCommand>::iterator it = data.commands.begin();
it != data.commands.end();
++it)
{
ab >> *it;
}
return ab;
}
inline std::ostream& operator<<(std::ostream& o, const SVHControlCommandAllChannels& cc)
{
o << "Commands: ";
unsigned int i = 0;
for (std::vector<SVHControlCommand>::const_iterator it = cc.commands.begin();
it != cc.commands.end();
++it)
{
o << "Chan " << i << " : " << *it;
++i;
}
o << std::endl;
return o;
}
} // namespace driver_svh
#endif // SVHCONTROLCOMMAND_H