%hScanLTEWaveformRadioConnectivityCheck Checks for radio connection
%  [RADIOFOUND, RADIOINFO] =
%  hScanLTEWaveformRadioConnectivityCheck(RADIOCHOICE)checks for the radio
%  connection and outputs the following information:
%  RADIOFOUND - Connection status. 
%               1, if radio is connected
%               0, if radio is not connected.
%  RADIOINFO  - Connected radio information such as IP address, Device
%               name, Platform, Serial number.

%   Copyright 2019-2020 The MathWorks, Inc.

function [radioFound, radioInfo] = ...
                        hScanLTEWaveformRadioConnectivityCheck(radioChoice,varargin)
    switch radioChoice
        case 'RTL-SDR'
            radioInfo = sdrrinfo;
            if(isempty(radioInfo))
                radioFound = false;
            else
                radioFound = true;
            end
        case 'ADALM-PLUTO'
            radioInfo = findPlutoRadio();
            if(isempty(radioInfo))
                radioFound = false;
            else
                radioFound = true;
            end
        case {'USRP-B200/B210','USRP-N200/N210','USRP-X300/X310'}
            [~,radioInfo] = evalc('findsdru');
            for i = 1:length(radioInfo)
                switch radioChoice
                    case 'USRP-B200/B210'
                        if (strcmp(radioInfo(i).Platform,'B200') || strcmp(radioInfo(i).Platform,'B210'))
                            radioFound = true;
                            break;
                        else
                            radioFound = false;
                        end
                    case 'USRP-N200/N210'
                        if (strcmp(radioInfo(i).Platform,'N200/N210/USRP2'))
                            radioFound = true;
                            break;
                        else
                            radioFound = false;
                        end
                    case 'USRP-X300/X310'
                        if (strcmp(radioInfo(i).Platform,'X300') || strcmp(radioInfo(i).Platform,'X310'))
                            radioFound = true;
                            break;
                        else
                            radioFound = false;
                        end
                end
            end
        otherwise        % For ZedRadio and ZC706Radio
            SDRDeviceName = 'AD936x';
            radioInfo = sdrdev(SDRDeviceName);
            radioInfo.IPAddress = varargin{1};
            radioFound = true;
            try
                testConnection(radioInfo);
            catch
                radioFound = false;
            end
    end
end