/*C*****************************************************************************
 * NAME:         .c
 *-------------------------------------------------------------------------------
 * RELEASE:
 * REVISION:     1.0
 *-------------------------------------------------------------------------------
 * PURPOSE:
 *
 *******************************************************************************/

/*_____ I N C L U D E S ______________________________________________________*/

#include "config.h" //全局声明

/*_____ M A C R O S __________________________________________________________*/
const char TsatURL[] = "AT+SOCKA=TCP,test.joyfueling.com,7011\r\n";
/*_____ D E F I N I T I O N ___________________AT+ GPSDTTY=”type”_______________________________*/
const char CMD_LinkMode[] = "AT+WKMOD=NET\r\n";
const char CMD_UARTFL[] = "AT+UARTFL=4096\r\n";
const char CMD_HEARTEN[] = "AT+HEARTEN=OFF\r\n";
const char CMD_Save[] = "AT+S\r\n";
const char CMD_ATRec[] = "AT+E=OFF\r\n";
const char CMD_Model_Set[] = "usr.cn#";
const char CMD_Model_Set_1[] = "+++";
const char CMD_Model_Set_2[] = "a";
const char CMD_Model_NET[] = "AT+ENTM\r\n";
const char CMD_ICCID[] = "AT+ICCID?\r\n";
const char CMD_IMEI[] = "AT+IMEI?\r\n";
const char CMD_CSQ[] = "AT+CSQ?\r\n";
char CMD_APN[50] = "AT+APN=";
const char NextStr[] = "\r\n\0";

/***********************USR-K3*************************/
const char WlanTsatURL[] = "AT+SOCKB1=TCPC,test.joyfueling.com,7011\r\n";
const char CMD_Reset[] = "AT+Z\r\n";
const char CMD_DHCP[] = "AT+WANN=DHCP\r\n";
const char CMD_GetIP[] = "AT+WANN\r\n";
const char CMD_GetLinkState[] = "AT+SOCKLKB1\r\n";
/***********************WIFI*************************/
const char CMD_WifiWSSSID[] = "AT+WIFI=KFB-2.4G,KFB123456\r\n";
const char CMD_WifiWSSSID_WIFIStation[] = "AT+WIFI=THX-HD4-2.4,KFB123456\r\n";
const char CMD_WifiSOCKET[] = "AT+Socket=0,0,test.joyfueling.com,7011\r\n";
const char CMD_WifiSOCKET_WIFIStation[] = "AT+Socket=0,0,192.168.14.100,7011\r\n";
const char CMD_WifiRSSI[] = "AT+CWJAP?\r\n";
const char CMD_WifiRST[] = "AT+RES\r\n";
/*******************************L510指令*****************************/
const char CMD_L510_AT[] = "+++";					  // 关闭回显
const char CMD_L510_ATRec[] = "ATE0\r\n";			  // 关闭回显 192.168.50.206
const char CMD_L510_IMEI[] = "AT+CGSN\r\n";			  // 获取IMEI码
const char CMD_L510_ICPIN[] = "AT+CPIN?\r\n";		  // 是否识别到卡
const char CMD_L510_ICCID[] = "AT+ICCID\r\n";		  // 获取IMEI码
const char CMD_L510_RSSI[] = "AT+CSQ\r\n";			  // 获取信号强度 (1-31)
const char CMD_L510_Model_NET[] = "AT+CIPMODE=1\r\n"; // 开启透传模式
const char CMD_L510_APN[] = "AT+QICSGP=1,1,\"CMNET\",\"\",\"\"\r\n";
const char CMD_L510_NETOPEN[] = "AT+NETOPEN\r\n";
const char CMD_L510_SOCKET[] = "AT+CIPOPEN=0,\"TCP\",\"test.joyfueling.com\",7011\r\n";
const char CMD_L510_GetLinkState[] = "AT+CIPOPQUERY?\r\n";
const char CMD_L510_RESET[] = "AT+RESET\r\n";
const char CMD_L510_SetGPSMode[] = "AT+GETGPS=GNRMC,0\r\n";
const char CMD_L510_GetGPS[] = "AT+MGPSC=1\r\n";

volatile u8 POS_Connect_TX_Buff[2000] = {0, 1, 2, 3, 4, 5, 6, 7}; // 数据发送缓存
volatile u8 POS_Connect_RX_Buff[2000];
volatile u8 POS2MD_Buff[2000];		 // pos的回复转接到wifi从机
volatile u8 POS_Connect_TX_Flag = 1; // 接收任务可以运行标志
typedef struct OperCodeStr
{
	char Country[64]; // 所在国家
	char Str[64];	  // 运营商名字
	char ICCID[10];	  // ICCID的前7位
	char APN[64];	  // 运营商对应的APN
} OperCodeStrType;

const OperCodeStrType Operators[] =
	{
		{"默认", "default", "890000", "internet"},
		{"中国", "ChinaMobile", "898600", "CMNET"},
		{"中国", "ChinaMobile", "898602", "CMNET"},
		{"中国", "ChinaMobile", "898604", "CMNET"},
		{"中国", "ChinaTelecom", "898607", "CMNET"},
		{"中国", "ChinaUnicom", "898601", "UNINET"},
		{"中国", "ChinaUnicom", "898606", "UNINET"},
		{"中国", "ChinaUnicom", "898609", "UNINET"},
		{"中国", "ChinaTelecom", "898603", "CTNET"},
		{"中国", "ChinaTelecom", "898611", "CTNET"},

		{"沙特", "STC", "8996601", "jawalnet.com.sa"},

		{"科威特", "STC", "8996504", "VIVA"},
		{"科威特", "Ooredoo", "8996503", "Action.ooredoo.com"},
		{"科威特", "zain", "899659", "HSPPS"},

		{"泰国", "AIS", "89660", "internet"},

		{"缅甸", "Vietna", "898405", "Metfone"},
		{"缅甸", "Mobifone", "898401", "smart"},
		{"缅甸", "Viettel", "898404", "smart"},
		{"缅甸", "VINA", "898402", "smart"},

		{"柬埔寨", "Metfone", "8985508", "Metfone"},
		{"柬埔寨", "Smart", "8985502", "smart"},
		{"柬埔寨", "Smart", "8985505", "smart"},
		{"柬埔寨", "Smart", "8985506", "smart"},

		{"孟加拉", "Bobi", "898800", "internet"},
		{"孟加拉", "Grameenphone", "898801", "gpinternet"},
		{"孟加拉", "Banglalink", "898803", "blweb"},

		{"印度", "Airtel", "899100", "airtelgprs.com"},
		{"印度", "Airtel", "899110", "airtelgprs.com"},
		{"印度", "Airtel", "899131", "airtelgprs.com"},
		{"印度", "Airtel", "899140", "airtelgprs.com"},
		{"印度", "Airtel", "899145", "airtelgprs.com"},
		{"印度", "Airtel", "899149", "airtelgprs.com"},
		{"印度", "Airtel", "899151", "airtelgprs.com"},
		{"印度", "Airtel", "899152", "airtelgprs.com"},
		{"印度", "Airtel", "899153", "airtelgprs.com"},
		{"印度", "Airtel", "899154", "airtelgprs.com"},
		{"印度", "Airtel", "899155", "airtelgprs.com"},
		{"印度", "Airtel", "899156", "airtelgprs.com"},
		{"印度", "Airtel", "899190", "airtelgprs.com"},
		{"印度", "Airtel", "899192", "airtelgprs.com"},
		{"印度", "Airtel", "899193", "airtelgprs.com"},
		{"印度", "Airtel", "899194", "airtelgprs.com"},
		{"印度", "Airtel", "899195", "airtelgprs.com"},
		{"印度", "Airtel", "899196", "airtelgprs.com"},
		{"印度", "Airtel", "899197", "airtelgprs.com"},
		{"印度", "Airtel", "899198", "airtelgprs.com"},
		{"印度", "Airtel", "899102", "airtelgprs.com"},
		{"印度", "Airtel", "899103", "airtelgprs.com"},

		{"印度", "Idea", "899189", "airtelgprs.com"},
		{"印度", "Idea", "8991799", "airtelgprs.com"},
		{"印度", "Idea", "8991845", "airtelgprs.com"},
		{"印度", "Idea", "8991846", "airtelgprs.com"},
		{"印度", "Idea", "8991848", "airtelgprs.com"},
		{"印度", "Idea", "8991849", "airtelgprs.com"},
		{"印度", "Idea", "8991850", "airtelgprs.com"},
		{"印度", "Idea", "8991852", "airtelgprs.com"},
		{"印度", "Idea", "8991853", "airtelgprs.com"},
		{"印度", "Idea", "899104", "airtelgprs.com"},
		{"印度", "Idea", "899107", "airtelgprs.com"},
		{"印度", "Idea", "899112", "airtelgprs.com"},
		{"印度", "Idea", "899114", "airtelgprs.com"},
		{"印度", "Idea", "899119", "airtelgprs.com"},
		{"印度", "Idea", "899122", "airtelgprs.com"},
		{"印度", "Idea", "899124", "airtelgprs.com"},
		{"印度", "Idea", "899144", "airtelgprs.com"},
		{"印度", "Idea", "899156", "airtelgprs.com"},
		{"印度", "Idea", "899170", "airtelgprs.com"},
		{"印度", "Idea", "899178", "airtelgprs.com"},
		{"印度", "Idea", "899182", "airtelgprs.com"},
		{"印度", "Idea", "899187", "airtelgprs.com"},

		{"印度", "Jio", "8991840", "Jionet"},
		{"印度", "Jio", "8991854", "Jionet"},
		{"印度", "Jio", "8991855", "Jionet"},
		{"印度", "Jio", "8991856", "Jionet"},
		{"印度", "Jio", "8991857", "Jionet"},
		{"印度", "Jio", "8991858", "Jionet"},
		{"印度", "Jio", "8991859", "Jionet"},
		{"印度", "Jio", "8991860", "Jionet"},
		{"印度", "Jio", "8991861", "Jionet"},
		{"印度", "Jio", "8991862", "Jionet"},
		{"印度", "Jio", "8991863", "Jionet"},
		{"印度", "Jio", "8991864", "Jionet"},
		{"印度", "Jio", "8991865", "Jionet"},
		{"印度", "Jio", "8991866", "Jionet"},
		{"印度", "Jio", "8991867", "Jionet"},
		{"印度", "Jio", "8991868", "Jionet"},
		{"印度", "Jio", "8991869", "Jionet"},
		{"印度", "Jio", "8991870", "Jionet"},
		{"印度", "Jio", "8991871", "Jionet"},
		{"印度", "Jio", "8991872", "Jionet"},
		{"印度", "Jio", "8991873", "Jionet"},
		{"印度", "Jio", "8991874", "Jionet"},

		{"厄瓜多尔", "MOVISTAR", "8959300", "internet.movistar.com.ec"},
		{"厄瓜多尔", "Claro", "8959301", "internet.claro.com.ec"},
		{"厄瓜多尔", "CNT", "8959302", "internet.cnt.net.ec"},

};

/*_____ D E C L A R A T I O N ____________________________internet.movistar.com.ec____________________*/

u16 crc16(u8 *puchMsg, u16 usDataLen);
const u8 auchCRCHi[] = {
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0 /**/,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
	0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
	0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
	0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
	0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
	0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
	0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
	0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
	0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
	0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
	0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
	0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
	0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
	0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
	0x80, 0x41, 0x00, 0xC1, 0x81, 0x40};

const u8 auchCRCLo[] = {
	0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06 /**/,
	0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
	0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
	0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
	0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
	0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
	0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
	0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
	0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
	0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
	0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
	0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
	0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
	0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
	0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
	0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
	0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
	0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
	0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
	0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
	0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
	0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
	0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
	0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
	0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
	0x43, 0x83, 0x41, 0x81, 0x80, 0x40};
u16 CRC_Check(u8 *puchMsg, u16 usDataLen)
{
	u8 uchCRCHi = 0xFF;
	u8 uchCRCLo = 0xFF;
	u16 uIndex;
	while (usDataLen--)
	{
		uIndex = uchCRCHi ^ *puchMsg++;
		uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex];
		uchCRCLo = auchCRCLo[uIndex];
	}
	return (uchCRCLo << 8 | uchCRCHi);
}
u16 DartCRC16(u8 *puchMsg, u16 usDataLen)
{
	u8 uchCRCHi = 0x00;
	u8 uchCRCLo = 0x00;
	u16 uIndex;
	while (usDataLen--)
	{
		uIndex = uchCRCHi ^ *puchMsg++;
		uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex];
		uchCRCLo = auchCRCLo[uIndex];
	}
	return (uchCRCLo << 8 | uchCRCHi);
}
u8 SUMCRC(u8 *puchMsg, u16 usDataLen)
{
	u8 sum = 0x00;
	while (usDataLen--)
	{
		sum += *puchMsg++;
	}
	return (sum);
}
/****************************************************
函数名：POS_Connect_IO_Configuration
功能  ：通讯部分用到的IO初始化
参数  ：无
返回值：无
****************************************************/
void POS_Connect_IO_Configuration(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB, ENABLE);

	GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);
	GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_Init(GPIOB, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;	   // 普通输出模式
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;	   // 推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // 100MHz
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;	   // 上拉
	GPIO_Init(GPIOB, &GPIO_InitStructure);			   // 初始化
}
/****************************************************
函数名：POS_Connect_NVPOS_Connect_Configuration
功能  ：通讯部分用到的中断向量配置
参数  ：无
返回值：无
****************************************************/
void POS_Connect_NVIC_Configuration(void)
{
	NVIC_InitTypeDef NVIC_InitStructure; // 定义中断配置结构体

	NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream7_IRQn; // USART1_TX_DMA
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;		  // USART??
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;		  //
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;			  // IRQ????
	NVIC_Init(&NVIC_InitStructure);							  //??NVIC_InitStruct???????????NVIC???USART1
}

/****************************************************
函数名：POS_Connect_NVPOS_Connect_Configuration
功能  ：通讯部分用到的串口配置
参数  ：无
返回值：无
****************************************************/
void POS_Connect_USART_Configuration(u32 BaudRate)
{
	USART_InitTypeDef USART_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
	USART_InitStructure.USART_BaudRate = BaudRate; // Baud;//?????
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
	USART_Init(USART1, &USART_InitStructure);
	USART_Cmd(USART1, ENABLE);

	USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
	USART_ClearFlag(USART1, USART_FLAG_IDLE);

	USART_DMACmd(USART1, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);
}
/*************************************************
函数名  ：DMA_Configuration（）
功能    ：DMA初始化
传入参数：无
返回值  ：无
**************************************************/
void POS_Connect_DMA_Configuration(void)
{
	DMA_InitTypeDef DMA_InitStructure;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
	/*******************发送TX*********************/
	DMA_DeInit(DMA2_Stream7);
	DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
	// DMA_InitStructure.DMA_BufferSize = UART_DMA_SEND_LEN;
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->DR;
	DMA_InitStructure.DMA_Channel = DMA_Channel_4;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)POS_Connect_TX_Buff;

	DMA_Init(DMA2_Stream7, &DMA_InitStructure);
	DMA_ITConfig(DMA2_Stream7, DMA_IT_TC, ENABLE);

	/*******************RX*********************/
	DMA_DeInit(DMA2_Stream5);
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_InitStructure.DMA_BufferSize = 2000;
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->DR;
	DMA_InitStructure.DMA_Channel = DMA_Channel_4;
	DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)POS_Connect_RX_Buff;

	DMA_Init(DMA2_Stream5, &DMA_InitStructure);
	DMA_Cmd(DMA2_Stream5, ENABLE);
}
// F*****************************************************************************
//* NAME:    POS_Connect_DMATX_IRQHandler
//* PURPOSE: 通讯DMA发送完成中断
//* PARAMS: 无
//* return:	 无
//******************************************************************************
void POS_Connect_DMATX_IRQHandler(void)
{
	u16 i = 0;
	DMA_ClearFlag(DMA2_Stream7, DMA_IT_TCIF7);
	POS_Connect_TX_DMAStop(); // 关闭DMA传输
}
// F*****************************************************************************
//* NAME:    POS_Connect_DMARX_IRQHandler
//* PURPOSE: DMA传输完成中断，Gas ModBus
//* PARAMS: 无
//* return:	 无
//******************************************************************************

