@@ -681,149 +681,3 @@ bool receiveInProcess()
681681 // if ((radioStatus & 0b1) == 0) return (false); //If bit 0 is cleared, there is no receive in progress
682682 // return (true); //If bit 0 is set, forget the other bits, there is a receive in progress
683683}
684-
685- void beginTraining ()
686- {
687- originalSettings = settings; // Make copy of current settings
688-
689- moveToTrainingFreq ();
690- }
691-
692- void beginDefaultTraining ()
693- {
694- Settings defaultSettings;
695- originalSettings = defaultSettings; // Upon completion we will return to default settings
696-
697- moveToTrainingFreq ();
698- }
699-
700- // Upon successful exchange of keys, go back to original settings
701- void endTraining (bool newTrainingAvailable)
702- {
703- settings = originalSettings; // Return to original radio settings
704-
705- // Apply new netID and AES if available
706- if (newTrainingAvailable)
707- {
708- if (lastPacketSize == sizeof (settings.encryptionKey ) + 1 ) // Error check, should be AES key + NetID
709- {
710- // Move training data into settings
711- for (int x = 0 ; x < sizeof (settings.encryptionKey ); x++)
712- settings.encryptionKey [x] = lastPacket[x];
713-
714- settings.netID = lastPacket[lastPacketSize - 1 ]; // Last spot in array is netID
715-
716- if (settings.debug == true )
717- {
718- systemPrint (" New Key: " );
719- for (uint8_t i = 0 ; i < 16 ; i++)
720- {
721- if (settings.encryptionKey [i] < 0x10 ) systemPrint (" 0" );
722- systemPrint (settings.encryptionKey [i], HEX);
723- systemPrint (" " );
724- }
725- systemPrintln ();
726-
727- systemPrint (" New ID: " );
728- systemPrintln (settings.netID );
729- }
730- }
731- else
732- {
733- // If the packet was marked as training but was not valid training data, then give up. Return to normal radio mode with pre-existing settings.
734- }
735- }
736- else
737- {
738- // We transmitted the training data, move the local training data into settings
739- for (int x = 0 ; x < sizeof (settings.encryptionKey ); x++)
740- settings.encryptionKey [x] = trainEncryptionKey[x];
741-
742- settings.netID = trainNetID; // Last spot in array is netID
743- }
744-
745- recordSystemSettings ();
746-
747- generateHopTable (); // Generate frequency table based on current settings
748-
749- configureRadio (); // Setup radio with settings
750-
751- returnToReceiving ();
752-
753- if (settings.pointToPoint == true )
754- changeState (RADIO_NO_LINK_RECEIVING_STANDBY);
755- else
756- changeState (RADIO_BROADCASTING_RECEIVING_STANDBY);
757-
758- systemPrintln (" LINK TRAINED" );
759- }
760-
761- // Change to known training frequency based on available freq and current major firmware version
762- // This will allow different minor versions to continue to train to each other
763- // Send special packet with train = 1, then wait for response
764- void moveToTrainingFreq ()
765- {
766- // During training use default radio settings. This ensures both radios are at known good settings.
767- Settings defaultSettings;
768- settings = defaultSettings; // Move to default settings
769-
770- // Disable hopping
771- settings.frequencyHop = false ;
772-
773- // Disable NetID checking
774- settings.pointToPoint = false ;
775-
776- generateHopTable (); // Generate frequency table based on current settings
777-
778- configureRadio (); // Setup radio with settings
779-
780- // Move to frequency that is not part of the hop table
781- // In normal operation we move 1/2 a channel away from min. In training, we move a full channel away + major firmware version.
782- float channelSpacing = (settings.frequencyMax - settings.frequencyMin ) / (float )(settings.numberOfChannels + 2 );
783- float trainFrequency = settings.frequencyMin + (channelSpacing * (FIRMWARE_VERSION_MAJOR % settings.numberOfChannels ));
784-
785- channels[0 ] = trainFrequency; // Inject this frequency into the channel table
786-
787- // Transmit general ping packet to see if anyone else is sitting on the training channel
788- sendTrainingPingPacket ();
789-
790- // Recalculate packetAirTime because we need to wait not for a 2-byte response, but a 19 byte response
791- packetAirTime = calcAirTime (sizeof (trainEncryptionKey) + sizeof (trainNetID) + 2 );
792-
793- changeState (RADIO_TRAINING_TRANSMITTING);
794- }
795-
796- // Generate new netID/AES key to share
797- // We assume the user needs to maintain their settings (airSpeed, numberOfChannels, freq min/max, bandwidth/spread/hop)
798- // but need to be on a different netID/AES key.
799- void generateTrainingSettings ()
800- {
801- LRS_DEBUG_PRINTLN (" Generate New Training Settings" );
802-
803- // Seed random number based on RF noise. We use Arduino random() because platform specific generation does not matter
804- randomSeed (radio.randomByte ());
805-
806- // Generate new NetID
807- trainNetID = random (0 , 256 ); // Inclusive, exclusive
808-
809- // Generate new AES Key. User may not be using AES but we still need both radios to have the same key in case they do enable AES.
810- for (int x = 0 ; x < 16 ; x++)
811- trainEncryptionKey[x] = random (0 , 256 ); // Inclusive, exclusive
812-
813- // We do not generate new AES Initial Values here. Those are generated during generateHopTable() based on the unit's settings.
814-
815- if (settings.debug == true )
816- {
817- systemPrint (F (" trainNetID: " ));
818- systemPrintln (trainNetID);
819-
820- systemPrint (F (" trainEncryptionKey:" ));
821- for (uint8_t i = 0 ; i < 16 ; i++)
822- {
823- systemPrint (" 0x" );
824- if (trainEncryptionKey[i] < 0x10 ) systemPrint (" 0" );
825- systemPrint (trainEncryptionKey[i], HEX);
826- }
827- systemPrintln ();
828- }
829- }
0 commit comments