

/**************************************************************************
 * telemtry_string.cpp
 * Comments:	This files contains functionality for vision string, 
 * 		logging string, and disk logging.
 *  
 *************************************************************************/


#include <sys/time.h>
#include <fstream>
#include "telemetry_string.h"
#include "io_element_control.h"
#include "io_element.h"
#include "depth.h"
#include "telemetry.h"
#include "parser.h"


enum ProtocolChoice {logSend, logRecv, visionSend, visionRecv, tmsRecv, depthSend, rovheadSend, shipheadSend};
Telemetry_String telstring;	// global Object


/************************ global for vision/Logging **********************/
long 	long_values[5];
int  	int_values[20];
float 	float_values[30];
float teleos_fb_foreaft;
float teleos_fb_turns;
float teleos_fb_lateral;
float teleos_fb_vertical;
int 	teleos_enable = 0;
int 	dive_num = 0;
int 	rpm_interval = 1;
int 	rpm;
char	current_time[50];
extern float dvl_altitude;
extern float ship_heading;
extern int deviation_fog, deviation_compass, declination_fog, declination_compass;

char vision_tx[255];   //Global for transmitt to tcl in teleos setup

/******************* Global variables for Disk Logging **********************/
int time_counter = 0;
char log_info_string[256];
char disk_log_string[1024];
string log_filename;
string old_log_filename;
int log_interval;
int log_time;
int disk_logging_status = 0;     	// default is off
int printer_logging_status = 0;     	// default is off
int tenths_of_sec = 1;
static char old_time[100];

/****************************************************************************/



/* Constructor - throw() keyword disables throwing exception */
Telemetry_String::Telemetry_String() 	throw()
{
 	first_log = NULL;
 	log_ptr = NULL;
 	log_count = 0;
}


/* Destructor - throw() keyword disables throwing exception */
Telemetry_String::~Telemetry_String()	throw()
{}



/* 
 * updateOutFields:	sets the values to be concatenated 
 * Preconditions:	protocolChoice - logSend/visionSend
 * Called By:		vision_device and logging_device 
 * Returns:		None. 	
 */