void POS_Connect_DMARX_IRQHandler(void)
{
	u8 i = 0;
	if (USART_GetITStatus(USART1, USART_IT_IDLE) != RESET) //?????????
	{
		USART_ClearFlag(USART1, USART_IT_IDLE);
		POS_Connect_RX_DMAStop(); // 关闭DMA接收
		DMA_ClearFlag(DMA2_Stream5, DMA_IT_TCIF5);
		TXHData.POS_Info.POS_ConnectRXTask_Flag = 1; // 使能接收任务
		i = USART1->SR;
		i = USART1->DR;
		TXHData.PCMail_RX_Len = 2000 - DMA2_Stream5->NDTR;
		POS_Connect_RX_DMALenSet(2000);
		POS_Connect_RX_DMAStart(); // 打开DMA传输()长度在选择发送队列时设置
	}
}
// F*****************************************************************************
//* NAME:    POS_Connect_u64ToBCD
//* PURPOSE: 用于u64类型转成BCD码类型
//* PARAMS: pData要转换的数据，Len长度
//* return:	 BCD类型
//******************************************************************************
u64 POS_Connect_u64ToBCD(u64 Dat)
{
	u8 i = 0;
	u64 T64 = 0, Temp = 0;
	u8 *pData;
	pData = (u8 *)&T64;
	for (i = 0; i < 8; i++)
	{
		Temp = Dat % 100;
		*(pData + i) = ((Temp / 10) << 4) + ((Temp % 10) & 0x0F);
		Dat /= 100;
	}

	return T64;
}
// 初始化队列
void InitQueue(MessageQueue_Type *Queue)
{
	Queue->Front = 0;
	Queue->Rear = 0;
}

// 入队操作
void EnQueue(MessageQueue_Type *Queue, u8 Content, u8 Priority)
{
	Message_Type *Message;
	int i = Queue->Rear; // 从队尾开始遍历
	// 按照优先级插入
	while (i != Queue->Front && Priority > Queue->Messages[(i - 1 + QUEUE_SIZE) % QUEUE_SIZE].Priority)
	{
		Queue->Messages[i] = Queue->Messages[(i - 1 + QUEUE_SIZE) % QUEUE_SIZE]; // 后移一位
		i = (i - 1 + QUEUE_SIZE) % QUEUE_SIZE;
	}
	Queue->Messages[i].Content = Content;
	Queue->Messages[i].Priority = Priority;
	Queue->Rear = (Queue->Rear + 1) % QUEUE_SIZE; // 队尾指针后移
}

