//----------------------------------------------------------------------------------
// <copyright file="TurnerC3.h" company="LiquidRobotics">
//	Copyright (c) Liquid Robotics Corporation.  All rights reserved.
// </copyright>
//
// <summary>
// 	This is the header file for managing the TurnerC3 Fluorometer in Current Data Mode
// </summary>
//
// <owner>Jim Kirklin</owner>
//----------------------------------------------------------------------------------


void TurnerC3(void* pParam) CALLBACK;

#define JAN_1_2000	946684800

typedef struct _C3_HEADER_
{
	uint8_t	type;
	uint8_t	length;
}C3_HEADER, *PC3_HEADER;

typedef struct _C3_ID_BLOCK_
{
	char 		serialNum[8];
	uint8_t		fwMajor;
	uint8_t		fwMinor;
	uint16_t	sensorsInstalled;
	uint8_t		datalogEnabled;
	uint16_t	datalogSize;
	uint16_t	datalogFree;
	uint8_t		commProtocolMajor;
	uint8_t		commProtocolMinor;
}C3_ID_BLOCK, *PC3_ID_BLOCK;


typedef struct _C3_DATE_TIME_BLOCK_
{
	uint16_t	halfdays;
	uint16_t	seconds;
}C3_DATE_TIME_BLOCK, *PC3_DATE_TIME_BLOCK;

typedef struct _C3_CFG_BLOCK_
{
	uint16_t	numSamples;		//0 = INFINITE
	uint16_t	period;			//In Seconds
	uint16_t	powerOnDelay;	//In milliseconds
	uint16_t	channelMask;	//Channels to read -- bits 0-5 are C1-C6, bit 6 is pressure, bit 7 is Temperature
	uint8_t		gainControl[8];	//Gain on the channel -- 0=1x, 1=10x, 2=100x, 3=auto gain -- index order is same as channel mask
	uint16_t	numReadingsAvg;	//Number of readings to average for a single sample result
	uint8_t		idlePower;		//0=Off between readings, 1=On between readings
	uint8_t		numWiperRev;	//Number of wiper revolutions before the sample
	uint16_t	cfgChecksum;	//internal checksum of the configuration data
}C3_CFG_BLOCK, *PC3_CFG_BLOCK;


typedef struct _C3_CURRENT_DATA_BLOCK_
{
	uint16_t			sampleC1;
	uint16_t			sampleC2;
	uint16_t			sampleC3;
	uint16_t			sampleC4;
	uint16_t			sampleC5;
	uint16_t			sampleC6;
	uint16_t			samplePres;
	uint16_t			sampleTemp;
	C3_DATE_TIME_BLOCK	c3DateTime;
}C3_CURRENT_DATA_BLOCK, *PC3_CURRENT_DATA_BLOCK;

typedef struct _C3_CALIBRATION_BLOCK_
{
	uint8_t				channel;
	C3_DATE_TIME_BLOCK	blankDateTime;
	uint16_t			valGain1;
	uint16_t			valGain10;
	uint16_t			valGain100;
	C3_DATE_TIME_BLOCK	standardDateTime;
	uint16_t			standardConcentration;
	uint16_t			valStandard;
	char				channelName[15];
	char				channelSerNum[10];
	char				standardUnits[8];
	char				tempCoefficient;		//N=none, C=chlorophyll, R=rhodamine
	uint16_t			tempCalibration;
	uint8_t				unused[3];
	uint16_t			calChecksum;
}C3_CALIBRATION_BLOCK, *PC3_CALIBRATION_BLOCK;




typedef struct _C3_0_LENGTH_CMD_
{
	C3_HEADER	header;
	uint16_t	checksum;
}C3_0_LENGTH_CMD, *PC3_0_LENGTH_CMD, C3_0_LENGTH_RESPONSE, *PC3_0_LENGTH_RESPONSE;

//typedef struct _C3_0_LENGTH_RESPONSE_
//{
//	C3_HEADER	header;
//	uint16_t	checksum;
//}C3_0_LENGTH_RESPONSE, *PC3_0_LENGTH_RESPONSE;


typedef struct _C3_SET_ID_
{
	C3_HEADER	header;
	char		serialNum[8];
	uint16_t	checksum;
}C3_SET_ID, *PC3_SET_ID;

