Changeset 641

Show
Ignore:
Timestamp:
07/03/09 11:30:08 (4 years ago)
Author:
balle
Message:

* merging r639 to trunk

Location:
trunk/mfiles
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/mfiles/COM_MakeBTConfigFile.m

    r414 r641  
    5959            prompt    = {'Filename:', 'SerialPort:', 'BaudRate:', 'DataBits:', 'SendPause:', 'ReceivePause:', 'Timeout:'}; 
    6060        else 
    61             prompt    = {'Filename:', 'NXT Name:', 'or NXT MAC:', 'or SerialPort:', 'SendPause:', 'ReceivePause:', 'Timeout:'}; 
     61            prompt    = {'Filename:', 'SerialPort:', 'SendPause:', 'ReceivePause:', 'Timeout:'}; 
    6262        end; 
    6363        num_lines = 1; 
     
    6868            default_parameters = {'bluetooth.ini','COM3','9600', '8', '5', '30', '2'}; 
    6969        else 
    70             default_parameters = {'bluetooth.ini','','', '/dev/rfcomm0', '5', '30', '2'}; 
     70            default_parameters = {'bluetooth.ini', '/dev/rfcomm0', '5', '30', '2'}; 
    7171        end; 
    7272 
     
    7979                baudrate     = str2double(my_parameters{3}); 
    8080                databits     = str2double(my_parameters{4}); 
     81                sendpause    = str2double(my_parameters{5}); 
     82                receivepause = str2double(my_parameters{6}); 
     83                timeout      = str2double(my_parameters{7}); 
    8184            else 
    82                 name         = my_parameters{2}; 
    83                 mac          = my_parameters{3}; 
    84                 port         = my_parameters{4}; 
     85                port         = my_parameters{2}; 
     86                sendpause    = str2double(my_parameters{3}); 
     87                receivepause = str2double(my_parameters{4}); 
     88                timeout      = str2double(my_parameters{5}); 
    8589            end; 
    86             sendpause    = str2double(my_parameters{5}); 
    87             receivepause = str2double(my_parameters{6}); 
    88             timeout      = str2double(my_parameters{7}); 
    8990 
    9091 
     
    105106            fwrite(h_file, sprintf('\r\n')); 
    106107 
     108            fwrite(h_file, sprintf('SerialPort=%s\r\n', port)); 
    107109            if ispc 
    108                fwrite(h_file, sprintf('SerialPort=%s\r\n', port)); 
    109110               fwrite(h_file, sprintf('BaudRate=%d\r\n',   baudrate)); 
    110111               fwrite(h_file, sprintf('DataBits=%d\r\n',   databits)); 
    111             else 
    112                fwrite(h_file, sprintf('NXTName=%s\r\n',    name)); 
    113                fwrite(h_file, sprintf('NXTMAC=%s\r\n',     mac)); 
    114                fwrite(h_file, sprintf('SerialPort=%s\r\n', port)); 
    115112            end; 
    116113            fwrite(h_file, sprintf('\r\n')); 
  • trunk/mfiles/COM_OpenNXTEx.m

    r438 r641  
    314314    else % LINUX file handle version 
    315315 
    316         NXTName = readFromIniFile( inisection, 'NXTName', inifilename ); 
    317         if isempty( NXTName ) 
    318             NXTMAC = readFromIniFile( inisection, 'NXTMAC', inifilename ); 
    319         else 
    320             NXTMAC = BT_Linux_ResolveName( NXTName ); 
    321         end; 
    322         if isempty( NXTMAC ) 
    323             ComPort = readFromIniFile( inisection, 'SerialPort', inifilename); 
    324         else 
    325             ComPort = BT_Linux_BindPort( NXTMAC ); 
    326         end; 
     316        ComPort = readFromIniFile( inisection, 'SerialPort', inifilename); 
    327317 
    328318        % on linux, there is no baudrate etc to set, so we ignore these ini 
     
    365355        handle = fopen( ComPort, 'r+' ); 
    366356        if handle == -1 
    367             % the creation of the device node after BindPort may take some time 
    368             pause( .5 ); 
    369             handle = fopen( ComPort, 'r+' ); 
    370         end; 
    371         if handle == -1 
    372357            error( 'MATLAB:RWTHMindstormsNXT:Bluetooth:couldNotOpenConnection', 'Could not open bluetooth connection using port %s.', ComPort ); 
    373358        end; 
    374         % make sure device is in raw mode - if this fails, let's hope for the best 
     359        % Try to make sure serial port is in raw mode. This is just a safety measure 
     360        % and probably not needed if btconnect is used. However, it doesn't hurt. 
    375361        unix( [ 'stty -F ' ComPort ' sane raw -echo -iexten' ] ); 
    376362    end 
     
    957943 
    958944 
    959 %% --- FUNCTION BT_Linux_ResolveName 
    960 function [ mac ] = BT_Linux_ResolveName( name ) 
    961  
    962     [ s, r ] = unix( 'hcitool scan' ); 
    963     if s 
    964         error( 'MATLAB:RWTHMindstormsNXT:Bluetooth:Linux:scanFailed', 'hcitool command failed. no bluetooth hardware/software installed?' ); 
    965     end; 
    966      
    967     scan_results = regexp( r, [ '^' 9 '(?<mac>\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)' 9 '(?<name>.+)$' ], ... 
    968         'names', 'dotexceptnewline', 'lineanchors' ); 
    969      
    970     r = strcmp( name, { scan_results.name } ); 
    971     if sum( r ) ~= 1 
    972         error( 'MATLAB:RWTHMindstormsNXT:Bluetooth:Linux:NxtNotFound', [ '"' name '" not found or not unique. Try specifying MAC address.' ] ); 
    973     end; 
    974     mac = scan_results( r ).mac; 
    975  
    976 end 
    977  
    978  
    979 %% --- FUNCTION BT_Linux_BindPort 
    980 function [ device ] = BT_Linux_BindPort( mac ) 
    981  
    982     % get list of currently bound ports 
    983     [ s, r ] = unix( 'rfcomm' ); 
    984     if s 
    985         error( 'MATLAB:RWTHMindstormsNXT:Bluetooth:Linux:RfCommFailed', 'rfcomm command failed (bluetooth tools not installed?)' ); 
    986     end; 
    987  
    988     bound_ports = regexp( r, '^rfcomm(?<port>\d+): (?<mac>\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)', ... 
    989         'names', 'dotexceptnewline', 'lineanchors' ); 
    990  
    991     r = strcmp( mac, { bound_ports.mac } ); 
    992  
    993     if sum( r ) > 0 
    994  
    995         % MAC address already bound to 
    996         port = bound_ports( find( r, 1 ) ).port; 
    997  
    998     else 
    999  
    1000         % find first free port and bind to it 
    1001         port = int2str( find( accumarray( reshape( str2double( { bound_ports.port } ) + 1, [], 1 ), 1 ) == 0, 1 ) - 1 ); 
    1002         if isempty( port ) 
    1003             port = int2str( max( str2double( { bound_ports.port } ) ) + 1 ); 
    1004         end; 
    1005         if isempty( port ) 
    1006             port = '0'; 
    1007         end; 
    1008  
    1009         [ s, r ] = unix( [ 'sudo rfcomm -r bind ' port ' ' mac ] ); 
    1010         if s || numel( r ) 
    1011             error( 'MATLAB:RWTHMindstormsNXT:Bluetooth:Linux:sudoFailed', 'sudo rfcomm failed (rfcomm.conf or sudo not setup properly?)' ); 
    1012         end; 
    1013  
    1014     end; 
    1015  
    1016     device = [ '/dev/rfcomm' port ]; 
    1017  
    1018 end 
    1019  
    1020  
    1021945%% --- FUNCTION StartMotorControl 
    1022946function h_out = StartMotorControl(progname, h_in)