Program Listing for File SVHControllerState.h

Return to documentation for file (/tmp/ws/src/schunk_svh_library/include/schunk_svh_library/control/SVHControllerState.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 SVHCONTROLLERSTATE_H
#define SVHCONTROLLERSTATE_H

#include <schunk_svh_library/serial/ByteOrderConversion.h>

namespace driver_svh {

struct SVHControllerState
{
  uint16_t pwm_fault;
  uint16_t pwm_otw;
  uint16_t pwm_reset;
  uint16_t pwm_active;
  uint16_t pos_ctrl;
  uint16_t cur_ctrl;

  SVHControllerState(uint16_t pwm_fault  = 0,
                     uint16_t pwm_otw    = 0,
                     uint16_t pwm_reset  = 0,
                     uint16_t pwm_active = 0,
                     uint16_t pos_ctrl   = 0,
                     uint16_t cur_ctrl   = 0)
    : pwm_fault(pwm_fault)
    , pwm_otw(pwm_otw)
    , pwm_reset(pwm_reset)
    , pwm_active(pwm_active)
    , pos_ctrl(pos_ctrl)
    , cur_ctrl(cur_ctrl)
  {
  }

  bool operator==(const SVHControllerState& other) const
  {
    return (pwm_fault == other.pwm_fault && pwm_otw == other.pwm_otw &&
            pwm_reset == other.pwm_reset && pwm_active == other.pwm_active &&
            pos_ctrl == other.pos_ctrl && cur_ctrl == other.cur_ctrl);
  }
};

inline driver_svh::ArrayBuilder& operator<<(driver_svh::ArrayBuilder& ab,
                                            const SVHControllerState& data)
{
  ab << data.pwm_fault << data.pwm_otw << data.pwm_reset << data.pwm_active << data.pos_ctrl
     << data.cur_ctrl;
  return ab;
}

inline driver_svh::ArrayBuilder& operator>>(driver_svh::ArrayBuilder& ab, SVHControllerState& data)
{
  ab >> data.pwm_fault >> data.pwm_otw >> data.pwm_reset >> data.pwm_active >> data.pos_ctrl >>
    data.cur_ctrl;

  return ab;
}

inline std::ostream& operator<<(std::ostream& o, const SVHControllerState& cs)
{
  o << std::setw(4) << std::setfill('0') << std::hex << "pwm_fault "
    << "0x" << static_cast<int>(cs.pwm_fault) << " "
    << "pwm_otw "
    << "0x" << static_cast<int>(cs.pwm_otw) << " "
    << "pwm_reset "
    << "0x" << static_cast<int>(cs.pwm_reset) << " "
    << "pwm_active "
    << "0x" << static_cast<int>(cs.pwm_active) << " "
    << "pos_ctr "
    << "0x" << static_cast<int>(cs.pos_ctrl) << " "
    << "cur_ctrl "
    << "0x" << static_cast<int>(cs.cur_ctrl) << " " << std::endl;
  // Reset Output stream to decimal output .. otherwise it may confuse people
  std::cout << std::dec;
  return o;
}

} // namespace driver_svh


#endif // SVHCONTROLLERSTATE_H