classdef am_generator < atomic
  %% Description
  %  generates entities with fixed interarrival times
  %% Ports
  %  inputs: none
  %  outputs: 
  %    out      generated entities
  %% States
  %  counter : number of workpieces generated
  %% System Parameters
  %  tG: time interval between new entities
  %  n0: id of first entity
  %  debug: flag to enable debug information

  methods
    function obj = am_generator(name, tG, n0, debug)
      if nargin == 4
        x = {};           % no inputs
        y = {'out'};      % output to emit entities
        s = {'counter'};  % 
        sysparams = struct('tG', tG, 'n0', n0, 'debug', debug);
      else
        error('mistake at constructor method for class am_generator');
      end
      obj = obj@atomic(name, x, y, s, 0, sysparams); % call parent
      obj.s.counter = obj.sysparams.n0; % initialize the state
    end
        
    function deltaintfun(obj)
      obj.s.counter = obj.s.counter + 1;
    end
               
    function deltaextfun(obj,gt) %#ok<INUSD>
      % unused, no input
    end
        
    function deltaconffun(obj,gt) %#ok<INUSD>
      % unused, no input
    end
        
    function lambdafun(obj)
      % generate an  entity with given id
      obj.y.out = {obj.s.counter + 1};

      if obj.sysparams.debug
        fprintf('%4.1f %8s OUT, out=%2d\n', ...
                obj.tnext, obj.name, cell2mat(obj.y.out))
      end
    end

    function ta = tafun(obj)
      ta = obj.sysparams.tG;
    end
  end  % methods
end   % classdef