void  Telemetry_String::updateOutFields(int protocolChoice)
{
   	if (protocolChoice == logSend)
   	{
		long_values[0]= (long int) vehicle.curr_raw_psi;  // milibar depth
		int_values[0]= ioElementControl.get_but_state (1,23);	// CTD Power	
		if ( vehicle.curr_depth < 2) int_values[1] = 0;		// in water switch
		else int_values[1] = 1;
			
		int_values[2]= (int)((vehicle.gesdac_output[0] + 5.00) * 4095 / 10 );				// port thruster
		int_values[3]= (int)((vehicle.gesdac_output[1] + 5.00) * 4095 / 10 );				// lateral thruster
		int_values[4]= (int)((vehicle.gesdac_output[2] + 5.00) * 4095 / 10 );   			// spare thruster
		int_values[5]= (int)((vehicle.gesdac_output[3] + 5.00) * 4095 / 10 );   			// stbd thruster
		int_values[6]= (int)((vehicle.gesdac_output[4] + 5.00) * 4095 / 10 );   			// vertical thruster
		int_values[7]= (int)((vehicle.gesdac_output[5] + 5.00) * 4095 / 10 );  				// sony cam pan
		int_values[8]= ioElementControl.get_but_state (1,8); 						// DVL OUTPUT
		int_values[9]= dive_num;
		
		float_values[0]= vehicle.curr_heading; 		// from vehicle.cpp
		float_values[1]= vehicle.curr_pitch;         	// from vehicle.cpp
		float_values[2]= vehicle.curr_roll;        	// from vehicle.cpp
		
		if (vehicle.autopilot.AltitudeSource == 0) float_values[3]= ioElementControl.get_analog_value(0,17);				// 17 is altimeter #1	
		else if (vehicle.autopilot.AltitudeSource == 1) float_values[3]= ioElementControl.get_analog_value(0,32);				// 32 is altimeter #2
		else if (vehicle.autopilot.AltitudeSource == 2)
			{
			extern float dvl_altitude;
			float_values[3]= dvl_altitude;
			}
		float_values[4]= ioElementControl.get_analog_value(0, vehicle.autopilot.turns_ch);
		float_values[5]= ioElementControl.get_analog_value(0, vehicle.autopilot.foreaft_ch);
		float_values[6]= ioElementControl.get_analog_value(0, vehicle.autopilot.latThruster_ch);
		float_values[7]= ioElementControl.get_analog_value(0, vehicle.autopilot.vertThruster_ch);
		float_values[8]= vehicle.curr_depth;
		float_values[9]= vehicle.camera.feedback_tilt;      	// sony
		float_values[10]= vehicle.camera.feedback_shoulder;   	// sony
		
	} 
	else if (protocolChoice == visionSend) 
	{
		struct timeval visionTime;
		struct timezone tz;
		time_t		currentTime;
		time_t		dummyTime;
		struct tm*	dummyGM;	
		double d;	
		int percentsec;	//percentage of a sec
		char time_str[32];

		gettimeofday(&visionTime, &tz);
		currentTime = time(&dummyTime);
		dummyGM = localtime(&currentTime);

		d = ((double)visionTime.tv_usec)/1000000.00;
		percentsec = (int) ((d * 100) + 1);	
		if (percentsec == 100) percentsec = 0;

		snprintf(time_str, 32, "%.2d%.2d%.2d%.2d", dummyGM->tm_hour, dummyGM->tm_min, dummyGM->tm_sec, percentsec);

	 	long_values[0]=  (long int) vehicle.curr_depth; 	
	 	
		int_values[0]= (int)((vehicle.teleos.port_thruster + 5.00) * 4095 / 10 );			// port thruster
		int_values[1]= (int)((vehicle.teleos.stbd_thruster + 5.00) * 4095 / 10 );			// stbd thruster
		int_values[2]= (int)((vehicle.teleos.lateral_thruster + 5.00) * 4095 / 10 );   			// lateral thruster
		int_values[3]= (int)((vehicle.teleos.vertical_thruster + 5.00) * 4095 / 10 );   		// vertical thruster
		int_values[4]= teleos_enable;
		int_values[5]= dive_num;  	
		int_values[6] = atoi(time_str);  	// Kenny 11/12/02 


	 	float_values[0]= vehicle.curr_heading; 	// heading (from depth.cpp)
		float_values[1]= vehicle.curr_pitch; 	// pitch (from depth.cpp)       		
		float_values[2]= vehicle.curr_roll; 	// roll (from depth.cpp)
				
		if (vehicle.autopilot.AltitudeSource == 0) // altitimter 1
			float_values[3]= ioElementControl.get_analog_value(0,17);				// 17 is altimeter #1	
		else if (vehicle.autopilot.AltitudeSource == 1) // altitimter 2
			float_values[3]= ioElementControl.get_analog_value(0,32);				// 32 is altimeter #2
		else if (vehicle.autopilot.AltitudeSource == 2) // DVL
			float_values[3]= vehicle.dvl_altitude;
					
		float_values[4]= teleos_fb_turns; 	//turns_ch
		float_values[5]= teleos_fb_foreaft; 	//foreaft
		float_values[6]= teleos_fb_lateral; 	//lateral	
		float_values[7]= teleos_fb_vertical;	//vertical
	 	float_values[8]= vehicle.curr_depth;			// depth
	 	float_values[9]= vehicle.camera.feedback_tilt ;		// sony camera tilt feedback
		float_values[10]= vehicle.camera.feedback_shoulder ;	// sony camera shoulder feedback
	        float_values[11]= vehicle.camera.feedback_pan ;		// sony camera pan feedback
		float_values[12]= ioElementControl.get_analog_value(0, 20);	// SIT cam tilt
		float_values[13]= ioElementControl.get_analog_value(0, 19);    	// SIT cam pan
                float_values[14] = 0; 						// spare
                float_values[15] = 0;                                      	// spare
		
	}
       	else if (protocolChoice == depthSend)
	{
        	 float_values[0]= vehicle.curr_depth;
	}
       	else if (protocolChoice == rovheadSend)
	{
                 float_values[0]= vehicle.curr_heading; 	// heading (from depth.cpp)
	}
       	else if (protocolChoice == shipheadSend)
	{
                 float_values[0] = ship_heading;
	}	
}

/* 
 * vision_concat:	concatenates the string to be sent to vision_tx 
 * Preconditions:	values should have some valid values, zero is okay.	
 * Called By:		vision_device 
 * Returns:		pointer to the char string of concatenated values. 	
 */
