[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] | 12 | classdef wl_cmd < handle_light |
---|
[4332] | 13 | |
---|
[4334] | 14 | properties(SetAccess = public) |
---|
| 15 | cmd; |
---|
| 16 | end |
---|
[1915] | 17 | |
---|
[4416] | 18 | properties(SetAccess = public, Hidden = true) |
---|
[4334] | 19 | len; |
---|
| 20 | numArgs; |
---|
| 21 | end |
---|
[1915] | 22 | |
---|
[4334] | 23 | properties(SetAccess = protected, Hidden=true) |
---|
| 24 | args; |
---|
| 25 | end |
---|
| 26 | |
---|
| 27 | properties(SetAccess = public, Hidden=true) |
---|
| 28 | % These properties correspond to the WARPLab Command Defines in wl_common.h |
---|
| 29 | CMD_PARAM_WRITE_VAL = 0; % 0x00000000 |
---|
| 30 | CMD_PARAM_READ_VAL = 1; % 0x00000001 |
---|
| 31 | CMD_PARAM_RSVD = hex2dec('FFFFFFFF'); % 0xFFFFFFFF |
---|
| 32 | |
---|
| 33 | CMD_PARAM_SUCCESS = 0; % 0x00000000 |
---|
| 34 | CMD_PARAM_ERROR = hex2dec('FF000000'); % 0xFF000000 |
---|
| 35 | end |
---|
[1915] | 36 | |
---|
[4334] | 37 | methods |
---|
| 38 | function obj = wl_cmd(varargin) |
---|
[1915] | 39 | obj.cmd = uint32(0); |
---|
| 40 | obj.len = uint16(0); |
---|
| 41 | obj.numArgs = uint16(0); |
---|
| 42 | |
---|
| 43 | if(nargin > 0) |
---|
| 44 | obj.cmd = uint32(varargin{1}); |
---|
| 45 | end |
---|
| 46 | |
---|
| 47 | if(nargin > 1) |
---|
| 48 | obj.setArgs(varargin{2:end}); |
---|
| 49 | end |
---|
[4334] | 50 | end |
---|
[1915] | 51 | |
---|
[4334] | 52 | function print(obj,varargin) |
---|
| 53 | fprintf('WL Command: 0x%8x length = 0x%x num_args = 0x%d \n', obj.cmd, obj.len, obj.numArgs ); |
---|
| 54 | tmp_args = obj.getArgs(); |
---|
| 55 | for index = 1:length(tmp_args) |
---|
| 56 | fprintf(' Arg[%d] = 0x%8x \n', index, tmp_args(index)); |
---|
| 57 | end |
---|
| 58 | end |
---|
[2124] | 59 | |
---|
[4334] | 60 | function setArgs(obj,varargin) |
---|
[4332] | 61 | % Delete old args |
---|
[1915] | 62 | obj.len = uint16(0); |
---|
| 63 | obj.numArgs = uint16(0); |
---|
| 64 | obj.addArgs(varargin{:}); |
---|
[4334] | 65 | end |
---|
[1915] | 66 | |
---|
[4334] | 67 | function addArgs(obj,varargin) |
---|
| 68 | for index = length(varargin):-1:1 |
---|
[1915] | 69 | if(min(size(varargin{index}))~=1) |
---|
[4334] | 70 | error('argument %d must be a scalar or 1-dimensional vector',index) |
---|
[1915] | 71 | end |
---|
| 72 | newArg = uint32(varargin{index}(:).'); |
---|
| 73 | obj.args{index + (obj.numArgs)} = newArg; |
---|
| 74 | obj.len = obj.len + (length(newArg)*4); |
---|
| 75 | end |
---|
| 76 | obj.numArgs = obj.numArgs + length(varargin); |
---|
[4334] | 77 | end |
---|
[1915] | 78 | |
---|
[4334] | 79 | function output = getArgs(obj) |
---|
[4416] | 80 | if(isempty(obj.args) == 0) |
---|
| 81 | output = cat(2, obj.args{:}); |
---|
[1915] | 82 | else |
---|
| 83 | output = []; |
---|
| 84 | end |
---|
[4334] | 85 | end |
---|
[1915] | 86 | |
---|
[4334] | 87 | function output = sizeof(obj) |
---|
[1915] | 88 | output = length(obj.serialize)*4; |
---|
[4334] | 89 | end |
---|
[1915] | 90 | |
---|
[4334] | 91 | function output = serialize(obj) |
---|
[4416] | 92 | % Serializes the command header and all arguments to a vector of uint32 items |
---|
| 93 | % The structure of the command header is: |
---|
| 94 | % typedef struct { |
---|
| 95 | % u32 cmd; |
---|
| 96 | % u16 length; |
---|
| 97 | % u16 numArgs; |
---|
| 98 | % } wl_cmd_hdr; |
---|
| 99 | % |
---|
| 100 | % NOTE: Calling cast(x,'uint32') is much slower than uint32(2) |
---|
| 101 | % Bitshift/bitor are slower than explicit mults/adds |
---|
| 102 | % |
---|
[4334] | 103 | output(1) = obj.cmd; |
---|
[4416] | 104 | output(2) = (2^16 * uint32(obj.len)) + uint32(obj.numArgs); |
---|
| 105 | |
---|
| 106 | if (~isempty(obj.args)) |
---|
| 107 | output = cat(2, output, obj.args{:}); |
---|
| 108 | end |
---|
[4334] | 109 | end |
---|
| 110 | end |
---|
[1915] | 111 | end |
---|