|
24 | 24 |
|
25 | 25 | /////////// GLOBALS ///////////
|
26 | 26 |
|
27 |
| -uint8_t bindingAddress[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
| 27 | +uint8_t bindingAddress[UID_SIZE] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
28 | 28 |
|
29 | 29 | const uint8_t version[] = {LATEST_VERSION};
|
30 | 30 |
|
@@ -144,19 +144,30 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet)
|
144 | 144 | {
|
145 | 145 | if (packet->function == MSP_ELRS_BIND)
|
146 | 146 | {
|
147 |
| - config.SetGroupAddress(packet->payload); |
| 147 | + // If the backpack was flashed with passphrase then we override the packet with the flashed UID, |
| 148 | + // if not then store the given UID in the config, send it and reboot to use it. |
| 149 | + if (firmwareOptions.hasUID) |
| 150 | + { |
| 151 | + if (memcmp(packet->payload, firmwareOptions.uid, UID_SIZE) != 0) |
| 152 | + { |
| 153 | + ERRLN("Mismatched bind-phrase UIDs, flash the TX backpack with the same bind-phrase as the TX module."); |
| 154 | + return; |
| 155 | + } |
| 156 | + } |
| 157 | + else if (memcmp(packet->payload, config.GetGroupAddress(), UID_SIZE) != 0) |
| 158 | + { |
| 159 | + config.SetGroupAddress(packet->payload); |
| 160 | + config.Commit(); |
| 161 | + rebootTime = 100 + millis(); // restart to set SetSoftMACAddress |
| 162 | + } |
148 | 163 | DBG("MSP_ELRS_BIND = ");
|
149 |
| - for (int i = 0; i < 6; i++) |
| 164 | + for (int i = 0; i < UID_SIZE; i++) |
150 | 165 | {
|
151 | 166 | DBG("%x", packet->payload[i]); // Debug prints
|
152 | 167 | DBG(",");
|
153 | 168 | }
|
154 | 169 | DBG(""); // Extra line for serial output readability
|
155 |
| - config.Commit(); |
156 |
| - // delay(500); // delay may not be required |
157 | 170 | sendMSPViaEspnow(packet);
|
158 |
| - // delay(500); // delay may not be required |
159 |
| - rebootTime = millis(); // restart to set SetSoftMACAddress |
160 | 171 | }
|
161 | 172 |
|
162 | 173 | switch (packet->function)
|
@@ -240,10 +251,10 @@ void SetSoftMACAddress()
|
240 | 251 | {
|
241 | 252 | if (!firmwareOptions.hasUID)
|
242 | 253 | {
|
243 |
| - memcpy(firmwareOptions.uid, config.GetGroupAddress(), 6); |
| 254 | + memcpy(firmwareOptions.uid, config.GetGroupAddress(), UID_SIZE); |
244 | 255 | }
|
245 | 256 | DBG("EEPROM MAC = ");
|
246 |
| - for (int i = 0; i < 6; i++) |
| 257 | + for (int i = 0; i < UID_SIZE; i++) |
247 | 258 | {
|
248 | 259 | DBG("%x", firmwareOptions.uid[i]); // Debug prints
|
249 | 260 | DBG(",");
|
@@ -328,7 +339,7 @@ void setup()
|
328 | 339 | esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
329 | 340 | esp_now_add_peer(firmwareOptions.uid, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
330 | 341 | #elif defined(PLATFORM_ESP32)
|
331 |
| - memcpy(peerInfo.peer_addr, firmwareOptions.uid, 6); |
| 342 | + memcpy(peerInfo.peer_addr, firmwareOptions.uid, UID_SIZE); |
332 | 343 | peerInfo.channel = 0;
|
333 | 344 | peerInfo.encrypt = false;
|
334 | 345 | if (esp_now_add_peer(&peerInfo) != ESP_OK)
|
|
0 commit comments