char* Telemetry_String::vision_concat()
{
	sprintf(vision_tx, "[%ld %d %d %d %d %d %d %d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f]\n",
		 long_values[0], int_values[0], int_values[1], int_values[2],
		 int_values[3], int_values[4], int_values[5], int_values[6],
                 float_values[0], float_values[1], float_values[2], float_values[3],
                 float_values[4], float_values[5], float_values[6], float_values[7],
                 float_values[8], float_values[9], float_values[10], float_values[11],
                 float_values[12], float_values[13], float_values[14], float_values[15]);
	return vision_tx;
}



/* 
 * logging_concat:	concatenates the string to be sent to logging 
 * Preconditions:	values should have some valid values, zero is okay.	
 * Called By:		logging_device
 * Comments:		
 * Returns:		pointer to the char string of concatenated values. 	
 */
char* Telemetry_String::logging_concat()
{
	static char tx_ptr[255];
	
	bzero(tx_ptr, 255);
	sprintf(tx_ptr, "[%ld %d %d %d %d %d %d %d %d %d %d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f]\n",
		 long_values[0], int_values[0], int_values[1], int_values[2],
		 int_values[3], int_values[4], int_values[5], int_values[6],
                 int_values[7], int_values[8], int_values[9],
                 float_values[0], float_values[1], float_values[2], float_values[3],
                 float_values[4], float_values[5], float_values[6], float_values[7],
                 float_values[8], float_values[9], float_values[10]);

	return tx_ptr;
}


/*
 * Called By:		depth_device
 * Comments:		$ - Start of Message, DBS - Depth, M - Meters
 * Returns:		pointer to the char string of concatenated values. 	
 */
char* Telemetry_String::depth_concat()
{
	static char tx_ptr[255];
	
	bzero(tx_ptr, 255);
	sprintf(tx_ptr, "$DBS,%4.1f,M\n", float_values[0]);
        return tx_ptr;
}


/*
 * Called By:		rovhead_device
 * Comments:		$ - Start of Message, HDT - ROV Heading, D - Degrees
 * Returns:		pointer to the char string of concatenated values. 	
 */
char* Telemetry_String::rovhead_concat()
{
	static char tx_ptr[255];
	
	bzero(tx_ptr, 255);
	sprintf(tx_ptr, "$HEHDT,%3.1f, T\r\n", float_values[0]);
	
	//sprintf(tx_ptr, "$PSSIROV,3.1f,+00.00,+00.00,000.00, D\n", float_values[0]);
	return tx_ptr;
}


/*
 * Called By:		shiphead_device
 * Comments:            $ - Start of Message, HDM - Ship Heading, D - Degrees
 * Returns:		pointer to the char string of concatenated values. 	
 */
char*
Telemetry_String::shiphead_concat()
{
	static char tx_ptr[255];
	
	bzero(tx_ptr, 255);
	sprintf(tx_ptr, "$HEHDT,%3.1f, T\r\n", float_values[0]);
	return tx_ptr;
}


/* Parse_and_set_string:	parses the vision string and sets system data.
 * Preconditions:		some_string contains a valid '\0' at the end.
 * Called By:			vision_device	
 * Comments:			This function is specific for vision parsing.
 * 				Teleos string must contain 14 tokens inorder
 * 				to be parsed correctly.		
 * Returns:			number of tokens parsed.
 */
int Telemetry_String::parse_and_set_string( char some_string[] )
{
   int  index[200];
   int 	retVal;
   int  str_len;

   str_len = strlen(some_string);

   retVal = parse_vision(&some_string[0], ' ', index, str_len, 200);

   if (retVal == 14)  	// fourteenth token is the checksum
   {
    	VisionControlStringIn.turns_ext_in = atof(&some_string[index[0]] );
	VisionControlStringIn.foreaft_ext_in = atof( &some_string[index[1]] ) ;
	VisionControlStringIn.lateral_ext_in = atof( &some_string[index[2]] ) ;
	VisionControlStringIn.vertical_ext_in = atof(&some_string[index[3]]  );
	VisionControlStringIn.spare_0_ext_in = atof( &some_string[index[4]] ) ;
	VisionControlStringIn.spare_1_ext_in = atof( &some_string[index[5]] ) ;
	VisionControlStringIn.spare_2_ext_in = atof( &some_string[index[6]]  ) ;
	VisionControlStringIn.spare_3_ext_in = atof( &some_string[index[7]] ) ;
	VisionControlStringIn.spare_4_ext_in = atof( &some_string[index[8]] ) ;
	VisionControlStringIn.spare_5_ext_in = atof( &some_string[index[9]] ) ;
	VisionControlStringIn.spare_6_ext_in = atof( &some_string[index[10]] ) ;
	VisionControlStringIn.spare_7_ext_in = atof(&some_string[index[11]] ) ;
	VisionControlStringIn.input_ctr_disable = atoi( &some_string[index[12]] ) ;
    }

    return retVal;

}



