From 4ed33df7f7b52e93bd8100f0fe83c8d7842c7fda Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 17:01:27 -0700 Subject: [PATCH 1/8] add clang-format config remove old astyle config --- .clang-format | 165 +++++++++++++++++++++++++++++++ examples/.clang-format | 145 +++++++++++++++++++++++++++ examples/examples_formatter.conf | 31 ------ 3 files changed, 310 insertions(+), 31 deletions(-) create mode 100644 .clang-format create mode 100644 examples/.clang-format delete mode 100644 examples/examples_formatter.conf diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..5b8681ed --- /dev/null +++ b/.clang-format @@ -0,0 +1,165 @@ +# See options listed at https://releases.llvm.org/12.0.1/tools/clang/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: Consecutive +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Left +AlignOperands: DontAlign +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: ["__capability", "__output", "__ununsed"] +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: MultiLine + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true +ColumnLimit: 0 +# CommentPragmas are a regex pattern indicating the comment is not be touched by the formatter +CommentPragmas: "^ Include gaurd .*" +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineBeforeAccessModifier: Always +# --- +# only in v13+ +# EmptyLineAfterAccessModifier: Leave +# --- +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: ".*" + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: "(Test)?$" +IncludeIsMainSourceRegex: "" +# --- +# only in v13+ +# IndentAccessModifiers: false +# --- +IndentCaseLabels: true +IndentCaseBlocks: false +IndentGotoLabels: false +IndentPPDirectives: BeforeHash +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: "" +MacroBlockEnd: "" +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +# --- +# only in v13+ +# ReferenceAlignment: Right +# --- +ReflowComments: true +# --- +# only in v13+ +# ShortNamespaceLines: 0 +# --- +# Sort**** is about sorting include/using statements alphabetically +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: c++11 +StatementAttributeLikeMacros: [emit] +StatementMacros: [Q_UNUSED, QT_REQUIRE_VERSION] +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - PRIPSTR + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME diff --git a/examples/.clang-format b/examples/.clang-format new file mode 100644 index 00000000..f95490cf --- /dev/null +++ b/examples/.clang-format @@ -0,0 +1,145 @@ +# See: https://releases.llvm.org/11.0.1/tools/clang/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +# LLVM is the default style setting, used when a configuration option is not set here +BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: false +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: No +BinPackArguments: true +BinPackParameters: true +# Only used when "BreakBeforeBraces" set to "Custom" +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + #AfterObjCDeclaration: + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +# Java-specific +#BreakAfterJavaFieldAnnotations: +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: false +ColumnLimit: 0 +# "" matches none +CommentPragmas: "" +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +# Docs say "Do not use this in config files". The default (LLVM 11.0.1) is "false". +#ExperimentalAutoDetectBinPacking: +FixNamespaceComments: false +ForEachMacros: [] +IncludeBlocks: Preserve +IncludeCategories: [] +# "" matches none +IncludeIsMainRegex: "" +IncludeIsMainSourceRegex: "" +IndentCaseBlocks: true +IndentCaseLabels: true +IndentExternBlock: Indent +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +# Java-specific +#JavaImportGroups: +# JavaScript-specific +#JavaScriptQuotes: +#JavaScriptWrapImports +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: "" +MacroBlockEnd: "" +# Set to a large number to effectively disable +MaxEmptyLinesToKeep: 100000 +NamespaceIndentation: None +NamespaceMacros: [] +# Objective C-specific +#ObjCBinPackProtocolList: +#ObjCBlockIndentWidth: +#ObjCBreakBeforeNestedBlockParam: +#ObjCSpaceAfterProperty: +#ObjCSpaceBeforeProtocolList +PenaltyBreakAssignment: 1 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 1 +PenaltyBreakFirstLessLess: 1 +PenaltyBreakString: 1 +PenaltyBreakTemplateDeclaration: 1 +PenaltyExcessCharacter: 1 +PenaltyReturnTypeOnItsOwnLine: 1 +# Used as a fallback if alignment style can't be detected from code (DerivePointerAlignment: true) +PointerAlignment: Right +RawStringFormats: [] +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +StatementMacros: [] +TabWidth: 2 +TypenameMacros: [] +# Default to LF if line endings can't be detected from the content (DeriveLineEnding). +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: [] diff --git a/examples/examples_formatter.conf b/examples/examples_formatter.conf deleted file mode 100644 index 79fd9a67..00000000 --- a/examples/examples_formatter.conf +++ /dev/null @@ -1,31 +0,0 @@ -# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style" -# http://astyle.sourceforge.net/astyle.html -# -# If you wish to change them, don't edit this file. -# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE -# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link - -mode=c - -# 2 spaces indentation -indent=spaces=2 - -# also indent macros -indent-preprocessor - -# indent classes, switches (and cases), comments starting at column 1 -indent-classes -indent-switches -indent-cases -indent-col1-comments - -# put a space around operators -pad-oper - -# put a space after if/for/while -pad-header - -# if you like one-liners, keep them -keep-one-line-statements - -# remove-comment-prefix From f40a116e53568c760830ee228586811e380e7b0e Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 17:30:32 -0700 Subject: [PATCH 2/8] ran clang-format on all C++ sources --- RF24Mesh.cpp | 135 +++--- RF24Mesh.h | 44 +- RF24Mesh_config.h | 13 +- .../RF24Mesh_Example/RF24Mesh_Example.ino | 6 +- .../RF24Mesh_Example_Master.ino | 11 +- .../RF24Mesh_Example_Master_Statics.ino | 9 +- .../RF24Mesh_Example_Master_To_Nodes.ino | 10 +- .../RF24Mesh_Example_Node2Node.ino | 9 +- .../RF24Mesh_Example_Node2NodeExtra.ino | 14 +- .../RF24Mesh_SerialConfig.ino | 4 +- examples_RPi/RF24Mesh_Example.cpp | 88 ++-- examples_RPi/RF24Mesh_Example_Master.cpp | 78 +-- .../ncurses/RF24Mesh_Ncurses_Master.cpp | 445 +++++++++--------- examples_pico/RF24Mesh_Example.cpp | 12 +- examples_pico/RF24Mesh_Example_Master.cpp | 14 +- examples_pico/defaultPins.h | 33 +- pyRF24Mesh/pyRF24Mesh.cpp | 15 +- 17 files changed, 473 insertions(+), 467 deletions(-) diff --git a/RF24Mesh.cpp b/RF24Mesh.cpp index d39b3a95..ff9b3cd6 100644 --- a/RF24Mesh.cpp +++ b/RF24Mesh.cpp @@ -6,11 +6,11 @@ #include "RF24Mesh.h" #include "RF24Mesh_config.h" -#if defined (__linux) && !defined(__ARDUINO_X86__) -#include +#if defined(__linux) && !defined(__ARDUINO_X86__) + #include #endif -RF24Mesh::RF24Mesh(RF24& _radio, RF24Network& _network): radio(_radio), network(_network) +RF24Mesh::RF24Mesh(RF24& _radio, RF24Network& _network) : radio(_radio), network(_network) { setCallback(NULL); meshStarted = false; @@ -19,7 +19,6 @@ RF24Mesh::RF24Mesh(RF24& _radio, RF24Network& _network): radio(_radio), network( #endif } - /*****************************************************/ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeout) @@ -29,7 +28,7 @@ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeou radio.stopListening(); } meshStarted = true; - if(!radio.begin()) + if (!radio.begin()) return 0; radio.setChannel(channel); radio.setDataRate(data_rate); @@ -40,15 +39,15 @@ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeou return false; } } - else{ - #if !defined(MESH_NOMASTER) + else { +#if !defined(MESH_NOMASTER) if (!addrMemAllocated) { addrMemAllocated = true; addrList = (addrListStruct*)malloc((MESH_MEM_ALLOC_SIZE * sizeof(addrListStruct))); addrListTop = 0; loadDHCP(); } - #endif +#endif mesh_address = 0; network.begin(mesh_address); } @@ -61,16 +60,16 @@ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeou uint8_t RF24Mesh::update() { uint8_t type = network.update(); - if (mesh_address == MESH_DEFAULT_ADDRESS) { return type; } + if (mesh_address == MESH_DEFAULT_ADDRESS) return type; - #if !defined(MESH_NOMASTER) +#if !defined(MESH_NOMASTER) if (type == NETWORK_REQ_ADDRESS) { doDHCP = 1; } if (!getNodeID()) { if ((type == MESH_ADDR_LOOKUP || type == MESH_ID_LOOKUP)) { - RF24NetworkHeader *header = (RF24NetworkHeader*)(&network.frame_buffer); + RF24NetworkHeader* header = (RF24NetworkHeader*)(&network.frame_buffer); header->to_node = header->from_node; int16_t returnAddr = 0; @@ -86,15 +85,15 @@ uint8_t RF24Mesh::update() } } else if (type == MESH_ADDR_RELEASE) { - uint16_t *fromAddr = (uint16_t*)network.frame_buffer; - for(uint8_t i = 0; i < addrListTop; i++) { + uint16_t* fromAddr = (uint16_t*)network.frame_buffer; + for (uint8_t i = 0; i < addrListTop; i++) { if (addrList[i].address == *fromAddr) { addrList[i].address = 0; } } } } - #endif //!NO_MASTER +#endif //!NO_MASTER return type; } @@ -103,7 +102,7 @@ uint8_t RF24Mesh::update() bool RF24Mesh::write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size) { - if (mesh_address == MESH_DEFAULT_ADDRESS) { return 0; } + if (mesh_address == MESH_DEFAULT_ADDRESS) return 0; RF24NetworkHeader header(to_node, msg_type); return network.write(header, data, size); @@ -113,14 +112,14 @@ bool RF24Mesh::write(uint16_t to_node, const void* data, uint8_t msg_type, size_ bool RF24Mesh::write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID) { - if (mesh_address == MESH_DEFAULT_ADDRESS) { return 0; } + if (mesh_address == MESH_DEFAULT_ADDRESS) return 0; int16_t toNode = 0; uint32_t lookupTimeout = millis() + MESH_WRITE_TIMEOUT; uint32_t retryDelay = 5; if (nodeID) { - while((toNode = getAddress(nodeID)) < 0) { + while ((toNode = getAddress(nodeID)) < 0) { if (millis() > lookupTimeout || toNode == -2) { return 0; } @@ -165,26 +164,26 @@ bool RF24Mesh::checkConnection() int16_t RF24Mesh::getAddress(uint8_t nodeID) { // Master will return and send 00 address for a nodeID with address 0, -1 if not found - //if (nodeID == _nodeID) { return mesh_address; } - if (!nodeID) { return 0; } - if (mesh_address == MESH_DEFAULT_ADDRESS) { return -2; } + //if (nodeID == _nodeID) return mesh_address; + if (!nodeID) return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return -2; - // Lets say 0 if nodeID 0, -1 if write failed or timed out, -2 if not found in list or address is default, - #if !defined(MESH_NOMASTER) +// Lets say 0 if nodeID 0, -1 if write failed or timed out, -2 if not found in list or address is default, +#if !defined(MESH_NOMASTER) if (!getNodeID()) { //Master Node - for(uint8_t i = 0; i < addrListTop; i++) { + for (uint8_t i = 0; i < addrListTop; i++) { if (addrList[i].nodeID == nodeID) { return addrList[i].address; } } return -2; } - #endif +#endif RF24NetworkHeader header(00, MESH_ADDR_LOOKUP); if (network.write(header, &nodeID, sizeof(nodeID))) { uint32_t timer = millis(); - while(network.update() != MESH_ADDR_LOOKUP) { + while (network.update() != MESH_ADDR_LOOKUP) { MESH_CALLBACK if (millis() - timer > MESH_LOOKUP_TIMEOUT) { return -1; @@ -201,11 +200,11 @@ int16_t RF24Mesh::getAddress(uint8_t nodeID) int16_t RF24Mesh::getNodeID(uint16_t address) { - if (address == MESH_BLANK_ID) { return _nodeID; } - if (address == 0) { return 0; } - if (mesh_address == MESH_DEFAULT_ADDRESS) { return -2; } + if (address == MESH_BLANK_ID) return _nodeID; + if (address == 0) return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return -2; - #if !defined(MESH_NOMASTER) +#if !defined(MESH_NOMASTER) if (!mesh_address) { //Master Node for (uint8_t i = 0; i < addrListTop; i++) { if (addrList[i].address == address) { @@ -214,14 +213,14 @@ int16_t RF24Mesh::getNodeID(uint16_t address) } return -2; } - #endif +#endif RF24NetworkHeader header(00, MESH_ID_LOOKUP); - if (network.write(header, &address, sizeof(address)) ) { + if (network.write(header, &address, sizeof(address))) { uint32_t timer = millis(); - while(network.update() != MESH_ID_LOOKUP) { + while (network.update() != MESH_ID_LOOKUP) { MESH_CALLBACK - if (millis() - timer > MESH_LOOKUP_TIMEOUT) { return -1; } + if (millis() - timer > MESH_LOOKUP_TIMEOUT) return -1; } int16_t ID = 0; memcpy(&ID, &network.frame_buffer[sizeof(RF24NetworkHeader)], sizeof(ID)); @@ -255,7 +254,7 @@ void RF24Mesh::beginDefault() bool RF24Mesh::releaseAddress() { - if (mesh_address == MESH_DEFAULT_ADDRESS) { return 0; } + if (mesh_address == MESH_DEFAULT_ADDRESS) return 0; RF24NetworkHeader header(00, MESH_ADDR_RELEASE); if (network.write(header, 0, 0)) { @@ -269,7 +268,7 @@ bool RF24Mesh::releaseAddress() uint16_t RF24Mesh::renewAddress(uint32_t timeout) { - if (radio.available()) { network.update(); } + if (radio.available()) network.update(); uint8_t reqCounter = 0; uint8_t totalReqs = 0; @@ -278,7 +277,7 @@ uint16_t RF24Mesh::renewAddress(uint32_t timeout) uint32_t start = millis(); while (!requestAddress(reqCounter)) { - if (millis() - start > timeout) { break; } + if (millis() - start > timeout) break; uint32_t timeoutInternal = 50 + ((totalReqs + 1) * (reqCounter + 1)) * 2; uint32_t startInternal = millis(); @@ -304,29 +303,29 @@ bool RF24Mesh::requestAddress(uint8_t level) network.multicast(header, 0, 0, level); uint32_t timr = millis(); - #define MESH_MAXPOLLS 4 +#define MESH_MAXPOLLS 4 uint16_t contactNode[MESH_MAXPOLLS]; uint8_t pollCount = 0; while (1) { - #if defined (MESH_DEBUG) +#if defined(MESH_DEBUG) bool goodSignal = radio.testRPD(); - #endif +#endif if (network.update() == NETWORK_POLL) { memcpy(&contactNode[pollCount], &network.frame_buffer[0], sizeof(uint16_t)); if (pollCount > 0 && contactNode[pollCount] != contactNode[pollCount - 1]) { //Drop duplicate polls to help prevent duplicate requests - ++pollCount; + ++pollCount; } - else{ - ++pollCount; + else { + ++pollCount; } IF_MESH_DEBUG(printf_P(PSTR("%u: MSH Poll %c -64dbm\n"), millis(), (goodSignal ? '>' : '<'))); } // end if - if (millis() - timr > 55 || pollCount >= MESH_MAXPOLLS ) { + if (millis() - timr > 55 || pollCount >= MESH_MAXPOLLS) { if (!pollCount) { IF_MESH_DEBUG(printf_P(PSTR("%u: MSH No poll from level %d\n"), millis(), level)); return 0; @@ -339,7 +338,6 @@ bool RF24Mesh::requestAddress(uint8_t level) MESH_CALLBACK } // end while - IF_MESH_DEBUG(printf_P(PSTR("%u: MSH Got poll from level %d count %d\n"), millis(), level, pollCount)); bool gotResponse = 0; @@ -358,7 +356,7 @@ bool RF24Mesh::requestAddress(uint8_t level) while (millis() - timr < 225) { if (network.update() == NETWORK_ADDR_RESPONSE) { - if (network.frame_buffer[7] == _nodeID ) { + if (network.frame_buffer[7] == _nodeID) { uint16_t newAddy = 0; memcpy(&newAddy, &network.frame_buffer[sizeof(RF24NetworkHeader)], sizeof(newAddy)); uint16_t mask = 0xFFFF; @@ -378,7 +376,7 @@ bool RF24Mesh::requestAddress(uint8_t level) return 0; } - uint16_t newAddress=0; + uint16_t newAddress = 0; memcpy(&newAddress, network.frame_buffer + sizeof(RF24NetworkHeader), sizeof(newAddress)); IF_MESH_DEBUG(printf_P(PSTR("Set address 0%o rcvd 0%o\n"), mesh_address, newAddress)); @@ -417,13 +415,13 @@ void RF24Mesh::setStaticAddress(uint8_t nodeID, uint16_t address) void RF24Mesh::setAddress(uint8_t nodeID, uint16_t address, bool searchBy) { //Look for the node in the list - for(uint8_t i = 0; i < addrListTop; i++) { + for (uint8_t i = 0; i < addrListTop; i++) { if (searchBy == false) { if (addrList[i].nodeID == nodeID) { addrList[i].address = address; - #if defined (__linux) && !defined(__ARDUINO_X86__) + #if defined(__linux) && !defined(__ARDUINO_X86__) saveDHCP(); - #endif + #endif return; //Found & set, complete } } @@ -431,9 +429,9 @@ void RF24Mesh::setAddress(uint8_t nodeID, uint16_t address, bool searchBy) if (addrList[i].address == address) { //printf("*** Addr 0%o Found, reassign fr ID %d to ID %d ***\n", addrList[i].address, addrList[i].nodeID, nodeID); addrList[i].nodeID = nodeID; - #if defined (__linux) && !defined(__ARDUINO_X86__) + #if defined(__linux) && !defined(__ARDUINO_X86__) saveDHCP(); - #endif + #endif return; } } @@ -444,18 +442,19 @@ void RF24Mesh::setAddress(uint8_t nodeID, uint16_t address, bool searchBy) } addrList[addrListTop].address = address; addrList[addrListTop++].nodeID = nodeID; //Set the value AND increment Top without another line of code - #if defined (__linux) && !defined(__ARDUINO_X86__) + #if defined(__linux) && !defined(__ARDUINO_X86__) saveDHCP(); #endif } /*****************************************************/ -void RF24Mesh::loadDHCP() { +void RF24Mesh::loadDHCP() +{ - #if defined (__linux) && !defined(__ARDUINO_X86__) - std::ifstream infile ("dhcplist.txt", std::ifstream::binary); - if (!infile) { return; } + #if defined(__linux) && !defined(__ARDUINO_X86__) + std::ifstream infile("dhcplist.txt", std::ifstream::binary); + if (!infile) return; infile.seekg(0, infile.end); int length = infile.tellg(); @@ -473,11 +472,12 @@ void RF24Mesh::loadDHCP() { /*****************************************************/ -void RF24Mesh::saveDHCP() { - #if defined (__linux) && !defined(__ARDUINO_X86__) +void RF24Mesh::saveDHCP() +{ + #if defined(__linux) && !defined(__ARDUINO_X86__) std::ofstream outfile("dhcplist.txt", std::ofstream::binary | std::ofstream::trunc); - for (int i=0; i< addrListTop; i++) { + for (int i = 0; i < addrListTop; i++) { outfile.write((char*)&addrList[i], sizeof(addrListStruct)); } outfile.close(); @@ -513,7 +513,7 @@ void RF24Mesh::DHCP() uint16_t m = fwd_by; uint8_t count = 0; - while(m) { //Octal addresses convert nicely to binary in threes. Address 03 = B011 Address 033 = B011011 + while (m) { //Octal addresses convert nicely to binary in threes. Address 03 = B011 Address 033 = B011011 m >>= 3; //Find out how many digits are in the octal address count += 3; } @@ -531,7 +531,7 @@ void RF24Mesh::DHCP() bool found = false; newAddress = fwd_by | (i << shiftVal); - if (newAddress == MESH_DEFAULT_ADDRESS) { continue; } + if (newAddress == MESH_DEFAULT_ADDRESS) continue; for (uint8_t i = 0; i < addrListTop; i++) { IF_MESH_DEBUG_MINIMAL(printf_P(PSTR("ID: %d ADDR: 0%o\n"), addrList[i].nodeID, addrList[i].address)); @@ -539,7 +539,7 @@ void RF24Mesh::DHCP() found = true; break; } - } // 3 conditions: 1. address in list = assigned to somebody else (bad); 2. address in list = assigned to this nodeID (ok); 3. address not in list (ok) + } // 3 conditions: 1. address in list = assigned to somebody else (bad); 2. address in list = assigned to this nodeID (ok); 3. address not in list (ok) if (!found) { header.type = NETWORK_ADDR_RESPONSE; @@ -547,10 +547,11 @@ void RF24Mesh::DHCP() //This is a routed request to 00 setAddress(header.reserved, newAddress); - // without this delay, address renewal fails for children with slower execution speed - #if defined (SLOW_ADDR_POLL_RESPONSE) + // without this delay, address renewal fails for children with slower execution speed + #if defined(SLOW_ADDR_POLL_RESPONSE) delay(SLOW_ADDR_POLL_RESPONSE); - #endif // defined (SLOW_ADDR_POLL_RESPONSE) + #endif // defined (SLOW_ADDR_POLL_RESPONSE) + if (header.from_node != MESH_DEFAULT_ADDRESS) { //Is NOT node 01 to 05 //delay(2); if (!network.write(header, &newAddress, sizeof(newAddress))) { @@ -575,10 +576,10 @@ void RF24Mesh::DHCP() #endif // !MESH_NOMASTER -void RF24Mesh::setCallback( void (*meshCallback)(void) ) { +void RF24Mesh::setCallback(void (*meshCallback)(void)) +{ this->meshCallback = meshCallback; - } /*****************************************************/ diff --git a/RF24Mesh.h b/RF24Mesh.h index 84246cf0..3fa8414e 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -22,9 +22,9 @@ // None defined // No Network ACK types -#define MESH_ADDR_LOOKUP 196 +#define MESH_ADDR_LOOKUP 196 #define MESH_ADDR_RELEASE 197 -#define MESH_ID_LOOKUP 198 +#define MESH_ID_LOOKUP 198 #define MESH_BLANK_ID 65535 @@ -57,6 +57,7 @@ class RF24Mesh * The mesh library and class documentation is currently in active development and usage may change. */ /**@{*/ + public: /** * Construct the mesh: @@ -69,7 +70,7 @@ class RF24Mesh * @param _radio The underlying radio driver instance * @param _network The underlying network instance */ - RF24Mesh(RF24 &_radio, RF24Network &_network); + RF24Mesh(RF24& _radio, RF24Network& _network); /** * Call this in setup() to configure the mesh and request an address.
@@ -104,7 +105,7 @@ class RF24Mesh * @param nodeID **Optional**: The @ref _nodeID "nodeID" of the recipient if not sending to master. * @return True if success; false if failed */ - bool write(const void *data, uint8_t msg_type, size_t size, uint8_t nodeID = 0); + bool write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID = 0); /** * Set a unique @ref _nodeID "nodeID" for this node. @@ -131,7 +132,7 @@ class RF24Mesh */ uint16_t renewAddress(uint32_t timeout = MESH_RENEWAL_TIMEOUT); - #if !defined(MESH_NOMASTER) +#if !defined(MESH_NOMASTER) /** * This is only to be used on the master node because it manages allocation of network addresses * for any requesting (non-master) node's ID, similar to DHCP. @@ -141,7 +142,7 @@ class RF24Mesh */ void DHCP(); - #endif +#endif /**@}*/ /** @@ -191,7 +192,7 @@ class RF24Mesh int16_t getAddress(uint8_t nodeID); /** @brief Write to a specific node by RF24Network address. */ - bool write(uint16_t to_node, const void *data, uint8_t msg_type, size_t size); + bool write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size); /** * Change the active radio channel after the mesh has been started. @@ -220,7 +221,7 @@ class RF24Mesh */ void setCallback(void (*meshCallback)(void)); - #define MESH_CALLBACK if (meshCallback) { meshCallback(); } +#define MESH_CALLBACK (if (meshCallback) meshCallback();) /** * Set or change a @ref _nodeID "nodeID" : node address (key : value) pair manually. @@ -244,7 +245,7 @@ class RF24Mesh */ void setAddress(uint8_t nodeID, uint16_t address, bool searchBy = false); - #if !defined(MESH_NOMASTER) +#if !defined(MESH_NOMASTER) /** * Save the @ref addrList to a binary file named "dhcplist.txt". * @note This function is for use on the master node only and only on Linux or x86 platforms. @@ -267,7 +268,7 @@ class RF24Mesh /** @deprecated For backward compatibility with older code. Use the synonymous setAddress() instead. */ void setStaticAddress(uint8_t nodeID, uint16_t address); - #endif // !defined(MESH_NOMASTER) +#endif // !defined(MESH_NOMASTER) /**@}*/ /** @@ -282,14 +283,15 @@ class RF24Mesh */ uint8_t _nodeID; - #if !defined(MESH_NOMASTER) +#if !defined(MESH_NOMASTER) /** * @brief A struct for storing a @ref _nodeID "nodeID" and an address in a single element of * the RF24Mesh::addrList array. * * @note This array only exists on the mesh network's master node. */ - typedef struct { + typedef struct + { /** @brief The @ref _nodeID "nodeID" of an network node (child) */ uint8_t nodeID; /** @brief The logical address of an network node (child) */ @@ -308,28 +310,28 @@ class RF24Mesh * @brief A array of addrListStruct elements for assigned addresses. * @see addrListStruct class reference */ - addrListStruct *addrList; + addrListStruct* addrList; /** @brief The number of entries in the addrListStruct of assigned addresses. */ uint8_t addrListTop; - #endif +#endif /**@}*/ private: - RF24 &radio; - RF24Network &network; + RF24& radio; + RF24Network& network; - /** Function pionter for customized callback usage in long running algorithms. */ + /** Function pointer for customized callback usage in long running algorithms. */ void (*meshCallback)(void); /** Actual requesting of the address once a contact node is discovered or supplied **/ bool requestAddress(uint8_t level); - #if !defined(MESH_NOMASTER) +#if !defined(MESH_NOMASTER) /** Indicator that an address request is available. */ bool doDHCP; /** Just ensures we don't re-allocate the memory buffer if restarting the mesh on master. **/ bool addrMemAllocated; - #endif +#endif /** Starts up the network layer with default address. */ void beginDefault(); @@ -339,8 +341,6 @@ class RF24Mesh uint8_t getLevel(uint16_t address); }; -#endif // define __RF24MESH_H__ - /** * @example RF24Mesh_Example.ino * Arduino Example Sketch
@@ -411,3 +411,5 @@ class RF24Mesh * A very limited ncurses interface used for initial monitoring/testing of RF24Mesh * @image html "images/RF24Mesh_Ncurses.JPG" */ + +#endif // define __RF24MESH_H__ diff --git a/RF24Mesh_config.h b/RF24Mesh_config.h index 193141ba..303746e4 100644 --- a/RF24Mesh_config.h +++ b/RF24Mesh_config.h @@ -16,7 +16,7 @@ #ifndef MESH_MAX_CHILDREN #define MESH_MAX_CHILDREN 4 #endif // MESH_MAX_CHILDREN -#if defined (RF24_TINY) +#if defined(RF24_TINY) #define MESH_NOMASTER #endif @@ -88,7 +88,7 @@ //#define MESH_MAX_ADDRESSES 255 /* UNUSED Determines the max size of the array used for storing addresses on the Master Node */ //#define MESH_ADDRESS_HOLD_TIME 30000 /* UNUSED How long before a released address becomes available */ -#if (defined (__linux) || defined (linux)) && !defined (__ARDUINO_X86__) && !defined (USE_RF24_LIB_SRC) +#if (defined(__linux) || defined(linux)) && !defined(__ARDUINO_X86__) && !defined(USE_RF24_LIB_SRC) #include //ATXMega @@ -98,15 +98,14 @@ #include #endif -#if defined (MESH_DEBUG_MINIMAL) - #define IF_MESH_DEBUG_MINIMAL(x) ({x;}) +#if defined(MESH_DEBUG_MINIMAL) + #define IF_MESH_DEBUG_MINIMAL(x) ({ x; }) #else #define IF_MESH_DEBUG_MINIMAL(x) #endif - -#if defined (MESH_DEBUG) - #define IF_MESH_DEBUG(x) ({x;}) +#if defined(MESH_DEBUG) + #define IF_MESH_DEBUG(x) ({ x; }) #else #define IF_MESH_DEBUG(x) #endif diff --git a/examples/RF24Mesh_Example/RF24Mesh_Example.ino b/examples/RF24Mesh_Example/RF24Mesh_Example.ino index 7dce089c..391ea5ac 100644 --- a/examples/RF24Mesh_Example/RF24Mesh_Example.ino +++ b/examples/RF24Mesh_Example/RF24Mesh_Example.ino @@ -54,8 +54,7 @@ void setup() { // mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect Serial.println(F("Could not connect to network.\nConnecting to the mesh...")); } while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS); - } - else { + } else { Serial.println(F("Radio hardware not responding.")); while (1) { // hold in an infinite loop @@ -90,7 +89,8 @@ void loop() { Serial.println("Send fail, Test OK"); } } else { - Serial.print("Send OK: "); Serial.println(displayTimer); + Serial.print("Send OK: "); + Serial.println(displayTimer); } } diff --git a/examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino b/examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino index 00263b6e..f93f7af5 100644 --- a/examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino +++ b/examples/RF24Mesh_Example_Master/RF24Mesh_Example_Master.ino @@ -42,7 +42,6 @@ void setup() { // hold in an infinite loop } } - } @@ -64,8 +63,14 @@ void loop() { uint32_t dat = 0; switch (header.type) { // Display the incoming millis() values from the sensor nodes - case 'M': network.read(header, &dat, sizeof(dat)); Serial.println(dat); break; - default: network.read(header, 0, 0); Serial.println(header.type); break; + case 'M': + network.read(header, &dat, sizeof(dat)); + Serial.println(dat); + break; + default: + network.read(header, 0, 0); + Serial.println(header.type); + break; } } diff --git a/examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino b/examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino index 3ed501e7..e036d96c 100644 --- a/examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino +++ b/examples/RF24Mesh_Example_Master_Statics/RF24Mesh_Example_Master_Statics.ino @@ -55,7 +55,6 @@ void setup() { // either node, to the master node. mesh.setStaticAddress(23, 02); mesh.setStaticAddress(24, 03); - } uint32_t displayTimer = 0; @@ -78,12 +77,16 @@ void loop() { uint32_t dat = 0; switch (header.type) { // Display the incoming millis() values from the sensor nodes - case 'M': network.read(header, &dat, sizeof(dat)); + case 'M': + network.read(header, &dat, sizeof(dat)); Serial.print(dat); Serial.print(" from RF24Network address 0"); Serial.println(header.from_node, OCT); break; - default: network.read(header, 0, 0); Serial.println(header.type); break; + default: + network.read(header, 0, 0); + Serial.println(header.type); + break; } } diff --git a/examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino b/examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino index f61e4e40..4a9496c1 100644 --- a/examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino +++ b/examples/RF24Mesh_Example_Master_To_Nodes/RF24Mesh_Example_Master_To_Nodes.ino @@ -46,7 +46,6 @@ void setup() { // hold in an infinite loop } } - } uint32_t displayTimer = 0; @@ -88,13 +87,12 @@ void loop() { if (millis() - displayTimer > 5000) { ctr++; for (int i = 0; i < mesh.addrListTop; i++) { - payload_t payload = {millis(), ctr}; + payload_t payload = { millis(), ctr }; if (mesh.addrList[i].nodeID == 1) { //Searching for node one from address list - payload = {ctr % 3, ctr}; + payload = { ctr % 3, ctr }; } - RF24NetworkHeader header(mesh.addrList[i].address, OCT); //Constructing a header - Serial.println( network.write(header, &payload, sizeof(payload)) == 1 ? F("Send OK") : F("Send Fail")); //Sending an message - + RF24NetworkHeader header(mesh.addrList[i].address, OCT); //Constructing a header + Serial.println(network.write(header, &payload, sizeof(payload)) == 1 ? F("Send OK") : F("Send Fail")); //Sending an message } displayTimer = millis(); } diff --git a/examples/RF24Mesh_Example_Node2Node/RF24Mesh_Example_Node2Node.ino b/examples/RF24Mesh_Example_Node2Node/RF24Mesh_Example_Node2Node.ino index ce633c55..4fc67c01 100644 --- a/examples/RF24Mesh_Example_Node2Node/RF24Mesh_Example_Node2Node.ino +++ b/examples/RF24Mesh_Example_Node2Node/RF24Mesh_Example_Node2Node.ino @@ -50,8 +50,7 @@ void setup() { // mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect Serial.println(F("Could not connect to network.\nConnecting to the mesh...")); } while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS); - } - else { + } else { Serial.println(F("Radio hardware not responding.")); while (1) { // hold in an infinite loop @@ -69,10 +68,11 @@ void loop() { RF24NetworkHeader header; uint32_t mills; network.read(header, &mills, sizeof(mills)); - Serial.print(F("Rcv ")); Serial.print(mills); + Serial.print(F("Rcv ")); + Serial.print(mills); Serial.print(F(" from nodeID ")); int _ID = mesh.getNodeID(header.from_node); - if ( _ID > 0) { + if (_ID > 0) { Serial.println(_ID); } else { Serial.println(F("Mesh ID Lookup Failed")); @@ -95,5 +95,4 @@ void loop() { } } } - } diff --git a/examples/RF24Mesh_Example_Node2NodeExtra/RF24Mesh_Example_Node2NodeExtra.ino b/examples/RF24Mesh_Example_Node2NodeExtra/RF24Mesh_Example_Node2NodeExtra.ino index 666ea683..b5bd7bc4 100644 --- a/examples/RF24Mesh_Example_Node2NodeExtra/RF24Mesh_Example_Node2NodeExtra.ino +++ b/examples/RF24Mesh_Example_Node2NodeExtra/RF24Mesh_Example_Node2NodeExtra.ino @@ -35,7 +35,7 @@ RF24Mesh mesh(radio, network); uint32_t millisTimer = 0; uint32_t stringTimer = 0; -char dataStr[] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"}; +char dataStr[] = { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" }; char tmpStr[sizeof(dataStr) + 1]; uint8_t strCtr = 1; @@ -59,8 +59,7 @@ void setup() { // mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect Serial.println(F("Connecting to the mesh...")); } - } - else { + } else { Serial.println(F("Radio hardware not responding.")); while (1) { // hold in an infinite loop @@ -107,7 +106,7 @@ void loop() { Serial.print(mills); int _ID = 0; _ID = mesh.getNodeID(hdr.from_node); - if ( _ID > 0) { + if (_ID > 0) { if (_ID == nodeID) { Serial.println(F(" from master.")); } else { @@ -131,7 +130,7 @@ void loop() { // Send to the master node every second - if (millis() - millisTimer >= 1000 ) { + if (millis() - millisTimer >= 1000) { millisTimer = millis(); // Send an 'M' type to other Node containing the current millis() @@ -145,11 +144,12 @@ void loop() { Serial.println(F("Send fail, Test OK")); } } else { - Serial.print(F("Send OK: ")); Serial.println(millisTimer); + Serial.print(F("Send OK: ")); + Serial.println(millisTimer); } } - if (millis() - stringTimer >= delayTime ) { + if (millis() - stringTimer >= delayTime) { stringTimer = millis(); //Copy the current number of characters to the temporary array memcpy(tmpStr, dataStr, strCtr); diff --git a/examples/RF24Mesh_SerialConfig/RF24Mesh_SerialConfig.ino b/examples/RF24Mesh_SerialConfig/RF24Mesh_SerialConfig.ino index e20380b8..deb31beb 100644 --- a/examples/RF24Mesh_SerialConfig/RF24Mesh_SerialConfig.ino +++ b/examples/RF24Mesh_SerialConfig/RF24Mesh_SerialConfig.ino @@ -55,8 +55,7 @@ void setup() { // mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect Serial.println(F("Could not connect to network.\nConnecting to the mesh...")); } while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS); - } - else { + } else { Serial.println(F("Radio hardware not responding.")); while (1) { // hold in an infinite loop @@ -77,5 +76,4 @@ void loop() { // Send the current millis() value to the master node as an 'M' type message mesh.write(&displayTimer, 'M', sizeof(displayTimer)); } - } diff --git a/examples_RPi/RF24Mesh_Example.cpp b/examples_RPi/RF24Mesh_Example.cpp index 2f6917f9..e62aa949 100644 --- a/examples_RPi/RF24Mesh_Example.cpp +++ b/examples_RPi/RF24Mesh_Example.cpp @@ -18,57 +18,57 @@ RF24Mesh mesh(radio, network); uint32_t displayTimer = 0; -int main(int argc, char **argv) +int main(int argc, char** argv) { - // Set the nodeID to 0 for the master node - mesh.setNodeID(4); - // Connect to the mesh - printf("start nodeID %d\n", mesh.getNodeID()); - if (!mesh.begin()) { - if (radio.isChipConnected()) { - do { - // mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect - printf("Could not connect to network.\nConnecting to the mesh...\n"); - } while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS); - } - else { - printf("Radio hardware not responding.\n"); - return 0; + // Set the nodeID to 0 for the master node + mesh.setNodeID(4); + // Connect to the mesh + printf("start nodeID %d\n", mesh.getNodeID()); + if (!mesh.begin()) { + if (radio.isChipConnected()) { + do { + // mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect + printf("Could not connect to network.\nConnecting to the mesh...\n"); + } while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS); + } + else { + printf("Radio hardware not responding.\n"); + return 0; + } } - } - radio.printDetails(); - - while (1) - { - // Call mesh.update to keep the network updated - mesh.update(); + radio.printDetails(); - // Send the current millis() to the master node every second - if (millis() - displayTimer >= 1000) + while (1) { - displayTimer = millis(); + // Call mesh.update to keep the network updated + mesh.update(); - if (!mesh.write(&displayTimer, 'M', sizeof(displayTimer))) - { - // If a write fails, check connectivity to the mesh network - if (!mesh.checkConnection()) + // Send the current millis() to the master node every second + if (millis() - displayTimer >= 1000) { - // The address could be refreshed per a specified timeframe or only when sequential writes fail, etc. - printf("Renewing Address\n"); - mesh.renewAddress(); - } - else - { - printf("Send fail, Test OK\n"); + displayTimer = millis(); + + if (!mesh.write(&displayTimer, 'M', sizeof(displayTimer))) + { + // If a write fails, check connectivity to the mesh network + if (!mesh.checkConnection()) + { + // The address could be refreshed per a specified timeframe or only when sequential writes fail, etc. + printf("Renewing Address\n"); + mesh.renewAddress(); + } + else + { + printf("Send fail, Test OK\n"); + } + } + else + { + printf("Send OK: %u\n", displayTimer); + } } - } - else - { - printf("Send OK: %u\n", displayTimer); - } + delay(1); } - delay(1); - } - return 0; + return 0; } diff --git a/examples_RPi/RF24Mesh_Example_Master.cpp b/examples_RPi/RF24Mesh_Example_Master.cpp index f12aaa8e..243c674d 100644 --- a/examples_RPi/RF24Mesh_Example_Master.cpp +++ b/examples_RPi/RF24Mesh_Example_Master.cpp @@ -18,49 +18,49 @@ RF24 radio(22, 0); RF24Network network(radio); RF24Mesh mesh(radio, network); -int main(int argc, char **argv) +int main(int argc, char** argv) { - // Set the nodeID to 0 for the master node - mesh.setNodeID(0); - // Connect to the mesh - printf("start\n"); - if (!mesh.begin()) { - // if mesh.begin() returns false for a master node, then radio.begin() returned false. - printf("Radio hardware not responding.\n"); - return 0; - } - radio.printDetails(); + // Set the nodeID to 0 for the master node + mesh.setNodeID(0); + // Connect to the mesh + printf("start\n"); + if (!mesh.begin()) { + // if mesh.begin() returns false for a master node, then radio.begin() returned false. + printf("Radio hardware not responding.\n"); + return 0; + } + radio.printDetails(); - while (1) - { - // Call network.update as usual to keep the network updated - mesh.update(); + while (1) + { + // Call network.update as usual to keep the network updated + mesh.update(); - // In addition, keep the 'DHCP service' running on the master node so addresses will - // be assigned to the sensor nodes - mesh.DHCP(); + // In addition, keep the 'DHCP service' running on the master node so addresses will + // be assigned to the sensor nodes + mesh.DHCP(); - // Check for incoming data from the sensors - while (network.available()) - { - // printf("rcv\n"); - RF24NetworkHeader header; - network.peek(header); + // Check for incoming data from the sensors + while (network.available()) + { + // printf("rcv\n"); + RF24NetworkHeader header; + network.peek(header); - uint32_t dat = 0; - switch (header.type) - { // Display the incoming millis() values from the sensor nodes - case 'M': - network.read(header, &dat, sizeof(dat)); - printf("Rcv %u from 0%o\n", dat, header.from_node); - break; - default: - network.read(header, 0, 0); - printf("Rcv bad type %d from 0%o\n", header.type, header.from_node); - break; - } + uint32_t dat = 0; + switch (header.type) + { // Display the incoming millis() values from the sensor nodes + case 'M': + network.read(header, &dat, sizeof(dat)); + printf("Rcv %u from 0%o\n", dat, header.from_node); + break; + default: + network.read(header, 0, 0); + printf("Rcv bad type %d from 0%o\n", header.type, header.from_node); + break; + } + } + delay(2); } - delay(2); - } - return 0; + return 0; } diff --git a/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp b/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp index 03f31649..921cc88d 100644 --- a/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp +++ b/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp @@ -36,8 +36,8 @@ void pingNode(uint8_t listNo); uint8_t nodeCounter; uint16_t failID = 0; -WINDOW *win; -WINDOW *topoPad; +WINDOW* win; +WINDOW* topoPad; void drawTopology(); int nodeY, nodeX = 0; int maxY, maxX = 0; @@ -45,243 +45,248 @@ int maxY, maxX = 0; int main() { - printf("Establishing mesh...\n"); - mesh.setNodeID(0); - if (!mesh.begin()) { - // if mesh.begin() returns false for a master node, then radio.begin() returned false. - printf("Radio hardware not responding.\n"); - return 0; - } - radio.printDetails(); - mesh.setStaticAddress(8,01); - win = initscr(); /* Start curses mode */ - getmaxyx(win, maxX, maxY); - start_color(); - curs_set(0); - //keypad(stdscr, TRUE); //Enable user interaction - init_pair(1, COLOR_GREEN, COLOR_BLACK); - init_pair(2, COLOR_BLUE, COLOR_GREEN); - init_pair(3, COLOR_MAGENTA, COLOR_BLACK); - init_pair(4, COLOR_YELLOW, COLOR_BLACK); - init_pair(5, COLOR_CYAN, COLOR_BLACK); - topoPad = newpad(31, 75); - attron(COLOR_PAIR(1)); - printw("RF24Mesh Master Node Monitoring Interface by TMRh20 - 2014-2022\n"); - attroff(COLOR_PAIR(1)); - refresh(); /* Print it on to the real screen */ - - uint32_t kbTimer = 0, kbCount = 0, pingTimer = millis(); - unsigned long totalPayloads = 0; - uint8_t boldID = 0; - - while (1) - { - - // Call mesh.update to keep the network updated - mesh.update(); - // In addition, keep the 'DHCP service' running on the master node so addresses will - // be assigned to the sensor nodes - mesh.DHCP(); + printf("Establishing mesh...\n"); + mesh.setNodeID(0); + if (!mesh.begin()) { + // if mesh.begin() returns false for a master node, then radio.begin() returned false. + printf("Radio hardware not responding.\n"); + return 0; + } + radio.printDetails(); + mesh.setStaticAddress(8, 01); + win = initscr(); /* Start curses mode */ + getmaxyx(win, maxX, maxY); + start_color(); + curs_set(0); + //keypad(stdscr, TRUE); //Enable user interaction + init_pair(1, COLOR_GREEN, COLOR_BLACK); + init_pair(2, COLOR_BLUE, COLOR_GREEN); + init_pair(3, COLOR_MAGENTA, COLOR_BLACK); + init_pair(4, COLOR_YELLOW, COLOR_BLACK); + init_pair(5, COLOR_CYAN, COLOR_BLACK); + topoPad = newpad(31, 75); + attron(COLOR_PAIR(1)); + printw("RF24Mesh Master Node Monitoring Interface by TMRh20 - 2014-2022\n"); + attroff(COLOR_PAIR(1)); + refresh(); /* Print it on to the real screen */ + + uint32_t kbTimer = 0, kbCount = 0, pingTimer = millis(); + unsigned long totalPayloads = 0; + uint8_t boldID = 0; + + while (1) + { + + // Call mesh.update to keep the network updated + mesh.update(); + // In addition, keep the 'DHCP service' running on the master node so addresses will + // be assigned to the sensor nodes + mesh.DHCP(); + + attron(A_BOLD | COLOR_PAIR(1)); + mvprintw(2, 0, "[Last Payload Info]\n"); + attroff(A_BOLD | COLOR_PAIR(1)); + + // Check for incoming data from the sensors + while (network.available()) { + RF24NetworkHeader header; + network.peek(header); + + // Print the total number of received payloads + mvprintw(9, 0, " Total: %lu\n", totalPayloads++); + + kbCount++; + + // Read the network payload + network.read(header, 0, 0); + + // Display the header info + mvprintw(3, 0, " HeaderID: %u \n Type: %d \n From: 0%o \n ", header.id, header.type, header.from_node); + + for (uint8_t i = 0; i < mesh.addrListTop; i++) { + if (header.from_node == mesh.addrList[i].address) { + boldID = mesh.addrList[i].nodeID; + } + } + } + printNodes(boldID); + + if (millis() - kbTimer > 1000) { + kbTimer = millis(); + attron(A_BOLD | COLOR_PAIR(1)); + mvprintw(7, 0, "[Data Rate (In)]"); + attroff(A_BOLD | COLOR_PAIR(1)); + mvprintw(8, 0, " Kbps: %.2f", (kbCount * 32 * 8) / 1000.00); + kbCount = 0; + } - attron(A_BOLD | COLOR_PAIR(1)); - mvprintw(2, 0, "[Last Payload Info]\n"); - attroff(A_BOLD | COLOR_PAIR(1)); + // Ping each connected node, one per second + if (millis() - pingTimer > 1003 && mesh.addrListTop > 0) { + pingTimer = millis(); + if (nodeCounter == mesh.addrListTop) { + nodeCounter = 0; + } + pingNode(nodeCounter); + nodeCounter++; + drawTopology(); + } - // Check for incoming data from the sensors - while (network.available()) { - RF24NetworkHeader header; - network.peek(header); + /* + uint32_t nOK, nFails; + network.failures(&nFails, &nOK); + attron(A_BOLD | COLOR_PAIR(1)); + mvprintw(2, 24, "[Transmit Results] "); + attroff(A_BOLD | COLOR_PAIR(1)); + mvprintw(3, 25, " #OK: %u ", nOK); + mvprintw(4, 25, " #Fail: %u ", nFails); + */ - // Print the total number of received payloads - mvprintw(9, 0, " Total: %lu\n", totalPayloads++); + prefresh(topoPad, 0, 0, 18, 1, maxX - 1, maxY - 2); + refresh(); - kbCount++; + delay(2); + } //while 1 - // Read the network payload - network.read(header, 0, 0); + endwin(); /* End curses mode */ + return 0; +} - // Display the header info - mvprintw(3, 0, " HeaderID: %u \n Type: %d \n From: 0%o \n ", header.id, header.type, header.from_node); +void printNodes(uint8_t boldID) +{ - for (uint8_t i = 0; i < mesh.addrListTop; i++) { - if (header.from_node == mesh.addrList[i].address) { - boldID = mesh.addrList[i].nodeID; + uint8_t xCoord = 2; + attron(A_BOLD | COLOR_PAIR(1)); + mvprintw(xCoord++, 27, "[Address Assignments]\n"); + attroff(A_BOLD | COLOR_PAIR(1)); + for (uint8_t i = 0; i < mesh.addrListTop; i++) { + if (failID == mesh.addrList[i].nodeID) { + attron(COLOR_PAIR(2)); } - } - } - printNodes(boldID); - - if (millis() - kbTimer > 1000) { - kbTimer = millis(); - attron(A_BOLD | COLOR_PAIR(1)); - mvprintw(7, 0, "[Data Rate (In)]"); - attroff(A_BOLD | COLOR_PAIR(1)); - mvprintw(8, 0, " Kbps: %.2f", (kbCount * 32 * 8) / 1000.00); - kbCount = 0; - } - - // Ping each connected node, one per second - if (millis() - pingTimer > 1003 && mesh.addrListTop > 0) { - pingTimer = millis(); - if ( nodeCounter == mesh.addrListTop) { - nodeCounter = 0; - } - pingNode(nodeCounter); - nodeCounter++; - drawTopology(); - + else if (boldID == mesh.addrList[i].nodeID) { + attron(A_BOLD | COLOR_PAIR(1)); + } + mvprintw(xCoord++, 28, "ID: %d Network: 0%o ", mesh.addrList[i].nodeID, mesh.addrList[i].address); + attroff(A_BOLD | COLOR_PAIR(1)); + attroff(COLOR_PAIR(2)); } - - /*uint32_t nOK,nFails; - network.failures(&nFails,&nOK); - attron(A_BOLD | COLOR_PAIR(1)); - mvprintw(2,24,"[Transmit Results] "); - attroff(A_BOLD | COLOR_PAIR(1)); - mvprintw(3,25," #OK: %u ",nOK); - mvprintw(4,25," #Fail: %u ",nFails);*/ - - prefresh(topoPad, 0, 0, 18 , 1, maxX-1, maxY-2); - refresh(); - - delay(2); - }//while 1 - - endwin(); /* End curses mode */ - return 0; + //mvprintw(xCoord++, 28, " "); + //mvprintw(xCoord++, 28, " "); + //mvprintw(xCoord++, 28, " "); + getyx(win, nodeY, nodeX); } +void pingNode(uint8_t listNo) +{ -void printNodes(uint8_t boldID) { - - uint8_t xCoord = 2; - attron(A_BOLD | COLOR_PAIR(1)); - mvprintw(xCoord++, 27, "[Address Assignments]\n"); - attroff(A_BOLD | COLOR_PAIR(1)); - for ( uint8_t i = 0; i < mesh.addrListTop; i++) { - if ( failID == mesh.addrList[i].nodeID) { - attron(COLOR_PAIR(2)); - } else if ( boldID == mesh.addrList[i].nodeID ) { - attron(A_BOLD | COLOR_PAIR(1)); - } - mvprintw(xCoord++, 28, "ID: %d Network: 0%o ", mesh.addrList[i].nodeID, mesh.addrList[i].address); + attron(A_BOLD | COLOR_PAIR(1)); + mvprintw(11, 0, "[Ping Test]\n"); attroff(A_BOLD | COLOR_PAIR(1)); - attroff(COLOR_PAIR(2)); - } - //mvprintw(xCoord++, 28, " "); - //mvprintw(xCoord++, 28, " "); - //mvprintw(xCoord++, 28, " "); - getyx(win,nodeY,nodeX); -} -void pingNode(uint8_t listNo) { - - attron(A_BOLD | COLOR_PAIR(1)); - mvprintw(11, 0, "[Ping Test]\n"); - attroff(A_BOLD | COLOR_PAIR(1)); + RF24NetworkHeader headers(mesh.addrList[listNo].address, NETWORK_PING); + uint32_t pingtime = millis(); + bool ok = false; + if (headers.to_node) { + ok = network.write(headers, 0, 0); + if (ok && failID == mesh.addrList[listNo].nodeID) { + failID = 0; + } + if (!ok) { + failID = mesh.addrList[listNo].nodeID; + } + } + pingtime = millis() - pingtime; + mvprintw(12, 0, " ID:%d ", mesh.addrList[listNo].nodeID); + mvprintw(13, 0, " Net:0%o ", mesh.addrList[listNo].address); + mvprintw(14, 0, " Time:%ums ", pingtime); - RF24NetworkHeader headers(mesh.addrList[listNo].address, NETWORK_PING); - uint32_t pingtime = millis(); - bool ok = false; - if (headers.to_node) { - ok = network.write(headers, 0, 0); - if (ok && failID == mesh.addrList[listNo].nodeID) { - failID = 0; + if (ok || !headers.to_node) { + mvprintw(15, 0, " OK "); } - if (!ok) { - failID = mesh.addrList[listNo].nodeID; + else { + attron(A_BOLD); + mvprintw(15, 0, " FAIL"); + attroff(A_BOLD); } - } - pingtime = millis() - pingtime; - mvprintw(12, 0, " ID:%d ", mesh.addrList[listNo].nodeID); - mvprintw(13, 0, " Net:0%o ", mesh.addrList[listNo].address); - mvprintw(14, 0, " Time:%ums ", pingtime); - - if (ok || !headers.to_node) { - mvprintw(15, 0, " OK "); - } else { - attron(A_BOLD); - mvprintw(15, 0, " FAIL"); - attroff(A_BOLD); - } } /****************************************************************************************/ -void drawTopology(){ - wclear(topoPad); - wattroff(topoPad, COLOR_PAIR(1)); - mvprintw(17,10,"Mesh Topology"); - mvwprintw(topoPad, nodeY > 15 ? nodeY-16 : 0,0,""); - wattron(topoPad,COLOR_PAIR(1)); - int topoPadmaxX; - topoPadmaxX = getmaxx(topoPad); - - for (int i = 01; i < 06; i++){ - for (int j = 0; j < mesh.addrListTop; j++){ - - if(mesh.addrList[j].address == i){ - wprintw(topoPad,"0%o[%d] | ", mesh.addrList[j].address, mesh.addrList[j].nodeID); - } - - } - } - wprintw(topoPad,"\n"); - wattron(topoPad,COLOR_PAIR(4)); - uint16_t g = 051; - for(int h = 011; h <= 015; h++){ - - for (int i = h; i <= g; i+=010){ - - for (int j = 0; j < mesh.addrListTop; j++){ - if(mesh.addrList[j].address == i){ - int y=0; int x=0; - getyx(topoPad,y,x); - if(x >= topoPadmaxX){ wprintw(topoPad,"\n"); } - wprintw(topoPad,"0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); - } - } - } - g++; - wprintw(topoPad, "| "); - } - wprintw(topoPad,"\n"); - wattron(topoPad,COLOR_PAIR(5)); - g = 0411; - for(int h = 0111; h <= 0145; h++){ - - for (int i = h; i <= g; i+=0100){ - - for (int j = 0; j < mesh.addrListTop; j++){ - if(mesh.addrList[j].address == i){ - int y=0; int x=0; - getyx(topoPad, y, x); - if(x >= topoPadmaxX){ wprintw(topoPad,"\n"); } - wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); - } - } - } - g++; - - } - wprintw(topoPad,"\n"); - wattron(topoPad,COLOR_PAIR(3)); - g = 04111; - - for(int h = 01111; h <= 01445; h++){ - - for (int i = h; i <= g; i+=01000){ - - for (int j = 0; j < mesh.addrListTop; j++){ - if(mesh.addrList[j].address == i){ - int y=0; int x=0; - getyx(topoPad,y,x); - if(x >= topoPadmaxX){ wprintw(topoPad,"\n"); } - wprintw(topoPad,"0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); - } - } - } - g++; - - } - wattroff(topoPad,COLOR_PAIR(2)); +void drawTopology() +{ + wclear(topoPad); + wattroff(topoPad, COLOR_PAIR(1)); + mvprintw(17, 10, "Mesh Topology"); + mvwprintw(topoPad, nodeY > 15 ? nodeY - 16 : 0, 0, ""); + wattron(topoPad, COLOR_PAIR(1)); + int topoPadmaxX; + topoPadmaxX = getmaxx(topoPad); + + for (int i = 01; i < 06; i++) { + for (int j = 0; j < mesh.addrListTop; j++) { + + if (mesh.addrList[j].address == i) { + wprintw(topoPad, "0%o[%d] | ", mesh.addrList[j].address, mesh.addrList[j].nodeID); + } + } + } + wprintw(topoPad, "\n"); + wattron(topoPad, COLOR_PAIR(4)); + uint16_t g = 051; + for (int h = 011; h <= 015; h++) { + + for (int i = h; i <= g; i += 010) { + + for (int j = 0; j < mesh.addrListTop; j++) { + if (mesh.addrList[j].address == i) { + int y = 0; + int x = 0; + getyx(topoPad, y, x); + if (x >= topoPadmaxX) wprintw(topoPad, "\n"); + wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); + } + } + } + g++; + wprintw(topoPad, "| "); + } + wprintw(topoPad, "\n"); + wattron(topoPad, COLOR_PAIR(5)); + g = 0411; + for (int h = 0111; h <= 0145; h++) { + + for (int i = h; i <= g; i += 0100) { + + for (int j = 0; j < mesh.addrListTop; j++) { + if (mesh.addrList[j].address == i) { + int y = 0; + int x = 0; + getyx(topoPad, y, x); + if (x >= topoPadmaxX) wprintw(topoPad, "\n"); + wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); + } + } + } + g++; + } + wprintw(topoPad, "\n"); + wattron(topoPad, COLOR_PAIR(3)); + g = 04111; + + for (int h = 01111; h <= 01445; h++) { + + for (int i = h; i <= g; i += 01000) { + + for (int j = 0; j < mesh.addrListTop; j++) { + if (mesh.addrList[j].address == i) { + int y = 0; + int x = 0; + getyx(topoPad, y, x); + if (x >= topoPadmaxX) wprintw(topoPad, "\n"); + wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); + } + } + } + g++; + } + wattroff(topoPad, COLOR_PAIR(2)); } \ No newline at end of file diff --git a/examples_pico/RF24Mesh_Example.cpp b/examples_pico/RF24Mesh_Example.cpp index 269809c1..7e34412d 100644 --- a/examples_pico/RF24Mesh_Example.cpp +++ b/examples_pico/RF24Mesh_Example.cpp @@ -8,12 +8,12 @@ * nodes to change position in relation to each other and the master node. * */ -#include "pico/stdlib.h" // printf(), sleep_ms(), to_ms_since_boot(), get_absolute_time() -#include // tud_cdc_connected() -#include // RF24 radio object -#include // RF24Network network object -#include // RF24Mesh mesh object -#include "defaultPins.h" // board presumptive default pin numbers for CE_PIN and CSN_PIN +#include "pico/stdlib.h" // printf(), sleep_ms(), to_ms_since_boot(), get_absolute_time() +#include // tud_cdc_connected() +#include // RF24 radio object +#include // RF24Network network object +#include // RF24Mesh mesh object +#include "defaultPins.h" // board presumptive default pin numbers for CE_PIN and CSN_PIN // instantiate an object for the nRF24L01 transceiver RF24 radio(CE_PIN, CSN_PIN); diff --git a/examples_pico/RF24Mesh_Example_Master.cpp b/examples_pico/RF24Mesh_Example_Master.cpp index 84e924c8..fc9a513e 100644 --- a/examples_pico/RF24Mesh_Example_Master.cpp +++ b/examples_pico/RF24Mesh_Example_Master.cpp @@ -6,12 +6,12 @@ * routing nodes as required. The master node manages the address assignments for the individual nodes * in a manner similar to DHCP. */ -#include "pico/stdlib.h" // printf(), sleep_ms(), to_ms_since_boot(), get_absolute_time() -#include // tud_cdc_connected() -#include // RF24 radio object -#include // RF24Network network object -#include // RF24Mesh mesh object -#include "defaultPins.h" // board presumptive default pin numbers for CE_PIN and CSN_PIN +#include "pico/stdlib.h" // printf(), sleep_ms(), to_ms_since_boot(), get_absolute_time() +#include // tud_cdc_connected() +#include // RF24 radio object +#include // RF24Network network object +#include // RF24Mesh mesh object +#include "defaultPins.h" // board presumptive default pin numbers for CE_PIN and CSN_PIN // instantiate an object for the nRF24L01 transceiver RF24 radio(CE_PIN, CSN_PIN); @@ -42,7 +42,6 @@ bool setup() return true; } - void loop() { // Call network.update as usual to keep the network updated @@ -73,7 +72,6 @@ void loop() } } - int main() { stdio_init_all(); // init necessary IO for the RP2040 diff --git a/examples_pico/defaultPins.h b/examples_pico/defaultPins.h index e6819cac..859a0920 100644 --- a/examples_pico/defaultPins.h +++ b/examples_pico/defaultPins.h @@ -2,28 +2,27 @@ #ifndef DEFAULTPINS_H #define DEFAULTPINS_H -#if defined (ADAFRUIT_QTPY_RP2040) -// for this board, you can still use the Stemma QT connector as a separate I2C bus (`i2c1`) -#define CE_PIN PICO_DEFAULT_I2C_SDA_PIN // the pin labeled SDA -#define CSN_PIN PICO_DEFAULT_I2C_SCL_PIN // the pin labeled SCL +#if defined(ADAFRUIT_QTPY_RP2040) + // for this board, you can still use the Stemma QT connector as a separate I2C bus (`i2c1`) + #define CE_PIN PICO_DEFAULT_I2C_SDA_PIN // the pin labeled SDA + #define CSN_PIN PICO_DEFAULT_I2C_SCL_PIN // the pin labeled SCL -#elif defined (PIMORONI_TINY2040) -// default SPI_SCK_PIN = 6 -// default SPI_TX_PIN = 7 -// default SPI_RX_PIN = 4 -#define CE_PIN PICO_DEFAULT_I2C_SCL_PIN // pin 3 -#define CSN_PIN PICO_DEFAULT_SPI_CSN_PIN // pin 5 +#elif defined(PIMORONI_TINY2040) + // default SPI_SCK_PIN = 6 + // default SPI_TX_PIN = 7 + // default SPI_RX_PIN = 4 + #define CE_PIN PICO_DEFAULT_I2C_SCL_PIN // pin 3 + #define CSN_PIN PICO_DEFAULT_SPI_CSN_PIN // pin 5 - -#elif defined (SPARFUN_THINGPLUS) -#define CSN_PIN 16 // the pin labeled 16 -#define CE_PIN 7 // the pin labeled SCL +#elif defined(SPARFUN_THINGPLUS) + #define CSN_PIN 16 // the pin labeled 16 + #define CE_PIN 7 // the pin labeled SCL #else -// pins available on (ADAFRUIT_ITSYBITSY_RP2040 || ADAFRUIT_FEATHER_RP2040 || Pico_board || Sparkfun_ProMicro || SparkFun MicroMod) + // pins available on (ADAFRUIT_ITSYBITSY_RP2040 || ADAFRUIT_FEATHER_RP2040 || Pico_board || Sparkfun_ProMicro || SparkFun MicroMod) -#define CE_PIN 7 -#define CSN_PIN 8 + #define CE_PIN 7 + #define CSN_PIN 8 #endif // board detection macro defs #endif // DEFAULTPINS_H diff --git a/pyRF24Mesh/pyRF24Mesh.cpp b/pyRF24Mesh/pyRF24Mesh.cpp index 2d042141..15e41691 100644 --- a/pyRF24Mesh/pyRF24Mesh.cpp +++ b/pyRF24Mesh/pyRF24Mesh.cpp @@ -5,7 +5,6 @@ namespace bp = boost::python; - // ******************** explicit wrappers ************************** // where needed, especially where buffer is involved @@ -15,9 +14,9 @@ void throw_ba_exception(void) bp::throw_error_already_set(); } -char *get_bytes_or_bytearray_str(bp::object buf) +char* get_bytes_or_bytearray_str(bp::object buf) { - PyObject *py_ba; + PyObject* py_ba; py_ba = buf.ptr(); if (PyByteArray_Check(py_ba)) return PyByteArray_AsString(py_ba); @@ -31,7 +30,7 @@ char *get_bytes_or_bytearray_str(bp::object buf) int get_bytes_or_bytearray_ln(bp::object buf) { - PyObject *py_ba; + PyObject* py_ba; py_ba = buf.ptr(); if (PyByteArray_Check(py_ba)) return PyByteArray_Size(py_ba); @@ -45,17 +44,17 @@ int get_bytes_or_bytearray_ln(bp::object buf) bool write_wrap1(RF24Mesh& ref, bp::object buf, uint8_t msg_type) { - return ref.write(get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf)); + return ref.write(get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf)); } bool write_wrap2(RF24Mesh& ref, bp::object buf, uint8_t msg_type, uint8_t nodeID) { - return ref.write(get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf), nodeID); + return ref.write(get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf), nodeID); } -bool write_to_node_wrap(RF24Mesh& ref, uint16_t to_node, bp::object buf, uint8_t msg_type) +bool write_to_node_wrap(RF24Mesh& ref, uint16_t to_node, bp::object buf, uint8_t msg_type) { - return ref.write(to_node, get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf)); + return ref.write(to_node, get_bytes_or_bytearray_str(buf), msg_type, get_bytes_or_bytearray_ln(buf)); } // ******************** overload wrappers ************************** From 9f6ac9b5d67cce121249a550e8d66792072c502e Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 17:31:29 -0700 Subject: [PATCH 3/8] Arduino CI make PR size delta reports --- .github/workflows/build_arduino.yml | 40 +++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_arduino.yml b/.github/workflows/build_arduino.yml index 97e53ba7..b06d65fc 100644 --- a/.github/workflows/build_arduino.yml +++ b/.github/workflows/build_arduino.yml @@ -12,6 +12,10 @@ on: - ".github/workflows/build_arduino.yml" - "examples/**" +env: + # convenient variable used multiple times + SKETCHES_REPORTS: sketches-reports + jobs: check_formatting: runs-on: ubuntu-latest @@ -42,7 +46,6 @@ jobs: - "arduino:avr:yun" - "arduino:avr:uno" - "arduino:avr:diecimila" - - "arduino:avr:nano" - "arduino:avr:mega" - "arduino:avr:megaADK" - "arduino:avr:leonardo" @@ -65,7 +68,6 @@ jobs: - "arduino:avr:unowifi" - "arduino:mbed:nano33ble" - "arduino:samd:mkr1000" - - "arduino:samd:mkrzero" - "arduino:samd:mkrwifi1010" - "arduino:samd:nano_33_iot" - "arduino:samd:mkrfox1200" @@ -80,6 +82,15 @@ jobs: - "arduino:samd:tian" - "arduino:megaavr:uno2018" # - "arduino:megaavr:nano4809" # board not found + # By default, don't generate size deltas data. + enable-deltas-report: + - false + # Generate size deltas data for this board + include: + - fqbn: arduino:avr:nano + enable-deltas-report: true + - fqbn: arduino:samd:mkrzero + enable-deltas-report: true steps: - name: Checkout @@ -101,3 +112,28 @@ jobs: - source-path: ./ # - name: RF24Network fqbn: ${{ matrix.fqbn }} + enable-deltas-report: ${{ matrix.enable-deltas-report }} + sketches-report-path: ${{ env.SKETCHES_REPORTS }} + # This step is needed to pass the size data to the report job + - name: Upload sketches report to workflow artifact + if: ${{ matrix.enable-deltas-report }} + uses: actions/upload-artifact@v2 + with: + name: ${{ env.SKETCHES_REPORTS }} + path: ${{ env.SKETCHES_REPORTS }} + + # When using a matrix to compile for multiple boards, it's necessary to use a separate job for the deltas report + report: + needs: [build] + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Download sketches reports artifact + uses: actions/download-artifact@v2 + with: + name: ${{ env.SKETCHES_REPORTS }} + path: ${{ env.SKETCHES_REPORTS }} + + - uses: arduino/report-size-deltas@v1 + with: + sketches-reports-source: ${{ env.SKETCHES_REPORTS }} \ No newline at end of file From 7f6c717e4d5fd269a90e49bceb02a9f02aa3ec23 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 17:43:46 -0700 Subject: [PATCH 4/8] update workflows --- .github/workflows/build_arduino.yml | 35 ++++++++++++++++---------- .github/workflows/build_platformIO.yml | 34 +++++++++++++++---------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build_arduino.yml b/.github/workflows/build_arduino.yml index b06d65fc..1ebf029d 100644 --- a/.github/workflows/build_arduino.yml +++ b/.github/workflows/build_arduino.yml @@ -21,19 +21,28 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Check code formatting - uses: per1234/artistic-style-action@main - with: - options-file-path: ./examples/examples_formatter.conf - name-patterns: | - - '*.ino' - - '*.cpp' - - '*.hpp' - - '*.h' - target-paths: | - - examples + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + # Ubuntu 20.04.4 LTS reunners ship with clang-tools v12 + # - name: Install clang-tools + # uses: KyleMayes/install-llvm-action@v1 + # with: + # version: 12 + - name: Install linter python package + run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1 + - name: run linter as a python package + id: linter + run: | + cpp-linter \ + --version=12 \ + --style=file \ + --tidy-checks='-*' \ + --files-changed-only='False' \ + --extensions=ino + - name: Linter checks failed? + if: steps.linter.outputs.checks-failed > 0 + run: exit 1 + build: needs: check_formatting runs-on: ubuntu-latest diff --git a/.github/workflows/build_platformIO.yml b/.github/workflows/build_platformIO.yml index 07a7c019..3b5885a3 100644 --- a/.github/workflows/build_platformIO.yml +++ b/.github/workflows/build_platformIO.yml @@ -65,19 +65,27 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Check code formatting - uses: per1234/artistic-style-action@main - with: - options-file-path: ./examples/examples_formatter.conf - name-patterns: | - - '*.ino' - - '*.cpp' - - '*.hpp' - - '*.h' - target-paths: | - - examples + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + # Ubuntu 20.04.4 LTS reunners ship with clang-tools v12 + # - name: Install clang-tools + # uses: KyleMayes/install-llvm-action@v1 + # with: + # version: 12 + - name: Install linter python package + run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1 + - name: run linter as a python package + id: linter + run: | + cpp-linter \ + --version=12 \ + --style=file \ + --tidy-checks='-*' \ + --files-changed-only='False' \ + --extensions=ino + - name: Linter checks failed? + if: steps.linter.outputs.checks-failed > 0 + run: exit 1 build: needs: [check_formatting, validate_lib_json] From 5cc09671d4bd555e68557efdb93305a389e7c789 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 17:57:10 -0700 Subject: [PATCH 5/8] MESH_CALLBACK macro must be 2 lines --- RF24Mesh.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RF24Mesh.h b/RF24Mesh.h index 3fa8414e..27bf4eba 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -221,7 +221,8 @@ class RF24Mesh */ void setCallback(void (*meshCallback)(void)); -#define MESH_CALLBACK (if (meshCallback) meshCallback();) +#define MESH_CALLBACK \ + if (meshCallback) meshCallback(); /** * Set or change a @ref _nodeID "nodeID" : node address (key : value) pair manually. From c785a09ac1974d134284484e05b7452463657f8a Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 18:22:49 -0700 Subject: [PATCH 6/8] Update build_linux.yml --- .github/workflows/build_linux.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 061e2af0..14d4eb27 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -34,7 +34,34 @@ env: BUILD_TYPE: Release jobs: + check_formatting: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + # Ubuntu 20.04.4 LTS reunners ship with clang-tools v12 + # - name: Install clang-tools + # uses: KyleMayes/install-llvm-action@v1 + # with: + # version: 12 + - name: Install linter python package + run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1 + - name: run linter as a python package + id: linter + run: | + cpp-linter \ + --version=12 \ + --style=file \ + --tidy-checks='-*' \ + --files-changed-only='False' \ + --ignore='examples|examples_pico' + - name: Linter checks failed? + if: steps.linter.outputs.checks-failed > 0 + run: exit 1 + using_cmake: + needs: check_formatting runs-on: ubuntu-latest strategy: From 35d113592584035e72a08912bdc7c4bd8bfc3ac8 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 18:28:29 -0700 Subject: [PATCH 7/8] update build_rp2xxx.yml --- .github/workflows/build_rp2xxx.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/build_rp2xxx.yml b/.github/workflows/build_rp2xxx.yml index b8f7b72b..65b325d0 100644 --- a/.github/workflows/build_rp2xxx.yml +++ b/.github/workflows/build_rp2xxx.yml @@ -24,7 +24,34 @@ env: BUILD_TYPE: Release jobs: + check_formatting: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + # Ubuntu 20.04.4 LTS reunners ship with clang-tools v12 + # - name: Install clang-tools + # uses: KyleMayes/install-llvm-action@v1 + # with: + # version: 12 + - name: Install linter python package + run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1 + - name: run linter as a python package + id: linter + run: | + cpp-linter \ + --version=12 \ + --style=file \ + --tidy-checks='-*' \ + --files-changed-only='False' \ + --ignore='examples|examples_RPi|' + - name: Linter checks failed? + if: steps.linter.outputs.checks-failed > 0 + run: exit 1 + build: + needs: check_formatting runs-on: ubuntu-latest strategy: From 557dac52397272a7fc5457506d0db17968751769 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 19 Jun 2022 18:33:13 -0700 Subject: [PATCH 8/8] only check pico examples in rp2xxx CI --- .github/workflows/build_rp2xxx.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_rp2xxx.yml b/.github/workflows/build_rp2xxx.yml index 65b325d0..3e5db046 100644 --- a/.github/workflows/build_rp2xxx.yml +++ b/.github/workflows/build_rp2xxx.yml @@ -45,7 +45,7 @@ jobs: --style=file \ --tidy-checks='-*' \ --files-changed-only='False' \ - --ignore='examples|examples_RPi|' + --ignore='!examples_pico|' - name: Linter checks failed? if: steps.linter.outputs.checks-failed > 0 run: exit 1