﻿/**
* @file
* @brief    
* @details  
* @author   Junlong Cheng. Email: chengjunlong@whu.edu.cn
* @date     2021/10/19
* @version  1.0
* @par      Copyright(c) 2012-2021 School of Geodesy and Geomatics, University of Wuhan. All Rights Reserved.
* @par      History:
*           2021/10/19,Junlong Cheng, new \n
*/

#ifndef __X_DEFINE_INTERNAL_H__
#define __X_DEFINE_INTERNAL_H__

#define GLOBAL_ROS_NAMESPACE    "planet_smartpnt"

#define DEVICE_TYPE_NONE        0x00
#define DEVICE_TYPE_MCS_TCP     0x01
#define DEVICE_TYPE_MCS_UDP     0x02
#define DEVICE_TYPE_CAM_UDP     0x03
#define DEVICE_TYPE_IMU_UDP     0x04
#define DEVICE_TYPE_CAM         0x05
#define DEVICE_TYPE_IMU         0x06
#define DEVICE_TYPE_LID         0x07
#define DEVICE_TYPE_ODO         0x08
#define DEVICE_TYPE_GPS         0x09
#define DEVICE_TYPE_ALL         0xFF

#define DEVICE_STATUS_ROS_TOPIC "/device_status_ros_msg"

#define DEVICE_STATUS_UNKNOWN   0   // not open or timeout
#define DEVICE_STATUS_START     1   // has already started
#define DEVICE_STATUS_ACTIVE    2   // active
#define DEVICE_STATUS_TIMEOUT   3   // timeout
#define DEVICE_STATUS_STOP      4   // timeout

#define DEVICE_COMMAND_ROS_TOPIC "/device_command_ros_msg"
#define DEVICE_COMMAND_UNKNOWN  0   // unknown
#define DEVICE_COMMAND_START    1   // start
#define DEVICE_COMMAND_ACTIVE   2   // stop
#define DEVICE_COMMAND_STATUS   3   // status

#define MAX_CAM_COUNT        8
#define CAM_SYNC_ROS_TOPIC      "/cam_sync_ros_msg"
#define CAM_SYNC_MSG_QUE_PREFIX "cam_sync_msg_que"
#define CAM_SYNC_MSG_QUE_FORMAT "%02d"

#define MAX_IMU_COUNT           3
#define MAX_GPS_COUNT           4
#define MAX_LID_COUNT           1

#define DEVICE_START_REQUEST_SRV_NAME   "device_start_req_ros_srv"
#define DEVICE_STATUS_QUERY_SRV_NAME    "device_status_query_srv"

typedef struct CAM_SYNC_MSG
{
    long                seq;
    double              systime;
    double              gpstime;
    
    CAM_SYNC_MSG()
    {
        seq = 0;
        systime = 0.0;
        gpstime = 0.0;
    }   
} CAM_SYNC_MSG;

typedef struct CAM_SYNC_MSG_QUE
{  
    long int msg_type; 
    CAM_SYNC_MSG    msg;
    
    CAM_SYNC_MSG_QUE()
    {
        msg_type = -1;
    }
} CAM_SYNC_MSG_QUE;

typedef struct DEVICE_STATUS_MSG
{
    int         type;   // device type
    int         id;     // device id
    int         status; // device status
    
    DEVICE_STATUS_MSG()
    {
        type =  DEVICE_TYPE_NONE;
        id   = -1;
        status = DEVICE_STATUS_UNKNOWN;
    }   
} DEVICE_STATUS_MSG;


// Linux消息队列相关，发送和接收方必须使用同一个，定义在这儿

 //i = 0, msgStrKey = cam_sync_msg_que_00, msgQueKey = 48071, msgQueId = 262148
 //i = 1, msgStrKey = cam_sync_msg_que_01, msgQueKey = 44006, msgQueId = 294917
 //i = 2, msgStrKey = cam_sync_msg_que_02, msgQueKey = 39813, msgQueId = 327686
 //i = 3, msgStrKey = cam_sync_msg_que_03, msgQueKey = 35748, msgQueId = 360455
 //i = 4, msgStrKey = cam_sync_msg_que_04, msgQueKey = 64323, msgQueId = 393224
 //i = 5, msgStrKey = cam_sync_msg_que_05, msgQueKey = 60258, msgQueId = 425993
 //i = 6, msgStrKey = cam_sync_msg_que_06, msgQueKey = 56065, msgQueId = 458762
 //i = 7, msgStrKey = cam_sync_msg_que_07, msgQueKey = 52000, msgQueId = 491531

static int CAM_SYNC_MSG_QUE_KRY[MAX_CAM_COUNT+1] = {
    48071, /* cam_sync_msg_que_00 */
    44006, /* cam_sync_msg_que_01 */
    39813, /* cam_sync_msg_que_02 */
    35748, /* cam_sync_msg_que_03 */
    64323, /* cam_sync_msg_que_04 */
    60258, /* cam_sync_msg_que_05 */
    56065, /* cam_sync_msg_que_06 */
    52000, /* cam_sync_msg_que_07 */
    00000
};

