##############################################################################
# Copyright 2008 MBARI.                                                      #
# Monterey Bay Aquarium Research Institute Proprietary Information.          #
# All rights reserved.                                                       #
##############################################################################

set server_input navproc
set port_input 60042
set gui_connected 0

#
# disconnet connection command
#
proc gui_disconnect {} {
    global gui_connected
        
    # set connected state
    set gui_connected 0
    
    # disable all the frames
    disable_jog 1
    disable_mode
    disable_offset
    disable_move

    # disconnect GUI from server
    disconnect_auto_rov

    # set status lights to reflect a disconnected
    set_con_stat red
    set_mov_stat black
    set_ben_stat black
    set_mid_stat black
    set_dvl_stat black

    # change the button state
    .pilot_interface.serv_frm.conn_btn configure -text "  Connect  "
}


#
# connect button command
#

proc connect_cmd {} { 
    global server_input port_input gui_connected

    if { $gui_connected > 0 } {

        # disconnect GUI from server
        disconnect_auto_rov

        # disable all the frames
        disable_jog 1
        disable_mode
        disable_offset
        disable_move

        # set status lights to reflect a disconnected
        set_con_stat red
        set_mov_stat black
        set_ben_stat black
        set_mid_stat black
        set_dvl_stat black

        # set connected state
        set gui_connected 0
        
        # change the button state
        .pilot_interface.serv_frm.conn_btn configure -text "  Connect  "

    } else {
        
        # connect GUI from server
        connect_auto_rov $server_input $port_input

        # set connection status to black, because you don't 
        # know what will happen on a connect attempt
        set_con_stat black
        
        # disable all the frames
        enable_jog
        enable_mode
        enable_offset
        enable_move

        # set connected state
        set gui_connected 1

        # change the button state
        .pilot_interface.serv_frm.conn_btn configure -text "Disconnect "
    }
}


