Program Listing for File dashboard_client.h

Return to documentation for file (include/ur_client_library/ur/dashboard_client.h)

// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-

// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2019 FZI Forschungszentrum Informatik
// Created on behalf of Universal Robots A/S
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
//----------------------------------------------------------------------
#ifndef UR_ROBOT_DRIVER_DASHBOARD_CLIENT_DASHBOARD_CLIENT_H_INCLUDED
#define UR_ROBOT_DRIVER_DASHBOARD_CLIENT_DASHBOARD_CLIENT_H_INCLUDED

#include <ur_client_library/comm/tcp_socket.h>
#include <ur_client_library/ur/version_information.h>

namespace urcl
{
class DashboardClient : public comm::TCPSocket
{
public:
  DashboardClient(const std::string& host);
  DashboardClient() = delete;
  virtual ~DashboardClient() = default;

  static constexpr int DASHBOARD_SERVER_PORT = 29999;

  bool connect(const size_t max_num_tries = 0,
               const std::chrono::milliseconds reconnection_time = std::chrono::seconds(10));

  void disconnect();

  std::string sendAndReceive(const std::string& command);

  bool sendRequest(const std::string& command, const std::string& expected);

  std::string sendRequestString(const std::string& command, const std::string& expected);

  bool waitForReply(const std::string& command, const std::string& expected,
                    std::chrono::duration<double> timeout = std::chrono::seconds(30));

  bool retryCommand(const std::string& requestCommand, const std::string& requestExpectedResponse,
                    const std::string& waitRequest, const std::string& waitExpectedResponse,
                    const std::chrono::duration<double> timeout,
                    const std::chrono::duration<double> retry_period = std::chrono::seconds(1));

  bool commandPowerOff();

  bool commandPowerOn(const std::chrono::duration<double> timeout = std::chrono::seconds(300));

  bool commandBrakeRelease();

  bool commandLoadProgram(const std::string& program_file_name);

  bool commandLoadInstallation(const std::string& installation_file_name);

  bool commandPlay();

  bool commandPause();

  bool commandStop();

  bool commandClosePopup();

  bool commandCloseSafetyPopup();

  bool commandRestartSafety();

  bool commandUnlockProtectiveStop();

  bool commandShutdown();

  bool commandQuit();

  bool commandRunning();

  bool commandIsProgramSaved();

  bool commandIsInRemoteControl();

  bool commandPopup(const std::string& popup_text);

  bool commandAddToLog(const std::string& log_text);

  bool commandPolyscopeVersion(std::string& polyscope_version);

  bool commandGetRobotModel(std::string& robot_model);

  bool commandGetSerialNumber(std::string& serial_number);

  bool commandRobotMode(std::string& robot_mode);

  bool commandGetLoadedProgram(std::string& loaded_program);

  bool commandSafetyMode(std::string& safety_mode);

  bool commandSafetyStatus(std::string& safety_status);

  bool commandProgramState(std::string& program_state);

  bool commandGetOperationalMode(std::string& operational_mode);

  bool commandSetOperationalMode(const std::string& operational_mode);

  bool commandClearOperationalMode();

  bool commandSetUserRole(const std::string& user_role);

  bool commandGetUserRole(std::string& user_role);

  bool commandGenerateFlightReport(const std::string& report_type);

  bool commandGenerateSupportFile(const std::string& dir_path);

  bool commandSaveLog();

private:
  void assertVersion(const std::string& e_series_min_ver, const std::string& cb3_min_ver,
                     const std::string& required_call);
  bool send(const std::string& text);
  std::string read();
  void rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");

  timeval getConfiguredReceiveTimeout() const;

  VersionInformation polyscope_version_;
  std::string host_;
  int port_;
  std::mutex write_mutex_;
};
}  // namespace urcl
#endif  // ifndef UR_ROBOT_DRIVER_DASHBOARD_CLIENT_DASHBOARD_CLIENT_H_INCLUDED