typedef struct
{
	short int year;
	short int month;
	short int day;
	short int hour;
	short int minute;
	short int second;
} time_type;

typedef struct
{
	double dVersionNumber;		       ///< Program version number (i.e. 8.20)
	double dDataRateHz;			       ///< i.e. 100.0 records/second. If you do not know it, set this to zero
									   ///< and then fill it in from the interface dialog boxes
	double dGyrosScaleFactor;	       ///< Scale (multiply) the gyro measurements by this to get degrees/sec,
									   ///< if bDeltaTheta=0. Scale the gyros by this to get degrees, if
									   ///< bDeltaTheta =1. If you do not know it, then the data can not be
									   ///< processed. Our default is to store the gyro data in 0.01 arcsec
									   ///< increments or 0.01 arcsec/sec, so that GYRO_SCALE = 360000(Needed)
	double dAccelScaleFactor;	       ///< Scale (multiply) the accel measurements by this to get m/s2
									   ///< if bDeltaVelocity=0. Scale the accels by this to get m/s, if
									   ///< bDeltaVelocity =1. If you do not know it, the data can not be
									   ///< processed. Our default is to store the accel data in 1e-6 m/s
									   ///< increments or 1e-6 m/s2, so that ACCEL_SCALE = 1000000(Needed)
	double dTimeTagBias;	           ///< default is 0.0, but if you have a known millisecond-level bias in
									   ///< in your GPS..INS time tags, then enter it here
	int bDeltaTheta;		           ///< Default is 1, which indicates the data to follow will be delta
									   ///< thetas, meaning angular increments (i.e. scale and divide by
									   ///< by dDataRateHz to get degrees/second). If the flag is set to 0, then
									   ///< the data will be read directly as scaled angular rates
									   ///< Comment:0-angular rate,1-angular increment(Needed)
	int bDeltaVelocity;			       ///< Default is 1, which indicates the data to follow will be delta v's,
									   ///< meaning velocity increments (i.e. scale and divide by
									   ///< dDataRateHz to get m/s2). If the flag is set to 0, then the data will
									   ///< be read directly as scaled accelerations
									   ///< Comment:0-angular rate,1-angular increment(Needed)
	int iUtcOrGpsTime;			       ///< Defines the time-tags as being in UTC or GPS seconds of the week
									   ///< 0 – Unknown (default is GPS), 1 – UTC, 2 – GPS
	int iRcvTimeOrCorrTime;		       ///< Defines whether the GPS time-tags are on the nominal top of the
									   ///< second or are corrected for receiver time bias
									   ///< 0 - do not know (default is corrected time)
									   ///< 1 - receive time on the nominal top of the epoch
									   ///< 2 - corrected time i.e. corr_time = rcv_time - rcvr_clock_bias
	long lXoffset;				       ///< X value of lever arm, in millimeters
	long lYoffset;				       ///< Y value of lever arm, in millimeters
	long lZoffset;				       ///< Z value of lever arm, in millimeters
	time_type tCreate;		           ///< Creation time; skip if writing directly to this format (12 bytes)
	char szImuName[32];			       ///< Name or type of inertial unit that is being used
	bool bDirValid;					   ///< Set to true if the sensor definition that follows is valid
									   ///< Skip if writing directly to this format
	unsigned char ucX;		           ///< Direction of X-axis; skip if writing directly to this format
	unsigned char ucY;		           ///< Direction of Y-axis; skip if writing directly to this format
	unsigned char ucZ;			       ///< Direction of Z-axis; skip if writing directly to this format
	char szProgramName[32];  	       ///< Name of calling program; skip if writing directly to this format
	bool bLeverArmValid;	           ///< Set to true if the sensor definition that follows is valid
									   ///< Lever arm is from IMU to GPS phase centre
	char szHeader[8];			       ///< $IMURAW[\0] - NULL terminated ASCII string
	char bIsIntelOrMotorola;	       ///< 0 – Intel (Little Endian) - default
									   ///< 1 – Motorola (Big Endian) - swap bytes for IExplorer
									   ///< This can be set for any user who directly writes in our
									   ///< format with a Big Endian processor. IExplorer will swap the bytes
	char Reserved[354];		           ///< Reserved for future use; bytes should be zeroed
	double dt;                         ///< 采样间隔,通过读取IMU数据体得到的

} INS_HEAR, IE83_MIr_header_type, IE84_MIr_header_type;

typedef struct
{
	double Time;				       ///< GPS time frame – seconds of the week
	int	 gx, gy, gz;				   ///< delta theta or angular rate depending on flag in the header
	int	 ax, ay, az;				   ///< delta v or acceleration depending on flag in the header

} IE83_INS_type, IE84_INS_type;	       ///< this is the binary structure type expected in GPSIMU



#endif // __X_DEFINE_INTERNAL_H__