/**
 * @file
 * @author VoXel Interaction Design <office@voxel.at>
 * @version     1.0.0
 *
 *
 * @section DESCRIPTION
 *
 * Sentis-ToF-m100 camera API structure and type dfinitions
 * definitions
 *
 */

//apitypes.h
#ifndef _APITYPES_H
#define _APITYPES_H

/**
 * @defgroup flags Flags macros
 *
 * @brief API Flags. 
 *
 * The following macros define the values of the flags that can be use in the API functions
 *
 * @{
 */
//Config flags:
#define HOLD_CONTROL_ALIVE 0x00000001 /**< Indicate that the control connection will be opened until the handle is closed. */
//GetData flags:
#define SENTIS_NON_BLOCKING_INPUT 0x00000001 /**< Indicate that the STSgetData function should return without waiting if the frame queue is empty. */
/** @} */

/* Camera registers */
/**
 * @defgroup registers Registers macros
 *
 * @brief General Register Definitions
 *
 * @{
 */
#define Mode0 					0x0001
#define Status 					0x0003
#define ImageDataFormat 			0x0004
#define IntegrationTime 			0x0005
#define DeviceType 				0x0006
#define DeviceInfo 				0x0007
#define FirmwareInfo 				0x0008
#define ModulationFrecuency 			0x0009
#define FrameRate 				0x000A
#define HardwareConfiguration 			0x000B
#define SerialNumberLowWord 			0x000C
#define SerialNumberHighWord			0x000D
#define FrameCounter 				0x000E
#define ConfidenceThresLow 			0x0010
#define ConfidenceThresHig 			0x0011
#define Mode1 					0x0019
#define CalculationTime 			0x001A
#define LedboarsTemp 				0x001B
#define MainboardTemp 				0x001C
#define LinearizationAmplitude			0x001D
#define LinearizationPhasseShift 		0x001E
#define MaxLedTemp 				0x0024
#define HorizontalFov 				0x0026
#define VerticalFov 				0x0027
#define TriggerDelay 				0x002B
#define BootloaderStatus 			0x002C
#define TemperatureCompensationGradient	 	0x002D
#define ApplicationVersion 			0x002E
#define DistCalibGradient 			0x002F
#define DistCalibOffset 			0x0030
#define CmdExec 				0x0033
#define CmdExecResult 				0x0034
#define FactoryMacAddr2 			0x0035
#define FactoryMacAddr1 			0x0036
#define FactoryMacAddr0 			0x0037
#define FactoryYear 				0x0038
#define FactoryMonthDay 			0x0039
#define FactoryHourMinute 			0x003A
#define FactoryTimezone 			0x003B
/** @} */

/**
 * @defgroup image_format Image data format macros
 *
 * @brief Image data format configurations
 *
 * @{
 */
#define DEPTH_AMP_DATA 		0x0000
#define XYZ_COORDS_DATA 	0x0010
#define XYZ_AMP_DATA		0x0020
#define PHASES_0_270_DATA	0X0038
#define PHASES_270_0_DATA	0x0040
/** @} */

/**
 *
 * @brief Device handle
 *
 * This type contains the necessary data to communicate with
 * the Sentis-ToF-m100 camera after opening a connection.
 * these connection data are created with the STSOpen function
 * and they should be correctly closed with the STSClose
 * function to avoid any memory problems
 *
 */
typedef void * T_SENTIS_HANDLE;

/**
 *
 * @brief Configuration structure
 *
 * This structure is used for configuring the API and
 * for setting the connection parameters. It is used in the STSOpen function
 *
 */
typedef struct {
	unsigned short udp_port; /**< The udp port to use. */
	unsigned short tcp_port; /**< The tcp port to use. */
	unsigned flags; /**< Bit level set unsigned for flags. Used for forcing a specific behavior of the connection. */
	char const *tcp_ip; /**< Pointer to the string with the tcp ip address in network pointed format. */
	char const *udp_ip; /**< Pointer to the string with the udp multicast group ip address in network pointed format. */
} T_SENTIS_CONFIG;


/**
 *
 * @brief Error code
 *
 * Type of the response returned when calling API functions
 *
 */
typedef int T_ERROR_CODE;

/**
 *
 * @brief The structure contains all members of the frame header.
 *
 * It will be used for receiving and reading the configuration
 * of the image frame within STSgetData.
 *
 *
 */
typedef struct  {
	unsigned short reserved1; /**< Reserved 2 bytes. */
	unsigned short headerVersion; /**< Reserved short. */
	unsigned short imageWidth;  /**< Width of the image */
	unsigned short imageHeight;  /**< Height of the image. */
	unsigned char nofChannels; /**< Number of channels. */
	unsigned char bytesPerPixel; /**< Number of bytes per pixel. */
	unsigned short imageFormat; /**< Format of the image data. Value of the imageFormat register. */
	unsigned timestamp; /**< Unix timestamp */
	unsigned short frameCounter; /**< Frame counter */
	char reserved2[8]; /**< Reserved 8 bytes */
	unsigned char mainTemp; /**< Temperature of the main board. */
	unsigned char ledTemp; /**< Temperature of the led lamp. */
	unsigned short firmwareVersion; /**< Version of the firmware loaded in the camera. */
	char reserved3[30]; /**< Reserved 30 bytes */
	unsigned short headerCrc16; /**< Crc16 value of the header */
} T_SENTIS_DATA_HEADER;

#endif
