| 1 | function [type cmd bytes] = name2commandbytes(name) |
|---|
| 2 | % Determines command bytes from given command name |
|---|
| 3 | % |
|---|
| 4 | % Syntax |
|---|
| 5 | % |[type cmd bytes] = name2commandbytes(name)| |
|---|
| 6 | % |
|---|
| 7 | % Description |
|---|
| 8 | % The function names are directly taken from the LEGO |
|---|
| 9 | % Mindstorms Bluetooth SDK and Direct Commands Appendix |
|---|
| 10 | % |
|---|
| 11 | % Signature |
|---|
| 12 | % Author: Linus Atorf (see AUTHORS) |
|---|
| 13 | % Date: 2007/10/14 |
|---|
| 14 | % Copyright: 2007, RWTH Aachen University |
|---|
| 15 | % |
|---|
| 16 | ; |
|---|
| 17 | % |
|---|
| 18 | % *********************************************************************************************** |
|---|
| 19 | % * This file is part of the RWTH - Mindstorms NXT Toolbox. * |
|---|
| 20 | % * * |
|---|
| 21 | % * The RWTH - Mindstorms NXT Toolbox is free software: you can redistribute it and/or modify * |
|---|
| 22 | % * it under the terms of the GNU General Public License as published by the Free Software * |
|---|
| 23 | % * Foundation, either version 3 of the License, or (at your option) any later version. * |
|---|
| 24 | % * * |
|---|
| 25 | % * The RWTH - Mindstorms NXT Toolbox is distributed in the hope that it will be useful, * |
|---|
| 26 | % * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * |
|---|
| 27 | % * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
|---|
| 28 | % * * |
|---|
| 29 | % * You should have received a copy of the GNU General Public License along with the * |
|---|
| 30 | % * RWTH - Mindstorms NXT Toolbox. If not, see <http: |
|---|
| 31 | % *********************************************************************************************** |
|---|
| 32 | |
|---|
| 33 | %% System commands |
|---|
| 34 | NXT__GET_FIRMWARE_VERSION = [1; 136]; %#ok<NASGU> %hex2dec(['01'; '88']); |
|---|
| 35 | NXT__SET_BRICK_NAME = [1; 152]; %#ok<NASGU> %hex2dec(['01'; '98']); |
|---|
| 36 | NXT__GET_DEVICE_INFO = [1; 155]; %#ok<NASGU> %hex2dec(['01'; '9B']); |
|---|
| 37 | NXT__POLL_COMMAND_LENGTH = [1; 161]; %#ok<NASGU> %hex2dec(['01'; 'A1']); |
|---|
| 38 | NXT__POLL_COMMAND = [1; 162]; %#ok<NASGU> %hex2dec(['01'; 'A2']); |
|---|
| 39 | |
|---|
| 40 | NXT__READ_IO_MAP = [1; 148]; %#ok<NASGU> %hex2dec(['01'; '94']); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | %% Direct commands |
|---|
| 44 | NXT__STARTPROGRAM = [0; 0]; %#ok<NASGU> %hex2dec(['00'; '00']); |
|---|
| 45 | NXT__STOPPROGRAM = [0; 1]; %#ok<NASGU> %hex2dec(['00'; '01']); |
|---|
| 46 | NXT__PLAYSOUNDFILE = [0; 2]; %#ok<NASGU> %hex2dec(['00'; '02']); |
|---|
| 47 | NXT__PLAYTONE = [0; 3]; %#ok<NASGU> %hex2dec(['00'; '03']); |
|---|
| 48 | NXT__SETOUTPUTSTATE = [0; 4]; %#ok<NASGU> %hex2dec(['00'; '04']); |
|---|
| 49 | NXT__SETINPUTMODE = [0; 5]; %#ok<NASGU> %hex2dec(['00'; '05']); |
|---|
| 50 | NXT__GETOUTPUTSTATE = [0; 6]; %#ok<NASGU> %hex2dec(['00'; '06']); |
|---|
| 51 | NXT__GETINPUTVALUES = [0; 7]; %#ok<NASGU> %hex2dec(['00'; '07']); |
|---|
| 52 | NXT__RESETINPUTSCALEDVALUE = [0; 8]; %#ok<NASGU> %hex2dec(['00'; '08']); |
|---|
| 53 | NXT__MESSAGEWRITE = [0; 9]; %#ok<NASGU> %hex2dec(['00'; '09']); |
|---|
| 54 | NXT__RESETMOTORPOSITION = [0; 10]; %#ok<NASGU> %hex2dec(['00'; '0A']); |
|---|
| 55 | NXT__GETBATTERYLEVEL = [0; 11]; %#ok<NASGU> %hex2dec(['00'; '0B']); |
|---|
| 56 | NXT__STOPSOUNDPLAYBACK = [0; 12]; %#ok<NASGU> %hex2dec(['00'; '0C']); |
|---|
| 57 | NXT__KEEPALIVE = [0; 13]; %#ok<NASGU> %hex2dec(['00'; '0D']); |
|---|
| 58 | NXT__LSGETSTATUS = [0; 14]; %#ok<NASGU> %hex2dec(['00'; '0E']); |
|---|
| 59 | NXT__LSWRITE = [0; 15]; %#ok<NASGU> %hex2dec(['00'; '0F']); |
|---|
| 60 | NXT__LSREAD = [0; 16]; %#ok<NASGU> %hex2dec(['00'; '10']); |
|---|
| 61 | NXT__GETCURRENTPROGRAMNAME = [0; 17]; %#ok<NASGU> %hex2dec(['00'; '11']); |
|---|
| 62 | NXT__MESSAGEREAD = [0; 19]; %#ok<NASGU> %hex2dec(['00'; '13']); |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | %% Parameter check |
|---|
| 66 | %NOTE this error-check can be ommitted for a little speedup: about 1ms for |
|---|
| 67 | %every 10 calls... so probably not worth it... |
|---|
| 68 | if ~exist(['NXT__' name], 'var') || ~isvector(['NXT__' name]) |
|---|
| 69 | error('MATLAB:RWTHMindstormsNXT:invalidNXTCommandName', 'Unknown NXT function or direct command "%s". See inside this method (private/name2commandbytes.m) for a list.', name) |
|---|
| 70 | end%if |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | %% Determine command bytes |
|---|
| 74 | bytes = eval(['NXT__' name]); |
|---|
| 75 | type = bytes(1); |
|---|
| 76 | cmd = bytes(2); |
|---|
| 77 | |
|---|
| 78 | end%function |
|---|