private static void Discovery_RadioDiscovered(Radio discovered_radio) { //Log("1 API::Discovery_RadioDiscovered("+discovered_radio.ToString()+")"); if (filter_serial.Count > 0) { bool found = false; foreach (string s in filter_serial) { if (discovered_radio.Serial.Contains(s)) { found = true; //Debug.WriteLine("Found radio that matches filter: " + radio.Serial); break; } } if (!found) { return; } } // keep the radio alive in the list if it exists if (_radio_list_timed.ContainsKey(discovered_radio.Serial)) { _cleanupTimer.Stop(); _radio_list_timed[discovered_radio.Serial] = _cleanupTimer.Duration; } Radio r = null; lock (radio_list) { if (_radioDictionaryByIP.ContainsKey(discovered_radio.IP)) { r = _radioDictionaryByIP[discovered_radio.IP]; } if (r != null) { if (r.Model == discovered_radio.Model && r.Serial == discovered_radio.Serial) { LogDiscovery("2 API::Discovery_RadioDiscovered(" + discovered_radio.ToString() + ") - IP/Model/Serial match found in list"); ulong ver_1_0 = FlexVersion.Parse("1.0.0.0"); if (r.DiscoveryProtocolVersion <= ver_1_0 && discovered_radio.DiscoveryProtocolVersion > ver_1_0) { LogDiscovery("3 API::Discovery_RadioDiscovered(" + discovered_radio.ToString() + ") - newer protocol, updating radio info"); r.DiscoveryProtocolVersion = discovered_radio.DiscoveryProtocolVersion; r.Callsign = discovered_radio.Callsign; r.Nickname = discovered_radio.Nickname; r.Serial = discovered_radio.Serial; } if (discovered_radio.Version != r.Version) { LogDiscovery("4 API::Discovery_RadioDiscovered(" + discovered_radio.ToString() + ") - updating radio version"); Debug.WriteLine("Version Updated-" + r.ToString()); r.Version = discovered_radio.Version; r.Updating = false; } // update the status if this is a newer discovery version if (discovered_radio.DiscoveryProtocolVersion > ver_1_0) { if (r.Status != discovered_radio.Status) { LogDiscovery("5 API::Discovery_RadioDiscovered(" + discovered_radio.ToString() + ") - update radio status - " + discovered_radio.Status); r.Status = discovered_radio.Status; } if (r.InUseIP != discovered_radio.InUseIP) { r.InUseIP = discovered_radio.InUseIP; } if (r.InUseHost != discovered_radio.InUseHost) { r.InUseHost = discovered_radio.InUseHost; } } //Debug.WriteLine("Skipping Radio -- already in list: "+radio.ToString()); return; } } Debug.WriteLine("Discovered " + discovered_radio.ToString()); LogDiscovery("6 API::Discovery_RadioDiscovered(" + discovered_radio.ToString() + ") - Add radio to list"); radio_list.Add(discovered_radio); bool b = _radioDictionaryByIP.TryAdd(discovered_radio.IP, discovered_radio); } if (!_radio_list_timed.ContainsKey(discovered_radio.Serial)) { _cleanupTimer.Stop(); bool b = _radio_list_timed.TryAdd(discovered_radio.Serial, _cleanupTimer.Duration); } OnRadioAddedEventHandler(discovered_radio); //Debug.WriteLine("Adding Radio: " + radio.ToString()); }