/* 
*	file: nikonD3Messages.h
*	author: Eric J Martin
*	
*	copyright: MBARI 2013
*
*	This is a definition file for inclusion in servers and clients
*	used to communicate through tcp passed data structures for 
*	configuration and control of the nikon D3 and D700.
*
*/

#ifndef _NIKOND3MESSAGES_H_
#define _NIKOND3MESSAGES_H_


#define NIKON_MESSAGE_HEADER_START		(0x1801)	//Start of the header word

#define NIKON_PROTOCOL_CURRENT_VERSION  (0x01)		//Current Protocol Version

#define NIKON_MESSAGE_STRING_LENGTH		(256)	
#define NIKON_MESSAGE_MAXDATALENGTH	    (1400)


typedef enum {
	NIKON_COMMAND_GET,					// Get a parameter 
	NIKON_COMMAND_SET,					// Set a parameter or execute command
	NIKON_COMMAND_ERROR					// Returned by servers for unknown and malformed messages
} NikonCommandType;


typedef enum {
	//ENABLING FUNCTIONS
	NIKON_MESSAGE_NONE = 0,			// Null message used to test communication
	NIKON_MESSAGE_SYSTEM_RESET,		// Set to have server reload default config, this will stop acq
	NIKON_MESSAGE_CONNECT,			// Attempt to connect (1) or disconnect (0) the PTP connection to the dsc (NikonMessageLongType)
	NIKON_MESSAGE_PRETRIGGER,		// Enable (1) or Disable (0) Pretrigger image staggering for faster acquisition (NikonMessageLongType)
	NIKON_MESSAGE_ACQUISITION,		// Enable (1) or Disable (0) Image acquisition (NikonMessageLongType)
	NIKON_MESSAGE_LASERPOWER,       // Enable (1) or Disable (0) The digital output line. This is a 232 CTS line hooked up to a 
									// optocoupler powering a "coil" on a solid state relay.
	
	
	//Variables of acquisition
	NIKON_MESSAGE_INTERVAL,			// The interval on which to trigger frames in milliseconds (NikonMessageLongType)
	NIKON_MESSAGE_FILEPREFIX,		// Get/set the file prefix for image acquisition (NikonMessageStringType)
	
	//GET ONLY MESSAGES
	NIKON_MESSAGE_STATUS,			// Get NikonMessageStatusType of GET ONLY
	NIKON_MESSAGE_IMAGECOUNT,		// Get the current frame number (NikonMessageLongType) GET ONLY
	NIKON_MESSAGE_TRIGGERCOUNT,     // Get the current trigger number issued.
	NIKON_MESSAGE_CONFIGFILE,		// The filename of the configuration for the server (NikonMessageStringType) GET ONLY
	NIKON_MESSAGE_TIME,				// Get the time of the clock on the server, set forces a sync with the camera GET ONLY

	//TRIGGER SERIAL PORT OPTIONS
	NIKON_MESSAGE_TRIGGERCONFIG,	// Get/Set the current serial port used for triggering (NikonMessageUARTType) GET ONLY

	//NAVIGATION INPUTS
	NIKON_MESSAGE_POSITION,			// Set the navigation for embedding into exif information of saved images. (NikonMessagePositionType)


} NikonMessageType;

typedef enum {
	NIKON_ERROR_UNKNOWNCMD = 0,		// Unknown Command response
	NIKON_ERROR_INVALID,			// The data or setting has an invalid value.
	NIKON_ERROR_DISCONNECTED,		// The server has lost connection to the camera. 
	NIKON_ERROR_UNKNOWN,
} NikonMessageErrorType;

// Header for message
typedef struct {
	unsigned short startOfMessage;		// marker for the start of message
	unsigned char version;				// protocol version
	unsigned char nikonCommand;			// command to enact as per NikonCommandType
	unsigned short nikonMessage;		// message format as per NikonMessageType
	unsigned char cameraID;				//reserved for potential multiple camera control
	unsigned char reservedHeader[2];	//reserved for future header messages
	unsigned long byteCount;			//size of message in bytes to follow
} NikonMessageHeaderType;



// Integer message field
typedef struct {
	long value;
} NikonMessageLongType;

// String message block
typedef struct {
	char name[NIKON_MESSAGE_STRING_LENGTH];
} NikonMessageStringType;

// Multivariable status message :TODO: not implemented.
typedef struct {
	unsigned long errorCount;			// Current error count
	unsigned long freeDiskSpace;		// Amount of disk space available in MB
	unsigned long imageCount;			// Count of frames in the current instance of recording. 
	unsigned long triggerCount;			
} NikonMessageStatusType;

// Multivariable serial config message :DEPRECATED: not implemented.
typedef struct {
	unsigned char  name[NIKON_MESSAGE_STRING_LENGTH];
	unsigned long  baudRate;
	unsigned short bits;
	unsigned char  parity;	
	unsigned short stop;
} NikonMessageUARTType;

// Multivariable message for transmission of navigation data for insertion into EXIF image metadata :DEPRECATED:
typedef struct {
	signed int		degreesLatitude;
	float			minutesLatitude;
	signed int		degreesLongitude;
	float			minutesLongitude;
} NikonMessagePositionType;

#endif