Skip to content

Commit

Permalink
Proto buffers basic
Browse files Browse the repository at this point in the history
  • Loading branch information
NestorDP committed Nov 29, 2024
1 parent 74e83ce commit 5a0a146
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 445 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@


.vscode/
*__pycache__/
86 changes: 0 additions & 86 deletions littlebot_base/include/littlebot_base/littlebot_communication.hpp

This file was deleted.

54 changes: 1 addition & 53 deletions littlebot_base/include/littlebot_base/littlebot_hardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,26 @@ class LittlebotHardwareComponent : public hardware_interface::SystemInterface
* @brief Deconstructor for the LittlebotHardwareComponent class
*
*/
// ~LittlebotHardwareComponent() override;
~LittlebotHardwareComponent() = default;

/**
* @brief
*/
hardware_interface::CallbackReturn on_init(
const hardware_interface::HardwareInfo & info) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_configure(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_activate(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_shutdown(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_deactivate(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_error(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
Expand Down Expand Up @@ -117,40 +99,6 @@ class LittlebotHardwareComponent : public hardware_interface::SystemInterface
* @brief
*/
static constexpr int kNumStateInterface_{2};











/**
* @brief
*/
//std::shared_ptr<LittlebotCommunicationInterface> littlebot_communication_ptr_;

/**
* @brief The name of the package where the communication plugin is implemented.
*
*/
//const std::string communication_plugin_package_name_{"littlebot_base"};

/**
* @brief The name of the communication plugin.
*
*/
//std::string communication_plugin_name_{""};

/**
* @brief The base class of the communication plugin.
*
*/
//const std::string communication_plugin_base_class_{"LittlebotCommunicationInterface"};

};

} // namespace littlebot_base
57 changes: 57 additions & 0 deletions littlebot_base/scripts/littlebot_fake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 26 09:09:20 2018
@author: nestor
"""

import base64
import serial
import sys

import todolist_pb2 as TodoList

serial_port = sys.argv[1]

ser = serial.Serial(serial_port, baudrate=115200) # open serial port

start_character = b'<'
end_character = b'>'

# Create a new TodoList
my_list = TodoList.TodoList()
my_list.owner_id = 1234

my_list.owner_name = "Tim"

first_item = my_list.todos.add()
first_item.state = TodoList.TaskState.Value("TASK_DONE")
first_item.task = "Test ProtoBuf for Python"
first_item.due_date = "31.10.2019"

# Serialize the TodoList and send it over the serial port
encoded_data = start_character + my_list.SerializeToString() + end_character
ser.write(encoded_data)
print(f"Encoded data sent: {encoded_data}\n")

ser.flush()

my_list2 = TodoList.TodoList()

# Read the encoded data from the serial port
data = ser.read()
if data == start_character:
encoded_data_received = ser.read_until(end_character)

# Debugging print
print(f"Encoded data received: {encoded_data_received}")

# Parse the decoded data into a TodoList
try:
my_list2.ParseFromString(encoded_data_received[:-1])
print(my_list2)
except Exception as e:
print(f"Failed to parse the message: {e}")

ser.close()
26 changes: 0 additions & 26 deletions littlebot_base/scripts/littlebot_mock.py

This file was deleted.

58 changes: 0 additions & 58 deletions littlebot_base/src/littlebot_communication.cpp

This file was deleted.

Loading

0 comments on commit 5a0a146

Please sign in to comment.