/* lineout:			writes a line out one by one	
 * Preconditions:		line must contain valid '\0' at the end.
 * Called By:			vision_device	logging_device	
 * Returns:			None	
 */
void Telemetry_String::lineout(int fd, char* line)
{
	while(*line) write(fd, line++, 1);	
}


/**************************************************************************
 * Disk Logging functions 
 * Comments:	Below consists of functions used for disk logging, we will
 * 		eventually like to move the rest of the functions out of 
 * 		this file.  
 *  
 *************************************************************************/

int Telemetry_String::add_log_item (string name, int type, int channel, string filename, int time, int interval)
{
	Disk_Logging * new_log;
	Disk_Logging * temp;
	
	log_filename = filename;
	log_time = time;
	log_interval = interval;

	if (strlen(name.c_str()) == 0)
	{	
		return -1;
	}
	
	if (check_log_db (name) > 0)
	{
		cout <<"disk_logging.cpp: name is empty or item exist on log db already"<<endl;
     	     	return -1;
	}

	// create a new node
	new_log = new Disk_Logging;
	new_log->name = name;
	new_log->next = NULL;
	
	//--------------------- for now -----------------
	new_log->type = type;
	new_log->channel = channel;
	

	
	// now start adding the new node to database
        temp = first_log;

        // first node
     	if (temp == NULL)
     		first_log = new_log;
     	
     	else
     	{
     		for (log_ptr = first_log; log_ptr != NULL; log_ptr = log_ptr->next)
     		{
     			temp = log_ptr;     		                                              	
     		}
  			// insert new node at the end
     		assert(temp);
     		temp->next = new_log;
  	}
  	log_count++;  		
     	//display_log_db();   	
	return 1;
}


int Telemetry_String::delete_all_log_item ()
{
	Disk_Logging *ptr;
	Disk_Logging *temp;
	
	if (first_log == NULL)
    	{
    		cout<<"telemetry_string.cpp: logging db is empty \n";
		return 0;
	}	
	ptr = first_log;
	while (ptr != NULL)
	{
		temp = ptr;
		ptr = ptr->next;
		delete temp;
	}
	first_log = NULL;
	log_ptr = NULL;
 	log_count = 0;
	return 1;
}


int Telemetry_String::delete_log_item (int index)
{

	Disk_Logging *temp;
	Disk_Logging *prev_log;
			                                    	
   	if (first_log == NULL)
    	{
    		cout<<"telemetry_string.cpp: logging db is empty \n";
		return 0;
	}	
   	if (index >= log_count)
    	{
    		cout<<"telemetry_string.cpp: log index is out of range \n";
		return 0;
	}	
	log_ptr = first_log;
	
	int i = 0;
	while (log_ptr != NULL && i < index)
	{
		log_ptr = log_ptr->next;
		i++;
	}

 	// if removing the first node
    	if (log_ptr == first_log)
	{
		first_log = log_ptr->next;
	 	
	 	cout <<"deleting : " <<log_ptr->name<<endl;
	 	delete log_ptr;
		cout<<"telemetry_string.cpp: Deleting the first Logging node \n";
	 	
	 	log_count--;
		//display_log_db();		
	 	return 1;
	}

	// if it is in the middle
     	 for (prev_log = first_log; prev_log->next != log_ptr; prev_log = prev_log->next)
     	 {
     	 	// do nothing
     	 }
     		
        assert(log_ptr);
     	temp = log_ptr->next;
     	
     	prev_log->next =  temp;
     	
	cout <<"deleting : " <<log_ptr->name<<endl;
     	delete log_ptr;
     	log_count--;
     	if (log_count == 0)
	{
		first_log = NULL;
		log_ptr = NULL;
	}
	//display_log_db();                         	
  	return 1;
}


int Telemetry_String::check_log_db(string name)
{
       	if (first_log == NULL )	return -1;
	log_ptr = first_log;
	
	while (log_ptr != NULL)
	{
	 	if (log_ptr->name == name || strlen(name.c_str()) == 0)	return 1;
	 	log_ptr = log_ptr->next;
	}
	return -1;
}


