source: ResearchApps/PHY/WARPLAB/WARPLab7/M_Code_Reference/classes/wl_trigger_IDs.m

Last change on this file was 4332, checked in by welsh, 9 years ago

Code cleanup.

File size: 2.4 KB
Line 
1%-------------------------------------------------------------------------
2% WARPLab Framework
3%
4% Copyright 2013, Mango Communications. All rights reserved.
5%           Distributed under the WARP license  (http://warpproject.org/license)
6%
7% Chris Hunter (chunter [at] mangocomm.com)
8% Patrick Murphy (murphpo [at] mangocomm.com)
9% Erik Welsh (welsh [at] mangocomm.com)
10%-------------------------------------------------------------------------
11
12classdef wl_trigger_IDs < handle_light
13   
14    properties(SetAccess = private)
15        IDs;
16        currID_index;
17    end
18   
19    methods(Access = private)
20        function obj = wl_trigger_IDs()
21            obj.currID_index = 1;
22            obj.IDs = uint32(1);
23           
24            for k = 2:32
25               obj.IDs(k) = uint32(bitshift(obj.IDs(k-1),1)); 
26            end
27        end
28    end
29   
30    methods(Static)
31        function obj = instance()
32            persistent uniqueInstance
33           
34            if isempty(uniqueInstance)
35                obj = wl_trigger_IDs;
36                uniqueInstance = obj;
37            else
38                obj = uniqueInstance;
39            end
40        end
41       
42        function out = numAllocatedTrigs()
43            obj = wl_trigger_IDs.instance();
44            out = obj.currID_index - 1;
45        end
46       
47        function reset()
48            obj = wl_trigger_IDs.instance();
49            obj.currID_index = 1;
50        end
51       
52        function out = getID(varargin)
53           obj = wl_trigger_IDs.instance();
54           
55           N = varargin{1};
56           reset = true;
57           
58           for k = 1:length(varargin)
59              if(ischar(varargin{k}))
60                  if(strcmpi(varargin{k},'incrementid'))
61                      reset = false;
62                  elseif(strcmpi(varargin{k},'resetid'))
63                      reset = true;
64                  end
65              end
66           end
67           
68           if(reset)
69              obj.reset();
70           end
71           
72           if((obj.currID_index + (N - 1)) > length(obj.IDs))
73                error('Too many trigger IDs have been allocated. The total number of triggers from the host computer cannot exceed 32.'); 
74           end
75           
76           out = obj.IDs(obj.currID_index:((obj.currID_index + (N - 1))));
77           obj.currID_index = obj.currID_index + N;
78        end
79    end
80end
Note: See TracBrowser for help on using the repository browser.