From 1e3c68054f56309d873fc8634bcfd5bff29f570b Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Tue, 11 Dec 2018 14:30:33 +0100 Subject: [PATCH] format code (editorconfig and clang-format) --- .clang-format | 66 ++++++++++++++++++++++++++++++++++++++++++++++ .editorconfig | 11 ++++++++ .gitignore | 19 +++++++------ src/wlanSignal.cpp | 61 ++++++++++++++++++++---------------------- 4 files changed, 117 insertions(+), 40 deletions(-) create mode 100644 .clang-format create mode 100644 .editorconfig diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..cdcb29d --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +--- +BasedOnStyle: Google +AccessModifierOffset: -2 +ConstructorInitializerIndentWidth: 2 +AlignEscapedNewlinesLeft: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLoopsOnASingleLine: false +AlwaysBreakTemplateDeclarations: true +AlwaysBreakBeforeMultilineStrings: false +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: 3 +TabWidth: 3 +UseTab: Never +IndentFunctionDeclarationAfterType: false +SpacesInParentheses: true +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: 'false' + AfterEnum : 'true' + AfterFunction : 'false' + AfterNamespace : 'true' + AfterStruct : 'true' + AfterUnion : 'true' + BeforeCatch : 'true' + BeforeElse : 'true' + IndentBraces : 'false' +} +... diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..55f5a4e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 3 +tab_width = 3 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 diff --git a/.gitignore b/.gitignore index 47ab9f9..770d581 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ -# Dateien in Doku: # -doku/*.txt -doku/*.aux -doku/*.out -doku/*.pdf -doku/*.gz -doku/*.toc -doku/*.log \ No newline at end of file +# Dateien in Doku: # +doku/*.txt +doku/*.aux +doku/*.out +doku/*.pdf +doku/*.gz +doku/*.toc +doku/*.log + +# Ignore Visual Studio Code folder +.vscode/ diff --git a/src/wlanSignal.cpp b/src/wlanSignal.cpp index 4515e1b..9ffe34a 100644 --- a/src/wlanSignal.cpp +++ b/src/wlanSignal.cpp @@ -14,68 +14,65 @@ using namespace std; using namespace ros; using namespace wlan_pioneer; - -int8_t getWlanSignalStrength(const string &interface) { +int8_t getWlanSignalStrength( const string& interface ) { struct iw_statistics stats; struct iwreq req; - memset(&stats, 0, sizeof(stats)); - memset(&req, 0, sizeof(iwreq)); - strncpy(req.ifr_name, interface.c_str(), 16); + memset( &stats, 0, sizeof( stats ) ); + memset( &req, 0, sizeof( iwreq ) ); + strncpy( req.ifr_name, interface.c_str(), 16 ); req.u.data.pointer = &stats; - req.u.data.length = sizeof(iw_statistics); + req.u.data.length = sizeof( iw_statistics ); #ifdef CLEAR_UPDATED req.u.data.flags = 1; #endif - int sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if(sockfd == -1) { - ROS_ERROR("Could not create simple datagram socket"); - return numeric_limits::min() ; + int sockfd = socket( AF_INET, SOCK_DGRAM, 0 ); + if ( sockfd == -1 ) { + ROS_ERROR( "Could not create simple datagram socket" ); + return numeric_limits::min(); } - if(ioctl(sockfd, SIOCGIWSTATS, &req) == -1) { - ROS_ERROR("Error retrieving WLAN signal strength "); - close(sockfd); - return numeric_limits::min() ; - + if ( ioctl( sockfd, SIOCGIWSTATS, &req ) == -1 ) { + ROS_ERROR( "Error retrieving WLAN signal strength " ); + close( sockfd ); + return numeric_limits::min(); } - close(sockfd); + close( sockfd ); return stats.qual.level; } - -int main(int argc, char **argv) { - init(argc, argv, "wlanSignal"); +int main( int argc, char** argv ) { + init( argc, argv, "wlanSignal" ); NodeHandle node; string wlanInterface2G4; string wlanInterface5G; - if (node.param("wlan_interface_2G4", wlanInterface2G4, "wlan0")) { - ROS_INFO("Param wlan_interface_2G4: %s", wlanInterface2G4.c_str()); + if ( node.param( "wlan_interface_2G4", wlanInterface2G4, "wlan0" ) ) { + ROS_INFO( "Param wlan_interface_2G4: %s", wlanInterface2G4.c_str() ); } else { - ROS_INFO("Param 'wlan_interface_2G4' not set. Using 'wlan0'"); + ROS_INFO( "Param 'wlan_interface_2G4' not set. Using 'wlan0'" ); } - if (node.param("wlan_interface_5G", wlanInterface5G, "wlan0")) { - ROS_INFO("Param wlan_interface_5G: %s", wlanInterface5G.c_str()); + if ( node.param( "wlan_interface_5G", wlanInterface5G, "wlan0" ) ) { + ROS_INFO( "Param wlan_interface_5G: %s", wlanInterface5G.c_str() ); } else { - ROS_INFO("Param 'wlan_interface_5G' not set. Using 'wlan0'"); + ROS_INFO( "Param 'wlan_interface_5G' not set. Using 'wlan0'" ); } // topic: wlan_signal - Publisher publisher = node.advertise("wlan_signal", 1000); - Rate loopRate(1); // every second + Publisher publisher = node.advertise( "wlan_signal", 1000 ); + Rate loopRate( 1 ); // every second - while (ok()) { + while ( ok() ) { WlanSignalMsg msg; msg.timestamp = Time::now(); - msg.level_2G4 = getWlanSignalStrength(wlanInterface2G4); - msg.level_5G = getWlanSignalStrength(wlanInterface5G); + msg.level_2G4 = getWlanSignalStrength( wlanInterface2G4 ); + msg.level_5G = getWlanSignalStrength( wlanInterface5G ); - ROS_INFO("Signal strength 2.4G: %i Signal strength 5G: %i", msg.level_2G4, msg.level_5G); + ROS_INFO( "Signal strength 2.4G: %i Signal strength 5G: %i", msg.level_2G4, msg.level_5G ); - publisher.publish(msg); + publisher.publish( msg ); spinOnce(); loopRate.sleep(); }