-
-
Notifications
You must be signed in to change notification settings - Fork 196
ESP-NOW Support #3448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
torbacz
wants to merge
14
commits into
nanoframework:main
Choose a base branch
from
torbacz:espnbow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ESP-NOW Support #3448
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
280def8
ESPNOW initial
torbacz dcab28a
Minor error handling
torbacz 663edbb
Add encryption
torbacz 8fbabc5
Remove debug code/comments
torbacz e66b374
PR fixes
torbacz 8211b43
Fix checksum
torbacz e634e16
Fix declarations
torbacz f478b91
Change implementation to internal queue.
torbacz 1d49d30
More case renames
josesimoes 4f8fc5a
Remove unnecessary type declarations
josesimoes 5a9f808
Add EspNow event
josesimoes ecd9901
Update assembly declaration
josesimoes d7048b4
Rework native implementation to follow managed changes
josesimoes 9fa42d5
Update declaration
josesimoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # | ||
| # Copyright (c) .NET Foundation and Contributors | ||
| # See LICENSE file in the project root for full license information. | ||
| # | ||
|
|
||
| # native code directory | ||
| set(BASE_PATH_FOR_THIS_MODULE ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/nanoFramework.EspNow) | ||
|
|
||
|
|
||
| # set include directories | ||
| list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/CLR/Core) | ||
| list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/CLR/Include) | ||
| list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/HAL/Include) | ||
| list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/PAL/Include) | ||
| list(APPEND nanoFramework.EspNow_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE}) | ||
|
|
||
| # source files | ||
| set(nanoFramework.EspNow_SRCS | ||
| nanoFramework_espnow_native.cpp | ||
| nanoFramework_espnow_native_nanoFramework_EspNow_EspNowController.cpp | ||
| ) | ||
|
|
||
| foreach(SRC_FILE ${nanoFramework.EspNow_SRCS}) | ||
| set(nanoFramework.EspNow_SRC_FILE SRC_FILE-NOTFOUND) | ||
| find_file(nanoFramework.EspNow_SRC_FILE ${SRC_FILE} | ||
| PATHS | ||
| ${BASE_PATH_FOR_THIS_MODULE} | ||
| ${TARGET_BASE_LOCATION} | ||
| CMAKE_FIND_ROOT_PATH_BOTH | ||
| ) | ||
|
|
||
| if (BUILD_VERBOSE) | ||
| message("${SRC_FILE} >> ${nanoFramework.EspNow_SRC_FILE}") | ||
| endif() | ||
|
|
||
| list(APPEND nanoFramework.EspNow_SOURCES ${nanoFramework.EspNow_SRC_FILE}) | ||
| endforeach() | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
|
|
||
| FIND_PACKAGE_HANDLE_STANDARD_ARGS(nanoFramework.EspNow DEFAULT_MSG nanoFramework.EspNow_INCLUDE_DIRS nanoFramework.EspNow_SOURCES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
targets/ESP32/_nanoCLR/nanoFramework.EspNow/nanoFramework_espnow_native.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright (c) .NET Foundation and Contributors | ||
| // See LICENSE file in the project root for full license information. | ||
|
|
||
| #include "nanoFramework_espnow_native.h" | ||
|
|
||
| // clang-format off | ||
|
|
||
| static const CLR_RT_MethodHandler method_lookup[] = | ||
| { | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeInitialize___I4, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeDispose___VOID__BOOLEAN, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeEspNowSend___I4__SZARRAY_U1__SZARRAY_U1__I4, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeEspNowAddPeer___I4__SZARRAY_U1__U1__BOOLEAN__SZARRAY_U1, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeGetMaximumDataLength___I4, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeReadPacket___I4__SZARRAY_U1__SZARRAY_U1__I4, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeGetReceiveOverflowCount___I4, | ||
| Library_nf_espnow_nanoFramework_EspNow_EspNowController::NativeReadSendStatus___I4__SZARRAY_U1, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| }; | ||
|
|
||
| const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_EspNow = | ||
| { | ||
| "nanoFramework.EspNow", | ||
| 0x65E7BDBE, | ||
| method_lookup, | ||
| { 100, 0, 0, 1 } | ||
| }; | ||
|
|
||
| // clang-format on |
110 changes: 110 additions & 0 deletions
110
targets/ESP32/_nanoCLR/nanoFramework.EspNow/nanoFramework_espnow_native.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright (c) .NET Foundation and Contributors | ||
| // See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| #ifndef NANOFRAMEWORK_ESPNOW_NATIVE_H | ||
| #define NANOFRAMEWORK_ESPNOW_NATIVE_H | ||
|
|
||
| #include <nanoCLR_Interop.h> | ||
| #include <nanoCLR_Runtime.h> | ||
| #include <nanoPackStruct.h> | ||
| #include <corlib_native.h> | ||
| #include <nanoHAL.h> | ||
|
|
||
| #include <esp_interface.h> | ||
| #include <esp_wifi.h> | ||
| #include <esp_now.h> | ||
|
|
||
| #ifdef ESP_NOW_MAX_DATA_LEN_V2 | ||
| #define NF_ESPNOW_MAX_DATA_LEN ESP_NOW_MAX_DATA_LEN_V2 | ||
| #else | ||
| #define NF_ESPNOW_MAX_DATA_LEN ESP_NOW_MAX_DATA_LEN | ||
| #endif | ||
|
|
||
| static constexpr uint32_t NF_ESPNOW_RX_QUEUE_DEPTH = 10; | ||
|
|
||
| typedef enum __nfpack EspNowEventType | ||
| { | ||
| EspNowEventType_DataSent = 1, | ||
| EspNowEventType_DataReceived = 2, | ||
| } EspNowEventType; | ||
|
|
||
| typedef enum __nfpack EspNowSendStatus | ||
| { | ||
| EspNowSendStatus_Success = 0, | ||
| EspNowSendStatus_Fail = 1, | ||
| } EspNowSendStatus; | ||
|
|
||
| struct EspNowPacket | ||
| { | ||
| uint8_t peer_mac[ESP_NOW_ETH_ALEN]; | ||
| uint8_t *data; | ||
| uint16_t data_len; | ||
| }; | ||
|
|
||
| struct Library_nf_espnow_nanoFramework_EspNow_DataReceivedEventArgs | ||
| { | ||
| static const int FIELD___peerMac = 1; | ||
| static const int FIELD___data = 2; | ||
| static const int FIELD___dataLen = 3; | ||
|
|
||
| //--// | ||
| }; | ||
|
|
||
| struct Library_nf_espnow_nanoFramework_EspNow_DataSentEventArgs | ||
| { | ||
| static const int FIELD___peerMac = 1; | ||
| static const int FIELD___status = 2; | ||
|
|
||
| //--// | ||
| }; | ||
|
|
||
| struct Library_nf_espnow_nanoFramework_EspNow_EspNowController | ||
| { | ||
| static const int FIELD_STATIC__s_instance = 0; | ||
| static const int FIELD_STATIC__s_syncLock = 1; | ||
| static const int FIELD_STATIC__s_eventListener = 2; | ||
|
|
||
| static const int FIELD___disposed = 1; | ||
| static const int FIELD___syncLock = 2; | ||
| static const int FIELD___callbacksDataReceivedEvent = 3; | ||
| static const int FIELD___callbacksDataSentEvent = 4; | ||
|
|
||
| NANOCLR_NATIVE_DECLARE(NativeInitialize___I4); | ||
| NANOCLR_NATIVE_DECLARE(NativeDispose___VOID__BOOLEAN); | ||
| NANOCLR_NATIVE_DECLARE(NativeEspNowSend___I4__SZARRAY_U1__SZARRAY_U1__I4); | ||
| NANOCLR_NATIVE_DECLARE(NativeEspNowAddPeer___I4__SZARRAY_U1__U1__BOOLEAN__SZARRAY_U1); | ||
| NANOCLR_NATIVE_DECLARE(NativeGetMaximumDataLength___I4); | ||
| NANOCLR_NATIVE_DECLARE(NativeReadPacket___I4__SZARRAY_U1__SZARRAY_U1__I4); | ||
| NANOCLR_NATIVE_DECLARE(NativeGetReceiveOverflowCount___I4); | ||
| NANOCLR_NATIVE_DECLARE(NativeReadSendStatus___I4__SZARRAY_U1); | ||
|
|
||
| //--// | ||
| static void DataSentCb(const wifi_tx_info_t *tx_info, esp_now_send_status_t status); | ||
| static void DataRecvCb(const esp_now_recv_info *recv_info, const uint8_t *incomingData, int len); | ||
| }; | ||
|
|
||
| struct Library_nf_espnow_nanoFramework_EspNow_EspNowEvent | ||
| { | ||
| static const int FIELD__EventType = 3; | ||
|
|
||
| //--// | ||
| }; | ||
|
|
||
| struct Library_nf_espnow_nanoFramework_EspNow_EspNowEventListener | ||
| { | ||
| static const int FIELD___controller = 1; | ||
|
|
||
| //--// | ||
| }; | ||
|
|
||
| struct Library_nf_espnow_nanoFramework_EspNow_EspNowException | ||
| { | ||
| static const int FIELD___espErr = 5; | ||
|
|
||
| //--// | ||
| }; | ||
|
|
||
| extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_EspNow; | ||
|
|
||
| #endif // NANOFRAMEWORK_ESPNOW_NATIVE_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.