%function bstruct = controlsonar(command)
function bstruct = controlsonar(command)
	global sonarType

if isempty(sonarType),
	sonarWizard
end

if strcmp(sonarType,'none'),
	bstruct = [];
	return
end

[bdefaults,bnames] = behaviorDefaults;
bstruct = bdefaults{indexof(bnames,sonarType)};

if (strcmp(sonarType, 'controlsonar')), % = Klein sonar, backwards compatible
    switch command
    case {'loggingOn','on'}
        bstruct = setfield(bstruct,'logging','on'); 
    case {'loggingOff','off'}
        bstruct = setfield(bstruct,'logging','off');
    case {'powerOn','normal'}
        bstruct = setfield(bstruct,'setmode','normal');
    case {'powerOff','lowpower'}
        bstruct = setfield(bstruct,'setmode','lowpower');
    case {'pingOn'}
        bstruct = setfield(bstruct,'setmode','normal');
    case {'pingOff','standby'}
        bstruct = setfield(bstruct,'setmode','standby'); 
    end;
elseif (strcmp(sonarType, 'controlsonaredgetech')),
    switch command
    case {'logginOn','on'}
        bstruct = setfield(bstruct,'logging','on'); 
    case {'loggingOff','off'}
        bstruct = setfield(bstruct,'logging','off');
    case {'pingOn','normal'}
        bstruct = setfield(bstruct,'setmodesbp','on');
        bstruct = setfield(bstruct,'setmodessl','on');
        bstruct = setfield(bstruct,'setmodessh','on');
    case {'pingOff','standby'}
        bstruct = setfield(bstruct,'setmodesbp','off');
        bstruct = setfield(bstruct,'setmodessl','off');
        bstruct = setfield(bstruct,'setmodessh','off');
    case {'powerOn'}
        bstruct = setfield(bstruct,'sonarsystempoweron','True');
    case {'powerOff','lowpower'}
        bstruct = setfield(bstruct,'sonarsystempoweroff','True');
    end;
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sonarWizard()
	global sonarType
%quest = 'Please select a payload:';
%title = 'Sonar Selection.';
btn1 = 'Klein SSS';
btn2 = 'Edgetech SSS/SBP';
btn3 = 'Reson Payload Controller';
btn4 = 'No Payload';
%button = questdlg(quest,title,btn1,btn2,btn4,btn1);
objnames = {'Behavior','Relative Behavior','Block'};
[s,v] = listdlg('PromptString','Please select a payload:','Name','Sonar Selection',...
	'SelectionMode','single','ListSize',[160 100],'ListString',{btn1,btn2,btn4});
if v == 0, 
sonarWizard
return, 
end

if s == 1,
	sonarType = 'controlsonar';
elseif s == 2,
	sonarType = 'controlsonaredgetech';
elseif s == 3,
	sonarType = 'none';
end

%if strcmp(button,btn1),
%elseif strcmp(button,btn2),
%elseif strcmp(button,btn4),
%end

