Program Listing for File SVHSerialPacket.h

Return to documentation for file (/tmp/ws/src/schunk_svh_library/include/schunk_svh_library/serial/SVHSerialPacket.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 SVHSERIALPACKET_H
#define SVHSERIALPACKET_H

#include <schunk_svh_library/serial/ByteOrderConversion.h>

namespace driver_svh {

//===============
// Some constants
//===============

// packet sizes
const size_t C_PACKET_APPENDIX_SIZE = 8;
const size_t C_DEFAULT_PACKET_SIZE  = 48;

// packet headers
const uint8_t PACKET_HEADER1 = 0x4C;
const uint8_t PACKET_HEADER2 = 0xAA;

// adress constants for commands
const uint8_t SVH_GET_CONTROL_FEEDBACK =
  0x00;
const uint8_t SVH_SET_CONTROL_COMMAND = 0x01;
const uint8_t SVH_GET_CONTROL_FEEDBACK_ALL =
  0x02;
const uint8_t SVH_SET_CONTROL_COMMAND_ALL = 0x03;
const uint8_t SVH_GET_POSITION_SETTINGS =
  0x04;
const uint8_t SVH_SET_POSITION_SETTINGS = 0x05;
const uint8_t SVH_GET_CURRENT_SETTINGS =
  0x06;
const uint8_t SVH_SET_CURRENT_SETTINGS = 0x07;
const uint8_t SVH_GET_CONTROLLER_STATE =
  0x08;
const uint8_t SVH_SET_CONTROLLER_STATE =
  0x09;
const uint8_t SVH_GET_ENCODER_VALUES = 0x0A;
const uint8_t SVH_SET_ENCODER_VALUES = 0x0B;
const uint8_t SVH_GET_FIRMWARE_INFO  = 0x0C;

struct SVHSerialPacket
{
  uint8_t index;
  uint8_t address;
  std::vector<uint8_t> data;

  SVHSerialPacket(size_t data_length = 0, uint8_t address = SVH_GET_CONTROL_FEEDBACK)
    : address(address)
    , data(data_length, 0)
  {
  }

  bool operator==(const SVHSerialPacket& other) const
  {
    return (index == other.index && address == other.address && data == other.data);
  }
};

driver_svh::ArrayBuilder& operator<<(driver_svh::ArrayBuilder& ab, const SVHSerialPacket& data);

driver_svh::ArrayBuilder& operator>>(driver_svh::ArrayBuilder& ab, SVHSerialPacket& data);

std::ostream& operator<<(std::ostream& o, const SVHSerialPacket& sp);

} // namespace driver_svh
#endif // SVHSERIALPACKET_H