/*!
 *
 * 02may2011, edv: modified for VxWorks prototype
 *
\copyright  Copyright (C) Kontron AG 2010. All Rights Reserved.
    
\project    KEAPI
\subproject 
\file       keapi_types.h
\brief      KEAPI data types.
\author     Pavel Masek
\date       02.10.2010
\version    1.2
*****************************************************************************/
#ifndef _KEAPI_TYPES_H
#define	_KEAPI_TYPES_H

#ifdef __cplusplus
extern "C" {
#endif

#define KEAPI_SERVER_PORT					7890																/*!< Default port for client-server communication */
#define KEAPI_VERSION_TEXT				"KEAPI v. 1.2.0.5"									/*!< Keapi string sent during server/client initialization */
#define KEAPI_VERSION							0x01020005													/*!< Identification of keapi version */
#define MAX_STR										128																	/*!< Maximal count of characters for string fields */	

enum LogLevel
{
   LV_ERROR = 0x01,
   LV_WARN  = 0x02,
   LV_INFO  = 0x04,
   LV_DEBUG = 0x08,
   LV_TRACE = 0x10,
   LV_ALLTIME = 0xFF
};

/*//////////////////////////////////////////////////////////////////////////////
// Call type definition
////////////////////////////////////////////////////////////////////////////// */

#define PLATFORM(x) PLATFORM_ ## x

#ifdef _WIN32
#define PLATFORM_Windows 1

#if defined(KONTRON_API_EXPORTS)
#define KEAPI_CALLTYPE __declspec (dllexport)
#elif defined(__cplusplus)
#define KEAPI_CALLTYPE extern "C" __declspec (dllimport)
#else
#define KEAPI_CALLTYPE __declspec (dllimport)
#endif

// disable because this forces us to use non-standard functions
#define _CRT_SECURE_NO_WARNINGS

#elif __linux__

#define PLATFORM_Linux 1
#define KEAPI_CALLTYPE __attribute__ ((stdcall))

#else
#define PLATFORM_VxWorks 1
#define KEAPI_CALLTYPE 
/*#error "unsupported platform"*/
#endif

////////////////////////////////////////////////////////////////////////////////
// Definition of keapi data types
////////////////////////////////////////////////////////////////////////////////

#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

#ifndef FALSE
#define FALSE               0
#endif

#ifndef TRUE
#define TRUE                1
#endif

typedef char                KEAPI_INT8;
typedef short               KEAPI_INT16;
typedef int									KEAPI_INT32;
typedef long long           KEAPI_INT64;
typedef unsigned char       KEAPI_UINT8;
typedef unsigned short      KEAPI_UINT16;
typedef unsigned int        KEAPI_UINT32;
typedef unsigned long long  KEAPI_UINT64;
typedef char*               KEAPI_PINT8;
typedef short*              KEAPI_PINT16;
typedef int*                KEAPI_PINT32;
typedef long long*          KEAPI_PINT64;
typedef unsigned char*      KEAPI_PUINT8;
typedef unsigned short*     KEAPI_PUINT16;
typedef unsigned int*       KEAPI_PUINT32;
typedef unsigned long long* KEAPI_PUINT64;
typedef float               KEAPI_FLOAT;
typedef double              KEAPI_DOUBLE;
typedef float*              KEAPI_PFLOAT;
typedef double*             KEAPI_PDOUBLE;
typedef char                KEAPI_CHAR;
typedef char*               KEAPI_PCHAR;
typedef unsigned char       KEAPI_UCHAR;
typedef unsigned char*      KEAPI_PUCHAR;
typedef unsigned char       KEAPI_BOOL;
typedef unsigned char*      KEAPI_PBOOL;
typedef unsigned int        KEAPI_RETVAL;

/*//////////////////////////////////////////////////////////////////////////////
// Definition of keapi return values
/////////////////////////////////////////////////////////////////////////////// */

/* General return values */
#define KEAPI_RET_SUCCESS                               0x00000000   /*!< The function was successfull                     */
#define KEAPI_RET_ERROR                                 0xFFFFFFFF   /*!< General error. Use only when there is no appropriate specific error return value */
#define KEAPI_RET_PARAM_ERROR							0x00000001   /*!< Wrong parametr value */
#define KEAPI_RET_PARAM_NULL							0x00000002   /*!< Parameter is NULL where it is not allowed	*/
#define KEAPI_RET_HW_COUNT_EXCEEDED						0x00000006   /*!< HW count exceeded */
#define KEAPI_RET_WD_TIMEOUT_NOT_SUPPORTED				0x00000007   /*!< WD timeout not supported */
#define KEAPI_RET_BUFFER_OVERFLOW                       0x00000008   /*!< Buffer overflow (probably configuration error) */
#define KEAPI_RET_SETTING_ERROR				            0x00000009   /*!< Error while setting value or feature (enable, disable) */
#define KEAPI_RET_WRITE_ERROR                           0x0000000A   /*!< Cannot write */
#define KEAPI_RET_READ_ERROR                            0x0000000B   /*!< Cannot read */
#define KEAPI_RET_MALLOC_ERROR							0x0000000C	 /*!< Memory allocation failed */
#define KEAPI_RET_LIBRARY_ERROR							0x0000000D	 /*!< Exported function could not be loaded from library*/
#define KEAPI_RET_WMI_ERROR								0x0000000E   /*!< This signalizes some problem during reading from WMI   */
#define KEAPI_RET_NOT_INITIALIZED						0x0000000F   /*!< KEAPI library is not initialized                 */
#define KEAPI_RET_PARTIAL_SUCCESS						0x00000010   /*!< This signalizes that some of the parameters were not initialized. Should be replaced by more specific retval to specify which parameters were successfully initialized and which parameters were not. */
#define KEAPI_RET_FUNCTION_NOT_SUPPORTED				0x00000011   /*!< Function is not supported on current platform/HW */
#define KEAPI_RET_RETRIEVAL_ERROR						0x00000012   /*!< Error while retrieving information               */
#define KEAPI_RET_FUNCTION_NOT_IMPLEMENTED				0x00000013   /*!< Function is not yet implemented */
#define KEAPI_RET_NOT_SUPPORTED_HWSWCONF                KEAPI_RET_FUNCTION_NOT_SUPPORTED

/* Remote connection return values */
#define KEAPI_RET_RPC_ERR_MAX_CONN_COUNT_EXCEEDED		0x00010001   /*!< RPC - Maximal count of allowed connections on the client side was reached */
#define KEAPI_RET_RPC_ERR_SOCKET_ERROR					0x00010002   /*!< RPC - This signalizes some error with socket manipulation */
#define KEAPI_RET_RPC_ERR_CONNECTION_NOT_FOUND			0x00010003   /*!< RPC - Connection for given board handle does not exist */
#define KEAPI_RET_RPC_ERR_NOT_IMPLEMENTED     			0x00010004   /*!< RPC - Function is not implemented for remote call */
#define KEAPI_RET_RPC_ERR_SOCKET_TIMEOUT				0x00010005   /*!< RPC - This error is returned if time limit for select function expired */
#define KEAPI_RET_RPC_ERR_PACKET_ERROR					0x00010006	 /*!< RPC - This error is returned if format of keapi packet is wrong */
#define KEAPI_RET_RMT_CON_ERROR							0x00010007   /*!< RPC - Remote call failed */
#define KEAPI_RET_INVALID_IP							0x00010008   /*!< RPC - IP address is not in a valid format */


/*///////////////////////////////////////////////////////////////////////////////
// Definition of keapi status codes
/////////////////////////////////////////////////////////////////////////////// */

/* System states - used by functions KEApiGetSystemState and KEApiSetSystemState */
#define SYSTEM_STATE_TURN_ON    0         /*!< System is running/turn-on system */
#define SYSTEM_STATE_TURN_OFF   1         /*!< Turn-off system                  */
#define SYSTEM_STATE_HIBERNATE  2         /*!< Hibernate system                 */
#define SYSTEM_STATE_RESTART    3         /*!< Restart system                 */

/* Intruder states - used by functions KEApiGetIntruderStatus and KEApiSetIntruderStatus */
#define INTRUDER_STATUS_CASE_CLOSED     0   /*!< Case was not opened            */
#define INTRUDER_STATUS_CASE_OPENED     1   /*!< Case was opened                */

/* Battery power states */
#define POWER_STATE_CHARGING     	0
#define POWER_STATE_CHARGED      	1
#define POWER_STATE_DISCHARGING     	2

/* Fan control modes */
#define FAN_METHOD_MAX_SPEED 0
#define FAN_METHOD_MANUAL 1
#define FAN_METHOD_THERMAL_CRUISE 2

/* CPU frequencies */
#define CPU_FREQUENCY_MIN 0
#define CPU_FREQUENCY_MAX 1
#define CPU_FREQUENCY_CURRENT 2

/* CPU performance */
#define CPU_PERFORMANCE_HIGH 0
#define CPU_PERFORMANCE_POWER_SAVE 1
#define CPU_PERFORMANCE_ON_DEMAND 2
#define CPU_PERFORMANCE_CONSERVATIVE 3
#define CPU_PERFORMANCE_USER 4

/* GPIO direction */
#define GPIO_DIRECTION_IN 0
#define GPIO_DIRECTION_OUT 1

#define KEAPI_LOCAL_BOARD_HANDLE        0   /*!< Handle of local board is always 0 */


/*///////////////////////////////////////////////////////////////////////////////
// Definition of keapi structures
/////////////////////////////////////////////////////////////////////////////// */

/*! \brief Structure for board basic info                                        */
typedef struct Keapi_Version_Data
{
   KEAPI_CHAR KeapiVersionText		[MAX_STR];
	 KEAPI_UINT32 KeapiVersion;
} KEAPI_VERSION_DATA, *PKEAPI_VERSION_DATA;

/* ////////////////////////////////////////////////////////////////////////////// */
typedef struct Board_Info
{
    KEAPI_CHAR boardManufacturer	[MAX_STR];    /*!< Board manufacturer               */
    KEAPI_CHAR boardName					[MAX_STR];    /*!< Board name                       */
    KEAPI_CHAR boardVersion				[MAX_STR];    /*!< Board version                    */
    KEAPI_CHAR boardSerialNumber	[MAX_STR];    /*!< Board serial number              */
    KEAPI_CHAR biosVersion				[MAX_STR];    /*!< BIOS version                     */
    KEAPI_CHAR biosDate						[MAX_STR];    /*!< BIOS date in format dd/mm/yyyy   */
} BOARD_INFO, *PBOARD_INFO;

/*////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for CPU basic info                                        */
typedef struct Cpu_Info
{
	KEAPI_CHAR	cpuName							[MAX_STR];		/*!< CPU name*/
	KEAPI_INT32	cpuCount;													/*!< Number of CPUs*/
	KEAPI_INT32	cpuCoreCount;											/*!< Number of cores of each CPU*/
	KEAPI_INT32	cpuThreadCount;										/*!< Number of CPU threads*/
	KEAPI_FLOAT	cpuMaxCoreSpeed;									/*!< Designed core speed in MHz*/
	KEAPI_INT32	fsbSpeed;													/*!< FSB speed in MHz*/
	KEAPI_INT32	l1Cache;													/*!< L1 cache size in kB*/
	KEAPI_INT32	l2Cache;													/*!< L2 cache size in kB*/
	KEAPI_INT32	l3Cache;													/*!< L3 cache size in kB*/
} CPU_INFO, *PCPU_INFO;

/*////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for physical memory info*/
typedef struct Memory_Info
{
	KEAPI_INT32	memTotal;													/*!< Total physical memory size in MB*/
	KEAPI_INT32	memFree;													/*!< Free memory in MB*/
	KEAPI_INT32	memSpeed;													/*!< Memory speed in MHz*/
	KEAPI_CHAR	memType							[MAX_STR];		/*!< Type of memory (DDR, DDR2, etc.  */
} MEMORY_INFO, *PMEMORY_INFO;


/*////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for memory module info*/
typedef struct MemoryModule
{
	KEAPI_INT32	moduleSize;												/*!< Module capacity in MB*/
	KEAPI_CHAR	manufacturer				[MAX_STR];		/*!< Memory module manufacturer*/
	KEAPI_CHAR	partNumber					[MAX_STR];		/*!< Memory module part number*/
	KEAPI_CHAR	serialNumber				[MAX_STR];		/*!< Memory module serial number*/
} MEMORY_MODULE, *PMEMORY_MODULE;


/*////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for battery info*/
typedef struct Battery_Info
{
	KEAPI_CHAR	deviceName					[MAX_STR];		/*!< Device name*/ 
	KEAPI_CHAR	type								[MAX_STR];		/*!< LION, NiCd, NiMH�*/
	KEAPI_CHAR	serialNumber				[MAX_STR];		/*!< Serial number */
	KEAPI_INT32	designedVoltage;									/*!< Designed voltage in mV*/
	KEAPI_INT32	designedCapacity;									/*!< Designed capacity of fully charged battery in mAh*/
	KEAPI_INT32	fullyChargedCapacity;							/*!< Real capacity of fully charged battery in mAh*/
	KEAPI_INT32	cycleCount;												/*!< Number of charge/discharge cycles experienced during lifetime*/
} BATTERY_INFO, *PBATTERY_INFO;

/*////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for actual battery state */
typedef struct BatteryState
{
	KEAPI_INT32	powerState;												/*!< Current power state - charging = 0, charged = 1, discharging = 2*/
	KEAPI_INT32	fullBatteryRemainingTime;					/*!< Remaining time in seconds when battery is full and AC power unplugged*/
	KEAPI_INT32	remainingTime;										/*!< Remaining time in seconds*/
	KEAPI_INT32	remainingCapacity;								/*!< Remaining capacity in mAh*/
	KEAPI_INT32	currentVoltage;										/*!< Current voltage in mV*/
	KEAPI_INT32	rate;															/*!< Current charging/discharging rate in mA*/
	KEAPI_INT32	chargeState;											/*!< Battery charge state in percentage */
} BATTERY_STATE, *PBATTERY_STATE;


/*////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for PCI device info*/
typedef struct Pci_Device
{
	KEAPI_INT32	domain;														/*!< Domain number*/
	KEAPI_INT32	bus;															/*!< Bus number*/
	KEAPI_INT32	slot;															/*!< Slot number*/
	KEAPI_INT32	funct;														/*!< Function number*/
	KEAPI_INT32	deviceId;													/*!< Device ID*/
	KEAPI_INT32	vendorId;													/*!< Vendor ID*/
	KEAPI_INT32	classId;													/*!< Class ID*/
	KEAPI_CHAR	deviceName					[MAX_STR];		/*!< Name of the device*/
	KEAPI_CHAR	vendorName					[MAX_STR];		/*!< Name of the vendor*/
	KEAPI_CHAR	className						[MAX_STR];		/*!< Name of the class*/
} PCI_DEVICE, *PPCI_DEVICE;


/* ////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for network device info*/
typedef struct Network_Device
{
	KEAPI_CHAR	ip									[MAX_STR];		/*!< IP address*/
	KEAPI_CHAR	mac									[MAX_STR];		/*!< MAC address in format XX-XX-XX-XX-XX-XX*/
	KEAPI_INT32	speed;														/*!< Connection speed*/
	KEAPI_CHAR	deviceName					[MAX_STR];		/*!< Name of the network device*/
} NETWORK_DEVICE, *PNETWORK_DEVICE;



/* ////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for disk drive info*/
typedef struct Disk_Drive
{
	KEAPI_CHAR	name[MAX_STR];										/*!< HDD name*/
	KEAPI_CHAR	model[MAX_STR];										/*!< Model*/
	KEAPI_CHAR	diskSerialNumber		[MAX_STR];		/*!< Serial number*/
	KEAPI_UINT32	size;														/*!< Size in MB*/
} DISK_DRIVE, *PDISK_DRIVE;


/* ////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for disk partition info*/
typedef struct Disk_Partition
{
	KEAPI_CHAR	name								[MAX_STR];		/*!< Partition name*/
	KEAPI_CHAR	fsType							[MAX_STR];		/*!< Filesystem type*/
	KEAPI_UINT32	partitionSize;									/*!< Size in MB*/
	KEAPI_UINT32	freeSpace;											/*!< Free space in MB*/
} DISK_PARTITION, *PDISK_PARTITION;


/* ////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for temperature sensor info*/
typedef struct Temp_Sensor
{
	KEAPI_CHAR	name								[MAX_STR];		/*!< Sensor�s name*/
	KEAPI_INT32	value;														/*!< Value obtained from sensor in millidegrees*/
} TEMP_SENSOR, *PTEMP_SENSOR;


/* ////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for voltage sensor info*/
typedef struct Voltage_Sensor
{
    KEAPI_CHAR  name							[MAX_STR];		/*!< Sensor�s name*/
    KEAPI_INT32 value;													/*!< Value obtained from the sensor in millivolts*/
} VOLTAGE_SENSOR, *PVOLTAGE_SENSOR;


/* ////////////////////////////////////////////////////////////////////////////// */
/*! \brief Structure for fan info	*/
typedef struct Fan
{
	KEAPI_CHAR	name								[MAX_STR];		/*!< Fan name*/
	KEAPI_UINT32	rpm;														/*!< Revolutions per minute*/
	KEAPI_UINT8	pwm;															/*!< Pulse width modulation fan control*/
	KEAPI_UINT8	powerMode;												/*!< Fan speed control mode 0 = DC, 1 = PWM*/
	KEAPI_UINT8	method;														/*!< Method of control - Maximal speed, manual control or thermal cruise */
} FAN, *PFAN;

#ifdef __cplusplus
} /* #ifdef __cplusplus */
#endif

#endif /* _KEAPI_TYPES_H */
/**********************************************************************
  Copyright (C) Kontron AG 2010. All Rights Reserved.
 **********************************************************************/
