#include "ParsePackGateWayData.h"
#include "DeviceConfigDataManage.h"
#include "TrainDataManage.h"
#include "2oo2InterfaceDataManage.h"
#include "dquCIInterFace.h"
#include "WLBrakeDataManage.h"
#include "RRMManageAPI.h"

AtsScreenMsgFstStru g_strAtsMsgFst = { 0u };		/*远程筛选首次消息*/
AtsMsgCfmStru g_strAtsCfmFst = { 0u };				/*远程筛选首次确认*/
AtsScreenMsgSndStru g_strAtsMsgSnd = { 0u };		/*远程筛选二次消息*/
AtsMsgCfmStru g_strAtsCfmSnd = { 0u };				/*远程筛选二次确认*/

AtsEaMsgStru g_strAtsEaMsgFst = { 0u };				/*取消区间疏散首次消息*/
AtsMsgCfmStru g_strAtsEaCfmFst = { 0u };			/*取消区间疏散首次确认*/
AtsEaMsgStru g_strAtsEaMsgSnd = { 0u };				/*取消区间疏散再次消息*/
AtsMsgCfmStru g_strAtsEaCfmSnd = { 0u };			/*取消区间疏散再次确认*/

AtsWlbMsgStru g_strAtsWlbMsgFst = { 0u };			/*设置/取消全线列车紧急制动首次消息*/
AtsMsgCfmStru g_strAtsWlbCfmFst = { 0u };			/*设置/取消全线列车紧急制动首次确认*/
AtsWlbMsgStru g_strAtsWlbMsgSnd = { 0u };			/*取消全线列车紧急制动再次消息*/
AtsMsgCfmStru g_strAtsWlbCfmSnd = { 0u };			/*取消全线列车紧急制动再次确认*/

AtsDaMsgStru g_strAtsDaMsgFst = { 0u };				/*取消脱轨防护区首次消息*/
AtsMsgCfmStru g_strAtsDaCfmFst = { 0u };			/*取消脱轨防护区首次确认*/
AtsDaMsgStru g_strAtsDaMsgSnd = { 0u };				/*取消脱轨防护区再次消息*/
AtsMsgCfmStru g_strAtsDaCfmSnd = { 0u };			/*取消脱轨防护区再次确认*/

AtsMsgCfmStru g_strSndAtsCfmFst = { 0U };			/*第二个ATS的远程筛选首次确认*/
AtsMsgCfmStru g_strSndAtsEaCfmFst = { 0U };			/*第二个ATS的取消区间疏散首次确认*/
AtsMsgCfmStru g_strSndAtsWlbCfmFst = { 0U };		/*第二个ATS的设置/取消全线列车紧急制动首次确认*/
AtsMsgCfmStru g_strSndAtsDaCfmFst = { 0U };			/*第二个ATS的取消脱轨防护区首次确认*/