// 出队操作
Message_Type *DeQueue(MessageQueue_Type *Queue)
{
	Message_Type *Message;
	if (Queue->Front != Queue->Rear)
	{
		Message = &Queue->Messages[Queue->Front];
		Queue->Front = (Queue->Front + 1) % QUEUE_SIZE;
		return Message;
	}
	else
	{
		Message->Content = 0;
		return Message;
	}
}
// 查询队列中是不是包含特定消息
u8 FindMessage(MessageQueue_Type *Queue, u8 Content)
{
	u8 i = 0;
	for (i = 0; i < QUEUE_SIZE; i++)
	{
		if (Queue->Messages[i].Content == Content)
		{
			return Queue->Messages[i].Priority;
		}
	}
	return 0;
}
void POS_Network_APN_Set(void)
{
	char CMD[50] = "AT+APN=";
	u32 i = 0;
	u16 Temp = 0;
	u32 numElements = 0;
	u32 strllen = 0;
	if ((TXHData.POS_Info.ConnectType != POS_Connect_Typ_Station))
	{
		BEEP = 1;
		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < strlen(CMD_Model_Set_2); i++)
			POS_Connect_TX_Buff[i] = CMD_Model_Set_2[i];
		POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
		delay_ms(500);

		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < strlen(CMD_Model_NET); i++)
			POS_Connect_TX_Buff[i] = CMD_Model_NET[i];
		POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
		delay_ms(1000);

		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < strlen(CMD_Model_Set_1); i++)
			POS_Connect_TX_Buff[i] = CMD_Model_Set_1[i];
		POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
		delay_ms(1000);

		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < strlen(CMD_Model_Set_2); i++)
			POS_Connect_TX_Buff[i] = CMD_Model_Set_2[i];
		POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
		delay_ms(1000);
		{
			strcat(CMD, (const char *)TXHData.POSData.WirelessData.APN);
			strcat(CMD, NextStr);
			TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
			for (i = 0; i < strlen((char *)&CMD); i++)
				POS_Connect_TX_Buff[i] = CMD[i];
			POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
			POS_Connect_TX_DMAStart();
		};
		delay_ms(1000);
		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < sizeof(CMD_Save); i++)
			POS_Connect_TX_Buff[i] = CMD_Save[i];
		POS_Connect_TX_DMALenSet(i - 1); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
		delay_ms(100);
		BEEP = 0;
	}
}
void POS_WIFIReconnect(void)
{
	u32 i = 0, j = 0;
	u16 Temp = 0;
	u32 numElements = 0;
	u32 strllen = 0;
	u16 StartLen = 0, EndLen = 0;

	for (i = 0; i < 100; i++)
		POS_Connect_TX_Buff[i] = 0;
	TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
	for (i = 0; i < 8; i++)
		POS_Connect_TX_Buff[i] = CMD_WifiWSSSID[i];
	for (i = 0; i < strlen((const char *)TXHData.POSData.WirelessData.WiFIName); i++)
		POS_Connect_TX_Buff[8 + i] = TXHData.POSData.WirelessData.WiFIName[i];
	POS_Connect_TX_Buff[8 + i] = ',';
	j = 8 + i + 1;
	for (i = 0; i < strlen((const char *)TXHData.POSData.WirelessData.WiFIPassWord); i++)
		POS_Connect_TX_Buff[j + i] = TXHData.POSData.WirelessData.WiFIPassWord[i];
	strcat(POS_Connect_TX_Buff, "\r\n\0");
	POS_Connect_TX_DMALenSet(strlen((const char *)POS_Connect_TX_Buff)); // 设置发送DMA长度
	POS_Connect_TX_DMAStart();
	while (!TXHData.POS_Info.POS_ConnectRXTask_Flag)
	{
		delay_ms(1);
		i++;
		if (i > 100)
			break;
	}
	if (POS_URL == SWF_ON) // 测试服务器
	{
		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < strlen(CMD_WifiSOCKET); i++)
			POS_Connect_TX_Buff[i] = CMD_WifiSOCKET[i];
		POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
		while (!TXHData.POS_Info.POS_ConnectRXTask_Flag)
		{
			delay_ms(1);
			i++;
			if (i > 100)
				break;
		}
	}
	else
	{
		for (i = 0; i < 100; i++)
			POS_Connect_TX_Buff[i] = 0;
		TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
		for (i = 0; i < 14; i++)
			POS_Connect_TX_Buff[i] = CMD_WifiSOCKET[i];
		// const char CMD_WifiSOCKET[]="AT+Socket=0,0,test.joyfueling.com,7011\r\n";
		StartLen = strlen((const char *)TXHData.POSData.WirelessData.CMD_SOCKA);
		if (StartLen)
		{
			for (i = 0; i < StartLen; i++)
				POS_Connect_TX_Buff[14 + i] = TXHData.POSData.WirelessData.CMD_SOCKA[i];
			strcat(POS_Connect_TX_Buff, "\r\n\0");
		}
		POS_Connect_TX_DMALenSet(strlen((const char *)POS_Connect_TX_Buff)); // 设置发送DMA长度
		POS_Connect_TX_DMAStart();
	}

	while (!TXHData.POS_Info.POS_ConnectRXTask_Flag)
	{
		delay_ms(1);
		i++;
		if (i > 100)
			break;
	}
}
void POS_Connect_Init(void)
{
	u32 i = 0;
	u8 Temp = 0;
	POS_Connect_IO_Configuration();
	POS_Connect_DMA_Configuration();
	POS_Connect_USART_Configuration(115200);
	POS_Connect_NVIC_Configuration();
	RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); // 开启 RNG 时钟
	RNG_Cmd(ENABLE);									// 使能 RNG
	delay_ms(1000);
	// InitQueue(&TXHData.POS_TX_MessageQueue);
	// 数据上传永远占据最低优先，并且不会被移除队列，其余指令优先级不能低于2，否则可能不会被执行
	//	EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_SynchronizationTime,Message_Priority_3);
	//	EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_FuelData,Message_Priority_1);
	TXHData.POS_Info.POS_CMD_Next = POSConnect_SynchronizationTime;
	TXHData.POS_Info.Link_Flag = 0;
	TXHData.ReSendDataTimer.Init = 0;				  // 清除初始化标志
	TXHData.ReSendDataTimer.Flag = 0;				  // 清除到时标志
	TXHData.ReSendDataTimer.ON_OFF = 0;				  // 打开
	TXHData.ReSendDataTimer.Cycle = 0;				  // 设置为循环模式，发送时启动
	TXHData.ReSendDataTimer.TimerCountMax = 1000 * 1; // 周期1秒

	TXHData.POSCutTimer.Init = 0;			  // 清除初始化标志
	TXHData.POSCutTimer.Flag = 1;			  // 清除到时标志
	TXHData.POSCutTimer.ON_OFF = 1;			  // 打开
	TXHData.POSCutTimer.Cycle = 1;			  // 设置为循环模式，发送时启动ssssssssss/dddd
	TXHData.POSCutTimer.TimerCountMax = 8000; // 周期8秒

	TXHData.HeartbeatTimer.Init = 0;				 // 清除初始化标志
	TXHData.HeartbeatTimer.Flag = 0;				 // 清除到时标志
	TXHData.HeartbeatTimer.ON_OFF = 1;				 // 打开
	TXHData.HeartbeatTimer.Cycle = 1;				 // 设置为循环模式，发送时
	TXHData.HeartbeatTimer.TimerCountMax = 1000 * 1; // 周期1秒

	TXHData.DelayDetectionTimer.Init = 0;			  // 清除初始化标志
	TXHData.DelayDetectionTimer.Flag = 0;			  // 清除到时标志
	TXHData.DelayDetectionTimer.ON_OFF = 0;			  // 打开
	TXHData.DelayDetectionTimer.Cycle = 0;			  // 设置为循环模式，发送时
	TXHData.DelayDetectionTimer.TimerCountMax = 1000; // 周期10秒

	TXHData.POS_RS232Timer.Init = 0;			// 清除初始化标志
	TXHData.POS_RS232Timer.Flag = 1;			// 清除到时标志
	TXHData.POS_RS232Timer.ON_OFF = 1;			// 打开
	TXHData.POS_RS232Timer.Cycle = 1;			// 设置为循环模式，发送时启动cc/
	TXHData.POS_RS232Timer.TimerCountMax = 500; // 周期0.5秒

	TXHData.POSReLinkTimer.Init = 0;				  // 清除初始化标志
	TXHData.POSReLinkTimer.Flag = 0;				  // 清除到时标志
	TXHData.POSReLinkTimer.ON_OFF = 1;				  // 打开
	TXHData.POSReLinkTimer.Cycle = 1;				  // 设置为循环模式，发送时启动cc/
	TXHData.POSReLinkTimer.TimerCountMax = 1000 * 70; // 周期0.5秒
	for (i = 0; i < 4; i++)
	{
		TXHData.MDRestartTimer[i].Init = 0;				 // 清除初始化标志
		TXHData.MDRestartTimer[i].Flag = 0;				 // 清除到时标志
		TXHData.MDRestartTimer[i].ON_OFF = 1;			 // 打开
		TXHData.MDRestartTimer[i].Cycle = 0;			 // 设置为循环模式，发送时启动
		TXHData.MDRestartTimer[i].TimerCountMax = 11000; // 周期10秒
	}
	TXHData.POS_Info.WiFiRSSI = 0;

	if (TXHData.POSData.POSConnectTyye.Flag.ConnectMode > 0)
		TXHData.POS_Info.ConnectType = TXHData.POSData.POSConnectTyye.Flag.ConnectMode - 1;
	if (TXHData.POSData.POSConnectTyye.Flag.NetworkSet > 0)
		TXHData.POS_Info.NetType = TXHData.POSData.POSConnectTyye.Flag.NetworkSet - 1;
	if (TXHData.POS_Info.ConnectType == POS_Connect_Typ_Station) // 站级
	{
		POSConnect_Station;
		TXHData.POSNetSetState.Flag.WorkMode = 1;
	}
	else
	{
		POSConnect_Cloud;
	}

	switch (TXHData.POS_Info.NetType)
	{
	case POS_Net_Typ_WAN:
		TXHData.POSReLinkTimer.TimerCountMax = 1000 * 30;
		POS_LinkA_Out = 0;
		break;
	case POS_Net_Typ_WiFi:
		TXHData.POSReLinkTimer.TimerCountMax = 1000 * 60;
		break;
	case POS_Net_Typ_4G_GM5:
		TXHData.POSReLinkTimer.TimerCountMax = 1000 * 60;
		break;
	case POS_Net_Typ_4G_L510:
		TXHData.POSReLinkTimer.TimerCountMax = 1000 * 60;
		POS_LinkA_Out = 0;
		TXHData.HeartbeatTimer.TimerCountMax = 1000 * 15;
		break;
	}
	STM32CPU.v.id[0] = *(u32 *)0x1fff7a10;
	STM32CPU.v.id[1] = *(u32 *)(0x1fff7a10 + 4);
	STM32CPU.v.id[2] = *(u32 *)(0x1fff7a10 + 8);
	for (i = 0; i < 20; i++)
		TXHData.POSData.WirelessData.IMEI[i] = 0;
	sprintf(&TXHData.POSData.WirelessData.IMEI[0], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%",
			STM32CPU.v.byte[0], STM32CPU.v.byte[2], STM32CPU.v.byte[4], STM32CPU.v.byte[5], STM32CPU.v.byte[6],
			STM32CPU.v.byte[7], STM32CPU.v.byte[8], STM32CPU.v.byte[9], STM32CPU.v.byte[10], STM32CPU.v.byte[11]);
	if (FMItemWrite(CF_POSData, 0))
		BEEP = 0;
}
void FToHA(u8 *Buff, float Temp) // 浮点数转换成字符串形式HEX，传进来是地址
{
	u8 HexToAsc[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
	u8 i = 0;
	u8 *N;
	N = (u8 *)(&Temp);
	for (i = 0; i < 4; i++)
	{
		*(Buff + i * 2) = HexToAsc[*(N + 3 - i) >> 4];
		*(Buff + i * 2 + 1) = HexToAsc[*(N + 3 - i) & 0x0f];
	}
}

u8 FindCharFStr(u8 *Str, char Cha, u8 Num)
{
	u8 i = 0, len = 0;
	for (; *Str; ++Str)
	{
		len++;
		if (Cha == *Str)
			i++;
		if (i == Num)
			return len;
	}
	return 0;
}
u8 Encrypt_Data(u8 Data, u8 Type, u8 Bit)
{
	u16 Temp = 0;

	if (Bit > 0x7)
		Bit = 7;
	Temp = (Data << 8) | Data;
	if (Type == 0)
	{
		Temp = Temp >> Bit;
		return (Temp & 0xff);
	}
	else if (Type == 1)
	{
		Temp = Temp << Bit;
		Temp >>= 8;
		return (Temp & 0xff);
	}
}
u8 Decode_Data(u8 Data, u8 Type, u8 Bit)
{
	u16 Temp = 0;

	if (Bit > 7)
		Bit = 7;

	Temp = (Data << 8) | Data;
	if (Type == 0)
	{
		Temp = Temp << Bit;
		Temp >>= 8;
		return (Temp & 0xff);
	}
	else if (Type == 1)
	{
		Temp = Temp >> Bit;
		return (Temp & 0xff);
	}
}

// F*****************************************************************************
//* NAME:    POS_ConnectTask
//* PURPOSE: 通讯接收数据处理任务
//* PARAMS: 无
//* return:	无
//******************************************************************************
volatile u32 POS_RX_RNGData = 0;
volatile u16 FrameNow = 0;
volatile u8 FrameTimeout = 0;
void POS_ConnectRXTask(void)
{
	u16 POS_ConnectRX_CMD = 0; // 指令
	u16 POS_ConnectRX_Len = 0; // 长度
	u8 Temp8 = 0, Package = 0;
	u8 POS_ConnectRX_AuthorizeNum_Temp = 0;
	u16 POS_ConnectRX_Check = 0; // 校验变量
	volatile u8 TimeLenOffset = 0, Encrypt_Flag1 = 0, Encrypt_Flag2 = 0;
	volatile u16 MD_Port_Num = 0, DeviceNumber = 0, MD_Port_Num_Top = 0, DeviceNumber_Top = 0, FrameTop = 0, Offset = 0, len = 0, WifiLenOffset = 0;
	u16 i = 0, j = 0, CRCTemp = 0, Temp16 = 0;
	u32 Temp32 = 0;
	if (TXHData.POSNetSetState.Flag.WorkMode == 1) // 透传模式
	{
		while (TXHData.PCMail_RX_Len > 10)
		{
			Package++; // 第几包，如果有粘包，标识用
			if (TXHData.POS_Info.NetType == POS_Net_Typ_WiFi && TXHData.POS_Info.ConnectType != POS_Connect_Typ_Station)
				WifiLenOffset = 7;
			if (POS_Connect_RX_Buff[WifiLenOffset + TimeLenOffset] == 0xFA)
			{
				TXHData.PosCTIME.Year = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 1];
				TXHData.PosCTIME.Month = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 2];
				TXHData.PosCTIME.Day = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 3];
				TXHData.PosCTIME.Hour = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 4];
				TXHData.PosCTIME.Min = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 5];
				TXHData.PosCTIME.Sec = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 6];
				if (TXHData.PosCTIME.Sec > TXHData.CTIME.Sec)
					Temp8 = MD_Connect_BCDTou64(TXHData.PosCTIME.Sec) - MD_Connect_BCDTou64(TXHData.CTIME.Sec);
				else
					Temp8 = MD_Connect_BCDTou64(TXHData.CTIME.Sec) - MD_Connect_BCDTou64(TXHData.PosCTIME.Sec);
				if ((Temp8 >= 5 && TXHData.PosCTIME.Sec < 0x54 && TXHData.PosCTIME.Sec > 0x6) && (TXHData.PosCTIME.Year >= 0x24 && TXHData.PosCTIME.Year <= 0x50))
				{
					TXHData.CTIME = TXHData.PosCTIME;
					DS1307_Write();
				}
				TimeLenOffset = 6;
			}
			POS_ConnectRX_Len = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 1] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 2]; // 提取长度码
			Temp32 = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 3] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 4] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 5] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 6];
			if (Temp32 != POS_RX_RNGData && POS_ConnectRX_Len < 2000 && POS_ConnectRX_Len > 0) // 随机码不能重复
			// if(1)//随机码不能重复
			{
				POS_RX_RNGData = Temp32;
				if (TXHData.PCMail_RX_Len > (WifiLenOffset + POS_ConnectRX_Len + 2 + 1))
				{
					TXHData.PCMail_RX_Len = TXHData.PCMail_RX_Len - (POS_ConnectRX_Len + 2);
				}
				else
				{
					TXHData.PCMail_RX_Len = 0;
				}
				Temp16 = CRC_Check(&POS_Connect_RX_Buff[WifiLenOffset], POS_ConnectRX_Len);
				if (Temp16 == ((POS_Connect_RX_Buff[WifiLenOffset + POS_ConnectRX_Len] << 8) | POS_Connect_RX_Buff[WifiLenOffset + POS_ConnectRX_Len + 1]))
				// if(1)//随机码不能重复
				{
					if (TXHData.UDisk_Flag)
						Log_Task(&POS_Connect_RX_Buff[WifiLenOffset], POS_ConnectRX_Len + 2, 4, Info_Receive);
					Encrypt_Flag1 = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 4] & 0x0f) % 2;
					Encrypt_Flag2 = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 6] & 0x0f) / 2;

					for (i = 0; i < POS_ConnectRX_Len - TimeLenOffset - 7; i++)
						POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 7 + i] = Decode_Data(POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 7 + i], Encrypt_Flag1, Encrypt_Flag2);

					//					if(TXHData.UDisk_Flag)
					//				     Log_Task(&POS_Connect_RX_Buff[(WifiLenOffset) + 0],POS_ConnectRX_Len + 2,4,Info_Receive);
					POS_ConnectRX_CMD = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 7];
					TXHData.POS_Info.Link_Flag = 1;
					TXHData.POSCutTimer.TimerCount = 0;
					TXHData.POSCutTimer.Flag = 0;
					TXHData.POSReLinkTimer.Flag = 0;
					TXHData.POSReLinkTimer.TimerCount = 0;
					TXHData.DelayDetection = TXHData.DelayDetectionTimer.TimerCount;
					TXHData.DelayDetectionTimer.Init = 1;
					if (TXHData.POS_Info.NetType == POS_Net_Typ_WAN || TXHData.POS_Info.NetType == POS_Net_Typ_4G_L510)
						POS_LinkA_Out = 1;
					Offset = 0;
					switch (POS_ConnectRX_CMD)
					{
					case POSConnect_FuelData:
					{
						if (TXHData.PREXDATA_WaitUpNummber)
						{
							TXHData.POS_Info.POS_CMD_Next = POSConnect_PREXDATAUp;
						}
						for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Port_Num_Top; MD_Port_Num++)
						{
							switch (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType)
							{
							case PosBlueSky:
							case PosLY:
							case PosJP:
							case PosDart:
							case PosYGao:
							case PosHongYang:
							case PosLanFeng:
							case PosSSLan:
							case PosBlueSkyPlus:
							{
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								{
									TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].SlaveNeedReply = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
									switch (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset])
									{
									case 0:
									{
									}
									break;
									case 1:
									{
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
									}
									break;
									case 2:
									{
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateRecords = 0;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].OrderNumber = 0;
										FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
										for (i = 0; i < 20; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CardNumber[i] = 0;
										for (i = 0; i < 10; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CarLicensePlate[i] = 0;
									}
									break;
									}
									Offset++;
								}
							}
							break;
							case PosYWY:
							case PosPLC:
							case PosPrice1_4:
							{
								switch (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset])
								{
								case 0:
								{
								}
								break;
								case 1:
								{
									TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
								}
								break;
								case 2:
								{
								}
								break;
								}
								Offset++;
							}
							break;
							case PosRFID:
							{
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								{
									TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].SlaveNeedReply = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
									switch (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset])
									{
									case 0:
									{
										if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState == 0x10) // 加油中
										{
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = 0;
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next != RFID_MDConnectCmdFindACK && TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next != RFID_MDConnectCmdLossACK)
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
										}
										Offset++;
									}
									break;
									case 1: // 通过
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										for (i = 0; i < 15; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDUserName[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + i + 1];
										for (i = 0; i < 10; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CarLicensePlate[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + i + 16];
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].BalanceDecimal = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + 26];
										for (i = 0; i < 5; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Balance[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + i + 27];
										Offset += 32;
									}
									break;
									case 2: // 密码错误
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										Offset++;
									}
									break;
									case 4: // 无效卡
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										Offset++;
									}
									break;
									case 8: // 余额不足
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										Offset++;
									}
									break;
									case 0x10: // 实时余额
									{
										if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next != RFID_MDConnectCmdFindACK && TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next != RFID_MDConnectCmdLossACK)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteFullingInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].BalanceDecimal = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + 1];
										for (i = 0; i < 5; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Balance[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + i + 2];
										Offset += 7;
									}
									break;
									case 0x20: // 积分余额
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										for (i = 0; i < 4; i++)
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Balance[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset + i + 1];
										Offset += 5;
									}
									break;
									case 0x40: // 授权取消
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.LockState = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										Offset++;
									}
									break;
									case 235: //
									case 236: //
									case 237: //
									case 238: //
									case 239: //
									case 240: //
									case 241: //
									case 242: //
									case 243: //
									case 244: //
									case 245: //
									case 246: //
									case 247: //
									case 248: //
									case 249: //
									case 250: //
									case 251: //
									case 252: //
									case 253: //
									case 254: //
									case 255: //
									{
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = RFID_MDConnectCmdWriteCardInfo;
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 0;
										TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].RFIDState = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
										Offset++;
									}
									break;
									}
								}
							}
							break;
							}
						}
						if (TXHData.MD_Multiplex_Port_Data.DeviceNumber > 0)
						{
							for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Multiplex_Port_Data.DeviceNumber - 1; MD_Port_Num++)
							{ /*设备类型：00无;04打印机;06液位仪;05单价牌*/
								{
									TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].SlaveNeedReply = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset];
									switch (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + Offset])
									{
									case 0:
									{
									}
									break;
									case 1:
									{
										TXHData.MD_Multiplex_Port_Data.State[MD_Port_Num].Flag.UpdateDisplay = 0;
									}
									break;
									case 2:
									{
										TXHData.MD_Multiplex_Port_Data.State[MD_Port_Num].Flag.UpdateRecords = 0;
									}
									break;
									}
									Offset++;
								}
							}
						}
					}
					break;
					case POSConnect_Authorize:
					{
						if (POS_ConnectRX_Len >= 0x1B) // 判断一下长度
						{
							for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Port_Num_Top; MD_Port_Num++)
							{
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								{
									if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.AuthorizeState == 0 && TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.Start_Flag == 0 && TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunControlState != Control_BoxAuto)
									{
										if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber == MD_Connect_BCDTou64(POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + POS_ConnectRX_AuthorizeNum_Temp * 13]))
										{
											if ((TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Call == 1 || TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunControlState == Control_NoGun) && TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
											{
												TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].NowAuthorizeType = NowAuthorizeType_Online;
												// TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WiFiPortNum
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13]);
												TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].OrderNumber = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 17] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 18] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 19] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 20]);
												// TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState. Flag.AuthorizeState = 1;
												FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
												TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next_End = 0;
												if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue)
												{
													switch (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType) // 无协议、无预置值不启动
													{
													case PosBlueSky:
													{
														switch (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType)
														{
														case Preset_Sale:
														{
															if (TXHData.MD_Port_Data[MD_Port_Num].PortData.Device_Type == Display_664)
															{
																if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue == 0x900000)
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdStart;
																else
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdWritePrsetSale;
															}
															else
															{
																if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue == 0x90000000)
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdStart;
																else
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdWritePrsetSale;
															}
														}
														break;
														case Preset_Volume:
														{
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdWritePrsetVolume;
														}
														break;
														}
													}
													break;
													case PosLY:
													{
														if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top)
														{
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 14] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 15] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 16]);
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = LY_MDConnectCmdAuthorize;
															// TXHData.MD_Port_Info[i].pGunNow = TXHData.MD_Port_Data[i].GunData[j].GunNummber;
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
														}
													}
													break;
													case PosJP:
													{
														if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top)
														{
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 14] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 15] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 16]);
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = LY_MDConnectCmdAuthorize;
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
															// TXHData.MD_Port_Info[i].pGunNow = TXHData.MD_Port_Data[i].GunData[j].GunNummber;
														}
													}
													break;
													case PosYGao:
													{
														if (TXHData.MD_Port_Data[MD_Port_Num].PortData.Device_Type == Display_664)
														{
															if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue == 0x900000)
																TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdStart;
															else
																TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdWritePrset;
														}
														else
														{
															if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue == 0x90000000)
																TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdStart;
															else
																TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdWritePrset;
														}
													}
													break;
													case PosHongYang:
													{
														switch (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType)
														{
														case Preset_Sale:
														{
															if (TXHData.MD_Port_Data[MD_Port_Num].PortData.Device_Type == Display_664)
															{
																if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue == 0x900000)
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdStart;
																else
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdWritePrsetSale;
															}
															else
															{
																if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue == 0x90000000)
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdStart;
																else
																	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdWritePrsetSale;
															}
														}
														break;
														case Preset_Volume:
														{
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdWritePrsetVolume;
														}
														break;
														}
													}
													break;
													case PosSSLan:
													{
														i = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].FatherNum; // 获取设备父号
														TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = i;
														if (TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top)
														{
															TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].SonNow = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].SonNum; // 获取设备在父设备中的位置号，作为当前操作父设备中的哪个设备的识别
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 14] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 15] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 16]);
															TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
															TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].MB_CMD_Need = LY_MDConnectCmdAuthorize;
															TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
														}
													}
													break;
													case PosBlueSkyPlus:
													{
														TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LTP_GunCMDAuthorize;
													}
													break;
													}
												}
											}
											//												POS_ConnectRX_AuthorizeNum_Temp ++;
											//												if(POS_ConnectRX_AuthorizeNum_Temp >= POS_ConnectRX_AuthorizeNum)
											break;
										}
									}
								}
								if (DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber)
									break;
							}
						}
					}
					break;
					case POSConnect_Preset:
					{
						if (POS_ConnectRX_Len >= 0x1B) // 判断一下长度
						{
							for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Port_Num_Top; MD_Port_Num++)
							{
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								{
									if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.Start_Flag == 0 && TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
									{
										if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber == MD_Connect_BCDTou64(POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8 + POS_ConnectRX_AuthorizeNum_Temp * 13]))
										{
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresetValue = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13]);
											TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].OrderNumber = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 17] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 18] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 19] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 20]);
											// TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState. Flag.AuthorizeState = 1;
											FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
											TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next_End = 1;
											switch (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType)
											{
											case PosBlueSky:
											{
												switch (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType)
												{
												case Preset_Sale:
												{
													TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdWritePrsetSale;
												}
												break;
												case Preset_Volume:
												{
													TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdWritePrsetVolume;
												}
												break;
												}
											}
											break;
											case PosYGao:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdWritePrset;
											}
											break;
											case PosHongYang:
											{
												switch (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].PresteType)
												{
												case Preset_Sale:
												{
													TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdWritePrsetSale;
												}
												break;
												case Preset_Volume:
												{
													TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdWritePrsetVolume;
												}
												break;
												}
											}
											break;
											case PosBlueSkyPlus:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LTP_GunCMDWritePrset;
											}
											break;
											}
											break;
										}
									}
								}
								if (DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber)
									break;
							}
						}
					}
					break;
					case POSConnect_DisAuthorize:
					{
						for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Port_Num_Top; MD_Port_Num++)
						{
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
							{
								if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber == MD_Connect_BCDTou64(POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8]))
								{
									{
										TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
										switch (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType)
										{
										case PosBlueSky:
										{
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdStop;
										}
										break;
										case PosLY:
										{
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top && (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0))
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = LY_MDConnectCmdDisauthorize;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
											}
										}
										break;
										case PosJP:
										{
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top && (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0))
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = LY_MDConnectCmdDisauthorize;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
											}
										}
										break;
										case PosYGao:
										{
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdStop;
										}
										break;
										case PosHongYang:
										{
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdStop;
										}
										break;
										case PosSSLan:
										{
											i = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].FatherNum; // 获取设备父号
											TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = i;
											if (TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top)
											{
												TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].SonNow = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].SonNum; // 获取设备在父设备中的位置号，作为当前操作父设备中的哪个设备的识别
												TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].MB_CMD_Need = LY_MDConnectCmdDisauthorize;
												TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
											}
										}
										break;
										case PosBlueSkyPlus:
										{
											if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].WaitPREXDATA_flag == 0)
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LTP_GunCMDStop;
										}
										break;
										}
									}
									break;
								}
							}
							if (DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber)
								break;
						}
					}
					break;
					case POSConnect_ChangePrice:
					{
						for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Port_Num_Top; MD_Port_Num++)
						{
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
							{
								if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber == MD_Connect_BCDTou64(POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8]))
								{
									{
										TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
										if (TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top)
										{
											TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11]);
											//												if(TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price >= 0x7532)
											//												{
											//												//	TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price = 0x1234;
											//													if (CoreDebug->DHCSR & 1)
											//															 {  //check C_DEBUGEN == 1 -> Debugger Connected
											//																__breakpoint(0);  // halt program execution here
											//														}
											//												  }
											switch (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType)
											{
											case PosBlueSky:
											{
												//													TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = C_MDConnectCmdWritePrice;
												//													TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectASKControlPower;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = C_MDConnectCmdWritePrice;
											}
											break;
											case PosLY:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = LY_MDConnectCmdWritePrice;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
											}
											break;
											case PosJP:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].LYGunNeedCMD = LY_MDConnectCmdWritePrice;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
											}
											break;
											case PosDart:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = DART_MDConnectCmdWritePrice;
											}
											case PosYGao:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = YG_MDConnectCmdWritePrice;
											}
											break;
											case PosHongYang:
											{
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = HY_MDConnectCmdWritePrice;
											}
											break;
											case PosSSLan:
											{
												i = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].FatherNum; // 获取设备父号
												TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = i;
												if (TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].Handshake == TXHData.MD_Port_Info[MD_Port_Num].Handshake_Top)
												{
													TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].SonNow = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].SonNum; // 获取设备在父设备中的位置号，作为当前操作父设备中的哪个设备的识别
													TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].MB_CMD_Need = LY_MDConnectCmdWritePrice;
													TXHData.MD_Port_Info[MD_Port_Num].FatherDevice[i].MB_CMD_Next = LY_MDConnectCmdChoiceGun;
												}
											}
											break;
											case PosBlueSkyPlus:
											{
												TXHData.MD_Port_Info[MD_Port_Num].pGunCapture = DeviceNumber;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].MB_CMD_Next = LTP_GunCMDWriteParameter;
												TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].ParameterNumber = 0x01;
											}
											break;
											}
										}
									}
									break;
								}
							}
							if (DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber)
								break;
						}
					}
					break;
					case POSConnect_Config:
					{
						Offset = (WifiLenOffset + TimeLenOffset) + 8;
						if (POS_Connect_RX_Buff[Offset] < 5 && POS_Connect_RX_Buff[Offset] > 0)
						{
							MD_Port_Num = POS_Connect_RX_Buff[Offset] - 1;
							Offset++;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.BaudRate = MD_Connect_BCDTou64((POS_Connect_RX_Buff[Offset] << 16) | (POS_Connect_RX_Buff[Offset + 1] << 8) | POS_Connect_RX_Buff[Offset + 2]);
							Offset += 3;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.StopBits = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
							Offset += 1;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.Parity_Even = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
							Offset += 1;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
							Offset += 1;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
							Offset += 1;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.MBCountTime = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
							Offset += 1;
							TXHData.MD_Port_Data[MD_Port_Num].PortData.Device_Type = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
							Offset += 1;
							if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosRFID)
							{
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								{
									TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
									Offset += 1;
									TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunAddr = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
									Offset += 1;
									if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].RFIDBinding != MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]) && TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].RFIDBinding > 0) // 之前绑定过一把枪，要把那把枪的信息消掉
									{
										for (i = 0; i < TXHData.MD_Port_Num_Top; i++)
										{
											for (j = 0; j < TXHData.MD_Port_Data[i].PortData.DeviceNumber; j++)
											{
												if (TXHData.MD_Port_Data[i].GunData[j].GunNummber == TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].RFIDBinding)
												{
													TXHData.MD_Port_Info[i].GunInfo[j].AssociatedDevices.Number = 0;
													TXHData.MD_Port_Info[i].GunInfo[j].AssociatedDevices.Port = 0;
													TXHData.MD_Port_Info[i].GunInfo[j].AssociatedDevices.location = 0;
												}
											}
										}
									}
									TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].RFIDBinding = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
									Offset += 1;
								}
							}
							else
							{
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								{
									TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
									Offset += 1;
									TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunAddr = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
									Offset += 1;
								}
								if ((POS_Connect_RX_Buff[Offset] & 0x0f) < 4)
									TXHData.MD_Port_Data[MD_Port_Num].PortData.GunDec.Dec.OilCNT = POS_Connect_RX_Buff[Offset] & 0x0f;
								Offset += 1;
								if ((POS_Connect_RX_Buff[Offset] >> 4) < 4)
									TXHData.MD_Port_Data[MD_Port_Num].PortData.GunDec.Dec.MoneyCNT = (POS_Connect_RX_Buff[Offset] >> 4) & 0x0f;
								if ((POS_Connect_RX_Buff[Offset] & 0x0f) < 4)
									TXHData.MD_Port_Data[MD_Port_Num].PortData.GunDec.Dec.Price = POS_Connect_RX_Buff[Offset] & 0x0f;
								Offset += 1;
								if ((POS_ConnectRX_Len) > (26 + DeviceNumber * 2))
								{
									for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
									{
										TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunControlState = POS_Connect_RX_Buff[Offset];
										Offset += 1;
									}
								}
							}
							for (i = TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; i < 16; i++)
								TXHData.MD_Port_Data[MD_Port_Num].GunData[i].RFIDBinding = TXHData.MD_Port_Data[MD_Port_Num].GunData[i].GunAddr = TXHData.MD_Port_Data[MD_Port_Num].GunData[i].GunNummber = 0;

							FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
							MD_Port_Init(MD_Port_Num);
							TXHData.MDRestartTimer[MD_Port_Num].ON_OFF = 1;
							//							EnQueue(&TXHData.POS_TX_MessageQueue,POS_ConnectRX_CMD,Message_Priority_2);
						}
						else if (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8] == 5 && TXHData.HardwareVersion < 32) // 24-31是大板，32-38是小板,小板没有第五端口
						{
							Offset = (WifiLenOffset + TimeLenOffset) + 9;
							TXHData.MD_Multiplex_Port_Data.DeviceNumber = POS_Connect_RX_Buff[Offset];
							if (TXHData.MD_Multiplex_Port_Data.DeviceNumber > 4)
								TXHData.MD_Multiplex_Port_Data.DeviceNumber = 4; // 最多4个，留一个给GPS模块
							Offset++;
							for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Multiplex_Port_Data.DeviceNumber; MD_Port_Num++)
							{
								TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].DeviceNumber = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
								Offset++;
								TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].POSType = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
								Offset++;
								TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].BaudRate = MD_Connect_BCDTou64((POS_Connect_RX_Buff[Offset] << 16) | (POS_Connect_RX_Buff[Offset + 1] << 8) | POS_Connect_RX_Buff[Offset + 2]);
								Offset += 3;
								TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].StopBits = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
								Offset++;
								TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].Parity_Even = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
								Offset++;
								TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].MBCountTime = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Offset]);
								Offset++;
								Temp16 = (POS_Connect_RX_Buff[Offset] << 8) | POS_Connect_RX_Buff[Offset + 1];
								Offset += 2;
								Offset += Temp16;
							}
							if (TXHData.HardwareVersion >= 26) // 版本26之后增加GPS模块
							{
								TXHData.MD_Multiplex_Port_Info.MultiplexDevicerTimer[TXHData.MD_Multiplex_Port_Data.DeviceNumber].Init = 0;					 // 清除初始化标志
								TXHData.MD_Multiplex_Port_Info.MultiplexDevicerTimer[TXHData.MD_Multiplex_Port_Data.DeviceNumber].Flag = 0;					 // 清除到时标志
								TXHData.MD_Multiplex_Port_Info.MultiplexDevicerTimer[TXHData.MD_Multiplex_Port_Data.DeviceNumber].ON_OFF = 1;				 // 打开
								TXHData.MD_Multiplex_Port_Info.MultiplexDevicerTimer[TXHData.MD_Multiplex_Port_Data.DeviceNumber].Cycle = 1;				 // 设置为循环模式，发送时启动
								TXHData.MD_Multiplex_Port_Info.MultiplexDevicerTimer[TXHData.MD_Multiplex_Port_Data.DeviceNumber].TimerCountMax = 10 * 1000; // 周期1000（1s）
								TXHData.MD_Multiplex_Port_Data.PortData[TXHData.MD_Multiplex_Port_Data.DeviceNumber].MBCountTime = 10 * 100;
								TXHData.MD_Multiplex_Port_Data.PortData[TXHData.MD_Multiplex_Port_Data.DeviceNumber].POSType = Multiplex_GPS;
								TXHData.MD_Multiplex_Port_Data.PortData[TXHData.MD_Multiplex_Port_Data.DeviceNumber].BaudRate = 9600;
								TXHData.MD_Multiplex_Port_Data.PortData[TXHData.MD_Multiplex_Port_Data.DeviceNumber].StopBits = 1;

								TXHData.MD_Multiplex_Port_Data.DeviceNumber += 1; // GPS模块放在随后的一个位置
							}

							FMItemWrite(CF_MD_Multiplex_Port_Data, 0);
							Multiplex_Port_Init();
						}
					}
					break;
					case POSConnect_SynchronizationTime:
					{
						TXHData.CTIME.Year = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];	// 年
						TXHData.CTIME.Month = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9]; // 月
						TXHData.CTIME.Day = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10];	// 日
						TXHData.CTIME.Hour = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11]; // 时
						TXHData.CTIME.Min = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12];	// 分
						TXHData.CTIME.Sec = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13];	// 秒
						DS1307_Write();
						DS1307_Read();
						if (TXHData.CTIME.Sec == 0xff)
						{
							DS1307_Init();
							TXHData.CTIME.Year = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];	// 年
							TXHData.CTIME.Month = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9]; // 月
							TXHData.CTIME.Day = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10];	// 日
							TXHData.CTIME.Hour = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11]; // 时
							TXHData.CTIME.Min = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12];	// 分
							TXHData.CTIME.Sec = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13];	// 秒
							DS1307_Write();
							DS1307_Read();
						}
						//						if(TXHData.POS_TX_MessageQueue.Messages[TXHData.POS_TX_MessageQueue.Front].Content == POSConnect_SynchronizationTime)
						{
							// DeQueue(&TXHData.POS_TX_MessageQueue);//当握手用，如果收不到时间同步，一直发

							{
								// TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
								TXHData.POS_Info.POS_CMD_Next = POSConnect_BoxVersion;
								// EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_FuelData,Message_Priority_1);
							}
						}
					}
					break;
					case POSConnect_TankAPCDownload:
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
						TXHData.CTIME.Year = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];	// 年
						TXHData.CTIME.Month = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9]; // 月
						TXHData.CTIME.Day = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10];	// 日
						TXHData.CTIME.Hour = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11]; // 时
						TXHData.CTIME.Min = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12];	// 分
						TXHData.CTIME.Sec = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13];	// 秒
						DS1307_Write();
						TXHData.RNGData = RNG_GetRandomNumber();
						// TXHData.RNGData = 0x12345678;
						Encrypt_Flag1 = ((TXHData.RNGData >> 16) & 0x0f) % 2;
						Encrypt_Flag2 = (TXHData.RNGData & 0x0f) / 2;
					}
					break;
					case POSConnect_BoxVersion:
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_BoxVersion;
						TXHData.ROM_UpData_Port = 0;
					}
					break;
					case POSConnect_BoxROMownload:
					{
						for (MD_Port_Num = 0; MD_Port_Num < 4; MD_Port_Num++)
						{
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.GunUP_Flag == 1)
									break;
							if (DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber)
								break;
						}
						if (MD_Port_Num >= 4)
						{
							FrameTimeout = 0;
							BEEP = BEEP_ON;
							if (TXHData.ATDB45Type >= At45DB321)
							{
								TXHData.POS_Info.POS_CMD_Next = POSConnect_BoxROMownload;
								// EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_BoxROMownload,Message_Priority_2);
								FrameTop = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];	 // 总段数
								FrameNow = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11]; // 当前段数
								for (i = 0; i < 512; i++)
									TXHData.Frame[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12 + i];
								if (AT45DBItemWrite(CA_Frame, FrameNow - 1 + RomUpDataAddr_New))
								{
									TXHData.ROM_UpData_Port = 0;
									TXHData.ROM_UpData_ProgressBar = FrameNow * 100 / FrameTop;
									TXHData.DisplayOn = 1;
									FrameNow++;
									if (FrameNow > FrameTop)
									{
										// TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
										TXHData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag = 1;
										TXHData.ROM_UpData.ROM_UpData_State.Flag.RightRun_Flag = 3;
										TXHData.ROM_UpData.FrameTop = FrameTop;
										FMItemWrite(CF_ROM_UpData, 0);
									}
								}
							}
							BEEP = BEEP_OFF;
						}
						else
						{
							TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
							TXHData.ROM_UpData.ROM_UpData_State.Flag.DisableUpdate = 1;
						}
					}
					break;
					case POSConnect_WhiteList:
					{
						FrameTimeout = 0;
						TXHData.POSData.WhiteListVersion = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];
						FrameTop = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10];	 // 总段数
						FrameNow = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12]; // 当前段数
						if (FrameTop * FrameNow && (FrameTop < 20))
						{
							if (POS_ConnectRX_Len > 16)
								DeviceNumber_Top = (POS_ConnectRX_Len - 16) / 6;
							else
								DeviceNumber_Top = 0;
							for (i = 0; i < DeviceNumber_Top; i++)
								for (j = 0; j < 6; j++)
									TXHData.WhiteList.CardNum[(FrameNow - 1) * 10 + i][j] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13 + i * 6 + j];
							TXHData.DisplayOn = 1;
							FrameNow++;
							if (FrameNow > FrameTop)
							{
								if (FrameTop >= 1)
									TXHData.WhiteList.WhiteListTop = (FrameTop - 1) * 10 + DeviceNumber_Top;
								else
									TXHData.WhiteList.WhiteListTop = 0;
								for (i = TXHData.WhiteList.WhiteListTop; i < 200; i++) // 清除剩余的白名单
									for (j = 0; j < 6; j++)
										TXHData.WhiteList.CardNum[i][j] = 0;
								FMItemWrite(CF_WhiteList, 0);
								FMItemWrite(CF_POSData, 0);
								TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
							}
							else
								TXHData.POS_Info.POS_CMD_Next = POSConnect_WhiteList;
						}
					}
					break;
					case POSConnect_DeviceVersion:
					{
						TXHData.ROM_UpData_Port = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];
						TXHData.POS_Info.POS_CMD_Next = POSConnect_DeviceVersion;
					}
					break;
					case POSConnect_DeviceROMownload:
					{
						for (MD_Port_Num = 0; MD_Port_Num < 4; MD_Port_Num++)
						{
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
								if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.GunUP_Flag == 1)
									break;
							if (DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber)
								break;
						}
						if (MD_Port_Num >= 4)
						{
							FrameTimeout = 0;
							BEEP = BEEP_ON;
							if (TXHData.ATDB45Type >= At45DB321 && POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8] <= 4)
							{
								TXHData.ROM_UpData_Port = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];
								MD_Port_Num = TXHData.ROM_UpData_Port - 1;
								for (i = 0; i < 16; i++)
									TXHData.MD_Port_Data[MD_Port_Num].GunData[i].ROM_UpData_State.Flag.Update_Flag = 0;
								TXHData.POS_Info.POS_CMD_Next = POSConnect_DeviceROMownload;
								for (i = 0; i < 10; i++)
									TXHData.MD_Port_Data[MD_Port_Num].PortData.ROM_UpData_Version[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9 + i];
								FrameTop = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 19] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 20]; // 总段数
								FrameNow = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 21] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 22]; // 当前段数
								for (i = 0; i < 512; i++)
									TXHData.Frame[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 23 + i];
								if (AT45DBItemWrite(CA_DeviceFrame, FrameNow - 1 + MD_Port_Num * 1024))
								{
									TXHData.ROM_UpData_ProgressBar = FrameNow * 100 / FrameTop;
									TXHData.DisplayOn = 1;
									FrameNow++;
									if (FrameNow > FrameTop)
									{
										for (i = 0; i < 16; i++)
											TXHData.MD_Port_Data[MD_Port_Num].GunData[i].ROM_UpData_State.Flag.Update_Flag = 1;
										// TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
										TXHData.MD_Port_Data[MD_Port_Num].PortData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag = 1;
										TXHData.MD_Port_Data[MD_Port_Num].PortData.ROM_UpData.ROM_UpData_State.Flag.RightRun_Flag = 1;
										TXHData.MD_Port_Data[MD_Port_Num].PortData.ROM_UpData.FrameTop = FrameTop;
										FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
									}
									else if (FrameNow == 1)
									{
										for (i = 0; i < 16; i++)
											TXHData.MD_Port_Data[MD_Port_Num].GunData[i].ROM_UpData_State.Flag.Update_Flag = 0;
										TXHData.MD_Port_Data[MD_Port_Num].PortData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag = 0;
										FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
									}
								}
							}
							BEEP = BEEP_OFF;
						}
						else
						{
							TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
							TXHData.ROM_UpData.ROM_UpData_State.Flag.DisableUpdate = 1;
						}
					}
					break;
					case POSConnect_PREXDATAUp:
					{
						Temp16 = (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
						if (TXHData.PREXDATA_Upload.PREXDATA_NowFrame == Temp16 && TXHData.PREXDATA_Upload.PREXDATA_NowWaitUpNummber == TXHData.PREXDATA_WaitUpNummber) // 帧特征相符，并且上传等待回复期间没有新增记录
						{
							if (TXHData.PREXDATA_WaitUpNummber > TXHData.PREXDATA_Upload.PREXDATA_NowFrameLen)
								TXHData.PREXDATA_WaitUpNummber -= TXHData.PREXDATA_Upload.PREXDATA_NowFrameLen;
							else
							{
								TXHData.PREXDATA_WaitUpNummber = 0;
								TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
							}

							TXHData.PREXDATA_Upload.PREXDATA_NowFrame = 0;
							TXHData.PREXDATA_Upload.PREXDATA_NowFrameLen = 0;
							FMItemWrite(CF_PREXDATA_Upload, 0);
							FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
							TXHData.DisplayOn = 1;
						}
					}
					break;
					case POSConnect_PrintfInfo:
					{
						for (i = 0; i < 20; i++)
							for (j = 0; j < 32; j++)
								TXHData.PrintInfo.PrintBuff[i][j] = 0x20;
						TXHData.POS_Info.POS_CMD_Next = POSConnect_PrintfInfo;
						FrameTop = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];
						len = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9];
						if (FrameTop > 20)
							FrameTop = 20;
						if (len > 32)
							len = 32;
						for (i = 0; i < FrameTop; i++)
							for (j = 0; j < len; j++)
								TXHData.PrintInfo.PrintBuff[i][j] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10 + i * len + j];
						FMItemWrite(CF_PrintInfo, 0);
					}
					break;
					case POSConnect_Print:
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_Print;
						TXHData.PrintRecord.GunNumber = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 8];
						TXHData.PrintRecord.FData.MoneyCNT = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12]);
						TXHData.PrintRecord.FData.OilCNT = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 13] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 14] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 15] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 16]);
						TXHData.PrintRecord.Price = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 17] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 18] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 19]);
						TXHData.PrintRecord.RTIME.Year = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 20];	 // 年
						TXHData.PrintRecord.RTIME.Month = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 21]; // 月
						TXHData.PrintRecord.RTIME.Day = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 22];	 // 日
						TXHData.PrintRecord.RTIME.Hour = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 23];	 // 时
						TXHData.PrintRecord.RTIME.Min = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 24];	 // 分
						TXHData.PrintRecord.RTIME.Sec = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 25];	 // 秒
						if (POS_ConnectRX_Len > 32)
							TXHData.PrintRecord.OrderNumber = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 26] << 24) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 27] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 28] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 29]);
						TXHData.MD_Multiplex_Port_Info.PrintType = PT_Record;
					}
					break;
					case POSConnect_WritePriceTag:
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
						for (MD_Port_Num = 0; MD_Port_Num < 4; MD_Port_Num++)
						{
							if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosPrice1_4)
							{
								if (TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.State.Flag.Online == 1)
								{
									DeviceNumber = (POS_ConnectRX_Len - 14) / 5;
									for (i = 0; i < DeviceNumber; i++)
									{
										TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.Price[i] = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9 + i * 5] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10 + i * 5] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11 + i * 5]);
										TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.Decimal[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12 + i * 5];
									}
									TXHData.MD_Port_Info[MD_Port_Num].GunInfo[0].MB_CMD_Next = Price_MDConnectCmdWriteDecimal;
								}
								break;
							}
						}
						if (MD_Port_Num == 4)
						{
							for (MD_Port_Num = 0; MD_Port_Num < 5; MD_Port_Num++)
							{
								if (TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].POSType == Multiplex_Price)
								{
									TXHData.MD_Multiplex_Port_Info.DevicerCapture = MD_Port_Num;
									if (TXHData.MD_Multiplex_Port_Data.State[MD_Port_Num].Flag.Online == 1)
									{
										DeviceNumber = (POS_ConnectRX_Len - 14) / 5;
										for (i = 0; i < DeviceNumber; i++)
										{
											TXHData.MD_Multiplex_Port_Info.PriceTagData.Price[i] = ((POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 9 + i * 5] << 16) | (POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 10 + i * 5] << 8) | POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 11 + i * 5]);
											TXHData.MD_Multiplex_Port_Info.PriceTagData.Decimal[i] = POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + 12 + i * 5];
										}
										TXHData.MD_Multiplex_Port_Info.MB_CMD_Next[MD_Port_Num] = Price_MDConnectCmdWriteDecimal;
									}
									break;
								}
							}
						}
					}
					break;
					default:
						for (i = 0; i < 50; i++)
							POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + i] = 0;
						break;
					}
				}
				else
				{
					for (i = 0; i < 50; i++)
						POS_Connect_RX_Buff[(WifiLenOffset + TimeLenOffset) + i] = 0;
					TXHData.PCMail_RX_Len = 0;
					break;
				}
			}
			else
			{
				TXHData.PCMail_RX_Len = 0;
				break;
			}
			if (TXHData.PCMail_RX_Len)
			{
				TimeLenOffset = 0;
				for (i = 0; i < TXHData.PCMail_RX_Len; i++)
				{
					POS_Connect_RX_Buff[(WifiLenOffset) + i] = POS_Connect_RX_Buff[WifiLenOffset + POS_ConnectRX_Len + 2 + i];
				}
			}
		}
		for (i = TXHData.PCMail_RX_Len; i < 40; i++)
		{
			POS_Connect_RX_Buff[i] = 0;
		}
	}
	else // 指令模式
	{
		switch (TXHData.POS_Info.NetType)
		{
		case POS_Net_Typ_4G_GM5:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case GM5_ENTM:
				{
					TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_Model_Set_1;
					TXHData.HeartbeatTimer.TimerCount = 0;
					TXHData.HeartbeatTimer.Flag = 1;
				}
				break;
				case GM5_Model_Set_1:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "a");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_Model_Set_2;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_Model_Set_2:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "ok");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_Rec;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_Rec:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_HEARTEN;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_HEARTEN:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_UARTFL;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_UARTFL:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_LinkMode;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_APN:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_LinkMode;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_LinkMode:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						if (TXHData.HardwareVersion > 24) // 新的硬件版本，从这开始，所有的模块使用主芯片生成IMEI码
						{
							TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_GetICCID;
						}
						else
						{
							TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_GetIMEI;
						}
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_GetIMEI:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "IMEI:");
					if (Temp16)
					{
						for (i = 0; i < 20; i++)
							TXHData.POSData.WirelessData.IMEI[i] = 0;
						for (i = 0; i < 15; i++)
							TXHData.POSData.WirelessData.IMEI[5 + i] = POS_Connect_RX_Buff[Temp16 + 4 + i];
						FMItemWrite(CF_POSData, 0);
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_GetICCID;
					}
				}
				break;
				case GM5_GetICCID:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "ICCID:");
					if (Temp16)
					{
						for (i = 0; i < 20; i++)
							TXHData.ICCID[i] = 0;
						for (i = 0; i < 20; i++)
							TXHData.ICCID[i] = POS_Connect_RX_Buff[Temp16 + 5 + i];
						// FMItemWrite(CF_,0);
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_SOCKET;
					}
				}
				break;
				case GM5_SOCKET:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_CSQ;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case GM5_CSQ:
				{
					if (TXHData.POS_Info.WiFiRSSI)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_Save;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
					Temp16 = mystrstr(POS_Connect_RX_Buff, "CSQ:");
					if (Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POS_Info.WiFiRSSI = MD_Connect_BCDTou64(((POS_Connect_RX_Buff[Temp16 + 4] - 0x30) << 4) | (POS_Connect_RX_Buff[Temp16 + 5] - 0x30));
						Temp16 = mystrstr(POS_Connect_RX_Buff, ",");
						if (Temp16)
						{
							if (POS_Connect_RX_Buff[Temp16 + 1] >= 0x30)
								TXHData.POS_Info.WiFiChannel = MD_Connect_BCDTou64(((POS_Connect_RX_Buff[Temp16] - 0x30) << 4) | (POS_Connect_RX_Buff[Temp16 + 1] - 0x30));
							else
								TXHData.POS_Info.WiFiChannel = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Temp16] - 0x30);
						}
					}
				}
				break;
				case GM5_Save:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.WorkMode = 1;
						TXHData.HeartbeatTimer.TimerCountMax = 1000;
					}
				}
				break;
				case GM5_RESET:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_ENTM;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				}
			}
		};
		break;
		case POS_Net_Typ_4G_L510:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case L510_ATRec:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						//								for(i = 0;i < 20;i ++)
						//									TXHData.POSData.WirelessData.IMEI[i] = 0;
						// TXHData.HeartbeatTimer.TimerCount = 0;
						// TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_IMEI;
					}
				}
				break;
				case L510_IMEI:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "\"");
					if (Temp16)
					{
						//								for(i = 0;i < 20;i ++)
						//									TXHData.POSData.WirelessData.IMEI[i] = 0;
						//								for(i = 0;i < 15;i ++)
						//									TXHData.POSData.WirelessData.IMEI[5 + i] = POS_Connect_RX_Buff[Temp16 + i];
						//								FMItemWrite(CF_POSData,0);
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_ICPIN;
					}
				}
				break;
				case L510_SetGPSMode:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_ICPIN;
					}
				}
				break;
				case L510_ICPIN:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "READY");

					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_ICCID;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case L510_ICCID:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "ICCID:");
					if (Temp16)
					{
						for (i = 0; i < 20; i++)
							TXHData.ICCID[i] = 0;
						for (i = 0; i < 15; i++)
							TXHData.ICCID[5 + i] = POS_Connect_RX_Buff[Temp16 + 5 + i];
						// FMItemWrite(CF_,0);
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_RSSI;
					}
				}
				break;
				case L510_RSSI:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "CSQ:");
					if (Temp16)
					{
						if (TXHData.POS_Info.WiFiRSSI)
						{
							TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_Model_NET;
						}
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POS_Info.WiFiRSSI = MD_Connect_BCDTou64(((POS_Connect_RX_Buff[Temp16 + 4] - 0x30) << 4) | (POS_Connect_RX_Buff[Temp16 + 5] - 0x30));
					}
				}
				break;
				case L510_Model_NET:
				{
					//							Temp16 = mystrstr(POS_Connect_RX_Buff,"OK");
					//							if(Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_NETOPEN;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case L510_APN:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_NETOPEN;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case L510_NETOPEN:
				{
					//							Temp16 = mystrstr(POS_Connect_RX_Buff,"OK");
					//							if(Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_SOCKET;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case L510_SOCKET:
				{
					TXHData.POSNetSetState.Flag.WorkMode = 1;
					TXHData.HeartbeatTimer.TimerCountMax = 1000;
				}
				break;
				case L510_AT:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_RESET;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case L510_RESET:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_ATRec;
						//								TXHData.HeartbeatTimer.TimerCount = 0;
						//								TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				}
			}
		};
		break;
		case POS_Net_Typ_WiFi:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case WIFI_ATRec:
				{
					//							Temp16 = mystrstr(POS_Connect_RX_Buff,"OK");
					//							if(Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = WIFI_WifiWSSSID;
					}
				}
				break;
				case WIFI_WifiWSSSID:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = WIFI_WifiRSSI;
					}
				}
				break;
				case WIFI_WifiRSSI:
				{
					//							Temp16 = mystrstr(POS_Connect_RX_Buff,"atus:");
					//							if(Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POS_Info.WiFiRSSI = MD_Connect_BCDTou64(((POS_Connect_RX_Buff[Temp16 + 5] - 0x30) << 4) | (POS_Connect_RX_Buff[Temp16 + 6] - 0x30));
						Temp16 = mystrstr(POS_Connect_RX_Buff, ",");
						if (Temp16)
						{
							if (POS_Connect_RX_Buff[Temp16 + 1] >= 0x30)
								TXHData.POS_Info.WiFiChannel = MD_Connect_BCDTou64(((POS_Connect_RX_Buff[Temp16] - 0x30) << 4) | (POS_Connect_RX_Buff[Temp16 + 1] - 0x30));
							else
								TXHData.POS_Info.WiFiChannel = MD_Connect_BCDTou64(POS_Connect_RX_Buff[Temp16] - 0x30);
						}
						TXHData.POSNetSetState.Flag.POSNetCMDNext = WIFI_WifiSOCKET;
					}
				}
				break;
				case WIFI_WifiSOCKET:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						//								TXHData.HeartbeatTimer.TimerCount = 0;
						//								TXHData.HeartbeatTimer.Flag = 1;
						//								STM32CPU.v.id[0] = *(u32*)0x1fff7a10;
						//								STM32CPU.v.id[1] = *(u32*)(0x1fff7a10 + 4);
						//								STM32CPU.v.id[2] = *(u32*)(0x1fff7a10 + 8);
						//								for(i = 0;i < 20;i ++)
						//									TXHData.POSData.WirelessData.IMEI[i] = 0;
						//					//			for(i = 0;i < 12;i ++)
						//					//				TXHData.POSData.WirelessData.IMEI[i+8] = STM32CPU.v.byte[i];
						//								sprintf(&TXHData.POSData.WirelessData.IMEI[0],"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%",
						//																												STM32CPU.v.byte[0],STM32CPU.v.byte[2],STM32CPU.v.byte[4],STM32CPU.v.byte[5],STM32CPU.v.byte[6],
						//																												STM32CPU.v.byte[7],STM32CPU.v.byte[8],STM32CPU.v.byte[9],STM32CPU.v.byte[10],STM32CPU.v.byte[11]);
						//								if(FMItemWrite(CF_POSData,0))
						//									BEEP = 0;
						TXHData.POSNetSetState.Flag.WorkMode = 1;
						TXHData.HeartbeatTimer.TimerCountMax = 1000;
					}
				}
				break;
				case WIFI_WifiRST:
				{
					//							Temp16 = mystrstr(POS_Connect_RX_Buff,"OK");
					//							if(Temp16)
					{
						TXHData.POSNetSetState.Flag.WorkMode = 0;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = WIFI_ATRec;
						//								TXHData.POSNetSetState.Flag.POSNetSetNeedFlag = 0;
						TXHData.POSReLinkTimer.Flag = 0;
						TXHData.POSReLinkTimer.TimerCount = 0;
					}
				}
				break;
				}
			}
		};
		break;
		case POS_Net_Typ_WAN:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case USRK3_ENTM:
				{
					//							Temp16 = mystrstr(POS_Connect_RX_Buff,"OK");
					//							if(Temp16)
					//							{
					//								STM32CPU.v.id[0] = *(u32*)0x1fff7a10;
					//								STM32CPU.v.id[1] = *(u32*)(0x1fff7a10 + 4);
					//								STM32CPU.v.id[2] = *(u32*)(0x1fff7a10 + 8);
					//								for(i = 0;i < 20;i ++)
					//									TXHData.POSData.WirelessData.IMEI[i] = 0;
					//					//			for(i = 0;i < 12;i ++)
					//					//				TXHData.POSData.WirelessData.IMEI[i+8] = STM32CPU.v.byte[i];
					//								sprintf(&TXHData.POSData.WirelessData.IMEI[0],"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%",
					//																												STM32CPU.v.byte[0],STM32CPU.v.byte[2],STM32CPU.v.byte[4],STM32CPU.v.byte[5],STM32CPU.v.byte[6],
					//																												STM32CPU.v.byte[7],STM32CPU.v.byte[8],STM32CPU.v.byte[9],STM32CPU.v.byte[10],STM32CPU.v.byte[11]);
					//								if(FMItemWrite(CF_POSData,0))
					//									BEEP = 0;
					//								TXHData.POSNetSetState.Flag.WorkMode = 1;
					//								TXHData.HeartbeatTimer.TimerCountMax = 1000;
					//								}
					//							else
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_Model_Set_1;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case USRK3_Model_Set_1:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "a");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_Model_Set_2;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case USRK3_Model_Set_2:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "ok");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_Rec;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case USRK3_Rec:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_DHCP;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case USRK3_DHCP:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_GetIP;
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
					}
				}
				break;
				case USRK3_GetIP:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "DHCP,");
					if (Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						for (i = 0; i < 20; i++)
							TXHData.POS_Info.IP[i] = POS_Connect_RX_Buff[Temp16 + 4 + i];
						Temp16 = mystrstr(TXHData.POS_Info.IP, ",");
						if (Temp16)
						{
							for (i = 0; i < 2; i++)
								TXHData.POS_Info.IP[i + Temp16 - 1] = 0;
						}
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_SOCKET;
						TXHData.DisplayOn = 1;
					}
				}
				break;
				case USRK3_SOCKET:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_GetLinkState;
					}
				}
				break;
				case USRK3_GetLinkState:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						TXHData.HeartbeatTimer.TimerCount = 0;
						TXHData.HeartbeatTimer.Flag = 1;
						TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_RST;
					}
				}
				break;
				case USRK3_RST:
				{
					Temp16 = mystrstr(POS_Connect_RX_Buff, "OK");
					if (Temp16)
					{
						//								STM32CPU.v.id[0] = *(u32*)0x1fff7a10;
						//								STM32CPU.v.id[1] = *(u32*)(0x1fff7a10 + 4);
						//								STM32CPU.v.id[2] = *(u32*)(0x1fff7a10 + 8);
						//								for(i = 0;i < 20;i ++)
						//									TXHData.POSData.WirelessData.IMEI[i] = 0;
						//					//			for(i = 0;i < 12;i ++)
						//					//				TXHData.POSData.WirelessData.IMEI[i+8] = STM32CPU.v.byte[i];
						//								sprintf(&TXHData.POSData.WirelessData.IMEI[0],"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%",
						//																												STM32CPU.v.byte[0],STM32CPU.v.byte[2],STM32CPU.v.byte[4],STM32CPU.v.byte[5],STM32CPU.v.byte[6],
						//																												STM32CPU.v.byte[7],STM32CPU.v.byte[8],STM32CPU.v.byte[9],STM32CPU.v.byte[10],STM32CPU.v.byte[11]);
						//								if(FMItemWrite(CF_POSData,0))
						//									BEEP = 0;
						TXHData.POSNetSetState.Flag.WorkMode = 1;
						TXHData.HeartbeatTimer.TimerCountMax = 1000;
					}
				}
				break;
				}
			};
			break;
		}
		break;
		}
		TXHData.PCMail_RX_Len = 0;
		for (i = 0; i < 100; i++)
			POS_Connect_RX_Buff[i] = 0;
	}
}
u16 POS_ConnectTXTask(u8 POS_Connect_Typ, u8 GunNum, u8 POS_Connect_Com) // 数据发送任务
{
	u16 i = 0, k = 0, j = 0;
	u8 Encrypt_Flag1 = 0;
	u8 Encrypt_Flag2 = 0;
	u64 Temp = 0;
	u16 len = 0, lenTemp = 0, TxLenOffset = 0;
	u64 CRCTemp = 0;
	u8 *PBuff;
	u8 Char_Buff[30];
	u16 MD_Port_Num = 0, DeviceNumber = 0;

	for (i = 0; i < 100; i++)
		POS_Connect_TX_Buff[i] = 0;
	if (TXHData.POSReLinkTimer.Flag && TXHData.POS_Info.ConnectType != POS_Connect_Typ_Station) // 站级)
	{
		TXHData.POSReLinkTimer.Flag = 0;
		TXHData.POSNetSetState.Flag.WorkMode = 0;
		switch (TXHData.POS_Info.NetType)
		{
		case POS_Net_Typ_WAN:
			TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_ENTM;
			break;
		case POS_Net_Typ_WiFi:
			TXHData.POSNetSetState.Flag.POSNetCMDNext = WIFI_WifiRST;
			break;
		case POS_Net_Typ_4G_GM5:
			TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_ENTM;
			break;
		case POS_Net_Typ_4G_L510:
			TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_AT;
			;
			break;
		}
	}
	if (TXHData.POSNetSetState.Flag.WorkMode == 1) // 透传模式
	{
		if (TXHData.POSCutTimer.Flag == 1)
		{
			if (TXHData.POS_Info.Link_Flag == 1)
			{
				for (MD_Port_Num = 0; MD_Port_Num < 4; MD_Port_Num++)
				{
					for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
					{
						if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.Online == 1)
						{
							TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay = 1;
							if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateRecords == 1) // 慎重，非油机设备不要用这个标志
							{
								TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateRecords = 0;
								TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].CTOTAL = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CTOTAL;
								TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].FData = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].FData;
								TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].GunNumber = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
								TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].Price = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price;
								TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME = TXHData.CTIME;
								TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].OrderNumber = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].OrderNumber;
								TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].OrderNumber = 0;
								for (i = 0; i < 6; i++)
									TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].CardNum[i] = TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].AssociatedDevices.location].CardNumber[i];
								for (i = 0; i < 6; i++)
									TXHData.MD_Port_Info[TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].AssociatedDevices.Port].GunInfo[TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].AssociatedDevices.location].CardNumber[i] = 0;

								AT45DBItemWrite(CA_PREXDATA, TXHData.PREXDATA_WaitUpNummber / 5);
								FMItemWrite(CF_PREXDATA_TTC, 0);
								if (TXHData.PREXDATA_WaitUpNummber < TXHData.OfflineAuthorizeNumberMax)
									TXHData.PREXDATA_WaitUpNummber++;
								FMItemWrite(CF_PREXDATA_WaitUpNummber, 0);
							}
						}
					}
					FMItemWrite(CF_MD_Port_Data, MD_Port_Num);
				}
				if (TXHData.POS_Info.NetType == POS_Net_Typ_WAN || TXHData.POS_Info.NetType == POS_Net_Typ_4G_L510)
					POS_LinkA_Out = 0;
				TXHData.POS_Info.Link_Flag = 0;
				TXHData.POS_Info.POS_CMD_Next = POSConnect_SynchronizationTime;
				//			EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_SynchronizationTime,Message_Priority_3);//重新同步时间
			}
		}
		if (POS_Connect_TX_Flag == 1)
		{
			while (Encrypt_Flag2 == 0)
			{ // 不能使用原始数据
				TXHData.RNGData = RNG_GetRandomNumber();
				// TXHData.RNGData = 0x12345678;
				Encrypt_Flag1 = ((TXHData.RNGData >> 16) & 0x0f) % 2;
				Encrypt_Flag2 = (TXHData.RNGData & 0x0f) / 2;
			}
			if (TXHData.POS_Info.NetType == POS_Net_Typ_WiFi && TXHData.POS_Info.ConnectType != POS_Connect_Typ_Station)
			{
				TxLenOffset = 7;
				POS_Connect_TX_Buff[0] = 0x55;
				POS_Connect_TX_Buff[1] = 0xFD;
				POS_Connect_TX_Buff[2] = 0xAA;
				POS_Connect_TX_Buff[3] = 0x00;
				POS_Connect_TX_Buff[4] = 0x00;
				POS_Connect_TX_Buff[5] = 0x61;
				POS_Connect_TX_Buff[6] = 0x00;
			}
			POS_Connect_TX_Buff[TxLenOffset + 0] = 0xfa; // 帧头
			POS_Connect_TX_Buff[TxLenOffset + 1] = TXHData.CTIME.Year;
			POS_Connect_TX_Buff[TxLenOffset + 2] = TXHData.CTIME.Month;
			POS_Connect_TX_Buff[TxLenOffset + 3] = TXHData.CTIME.Day;
			POS_Connect_TX_Buff[TxLenOffset + 4] = TXHData.CTIME.Hour;
			POS_Connect_TX_Buff[TxLenOffset + 5] = TXHData.CTIME.Min;
			POS_Connect_TX_Buff[TxLenOffset + 6] = TXHData.CTIME.Sec;
			for (i = 0; i < 4; i++)
				POS_Connect_TX_Buff[TxLenOffset + 9 + i] = TXHData.RNGData >> (8 * (3 - i));

			if (TXHData.POS_Info.ConnectType == POS_Connect_Typ_Station) // 站级
			{
				POS_Connect_TX_Buff[TxLenOffset + 13] = POS_Connect_Com;
				len = TxLenOffset + 8 + 6;
			}
			else // 中心
			{
				if (POS_LinkA || (TXHData.BoardType == 0) || TXHData.POS_Info.NetType == POS_Net_Typ_WAN || TXHData.POS_Info.NetType == POS_Net_Typ_4G_L510)
				{
					for (i = 0; i < 20; i++)
						POS_Connect_TX_Buff[TxLenOffset + 13 + i] = TXHData.POSData.WirelessData.IMEI[i];
					for (i = 0; i < 10; i++)
						POS_Connect_TX_Buff[TxLenOffset + 33 + i] = TXHData.GPSData.Buff[i];
					POS_Connect_TX_Buff[TxLenOffset + 43] = POS_Connect_Com;
					len = TxLenOffset + 38 + 6;
				}
				else
				{
					TXHData.POSCutTimer.Flag = 1;
					return 0;
				}
			}
			if (len)
			{
				TXHData.DelayDetectionTimer.ON_OFF = 1;
				TXHData.POS_TX_CMDNow = POS_Connect_Com;
				switch (POS_Connect_Com)
				{
				case POSConnect_SynchronizationTime:
				case POSConnect_Config:
				case POSConnect_ChangePrice:
				case POSConnect_DisAuthorize:
				case POSConnect_Authorize:
				{
				}
				break;
				case POSConnect_BoxVersion:
				{
					TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
					for (i = 0; i < 10; i++)
						POS_Connect_TX_Buff[len + i] = BoxVersion[i];
					len += 10;
					POS_Connect_TX_Buff[len] = TXHData.POSData.WhiteListVersion;
					len++;
				}
				break;
				case POSConnect_FuelData:
				{
					if (TXHData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag == 1)
					{
						__set_FAULTMASK(1);
						NVIC_SystemReset();
					}
					for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Port_Num_Top; MD_Port_Num++)
					{
						if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosJP || TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosBlueSky ||
							TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosLY || TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosDart ||
							TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosYGao || TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosHongYang ||
							TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosLanFeng || TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosSSLan ||
							TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosBlueSkyPlus)
						{
							POS_Connect_TX_Buff[len] = 0x01; // 设备类型  油枪数据s
							len += 3;						 // 预留长度字节位置
							lenTemp = len;					 // 记录数据块起始位置。用来计算数据块长度长度

							POS_Connect_TX_Buff[len] = 2; // 无数据长度
							len += 1;
							POS_Connect_TX_Buff[len] = 29; // 有数据长度
							len += 1;
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
							{
								POS_Connect_TX_Buff[len] = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
								len += 1;
								POS_Connect_TX_Buff[len] = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.State;
								len += 1;
								if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay == 1 || TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateRecords == 1 || TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.Start_Flag == 1)
								{
									for (i = 0; i < 4; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].OrderNumber >> ((3 - i) * 8);
									len += 4;
									for (i = 0; i < 4; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].FData.OilCNT >> ((3 - i) * 8);
									len += 4;
									for (i = 0; i < 4; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].FData.MoneyCNT >> ((3 - i) * 8);
									len += 4;
									for (i = 0; i < 3; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Price >> ((2 - i) * 8);
									len += 3;
									for (i = 0; i < 6; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CTOTAL.TotalLit >> ((5 - i) * 8);
									len += 6;
									for (i = 0; i < 6; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CTOTAL.TotalMoney >> ((5 - i) * 8);
									len += 6;
								}
							}
							POS_Connect_TX_Buff[lenTemp - 2] = (len - lenTemp) >> 8;
							POS_Connect_TX_Buff[lenTemp - 1] = (len - lenTemp) & 0xff;
						}
						else if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosYWY)
						{
							POS_Connect_TX_Buff[len] = 0x02;
							len += 3;
							lenTemp = len;
							for (DeviceNumber = 0; DeviceNumber < TXHData.TankNumTop; DeviceNumber++)
							{
								POS_Connect_TX_Buff[len] = DeviceNumber + 1;
								len += 1;
								POS_Connect_TX_Buff[len] = TXHData.TankState[MD_Port_Num][DeviceNumber].State;
								len += 1;
								for (i = 0; i < 16; i++)
									POS_Connect_TX_Buff[i + len] = TXHData.TankData[MD_Port_Num][DeviceNumber].Buff[i];
								len += 16;
							}
							POS_Connect_TX_Buff[lenTemp - 2] = (len - lenTemp) << 8;
							POS_Connect_TX_Buff[lenTemp - 1] = (len - lenTemp) & 0xff;
						}
						else if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosPLC)
						{
							POS_Connect_TX_Buff[len] = 0x07;
							len += 1;
							POS_Connect_TX_Buff[len] = 1;
							len += 1;
							POS_Connect_TX_Buff[len] = 59;
							len += 1;
							POS_Connect_TX_Buff[len] = TXHData.CNGPLCState.State;
							len += 1;
							for (i = 0; i < 58; i++)
								POS_Connect_TX_Buff[i + len] = TXHData.CNGPLCData.Buff[i];
							len += 58;
						}
						else if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosRFID)
						{
							POS_Connect_TX_Buff[len] = 0x03;
							len += 3;
							lenTemp = len;
							POS_Connect_TX_Buff[len] = 2; // 无数据长度
							len += 1;
							POS_Connect_TX_Buff[len] = 17; // 有数据长度
							len += 1;
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[MD_Port_Num].PortData.DeviceNumber; DeviceNumber++)
							{
								POS_Connect_TX_Buff[len] = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunNummber;
								len += 1;
								POS_Connect_TX_Buff[len] = TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.State;
								len += 1;
								if (TXHData.MD_Port_Data[MD_Port_Num].GunData[DeviceNumber].GunState.Flag.UpdateDisplay == 1)
								{
									for (i = 0; i < 10; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CardNumber[i];
									len += 10;
									for (i = 0; i < 2; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].CardPSWD[i];
									len += 2;
									for (i = 0; i < 3; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].GunInfo[DeviceNumber].Mileage >> ((2 - i) * 8);
									len += 3;
								}
							}
							POS_Connect_TX_Buff[lenTemp - 2] = (len - lenTemp) << 8;
							POS_Connect_TX_Buff[lenTemp - 1] = (len - lenTemp) & 0xff;
						}
						else if (TXHData.MD_Port_Data[MD_Port_Num].PortData.POSType == PosPrice1_4)
						{
							POS_Connect_TX_Buff[len] = PosPrice1_4;
							len += 3;
							lenTemp = len;
							POS_Connect_TX_Buff[len] = 1; // 无数据长度
							len += 1;
							POS_Connect_TX_Buff[len] = 1 + TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.PriceNumber * 3; // 有数据长度
							len += 1;
							POS_Connect_TX_Buff[len] = TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.State.State;
							len += 1;
							for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.PriceNumber; DeviceNumber++)
							{
								if (TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.State.Flag.UpdateDisplay == 1)
								{
									for (i = 0; i < 3; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.MD_Port_Info[MD_Port_Num].PriceTagData.Price[DeviceNumber] >> ((2 - i) * 8);
									len += 3;
								}
							}
							POS_Connect_TX_Buff[lenTemp - 2] = (len - lenTemp) << 8;
							POS_Connect_TX_Buff[lenTemp - 1] = (len - lenTemp) & 0xff;
						}
					}
					if (TXHData.MD_Multiplex_Port_Data.DeviceNumber > 0)
					{
						for (MD_Port_Num = 0; MD_Port_Num < TXHData.MD_Multiplex_Port_Data.DeviceNumber - 1; MD_Port_Num++)
						{ /*设备类型：00无;04打印机;06液位仪;05单价牌*/
							if (TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].POSType == Multiplex_Print)
							{
								POS_Connect_TX_Buff[len] = Multiplex_Print;
								len += 1;
								POS_Connect_TX_Buff[len] = 1;
								len += 1;
								POS_Connect_TX_Buff[len] = TXHData.MD_Multiplex_Port_Info.State[MD_Port_Num].State;
								len += 1;
							}
							if (TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].POSType == Multiplex_YWY)
							{
								POS_Connect_TX_Buff[len] = Multiplex_YWY;
								len += 1;
								POS_Connect_TX_Buff[len] = TXHData.TankNumTop;
								len += 1;
								POS_Connect_TX_Buff[len] = 18;
								len += 1;
								for (DeviceNumber = 0; DeviceNumber < TXHData.TankNumTop; DeviceNumber++)
								{
									POS_Connect_TX_Buff[len] = DeviceNumber + 1;
									len += 1;
									POS_Connect_TX_Buff[len] = TXHData.TankState[4][DeviceNumber].State;
									len += 1;
									for (i = 0; i < 16; i++)
										POS_Connect_TX_Buff[i + len] = TXHData.TankData[4][DeviceNumber].Buff[i];
									len += 16;
								}
							}
							else if (TXHData.MD_Multiplex_Port_Data.PortData[MD_Port_Num].POSType == Multiplex_Price)
							{
								POS_Connect_TX_Buff[len] = Multiplex_Price;
								len += 3;
								lenTemp = len;
								POS_Connect_TX_Buff[len] = 1; // 无数据长度
								len += 1;
								POS_Connect_TX_Buff[len] = 1 + TXHData.MD_Multiplex_Port_Info.PriceTagData.PriceNumber * 3; // 有数据长度
								len += 1;
								POS_Connect_TX_Buff[len] = TXHData.MD_Multiplex_Port_Data.State[MD_Port_Num].State;
								len += 1;
								for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Multiplex_Port_Info.PriceTagData.PriceNumber; DeviceNumber++)
								{
									if (TXHData.MD_Multiplex_Port_Data.State[MD_Port_Num].Flag.UpdateDisplay == 1)
									{
										for (i = 0; i < 3; i++)
											POS_Connect_TX_Buff[i + len] = TXHData.MD_Multiplex_Port_Info.PriceTagData.Price[DeviceNumber] >> ((2 - i) * 8);
										len += 3;
									}
								}
								POS_Connect_TX_Buff[lenTemp - 2] = (len - lenTemp) << 8;
								POS_Connect_TX_Buff[lenTemp - 1] = (len - lenTemp) & 0xff;
							}
						}
					}
				}
				break;
				case POSConnect_BoxROMownload:
				{
					FrameTimeout++;
					if (FrameTimeout < 5 && TXHData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag == 0)
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_BoxROMownload;
					}
					else
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
						if (TXHData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag == 0)
							TXHData.ROM_UpData_ProgressBar = 0xFF; // 失败
					}
					POS_Connect_TX_Buff[len] = (FrameNow >> 8) & 0xff;
					POS_Connect_TX_Buff[len + 1] = FrameNow & 0xff;
					len += 2;
				}
				break;
				case POSConnect_WhiteList:
				{
					FrameTimeout++;
					if (FrameTimeout < 5)
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_WhiteList;
					}
					else
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
					}
					POS_Connect_TX_Buff[len] = (FrameNow >> 8) & 0xff;
					POS_Connect_TX_Buff[len + 1] = FrameNow & 0xff;
					len += 2;
				}
				break;
				case POSConnect_DeviceVersion:
				{
					TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
					POS_Connect_TX_Buff[len] = TXHData.ROM_UpData_Port;
					len++;
					for (DeviceNumber = 0; DeviceNumber < TXHData.MD_Port_Data[TXHData.ROM_UpData_Port - 1].PortData.DeviceNumber; DeviceNumber++)
					{
						if (TXHData.MD_Port_Info[TXHData.ROM_UpData_Port - 1].GunInfo[DeviceNumber].GunVersion.VersionFindFlag == 1)
						{
							POS_Connect_TX_Buff[len] = TXHData.MD_Port_Data[TXHData.ROM_UpData_Port - 1].GunData[DeviceNumber].GunNummber;
							len += 1;
							for (i = 0; i < 10; i++)
								POS_Connect_TX_Buff[len + i] = TXHData.MD_Port_Info[TXHData.ROM_UpData_Port - 1].GunInfo[DeviceNumber].GunVersion.Version[i];
							len += 10;
						}
					}
				}
				break;
				case POSConnect_DeviceROMownload:
				{
					FrameTimeout++;
					if (FrameTimeout < 5 && TXHData.MD_Port_Data[TXHData.ROM_UpData_Port - 1].PortData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag == 0)
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_DeviceROMownload;
						//					EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_BoxROMownload,Message_Priority_2);
					}
					else
					{
						TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
						if (TXHData.MD_Port_Data[TXHData.ROM_UpData_Port - 1].PortData.ROM_UpData.ROM_UpData_State.Flag.Update_Flag == 0)
							TXHData.ROM_UpData_ProgressBar = 0xFF; // 失败
					}
					POS_Connect_TX_Buff[len] = TXHData.ROM_UpData_Port;
					POS_Connect_TX_Buff[len + 1] = (FrameNow >> 8) & 0xff;
					POS_Connect_TX_Buff[len + 2] = FrameNow & 0xff;
					len += 3;
				}
				break;
				case POSConnect_PREXDATAUp:
				{
					//				EnQueue(&TXHData.POS_TX_MessageQueue,POSConnect_PREXDATAUp,Message_Priority_3);
					TXHData.DisplayOn = 1;
					POS_Connect_TX_Buff[len] = (TXHData.PREXDATA_WaitUpNummber / 10) >> 8; // 帧特征
					len += 1;
					POS_Connect_TX_Buff[len] = TXHData.PREXDATA_WaitUpNummber / 10; // 帧特征
					len += 1;
					if (TXHData.PREXDATA_WaitUpNummber > 10)
						Temp = 10;
					else
						Temp = TXHData.PREXDATA_WaitUpNummber;
					TXHData.PREXDATA_Upload.PREXDATA_NowWaitUpNummber = TXHData.PREXDATA_WaitUpNummber;
					TXHData.PREXDATA_Upload.PREXDATA_NowFrame = TXHData.PREXDATA_WaitUpNummber / 10;
					TXHData.PREXDATA_Upload.PREXDATA_NowFrameLen = Temp;
					FMItemWrite(CF_PREXDATA_Upload, 0);
					POS_Connect_TX_Buff[len] = Temp; // 本次传输条数
					len += 1;
					POS_Connect_TX_Buff[len] = 40;
					len += 1;
					for (i = 0; i < Temp; i++)
					{
						if (TXHData.PREXDATA_WaitUpNummber > 0)
							AT45DBItemRead(CA_PREXDATA, (TXHData.PREXDATA_WaitUpNummber - 1 - i) / 5);
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].GunNumber;
						len += 1;
						for (k = 0; k < 4; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].FData.OilCNT >> ((3 - k) * 8);
						len += 4;
						for (k = 0; k < 4; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].FData.MoneyCNT >> ((3 - k) * 8);
						len += 4;
						for (k = 0; k < 3; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].Price >> ((2 - k) * 8);
						len += 3;
						for (k = 0; k < 6; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].CTOTAL.TotalLit >> ((5 - k) * 8);
						len += 6;
						for (k = 0; k < 6; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].CTOTAL.TotalMoney >> ((5 - k) * 8);
						len += 6;
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME.Year;
						len += 1;
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME.Month;
						len += 1;
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME.Day;
						len += 1;
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME.Hour;
						len += 1;
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME.Min;
						len += 1;
						POS_Connect_TX_Buff[len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].RTIME.Sec;
						len += 1;
						for (k = 0; k < 4; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].OrderNumber >> ((3 - k) * 8);
						len += 4;
						for (k = 0; k < 6; k++)
							POS_Connect_TX_Buff[k + len] = TXHData.PREXDATA[(TXHData.PREXDATA_WaitUpNummber - 1 - i) % 5].CardNum[k];
						len += 6;
					}
				}
				break;
				case POSConnect_PrintfInfo:
				{
					TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
					POS_Connect_TX_Buff[len] = 0x59;
					len += 1;
				}
				break;
				case POSConnect_Print:
				{
					TXHData.POS_Info.POS_CMD_Next = POSConnect_FuelData;
					POS_Connect_TX_Buff[len] = 0x59;
					len += 1;
				}
				break;
				}
				POS_Connect_TX_Buff[TxLenOffset + 7] = ((len - TxLenOffset) >> 8) & 0xff;
				POS_Connect_TX_Buff[TxLenOffset + 8] = (len - TxLenOffset) & 0xff;

				//			if(TXHData.UDisk_Flag)
				//				Log_Task(&POS_Connect_TX_Buff[TxLenOffset],len - TxLenOffset,4,Info_Issue);

				for (i = 0; i < len - TxLenOffset; i++)
					POS_Connect_TX_Buff[TxLenOffset + 13 + i] = Encrypt_Data(POS_Connect_TX_Buff[TxLenOffset + 13 + i], Encrypt_Flag1, Encrypt_Flag2);

				if (TXHData.UDisk_Flag)
					Log_Task(&POS_Connect_TX_Buff[TxLenOffset], len - TxLenOffset, 4, Info_Issue);
				CRCTemp = CRC_Check(&POS_Connect_TX_Buff[TxLenOffset], len - TxLenOffset); // 校验
				POS_Connect_TX_Buff[len] = (CRCTemp >> 8) & 0xff;
				len++;
				POS_Connect_TX_Buff[len] = CRCTemp & 0xff;
				len++;
				if (TXHData.POS_Info.NetType == POS_Net_Typ_WiFi && TXHData.POS_Info.ConnectType != POS_Connect_Typ_Station)
				{
					POS_Connect_TX_Buff[3] = ((len - 5) >> 8) & 0xff;
					POS_Connect_TX_Buff[4] = (len - 5) & 0xff;
					POS_Connect_TX_Buff[len] = SUMCRC(&POS_Connect_TX_Buff[5], len - 5);
					len++;
				}
				POS_Connect_TX_DMALenSet(len);
				POS_Connect_TX_DMAStart();
				return len;
			}
		}
	}
	else if (TXHData.POSNetSetState.Flag.WorkMode == 0) // 指令模式
	{
		switch (TXHData.POS_Info.NetType)
		{
		case POS_Net_Typ_4G_GM5:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case GM5_ENTM:
				{
					for (i = 0; i < strlen(CMD_Model_NET); i++)
						POS_Connect_TX_Buff[i] = CMD_Model_NET[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.POSNetSetState.Flag.POSNetCMDNext = GM5_Model_Set_1;
					TXHData.HeartbeatTimer.TimerCountMax = 1000;
				}
				break;
				case GM5_Model_Set_1:
				{
					for (i = 0; i < strlen(CMD_Model_Set_1); i++)
						POS_Connect_TX_Buff[i] = CMD_Model_Set_1[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_Model_Set_2:
				{
					for (i = 0; i < strlen(CMD_Model_Set_2); i++)
						POS_Connect_TX_Buff[i] = CMD_Model_Set_2[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_Rec:
				{
					for (i = 0; i < strlen(CMD_ATRec); i++)
						POS_Connect_TX_Buff[i] = CMD_ATRec[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_HEARTEN:
				{
					for (i = 0; i < strlen(CMD_HEARTEN); i++)
						POS_Connect_TX_Buff[i] = CMD_HEARTEN[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_UARTFL:
				{
					for (i = 0; i < strlen(CMD_UARTFL); i++)
						POS_Connect_TX_Buff[i] = CMD_UARTFL[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_APN:
				{
					for (i = 0; i < strlen(CMD_APN); i++)
						POS_Connect_TX_Buff[i] = CMD_APN[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_LinkMode:
				{
					for (i = 0; i < strlen(CMD_LinkMode); i++)
						POS_Connect_TX_Buff[i] = CMD_LinkMode[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_GetIMEI:
				{
					for (i = 0; i < strlen(CMD_IMEI); i++)
						POS_Connect_TX_Buff[i] = CMD_IMEI[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_GetICCID:
				{
					for (i = 0; i < strlen(CMD_ICCID); i++)
						POS_Connect_TX_Buff[i] = CMD_ICCID[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_SOCKET:
				{
					if (TXHData.POS_Info.ConnectType == POS_Connect_Typ_Cloud_Tast) // 测试服务器
					{
						for (i = 0; i < strlen(TsatURL); i++)
							POS_Connect_TX_Buff[i] = TsatURL[i];
					}
					else
					{
						for (i = 0; i < 13; i++)
							POS_Connect_TX_Buff[i] = TsatURL[i];
						//"AT+SOCKA=TCP,test.joyfueling.com,7011\r\n";
						Temp = strlen((const char *)TXHData.POSData.WirelessData.CMD_SOCKA);
						if (Temp)
						{
							for (i = 0; i < Temp; i++)
								POS_Connect_TX_Buff[13 + i] = TXHData.POSData.WirelessData.CMD_SOCKA[i];
							strcat(POS_Connect_TX_Buff, "\r\n\0");
						}

						i = strlen((char *)&POS_Connect_TX_Buff);
					}
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_CSQ:
				{
					for (i = 0; i < strlen(CMD_CSQ); i++)
						POS_Connect_TX_Buff[i] = CMD_CSQ[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case GM5_Save:
				{
					for (i = 0; i < strlen(CMD_Save); i++)
						POS_Connect_TX_Buff[i] = CMD_Save[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 10;
				}
				break;
				case GM5_RESET:
				{
					for (i = 0; i < strlen(CMD_Reset); i++)
						POS_Connect_TX_Buff[i] = CMD_Reset[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 10;
				}
				break;
				}
			}
		};
		break;
		case POS_Net_Typ_4G_L510:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case L510_ATRec:
				{
					for (i = 0; i < strlen(CMD_L510_ATRec); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_ATRec[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.HeartbeatTimer.TimerCountMax = 3000;
				}
				break;
				case L510_IMEI:
				{
					for (i = 0; i < strlen(CMD_L510_IMEI); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_IMEI[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_SetGPSMode:
				{
					for (i = 0; i < strlen(CMD_L510_SetGPSMode); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_SetGPSMode[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_ICPIN:
				{
					for (i = 0; i < strlen(CMD_L510_ICPIN); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_ICPIN[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					// TXHData.HeartbeatTimer.TimerCountMax = 3000;
				}
				break;
				case L510_ICCID:
				{
					for (i = 0; i < strlen(CMD_L510_ICCID); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_ICCID[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_RSSI:
				{
					for (i = 0; i < strlen(CMD_L510_RSSI); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_RSSI[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_Model_NET:
				{
					for (i = 0; i < strlen(CMD_L510_Model_NET); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_Model_NET[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_APN:
				{
					for (i = 0; i < strlen(CMD_L510_APN); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_APN[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_NETOPEN:
				{
					for (i = 0; i < strlen(CMD_L510_NETOPEN); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_NETOPEN[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_SOCKET:
				{
					if (TXHData.POS_Info.ConnectType == POS_Connect_Typ_Cloud_Tast) // 测试服务器
					{
						for (i = 0; i < strlen(CMD_L510_SOCKET); i++)
							POS_Connect_TX_Buff[i] = CMD_L510_SOCKET[i];
					}
					else
					{
						for (i = 0; i < 20; i++)
							POS_Connect_TX_Buff[i] = CMD_L510_SOCKET[i];
						//"AT+SOCKA=TCP,test.joyfueling.com,7011\r\n";
						Temp = strlen((const char *)TXHData.POSData.WirelessData.CMD_SOCKA);
						k = mystrstr(TXHData.POSData.WirelessData.CMD_SOCKA, ",");
						if (Temp)
						{
							for (i = 0; i < k - 1; i++)
								POS_Connect_TX_Buff[20 + i] = TXHData.POSData.WirelessData.CMD_SOCKA[i];
							POS_Connect_TX_Buff[20 + k - 1] = '\"';
							for (i = k; i < Temp + 1; i++)
								POS_Connect_TX_Buff[20 + i] = TXHData.POSData.WirelessData.CMD_SOCKA[i - 1];
							strcat(POS_Connect_TX_Buff, "\r\n\0");
						}

						i = strlen((char *)&POS_Connect_TX_Buff);
					}
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_GetLinkState:
				{
					for (i = 0; i < strlen(CMD_L510_GetLinkState); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_GetLinkState[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case L510_AT:
				{
					if (TXHData.HeartbeatTimer.TimerCountMax == 1001)
						TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_RESET;
					else
						TXHData.HeartbeatTimer.TimerCountMax = 1001;
					for (i = 0; i < strlen(CMD_L510_AT); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_AT[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					/// TXHData.POSNetSetState.Flag.POSNetCMDNext = L510_RESET;
				}
				break;
				case L510_RESET:
				{
					for (i = 0; i < strlen(CMD_L510_RESET); i++)
						POS_Connect_TX_Buff[i] = CMD_L510_RESET[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 15;
				}
				break;
				}
			}
		};
		break;
		case POS_Net_Typ_WiFi:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case WIFI_ATRec:
				{
					TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
					for (i = 0; i < strlen(CMD_ATRec); i++)
						POS_Connect_TX_Buff[i] = CMD_ATRec[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					// TXHData.HeartbeatTimer.TimerCountMax = 1000*10;
				}
				break;
				case WIFI_WifiWSSSID:
				{
					TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
					for (i = 0; i < 100; i++)
						POS_Connect_TX_Buff[i] = 0;
					TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
					{
						//								if(TXHData.POS_Info.ConnectType == POS_Connect_Typ_WifiStation)
						//								{
						//								  TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
						//									for(i = 0;i < strlen(CMD_WifiWSSSID_WIFIStation);i ++)
						//										POS_Connect_TX_Buff[i] = CMD_WifiWSSSID_WIFIStation[i];
						//									POS_Connect_TX_DMALenSet(i);   //设置发送DMA长度
						//									POS_Connect_TX_DMAStart();
						//								  }
						//								else
						{
							for (i = 0; i < 8; i++)
								POS_Connect_TX_Buff[i] = CMD_WifiWSSSID[i];
							for (i = 0; i < strlen((const char *)TXHData.POSData.WirelessData.WiFIName); i++)
								POS_Connect_TX_Buff[8 + i] = TXHData.POSData.WirelessData.WiFIName[i];
							POS_Connect_TX_Buff[8 + i] = ',';
							j = 8 + i + 1;
							for (i = 0; i < strlen((const char *)TXHData.POSData.WirelessData.WiFIPassWord); i++)
								POS_Connect_TX_Buff[j + i] = TXHData.POSData.WirelessData.WiFIPassWord[i];
							strcat(POS_Connect_TX_Buff, "\r\n\0");
							POS_Connect_TX_DMALenSet(strlen((const char *)POS_Connect_TX_Buff)); // 设置发送DMA长度
							POS_Connect_TX_DMAStart();
						}
					}
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 10;
				}
				break;
				case WIFI_WifiRSSI:
				{
					for (i = 0; i < strlen(CMD_WifiRSSI); i++)
						POS_Connect_TX_Buff[i] = CMD_WifiRSSI[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.POSNetSetState.Flag.POSNetCMDNext = WIFI_WifiSOCKET;
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 2;
				}
				break;
				case WIFI_WifiSOCKET:
				{
					switch (TXHData.POS_Info.ConnectType)
					{
					case POS_Connect_Typ_Cloud_Tast:
					{
						TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
						for (i = 0; i < strlen(CMD_WifiSOCKET); i++)
							POS_Connect_TX_Buff[i] = CMD_WifiSOCKET[i];
						POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
						POS_Connect_TX_DMAStart();
					}
					break;
					case POS_Connect_Typ_Cloud:
					{
						for (i = 0; i < 100; i++)
							POS_Connect_TX_Buff[i] = 0;
						TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
						for (i = 0; i < 14; i++)
							POS_Connect_TX_Buff[i] = CMD_WifiSOCKET[i];
						// const char CMD_WifiSOCKET[]="AT+Socket=0,0,test.joyfueling.com,7011\r\n";
						j = strlen((const char *)TXHData.POSData.WirelessData.CMD_SOCKA);
						if (j)
						{
							for (i = 0; i < j; i++)
								POS_Connect_TX_Buff[14 + i] = TXHData.POSData.WirelessData.CMD_SOCKA[i];
							strcat(POS_Connect_TX_Buff, "\r\n\0");
						}
						POS_Connect_TX_DMALenSet(strlen((const char *)POS_Connect_TX_Buff)); // 设置发送DMA长度
						POS_Connect_TX_DMAStart();
					}
					break;
						//								case POS_Connect_Typ_WifiStation:
						//								{
						//								  TXHData.POS_Info.POS_ConnectRXTask_Flag = 0;
						//									for(i = 0;i < strlen(CMD_WifiSOCKET_WIFIStation);i ++)
						//										POS_Connect_TX_Buff[i] = CMD_WifiSOCKET_WIFIStation[i];
						//									POS_Connect_TX_DMALenSet(i);   //设置发送DMA长度
						//									POS_Connect_TX_DMAStart();
						//								  }break;
					}
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 10;
				}
				break;
				case WIFI_WifiRST:
				{
					for (i = 0; i < strlen(CMD_WifiRST); i++)
						POS_Connect_TX_Buff[i] = CMD_WifiRST[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 10;
				}
				break;
				}
			}
		};
		break;
		case POS_Net_Typ_WAN:
		{
			{
				switch (TXHData.POSNetSetState.Flag.POSNetCMDNext)
				{
				case USRK3_ENTM:
				{
					for (i = 0; i < strlen(CMD_Model_NET); i++)
						POS_Connect_TX_Buff[i] = CMD_Model_NET[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.POSNetSetState.Flag.POSNetCMDNext = USRK3_Model_Set_1;
					TXHData.HeartbeatTimer.TimerCountMax = 1000;
				}
				break;
				case USRK3_Model_Set_1:
				{
					for (i = 0; i < strlen(CMD_Model_Set_1); i++)
						POS_Connect_TX_Buff[i] = CMD_Model_Set_1[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_Model_Set_2:
				{
					for (i = 0; i < strlen(CMD_Model_Set_2); i++)
						POS_Connect_TX_Buff[i] = CMD_Model_Set_2[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_Rec:
				{
					for (i = 0; i < strlen(CMD_ATRec); i++)
						POS_Connect_TX_Buff[i] = CMD_ATRec[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_DHCP:
				{
					for (i = 0; i < strlen(CMD_DHCP); i++)
						POS_Connect_TX_Buff[i] = CMD_DHCP[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_GetIP:
				{
					for (i = 0; i < strlen(CMD_GetIP); i++)
						POS_Connect_TX_Buff[i] = CMD_GetIP[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_SOCKET:
				{
					if (TXHData.POS_Info.ConnectType == POS_Connect_Typ_Cloud_Tast) // 测试服务器
					{
						for (i = 0; i < strlen(WlanTsatURL); i++)
							POS_Connect_TX_Buff[i] = WlanTsatURL[i];
					}
					else
					{
						for (i = 0; i < 15; i++)
							POS_Connect_TX_Buff[i] = WlanTsatURL[i];
						//"AT+SOCKB1=TCPC,test.joyfueling.com,7011\r\n"
						j = strlen((const char *)TXHData.POSData.WirelessData.CMD_SOCKA);
						if (j)
						{
							for (i = 0; i < j; i++)
								POS_Connect_TX_Buff[15 + i] = TXHData.POSData.WirelessData.CMD_SOCKA[i];
							strcat(POS_Connect_TX_Buff, "\r\n\0");
						}

						i = strlen((char *)&POS_Connect_TX_Buff);
					}
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_GetLinkState:
				{
					for (i = 0; i < strlen(CMD_GetLinkState); i++)
						POS_Connect_TX_Buff[i] = CMD_GetLinkState[i];
					POS_Connect_TX_DMALenSet(i); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
				}
				break;
				case USRK3_RST:
				{
					for (i = 0; i < sizeof(CMD_Reset); i++)
						POS_Connect_TX_Buff[i] = CMD_Reset[i];
					POS_Connect_TX_DMALenSet(i - 1); // 设置发送DMA长度
					POS_Connect_TX_DMAStart();
					TXHData.HeartbeatTimer.TimerCountMax = 1000 * 10;
				}
				break;
				}
			}
		};
		break;
		}
	}
	return 0;
}
