/****************************************************************************/
/* Copyright 2006 MBARI.                                                    */
/* Monterey Bay Aquarium Research Institute Proprietary Information.        */
/* All rights reserved.                                                     */
/****************************************************************************/


#include <stdlib.h>
#include "Gulper_Main.h"

int8 system_status = 0; // Used to store time between fire and proximity sensor


/* Actual Command Processing Below */

///*** Fire Command ***///
void handle_fire_command() {
	startTimer(); // Start the clock
	T2_startTimer(); // Start the actuation clock also
	
  output_bit(PIN_B2, HI); // Turn on fired LED
  
	output_bit(PIN_C4, LO); // Fire pin puller
	output_bit(PIN_C5, HI);

  //delay_us(150000); // Delay for 150 msec

  //output_bit(PIN_C4, HI); // Clear pin puller
 	//output_bit(PIN_C5, LO);

  Fired = true;   	
}


///*** Query Command ***///
void handle_query_command() {
  if(Fired && proximity) {
  	Final_Proximity_Milliseconds = ( (ElapsedSeconds * 1000) + (Elapsed_int_count * 66.6666) );
  } 
  // Print the time
  sprintf(response_message, "%Ld\r\n", Final_Proximity_Milliseconds);  
  send_response(response_message);
}


///*** Status Command ***///
void handle_status_command() {
	system_status = ( (Fired<<2)|(pin_puller_retracted<<1)|(proximity) );
	sprintf(response_message, "%x\r\n", system_status);
  send_response(response_message);
}


///*** Version Command ***///
void handle_version_command() {
  sprintf(response_message,"%s\r\n",VS_VERSION);
  send_response(response_message);
}


///*** Actuation Voltage Command ***///
void handle_actuation_voltage_command() {
  // Print the time
  sprintf(response_message, "%Ld\r\n", Final_Actuation_Milliseconds);  
  send_response(response_message);
}