/**
* @brief 解析网关数据帧
* @param const UINT8* dataBuf, 数据缓冲区
* @param const UINT16 dataLength, 数据长度
* @return CI_SUCCESS:成功；CI_ERROR:失败
*/
UINT8 ParseGateWayToCiDataFrame(const UINT8* dataBuf, const UINT16 dataLength)
{
	UINT8 chRtn = CI_ERROR;
	UINT8 chMsgNum = 0u;
	UINT32 dwDataVer = 0u;
	UINT32 dwPrtclMsg = 0u;
	UINT8 chMsgId = 0u;
	UINT16 ii = 0u;
	UINT16 jj = 0U;
	UINT32 dwDataVerLocal = 0u;
	UINT8 chMsgIndex = 0u;
	UINT8 chLocalId = 0u;
	UINT8 chTrainIndex = 0u;
	UINT16 wMsgLen = 0U;
	UINT16 wMsgLenCount = 0U;
	UINT8 cAtsId = 0U;
	UINT8 cStation = 0U;
	UINT16 wIndex = 0U;
	UINT8 cAtsSendRcId = 0U;
	UINT32 dwTime = 0U;
	UINT8 cTrainNum = 0U;
	AtsScreenTrainInfoStru strTrainInfo[TRAIN_SUM_MAX] = { 0U };
	UINT32 dwTrainHlhtId = 0U;  /*列车互联互通ID*/
	UINT8 cCmdType = 0U;  /*命令类型*/
	UINT8 cLineAttr = 0U;  /*线路属性*/
	UINT8 cDevType = 0U;  /*设备类型*/
	UINT8 cDevNum = 0U;
	UINT16 wDevId = 0U;
	UINT8 szCrcTmp[1024] = { 0U };
	
	if ((NULL != dataBuf) && (0u < dataLength))
	{
		chLocalId = GetSystemParaLocalCiId();

		/* 消息数量 */
		chMsgNum = dataBuf[ii++];
		/* 数据版本号 */
		dwDataVer = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		/* 协议消息 */
		dwPrtclMsg = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		chRtn = GetCiEmapCheckVer(chLocalId, &dwDataVerLocal, CI_SYSTEM_TYPE_ATS);
		if (CI_SUCCESS == chRtn)
		{
			if(dwDataVer == dwDataVerLocal)
			{
				; /* 数据版本号校验通过 */
			}
			else
			{
				chRtn = CI_ERROR;
			}
		}
		else
		{
			; /*获取失败*/
		}

		if (CI_SUCCESS == chRtn)
		{
			if (GATE_WAY_PRTCL_VER == dwPrtclMsg)
			{
				; /* 协议版本号校验通过 */
			}
			else
			{
				chRtn = CI_ERROR;
			}
		}
		else
		{
			; /*不处理*/
		}

		if (CI_SUCCESS == chRtn)
		{
			for (chMsgIndex = 0u; chMsgIndex < chMsgNum; chMsgIndex++)
			{
				chMsgId = dataBuf[ii++];
				wMsgLen = ShortFromChar(&dataBuf[ii]);
				ii += 2U;
				wMsgLenCount = ii;
				ii++;
				switch (chMsgId)
				{
				case MSG_TYPE_REQUEST_FIRST:/* 远程筛选首次消息 */
				{
					wIndex = ShortFromChar(&dataBuf[ii + 2U]);
					if ((FLAG_SET != g_strAtsMsgFst.chFlag) || (g_strAtsMsgFst.wIndex == wIndex))
					{
						/*未收到或重复收到同一个ATS的一次命令时，解析第一个ATS下发的远程筛选首次消息*/
						g_strAtsMsgFst.dwCycle = Get2oo2CurCycleNum();
						g_strAtsMsgFst.chAtsId = dataBuf[ii++];
						if (0U < g_strAtsMsgFst.chAtsId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsMsgFst.chStation = dataBuf[ii++];
							g_strAtsMsgFst.wIndex = ShortFromChar(&dataBuf[ii]);
							ii += 2U;
							if (0U < g_strAtsMsgFst.wIndex)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsMsgFst.chTiocId = dataBuf[ii++];
							if (g_strAtsMsgFst.chTiocId == chLocalId)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsMsgFst.dwTime = LongFromChar(&dataBuf[ii]);
							ii += 4u;

							g_strAtsMsgFst.chTrainNum = dataBuf[ii++];
							if ((0U < g_strAtsMsgFst.chTrainNum) && (ATS_GATEWAY_CI_TRAIN_MAX > g_strAtsMsgFst.chTrainNum))
							{
								for (chTrainIndex = 0u; chTrainIndex < g_strAtsMsgFst.chTrainNum; chTrainIndex++)
								{
									g_strAtsMsgFst.strTrainInfo[chTrainIndex].dwTrainId = LongFromChar(&dataBuf[ii]);
									ii += 4u;
									if ((0U == g_strAtsMsgFst.strTrainInfo[chTrainIndex].dwTrainId)
										|| (UINT32_MAX == g_strAtsMsgFst.strTrainInfo[chTrainIndex].dwTrainId))
									{
										chRtn = CI_ERROR;
									}
									else
									{
										; /*DO NOTHING*/
									}

									g_strAtsMsgFst.strTrainInfo[chTrainIndex].wLgcId = ShortFromChar(&dataBuf[ii]);
									ii += 2u;

									if ((0U == g_strAtsMsgFst.strTrainInfo[chTrainIndex].wLgcId)
										|| (UINT16_MAX == g_strAtsMsgFst.strTrainInfo[chTrainIndex].wLgcId))
									{
										chRtn = CI_ERROR;
									}
									else
									{
										; /*DO NOTHING*/
									}

									if (CI_SUCCESS == chRtn)
									{
										; /*不处理*/
									}
									else
									{
										break;
									}
								}
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsMsgFst.chFlag = FLAG_SET;
						}
						else
						{
							; /*DO NOTHING*/
						}
					}
					else
					{
					    /*解析第二个ATS下发的远程筛选首次消息*/
						cAtsId = dataBuf[ii];  /*解析ATS ID*/
						ii++;
						if (0U < cAtsId)
						{
							cStation = dataBuf[ii];  /*解析车站编号*/
							ii++;

							wIndex = ShortFromChar(&dataBuf[ii]);  /*解析操作中编号*/
							ii += 2U;

							if (0U < wIndex)
							{
								cAtsSendRcId = dataBuf[ii];  /*解析RC ID*/
								ii++;
								if (cAtsSendRcId == chLocalId)
								{
									dwTime = LongFromChar(&dataBuf[ii]);  /*解析一次命令请求时间*/
									ii += 4U;

									cTrainNum = dataBuf[ii];
									ii++;
									if ((0U < cTrainNum) && (ATS_GATEWAY_CI_TRAIN_MAX > cTrainNum))
									{
										for (chTrainIndex = 0U; chTrainIndex < cTrainNum; chTrainIndex++)
										{
											strTrainInfo[chTrainIndex].dwTrainId = LongFromChar(&dataBuf[ii]);
											ii += 4U;
											if ((0U == strTrainInfo[chTrainIndex].dwTrainId)
												|| (UINT32_MAX == strTrainInfo[chTrainIndex].dwTrainId))
											{
												debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Train Id[%d] Error\n", MSG_TYPE_REQUEST_FIRST, strTrainInfo[chTrainIndex].dwTrainId);
												chRtn = CI_ERROR;
											}
											else
											{
												; /*DO NOTHING*/
											}

											strTrainInfo[chTrainIndex].wLgcId = ShortFromChar(&dataBuf[ii]);
											ii += 2U;

											if ((0U == strTrainInfo[chTrainIndex].wLgcId)
												|| (UINT16_MAX == strTrainInfo[chTrainIndex].wLgcId))
											{
												debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse LogSec Id[%d] Error\n", MSG_TYPE_REQUEST_FIRST, strTrainInfo[chTrainIndex].wLgcId);
												chRtn = CI_ERROR;
											}
											else
											{
												; /*DO NOTHING*/
											}

											if (CI_SUCCESS == chRtn)
											{
												; /*不处理*/
											}
											else
											{
												break;
											}
										}
									}
									else
									{
										debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Train Num[%d] Error\n", MSG_TYPE_REQUEST_FIRST, cTrainNum);
										chRtn = CI_ERROR;
									}
								}
								else
								{
									debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Rc Id[%d] Error\n", MSG_TYPE_REQUEST_FIRST, cAtsSendRcId);
									chRtn = CI_ERROR;
								}
							}
							else
							{
								debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse WorkStation Id[%d] Error\n", MSG_TYPE_REQUEST_FIRST, wIndex);
								chRtn = CI_ERROR;
							}
						}
						else
						{
							debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Ats Id[%d] Error\n", MSG_TYPE_REQUEST_FIRST, cAtsId);
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strSndAtsCfmFst.chFlag = FLAG_SET;
							g_strSndAtsCfmFst.chTiocId = cAtsSendRcId;
							g_strSndAtsCfmFst.chStation = cStation;
							g_strSndAtsCfmFst.wIndex = wIndex;
							g_strSndAtsCfmFst.dwTime = dwTime;
							g_strSndAtsCfmFst.chOpStatus = CONFIRM_FIRST_OTHER_DEV_OP;  /*反馈其它操作站站操作中*/

							/*计算CRC*/
							szCrcTmp[jj] = cAtsId;
							jj++;
							LongToChar(dwTime, &szCrcTmp[jj]);
							jj += 4U;
							szCrcTmp[jj] = cTrainNum;
							jj++;
							for (chTrainIndex = 0U; chTrainIndex < cTrainNum; chTrainIndex++)
							{
								LongToChar(strTrainInfo[chTrainIndex].dwTrainId, &szCrcTmp[jj]);
								jj += 4U;
								ShortToChar(strTrainInfo[chTrainIndex].wLgcId, &szCrcTmp[jj]);
								jj += 2U;
							}
							g_strSndAtsCfmFst.dwCrc32 = Tioc_CommonCrc32(szCrcTmp, jj);
						}
						else
						{
							; /*DO NOTHING*/
						}
					}
					break;
				}
				case MSG_TYPE_REQUEST_SECOND:/* 远程筛选二次消息 */
				{

					g_strAtsMsgSnd.dwCycle = Get2oo2CurCycleNum();
					g_strAtsMsgSnd.chAtsId = dataBuf[ii++];
					if (0U < g_strAtsMsgSnd.chAtsId)
					{
						;
					}
					else
					{
						chRtn = CI_ERROR;
					}

					if (CI_SUCCESS==chRtn)
					{
						g_strAtsMsgSnd.chStation = dataBuf[ii++];
						g_strAtsMsgSnd.wIndex = ShortFromChar(&dataBuf[ii]);
						ii += 2U;
						if (0U < g_strAtsMsgSnd.wIndex)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}

					if (CI_SUCCESS==chRtn)
					{
						g_strAtsMsgSnd.chTiocId = dataBuf[ii++];
						if (g_strAtsMsgSnd.chTiocId == chLocalId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsMsgSnd.dwTime = LongFromChar(&dataBuf[ii]);
						ii += 4u;
						g_strAtsMsgSnd.chTrainNum = dataBuf[ii++];
						if ((0U < g_strAtsMsgSnd.chTrainNum) && (ATS_GATEWAY_CI_TRAIN_MAX > g_strAtsMsgSnd.chTrainNum))
						{
							for (chTrainIndex = 0u; chTrainIndex < g_strAtsMsgSnd.chTrainNum; chTrainIndex++)
							{
								g_strAtsMsgSnd.strTrainInfo[chTrainIndex].dwTrainId = LongFromChar(&dataBuf[ii]);
								ii += 4u;
								g_strAtsMsgSnd.strTrainInfo[chTrainIndex].wLgcId = ShortFromChar(&dataBuf[ii]);
								ii += 2u;
								if ((0U == g_strAtsMsgSnd.strTrainInfo[chTrainIndex].dwTrainId)
									|| (UINT32_MAX == g_strAtsMsgSnd.strTrainInfo[chTrainIndex].dwTrainId))
								{
									chRtn = CI_ERROR;
								}
								else
								{
									; /*DO NOTHING*/
								}

								if ((0U == g_strAtsMsgSnd.strTrainInfo[chTrainIndex].wLgcId)
									|| (UINT16_MAX == g_strAtsMsgSnd.strTrainInfo[chTrainIndex].wLgcId))
								{
									chRtn = CI_ERROR;
								}
								else
								{
									; /*DO NOTHING*/
								}
								if (CI_SUCCESS == chRtn)
								{
									; /*不处理*/
								}
								else
								{
									break;
								}
							}
						}
						else
						{
							chRtn = CI_ERROR;/*丢包*/
						}
						g_strAtsMsgSnd.dwCrc32 = LongFromChar(&dataBuf[ii]);
						ii += 4u;
					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsMsgSnd.chFlag = FLAG_SET;
					}
					else
					{
						; /*DO NOTHING*/
					}
					break;
				}
				case MSG_TYPE_EA_CANCLE_FIRST:/* 区间疏散取消首次消息 */
				{
					wIndex = ShortFromChar(&dataBuf[ii + 2U]);
					if ((FLAG_SET != g_strAtsEaMsgFst.chFlag) || (g_strAtsEaMsgFst.wIndex == wIndex))
					{
						/*未收到或重复收到同一个ATS的一次命令时，解析第一个ATS下发的取消区间疏散首次消息*/
						g_strAtsEaMsgFst.dwCycle = Get2oo2CurCycleNum();	/* 接收到取消区间疏散消息的周期号 */
						g_strAtsEaMsgFst.chAtsId = dataBuf[ii++];			/* ATS编号 */
						if (0U < g_strAtsEaMsgFst.chAtsId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsEaMsgFst.chStation = dataBuf[ii++];	/* 车站编号 */
							g_strAtsEaMsgFst.wIndex = ShortFromChar(&dataBuf[ii]);	/* 操作站编号 */
							ii += 2U;
							if (0U < g_strAtsEaMsgFst.wIndex)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsEaMsgFst.chTiocId = dataBuf[ii++];	/* TIOC编号 */
							if (g_strAtsEaMsgFst.chTiocId == chLocalId)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsEaMsgFst.dwEaTrainId = LongFromChar(&dataBuf[ii]);	/* 区间疏散列车互联互通编号 */
							ii += 4u;
							if ((0u < g_strAtsEaMsgFst.dwEaTrainId) && (UINT32_MAX > g_strAtsEaMsgFst.dwEaTrainId))
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}

						}
						else
						{
							; /*DO NOTHING*/
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsEaMsgFst.dwTime = LongFromChar(&dataBuf[ii]);	/* 下发消息时间 */
							ii += 4u;

							g_strAtsEaMsgFst.chType = dataBuf[ii];/* 类型 */
							ii++;

							if (ATS_EA_CMD_TYPE_CANCEL == g_strAtsEaMsgFst.chType)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsEaMsgFst.chLine = dataBuf[ii];/* 区域 */
							ii++;
							if ((EA_AREA_ALL == g_strAtsEaMsgFst.chLine) || (EA_AREA_UP == g_strAtsEaMsgFst.chLine) || (EA_AREA_DOWN == g_strAtsEaMsgFst.chLine))
							{
								g_strAtsEaMsgFst.chFlag = FLAG_SET;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							;
						}
					}
					else
					{
						/*解析第二个ATS下发的取消区间疏散首次消息*/
						cAtsId = dataBuf[ii];  /* ATS编号 */
						ii++;
						if (0U < cAtsId)
						{
							cStation = dataBuf[ii]; 	/* 车站编号 */
							ii++;

							wIndex = ShortFromChar(&dataBuf[ii]);  /* 操作站编号 */
							ii += 2U;
							if (0U < wIndex)
							{
								cAtsSendRcId = dataBuf[ii];  /* TIOC编号 */
								ii++;
								if (cAtsSendRcId == chLocalId)
								{
									dwTrainHlhtId = LongFromChar(&dataBuf[ii]);	 /* 区间疏散列车互联互通编号 */
									ii += 4U;
									if ((0U < dwTrainHlhtId) && (UINT32_MAX > dwTrainHlhtId))
									{
										dwTime = LongFromChar(&dataBuf[ii]);  /* 命令下发消息时间 */
										ii += 4U;

										cCmdType = dataBuf[ii];  /* 类型 */
										ii++;
										if (ATS_EA_CMD_TYPE_CANCEL == cCmdType)
										{
											cLineAttr = dataBuf[ii];/* 线路属性 */
											ii++;
											if ((EA_AREA_ALL == cLineAttr) || (EA_AREA_UP == cLineAttr) || (EA_AREA_DOWN == cLineAttr))
											{
												;
											}
											else
											{
												debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Line Attr[%d] Error\n", MSG_TYPE_EA_CANCLE_FIRST, cLineAttr);
												chRtn = CI_ERROR;
											}
										}
										else
										{
											debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Cmd Type[%d] Error\n", MSG_TYPE_EA_CANCLE_FIRST, cCmdType);
											chRtn = CI_ERROR;
										}
									}
									else
									{
										debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Train Id[%d] Error\n", MSG_TYPE_EA_CANCLE_FIRST, dwTrainHlhtId);
										chRtn = CI_ERROR;
									}
								}
								else
								{
									debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Rc Id[%d] Error\n", MSG_TYPE_EA_CANCLE_FIRST, cAtsSendRcId);
									chRtn = CI_ERROR;
								}
							}
							else
							{
								debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse WorkStation Id[%d] Error\n", MSG_TYPE_EA_CANCLE_FIRST, wIndex);
								chRtn = CI_ERROR;
							}
						}
						else
						{
							debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Ats Id[%d] Error\n", MSG_TYPE_EA_CANCLE_FIRST, cAtsId);
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strSndAtsEaCfmFst.chFlag = FLAG_SET;
							g_strSndAtsEaCfmFst.chTiocId = cAtsSendRcId;
							g_strSndAtsEaCfmFst.chStation = cStation;
							g_strSndAtsEaCfmFst.wIndex = wIndex;
							g_strSndAtsEaCfmFst.dwTime = dwTime;
							g_strSndAtsEaCfmFst.chOpStatus = CONFIRM_FIRST_OTHER_DEV_OP;  /*反馈其它操作站站操作中*/

							/*计算CRC*/
							szCrcTmp[jj] = cAtsId;
							jj++;
							szCrcTmp[jj] = cStation;
							jj++;
							ShortToChar(wIndex, &szCrcTmp[jj]);
							jj += 2U;
							LongToChar(dwTrainHlhtId, &szCrcTmp[jj]);
							jj += 4U;
							LongToChar(dwTime, &szCrcTmp[jj]);
							jj += 4U;
							szCrcTmp[jj] = cCmdType;
							jj++;
							szCrcTmp[jj] = cLineAttr;
							jj++;
							g_strSndAtsEaCfmFst.dwCrc32 = Tioc_CommonCrc32(szCrcTmp, jj);
						}
						else
						{
							;
						}
					}
					break;
				}
				case MSG_TYPE_EA_CANCLE_SECOND:/* 区间疏散取消二次消息 */
				{
					g_strAtsEaMsgSnd.dwCycle = Get2oo2CurCycleNum();		/* 收到消息周期号 */
					g_strAtsEaMsgSnd.chAtsId = dataBuf[ii++];				/* ATS编号 */
					if (0U < g_strAtsEaMsgSnd.chAtsId)
					{
						;
					}
					else
					{
						chRtn = CI_ERROR;
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsEaMsgSnd.chStation = dataBuf[ii++];		/* 车站编号 */
						g_strAtsEaMsgSnd.wIndex = ShortFromChar(&dataBuf[ii]);	/* 操作站编号 */
						ii += 2U;
						if (0U < g_strAtsEaMsgSnd.wIndex)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsEaMsgSnd.chTiocId = dataBuf[ii++];		/* TIOC编号 */
						if (g_strAtsEaMsgSnd.chTiocId == chLocalId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsEaMsgSnd.dwEaTrainId = LongFromChar(&dataBuf[ii]);	/* 疏散列车互联互通编号 */
						ii += 4u;
						if ((0u < g_strAtsEaMsgSnd.dwEaTrainId) && (UINT32_MAX > g_strAtsEaMsgSnd.dwEaTrainId))
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}

					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsEaMsgSnd.dwTime = LongFromChar(&dataBuf[ii]);		/* 下发时间 */
						ii += 4u;

						g_strAtsEaMsgSnd.chType = dataBuf[ii];/* 命令类型 */
						ii++;

						if (ATS_EA_CMD_TYPE_CANCEL == g_strAtsEaMsgSnd.chType)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsEaMsgSnd.chLine = dataBuf[ii];	/* 要取消的区域 */
						ii++;
						if ((EA_AREA_ALL == g_strAtsEaMsgSnd.chLine) || (EA_AREA_UP == g_strAtsEaMsgSnd.chLine) || (EA_AREA_DOWN == g_strAtsEaMsgSnd.chLine))
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						;
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsEaMsgSnd.dwCrc32 = LongFromChar(&dataBuf[ii]);		/* CRC值 */
						ii += 4u;

						g_strAtsEaMsgSnd.chFlag = FLAG_SET;
					}
					else
					{
						;
					}

					break;
				}
				case MSG_TYPE_WLB_SET_FIRST:	/* 全线列车紧急制动一次命令 */
				{
					wIndex = ShortFromChar(&dataBuf[ii + 2U]);
					if ((FLAG_SET != g_strAtsWlbMsgFst.chFlag) || (g_strAtsWlbMsgFst.wIndex == wIndex))
					{
						/*未收到或重复收到同一个ATS的一次命令时，解析第一个ATS下发的全线紧急制动首次消息*/
						g_strAtsWlbMsgFst.dwCycle = Get2oo2CurCycleNum();	/* 接收到全线列车紧急制动命令周期号 */
						g_strAtsWlbMsgFst.chAtsId = dataBuf[ii++];			/* ATS编号 */
						if (0U < g_strAtsWlbMsgFst.chAtsId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsWlbMsgFst.chStation = dataBuf[ii++];	/* 车站编号 */
							g_strAtsWlbMsgFst.wIndex = ShortFromChar(&dataBuf[ii]);	/* 操作站编号 */
							ii += 2U;
							if (0U < g_strAtsWlbMsgFst.wIndex)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsWlbMsgFst.chTiocId = dataBuf[ii++];	/* TIOC编号 */
							if (g_strAtsWlbMsgFst.chTiocId == chLocalId)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsWlbMsgFst.chBrakeType = dataBuf[ii++]; /* 制动类型：集中区制动或物理区段制动 */
							if ((WLB_TYPE_RC == g_strAtsWlbMsgFst.chBrakeType) || (WLB_TYPE_PHYSEC == g_strAtsWlbMsgFst.chBrakeType))
							{
								; /* 制动类型合法 */
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /* DO NOTHING */
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsWlbMsgFst.chBrakeCount = dataBuf[ii++]; /* 数量 */
							if (1u == g_strAtsWlbMsgFst.chBrakeCount)
							{
								; /* 数量合法,仅为1 */
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /* DO NOTHING */
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsWlbMsgFst.wBrakeIndex = ShortFromChar(&dataBuf[ii]); /* ID */
							ii += 2u;

							chRtn = WlbUrgentIdCheck(g_strAtsWlbMsgFst.chBrakeType, g_strAtsWlbMsgFst.wBrakeIndex);  /*校验紧急ID是否合法*/
						}
						else
						{
							; /* DO NOTHING */
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsWlbMsgFst.dwTime = LongFromChar(&dataBuf[ii]);	/* 下发消息时间 */
							ii += 4u;

							g_strAtsWlbMsgFst.chType = dataBuf[ii];/* 命令类型 */
							ii++;

							if ((MSG_TYPE_WLB_SET == g_strAtsWlbMsgFst.chType) || (MSG_TYPE_WLB_CANCEL == g_strAtsWlbMsgFst.chType))
							{
								g_strAtsWlbMsgFst.chFlag = FLAG_SET;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							;
						}
					}
					else
					{
					    /*解析第二个ATS下发的全线紧急制动首次消息*/
						cAtsId = dataBuf[ii];  /* ATS编号 */
						ii++;
						if (0U < cAtsId)
						{
							cStation = dataBuf[ii];  /* 车站编号 */
							ii++;

							wIndex = ShortFromChar(&dataBuf[ii]);  /* 操作站编号 */
							ii += 2U;
							if (0U < wIndex)
							{
								cAtsSendRcId = dataBuf[ii];  /* TIOC编号 */
								ii++;
								if (cAtsSendRcId == chLocalId)
								{
									cDevType = dataBuf[ii];  /* 制动类型：集中区制动或物理区段制动 */
									ii++;
									if ((WLB_TYPE_RC == cDevType) || (WLB_TYPE_PHYSEC == cDevType))
									{
										cDevNum = dataBuf[ii];  /* 数量 */
										ii++;
										if (1U == cDevNum)
										{
											wDevId = ShortFromChar(&dataBuf[ii]); /* ID */
											ii += 2U;

											chRtn = WlbUrgentIdCheck(cDevType, wDevId);  /*校验紧急ID是否合法*/
											if (CI_SUCCESS == chRtn)
											{
												dwTime = LongFromChar(&dataBuf[ii]);  /* 下发消息时间 */
												ii += 4U;

												cCmdType = dataBuf[ii];  /* 命令类型 */
												ii++;
												if ((MSG_TYPE_WLB_SET == cCmdType) || (MSG_TYPE_WLB_CANCEL == cCmdType))
												{
													;
												}
												else
												{
													debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Cmd Type[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, cCmdType);
													chRtn = CI_ERROR;
												}
											}
											else
											{
												debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Dev Id[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, wDevId);
												chRtn = CI_ERROR;
											}
										}
										else
										{
											debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Dev Num[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, cDevNum);
											chRtn = CI_ERROR;
										}
									}
									else
									{
										debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Dev Type[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, cDevType);
										chRtn = CI_ERROR;
									}
								}
								else
								{
									debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Rc Id[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, cAtsSendRcId);
									chRtn = CI_ERROR;
								}
							}
							else
							{
								debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse WorkStation Id[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, wIndex);
								chRtn = CI_ERROR;
							}
						}
						else
						{
							debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Ats Id[%d] Error\n", MSG_TYPE_WLB_SET_FIRST, cAtsId);
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strSndAtsWlbCfmFst.chFlag = FLAG_SET;
							g_strSndAtsWlbCfmFst.chTiocId = cAtsSendRcId;
							g_strSndAtsWlbCfmFst.chStation = cStation;
							g_strSndAtsWlbCfmFst.wIndex = wIndex;
							g_strSndAtsWlbCfmFst.dwTime = dwTime;
							g_strSndAtsWlbCfmFst.chOpStatus = CONFIRM_FIRST_OTHER_DEV_OP;  /*反馈其它操作站站操作中*/

							/*计算CRC*/
							szCrcTmp[jj] = cAtsId;
							jj++;
							szCrcTmp[jj] = cStation;
							jj++;
							ShortToChar(wIndex, &szCrcTmp[jj]);
							jj += 2U;
							szCrcTmp[jj] = cDevType;
							jj++;
							szCrcTmp[jj] = cDevNum;
							jj++;
							ShortToChar(wDevId, &szCrcTmp[jj]);
							jj += 2U;
							LongToChar(dwTime, &szCrcTmp[jj]);
							jj += 4U;
							szCrcTmp[jj] = cCmdType;
							jj++;
							g_strSndAtsWlbCfmFst.dwCrc32 = Tioc_CommonCrc32(szCrcTmp, jj);
						}
						else
						{
							;
						}
					}
					break;
				}
				case MSG_TYPE_WLB_SET_SECOND:	/* 全线列车紧急制动二次命令 */
				{
					g_strAtsWlbMsgSnd.dwCycle = Get2oo2CurCycleNum();		/* 收到消息周期号 */
					g_strAtsWlbMsgSnd.chAtsId = dataBuf[ii++];				/* ATS编号 */
					if (0U < g_strAtsWlbMsgSnd.chAtsId)
					{
						;
					}
					else
					{
						chRtn = CI_ERROR;
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.chStation = dataBuf[ii++];		/* 车站编号 */
						g_strAtsWlbMsgSnd.wIndex = ShortFromChar(&dataBuf[ii]);		/* 操作站编号 */
						ii += 2U;
						if (0U < g_strAtsWlbMsgSnd.wIndex)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.chTiocId = dataBuf[ii++];		/* TIOC编号 */
						if (g_strAtsWlbMsgSnd.chTiocId == chLocalId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}
					
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.chBrakeType = dataBuf[ii++]; /* 制动类型 */
						if ((WLB_TYPE_RC == g_strAtsWlbMsgSnd.chBrakeType) || (WLB_TYPE_PHYSEC == g_strAtsWlbMsgSnd.chBrakeType))
						{
							; /* 制动类型合法 */
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /* DO NOTHING */
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.chBrakeCount = dataBuf[ii++]; /* 数量 */
						if (1u == g_strAtsWlbMsgSnd.chBrakeCount)
						{
							; /* 数量合法,仅为1 */
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /* DO NOTHING */
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.wBrakeIndex = ShortFromChar(&dataBuf[ii]); /* ID */
						ii += 2u;

						chRtn = WlbUrgentIdCheck(g_strAtsWlbMsgSnd.chBrakeType, g_strAtsWlbMsgSnd.wBrakeIndex);  /*校验紧急ID是否合法*/
					}
					else
					{
						; /* DO NOTHING */
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.dwTime = LongFromChar(&dataBuf[ii]);		/* 下发时间 */
						ii += 4u;

						g_strAtsWlbMsgSnd.chType = dataBuf[ii];/* 命令类型 */
						ii++;

						if (MSG_TYPE_WLB_CANCEL == g_strAtsWlbMsgSnd.chType)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsWlbMsgSnd.dwCrc32 = LongFromChar(&dataBuf[ii]);		/* CRC值 */
						ii += 4u;

						g_strAtsWlbMsgSnd.chFlag = FLAG_SET;
					}
					else
					{
						;
					}

					break;
				}
				case MSG_TYPE_DA_CANCLE_FIRST:/* 脱轨防护区取消首次消息 */
				{
					wIndex = ShortFromChar(&dataBuf[ii + 2U]);
					if ((FLAG_SET != g_strAtsDaMsgFst.chFlag) || (g_strAtsDaMsgFst.wIndex == wIndex))
					{
						/*未收到或重复收到同一个ATS的一次命令时，解析第一个ATS下发的取消脱轨防护首次消息*/
						g_strAtsDaMsgFst.dwCycle = Get2oo2CurCycleNum();	/* 接收到取消脱轨防护区消息的周期号 */
						g_strAtsDaMsgFst.chAtsId = dataBuf[ii++];			/* ATS编号 */
						if (0U < g_strAtsDaMsgFst.chAtsId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsDaMsgFst.chStation = dataBuf[ii++];	/* 车站编号 */
							g_strAtsDaMsgFst.wIndex = ShortFromChar(&dataBuf[ii]);	/* 操作站编号 */
							ii += 2U;
							if (0U < g_strAtsDaMsgFst.wIndex)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsDaMsgFst.chTiocId = dataBuf[ii++];	/* TIOC编号 */
							if (g_strAtsDaMsgFst.chTiocId == chLocalId)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							; /*DO NOTHING*/
						}
						if (CI_SUCCESS == chRtn)
						{
							g_strAtsDaMsgFst.dwDaTrainId = LongFromChar(&dataBuf[ii]);	/* 脱轨列车互联互通编号 */
							ii += 4u;
							if ((0u < g_strAtsDaMsgFst.dwDaTrainId) && (UINT32_MAX > g_strAtsDaMsgFst.dwDaTrainId))
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}

						}
						else
						{
							; /*DO NOTHING*/
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsDaMsgFst.dwTime = LongFromChar(&dataBuf[ii]);	/* 下发消息时间 */
							ii += 4u;

							g_strAtsDaMsgFst.chType = dataBuf[ii];/* 类型 */
							ii++;

							if (ATS_DA_CMD_TYPE_CANCEL == g_strAtsDaMsgFst.chType)
							{
								;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strAtsDaMsgFst.chLine = dataBuf[ii];/* 区域 */
							ii++;
							if ((DA_AREA_ALL == g_strAtsDaMsgFst.chLine) || (DA_AREA_UP == g_strAtsDaMsgFst.chLine) || (DA_AREA_DOWN == g_strAtsDaMsgFst.chLine))
							{
								g_strAtsDaMsgFst.chFlag = FLAG_SET;
							}
							else
							{
								chRtn = CI_ERROR;
							}
						}
						else
						{
							;
						}
					}
					else
					{
						/*解析第二个ATS下发的取消脱轨防护首次消息*/
						cAtsId = dataBuf[ii];  /* ATS编号 */
						ii++;
						if (0U < cAtsId)
						{
							cStation = dataBuf[ii];  /* 车站编号 */
							ii++;

							wIndex = ShortFromChar(&dataBuf[ii]);  /* 操作站编号 */
							ii += 2U;
							if (0U < wIndex)
							{
								cAtsSendRcId = dataBuf[ii];  /* TIOC编号 */
								ii++;
								if (cAtsSendRcId == chLocalId)
								{
									dwTrainHlhtId = LongFromChar(&dataBuf[ii]);  /* 脱轨列车互联互通编号 */
									ii += 4U;
									if ((0U < dwTrainHlhtId) && (UINT32_MAX > dwTrainHlhtId))
									{
										dwTime = LongFromChar(&dataBuf[ii]);  /* 下发消息时间 */
										ii += 4U;

										cCmdType = dataBuf[ii];  /* 类型 */
										ii++;
										if (ATS_DA_CMD_TYPE_CANCEL == cCmdType)
										{
											cLineAttr = dataBuf[ii];  /* 线路属性 */
											ii++;
											if ((DA_AREA_ALL == cLineAttr) || (DA_AREA_UP == cLineAttr) || (DA_AREA_DOWN == cLineAttr))
											{
												;
											}
											else
											{
												debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Line Attr[%d] Error\n", MSG_TYPE_DA_CANCLE_FIRST, cLineAttr);
												chRtn = CI_ERROR;
											}
										}
										else
										{
											debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Cmd Type[%d] Error\n", MSG_TYPE_DA_CANCLE_FIRST, cCmdType);
											chRtn = CI_ERROR;
										}
									}
									else
									{
										debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Train Id[%d] Error\n", MSG_TYPE_DA_CANCLE_FIRST, dwTrainHlhtId);
										chRtn = CI_ERROR;
									}
								}
								else
								{
									debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Rc Id[%d] Error\n", MSG_TYPE_DA_CANCLE_FIRST, cAtsSendRcId);
									chRtn = CI_ERROR;
								}
							}
							else
							{
								debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse WorkStation Id[%d] Error\n", MSG_TYPE_DA_CANCLE_FIRST, wIndex);
								chRtn = CI_ERROR;
							}
						}
						else
						{
							debug_infor_printf((const)"ParseGateWayToCiDataFrame: Cmd Id[%d] Parse Ats Id[%d] Error\n", MSG_TYPE_DA_CANCLE_FIRST, cAtsId);
							chRtn = CI_ERROR;
						}

						if (CI_SUCCESS == chRtn)
						{
							g_strSndAtsDaCfmFst.chFlag = FLAG_SET;
							g_strSndAtsDaCfmFst.chTiocId = cAtsSendRcId;
							g_strSndAtsDaCfmFst.chStation = cStation;
							g_strSndAtsDaCfmFst.wIndex = wIndex;
							g_strSndAtsDaCfmFst.dwTime = dwTime;
							g_strSndAtsDaCfmFst.chOpStatus = CONFIRM_FIRST_OTHER_DEV_OP;  /*反馈其它操作站站操作中*/

							/*计算CRC*/
							szCrcTmp[jj] = cAtsId;
							jj++;
							szCrcTmp[jj] = cStation;
							jj++;
							ShortToChar(wIndex, &szCrcTmp[jj]);
							jj += 2U;
							LongToChar(dwTrainHlhtId, &szCrcTmp[jj]);
							jj += 4U;
							LongToChar(dwTime, &szCrcTmp[jj]);
							jj += 4U;
							szCrcTmp[jj] = cCmdType;
							jj++;
							szCrcTmp[jj] = cLineAttr;
							jj++;
							g_strSndAtsDaCfmFst.dwCrc32 = Tioc_CommonCrc32(szCrcTmp, jj);
						}
						else
						{
							;
						}
					}
					break;
				}
				case MSG_TYPE_DA_CANCLE_SECOND:/* 脱轨防护区取消二次消息 */
				{
					g_strAtsDaMsgSnd.dwCycle = Get2oo2CurCycleNum();		/* 收到消息周期号 */
					g_strAtsDaMsgSnd.chAtsId = dataBuf[ii++];				/* ATS编号 */
					if (0U < g_strAtsDaMsgSnd.chAtsId)
					{
						;
					}
					else
					{
						chRtn = CI_ERROR;
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsDaMsgSnd.chStation = dataBuf[ii++];		/* 车站编号 */
						g_strAtsDaMsgSnd.wIndex = ShortFromChar(&dataBuf[ii]);		/* 操作站编号 */
						ii += 2U;
						if (0U < g_strAtsDaMsgSnd.wIndex)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsDaMsgSnd.chTiocId = dataBuf[ii++];		/* TIOC编号 */
						if (g_strAtsDaMsgSnd.chTiocId == chLocalId)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsDaMsgSnd.dwDaTrainId = LongFromChar(&dataBuf[ii]);	/* 疏散列车互联互通编号 */
						ii += 4u;
						if ((0u < g_strAtsDaMsgSnd.dwDaTrainId) && (UINT32_MAX > g_strAtsDaMsgSnd.dwDaTrainId))
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}

					}
					else
					{
						; /*DO NOTHING*/
					}
					if (CI_SUCCESS == chRtn)
					{
						g_strAtsDaMsgSnd.dwTime = LongFromChar(&dataBuf[ii]);		/* 下发时间 */
						ii += 4u;

						g_strAtsDaMsgSnd.chType = dataBuf[ii];/* 命令类型 */
						ii++;

						if (ATS_DA_CMD_TYPE_CANCEL == g_strAtsDaMsgSnd.chType)
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						; /*DO NOTHING*/
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsDaMsgSnd.chLine = dataBuf[ii];	/* 要取消的区域 */
						ii++;
						if ((DA_AREA_ALL == g_strAtsDaMsgSnd.chLine) || (DA_AREA_UP == g_strAtsDaMsgSnd.chLine) || (DA_AREA_DOWN == g_strAtsDaMsgSnd.chLine))
						{
							;
						}
						else
						{
							chRtn = CI_ERROR;
						}
					}
					else
					{
						;
					}

					if (CI_SUCCESS == chRtn)
					{
						g_strAtsDaMsgSnd.dwCrc32 = LongFromChar(&dataBuf[ii]);		/* CRC值 */
						ii += 4u;

						g_strAtsDaMsgSnd.chFlag = FLAG_SET;
					}
					else
					{
						;
					}

					break;
				}
				default:
				{
					chRtn = CI_ERROR;
					break;
				}
				}
				if (wMsgLen != (ii - wMsgLenCount))
				{
					chRtn = CI_ERROR;/*丢包*/
				}
				else
				{
					/*继续循环*/
				}
				if (CI_ERROR == chRtn)
				{
					break;
				}
				else
				{
					;
				}
			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chRtn)
	{
		; /*不处理*/
	}
	else
	{
		ClearAtsMsgFirst();
		ClearAtsMsgSecond();
		ClearAtsEaMsgFirst();
		ClearAtsEaMsgSecond();
		ClearAtsWlbMsgFirst();
		ClearAtsWlbMsgSecond();
		ClearAtsDaMsgFirst();
		ClearAtsDaMsgSecond();
		ClearSndAtsScreenFstCfmMsg();
		ClearSndAtsEaFstCfmMsg();
		ClearSndAtsWlbFstCfmMsg();
		ClearSndAtsDaFstCfmMsg();
	}

	return chRtn;
}

/**
* @brief 获取远程筛选ATS首次消息
* @param 无
* @return 远程筛选ATS首次消息
*/
AtsScreenMsgFstStru * GetAtsMsgFst(void)
{
	return &g_strAtsMsgFst;
}

/**
* @brief 获取远程筛选ATS二次消息
* @param 无
* @return 远程筛选ATS二次消息
*/
AtsScreenMsgSndStru * GetAtsMsgSnd(void)
{
	return &g_strAtsMsgSnd;
}

/**
* @brief 获取远程筛选首次确认消息
* @param 无
* @return 远程筛选首次确认消息
*/
AtsMsgCfmStru * GetAtsCfmFst(void)
{
	return &g_strAtsCfmFst;
}

/**
* @brief 获取远程筛选二次确认消息
* @param 无
* @return 远程筛选二次确认消息
*/
AtsMsgCfmStru * GetAtsCfmSnd(void)
{
	return &g_strAtsCfmSnd;
}

/**
* @brief 清除1次ATS筛选信息
* @param void
* @return void
*/
void ClearAtsMsgFirst(void)
{
	(void)CommonMemSet((void*)&g_strAtsMsgFst, (UINT32)sizeof(g_strAtsMsgFst), (UINT8)0U, (UINT32)sizeof(g_strAtsMsgFst));
}

/**
* @brief 清除2次ATS筛选信息
* @param void
* @return void
*/
void ClearAtsMsgSecond(void)
{
	(void)CommonMemSet((void*)&g_strAtsMsgSnd, (UINT32)sizeof(g_strAtsMsgSnd), (UINT8)0U, (UINT32)sizeof(g_strAtsMsgSnd));
}

/**
* @brief 获取ATS取消区间疏散首次消息
* @param 无
* @return ATS取消区间疏散首次消息
*/
AtsEaMsgStru * GetAtsEaMsgFst(void)
{
	return &g_strAtsEaMsgFst;
}

/**
* @brief 获取ATS取消区间疏散二次消息
* @param 无
* @return ATS取消区间疏散二次消息
*/
AtsEaMsgStru * GetAtsEaMsgSnd(void)
{
	return &g_strAtsEaMsgSnd;
}

/**
* @brief 获取ATS取消区间疏散首次确认
* @param 无
* @return ATS取消区间疏散首次确认
*/
AtsMsgCfmStru * GetAtsEaCfmFst(void)
{
	return &g_strAtsEaCfmFst;
}

/**
* @brief 获取ATS取消区间疏散二次确认
* @param 无
* @return ATS取消区间疏散二次确认
*/
AtsMsgCfmStru * GetAtsEaCfmSnd(void)
{
	return &g_strAtsEaCfmSnd;
}

/**
* @brief 清除1次ATS区间疏散信息
* @param void
* @return void
*/
void ClearAtsEaMsgFirst(void)
{
	(void)CommonMemSet((void*)&g_strAtsEaMsgFst, (UINT32)sizeof(g_strAtsEaMsgFst), (UINT8)0U, (UINT32)sizeof(g_strAtsEaMsgFst));
}

/**
* @brief 清除2次ATS区间疏散信息
* @param void
* @return void
*/
void ClearAtsEaMsgSecond(void)
{
	(void)CommonMemSet((void*)&g_strAtsEaMsgSnd, (UINT32)sizeof(g_strAtsEaMsgSnd), (UINT8)0U, (UINT32)sizeof(g_strAtsEaMsgSnd));
}

/**
* @brief 获取ATS设置/取消全线列车紧急制动首次消息
* @param 无
* @return ATS设置/取消区间疏散首次消息
*/
AtsWlbMsgStru * GetAtsWlbMsgFst(void)
{
	return &g_strAtsWlbMsgFst;
}

/**
* @brief 获取ATS取消全线列车紧急制动二次消息
* @param 无
* @return ATS取消全线列车紧急制动二次消息
*/
AtsWlbMsgStru * GetAtsWlbMsgSnd(void)
{
	return &g_strAtsWlbMsgSnd;
}

/**
* @brief 获取ATS设置/取消全线列车紧急制动首次确认
* @param 无
* @return ATS设置/取消全线列车紧急制动首次确认
*/
AtsMsgCfmStru * GetAtsWlbCfmFst(void)
{
	return &g_strAtsWlbCfmFst;
}

/**
* @brief 获取ATS取消全线列车紧急制动二次确认
* @param 无
* @return ATS取消全线列车紧急制动二次确认
*/
AtsMsgCfmStru * GetAtsWlbCfmSnd(void)
{
	return &g_strAtsWlbCfmSnd;
}

/**
* @brief 清除1次ATS设置/取消全线列车紧急制动信息
* @param void
* @return void
*/
void ClearAtsWlbMsgFirst(void)
{
	(void)CommonMemSet((void*)&g_strAtsWlbMsgFst, (UINT32)sizeof(g_strAtsWlbMsgFst), (UINT8)0U, (UINT32)sizeof(g_strAtsWlbMsgFst));
}

/**
* @brief 清除2次ATS取消全线列车紧急制动信息
* @param void
* @return void
*/
void ClearAtsWlbMsgSecond(void)
{
	(void)CommonMemSet((void*)&g_strAtsWlbMsgSnd, (UINT32)sizeof(g_strAtsWlbMsgSnd), (UINT8)0U, (UINT32)sizeof(g_strAtsWlbMsgSnd));
}

/**
* @brief 获取ATS取消脱轨防护区首次消息
* @param 无
* @return ATS取消脱轨防护区首次消息
*/
AtsDaMsgStru * GetAtsDaMsgFst(void)
{
	return &g_strAtsDaMsgFst;
}

/**
* @brief 获取ATS取消脱轨防护区二次消息
* @param 无
* @return ATS取消脱轨防护区二次消息
*/
AtsDaMsgStru * GetAtsDaMsgSnd(void)
{
	return &g_strAtsDaMsgSnd;
}

/**
* @brief 获取ATS取消脱轨防护区首次确认
* @param 无
* @return ATS取消脱轨防护区首次确认
*/
AtsMsgCfmStru * GetAtsDaCfmFst(void)
{
	return &g_strAtsDaCfmFst;
}

/**
* @brief 获取ATS取消脱轨防护区二次确认
* @param 无
* @return ATS取消脱轨防护区二次确认
*/
AtsMsgCfmStru * GetAtsDaCfmSnd(void)
{
	return &g_strAtsDaCfmSnd;
}

/**
* @brief 清除1次ATS取消脱轨防护区信息
* @param void
* @return void
*/
void ClearAtsDaMsgFirst(void)
{
	(void)CommonMemSet((void*)&g_strAtsDaMsgFst, (UINT32)sizeof(g_strAtsDaMsgFst), (UINT8)0U, (UINT32)sizeof(g_strAtsDaMsgFst));
}

/**
* @brief 清除2次ATS取消脱轨防护区信息
* @param void
* @return void
*/
void ClearAtsDaMsgSecond(void)
{
	(void)CommonMemSet((void*)&g_strAtsDaMsgSnd, (UINT32)sizeof(g_strAtsDaMsgSnd), (UINT8)0U, (UINT32)sizeof(g_strAtsDaMsgSnd));
}

/**
* @brief 组TIOC到网关数据
* @param 无
* @return CI_ERROR失败；CI_SUCCESS成功
*/
UINT8 PackTiocToGateWayData(const UINT8 deviceId, const UINT8 targetDevType)
{
	UINT8 szToGateWayDataBuf[CI_TO_ATS_DATA_LEN_MAX] = { 0u };
	UINT16 ii = 0u;
	UINT16 jj = 0U;
	UINT16 wMsgNumIndex = 0u;
	UINT8 chRtn = CI_ERROR;
	UINT32 dwDataVer = 0u;
	UINT8 chLocalId = GetSystemParaLocalCiId();
	UINT16 wMsgLenIndex = 0u;
	UINT8 chMsgNum = 0u;
	UINT8 chAtsScreenNum = 0u;
	UINT16 wTrainId = 0u;
	UINT16 wLgcId = 0u;
	UINT8 chScreenType = 0u;
	UINT8 chTrainIndex = 0u;
	UINT32 dwTrainId = 0u;
	UINT16 wMsgLen = 0u;
	UINT16 wDstDevId = 0u;
	UINT16 wTrainLgcId = 0u;
	UINT8 chEaNum = 0u;
	UINT16 wEaTrainid = 0u;
	UINT32 dwEaTrainHlhtId = 0u;
	UINT8 chEaLgcNum = 0u;
	UINT16 * pEaLgcId = NULL;
	UINT8 chEaIndex = 0u;
	UINT8 chEaLgcIndex = 0u;
	UINT8 chEaBuidFlag = 0u;
	UINT8 chEaSendNum = 0u;
	UINT16 wEaNumIndex = 0u;
	UINT8 chEaSrcId = 0u;
	UINT8 chPaType = 0u;
	UINT8 chEaConfigId = 0u;
	ATSTrainInfoStru strTrainInfo = {0u};             /** 汇报列车信息*/
	UINT8 chWlbState = WLB_SET;
	UINT16 wWlbSum = 0u;
	UINT16 wWlbSumIndex = 0;  /*紧急制动数量索引位置*/
	UINT16 wRcId = 0u;
	UINT16 wPhyCurSum = 0U;  /*本控区物理区段当前数量*/
	UINT16 wPhySecId = 0U;  /*物理区段ID*/
	UINT8 cPhySecAreaUrgentState = PHYSEC_AREA_URGENT_YES;  /*物理区段区域紧急制动状态*/
	UINT8 chEaAreaLineType = 0U;
	UINT8 chTrainPosMonitorState = 0u;/*列车位置监督标志*/
	UINT8 chTrainNvramFlag = 0u;/*列车NVRAM标志*/
	UINT32 dwFlyProtectOverCyc= GetFlyProtectOverCyc();  /*飞车*/
	UINT8 FlyProtectTrainNum;
	UINT8 TrainFlyAxis = 0U; /*飞车计轴*/
	UINT8 chIndex = 0U;
	TrainFlyProtectStru * pFlyData = NULL;

	wRcId = (UINT16)chLocalId;	/* RC编号，不带类型 */

	/* 留出消息条数填充位置 */
	ii++;

	chRtn = GetCiEmapCheckVer(chLocalId, &dwDataVer, targetDevType);
	if (CI_SUCCESS == chRtn)
	{/* 组数据版本 */
		LongToChar(dwDataVer, &szToGateWayDataBuf[ii]);
		ii += 4u;
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chRtn)
	{/* 组协议版本 */
		LongToChar(GATE_WAY_PRTCL_VER, &szToGateWayDataBuf[ii]);
		ii += 4u;
	}
	else
	{
		;
	}
	if (0U == dwFlyProtectOverCyc)
	{
		if (CI_SUCCESS == chRtn)
		{/* 组TIOC汇报给ATS的远程筛选列车信息 */
			szToGateWayDataBuf[ii++] = MSG_TYPE_REPORT;	/* 汇报远程筛选列车信息帧 */
			wMsgLenIndex = ii;							/* 记录帧长度存放下标 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = MSG_TYPE_REPORT;
			ShortToChar(GATE_WAY_APP_PRTCL_VER, &szToGateWayDataBuf[ii]);	/* 应用协议版本号 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
			chAtsScreenNum = GetAtsScreenNum();
			szToGateWayDataBuf[ii++] = chAtsScreenNum;						/* 远程筛选列车数量 */
			for (chTrainIndex = 0u; chTrainIndex < chAtsScreenNum; chTrainIndex++)
			{
				wTrainId = GetAtsScreenTrainIdByIndex(chTrainIndex);
				chRtn = dquDevName2HlhtId(wTrainId, wTrainLgcId, &dwTrainId);
				chScreenType = GetAtsScreenTypeByIndex(chTrainIndex);
				wLgcId = GetAtsScreenLgcIdByIndex(chTrainIndex);
				chTrainPosMonitorState = GetTrainPosMonitorState(wTrainId);
				chTrainNvramFlag = GetTrainNvramPosFlag(wTrainId);

				LongToChar(dwTrainId, &szToGateWayDataBuf[ii]);		/* 列车ID */
				ii += 4u;

				if (TRAIN_SCREEN_TYPE_LU == chScreenType)
				{
					if ((TRAIN_POS_MONITOR_VALID == chTrainPosMonitorState) || (TRAIN_NVRAM_POS_FLAG_NO == chTrainNvramFlag))
					{
						szToGateWayDataBuf[ii++] = TRAIN_SCREEN_TYPE_LU;			/* 远程筛选类别 */
					}
					else
					{
						szToGateWayDataBuf[ii++] = TRAIN_SCREEN_TYPE_POSTION_LOST;			/* 监督位置无效筛选 */
					}
				
				}
				else
				{
					szToGateWayDataBuf[ii++] = chScreenType;			
				}

				ShortToChar(wLgcId, &szToGateWayDataBuf[ii]);		/* 列车所处逻辑区段 */
				ii += 2u;
			}
			wMsgLen = (ii - wMsgLenIndex - 2u);
			ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);	/* 帧长度 */
			chMsgNum++;					/* 消息数量递增 */
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_CONFIRM_FIRST;				/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_CONFIRM_FIRST;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsCfmFst.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsCfmFst.wIndex, &szToGateWayDataBuf[ii]);        /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsCfmFst.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsCfmFst.chOpStatus;			/* 确认结果 */
				LongToChar(g_strAtsCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsCfmFst.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/*组第二个ATS的远程筛选首次确认信息*/
			if (FLAG_SET == g_strSndAtsCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii] = MSG_TYPE_CONFIRM_FIRST;				/* 帧类型 */
				ii++;
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2U;
				szToGateWayDataBuf[ii] = MSG_TYPE_CONFIRM_FIRST;
				ii++;
				szToGateWayDataBuf[ii] = chLocalId;							/* TIOC编号 */
				ii++;
				szToGateWayDataBuf[ii] = g_strSndAtsCfmFst.chStation;			/* 车站编号 */
				ii++;
				ShortToChar(g_strSndAtsCfmFst.wIndex, &szToGateWayDataBuf[ii]);        /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strSndAtsCfmFst.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4U;
				szToGateWayDataBuf[ii] = g_strSndAtsCfmFst.chOpStatus;			/* 确认结果 */
				ii++;
				LongToChar(g_strSndAtsCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4U;
				wMsgLen = (ii - wMsgLenIndex - 2U);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */

				/*组包后清除第二个ATS的确认信息*/
				ClearSndAtsScreenFstCfmMsg();
			}
			else
			{
				;
			}			
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsCfmSnd.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_CONFIRM_SECOND;				/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_CONFIRM_SECOND;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsCfmSnd.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsCfmSnd.wIndex, &szToGateWayDataBuf[ii]);    /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsCfmSnd.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsCfmSnd.chOpStatus;			/* 确认结果 */
				LongToChar(g_strAtsCfmSnd.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsCfmSnd.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/* 组TIOC汇报给ATS的区间疏散信息 */
			szToGateWayDataBuf[ii++] = MSG_TYPE_EA_REPORT;	/* 区间疏散汇报消息 */
			wMsgLenIndex = ii;							/* 记录帧长度存放下标 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = MSG_TYPE_EA_REPORT;
			ShortToChar(GATE_WAY_APP_PRTCL_VER, &szToGateWayDataBuf[ii]);	/* 应用协议版本号 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */

			chEaNum = GetEaNum();
			if (EA_MAX_NUM < chEaNum)
			{
				chRtn = CI_ERROR;
			}
			else
			{
				chEaSendNum = 0u;
				wEaNumIndex = ii;				/* 记录汇报数量存储下标 */
				ii++;

				for (chEaIndex = 0u; chEaIndex < chEaNum; chEaIndex++)
				{
					wEaTrainid = GetEvacuatingTrainIdByIndex(chEaIndex);
					chRtn = dquDevName2HlhtId(wEaTrainid, wTrainLgcId, &dwEaTrainHlhtId);
					chEaLgcNum = EaGetLgcNum(chEaIndex);
					pEaLgcId = EaGetLgcId(chEaIndex);
					chEaBuidFlag = GetEaBuildedFlag(chEaIndex);
					chEaSrcId = GetEaSrcTiocByIndex(chEaIndex);
					chPaType = GetPaTypeByIndex(chEaIndex);
					chEaConfigId = GetEaConfigID(chEaIndex);
					chEaAreaLineType = GetEaAreaLineType(chEaIndex);
					if ((NULL == pEaLgcId) || (CI_ERROR == chRtn) || (EA_SECTION_MAX_NUM < chEaLgcNum)
						|| ((PA_TYPE_DA != chPaType) && (PA_TYPE_EA != chPaType)))
					{
						chRtn = CI_ERROR;
						break;
					}
					else
					{
						if ((chEaSrcId == chLocalId) && (PA_TYPE_EA == chPaType))
						{
							chEaSendNum++;
							LongToChar(dwEaTrainHlhtId, &szToGateWayDataBuf[ii]);	/* 区间疏散列车互联互通ID */
							ii += 4u;

							szToGateWayDataBuf[ii++] = chEaConfigId;	    /* 防护区域ID，*/

							szToGateWayDataBuf[ii++] = chEaBuidFlag;		/* 防护区域建立标志 */

							szToGateWayDataBuf[ii++] = chEaAreaLineType;				/* 上下行区域 */

							szToGateWayDataBuf[ii++] = chEaLgcNum;				/* 逻辑区段数量 */
							for (chEaLgcIndex = 0u; chEaLgcIndex < chEaLgcNum; chEaLgcIndex++)
							{
								ShortToChar(pEaLgcId[chEaLgcIndex], &szToGateWayDataBuf[ii]);
								ii += 2u;
							}
						}
						else
						{
							; /* 本控区非建立控区，不汇报给ATS */
						}
					}
				}

				szToGateWayDataBuf[wEaNumIndex] = chEaSendNum;	/* 组汇报数量 */

				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);	/* 帧长度 */
				chMsgNum++;					/* 消息数量递增 */
			}
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsEaCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_EA_CONFIRM_FIRST;			/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_EA_CONFIRM_FIRST;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsEaCfmFst.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsEaCfmFst.wIndex, &szToGateWayDataBuf[ii]);  /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsEaCfmFst.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsEaCfmFst.chOpStatus;			/* 确认结果 */
				LongToChar(g_strAtsEaCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsEaCfmFst.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/*组第二个ATS的取消区间疏散首次确认信息*/
			if (FLAG_SET == g_strSndAtsEaCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii] = MSG_TYPE_EA_CONFIRM_FIRST;			/* 帧类型 */
				ii++;
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2U;
				szToGateWayDataBuf[ii] = MSG_TYPE_EA_CONFIRM_FIRST;
				ii++;
				szToGateWayDataBuf[ii] = chLocalId;							/* TIOC编号 */
				ii++;
				szToGateWayDataBuf[ii] = g_strSndAtsEaCfmFst.chStation;			/* 车站编号 */
				ii++;
				ShortToChar(g_strSndAtsEaCfmFst.wIndex, &szToGateWayDataBuf[ii]);  /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strSndAtsEaCfmFst.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4U;
				szToGateWayDataBuf[ii] = g_strSndAtsEaCfmFst.chOpStatus;			/* 确认结果 */
				ii++;
				LongToChar(g_strSndAtsEaCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4U;
				wMsgLen = (ii - wMsgLenIndex - 2U);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */

				/*组包后清除第二个ATS的确认信息*/
				ClearSndAtsEaFstCfmMsg();
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsEaCfmSnd.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_EA_CONFIRM_SECOND;			/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_EA_CONFIRM_SECOND;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsEaCfmSnd.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsEaCfmSnd.wIndex, &szToGateWayDataBuf[ii]);  /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsEaCfmSnd.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsEaCfmSnd.chOpStatus;			/* 确认结果 */
				LongToChar(g_strAtsEaCfmSnd.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsEaCfmSnd.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/* 组TIOC汇报给ATS的全线列车紧急制动信息 */
			szToGateWayDataBuf[ii++] = MSG_TYPE_WLB_REPORT;	/* 全线列车紧急制动汇报消息 */
			wMsgLenIndex = ii;							/* 记录帧长度存放下标 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = MSG_TYPE_WLB_REPORT;
			szToGateWayDataBuf[ii++] = chLocalId;  /* TIOC编号 */

			wWlbSum = 0U;
			wWlbSumIndex = ii;
			ii += 2U;

			/*组全线紧急制动信息*/
			chWlbState = WlbGetState();
			if (WLB_UNSET != chWlbState)
			{
				wWlbSum++;
				szToGateWayDataBuf[ii++] = WLB_TYPE_RC;	  /* 制动类型 */
				ShortToChar(wRcId, &szToGateWayDataBuf[ii]);  /* RC编号 */
				ii += 2u;
			}
			else
			{
				/* 未设置，不组包 */
			}

			/*组区域紧急制动信息*/
			wPhyCurSum = GetPhySecCurSum();
			for (jj = 0U; jj < wPhyCurSum; jj++)
			{
				wPhySecId = GetPhySecId(jj);
				cPhySecAreaUrgentState = GetPhySecAreaUrgentState(wPhySecId);
				if (PHYSEC_AREA_URGENT_NO != cPhySecAreaUrgentState)
				{
					wWlbSum++;
					szToGateWayDataBuf[ii++] = WLB_TYPE_PHYSEC;	  /* 制动类型 */
					ShortToChar(wPhySecId, &szToGateWayDataBuf[ii]);  /* 物理区段编号 */
					ii += 2U;
				}
				else
				{
					/*不组包*/
				}
			}

			ShortToChar(wWlbSum, &szToGateWayDataBuf[wWlbSumIndex]);  /* 组紧急制动数量 */

			wMsgLen = (ii - wMsgLenIndex - 2u);
			ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);	/* 帧长度 */
			chMsgNum++;					/* 消息数量递增 */
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsWlbCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_WLB_CONFIRM_FIRST;			/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_WLB_CONFIRM_FIRST;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsWlbCfmFst.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsWlbCfmFst.wIndex, &szToGateWayDataBuf[ii]); /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsWlbCfmFst.dwTime, &szToGateWayDataBuf[ii]);	/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsWlbCfmFst.chOpStatus;		/* 确认结果 */
				LongToChar(g_strAtsWlbCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsWlbCfmFst.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/*组第二个ATS的全线紧急制动首次确认信息*/
			if (FLAG_SET == g_strSndAtsWlbCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii] = MSG_TYPE_WLB_CONFIRM_FIRST;			/* 帧类型 */
				ii++;
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2U;
				szToGateWayDataBuf[ii] = MSG_TYPE_WLB_CONFIRM_FIRST;
				ii++;
				szToGateWayDataBuf[ii] = chLocalId;							/* TIOC编号 */
				ii++;
				szToGateWayDataBuf[ii] = g_strSndAtsWlbCfmFst.chStation;			/* 车站编号 */
				ii++;
				ShortToChar(g_strSndAtsWlbCfmFst.wIndex, &szToGateWayDataBuf[ii]); /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strSndAtsWlbCfmFst.dwTime, &szToGateWayDataBuf[ii]);	/* 时间 */
				ii += 4U;
				szToGateWayDataBuf[ii] = g_strSndAtsWlbCfmFst.chOpStatus;		/* 确认结果 */
				ii++;
				LongToChar(g_strSndAtsWlbCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4U;
				wMsgLen = (ii - wMsgLenIndex - 2U);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */

				/*组包后清除第二个ATS的确认信息*/
				ClearSndAtsWlbFstCfmMsg();
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsWlbCfmSnd.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_WLB_CONFIRM_SECOND;			/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_WLB_CONFIRM_SECOND;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsWlbCfmSnd.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsWlbCfmSnd.wIndex, &szToGateWayDataBuf[ii]); /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsWlbCfmSnd.dwTime, &szToGateWayDataBuf[ii]);	/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsWlbCfmSnd.chOpStatus;		/* 确认结果 */
				LongToChar(g_strAtsWlbCfmSnd.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsWlbCfmSnd.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/* 组TIOC汇报给ATS的脱轨防护区域信息 */
			szToGateWayDataBuf[ii++] = MSG_TYPE_DA_REPORT;	/* 脱轨防护区域汇报消息 */
			wMsgLenIndex = ii;							/* 记录帧长度存放下标 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = MSG_TYPE_DA_REPORT;
			ShortToChar(GATE_WAY_APP_PRTCL_VER, &szToGateWayDataBuf[ii]);	/* 应用协议版本号 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */

			chEaNum = GetEaNum();
			if (EA_MAX_NUM < chEaNum)
			{
				chRtn = CI_ERROR;
			}
			else
			{
				chEaSendNum = 0u;
				wEaNumIndex = ii;				/* 记录汇报数量存储下标 */
				ii++;

				for (chEaIndex = 0u; chEaIndex < chEaNum; chEaIndex++)
				{
					wEaTrainid = GetEvacuatingTrainIdByIndex(chEaIndex);
					chRtn = dquDevName2HlhtId(wEaTrainid, wTrainLgcId, &dwEaTrainHlhtId);
					chEaLgcNum = EaGetLgcNum(chEaIndex);
					pEaLgcId = EaGetLgcId(chEaIndex);
					chEaBuidFlag = GetEaBuildedFlag(chEaIndex);
					chEaSrcId = GetEaSrcTiocByIndex(chEaIndex);
					chPaType = GetPaTypeByIndex(chEaIndex);
					chEaAreaLineType = GetEaAreaLineType(chEaIndex);

					if ((NULL == pEaLgcId) || (CI_ERROR == chRtn) || (EA_SECTION_MAX_NUM < chEaLgcNum)
						|| ((PA_TYPE_DA != chPaType) && (PA_TYPE_EA != chPaType)))
					{
						chRtn = CI_ERROR;
						break;
					}
					else
					{
						if ((chEaSrcId == chLocalId) && (PA_TYPE_DA == chPaType))
						{
							chEaSendNum++;
							LongToChar(dwEaTrainHlhtId, &szToGateWayDataBuf[ii]);	/* 区间疏散列车互联互通ID */
							ii += 4u;

							szToGateWayDataBuf[ii++] = chEaAreaLineType;				/* 上下行区域 */

							szToGateWayDataBuf[ii++] = chEaLgcNum;				/* 逻辑区段数量 */
							for (chEaLgcIndex = 0u; chEaLgcIndex < chEaLgcNum; chEaLgcIndex++)
							{
								ShortToChar(pEaLgcId[chEaLgcIndex], &szToGateWayDataBuf[ii]);
								ii += 2u;
							}
						}
						else
						{
							; /* 本控区非建立控区，不汇报给ATS */
						}
					}
				}

				szToGateWayDataBuf[wEaNumIndex] = chEaSendNum;	/* 组汇报数量 */

				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);	/* 帧长度 */
				chMsgNum++;					/* 消息数量递增 */
			}
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsDaCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_DA_CONFIRM_FIRST;			/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_DA_CONFIRM_FIRST;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsDaCfmFst.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsDaCfmFst.wIndex, &szToGateWayDataBuf[ii]);  /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsDaCfmFst.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsDaCfmFst.chOpStatus;			/* 确认结果 */
				LongToChar(g_strAtsDaCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsDaCfmFst.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/*组第二个ATS的取消防护区域首次确认信息*/
			if (FLAG_SET == g_strSndAtsDaCfmFst.chFlag)
			{
				szToGateWayDataBuf[ii] = MSG_TYPE_DA_CONFIRM_FIRST;			/* 帧类型 */
				ii++;
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2U;
				szToGateWayDataBuf[ii] = MSG_TYPE_DA_CONFIRM_FIRST;
				ii++;
				szToGateWayDataBuf[ii] = chLocalId;							/* TIOC编号 */
				ii++;
				szToGateWayDataBuf[ii] = g_strSndAtsDaCfmFst.chStation;			/* 车站编号 */
				ii++;
				ShortToChar(g_strSndAtsDaCfmFst.wIndex, &szToGateWayDataBuf[ii]);  /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strSndAtsDaCfmFst.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4U;
				szToGateWayDataBuf[ii] = g_strSndAtsDaCfmFst.chOpStatus;			/* 确认结果 */
				ii++;
				LongToChar(g_strSndAtsDaCfmFst.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4U;
				wMsgLen = (ii - wMsgLenIndex - 2U);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */

				/*组包后清除第二个ATS的确认信息*/
				ClearSndAtsDaFstCfmMsg();
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			if (FLAG_SET == g_strAtsDaCfmSnd.chFlag)
			{
				szToGateWayDataBuf[ii++] = MSG_TYPE_DA_CONFIRM_SECOND;			/* 帧类型 */
				wMsgLenIndex = ii;												/* 记录帧长度存放下标 */
				ii += 2u;
				szToGateWayDataBuf[ii++] = MSG_TYPE_DA_CONFIRM_SECOND;
				szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
				szToGateWayDataBuf[ii++] = g_strAtsDaCfmSnd.chStation;			/* 车站编号 */
				ShortToChar(g_strAtsDaCfmSnd.wIndex, &szToGateWayDataBuf[ii]);  /* 操作站编号 */
				ii += 2U;
				LongToChar(g_strAtsDaCfmSnd.dwTime, &szToGateWayDataBuf[ii]);		/* 时间 */
				ii += 4u;
				szToGateWayDataBuf[ii++] = g_strAtsDaCfmSnd.chOpStatus;			/* 确认结果 */
				LongToChar(g_strAtsDaCfmSnd.dwCrc32, &szToGateWayDataBuf[ii]);	/* CRC */
				ii += 4u;
				wMsgLen = (ii - wMsgLenIndex - 2u);
				ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);		/* 帧长度 */
				chMsgNum++;														/* 消息数量递增 */
			}
			else
			{
				;
			}
			g_strAtsDaCfmSnd.chFlag = FLAG_UNSET;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			/* 组TIOC汇报给ATS的列车信息 */
			rrm_GetInfToATSUCTInfo(&strTrainInfo);
			szToGateWayDataBuf[ii++] = MSG_TYPE_TRIAN_INFO_REPORT;	/* 汇报远程筛选列车信息帧 */
			wMsgLenIndex = ii;							/* 记录帧长度存放下标 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = MSG_TYPE_TRIAN_INFO_REPORT;
			ShortToChar(GATE_WAY_APP_PRTCL_VER, &szToGateWayDataBuf[ii]);	/* 应用协议版本号 */
			ii += 2u;
			szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */
			szToGateWayDataBuf[ii++] = strTrainInfo.trainCnt;						/* 列车数量 */
			for (chTrainIndex = 0u; chTrainIndex < strTrainInfo.trainCnt; chTrainIndex++)
			{
				(void)dquDevName2HlhtId(strTrainInfo.TrainID[chTrainIndex], wTrainLgcId, &dwTrainId);
				LongToChar(dwTrainId, &szToGateWayDataBuf[ii]);		/* 列车互联互通ID */
				ii += 4u;

				ShortToChar(strTrainInfo.TailSecID[chTrainIndex], &szToGateWayDataBuf[ii]);		/* 列车车尾所处逻辑区段 */
				ii += 2u;
			}
			wMsgLen = (ii - wMsgLenIndex - 2u);
			ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);	/* 帧长度 */
			chMsgNum++;					/* 消息数量递增 */
		}
		else
		{
			;
		}
	}
	else
	{
		/*组飞车宕机信息*/
		szToGateWayDataBuf[ii++] = MSG_TYPE_TRAIN_FLY_INFO;			/* 帧类型 */
		wMsgLenIndex = ii;							/* 记录帧长度存放下标 */
		ii += 2u;
		szToGateWayDataBuf[ii++] = MSG_TYPE_TRAIN_FLY_INFO;

		ShortToChar(GATE_WAY_APP_PRTCL_VER, &szToGateWayDataBuf[ii]);	/* 应用协议版本号 */
		ii += 2u;
		szToGateWayDataBuf[ii++] = chLocalId;							/* TIOC编号 */

		FlyProtectTrainNum = GetFlyProtectNum();
		if (SHUT_DOWN_TRAIN_NUMMAX < FlyProtectTrainNum)
		{
			chRtn = CI_ERROR;
		}
		else
		{
			szToGateWayDataBuf[ii++] = FlyProtectTrainNum; /*组飞车列车数量*/
			for (chIndex = 0U; chIndex < FlyProtectTrainNum; chIndex++)
			{
				pFlyData = GetFlyProtectData(chIndex);
				wTrainId = pFlyData->wTrainId;
				TrainFlyAxis = pFlyData->flyProtectSecCnt;
				chRtn = dquDevName2HlhtId((UINT16)(CI_SYSTEM_TYPE_VOBC * 256U) + wTrainId, 0U, &dwTrainId); /*两字节列车ID转换为4字节互联互通ID*/
				if (chRtn == CI_SUCCESS)
				{/*互联互通ID查询成功*/
					LongToChar(dwTrainId, &szToGateWayDataBuf[ii]);		/* 列车ID */
					ii += 4u;
					/** 获取通信车对应的包络id */
					
					if (TRAIN_FLYALARM_SECNUM_MAX < TrainFlyAxis)
					{
						chRtn = CI_ERROR;
					}
					else
					{
						szToGateWayDataBuf[ii++] = TrainFlyAxis;			/* 计轴数量 */
						/* 获取计轴 id*/
						for (jj = 0U; jj < TrainFlyAxis; jj++)
						{
							wPhySecId = pFlyData->flyProtectSec[jj];
							ShortToChar(wPhySecId, &szToGateWayDataBuf[ii]);	
							ii += 2u;
						}
					}

				}
				else
				{   /*组包失败*/
					chRtn = CI_ERROR;
				}
			}
			wMsgLen = (ii - wMsgLenIndex - 2u);
			ShortToChar(wMsgLen, &szToGateWayDataBuf[wMsgLenIndex]);	/* 帧长度 */
		}

		if (CI_SUCCESS == chRtn)
		{
			debug_infor_printf((const)"\n GATEWAY_FLY_SHUT_DOWN \n");
			chMsgNum = 1U;
		}
	}
	if (CI_SUCCESS == chRtn)
	{
		/* 组包成功，填入消息数量 */
		szToGateWayDataBuf[wMsgNumIndex] = chMsgNum;
		wDstDevId = (UINT16)(((UINT16)targetDevType << 8U) | (UINT16)deviceId);
		chRtn = OutnetSafeSend(wDstDevId, 0u, &szToGateWayDataBuf[0], ii);
		if (CI_SUCCESS == chRtn)
		{
			debug_infor_printf((const)"\nGATEWAY_SEND:%d", ii);
			debug_out_array(0xAA, szToGateWayDataBuf, ii);
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	return chRtn;
}

/**
* @brief 全线紧急制动紧急ID校验
* @param const UINT8 cDeviceType 设备类型
* @param const UINT16 wDeviceId 设备ID
* @return 1 成功；0 失败
* @note Created By LQ 2023.11.09
*/
UINT8 WlbUrgentIdCheck(const UINT8 cDeviceType, const UINT16 wDeviceId)
{
	UINT8 retVal = CI_ERROR;
	UINT8 cLocalCiId = 0U;  /*本联锁ID*/
	UINT8 cPhySecBelongCiId = 0U;  /*物理区段所属联锁*/

	cLocalCiId = GetSystemParaLocalCiId();

	if (((WLB_TYPE_RC == cDeviceType) && (0U != wDeviceId) && (CI_SUM_MAX > wDeviceId))
		|| ((WLB_TYPE_PHYSEC == cDeviceType) && (0U != wDeviceId) && (PHYSICAL_SECTION_SUM_MAX > wDeviceId)))
	{
		switch (cDeviceType)
		{
		case WLB_TYPE_RC:
			if ((cLocalCiId == (UINT8)wDeviceId) && (0U != cLocalCiId))
			{
				retVal = CI_SUCCESS;
			}
			else
			{
				/*非本控区，返回失败*/
			}
			break;
		case WLB_TYPE_PHYSEC:
			cPhySecBelongCiId = GetPhySecBelongCiId(wDeviceId);
			if ((cLocalCiId == cPhySecBelongCiId) && (0U != cLocalCiId))
			{
				retVal = CI_SUCCESS;
			}
			else
			{
				/*非本控区，返回失败*/
			}
			break;
		default:
			/*返回失败*/
			break;  
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return retVal;
}

/**
* @brief 清除第二个ATS的远程筛选一次确认信息
* @param 无
* @return 无
* @note Created By LQ 2025.05.29
*/
void ClearSndAtsScreenFstCfmMsg(void)
{
	(void)CommonMemSet((void*)&g_strSndAtsCfmFst, (UINT32)sizeof(AtsMsgCfmStru), (UINT8)0U, (UINT32)sizeof(AtsMsgCfmStru));
}

/**
* @brief 清除第二个ATS的取消区间疏散一次确认信息
* @param 无
* @return 无
* @note Created By LQ 2025.05.29
*/
void ClearSndAtsEaFstCfmMsg(void)
{
	(void)CommonMemSet((void*)&g_strSndAtsEaCfmFst, (UINT32)sizeof(AtsMsgCfmStru), (UINT8)0U, (UINT32)sizeof(AtsMsgCfmStru));
}

/**
* @brief 清除第二个ATS的全线紧急制动一次确认信息
* @param 无
* @return 无
* @note Created By LQ 2025.05.29
*/
void ClearSndAtsWlbFstCfmMsg(void)
{
	(void)CommonMemSet((void*)&g_strSndAtsWlbCfmFst, (UINT32)sizeof(AtsMsgCfmStru), (UINT8)0U, (UINT32)sizeof(AtsMsgCfmStru));
}

/**
* @brief 清除第二个ATS的取消脱轨防护一次确认信息
* @param 无
* @return 无
* @note Created By LQ 2025.05.29
*/
void ClearSndAtsDaFstCfmMsg(void)
{
	(void)CommonMemSet((void*)&g_strSndAtsDaCfmFst, (UINT32)sizeof(AtsMsgCfmStru), (UINT8)0U, (UINT32)sizeof(AtsMsgCfmStru));
}