Beispiel #1
0
        public RadioInformation CanHearTransmission(double frequency,
                                                    RadioInformation.Modulation modulation,
                                                    byte encryptionKey,
                                                    uint sendingUnitId,
                                                    List <int> blockedRadios,
                                                    out RadioReceivingState receivingState,
                                                    out bool decryptable)
        {
            if (!IsCurrent())
            {
                receivingState = null;
                decryptable    = false;
                return(null);
            }

            RadioInformation    bestMatchingRadio      = null;
            RadioReceivingState bestMatchingRadioState = null;
            bool bestMatchingDecryptable = false;

            for (var i = 0; i < radios.Length; i++)
            {
                var receivingRadio = radios[i];

                if (receivingRadio != null)
                {
                    //handle INTERCOM Modulation is 2
                    if ((receivingRadio.modulation == RadioInformation.Modulation.INTERCOM) &&
                        (modulation == RadioInformation.Modulation.INTERCOM))
                    {
                        if ((unitId > 0) && (sendingUnitId > 0) &&
                            (unitId == sendingUnitId))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            decryptable = true;
                            return(receivingRadio);
                        }
                        decryptable    = false;
                        receivingState = null;
                        return(null);
                    }

                    if (modulation == RadioInformation.Modulation.DISABLED ||
                        receivingRadio.modulation == RadioInformation.Modulation.DISABLED)
                    {
                        continue;
                    }

                    //within 1khz
                    if ((FreqCloseEnough(receivingRadio.freq, frequency)) &&
                        (receivingRadio.modulation == modulation) &&
                        (receivingRadio.freq > 10000))
                    {
                        bool isDecryptable = (encryptionKey == 0 || (receivingRadio.enc ? receivingRadio.encKey : (byte)0) == encryptionKey);

                        if (isDecryptable && !blockedRadios.Contains(i))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            decryptable = true;
                            return(receivingRadio);
                        }

                        bestMatchingRadio      = receivingRadio;
                        bestMatchingRadioState = new RadioReceivingState
                        {
                            IsSecondary    = false,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };
                        bestMatchingDecryptable = isDecryptable;
                    }
                    if ((receivingRadio.secFreq == frequency) &&
                        (receivingRadio.secFreq > 10000))
                    {
                        if (encryptionKey == 0 || (receivingRadio.enc ? receivingRadio.encKey : (byte)0) == encryptionKey)
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = true,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };
                            decryptable = true;
                            return(receivingRadio);
                        }

                        bestMatchingRadio      = receivingRadio;
                        bestMatchingRadioState = new RadioReceivingState
                        {
                            IsSecondary    = true,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };
                    }
                }
            }

            decryptable    = bestMatchingDecryptable;
            receivingState = bestMatchingRadioState;
            return(bestMatchingRadio);
        }
        public RadioInformation CanHearTransmission(double frequency, RadioInformation.Modulation modulation,
                                                    uint sendingUnitId,
                                                    out RadioReceivingState receivingState)
        {
            if (!IsCurrent())
            {
                receivingState = null;
                return(null);
            }
            for (var i = 0; i < radios.Length; i++)
            {
                var receivingRadio = radios[i];

                if (receivingRadio != null)
                {
                    //handle INTERCOM Modulation is 2
                    if ((receivingRadio.modulation == RadioInformation.Modulation.INTERCOM) &&
                        (modulation == RadioInformation.Modulation.INTERCOM))
                    {
                        if ((unitId > 0) && (sendingUnitId > 0) &&
                            (unitId == sendingUnitId))
                        {
                            receivingState = new RadioReceivingState
                            {
                                IsSecondary    = false,
                                LastReceviedAt = DateTime.Now.Ticks,
                                ReceivedOn     = i
                            };


                            return(receivingRadio);
                        }
                        receivingState = null;
                        return(null);
                    }

                    if (modulation == RadioInformation.Modulation.DISABLED ||
                        receivingRadio.modulation == RadioInformation.Modulation.DISABLED)
                    {
                        continue;
                    }

                    if ((receivingRadio.freq == frequency) &&
                        (receivingRadio.modulation == modulation) &&
                        (receivingRadio.freq > 10000))
                    {
                        receivingState = new RadioReceivingState
                        {
                            IsSecondary    = false,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };

                        return(receivingRadio);
                    }
                    if ((receivingRadio.secFreq == frequency) &&
                        (receivingRadio.secFreq > 10000))
                    {
                        receivingState = new RadioReceivingState
                        {
                            IsSecondary    = true,
                            LastReceviedAt = DateTime.Now.Ticks,
                            ReceivedOn     = i
                        };

                        return(receivingRadio);
                    }
                }
            }
            receivingState = null;
            return(null);
        }