root/branches/atorf/RWTHMindstormsNXT/NXT_Get_Firmware_Version.m @ 122

Revision 122, 4.9 KB (checked in by behrens, 5 years ago)

add NXT_Get_Firmware_Version.m, add NXT_PlaySoundFile.m, add NXT_StopSoundPlayback.m (COM_* version)
add LUT entry NXTWRITE_IO_MAP (not supported yet)

Line 
1function [protocol_version firmware_version] = NXT_Get_Firmware_Version(varargin)
2% Returns the protocol and firmware version of the NXT
3
4% Syntax
5%   |[protocol_version firmware_version] = NXT_Get_Firmware_Version()|
6%
7%   |[protocol_version firmware_version] = NXT_Get_Firmware_Version(handle)|
8%
9% Description
10%   |[protocol_version firmware_version] = NXT_Get_Firmware_Version()| returns the protocol and
11%   firmware version of the NXT as strings.
12%
13%   |[protocol_version firmware_version] = NXT_Get_Firmware_Version(handle)| uses the given
14%   Bluetooth connection |handle|. This should be a serial handle on a PC system and a file handle on a Linux system.
15%
16%   If no Bluetooth |handle| is specified the default one (|COM_GetDefaultHandle|) is used.
17%
18% Examples
19%+   [protocol_version firmware_version] = NXT_Get_Firmware_Version();
20%
21%+   bt_handle = BT_OpenHandle('bluetooth.ini','check');
22%+   [protocol_version firmware_version] = NXT_Get_Firmware_Version(bt_handle);
23%
24% See also: COM_GetDefaultHandle
25%
26% Signature
27%   Author: Alexander Behrens (see AUTHORS)
28%   Date: 2008/05/22
29%   Copyright: 2008, RWTH Aachen University
30%
31;
32%
33% ***********************************************************************************************
34% *  This file is part of the RWTH - Mindstorms NXT Toolbox.                                    *
35% *                                                                                             *
36% *  The RWTH - Mindstorms NXT Toolbox is free software: you can redistribute it and/or modify  *
37% *  it under the terms of the GNU General Public License as published by the Free Software     *
38% *  Foundation, either version 3 of the License, or (at your option) any later version.        *
39% *                                                                                             *
40% *  The RWTH - Mindstorms NXT Toolbox is distributed in the hope that it will be useful,       *
41% *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS  *
42% *  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
43% *                                                                                             *
44% *  You should have received a copy of the GNU General Public License along with the           *
45% *  RWTH - Mindstorms NXT Toolbox. If not, see <http://www.gnu.org/licenses/>.                 *
46% ***********************************************************************************************
47
48%% Parameter check
49% check if bluetooth handle is given; if not use default one
50if nargin > 0
51    handle = varargin{1};
52else
53    handle = COM_GetDefaultHandle;
54end%if
55
56
57%% Use wrapper functions
58NXT_RequestFirmwareVersion(handle);
59[protocol_version firmware_version] = NXT_CollectFirmwareVersion(handle);
60
61end % end function
62
63
64
65%% ### Function: Request Firmware Version ###
66function NXT_RequestFirmwareVersion(varargin)
67% Sends the "GetFirmwareVersion" packet: Requests the protocol and firmware version of the NXT
68%
69% Usage: NXT_RequestFirmwareVersion(varargin)
70%               varargin     :  bluetooth handle (optional)
71%
72
73%% Parameter check
74% check if bluetooth handle is given; if not use default one
75if nargin > 0
76    handle = varargin{1};
77else
78    handle = COM_GetDefaultHandle;
79end%if
80
81
82%% Build bluetooth command
83[type cmd] = name2commandbytes('GET_FIRMWARE_VERSION');
84
85
86%% Pack bluetooth packet
87packet = COM_CreatePacket(type, cmd, 'reply', []);
88textOut(sprintf('+ Requesting firmware version...\n'));
89
90
91%% Send bluetooth packet
92COM_SendPacket(packet, handle);
93
94end % end function
95
96
97
98%% ### Function: Collect Protocol and Firmware Version ###
99function [protocol_version firmware_version] = NXT_CollectFirmwareVersion(varargin)
100% Retrieves the previously requested protocol and firmware version of the NXT
101%
102% Returns:    protocl_version   : protcol version of the NXT
103%             firmware_version  : firmware version of the NXT
104%
105
106%% Parameter check
107% check if bluetooth handle is given; if not use default one
108if nargin > 0
109   handle = varargin{1};
110else
111    handle = COM_GetDefaultHandle;
112end%if
113
114
115%% Get reference
116[dontcare ExpectedCmd] = name2commandbytes('GET_FIRMWARE_VERSION');
117
118%% Collect bluetooth packet
119[type cmd status content] = COM_CollectPacket(handle);
120
121%% Check if packet is the right one
122if cmd ~= ExpectedCmd || status ~= 0
123    warning('MATLAB:RWTHMindstormsNXT:Bluetooth:discardingUnexpectedPacket', 'Received packed not expected. Discarding and trying to continue...');
124    protocol_version = NaN;
125    firmware_version = NaN;
126    return;
127end%if
128
129%% Interpret packet content
130protocol_version = [num2str(wordbytes2dec(content(2),1)) '.' sprintf('%02d',wordbytes2dec(content(1),1))];
131firmware_version = [num2str(wordbytes2dec(content(4),1)) '.' sprintf('%02d',wordbytes2dec(content(3),1))];
132
133end % end function
Note: See TracBrowser for help on using the browser.