Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
Merge pull request #12 from NathanaelGandhi/ng/rename
Browse files Browse the repository at this point in the history
fix: rename package to linux_thermal_zone_base
  • Loading branch information
NathanaelGandhi authored May 16, 2024
2 parents f575169 + 5df9b0c commit ac2b83c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 62 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(thermal_zone)
project(linux_thermal_zone_base)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
Expand All @@ -8,19 +8,19 @@ endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(thermal_zone_interfaces REQUIRED)
find_package(linux_thermal_zone_interfaces REQUIRED)

add_executable(${PROJECT_NAME}
src/thermal_zone.cpp
src/thermal_zone_node.cpp)
src/linux_thermal_zone_base.cpp
src/linux_thermal_zone_base_node.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17

ament_target_dependencies(${PROJECT_NAME}
rclcpp
thermal_zone_interfaces
linux_thermal_zone_interfaces
)

install(TARGETS ${PROJECT_NAME}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# thermal_zone_publisher
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/NathanaelGandhi/thermal_zone/main.svg)](https://results.pre-commit.ci/latest/github/NathanaelGandhi/thermal_zone/main)
[![Release Drafter](https://github.com/NathanaelGandhi/thermal_zone/actions/workflows/release-drafter.yml/badge.svg?branch=release)](https://github.com/NathanaelGandhi/thermal_zone/actions/workflows/release-drafter.yml)
[![Mirror release to humble](https://github.com/NathanaelGandhi/thermal_zone/actions/workflows/mirror-release-to-humble.yaml/badge.svg?branch=release)](https://github.com/NathanaelGandhi/thermal_zone/actions/workflows/mirror-release-to-humble.yaml)
# linux_thermal_zone_base
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/NathanaelGandhi/linux_thermal_zone_base/main.svg)](https://results.pre-commit.ci/latest/github/NathanaelGandhi/linux_thermal_zone_base/main)
[![Release Drafter](https://github.com/NathanaelGandhi/linux_thermal_zone_base/actions/workflows/release-drafter.yml/badge.svg?branch=release)](https://github.com/NathanaelGandhi/linux_thermal_zone_base/actions/workflows/release-drafter.yml)
[![Mirror release to humble](https://github.com/NathanaelGandhi/linux_thermal_zone_base/actions/workflows/mirror-release-to-humble.yaml/badge.svg?branch=release)](https://github.com/NathanaelGandhi/linux_thermal_zone_base/actions/workflows/mirror-release-to-humble.yaml)

ROS2 node for thermal zone(s) found on linux systems at ```/sys/class/thermal/thermal_zone*```

## Interfaces
See [thermal_zone_interfaces](https://github.com/NathanaelGandhi/thermal_zone_interfaces) package
See [linux_thermal_zone_interfaces](https://github.com/NathanaelGandhi/linux_thermal_zone_interfaces) package
32 changes: 32 additions & 0 deletions include/linux_thermal_zone_base/linux_thermal_zone_base_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <rclcpp/rclcpp.hpp>
#include <string>

#include "linux_thermal_zone_interfaces/msg/linux_thermal_zone.hpp"
#include "linux_thermal_zone_interfaces/msg/linux_thermal_zone_base_node_hk.hpp"

class LinuxThermalZoneBaseNode : public rclcpp::Node
{
public:
explicit LinuxThermalZoneBaseNode(const std::string & node_name);
~LinuxThermalZoneBaseNode();

protected:
private:
size_t thermal_pub_count_;
rclcpp::TimerBase::SharedPtr timer_1s_;
rclcpp::TimerBase::SharedPtr timer_10s_;
rclcpp::Publisher<linux_thermal_zone_interfaces::msg::LinuxThermalZone>::SharedPtr
publisher_thermal_;
rclcpp::Publisher<linux_thermal_zone_interfaces::msg::LinuxThermalZoneBaseNodeHk>::SharedPtr
publisher_node_hk_;

void timer_1s_callback(void);
void timer_10s_callback(void);
std::vector<linux_thermal_zone_interfaces::msg::LinuxThermalZone> GetZoneMsgVector(void);
linux_thermal_zone_interfaces::msg::LinuxThermalZone GetZoneMsg(
std::string key, uint8_t zone_index);
double GetZoneTemperature(std::string prefix);
uint8_t CountMatchingDirectories(const std::string & pattern);
};
29 changes: 0 additions & 29 deletions include/thermal_zone/thermal_zone_node.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>thermal_zone</name>
<name>linux_thermal_zone_base</name>
<version>0.0.0</version>
<description>ROS2 node for thermal zone(s) found on linux systems</description>
<description>ROS2 base for Linux Thermal Zone(s)</description>
<maintainer email="[email protected]">Nathanael Gandhi</maintainer>
<license>MIT</license>

<depend>rclcpp</depend>
<depend>thermal_zone_interfaces</depend>
<depend>linux_thermal_zone_interfaces</depend>

<buildtool_depend>ament_cmake</buildtool_depend>

Expand Down
4 changes: 2 additions & 2 deletions src/thermal_zone.cpp → src/linux_thermal_zone_base.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <memory>
#include <rclcpp/rclcpp.hpp>

#include "thermal_zone/thermal_zone_node.hpp"
#include "linux_thermal_zone_base/linux_thermal_zone_base_node.hpp"

int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);

rclcpp::spin(std::make_shared<ThermalZoneNode>("thermal_zone_node"));
rclcpp::spin(std::make_shared<LinuxThermalZoneBaseNode>("linux_thermal_zone_base_node"));
// rclcpp::executors::SingleThreadedExecutor exec;
// exec.add_node(std::make_shared<ThermalZoneNode>("thermal_zone_node"));
// exec.spin();
Expand Down
40 changes: 22 additions & 18 deletions src/thermal_zone_node.cpp → src/linux_thermal_zone_base_node.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "thermal_zone/thermal_zone_node.hpp"
#include "linux_thermal_zone_base/linux_thermal_zone_base_node.hpp"

#include <chrono>
#include <filesystem>
Expand All @@ -10,23 +10,26 @@ using namespace std::chrono_literals;

// PUBLIC FUNCTIONS

ThermalZoneNode::ThermalZoneNode(const std::string & node_name)
LinuxThermalZoneBaseNode::LinuxThermalZoneBaseNode(const std::string & node_name)
: rclcpp::Node(node_name), thermal_pub_count_(0)
{
RCLCPP_INFO_STREAM(this->get_logger(), "default constructor executed");

timer_1s_ = this->create_wall_timer(1s, std::bind(&ThermalZoneNode::timer_1s_callback, this));
timer_10s_ = this->create_wall_timer(10s, std::bind(&ThermalZoneNode::timer_10s_callback, this));
timer_1s_ =
this->create_wall_timer(1s, std::bind(&LinuxThermalZoneBaseNode::timer_1s_callback, this));
timer_10s_ =
this->create_wall_timer(10s, std::bind(&LinuxThermalZoneBaseNode::timer_10s_callback, this));
RCLCPP_INFO_STREAM(this->get_logger(), "timers created");

publisher_thermal_ =
this->create_publisher<thermal_zone_interfaces::msg::ThermalZone>("thermal", 10);
this->create_publisher<linux_thermal_zone_interfaces::msg::LinuxThermalZone>("thermal", 10);
publisher_node_hk_ =
this->create_publisher<thermal_zone_interfaces::msg::ThermalZoneNodeHk>("node_hk", 10);
this->create_publisher<linux_thermal_zone_interfaces::msg::LinuxThermalZoneBaseNodeHk>(
"node_hk", 10);
RCLCPP_INFO_STREAM(this->get_logger(), "publishers created");
}

ThermalZoneNode::~ThermalZoneNode()
LinuxThermalZoneBaseNode::~LinuxThermalZoneBaseNode()
{
RCLCPP_INFO_STREAM(this->get_logger(), "destructor executed");
}
Expand All @@ -35,27 +38,27 @@ ThermalZoneNode::~ThermalZoneNode()

// PRIVATE FUNCTIONS

void ThermalZoneNode::timer_1s_callback()
void LinuxThermalZoneBaseNode::timer_1s_callback()
{
RCLCPP_DEBUG_STREAM(this->get_logger(), "timer_1s_callback executed");
std::vector<thermal_zone_interfaces::msg::ThermalZone> msgs = GetZoneMsgVector();
std::vector<linux_thermal_zone_interfaces::msg::LinuxThermalZone> msgs = GetZoneMsgVector();

RCLCPP_INFO_STREAM(this->get_logger(), "Publishing: " << msgs.size() << " ThermalZone messages");
for (thermal_zone_interfaces::msg::ThermalZone message : msgs) {
for (linux_thermal_zone_interfaces::msg::LinuxThermalZone message : msgs) {
publisher_thermal_->publish(message);
thermal_pub_count_++;
}
}

void ThermalZoneNode::timer_10s_callback()
void LinuxThermalZoneBaseNode::timer_10s_callback()
{
RCLCPP_DEBUG_STREAM(this->get_logger(), "timer_10s_callback executed");
thermal_zone_interfaces::msg::ThermalZoneNodeHk message;
linux_thermal_zone_interfaces::msg::LinuxThermalZoneBaseNodeHk message;
message.set__thermal_zone_publish_count(thermal_pub_count_);
publisher_node_hk_->publish(message);
}

uint8_t ThermalZoneNode::CountMatchingDirectories(const std::string & pattern)
uint8_t LinuxThermalZoneBaseNode::CountMatchingDirectories(const std::string & pattern)
{
uint8_t count = 0;

Expand All @@ -69,9 +72,10 @@ uint8_t ThermalZoneNode::CountMatchingDirectories(const std::string & pattern)
return count;
}

std::vector<thermal_zone_interfaces::msg::ThermalZone> ThermalZoneNode::GetZoneMsgVector(void)
std::vector<linux_thermal_zone_interfaces::msg::LinuxThermalZone>
LinuxThermalZoneBaseNode::GetZoneMsgVector(void)
{
std::vector<thermal_zone_interfaces::msg::ThermalZone> msgs;
std::vector<linux_thermal_zone_interfaces::msg::LinuxThermalZone> msgs;
const std::string key = "thermal_zone";
uint8_t num_zones = CountMatchingDirectories(key);

Expand All @@ -86,12 +90,12 @@ std::vector<thermal_zone_interfaces::msg::ThermalZone> ThermalZoneNode::GetZoneM
return msgs;
}

thermal_zone_interfaces::msg::ThermalZone ThermalZoneNode::GetZoneMsg(
linux_thermal_zone_interfaces::msg::LinuxThermalZone LinuxThermalZoneBaseNode::GetZoneMsg(
std::string key, uint8_t zone_index)
{
std::string prefix = "/sys/class/thermal/";

auto msg = thermal_zone_interfaces::msg::ThermalZone();
auto msg = linux_thermal_zone_interfaces::msg::LinuxThermalZone();

std::string id = key + std::to_string(zone_index);
std::string thermal_zone_dir = prefix + id;
Expand All @@ -105,7 +109,7 @@ thermal_zone_interfaces::msg::ThermalZone ThermalZoneNode::GetZoneMsg(
return msg;
}

double ThermalZoneNode::GetZoneTemperature(std::string thermal_zone_dir)
double LinuxThermalZoneBaseNode::GetZoneTemperature(std::string thermal_zone_dir)
{
std::string filename = "/temp";
std::string filepath = thermal_zone_dir + filename;
Expand Down

0 comments on commit ac2b83c

Please sign in to comment.