Program Listing for File fadecandy_driver_ros.h

Return to documentation for file (src/ros/fadecandy_driver_ros.h)

/*
 * Copyright (c) 2021 Eurotec, Netherlands
 * All rights reserved.
 *
 * Author: Jad Haj Mustafa
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 * 3. Neither the name of the copyright holder nor the names of its
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <diagnostic_updater/diagnostic_updater.hpp>
#include <fadecandy_msgs/msg/led_array.hpp>
#include <rclcpp/rclcpp.hpp>

#include "../fadecandy_driver.h"

namespace fadecandy_driver
{
class FadecandyDriverROS
{
public:
  FadecandyDriverROS(rclcpp::Node::SharedPtr node, double restart_patience);

  void run();

private:
  FadecandyDriver driver_;

  rclcpp::Node::SharedPtr node_;

  void setupConnection();

  rclcpp::Subscription<fadecandy_msgs::msg::LEDArray>::SharedPtr led_subscriber_;
  void setLedsCallback(const fadecandy_msgs::msg::LEDArray::SharedPtr msg);

  void diagnosticsCallback(diagnostic_updater::DiagnosticStatusWrapper& diagnostic_status);

  rclcpp::TimerBase::SharedPtr diagnostics_timer_;
  void diagnosticsTimerCallback();

  rclcpp::TimerBase::SharedPtr connect_timer_;
  void connectTimerCallback();

  diagnostic_updater::Updater diagnostic_updater_;

  double restart_patience_;
};
}  // namespace fadecandy_driver