From 18efe9990e81ab20538e9a584c96271bad86e771 Mon Sep 17 00:00:00 2001 From: Bryce Gruber Date: Mon, 16 Jun 2025 22:27:38 -0500 Subject: [PATCH] individual device type --- lib/config/config.h | 11 ++++++++--- src/Timer_main.cpp | 7 +++---- src/Tx_main.cpp | 22 ++++++++++++++++------ src/Vrx_main.cpp | 25 +++++++++++++++++-------- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/lib/config/config.h b/lib/config/config.h index 11692e9a..7087b4e4 100644 --- a/lib/config/config.h +++ b/lib/config/config.h @@ -2,10 +2,15 @@ #include "elrs_eeprom.h" +// Identifier for type of backpack +#define TX_BACKPACK_TYPE_ID (0b01U) +#define VRX_BACKPACK_TYPE_ID (0b10U) +#define TIMER_BACKPACK_TYPE_ID (0b11U) + // CONFIG_MAGIC is ORed with CONFIG_VERSION in the version field -#define TX_BACKPACK_CONFIG_MAGIC (0b01U << 30) -#define VRX_BACKPACK_CONFIG_MAGIC (0b10U << 30) -#define TIMER_BACKPACK_CONFIG_MAGIC (0b11U << 30) +#define TX_BACKPACK_CONFIG_MAGIC (TX_BACKPACK_TYPE_ID << 30) +#define VRX_BACKPACK_CONFIG_MAGIC (VRX_BACKPACK_TYPE_ID << 30) +#define TIMER_BACKPACK_CONFIG_MAGIC (TIMER_BACKPACK_TYPE_ID << 30) #define TX_BACKPACK_CONFIG_VERSION 4 #define VRX_BACKPACK_CONFIG_VERSION 5 diff --git a/src/Timer_main.cpp b/src/Timer_main.cpp index d84692d7..2ecb335f 100644 --- a/src/Timer_main.cpp +++ b/src/Timer_main.cpp @@ -160,8 +160,7 @@ void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len) firmwareOptions.uid[1] == mac_addr[1] && firmwareOptions.uid[2] == mac_addr[2] && firmwareOptions.uid[3] == mac_addr[3] && - firmwareOptions.uid[4] == mac_addr[4] && - firmwareOptions.uid[5] == mac_addr[5] + firmwareOptions.uid[4] == mac_addr[4] ) ) { @@ -340,6 +339,8 @@ void SetSoftMACAddress() // MAC address can only be set with unicast, so first byte must be even, not odd firmwareOptions.uid[0] = firmwareOptions.uid[0] & ~0x01; + // Set MAC address to be specific for type of device + firmwareOptions.uid[5] = TIMER_BACKPACK_TYPE_ID; WiFi.mode(WIFI_STA); #if defined(PLATFORM_ESP8266) @@ -448,8 +449,6 @@ void setup() xSemaphoreGive(semaphore); #endif - registerPeer(firmwareOptions.uid); - memcpy(sendAddress, firmwareOptions.uid, 6); } diff --git a/src/Tx_main.cpp b/src/Tx_main.cpp index 6748794a..68e522cb 100644 --- a/src/Tx_main.cpp +++ b/src/Tx_main.cpp @@ -125,12 +125,14 @@ void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len) { // Finished processing a complete packet // Only process packets from a bound MAC address - if (firmwareOptions.uid[0] == mac_addr[0] && + if ((firmwareOptions.uid[0] == mac_addr[0] && firmwareOptions.uid[1] == mac_addr[1] && firmwareOptions.uid[2] == mac_addr[2] && firmwareOptions.uid[3] == mac_addr[3] && - firmwareOptions.uid[4] == mac_addr[4] && - firmwareOptions.uid[5] == mac_addr[5]) + firmwareOptions.uid[4] == mac_addr[4] + ) || + TIMER_BACKPACK_TYPE_ID == mac_addr[5] + ) { ProcessMSPPacketFromPeer(msp.getReceivedPacket()); } @@ -269,7 +271,8 @@ void sendMSPViaEspnow(mspPacket_t *packet) } else { - esp_now_send(firmwareOptions.uid, (uint8_t *) &nowDataOutput, packetSize); + // Address set to NULL sends data to all registered peers + esp_now_send(NULL, (uint8_t *) &nowDataOutput, packetSize); } blinkLED(); @@ -309,6 +312,8 @@ void SetSoftMACAddress() // MAC address can only be set with unicast, so first byte must be even, not odd firmwareOptions.uid[0] = firmwareOptions.uid[0] & ~0x01; + // Set MAC address to be specific for type of device + firmwareOptions.uid[5] = TX_BACKPACK_TYPE_ID; WiFi.mode(WIFI_STA); #if defined(PLATFORM_ESP8266) @@ -388,11 +393,16 @@ void setup() rebootTime = millis(); } + // Create the peer address for transmitter with same UID + uint8_t peer_address[6]; + memcpy(peer_address, firmwareOptions.uid, 6); + peer_address[5] = VRX_BACKPACK_TYPE_ID; + #if defined(PLATFORM_ESP8266) esp_now_set_self_role(ESP_NOW_ROLE_COMBO); - esp_now_add_peer(firmwareOptions.uid, ESP_NOW_ROLE_COMBO, 1, NULL, 0); + esp_now_add_peer(peer_address, ESP_NOW_ROLE_COMBO, 1, NULL, 0); #elif defined(PLATFORM_ESP32) - memcpy(peerInfo.peer_addr, firmwareOptions.uid, 6); + memcpy(peerInfo.peer_addr, peer_address, 6); peerInfo.channel = 0; peerInfo.encrypt = false; if (esp_now_add_peer(&peerInfo) != ESP_OK) diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 7fbd022e..59bc1f6d 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -160,16 +160,17 @@ void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len) { DBGVLN(""); // Extra line for serial output readability // Finished processing a complete packet - // Only process packets from a bound MAC address + // Only process packets from a bound MAC address or a timer backpack + // if not in bind mode if (connectionState == binding || ( firmwareOptions.uid[0] == mac_addr[0] && firmwareOptions.uid[1] == mac_addr[1] && firmwareOptions.uid[2] == mac_addr[2] && firmwareOptions.uid[3] == mac_addr[3] && - firmwareOptions.uid[4] == mac_addr[4] && - firmwareOptions.uid[5] == mac_addr[5] - ) + firmwareOptions.uid[4] == mac_addr[4] + ) || + TIMER_BACKPACK_TYPE_ID == mac_addr[5] ) { gotInitialPacket = true; @@ -286,11 +287,16 @@ void SetupEspNow() ESP.restart(); } + // Create the peer address for transmitter with same UID + uint8_t peer_address[6]; + memcpy(peer_address, firmwareOptions.uid, 6); + peer_address[5] = TX_BACKPACK_TYPE_ID; + #if defined(PLATFORM_ESP8266) esp_now_set_self_role(ESP_NOW_ROLE_COMBO); - esp_now_add_peer(firmwareOptions.uid, ESP_NOW_ROLE_COMBO, 1, NULL, 0); + esp_now_add_peer(peer_address, ESP_NOW_ROLE_COMBO, 1, NULL, 0); #elif defined(PLATFORM_ESP32) - memcpy(peerInfo.peer_addr, firmwareOptions.uid, 6); + memcpy(peerInfo.peer_addr, peer_address, 6); peerInfo.channel = 0; peerInfo.encrypt = false; if (esp_now_add_peer(&peerInfo) != ESP_OK) @@ -307,7 +313,7 @@ void SetSoftMACAddress() { if (!firmwareOptions.hasUID) { - memcpy(firmwareOptions.uid, config.GetGroupAddress(), 6); + memcpy(firmwareOptions.uid, config.GetGroupAddress(), 6); } DBG("EEPROM MAC = "); for (int i = 0; i < 6; i++) @@ -319,6 +325,8 @@ void SetSoftMACAddress() // MAC address can only be set with unicast, so first byte must be even, not odd firmwareOptions.uid[0] = firmwareOptions.uid[0] & ~0x01; + // Set MAC address to be specific for type of device + firmwareOptions.uid[5] = VRX_BACKPACK_TYPE_ID; WiFi.mode(WIFI_STA); #if defined(PLATFORM_ESP8266) @@ -369,7 +377,8 @@ void sendMSPViaEspnow(mspPacket_t *packet) return; } - esp_now_send(firmwareOptions.uid, (uint8_t *) &nowDataOutput, packetSize); + // Address set to NULL sends data to all registered peers + esp_now_send(NULL, (uint8_t *) &nowDataOutput, packetSize); } void resetBootCounter()