Forráskód Böngészése

wifi从机(车端),WiFi模块收发数据转换为透传模式,解决等待模块命令时,丢失数据帧问题。
目前没有退出透传模式功能,等待后续CAN信号完善

huang_chao 2 éve
szülő
commit
89daf4be6c
2 módosított fájl, 32 hozzáadás és 4 törlés
  1. 30 4
      src/AppTaskUart1.c
  2. 2 0
      src/AppTaskUart1.h

+ 30 - 4
src/AppTaskUart1.c

@@ -91,6 +91,8 @@ const ATCmdFunc_t Atcmdfunc[] =
 	{AT_CWAUTOCONN, "AT+CWAUTOCONN=0\r\n", at_callbackFunc},  /* 建立Soft Station 模式 */
 	{AT_CWJAP, "AT+CWJAP=", at_callbackFunc},  /* 连接WiFi */
 	{AT_CIPSTART, "AT+CIPSTART=", at_callbackFunc},  /* 连接IP */
+	{AT_CIPMODE, "AT+CIPMODE=1\r\n", at_callbackFunc},  /* 设置透传模式 */
+	{AT_CIPSEND, "AT+CIPSEND\r\n", at_callbackFunc},  /* 开始发送数据 */
 #endif
 	{AT_SEND_DATA, "AT+CIPSEND=0,", at_callbackFunc},
 	{AT_CIFSR, "AT+CIFSR\r\n", at_callbackFunc},        /* 查看IP信息 */
@@ -181,7 +183,7 @@ void wifi_task(void *pvParameters)
 						tcp_server_process_status = TCP_IDLE;
 						wifiAskFlg = false;
 					}
-					else if(strstr((char *)UartDataBuffer,(char *)("+IPD"))) //收到从机的数据
+					else if(strstr((char *)UartDataBuffer, (char *)("+IPD"))) //收到从机的数据
 					{
 						uint8 *retptr = NULL;
 						uint16 TcpDataLen = 0;
@@ -216,14 +218,21 @@ void wifi_task(void *pvParameters)
 							DataSend.DataPtr = NULL;
 						}
 					}
+					else
+					{
+
+					}
 				}
+				/* 解码部分 */
+				wifiDataDecode(UartDataBuffer, ReadLen);
+
 				/* 心跳报文发送 */
 				static uint64 tickcount = 0;
 				if(xTaskGetTickCount() - tickcount > pdMS_TO_TICKS(2000))
 				{
 					tickcount = xTaskGetTickCount();
 					uint16 dataOutLen = 0;
-					uint8 dataOutBuffer[56] = {0};
+					uint8 dataOutBuffer[128] = {0};
 					/* 组包 */
 					dataOutLen = DecodeSlaveBuffer(dataOutBuffer, sizeof(dataOutBuffer),  HEARTBEAT_S);
 					/* 数据发送 */
@@ -379,6 +388,8 @@ static void wifiDataDecode(uint8 *dataIn,uint16 dataLen)
 sint8 tcpSendFunc(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDataLen)
 {
 	sint8 outValue = -1;
+#ifdef AT_CMD_SEND  /* 启用AT指令发送数据 */
+
 	uint8  sendErrConuter= 0;
 	uint16 ReadLen = 0;
 	char AtCmdSend[30] = {0};
@@ -402,7 +413,10 @@ sint8 tcpSendFunc(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDataLen)
 			ret = AtcmdDelayRecvFunc(UART_LPUART1, "SEND OK", 1000);
 			outValue = ret;
 		}
-
+#else
+	/* 透传 */
+	outValue = UART_Send_Data(UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, 100);
+#endif/* #ifdef AT_CMD_SEND  */
 	return outValue;
 }
 /**********************************************************************************************/
@@ -435,7 +449,8 @@ static void wifi_init(uint8 Step)
 			}
 			case 1:
 			{
-				WIFI_CMD_INIT(ATE_0,NULL,0,InitStep,ATRet);
+				//WIFI_CMD_INIT(ATE_0,NULL,0,InitStep,ATRet);
+				InitStep++;
 				break;
 			}
 			case 2: //设置工作模式
@@ -462,6 +477,16 @@ static void wifi_init(uint8 Step)
 				WIFI_CMD_INIT(AT_CIPSTART,wifi_ip_info_init,strlen(wifi_ip_info_init),InitStep,ATRet);
 				break;
 			}
+			case 6:/* 设置透传模式 */
+			{
+				WIFI_CMD_INIT(AT_CIPMODE,NULL,0,InitStep,ATRet);
+				if(0 == ATRet)
+				{
+					vTaskDelay(pdMS_TO_TICKS(2000));
+					AtcmdTransmit(AT_CIPSEND, NULL, 0, &ATRet);
+				}
+				break;
+			}
 			default:
 			{
 				return;
@@ -541,6 +566,7 @@ static sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint1
 		case AT_SET_MODE:
 		case AT_CWAUTOCONN:
 		case AT_CIFSR:
+		case AT_CIPMODE:
 		{
 			if (retptr)
 			{

+ 2 - 0
src/AppTaskUart1.h

@@ -37,6 +37,8 @@ typedef enum
 	AT_CWAUTOCONN,
 	AT_CWJAP,
 	AT_CIPSTART,
+	AT_CIPMODE,
+	AT_CIPSEND,
 	AT_SEND_DATA,
 	AT_CIFSR,     /* 获取IP信息 */
 }ATCmd;