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

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

Transport updates: Added robustness to Write IQ such that host will wait if node is not ready; Re-wrote java Read / Write IQ to more closely follow the MEX for performance reasons. Improved the performance of the java transport.

File size: 3.6 KB
RevLine 
[4332]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
[1915]12classdef wl_samples < wl_msg_helper   
13    properties(SetAccess = public)
14        buffSel;
15        flags;
16        startSamp;
17    end
[4309]18
[4416]19    properties(SetAccess = public, Hidden = true)
[1915]20        numSamp;
[4416]21        sample_iq_id; 
22        samps;
[1915]23    end
24   
[4309]25    properties(Hidden = true, Constant = true)
26        FLAG_IQ_ERROR      = 1;         % 0x01
27        FLAG_IQ_NOT_READY  = 2;         % 0x02
28        FLAG_CHKSUM_RESET  = 16;        % 0x10
29        FLAG_LAST_WRITE    = 32;        % 0x20
30    end
31   
[1915]32    methods
33        function obj = wl_samples(varargin)
[4416]34           obj.buffSel       = uint16(0); 
35           obj.flags         = uint8(0); 
36           obj.sample_iq_id  = uint8(0); 
37           obj.startSamp     = uint32(0);
38           obj.numSamp       = uint32(0);
39           obj.samps         = [];
[1915]40           
[4416]41           if(length(varargin) == 1) 
[1915]42               obj.deserialize(varargin{1});
43           end
44        end
45       
[4416]46        function setFlags(obj, flags)
[1915]47           flags = uint8(flags);
[4416]48           obj.flags = bitor(obj.flags, flags);
[1915]49        end
50       
[4416]51        function clearFlags(obj, flags)
[1915]52           flags = uint8(flags);
[4416]53           obj.flags = bitand(obj.flags, bitcmp(flags));
[1915]54        end
55       
[4416]56        function setSamples(obj, samples)
[1915]57           obj.numSamp = length(samples);
58           obj.samps = samples(:).';
59        end
60       
61        function output = getSamples(obj)
62           output = obj.samps; 
63        end
64       
65        function output = serialize(obj)
[4416]66            % Serializes the header and samples to a vector of uint32 items
67            %     The structure of the sample header is:
68            %             typedef struct {
69            %                 u16 buffSel;
70            %                 u8  flags;
71            %                 u8  sample_iq_id;
72            %                 u32 startSamp;
73            %                 u32 numSamp;
74            %             } wl_bb_samp_hdr;
75            %
76            % NOTE:  Calling cast(x,'uint32') is much slower than uint32(2)
77            %        Bitshift/bitor are slower than explicit mults/adds
78            %
79            output(1) = (2^16 * uint32(obj.buffSel)) + (2^8 * uint32(obj.flags)) + uint32(obj.sample_iq_id);
80            output(2) = obj.startSamp;
81            output(3) = obj.numSamp;
82           
83            if ( ~isempty(obj.samps))
84                output    = cat(2, output, obj.samps);
85            end
[1915]86        end
87       
88        function deserialize(obj,vec)
[4309]89           vec           = uint32(vec);
[4416]90           obj.buffSel   = bitshift(bitand(vec(1), 4294901760), -16);
91           obj.flags     = bitshift(bitand(vec(1), 65280), -8);
[1915]92           obj.startSamp = vec(2);
[4309]93           obj.numSamp   = vec(3);
[1915]94           
[4309]95           if(length(vec) > 3)
[1915]96              obj.samps = vec(4:end);
97           end
98           
99        end
100       
101        function output = sizeof(obj)
102            persistent wl_samples_length;
[4309]103           
[1915]104            if(isempty(wl_samples_length))
105                wl_samples_length = length(obj.serialize)*4;
106            end
[4309]107           
[1915]108            output = wl_samples_length;
109        end
110    end
111end
Note: See TracBrowser for help on using the repository browser.