Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 100
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortBlocksOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakAssignment: 2
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: C++17
59 changes: 59 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
Checks: >
-*,
bugprone-*,
cert-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-avoid-non-const-global-variables,
misc-*,
-misc-non-private-member-variables-in-classes,
performance-*,
-performance-avoid-endl,
readability-*,
-readability-magic-numbers,
-readability-identifier-length,
-readability-function-cognitive-complexity,
modernize-*,
-modernize-use-trailing-return-type,
-modernize-avoid-c-arrays

WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: 'file'
User: ''
CheckOptions:
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.VariableCase
value: camelBack
- key: readability-identifier-naming.ParameterCase
value: camelBack
- key: readability-identifier-naming.MemberCase
value: camelBack
- key: readability-identifier-naming.PrivateMemberPrefix
value: m_
- key: readability-identifier-naming.ProtectedMemberPrefix
value: m_
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.ConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: true
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
value: true
55 changes: 53 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.5)
project(MyProject)
cmake_minimum_required(VERSION 3.15)
project(LinkerHand-CPP-SDK
VERSION 1.1.7
LANGUAGES CXX
DESCRIPTION "LinkerHand C++ SDK for robotic hand control"
)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(LIB_SUBDIR "x86_64")
Expand Down Expand Up @@ -60,6 +64,53 @@ target_link_libraries(toolset_example ${LINKER_HAND_LIB} pthread)
add_executable(action_group_show_l10 examples/action_group_show_l10.cpp)
target_link_libraries(action_group_show_l10 ${LINKER_HAND_LIB} pthread)

#-----------------------------------------------------------------------------
# INSTALL TARGETS
#-----------------------------------------------------------------------------
# 安装头文件
install(DIRECTORY include/
DESTINATION include/linkerhand-cpp-sdk
FILES_MATCHING PATTERN "*.h"
)

# 安装库文件
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/lib/${LIB_SUBDIR})
install(DIRECTORY lib/${LIB_SUBDIR}/
DESTINATION lib/linkerhand-cpp-sdk/${LIB_SUBDIR}
FILES_MATCHING PATTERN "*.so*"
)
endif()

#-----------------------------------------------------------------------------
# PACKAGE CONFIGURATION
#-----------------------------------------------------------------------------
include(CMakePackageConfigHelpers)

# 创建包配置文件
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/LinkerHandCPPSDKConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

# 设置包配置变量(用于 configure_file)
set(PACKAGE_INCLUDE_INSTALL_DIR "include/linkerhand-cpp-sdk")
set(PACKAGE_LIB_INSTALL_DIR "lib/linkerhand-cpp-sdk/${LIB_SUBDIR}")

# 创建包配置文件模板
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/LinkerHandCPPSDKConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/LinkerHandCPPSDKConfig.cmake"
@ONLY
)

# 安装包配置文件
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/LinkerHandCPPSDKConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/LinkerHandCPPSDKConfigVersion.cmake"
DESTINATION lib/cmake/LinkerHandCPPSDK
)

#-----------------------------------------------------------------------------
# TESTING
#-----------------------------------------------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions cmake/LinkerHandCPPSDKConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@PACKAGE_INIT@

