#pragma once

#include <stdio.h>


//udp
#define ALPR_THREAD_PORT			30781//alpr
#define MAIN_THREAD_PORT			30782//main
#define MAIN_THREAD_ROLE_PORT      (30882)//main(role)
//#define CLIENT_UDP_PORT       30783
//udp
//#define MASTER_DISCOVERY_PORT 30786
#define ALPR_SRV_DISCOVERY_PORT 30787//srv
#define LOGIC_THREAD_PORT		(30783)//logic
#define COMM232_THREAD_PORT		(30788)//232

//tcp
#define MAIN_CAMERA_PORT	  37080		//main server port
#define UPGRADESVR_UDP_PORT   30784		//upgrade server port
#define PUSH_SVR_PORT         30785		//AlprSrv server port




#if 0
#define RECOG_IMG_WIDTH 1920
#define RECOG_IMG_HEIGHT 1080
#else
#define RECOG_IMG_WIDTH 1280
#define RECOG_IMG_HEIGHT 720
#endif
typedef enum msg_type
{
    M_SetROI = 1200,
    M_GetROI,
    M_PLATE_INFO,
    M_CLIENT_CONNECT,
    M_SetSystemConfig,
    M_GetSystemConfig,
    M_SetAlprConfig,
    M_GetAlprConfig,
    M_SetRS485Config,
    M_GetRS485Config,
    M_SetGateConfig,
    M_GetGateConfig,
    M_SetCameraConfig,
    M_GetCameraConfig,
    M_UploadJPG,
    M_OpenGate,
    M_UpgradeFile_Req,
    M_UpgradeFile_Res,
    M_VersionReq,
    M_VersionRes,
    M_SetPlateListReq,
    M_SetPlateListRes,
    M_GetPlateListReq,
    M_GetPlateListRes,
    M_SendCommDataReq,
    M_SendCommDataRes,
    M_RecogByManualReq,
    M_SetROIEx,
    M_GetROIEx,
    M_OpenTelnet,
    M_SetVirtualCoil,
    M_GetVirtualCoil,
    M_SensorAlarmStart,
    M_SensorAlarmStop,
	M_SetDevSN,//设置设备序列号add by fangzx 20170306
	M_GetDevSN,//获取设备序列号add by fangzx 20170306
	M_GetDevVerInfo,//获取设备版本信息add by fangzx 20170317
	M_SetBaseParam,//设置基本参数add by fangzx 20170417
	M_GetBaseParam,//获取基本参数add by fangzx 20170417
	M_SendHeartBeat,//发送心跳add by fangzx 20170419
	M_SetAPIClientType,
	M_ClearPlateList,//清空车牌列表add by fangzx 20170613
	M_ResetFactory,//恢复出厂设置add by fangzx 20170613
	M_SetDeviceData,//下发数据add by fangzx 20170701
	M_SetOfflineParam,//设置脱机参数
	M_GetOfflineParam,//获取脱机参数
	M_GetClientList,		//取客户端列表
	M_GetClientListResp,	//取客户端列表响应
	M_GetDeviceDataCount,
	M_GetDeviceDataCountRes,
	M_GetDeviceData,
	M_GetDeviceDataRes,
	M_SyncTimeReq,		//同步时间请求
	M_SyncTimeResp,		//同步时间响应
	M_TimeChangeNotify,	//sdk通过巨龙接口设置了时间
	M_ClearDeviceData,  //清空数据
	M_DevStatus,		//设备状态add by fangzx 20170803
	M_SetCountryCode,	//设置国家编码
	M_OpetationSDCardReq,	//SD卡操作
	M_OpetationSDCardRes,	//SD卡操作结果


	M_HeartBeat,
	M_SetcameraExpParam,
	M_GetcameraExpParam,
	//add by fangzx 20171013检测移动侦测阀值功能
	M_StartMDThrDetect,//检测移动侦测阀值
	M_GetMDThresholdReq,//获取移动侦测阀值
	M_GetMDThresholdRes,//获取移动侦测阀值结果
	//end
	
	//add by caoyanming 2017/09/21 Start
	M_CtrlBrightness,		//控制补光灯亮度
	M_SetDefOpenBrightValue, //设置默认开启补光灯的光敏值
	//add by caoyanming 2017/09/21 End
	
	M_AUXCAMDISCONNECT,		//辅助相机主动断开连接
	//add by caoyanming 2017/11/10 Start
	M_AddPlateListReq,
	M_AddPlateListRes,
	M_DelPlateListReq,
	M_DelPlateListRes,
	//add by caoyanming 2017/11/10 End
	//add by caoyanming 2017/10/12 Start
	M_SetDColorDLineSCNParam,	//设置双色双行屏的参数
	//add by caoyanming 2017/10/12 End

	M_RespAck,

	M_GetFunList,
	M_RespFunList,

	//add by linz zkparking 2.0 车队模式
	M_SetCarTeamMode,
	M_GetCarTeamModeReq,
	M_GetCarTeamModeRes,

	//add by fangzx 20180119获取设备许可授权状态
	M_GetLicenseStatusReq,
	M_GetLicenseStatusRes,
	//end

	//add by caoyanming 2017/12/25 Start
	M_WiegandCardNo,
	//add by caoyanming 2017/12/25 End

	//add by fangzx 2018/4/26 Start
	M_AddPlateListExtReq,
	M_DelPlateListExtReq,
	M_GetPlateListExtReq,
	M_ClearPlateListExtReq,
	//add by fangzx 2018/4/26 End


	//add by carl 2018/05/21
	M_GetLedMCUVer,
	M_GetLedMCUVerRes,
	M_GetSDImageFileList,
	M_GetSDImageFileListRes,
	//end add by carl 2018/05/21

	//add by fangzx 2018/05/31 Start
	//针对欧洲算法增加识别参数
	M_GetNAlprCfgReq,
	M_GetNAlprCfgRes,
	M_SetNAlprCfgReq,
	M_SetNAlprCfgRes,
	//add by fangzx 2018/05/31 End

	// Add by Caoym ftpClient 2018-09-06 Start
	M_SendImageToFtpSvr,
	M_GetFtpClientCfgReq,
	M_GetFtpClientCfgRes,
	M_SetFtpClientCfgReq,
	M_SetFtpClientCfgRes,
	// Add by Caoym ftpClient 2018-09-06 End

	//add by carl 20180913 start
	M_GetHttpClientCfgReq,
	M_GetHttpClientCfgRes,
	M_SetHttpClientCfgReq,
	M_SetHttpClientCfgRes,
	//add by carl 20180913 end

	//add by carl 20180914 start
	M_SetImportFileInfoReq,
	M_SetImportFileInfoRes,
	//add by carl 20180914 end

	//add by carl 20180915 start
	M_SetExportFileInfoReq,
	M_SetExportFileInfoRes,
	//add by carl 20180915 end

	//add by carl 20180918 start
	M_SetClearFileInfoReq,
	M_SetClearFileInfoRes,
	//add by carl 20180918 end

	//add by carl 2018/06/27
	M_HeartBeatAck,
	//end add by carl 2018/06/27

	//add by carl 2018/11/26
	M_Get4GStatusReq,
	M_Get4GStatusRes,
	M_Modem4GStatus,		//主动推送4G状态
	//end add by carl 2018/11/26

	M_SetAppAlprConfig,
	M_GetAppAlprConfig,
	M_Reboot4GModel,

	M_RecvOfflineRecordReady,


	M_SetP2PConfig,
	M_GetP2PConfig,

	M_Set4GConfig,
	M_Get4GConfig,

	M_OpenGateByID,
	M_SendCommDataByIDReq,

	M_SetWebServiceConfig,
	M_GetWebServiceConfig,

	M_SetCarSpaceROI,
	M_GetCarSpaceROI,
	M_SetCarSpaceConfig,
	M_GetCarSpaceConfig,
	M_GetCarSpaceRefreshState,

	M_CtrlLedFlickerReq,
	M_CtrlLedFlickerRes,

	M_CtrlLedTestReq,
	M_CtrlLedTestRes,

	M_RebootDevReq,

	M_UpgradeFileStart_Req,
	M_UpgradeFileStart_Res,
	M_UpgradeFileDoing_Req,
	M_UpgradeFileDoing_Res,
	M_UpgradeFileEnd_Req,
	M_UpgradeFileEnd_Res,

	M_CtrlLedFlickerStopReq,
	M_CtrlLedFlickerStopRes,
	M_DevLicenseInfoReq,
	M_DevLicenseInfoRes,

	M_SetSDKFunlist,		//设置SDK支持的功能列表
	M_UploadPlateJPG,

	M_GateOpened,	//开到位
	M_GateClosed,	//关到位
	M_CloseGate,	//关闸

    M_RoleDiscovery = 2000,//主从角色消息
}msg_t;

