Skip to content

Commit

Permalink
Merge pull request #9 from juraph-dev/options_menu
Browse files Browse the repository at this point in the history
Options menu
  • Loading branch information
juraph-dev authored Apr 22, 2023
2 parents 5210efd + b6c2aac commit 2e5a96e
Show file tree
Hide file tree
Showing 37 changed files with 2,391 additions and 1,571 deletions.
65 changes: 65 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
BasedOnStyle: Google
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true
BinPackParameters: true
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerBinding: false
PointerBindsToType: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakString: 1
PenaltyBreakFirstLessLess: 1000
PenaltyExcessCharacter: 1000
PenaltyReturnTypeOnItsOwnLine: 90
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: false
Standard: Auto
IndentWidth: 2
TabWidth: 2
UseTab: Never
IndentFunctionDeclarationAfterType: false
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
SortIncludes: false
SpaceAfterCStyleCast: false

# Configure each individual brace in BraceWrapping
BreakBeforeBraces: Custom

# Control of individual brace wrapping cases
BraceWrapping: {
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'true'
BeforeElse : 'true'
IndentBraces : 'false'
}
...
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ install(TARGETS ${PROJECT_NAME}-lib
RUNTIME DESTINATION bin
)

file(GLOB_RECURSE AMENT_LINT_AUTO_FILE_EXCLUDE
# Don't lint external submodules
external/*
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
Expand Down
11 changes: 6 additions & 5 deletions include/ornis/channel_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
class Channel
{
public:
Channel(){};
Channel() : request_pending_(false), ui_data_current_(false){};
~Channel(){};

enum class RequestEnum {
enum class RequestEnum
{
monitorEntryInformation,
monitorEntryInteraction,
monitorEntryInteractionResult,
Expand All @@ -31,19 +32,19 @@ class Channel
// Object controller
RequestEnum request_type_;
std::string response_string_;
std::atomic<bool> request_pending_ = false;
std::atomic<bool> request_pending_;
std::condition_variable condition_variable_;
std::map<std::string, std::string> request_details_;

std::map<std::string, std::vector<std::string>> response_map_;
std::pair<msg_tree::MsgTree, msg_tree::MsgTree> * request_response_trees_;
std::pair<msg_tree::MsgTree, msg_tree::MsgTree>* request_response_trees_;

// Structures to facilitate Object controller storing updated information
// for UI to grab when ready
std::map<std::string, std::vector<std::pair<std::string, std::string>>> latest_monitor_data_;
// Flag to allow the UI to check if the monitor data has been updated since
// last check.
std::atomic<bool> ui_data_current_ = false;
std::atomic<bool> ui_data_current_;
};

#endif // CHANNEL_INTERFACE_H_
42 changes: 25 additions & 17 deletions include/ornis/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

namespace helper_functions
{
inline bool getNthIndex(
const std::string & string, const char & target_char, const size_t & target_count, size_t & index)
inline bool getNthIndex(const std::string& string, const char& target_char, const size_t& target_count, size_t& index)
{
size_t count = 0;
size_t final_find = 0;
for (uint i = 0; i < string.length(); i++) {
if (string[i] == target_char) {
for (uint i = 0; i < string.length(); i++)
{
if (string[i] == target_char)
{
count++;
final_find = i;
if (count == target_count) {
if (count == target_count)
{
index = i;
return true;
}
Expand All @@ -26,33 +28,39 @@ inline bool getNthIndex(
return false;
}

inline void getAllIndexes(
const std::string & string, const char & target_char, std::vector<size_t> & index)
inline void getAllIndexes(const std::string& string, const char& target_char, std::vector<size_t>& index)
{
for (uint i = 0; i < string.length(); i++) {
if (string[i] == target_char) {
for (uint i = 0; i < string.length(); i++)
{
if (string[i] == target_char)
{
index.push_back(i);
}
}
}

inline bool getDataFromRequestString(
std::vector<std::string> & data_strings, const std::string & request_string)
inline bool getDataFromRequestString(std::vector<std::string>& data_strings, const std::string& request_string)
{
std::vector<size_t> data_start_char_indexes, data_end_char_indexes;
getAllIndexes(request_string, ':', data_start_char_indexes);
getAllIndexes(request_string, '\n', data_end_char_indexes);

size_t end_index = 0;
for (size_t start_index = 0; start_index < data_start_char_indexes.size(); ++start_index) {
for (size_t start_index = 0; start_index < data_start_char_indexes.size(); ++start_index)
{
// Get first index of data_end that is greater than data_end_char
while (true) {
while (true)
{
// If the end char (Usually a newline) occurs before the data start, it doens't belong to the data, so discard
if (data_end_char_indexes[end_index] < data_start_char_indexes[start_index]) {
if (data_end_char_indexes[end_index] < data_start_char_indexes[start_index])
{
end_index++;
} else {
data_strings.push_back(request_string.substr(
data_start_char_indexes[start_index] + 1, data_end_char_indexes[end_index] - data_start_char_indexes[start_index] - 1));
}
else
{
data_strings.push_back(
request_string.substr(data_start_char_indexes[start_index] + 1,
data_end_char_indexes[end_index] - data_start_char_indexes[start_index] - 1));
end_index++;
break;
}
Expand Down
80 changes: 33 additions & 47 deletions include/ornis/introspection_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,56 @@

namespace introspection
{
std::string getTypeSupportLibraryPath(
const std::string & package_name, const std::string & typesupport_identifier);
std::string getTypeSupportLibraryPath(const std::string& package_name, const std::string& typesupport_identifier);

const std::tuple<std::string, std::string, std::string> extractTypeIdentifier(
const std::string & full_type);
const std::tuple<std::string, std::string, std::string> extractTypeIdentifier(const std::string& full_type);

const std::pair<std::string, std::string> extractTypeAndPackage(const std::string & full_type);
const std::pair<std::string, std::string> extractTypeAndPackage(const std::string& full_type);

const rosidl_service_type_support_t * getServiceTypeSupport(
const std::string & type, const std::string & typesupport_identifier);
const rosidl_service_type_support_t* getServiceTypeSupport(const std::string& type,
const std::string& typesupport_identifier);

const rosidl_message_type_support_t * getMessageTypeSupport(
const std::string & type, const std::string & typesupport_identifier);
const rosidl_message_type_support_t* getMessageTypeSupport(const std::string& type,
const std::string& typesupport_identifier);

void messageDataToString(
const rosidl_typesupport_introspection_cpp::MessageMember & member_info,
const uint8_t * member_data, std::string & message_data);
void messageDataToString(const rosidl_typesupport_introspection_cpp::MessageMember& member_info,
const uint8_t* member_data, std::string& message_data);

void messageDataToDouble(
const rosidl_typesupport_introspection_cpp::MessageMember & member_info,
const uint8_t * member_data, double & message_data);
void messageDataToDouble(const rosidl_typesupport_introspection_cpp::MessageMember& member_info,
const uint8_t* member_data, double& message_data);

void messageTypeToString(
const rosidl_typesupport_introspection_cpp::MessageMember & member_info,
std::string & message_type);
void messageTypeToString(const rosidl_typesupport_introspection_cpp::MessageMember& member_info,
std::string& message_type);

void readMessageAsTreeString(
std::vector<std::string> & output, uint8_t * message_data,
const rosidl_typesupport_introspection_cpp::MessageMembers * members, int indent = 0);
void readMessageAsTreeString(std::vector<std::string>& output, uint8_t* message_data,
const rosidl_typesupport_introspection_cpp::MessageMembers* members, int indent = 0);

std::string readMessageAsString(
uint8_t * message_data, const rosidl_typesupport_introspection_cpp::MessageMembers * members);
std::string readMessageAsString(uint8_t* message_data,
const rosidl_typesupport_introspection_cpp::MessageMembers* members);

double readMessageAsDouble(
uint8_t * message_data, const rosidl_typesupport_introspection_cpp::MessageMembers * members);
double readMessageAsDouble(uint8_t* message_data, const rosidl_typesupport_introspection_cpp::MessageMembers* members);

void writeDataToMessage(
uint8_t * message_data, const rosidl_typesupport_introspection_cpp::MessageMembers * members,
const std::vector<std::string> & data);
void writeDataToMessage(uint8_t* message_data, const rosidl_typesupport_introspection_cpp::MessageMembers* members,
const std::vector<std::string>& data);

bool populateMessage(
uint8_t * message_data, const rosidl_typesupport_introspection_cpp::MessageMembers * members,
const std::string & data);
bool populateMessage(uint8_t* message_data, const rosidl_typesupport_introspection_cpp::MessageMembers* members,
const std::string& data);

void stringToMessageData(
uint8_t * message_data, const rosidl_typesupport_introspection_cpp::MessageMember & member,
const std::string & data);
void stringToMessageData(uint8_t* message_data, const rosidl_typesupport_introspection_cpp::MessageMember& member,
const std::string& data);

std::vector<uint32_t> getEntryOffset(
std::vector<std::string> entry_path, const std::string & member_type_id,
const rosidl_typesupport_introspection_cpp::MessageMembers * message_members);
std::vector<uint32_t> getEntryOffset(std::vector<std::string> entry_path, const std::string& member_type_id,
const rosidl_typesupport_introspection_cpp::MessageMembers* message_members);

void getMessageMember(
const std::vector<uint32_t> & offsets,
const rosidl_typesupport_introspection_cpp::MessageMembers * message_members,
rosidl_typesupport_introspection_cpp::MessageMember & found_member);
void getMessageMember(const std::vector<uint32_t>& offsets,
const rosidl_typesupport_introspection_cpp::MessageMembers* message_members,
rosidl_typesupport_introspection_cpp::MessageMember& found_member);

void getMessageMember(
const std::vector<uint32_t> & offsets,
const rosidl_typesupport_introspection_cpp::MessageMembers * message_members,
uint8_t * data, rosidl_typesupport_introspection_cpp::MessageMember & found_member,
uint8_t ** found_data);
void getMessageMember(const std::vector<uint32_t>& offsets,
const rosidl_typesupport_introspection_cpp::MessageMembers* message_members, uint8_t* data,
rosidl_typesupport_introspection_cpp::MessageMember& found_member, uint8_t** found_data);

bool parsableAsNumeric(const rosidl_typesupport_introspection_cpp::MessageMember & msg_info);
bool parsableAsNumeric(const rosidl_typesupport_introspection_cpp::MessageMember& msg_info);

} // namespace introspection

Expand Down
42 changes: 25 additions & 17 deletions include/ornis/monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,25 @@
class Monitor
{
public:
Monitor() : spin_(true), last_read_current_(false) {}
virtual ~Monitor() {}
Monitor() : spin_(true), last_read_current_(false)
{
}
virtual ~Monitor()
{
}

virtual void getEntryInfo(
const std::string & entry_name, const std::string & entry_details,
std::map<std::string, std::vector<std::string>> & entry_info) = 0;
virtual void getEntryInfo(const std::string& entry_name, const std::string& entry_details,
std::map<std::string, std::vector<std::string>>& entry_info) = 0;

virtual void getInteractionForm(const std::string & entry_details, msg_tree::MsgTree & form) = 0;
virtual void getInteractionForm(const std::string& entry_details, msg_tree::MsgTree& form) = 0;

virtual void interact(
const std::string & entry_name, const std::string & entry_details,
const msg_tree::MsgTree & request, msg_tree::MsgTree & response) = 0;
virtual void interact(const std::string& entry_name, const std::string& entry_details,
const msg_tree::MsgTree& request, msg_tree::MsgTree& response) = 0;

bool getValue(std::vector<std::pair<std::string, std::string>> & value)
bool getValue(std::vector<std::pair<std::string, std::string>>& value)
{
if (last_read_current_.load()) {
if (last_read_current_.load())
{
return false;
}
std::unique_lock<std::mutex> lk(data_mutex_);
Expand All @@ -51,18 +54,23 @@ class Monitor

protected:
// Function to interface with the command line (eg: ros2 topic info)
std::string callConsole(const std::string & cmd)
std::string callConsole(const std::string& cmd)
{
std::string result = "";
const std::string cmd_pipe = cmd + " 2>&1";
FILE * pipe = popen(cmd_pipe.c_str(), "r");
if (!pipe) throw std::runtime_error("popen() failed!");
try {
FILE* pipe = popen(cmd_pipe.c_str(), "r");
if (!pipe)
throw std::runtime_error("popen() failed!");
try
{
char buffer[128];
while (fgets(buffer, sizeof buffer, pipe) != NULL) {
while (fgets(buffer, sizeof buffer, pipe) != NULL)
{
result += buffer;
}
} catch (...) {
}
catch (...)
{
pclose(pipe);
throw;
}
Expand Down
Loading

0 comments on commit 2e5a96e

Please sign in to comment.