void Telemetry_String::display_log_db()
{
    	if (first_log == NULL)
    	{
    		cout<<"telemetry_string.cpp: logging db is empty \n";
		return;
	}	

	Disk_Logging *ptr;
	ptr = first_log;
	int count = 0;
	
	
	cout<<"\n---------------LOGGING DATABASE--------------"<<endl;               	

	while ( ptr != NULL )
 	{
 		cout<<"ptr->name : "<<ptr->name<<endl;		
		cout<<"ptr->type : "<<ptr->type<<endl;		
		cout<<"ptr->channel : "<<ptr->channel<<endl;		
		
		count++;
		ptr = ptr->next;
   	}
   	
   	cout<<"Size = "<<count<<endl;
  	cout<<"----------------------------------------------\n";
   	
   	return;       	
}


char* Telemetry_String::get_log_info(int index)
{
   	if (first_log == NULL)
    	{
    		cout<<"telemetry_string.cpp: logging db is empty \n";
		return 0;
	}	
   	if (index >= log_count)
    	{
    		cout<<"telemetry_string.cpp: log index is out of range \n";
		return 0;
	}	
	
	log_ptr = first_log;

	int i = 0;
	while (log_ptr != NULL && i < index)
	{
		log_ptr = log_ptr->next;
		i++;
	}
	
	snprintf (log_info_string, 256, "%s|%d|%d|%d|%d|%s", log_filename.c_str(), log_time,
					log_interval, log_ptr->type, log_ptr->channel, log_ptr->name.c_str());
 	//cout <<"log_info_string : "<<log_info_string<<endl;
 	return log_info_string;
}


char* get_curr_time()
{
	time_t currentTime;
	time_t dummyTime;
	struct tm* dummyGM;
	char 	singleField[5];
	int	str_len;
	int 	col;
	
	currentTime = time(&dummyTime);
	dummyGM = localtime(&currentTime);
	
	snprintf(current_time, 50, "%d:%d:%d %d/%d/%d", dummyGM->tm_hour, dummyGM->tm_min, dummyGM->tm_sec,
		 dummyGM->tm_mon, dummyGM->tm_mday, dummyGM->tm_year + 1900);
	return current_time;	
}

void *disk_logging(void *arg)
{
	char filename[256];
	bool sessionStarted = false;	
	extern int disk_logging_thread_timer;
    	
    	ofstream outfile;              		/* for outputing to file */
	
	while(1)
	{
		if (disk_logging_status == 1)
			{
			snprintf (filename, 256, log_filename.c_str());
			if (strlen(filename) == 0 ) //use default name if the file name is blank
				{
				//cout <<"telemetry_string.cpp: filename is empty or disk logging is disabled\n";
   	 			snprintf (filename, 256, "../logging/disk_logging");
    				}
    						    	
			memset(filename, 0, 256);
			snprintf (filename, 256, "../logging/%s", log_filename.c_str());
    	
   		 	if (sessionStarted == false) outfile.open(filename, ios::out);
			
			if (old_log_filename != log_filename)
				{
				old_log_filename = log_filename; //old filename for comparison inside loop
				outfile.close();         // close the old filename 
		  	
		  		
		        outfile.open(filename, ios::out); //open new file, create one if it doesn't exist
				sessionStarted = false;
				}
		
			if (sessionStarted == false) 
				{
				sessionStarted = true;
				time_counter = 0;
    				if ( !outfile.is_open() ) return NULL;
    				}
			
			outfile <<telstring.printing_log_data()<<endl; // for disk logging
	
			// This for loop is a delay loop for the while(1) loop above.
			// It delays for certain period until it is ready to 
			// get out of this loop and print out data to logging file
			for (int i = 0; i < log_interval; i++)	
	  			{
				time_counter++;	// Put another counter to check time for logging	
				// log_time is in minutes, need to convert it to seconds
				if (time_counter >= (log_time*600 ))	
					{
					disk_logging_status = 0;    		// kill the disk logging
					time_counter = 0;					// reset counter
					outfile.close();    // close the old filename (which is saved in "filename")
		  			}
				else 
					{
					usleep(100000);					// sleep 100 millisecond
	   				if(disk_logging_thread_timer < 100000) disk_logging_thread_timer++;
	   		 		}
				}
		}		
     		else usleep(100000);
	if(disk_logging_thread_timer < 100000) disk_logging_thread_timer++;
	}  	// end while
}