#define MAX_MSG_LEN 1024
#define MSG_HDR_LEN 12
#define MIN_MSG_LEN MSG_HDR_LEN
#define MSG_MAGIC       0xD38A9F74

typedef struct _cfg_msg_header
{
    msg_t          type;
    unsigned int   magic;
    int            len;
}cfg_msg_header;

typedef struct _cfg_msg
{
    msg_t          type;
    unsigned int   magic;
    int            len;
    char           body[MAX_MSG_LEN];

#ifdef __cplusplus
    _cfg_msg() {
        magic = MSG_MAGIC;
    }
    _cfg_msg(msg_t t) {
        type = t;
        magic = MSG_MAGIC;
    }
    void Init(msg_t t) {
        type = t;
        magic = MSG_MAGIC;
    }
    bool Isvalid() { return (MSG_MAGIC == magic && len >= MSG_HDR_LEN); }

    const char* typestr() {
        switch (type)
        {
        case M_SetROI: return "M_SetROI";
        case M_GetROI: return "M_GetROI";
        case M_PLATE_INFO: return "M_PLATE_INFO";
        case M_CLIENT_CONNECT:return "M_CLIENT_CONNECT";
        case M_SetSystemConfig:return "M_SetSystemConfig";
        case M_GetSystemConfig:return "M_GetSystemConfig";
        case M_SetAlprConfig:return "M_SetAlprConfig";
        case M_GetAlprConfig:return "M_GetAlprConfig";
        case M_SetRS485Config:return "M_SetRS485Config";
        case M_GetRS485Config:return "M_GetRS485Config";
        case M_SetGateConfig:return "M_SetGateConfig";
        case M_GetGateConfig:return "M_GetGateConfig";
        case M_SetCameraConfig:return "M_SetCameraConfig";
        case M_GetCameraConfig:return "M_GetCameraConfig";
        case M_UploadJPG: return "M_UploadJPG";
        case M_OpenGate: return "M_OpenGate";
        case M_UpgradeFile_Req: return "M_UpgradeFile_Req";
        case M_UpgradeFile_Res: return "M_UpgradeFile_Res";
        case M_VersionReq: return "M_VersionReq";
        case M_VersionRes: return "M_VersionRes";
        case  M_SetPlateListReq:return "M_SetPlateListReq";
        case M_SetPlateListRes:return "M_SetPlateListRes";
        case M_GetPlateListReq:return "M_GetPlateListReq";
        case M_GetPlateListRes:return "M_GetPlateListRes";
        case M_SendCommDataReq:return "M_SendCommDataReq";
        case M_SendCommDataRes:return "M_SendCommDataRes";
        case M_RecogByManualReq:return "M_RecogByManualReq";
        case M_SetROIEx:return "M_SetROIEx";
        case M_GetROIEx:return "M_GetROIEx";
        case M_OpenTelnet:return "M_OpenTelnet";
        case M_SetVirtualCoil:return "M_SetVirtualCoil";
        case M_GetVirtualCoil:return "M_GetVirtualCoil";
        case M_SensorAlarmStart:return "M_SensorAlarmStart";
        case M_SensorAlarmStop:return "M_SensorAlarmStop";
		case M_SetDevSN: return "M_SetDevSN";//设置设备序列号add by fangzx 20170306
		case M_GetDevSN: return "M_GetDevSN";//获取设备序列号add by fangzx 20170306
		case M_GetDevVerInfo: return "M_GetDevVerInfo";//获取设备版本信息add by fangzx 20170317
		case M_SetBaseParam: return "M_SetBaseParam";//设置基本参数add by fangzx 20170417
		case M_GetBaseParam: return "M_GetBaseParam";//获取基本参数add by fangzx 20170417
		case M_SendHeartBeat: return "M_SendHeartBeat";//发送心跳add by fangzx 20170419
		case M_SetAPIClientType:return "M_SetAPIClientType";
		case M_ClearPlateList: return "M_ClearPlateList";
		case M_ResetFactory: return "M_ResetFactory";
		case M_SetDeviceData: return "M_SetDeviceData";//下发数据add by fangzx 20170701
		case M_SetOfflineParam: return "M_SetOfflineParam";//设置脱机参数
		case M_GetOfflineParam: return "M_GetOfflineParam";//获取脱机参数
		case M_GetClientList:return "M_GetClientList";
		case M_GetClientListResp:return "M_GetClientListResp";
		case M_GetDeviceDataCount:return "M_GetDeviceDataCount";
		case M_GetDeviceDataCountRes:return "M_GetDeviceDataCountRes";
		case M_GetDeviceData:return "M_GetDeviceData";
		case M_GetDeviceDataRes:return "M_GetDeviceDataRes";
		case M_SyncTimeReq:return "M_SyncTimeReq";//同步时间请求
		case M_SyncTimeResp:return "M_SyncTimeResp";//同步时间响应
		case M_TimeChangeNotify:return "M_TimeChangeNotify";
		case M_HeartBeat:return "M_HeartBeat";//辅助相机心跳包
		case M_ClearDeviceData:return "M_ClearDeviceData";
		case M_DevStatus:return "M_DevStatus";//设备状态add by fangzx 20170803
		case M_SetCountryCode:return "M_SetCountryCode";
		case M_OpetationSDCardReq:return "M_OpetationSDCardReq";
		case M_OpetationSDCardRes:return "M_OpetationSDCardRes";

		case M_SetcameraExpParam:return "M_SetcameraExpParam";
		case M_GetcameraExpParam:return "M_GetcameraExpParam";
		//add by fangzx 20171013检测移动侦测阀值功能
		case M_StartMDThrDetect:return "M_StartMDThrDetect";//检测移动侦测阀值
		case M_GetMDThresholdReq:return "M_GetMDThresholdReq";//获取移动侦测阀值
		case M_GetMDThresholdRes:return "M_GetMDThresholdRes"; //获取移动侦测阀值结果
		//end
		//add by caoyanming 2017/09/21 Start
		case M_CtrlBrightness:return "M_CtrlBrightness";				//控制补光灯亮度
		case M_SetDefOpenBrightValue:return "M_SetDefOpenBrightValue";	//设置默认开启补光灯的光敏值
		//add by caoyanming 2017/09/21 End

		case M_AUXCAMDISCONNECT:return "M_AUXCAMDISCONNECT";		//辅助相机主动断开连接
		//add by caoyanming 2017/11/10 Start
		case M_AddPlateListReq:return "M_AddPlateListReq";
		case M_AddPlateListRes:return "M_AddPlateListRes";
		case M_DelPlateListReq:return "M_DelPlateListReq";
		case M_DelPlateListRes:return "M_DelPlateListRes";
		//add by caoyanming 2017/11/10 End
		case M_SetDColorDLineSCNParam:return "M_SetDColorDLineSCNParam";	//设置双色双行屏的参数
		case M_RespAck:return "M_RespAck";
		case M_GetFunList:return "M_GetFunList";
		case M_RespFunList:return "M_RespFunList";
		//add by linz zkparking 2.0 车队模式
		case M_SetCarTeamMode:return "M_SetCarTeamMode";
		case M_GetCarTeamModeReq:return "M_GetTeamModeReq";
		case M_GetCarTeamModeRes:return "M_GetCarTeamModeRes";
		//add by fangzx 20180119
		case M_GetLicenseStatusReq:return "M_GetLicenseStatusReq";
		case M_GetLicenseStatusRes:return "M_GetLicenseStatusRes";
		//end
		//add by caoyanming 2017/12/25 Start
		case M_WiegandCardNo:return "M_WiegandCardNo";
		//add by caoyanming 2017/12/25 End
		
		//add by fangzx 2018/4/26 Start
		case M_AddPlateListExtReq:return "M_AddPlateListExtReq";
		case M_DelPlateListExtReq:return "M_DelPlateListExtReq";
		case M_GetPlateListExtReq:return "M_GetPlateListExtReq";
		case M_ClearPlateListExtReq:return "M_ClearPlateListExtReq";
		//add by fangzx 2018/4/26 End
		case M_GetLedMCUVer:return "M_GetLedMCUVer";
		case M_GetLedMCUVerRes:return "M_GetLedMCUVerRes";
		case M_GetSDImageFileList:return "M_GetSDImageFileList";
		case M_GetSDImageFileListRes:return "M_GetSDImageFileListRes";

		case M_GetNAlprCfgReq:return "M_GetNAlprCfgReq";
		case M_GetNAlprCfgRes:return "M_GetNAlprCfgRes";
		case M_SetNAlprCfgReq:return "M_SetNAlprCfgReq";
		case M_SetNAlprCfgRes:return "M_SetNAlprCfgRes";

		// Add by Caoym ftpClient 2018-09-06 Start
		case M_SendImageToFtpSvr:return "M_SendImageToFtpSvr";
		case M_GetFtpClientCfgReq:return "M_GetFtpClientCfgReq";
		case M_GetFtpClientCfgRes:return "M_GetFtpClientCfgRes";
		case M_SetFtpClientCfgReq:return "M_SetFtpClientCfgReq";
		case M_SetFtpClientCfgRes:return "M_SetFtpClientCfgRes";
		// Add by Caoym ftpClient 2018-09-06 End

		case M_GetHttpClientCfgReq:return "M_GetHttpClientCfgReq";
		case M_GetHttpClientCfgRes:return "M_GetHttpClientCfgRes";
		case M_SetHttpClientCfgReq:return "M_SetHttpClientCfgReq";
		case M_SetHttpClientCfgRes:return "M_SetHttpClientCfgRes";
		case M_SetImportFileInfoReq:return "M_SetImportFileInfoReq";
		case M_SetImportFileInfoRes:return "M_SetImportFileInfoRes";
		case M_SetExportFileInfoReq:return "M_SetExportFileInfoReq";
		case M_SetExportFileInfoRes:return "M_SetExportFileInfoRes";
		case M_SetClearFileInfoReq:return "M_SetClearFileInfoReq";
		case M_SetClearFileInfoRes:return "M_SetClearFileInfoRes";
		case M_HeartBeatAck:return "M_HeartBeatAck";
		case M_Get4GStatusReq:return "M_Get4GStatusReq";
		case M_Get4GStatusRes:return "M_Get4GStatusRes";
		case M_Modem4GStatus:return "M_Modem4GStatus";
		case M_SetAppAlprConfig:return "M_SetAppAlprConfig";
		case M_GetAppAlprConfig:return "M_GetAppAlprConfig";
		case M_Reboot4GModel:return "M_Reboot4GModel";
		case M_RecvOfflineRecordReady:return "M_RecvOfflineRecordReady";

		case M_SetP2PConfig:return "M_SetP2PConfig";
		case M_GetP2PConfig:return "M_GetP2PConfig";
		case M_Set4GConfig:return "M_Set4GConfig";
		case M_Get4GConfig:return "M_Get4GConfig";
		case M_OpenGateByID:return "M_OpenGateByID";
		case M_SendCommDataByIDReq:return "M_SendCommDataByIDReq";

		case M_SetWebServiceConfig:return "M_SetWebServiceConfig";
		case M_GetWebServiceConfig:return "M_GetWebServiceConfig";

		case M_SetCarSpaceROI:return "M_SetCarSpaceROI";
		case M_GetCarSpaceROI:return "M_GetCarSpaceROI";
		case M_SetCarSpaceConfig:return "M_SetCarSpaceConfig";
		case M_GetCarSpaceConfig:return "M_GetCarSpaceConfig";
		case M_GetCarSpaceRefreshState:return "M_GetCarSpaceRefreshState";
		case M_CtrlLedFlickerReq:return "M_CtrlLedFlickerReq";
		case M_CtrlLedFlickerRes:return "M_CtrlLedFlickerRes";
		case M_CtrlLedTestReq:return "M_CtrlLedTestReq";
		case M_CtrlLedTestRes:return "M_CtrlLedTestRes";

		case M_RebootDevReq:return "M_RebootDevReq";

		case M_UpgradeFileStart_Req:return "M_UpgradeFileStart_Req";
		case M_UpgradeFileStart_Res:return "M_UpgradeFileStart_Res";
		case M_UpgradeFileDoing_Req:return "M_UpgradeFileDoing_Req";
		case M_UpgradeFileDoing_Res:return "M_UpgradeFileDoing_Res";
		case M_UpgradeFileEnd_Req:return "M_UpgradeFileEnd_Req";
		case M_UpgradeFileEnd_Res:return "M_UpgradeFileEnd_Res";

		case M_CtrlLedFlickerStopReq: return "M_CtrlLedFlickerStopReq";
		case M_CtrlLedFlickerStopRes: return "M_CtrlLedFlickerStopRes";
		case M_DevLicenseInfoReq: return "M_DevLicenseInfoReq";
		case M_DevLicenseInfoRes: return "M_DevLicenseInfoRes";

		case M_SetSDKFunlist: return "M_SetSDKFunlist";
		case M_UploadPlateJPG:return "M_UploadPlateJPG";
		case M_GateOpened:return "M_GateOpened";
		case M_GateClosed:return "M_GateClosed";
		case M_CloseGate:return "M_CloseGate";

        case M_RoleDiscovery: return "M_RoleDiscovery";

        default:
            break;
        }
        return "Invalid MSG";
    }
#endif

}cfg_msg;

enum res_code
{
    RC_OK,
    RC_InvalidLength,
    RC_InvalidName,
    RC_WriteErr,
};

typedef struct _file_msg
{
    int length;  //文件总长度
    char filename[20];
}file_msg;

