classdef mavlinkclient < handle & uav.internal.mavlink.Unsaveable
%MAVLINKCLIENT Store MAVLink client information
%   MAVLINKCLIENT object stores MAVLink client information
%   including System ID, Component ID, Component Type, and Autopilot
%   Type.
%
%   CLIENT = MAVLINKCLIENT(MAVLINK, SYSID, COMPID) creates a MAVLink
%   client interface for a MAVLink component. MAVLINK is a mavlinkio
%   object. SYSID and COMPID are used to identify the MAVLink
%   component.
%
%   MAVLINKCLIENT properties:
%       SystemID            - MAVLink Client System ID
%       ComponentID         - MAVLink Client Component ID
%       ComponentType       - MAVLink Client Type based on received
%                             heartbeat message
%       AutopilotType       - MAVLink Client Autopilot Type based on
%                             received heartbeat message
%
%   Example:
%
%       % Create a mavlinkio
%       mavlink = mavlinkio('common.xml');
%       connect(mavlink, 'udp');
%
%       % Get a mavlinkclient
%       client = mavlinkclient(mavlink, 1, 1);
%
%       % Inspect client component Type
%       client.ComponentType
%
%   See also mavlinkdialect, mavlinkio, mavlinksub

%   Copyright 2018-2020 The MathWorks, Inc.

    properties (Dependent, SetAccess = private)
        %SystemID MAVLink Client System ID
        SystemID
        %ComponentID MAVLink Client Component ID
        ComponentID
        %ComponentType MAVLink Client Type based on received heartbeat message
        ComponentType
        %AutopilotType MAVLink Client Autopilot Type based on received heartbeat message
        AutopilotType
    end

    properties (Access = private)
        %Client MAVLink client implementation
        Client
    end

    methods
        function obj = mavlinkclient(io, sysid, compid)
        %MAVLINKCLIENT construct a MAVLink client instance
            narginchk(3,3);
            validateattributes(sysid, {'numeric'}, {'integer', 'positive', '<=', 255}, 'mavlinkclient', 'sysid');
            validateattributes(compid, {'numeric'}, {'integer', 'nonnegative', '<=', 255}, 'mavlinkclient', 'compid');
            obj.Client = io.createClient(sysid, compid);
        end

        function type = get.ComponentType(obj)
        %getter for ComponentType
            type = obj.Client.ComponentType;
        end

        function type = get.AutopilotType(obj)
        %getter for AutopilotType
            type = obj.Client.AutopilotType;
        end

        function type = get.SystemID(obj)
        %getter for SystemID
            type = obj.Client.SystemID;
        end

        function type = get.ComponentID(obj)
        %getter for ComponentID
            type = obj.Client.ComponentID;
        end
    end
end