char* Telemetry_String::printing_log_data ()
{
	Disk_Logging *ptr;
        char temp[100];
 	string name;
        	
        memset(temp, 0, 100);	
	memset(disk_log_string, 0, 1024);
  	
        snprintf(temp, 100, "%s", get_curr_time() );
	strcat(disk_log_string, temp);	
	if(strcmp(old_time, temp) == 0)  //June 2005 Needed to differentiate the time samples
		{						// when the time interval is less than 1 sec
		char buffer[100];
		sprintf(buffer, ",.%d", tenths_of_sec);
		strcat(disk_log_string, buffer);
		tenths_of_sec++;
		}
	else 							// pad the columb when the time has changed
		{
		strcpy(old_time, temp);
		tenths_of_sec = 1;
		char buffer[100];
		sprintf(buffer, ",.%d", 0);
		strcat(disk_log_string, buffer);
		} 
 
        
	
	for (ptr = first_log ; ptr != NULL; ptr = ptr->next)
	{
	  	float value;
	        memset(temp, 0, 100);
	   	//cout <<" telemetry_string.cpp : ptr->type = "<<ptr->type<<endl;
	
	        switch (ptr->type)
		{
	 		case 0:    	// sub analog
	   		 		if(ptr->channel < 49) {
	   		 		value = ioElementControl.get_analog_value(ptr->type, ptr->channel);
	        			name = ioElementControl.get_element_name(ptr->type, 0, ptr->channel);
	        			}
	        			else {
	        			value = vehicle.gesdac_output[ptr->channel-49];
	        			name = ioElementControl.get_element_name(ptr->type, 0, ptr->channel);
	        			}
	        			if (name != "")	ptr->name = name;
	        				
				snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), value);
	   		        break;
	   		case 1:     	// surface analog
	
	        			value = ioElementControl.get_analog_value(ptr->type, ptr->channel);
	        			name = ioElementControl.get_element_name(ptr->type, 0, ptr->channel);
	        			if (name != "")	ptr->name = name;
	        				
				snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), value);
			        break;
			case 2:	// telemetry error
			 	snprintf(temp, 100, ", %s, %d", ptr->name.c_str(), telemetryObj.bad_packet_counter);
				break;	
			case 3:	// teleos input	 -> lateral, foreaft, vertical, turns
				snprintf(temp, 100, ", %s, %4.3f, %s, %4.3f, %s, %4.3f, %s, %4.3f",  "lateral", VisionControlStringIn.lateral_ext_in, "foreaft", VisionControlStringIn.foreaft_ext_in, "vertical", VisionControlStringIn.vertical_ext_in, "turns", VisionControlStringIn.turns_ext_in);
				break;	
			case 4: // heading
			  	snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.curr_heading + deviation_fog);
			   	break;
			case 5: // pitch
			  	snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.curr_pitch);
			   	break;
			case 6: // roll
			  	snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.curr_roll);
				break;
			case 7: // depth (meter)
			  	snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.curr_depth);
				break;
			case 8: // depth (milibar)            		  	
			  	snprintf(temp, 100, ", %s, %d", ptr->name.c_str(), vehicle.curr_raw_psi);
				break;
			case 9:	// speed1 (dvl)
			 	//snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.speed1);
				break;	
			case 10:// speed2 (dvl)
			 	//snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.speed2);
				break;	
			case 11:// speed3 (dvl)
			 	//snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.speed3);
				break;	
			case 12:// water alarm
			 	//snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.speed3);
				break;	
			case 13:// gf board1
			 	snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(),  ground_value);
				break;	
			case 14:// gf board2
			 	//snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), vehicle.speed3);
				break;	
			case 15:// Surface Analog out
				int surfVeh, digAnal;
				// dummy float values to satisfy the call
				float raw, gain, offset, max, min;
				
				surfVeh = 1;
				digAnal = 3;
				ioElementControl.readVoltage(surfVeh, digAnal, ptr->channel, value, raw,
							gain, offset, max, min);
	        		name = ioElementControl.get_element_name(surfVeh, digAnal, ptr->channel);
	        		if (name != "") ptr->name = name;
				snprintf(temp, 100, ", %s, %4.3f", ptr->name.c_str(), value);
		} 	// end switch case
				
			strcat(disk_log_string, temp);
			
	  } 	// end for loop

	  return disk_log_string;
}

