Skip to content
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

Fix odd binding behaviour #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ typedef enum

extern connectionState_e connectionState;
extern unsigned long bindingStart;

#define UID_SIZE 6
31 changes: 21 additions & 10 deletions src/Tx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/////////// GLOBALS ///////////

uint8_t bindingAddress[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t bindingAddress[UID_SIZE] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

const uint8_t version[] = {LATEST_VERSION};

Expand Down Expand Up @@ -144,19 +144,30 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet)
{
if (packet->function == MSP_ELRS_BIND)
{
config.SetGroupAddress(packet->payload);
// If the backpack was flashed with passphrase then we override the packet with the flashed UID,
// if not then store the given UID in the config, send it and reboot to use it.
if (firmwareOptions.hasUID)
{
if (memcmp(packet->payload, firmwareOptions.uid, UID_SIZE) != 0)
{
ERRLN("Mismatched bind-phrase UIDs, flash the TX backpack with the same bind-phrase as the TX module.");
return;
}
}
else if (memcmp(packet->payload, config.GetGroupAddress(), UID_SIZE) != 0)
{
config.SetGroupAddress(packet->payload);
config.Commit();
rebootTime = 100 + millis(); // restart to set SetSoftMACAddress
}
DBG("MSP_ELRS_BIND = ");
for (int i = 0; i < 6; i++)
for (int i = 0; i < UID_SIZE; i++)
{
DBG("%x", packet->payload[i]); // Debug prints
DBG(",");
}
DBG(""); // Extra line for serial output readability
config.Commit();
// delay(500); // delay may not be required
sendMSPViaEspnow(packet);
// delay(500); // delay may not be required
rebootTime = millis(); // restart to set SetSoftMACAddress
}

switch (packet->function)
Expand Down Expand Up @@ -240,10 +251,10 @@ void SetSoftMACAddress()
{
if (!firmwareOptions.hasUID)
{
memcpy(firmwareOptions.uid, config.GetGroupAddress(), 6);
memcpy(firmwareOptions.uid, config.GetGroupAddress(), UID_SIZE);
}
DBG("EEPROM MAC = ");
for (int i = 0; i < 6; i++)
for (int i = 0; i < UID_SIZE; i++)
{
DBG("%x", firmwareOptions.uid[i]); // Debug prints
DBG(",");
Expand Down Expand Up @@ -328,7 +339,7 @@ void setup()
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
esp_now_add_peer(firmwareOptions.uid, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
#elif defined(PLATFORM_ESP32)
memcpy(peerInfo.peer_addr, firmwareOptions.uid, 6);
memcpy(peerInfo.peer_addr, firmwareOptions.uid, UID_SIZE);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK)
Expand Down
Loading