typedef struct _C3_ID_RESPONSE_
{
	C3_HEADER	header;
	C3_ID_BLOCK	idBlock;
	uint16_t	checksum;
}C3_ID_RESPONSE, *PC3_ID_RESPONSE;

typedef struct _C3_DATE_TIME_
{
	C3_HEADER			header;
	C3_DATE_TIME_BLOCK	datetime;
	uint16_t			checksum;
}C3_SET_DATE_TIME, *PC3_SET_DATE_TIME, C3_DATE_TIME_RESPONSE, *PC3_DATE_TIME_RESPONSE;

//typedef struct _C3_DATE_TIME_RESPONSE_
//{
//	C3_HEADER		header;
//	C3_DATE_TIME	datetime;
//	uint16_t		checksum;
//}C3_DATE_TIME_RESPONSE, *PC3_DATE_TIME_RESPONSE;


typedef struct _C3_CONFIGURE_
{
	C3_HEADER		header;
	C3_CFG_BLOCK	configuration;
	uint16_t		checksum;
}C3_SET_CONFIGURE, *PC3_SET_CONFIGURE, C3_CONFIGURE_RESPONSE, *PC3_CONFIGURE_RESPONSE;


typedef struct _CURRENT_DATA_START_
{
	C3_HEADER	header;
	uint8_t		start;		//1=start sampling and reporting current data as per the configuration set. 0=stop taking current data
	uint16_t	checksum;
}CURRENT_DATA_START, *PCURRENT_DATA_START;

typedef struct _CURRENT_DATA_SAMPLE_
{
	C3_HEADER				header;
	C3_CURRENT_DATA_BLOCK	currentData;
	uint16_t				checksum;

}CURRENT_DATA_SAMPLE, *PCURRENT_DATA_SAMPLE;


typedef struct _C3_GET_CALIBRATION_
{
	C3_HEADER	header;
	uint8_t		channel;		//1-6=cyclops 1-6, 7=Pressure, 8=Temperature
	uint16_t	checksum;
}C3_GET_CALIBRATION, *PC3_GET_CALIBRATION;


typedef struct _C3_SET_CALIBRATION_
{
	C3_HEADER					header;
	C3_CALIBRATION_BLOCK		calibration;
	uint16_t					checksum;
}C3_SET_CALIBRATION, *PC3_SET_CALIBRATION, C3_CALIBRATION_RESPONSE, *PC3_CALIBRATION_RESPONSE;

/*
typedef struct _TYPE_91_REPORT_HEADER_
{
	uint32_t	payloadType;
	uint8_t		boardID;
	uint8_t		taskID;
	uint8_t		dataFormat:4;
	uint8_t		parser:1;
	uint8_t		priority:3;
	uint8_t		repeatCount;
}TYPE_91_REPORT_HEADER, *PTYPE_91_REPORT_HEADER;

typedef struct _TYPE_90_91_DATA_HEADER_
{
	uint32_t	latitude;
	uint32_t	longitude;
	uint32_t	timestamp;
}TYPE_90_91_DATA_HEADER, *PTYPE_90_91_DATA_HEADER;
*/

typedef struct _C3_DATA_REPORT_BLOCK_
{
	TYPE_90_91_DATA_HEADER	headerData;
	uint16_t	dataC1;
	uint16_t	dataC2;
	uint16_t	dataC3;
	uint16_t	pressure;
	uint16_t	temperature;
}C3_DATA_REPORT_BLOCK, *PC3_DATA_REPORT_BLOCK;

#define MAX_C3_SAMPLES		7

typedef struct _C3_DATA_REPORT_
{
	TYPE_91_REPORT_HEADER	headerReport;
	C3_DATA_REPORT_BLOCK	dataBlock[MAX_C3_SAMPLES];
}C3_DATA_REPORT, *PC3_DATA_REPORT;

typedef struct _C3_ASCII_REPORT_
{
	TYPE_91_REPORT_HEADER	headerReport;
	TYPE_90_91_DATA_HEADER	headerData;
	char					data[165];
}C3_ASCII_REPORT, *PC3_ASCII_REPORT;
