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 | |
---|
12 | classdef wl_samples < wl_msg_helper |
---|
13 | properties(SetAccess = public) |
---|
14 | buffSel; |
---|
15 | flags; |
---|
16 | startSamp; |
---|
17 | end |
---|
18 | |
---|
19 | properties(SetAccess = public, Hidden = true) |
---|
20 | numSamp; |
---|
21 | sample_iq_id; |
---|
22 | samps; |
---|
23 | end |
---|
24 | |
---|
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 | |
---|
32 | methods |
---|
33 | function obj = wl_samples(varargin) |
---|
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 = []; |
---|
40 | |
---|
41 | if(length(varargin) == 1) |
---|
42 | obj.deserialize(varargin{1}); |
---|
43 | end |
---|
44 | end |
---|
45 | |
---|
46 | function setFlags(obj, flags) |
---|
47 | flags = uint8(flags); |
---|
48 | obj.flags = bitor(obj.flags, flags); |
---|
49 | end |
---|
50 | |
---|
51 | function clearFlags(obj, flags) |
---|
52 | flags = uint8(flags); |
---|
53 | obj.flags = bitand(obj.flags, bitcmp(flags)); |
---|
54 | end |
---|
55 | |
---|
56 | function setSamples(obj, samples) |
---|
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) |
---|
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 |
---|
86 | end |
---|
87 | |
---|
88 | function deserialize(obj,vec) |
---|
89 | vec = uint32(vec); |
---|
90 | obj.buffSel = bitshift(bitand(vec(1), 4294901760), -16); |
---|
91 | obj.flags = bitshift(bitand(vec(1), 65280), -8); |
---|
92 | obj.startSamp = vec(2); |
---|
93 | obj.numSamp = vec(3); |
---|
94 | |
---|
95 | if(length(vec) > 3) |
---|
96 | obj.samps = vec(4:end); |
---|
97 | end |
---|
98 | |
---|
99 | end |
---|
100 | |
---|
101 | function output = sizeof(obj) |
---|
102 | persistent wl_samples_length; |
---|
103 | |
---|
104 | if(isempty(wl_samples_length)) |
---|
105 | wl_samples_length = length(obj.serialize)*4; |
---|
106 | end |
---|
107 | |
---|
108 | output = wl_samples_length; |
---|
109 | end |
---|
110 | end |
---|
111 | end |
---|