# 确定系统架构
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(LIB_SUBDIR "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(LIB_SUBDIR "aarch64")
else()
set(LIB_SUBDIR "x86_64")
endif()

# 设置包含目录和库目录(相对于安装前缀)
set(LinkerHandCPPSDK_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../@PACKAGE_INCLUDE_INSTALL_DIR@")
set(LinkerHandCPPSDK_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}/../../@PACKAGE_LIB_INSTALL_DIR@")

# 也支持从构建目录查找(用于开发时)
list(APPEND LinkerHandCPPSDK_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../include/linkerhand-cpp-sdk")
list(APPEND LinkerHandCPPSDK_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}/../../lib/linkerhand-cpp-sdk/${LIB_SUBDIR}")

# 查找库文件
find_library(LinkerHandCPPSDK_LIBRARY
NAMES linkerhand_cpp_sdk
PATHS ${LinkerHandCPPSDK_LIB_DIR}
NO_DEFAULT_PATH
)

# 检查库文件是否存在
if(NOT LinkerHandCPPSDK_LIBRARY)
message(FATAL_ERROR "LinkerHandCPPSDK library not found in ${LinkerHandCPPSDK_LIB_DIR}")
endif()

# 设置变量供外部使用
set(LinkerHandCPPSDK_FOUND TRUE)
set(LinkerHandCPPSDK_VERSION @PROJECT_VERSION@)

# 创建导入目标
if(NOT TARGET LinkerHandCPPSDK::LinkerHandCPPSDK)
add_library(LinkerHandCPPSDK::LinkerHandCPPSDK SHARED IMPORTED)
set_target_properties(LinkerHandCPPSDK::LinkerHandCPPSDK PROPERTIES
IMPORTED_LOCATION "${LinkerHandCPPSDK_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LinkerHandCPPSDK_INCLUDE_DIR}"
)
endif()

check_required_components(LinkerHandCPPSDK)
10 changes: 5 additions & 5 deletions examples/toolset_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void exit()
running = false;
std::string can_channel;

if (channel == COMM_TYPE::COMM_CAN_0) can_channel = "can0";
if (channel == COMM_TYPE::COMM_CAN_1) can_channel = "can1";
if (channel == COMM_CAN_0) can_channel = "can0";
if (channel == COMM_CAN_1) can_channel = "can1";

// system(std::string("sudo /usr/sbin/ip link set " + can_channel + " down").c_str());
exit(0);
Expand Down Expand Up @@ -525,13 +525,13 @@ int main()
switch (choice)
{
case 1:
channel = COMM_TYPE::COMM_CAN_0;
channel = COMM_CAN_0;
break;
case 2:
channel = COMM_TYPE::COMM_CAN_1;
channel = COMM_CAN_1;
break;
case 3:
channel = COMM_TYPE::COMM_ETHERCAT;
channel = COMM_ETHERCAT;
break;
case 0:
exit();
Expand Down
23 changes: 16 additions & 7 deletions include/CanBus.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef __linux__
#ifndef CAN_BUS_H
#define CAN_BUS_H
#ifndef LINKERHAND_CAN_BUS_H
#define LINKERHAND_CAN_BUS_H

#include <iostream>
#include <iomanip>
Expand All @@ -25,9 +25,13 @@

#include "ICanBus.h"

namespace Communication //Communicator
{
class CanBus : public ICanBus
namespace linkerhand {
namespace communication {

/**
* @brief Linux CAN 总线实现
*/
class CanBus : public linkerhand::communication::ICanBus
{
public:
CanBus(const std::string& interface, int bitrate, const LINKER_HAND linkerhand);
Expand Down Expand Up @@ -62,7 +66,12 @@ namespace Communication //Communicator

LINKER_HAND linker_hand;
};
}
} // namespace communication
} // namespace linkerhand

// 向后兼容:在全局命名空间中提供别名
namespace Communication = linkerhand::communication;

#endif
#endif // CAN_BUS_H
#endif // LINKERHAND_CAN_BUS_H

22 changes: 13 additions & 9 deletions include/CanBusFactory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef CAN_BUS_FACTORY_H
#define CAN_BUS_FACTORY_H
#ifndef LINKERHAND_CAN_BUS_FACTORY_H
#define LINKERHAND_CAN_BUS_FACTORY_H

#include "ICanBus.h"
#include "CanBus.h"
Expand All @@ -10,8 +10,8 @@

#include <stdexcept>

namespace Communication
{
namespace linkerhand {
namespace communication {
class CanBusFactory
{
public:
Expand All @@ -31,17 +31,17 @@ namespace Communication
if (interfaceOrChannel == "can1") {
channel = PCAN_USBBUS2;
}
return std::make_unique<PCANBus>(channel, baudrate, linkerHand);
return std::make_unique<linkerhand::communication::PCANBus>(channel, baudrate, linkerHand);

#else
// Linux/Unix 平台
if (interfaceOrChannel == "can0" || interfaceOrChannel == "can1") {
return std::make_unique<CanBus>(interfaceOrChannel, bitrate, linkerHand);
return std::make_unique<linkerhand::communication::CanBus>(interfaceOrChannel, bitrate, linkerHand);
}

#if USE_ETHERCAT
else if (interfaceOrChannel == "ethercat") {
return std::make_unique<EtherCAT>(handId);
return std::make_unique<linkerhand::communication::EtherCAT>(handId);
}
#endif

Expand All @@ -53,6 +53,10 @@ namespace Communication
#endif
}
};
}
} // namespace communication
} // namespace linkerhand

#endif // CAN_BUS_FACTORY_H
// 向后兼容:在全局命名空间中提供别名
namespace Communication = linkerhand::communication;

#endif // LINKERHAND_CAN_BUS_FACTORY_H
Loading