12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- /*
- * @Author : ChenJie
- * @Date : 2022-02-10 11:43:56
- * @Version : V3.0
- * @LastEditors : ChenJie
- * @LastEditTime : 2022-02-23 15:51:23
- * @Description : file content
- * @FilePath : \S32K146_4G\src\AppTaskUart1.c
- */
- /*
- * AppTaskUart2.c
- * 4G的串口函数
- * Created on: 2022年2月10日
- * Author: QiXiang_CHENJIE
- */
- #include "AppTaskUart1.h"
- const ATCmdFunc Atcmdfunc[] = {
- {AT_CMD_TEST, "AT\r\n", at_callbackFunc},
- {AT_SIMREADY, "AT+CPIN?\r\n", at_callbackFunc},
- {AT_GETICCID, "AT+CICCID\r\n", at_callbackFunc},
- {AT_CGREG, "AT+CGREG?\r\n", at_callbackFunc},
- {AT_CSQ, "AT+CSQ\r\n", at_callbackFunc},
- {AT_NETOPEN, "AT+NETOPEN\r\n", at_callbackFunc},
- {AT_CGIP, "AT+CDNSGIP=", at_callbackFunc},
- //{AT_CONNECT, "AT+CIPOPEN=0,\"TCP\",\"120.26.68.165\",14319\r\n", at_callbackFunc},
- {AT_CONNECT, "AT+CIPOPEN=", at_callbackFunc},
- {AT_CONNECTCHK, "AT+CIPOPEN?\r\n", at_callbackFunc},
- {AT_SEND, "AT+CIPSEND=", at_callbackFunc},
- {AT_DISCON, "AT+CIPCLOSE=0\r\n", at_callbackFunc},
- {AT_NETCLOSE, "AT+NETCLOSE\r\n", at_callbackFunc}};
- static process_Tcp gProcess_Tcp_Task = PROCESS_TCP_IDLE;
- #define PROC_TCP_STATE_SWITCH(a) (gProcess_Tcp_Task = a)
- void InitFunc(void);
- sint8 TcpConnectFunc(sint8 *ConnectId);
- sint8 TcpDataSendFunc(sint8 ConnectId);
- sint8 TcpRegisterChkFunc(void);
- void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen);
- void GetUtc8Time(UTC8TimeType *UTC8TimeTcp);
- static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc);
- static sint8 tcpipConnectionSend(uint8 TcpConnectId,uint8 * SendDataPtr,uint16 SendDataLen);
- static void TcpDataInfoRecvHandle(uint8 *DataRecv,uint16 DataRecvLen);
- void Uart_4G_Task(void *pvParameters)
- {
- (void)pvParameters;
- // 4G开机
- Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
- Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
- Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
- _4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
- // LED测试
- Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
- vTaskDelay(pdMS_TO_TICKS(5000));
- uint8 pReadLen = 0;
- InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
- uint32 SendTimerCounter = 0;
- for (;;)
- {
- switch (gProcess_Tcp_Task)
- {
- case PROCESS_TCP_IDLE: //空闲状态
- {
- vTaskDelay(pdMS_TO_TICKS(10));
- if (SocketId < 0)
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
- }
- else if ((TimerCounter -SendTimerCounter)>1000)
- {
- SendTimerCounter = TimerCounter;
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
- //Dio_FlipChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3);
- }
- else if (TimerCounter % 100 == 0)
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_RECV);
- }
- break;
- }
- case PROCESS_TCP_ATSYS:
- {
- sint8 ATRet = -1;
- AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
- if (ATRet == 0)
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
- }
- else
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
- }
- break;
- }
- case PROCESS_TCP_REGCHK: //驻网检查,包括SIM,CPIN检查,ICCID获取
- {
- sint8 RegChkRet = 0;
- RegChkRet = TcpRegisterChkFunc();
- if (RegChkRet > 0) //检查通过,SIM卡已就绪,已进行驻网
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_CONNECT);
- }
- else
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
- }
- break;
- }
- case PROCESS_TCP_CONNECT: //网络连接,包括域名转换
- {
- if (SocketId < 0)
- {
- sint8 ConnectRet = 0;
- ConnectRet = TcpConnectFunc(&SocketId);
- if (ConnectRet > 0)
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
- }
- else
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
- }
- }
- break;
- }
- case PROCESS_TCP_SEND: //网络数据发送
- {
- sint8 SendRet = -1;
- SendRet = TcpDataSendFunc(SocketId);
- if (SendRet == 0)
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
- }
- else
- {
- SocketId = -1;
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
- }
- break;
- }
- case PROCESS_TCP_RECV: //网络数据接收,100ms空闲状态下即可接收
- {
- memset(RX_Buffer[UART_LPUART1],0x00,sizeof(RX_Buffer[UART_LPUART1]));
- UART_Receive_Data(UART_LPUART1,RX_Buffer[UART_LPUART1],&pReadLen,100);
- if(pReadLen>0&&SocketId>=0)
- {
- TcpDataInfoRecvHandle(RX_Buffer[UART_LPUART1],pReadLen);
- }
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
- break;
- }
- case PROCESS_TCP_HEART: //心跳包发送
- {
- break;
- }
- case PROCESS_TCP_SLEEP: //网络休眠状态
- {
- break;
- }
- case PROCESS_TCP_ERROR: //错误状态
- {
- // Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
- // vTaskDelay(pdMS_TO_TICKS(100));
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
- // Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
- break;
- }
- }
- }
- }
- sint8 TcpDataSendFunc(sint8 ConnectId)
- {
- sint8 outValue = -1;
- uint32 pSendDataAddr = 0;
- uint16 DataSendLen = 0;
- memcpy(TcpbattSN, defaultSn, 17);
- TcpDataEncode(&pSendDataAddr, &DataSendLen); //数据组包,malloc申请在里面,pSendData指向申请的地址
- if (DataSendLen == 0)
- {
- return 0; //暂时无数据可以发
- }
- outValue = tcpipConnectionSend(ConnectId,(uint8 *)pSendDataAddr,DataSendLen);//发送函数
- if (pSendDataAddr != 0)
- {
- free((uint8 *)(pSendDataAddr));
- }
- pSendDataAddr = 0;
- return outValue;
- }
- sint8 TcpConnectFunc(sint8 *ConnectId)
- {
- uint8 ConnectStep = 0;
- sint8 ChkState = 0;
- sint8 ATRet = -1;
- while (1)
- {
- switch (ConnectStep)
- {
- case 0: // AT指令同步
- {
- char *ATCmdSend = (char *)("ATE0\r\n");
- uint8 ATCmdSendLen = mstrlen(ATCmdSend);
- uint8 ReadLen = 0;
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- uint8 *retptr = NULL;
- if (ReadLen > 0)
- {
- retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK"));
- if (retptr)
- {
- ConnectStep++;
- }
- else
- {
- ChkState = -ConnectStep;
- return ChkState;
- }
- }
- else
- {
- ChkState = -ConnectStep;
- return ChkState;
- }
- break;
- }
- case 1: // Netopen
- {
- AtcmdTransmit(AT_NETOPEN, NULL, 0, &ATRet);
- if (ATRet == 0)
- {
- ConnectStep++;
- }
- else
- {
- ChkState = -ConnectStep;
- return ChkState;
- }
- break;
- }
- case 2: //连接检查
- {
- AtcmdTransmit(AT_CONNECTCHK, NULL, 0, &ATRet); // ATret返回的值是连接id,如果未连接返回-1
- if (ATRet >= 0)
- {
- *ConnectId = ATRet;
- return 1;
- }
- else
- {
- ConnectStep++;
- *ConnectId = 0;
- }
- break;
- }
- case 3: //域名转换
- {
- char AtCmdSend[30] = {0};
- uint8 AtCmdSendLen = 0;
- AtCmdSendLen = mstrlen(WebSiteName);
- memcpy(AtCmdSend, WebSiteName, AtCmdSendLen);
- memcpy(AtCmdSend + AtCmdSendLen, (char *)CRLF, sizeof(CRLF));
- AtCmdSendLen = AtCmdSendLen + 2;
- AtcmdTransmit(AT_CGIP, AtCmdSend, AtCmdSendLen, &ATRet);
- if (ATRet == 0)
- {
- ConnectStep++;
- }
- else
- {
- ChkState = -ConnectStep;
- return ChkState;
- }
- break;
- }
- case 4: //创建连接
- {
- char AtCmdSend[20] = {0};
- uint8 AtCmdSendTotalLen = 0;
- sprintf(AtCmdSend, "%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp, WebSitePort); //此处需要优化
- AtCmdSendTotalLen = mstrlen(AtCmdSend);
- AtcmdTransmit(AT_CONNECT, AtCmdSend, AtCmdSendTotalLen, &ATRet);
- if (ATRet == 0)
- {
- ConnectStep++;
- }
- else
- {
- ChkState = -ConnectStep;
- return ChkState;
- }
- break;
- }
- default:
- ChkState = ConnectStep;
- return ChkState;
- }
- }
- }
- sint8 TcpRegisterChkFunc(void)
- {
- uint8 RegChkStep = 0;
- sint8 ChkState = 0; //默认为0
- sint8 ATRet = -1;
- while (1)
- {
- switch (RegChkStep)
- {
- case 0: // AT指令同步
- {
- AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
- if (ATRet == 0)
- {
- RegChkStep++;
- }
- else
- {
- ChkState = -RegChkStep;
- return ChkState;
- }
- break;
- }
- case 1: // CPIN检查
- {
- AtcmdTransmit(AT_SIMREADY, NULL, 0, &ATRet);
- if (ATRet == 0)
- {
- RegChkStep++;
- }
- else
- {
- ChkState = -RegChkStep;
- return ChkState;
- }
- break;
- }
- case 2:
- {
- AtcmdTransmit(AT_CGREG, NULL, 0, &ATRet); //驻网检查,返回值1和5是驻网成功
- if (ATRet == 1 || ATRet == 5)
- {
- RegChkStep++;
- }
- else
- {
- ChkState = -RegChkStep;
- return ChkState;
- }
- break;
- }
- default:
- ChkState = RegChkStep;
- return ChkState;
- break;
- }
- }
- }
- void InitFunc(void)
- {
- // 4G模块初始化
- uint8 _4G_InitStep = 0;
- sint8 ATRet = -1;
- uint8 ReadLen = 0;
- char *ATCmdSend = NULL;
- uint8 ATCmdSendLen = 0;
- while (1)
- {
- switch (_4G_InitStep)
- {
- case 0: // AT指令同步
- {
- AtcmdTransmit(AT_CMD_TEST, NULL, 0, &ATRet);
- if (ATRet == 0)
- {
- _4G_InitStep++;
- }
- else
- {
- _4G_InitStep = 0;
- }
- break;
- }
- case 1: //关闭回显
- {
- ATCmdSend = (char *)("ATE0\r\n");
- ATCmdSendLen = mstrlen(ATCmdSend);
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- uint8 *retptr = NULL;
- if (ReadLen > 0)
- {
- retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK"));
- if (retptr)
- {
- _4G_InitStep++;
- }
- else
- {
- _4G_InitStep = 0;
- }
- }
- else
- {
- _4G_InitStep = 0;
- }
- break;
- }
- case 2: // IMEI获取
- {
- ATCmdSend = (char *)("AT+SIMEI?\r\n");
- ATCmdSendLen = mstrlen(ATCmdSend);
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- uint8 *retptr = NULL;
- if (ReadLen > 0)
- {
- retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("+SIMEI"));
- if (retptr)
- {
- memcpy(ImeiNum, retptr + 8, 15);
- _4G_InitStep++;
- }
- else
- {
- _4G_InitStep = 0;
- }
- }
- else
- {
- _4G_InitStep = 0;
- }
- break;
- }
- case 3: // 打开时间自动更新
- {
- ATCmdSend = (char *)("AT+CTZU=1\r\n");
- ATCmdSendLen = mstrlen(ATCmdSend);
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- uint8 *retptr = NULL;
- if (ReadLen > 0)
- {
- retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK"));
- if (retptr)
- {
- _4G_InitStep++;
- }
- else
- {
- _4G_InitStep = 0;
- }
- }
- else
- {
- _4G_InitStep = 0;
- }
- break;
- }
- case 4: // ICCID获取
- {
- AtcmdTransmit(AT_GETICCID, NULL, 0, &ATRet);
- if (ATRet == 0)
- {
- _4G_InitStep++;
- }
- else
- {
- _4G_InitStep = 0;
- }
- break;
- }
- default:
- {
- return;
- break;
- }
- }
- }
- }
- static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc)
- {
- uint16 ReadLen = 0;
- uint8 *PtrATCmdSend = NULL;
- uint8 ATCmdFixedLen = 0;
- uint16 ATCmdTotalLen = 0;
- ATCmdFixedLen = mstrlen(Atcmdfunc[CmdIdx].str);
- ATCmdTotalLen = ATCmdFixedLen + SetValueLen;
- PtrATCmdSend = malloc(ATCmdTotalLen + 1);
- memset(PtrATCmdSend, 0x00, ATCmdTotalLen + 1);
- memcpy(PtrATCmdSend, Atcmdfunc[CmdIdx].str, ATCmdFixedLen);
- if (SetValuePtr != NULL)
- {
- memcpy(PtrATCmdSend + ATCmdFixedLen, SetValuePtr, SetValueLen);
- }
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, PtrATCmdSend, ATCmdTotalLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- *retFunc = Atcmdfunc[CmdIdx].cb(PtrATCmdSend, RX_Buffer[UART_LPUART1], CmdIdx, ReadLen);
- if (PtrATCmdSend != NULL)
- {
- memset(PtrATCmdSend, 0x00, ATCmdTotalLen + 1);
- free(PtrATCmdSend);
- }
- PtrATCmdSend = NULL;
- return;
- }
- sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen)
- {
- sint8 OutValue = -1;
- uint8 *retptr = NULL;
- char *OkAns = "OK";
- retptr = (uint8 *)strstr((char *)pReadStr, OkAns);
- switch (CmdIdx)
- {
- case AT_CMD_TEST:
- {
- if (retptr)
- {
- OutValue = 0;
- }
- break;
- }
- case AT_SIMREADY:
- {
- if (retptr)
- {
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)("READY"));
- if (retptr)
- {
- OutValue = 0;
- }
- }
- break;
- }
- case AT_GETICCID:
- {
- if (retptr)
- {
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)("ICCID:"));
- if (retptr)
- {
- memcpy(IccidNum, retptr + 7, 20);
- OutValue = 0;
- }
- }
- break;
- }
- case AT_CGREG:
- {
- if (retptr)
- {
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)("CGREG:"));
- if (retptr)
- {
- uint8 RegN = 0;
- uint8 RegState = 0;
- RegN = CharToHex(*(retptr + 7));
- RegState = CharToHex(*(retptr + 9));
- OutValue = (RegState + RegN);
- return OutValue;
- }
- }
- break;
- }
- case AT_NETOPEN:
- {
- if (retptr)
- {
- OutValue = 0;
- }
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)("opened")); //重复打开
- if (retptr)
- {
- OutValue = 0;
- }
- break;
- }
- case AT_CONNECTCHK:
- {
- if (retptr)
- {
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)("TCP"));
- if (retptr)
- {
- OutValue = CharToHex(*(retptr - 3));
- return OutValue;
- }
- }
- break;
- }
- case AT_CGIP:
- {
- if (retptr)
- {
- for (uint8 i = 0; i < 30; i++)
- {
- if (*(retptr - i) == ',')
- {
- memcpy(WebSiteIp, retptr - i + 1, 15);
- OutValue = 0;
- break;
- }
- }
- }
- break;
- }
- case AT_CONNECT:
- {
- if (retptr)
- {
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)("CIPOPEN:"));
- if (retptr)
- {
- SocketId = CharToHex(*(retptr + 9));
- }
- OutValue = 0;
- }
- break;
- }
- case AT_SEND:
- {
- retptr = (uint8 *)strstr((char *)pReadStr, (char *)(">"));
- if (retptr)
- {
- OutValue = 0;
- }
- break;
- }
- default:
- break;
- }
- return OutValue;
- }
- void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
- {
- uint8 DataIdx = 0;
- static uint32 TcpSendTimeCounter = 0;
- TcpSendTimeCounter++;
- if (TcpSendTimeCounter == 1)
- {
- DataIdx = VerMsg; //版本信息发送
- }
- else if (TcpSendTimeCounter % 10 == 0)
- {
- DataIdx = BattMsg; //电池信息发送
- }
- else if ((TcpSendTimeCounter+1) % 10 == 0)
- {
- DataIdx = 0x83; //储能开关信息发送
- }
- else if (TcpSendTimeCounter % 240 == 0)
- {
- DataIdx = GpsMsg; //定位信息发送
- }
- else
- {
- *SendLen = 0;
- DataIdx = 0; //不发送,返回
- return;
- }
- UTC8TimeType UTC8TimeTcp;
- GetUtc8Time(&UTC8TimeTcp); //时间获取
- uint8 *SendBuffer = NULL;
- switch (DataIdx)
- {
- case 0x82:
- {
- GPSInfo GpsRecvData;
- GPSMsgtoTcpType GpsToTcpInfo;
- *SendLen = sizeof(GpsToTcpInfo);
- SendBuffer = malloc(*SendLen);
- uint16 tac = 0;
- uint32 cellId = 0;
- uint8 DataLen = (uint16)sizeof(GpsToTcpInfo.gpsInfo);
- GpsToTcpInfo.startSymbol[0] = TCP_START_SYM1;
- GpsToTcpInfo.startSymbol[1] = TCP_START_SYM2;
- GpsToTcpInfo.cmdSymbol = TCP_CMD_SYM;
- GpsToTcpInfo.ansSymbol = TCP_ANS_SYM;
- memcpy(GpsToTcpInfo.SN, TcpbattSN, BATT_SN_LEN);
- GpsToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
- GpsToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
- GpsToTcpInfo.dataLength[1] = DataLen & 0xFF;
- GpsToTcpInfo.gpsInfo.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
- GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; // month
- GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; // day
- GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; // hour
- GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
- GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
- GpsToTcpInfo.gpsInfo.msgMark = DataIdx;
- GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
- GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF; // month
- GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF; // day
- GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; // hour
- GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
- GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
- if (xQueueReceive(GpsDataQueueHandle, &GpsRecvData, 0) == pdPASS)
- {
- memcpy((uint8 *)&GpsToTcpInfo.gpsInfo.GpsInfoData, (uint8 *)&GpsRecvData, sizeof(GPSInfo));
- }
- else
- {
- memset((uint8 *)&GpsToTcpInfo.gpsInfo.GpsInfoData, 0x00, sizeof(GPSInfo));
- }
- GpsToTcpInfo.gpsInfo.Tac[0] = tac >> 8;
- GpsToTcpInfo.gpsInfo.Tac[1] = tac & 0xFF;
- GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 24;
- GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 16;
- GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 8;
- GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
- uint16 xyzDatacahce[3] = {0};
- memcpy(xyzDatacahce, xyzData, 3);
- for (uint8 i = 0; i < 3; i++)
- {
- if (xyzDatacahce[i] > 0x8000) // 数据为负
- {
- xyzDatacahce[i] = (uint16)((uint16)(~(xyzDatacahce[i])) + 1);
- xyzDatacahce[i] = 20000U - xyzDatacahce[i];
- }
- else
- {
- xyzDatacahce[i] = xyzDatacahce[i] + 20000U;
- }
- }
- GpsToTcpInfo.gpsInfo.xData[0] = xyzDatacahce[0] >> 8;
- GpsToTcpInfo.gpsInfo.xData[1] = xyzDatacahce[0];
- GpsToTcpInfo.gpsInfo.yData[0] = xyzDatacahce[1] >> 8;
- GpsToTcpInfo.gpsInfo.yData[1] = xyzDatacahce[1];
- GpsToTcpInfo.gpsInfo.zData[0] = xyzDatacahce[2] >> 8;
- GpsToTcpInfo.gpsInfo.zData[1] = xyzDatacahce[2];
- GpsToTcpInfo.CRC = bcc_chk((uint8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType) - 1);
- memcpy(SendBuffer, &GpsToTcpInfo, sizeof(GpsToTcpInfo));
- *PtrSendAddr = (uint32)SendBuffer;
- break;
- }
- case 0x86:
- {
- VersionMsgtoTcpType VerMsgToTcpInfo;
- *SendLen = sizeof(VersionMsgtoTcpType);
- SendBuffer = malloc(*SendLen);
- uint16 DataLen = 0;
- DataLen = (uint16)sizeof(VerMsgToTcpInfo.VerInfo);
- VerMsgToTcpInfo.startSymbol[0] = TCP_START_SYM1;
- VerMsgToTcpInfo.startSymbol[1] = TCP_START_SYM2;
- VerMsgToTcpInfo.cmdSymbol = TCP_CMD_SYM;
- VerMsgToTcpInfo.ansSymbol = TCP_ANS_SYM;
- memcpy(VerMsgToTcpInfo.SN, TcpbattSN, BATT_SN_LEN);
- VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
- VerMsgToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
- VerMsgToTcpInfo.dataLength[1] = DataLen & 0xFF;
- VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
- VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; // month
- VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; // day
- VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; // hour
- VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
- VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
- VerMsgToTcpInfo.VerInfo.msgMark = DataIdx;
- VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
- VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF; // month
- VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF; // day
- VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; // hour
- VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
- VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
- memcpy(VerMsgToTcpInfo.VerInfo.ICCID, IccidNum, 20);
- memcpy(VerMsgToTcpInfo.VerInfo.IMEI, ImeiNum, 15);
- VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = bmsHwVersion>>8;
- VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = bmsHwVersion;
- VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = bmsSwVersion>>24;
- VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = bmsSwVersion>>16;
- VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = bmsSwVersion>>8;
- VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = bmsSwVersion;
- VerMsgToTcpInfo.VerInfo.HwVersion[0] = (HWVERSION >> 8) & 0xFF;
- VerMsgToTcpInfo.VerInfo.HwVersion[1] = (HWVERSION)&0xFF;
- VerMsgToTcpInfo.VerInfo.BLVersion[0] = (BLSWVERSION >> 24) & 0xFF;
- VerMsgToTcpInfo.VerInfo.BLVersion[1] = (BLSWVERSION >> 16) & 0xFF;
- VerMsgToTcpInfo.VerInfo.BLVersion[2] = (BLSWVERSION >> 8) & 0xFF;
- VerMsgToTcpInfo.VerInfo.BLVersion[3] = (BLSWVERSION)&0xFF;
- VerMsgToTcpInfo.VerInfo.DRVVersion[0] = (DRVSWVERSION >> 24) & 0xFF;
- VerMsgToTcpInfo.VerInfo.DRVVersion[1] = (DRVSWVERSION >> 16) & 0xFF;
- VerMsgToTcpInfo.VerInfo.DRVVersion[2] = (DRVSWVERSION >> 8) & 0xFF;
- VerMsgToTcpInfo.VerInfo.DRVVersion[3] = (DRVSWVERSION)&0xFF;
- VerMsgToTcpInfo.VerInfo.APPVersion[0] = (APPSWVERSION >> 24) & 0xFF;
- VerMsgToTcpInfo.VerInfo.APPVersion[1] = (APPSWVERSION >> 16) & 0xFF;
- VerMsgToTcpInfo.VerInfo.APPVersion[2] = (APPSWVERSION >> 8) & 0xFF;
- VerMsgToTcpInfo.VerInfo.APPVersion[3] = (APPSWVERSION)&0xFF;
- VerMsgToTcpInfo.VerInfo.BmsType = BMS_MANUFACTURE;
- VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
- VerMsgToTcpInfo.VerInfo.DataModuleType = DATA_MODULE_TYPE;
- VerMsgToTcpInfo.CRC = bcc_chk((uint8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo) - 1);
- memcpy(SendBuffer, &VerMsgToTcpInfo, sizeof(VersionMsgtoTcpType));
- *PtrSendAddr = (uint32)SendBuffer;
- break;
- }
- case 0x80:
- {
- uint16 ErrorTemp;
- ErrorTemp = GetErrorNum(ErrorArray,sizeof(ErrorArray)/2);
- uint8 ProtocolHeaderLen = 25; //电池信息协议头部加校验码长度,此长度不更改
- uint8 ProtocolFixedLen = 60; //电池信息协议固定总长度 如协议新增,需要更改此长度
- uint16 ProtocolFluctedLen = AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp; //电池信息协议变动长度
- uint16 DataLen;
- *SendLen = ProtocolFixedLen + ProtocolFluctedLen;
- SendBuffer = malloc(*SendLen);
- if (SendBuffer == NULL)
- {
- return;
- }
- *(SendBuffer + 0) = TCP_START_SYM1; //起始码-1
- *(SendBuffer + 1) = TCP_START_SYM2; //起始码-2
- *(SendBuffer + 2) = TCP_CMD_SYM; //命令标识-3
- *(SendBuffer + 3) = TCP_ANS_SYM; //应答标识-4
- memcpy(SendBuffer + 4, TcpbattSN, BATT_SN_LEN); // SN码 5-21
- *(SendBuffer + 21) = TCP_ENCPT_DISABLE; //加密方式-22
- DataLen = ProtocolFixedLen + ProtocolFluctedLen - ProtocolHeaderLen; //电池信息单元协议固定长度
- *(SendBuffer + 22) = (DataLen >> 8) & 0xFF; //数据长度H-23
- *(SendBuffer + 23) = DataLen & 0xFF; //数据长度L-24
- *(SendBuffer + 24) = (UTC8TimeTcp.year) & 0xFF; // year-25
- *(SendBuffer + 25) = UTC8TimeTcp.month & 0xFF; // month-26
- *(SendBuffer + 26) = UTC8TimeTcp.day & 0xFF; // day-27
- *(SendBuffer + 27) = UTC8TimeTcp.hour & 0xFF; // hour-28
- *(SendBuffer + 28) = UTC8TimeTcp.minute & 0xFF; // mins-29
- *(SendBuffer + 29) = UTC8TimeTcp.second & 0xFF; // sec-30
- *(SendBuffer + 30) = DataIdx; //电池信息发送-31
- *(SendBuffer + 31) = (UTC8TimeTcp.year) & 0xFF; // year-32
- *(SendBuffer + 32) = UTC8TimeTcp.month & 0xFF; // month-33
- *(SendBuffer + 33) = UTC8TimeTcp.day & 0xFF; // day-34
- *(SendBuffer + 34) = UTC8TimeTcp.hour & 0xFF; // hour-35
- *(SendBuffer + 35) = UTC8TimeTcp.minute & 0xFF; // mins-36
- *(SendBuffer + 36) = UTC8TimeTcp.second & 0xFF; // sec-37
- *(SendBuffer + 37) = CSQValue; //信号强度-38
- *(SendBuffer + 38) = 0; //故障等级-39
- *(SendBuffer + 39) = ErrorTemp >> 8; //故障代码H-40
- *(SendBuffer + 40) = ErrorTemp & 0xFF; //故障代码L-41
- *(SendBuffer + 41) = battI >> 8; //电流-42
- *(SendBuffer + 42) = battI & 0xFF; //电流-43
- *(SendBuffer + 43) = battPackVol >> 8; //电压-44
- *(SendBuffer + 44) = battPackVol & 0xFF; //电压-45
- *(SendBuffer + 45) = battPackVol >> 8; //电压-46
- *(SendBuffer + 46) = battPackVol & 0xFF; //电压-47
- *(SendBuffer + 47) = battMOSSwitchState; // mos状态-48
- *(SendBuffer + 48) = (uint8)(battSOC); // soc-49
- *(SendBuffer + 49) = (uint8)(battSOH); // soh-50
- *(SendBuffer + 50) = (battBalanceoInfo >> 24) & 0xFF;
- *(SendBuffer + 51) = (battBalanceoInfo >> 16) & 0xFF;
- *(SendBuffer + 52) = (battBalanceoInfo >> 8) & 0xFF;
- *(SendBuffer + 53) = battBalanceoInfo & 0xFF; //均衡状态-51-54
- *(SendBuffer + 54) = AppDataInfo.BattCellCount; //电压个数-55
- for (uint8 i = 0; i < AppDataInfo.BattCellCount; i++) //单体电压
- {
- *(SendBuffer + 54 + i * 2 + 1) = (battCellU[i] >> 8) & 0xFF;
- *(SendBuffer + 54 + i * 2 + 2) = battCellU[i] & 0xFF;
- }
- *(SendBuffer + 55 + AppDataInfo.BattCellCount * 2) = AppDataInfo.BattTempCount; //模组温度个数
- memcpy((SendBuffer + 55 + AppDataInfo.BattCellCount * 2 + 1), &battCellTemp, AppDataInfo.BattTempCount); //模组温度
- *(SendBuffer + 56 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battWorkState; //电池工作状态
- *(SendBuffer + 57 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battHeatEnableState; //电池加热使能状态
- *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = BmsOtherTemp + OtherTemp; //其他温度个数
- // *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 1) = MOSTemp; // mos温度
- // *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 2) = packTemp; //环境温度
- // *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 3) = fastChargeTemp; //快充温度
- // *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 4) = normalChargeTemp; //慢充温度
- // *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 5) = heatTemp1; //加热温度1
- // *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 6) = heatTemp2; //加热温度2
- *(SendBuffer + 59 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp) = bcc_chk(SendBuffer, ProtocolFixedLen + ProtocolFluctedLen - 1); //校验码
- *PtrSendAddr = (uint32)SendBuffer;
- break;
- }
- case 0x83://储能场景的开关信息
- {
- StorageInfoToTcp StorageInfo;
- *SendLen = sizeof(StorageInfo);
- SendBuffer = malloc(*SendLen);
- uint16 DataLen = 0;
- DataLen = (uint16)sizeof(StorageInfo.StorageMsg);
- StorageInfo.startSymbol[0] = TCP_START_SYM1;
- StorageInfo.startSymbol[1] = TCP_START_SYM2;
- StorageInfo.cmdSymbol = TCP_CMD_SYM;
- StorageInfo.ansSymbol = TCP_ANS_SYM;
- memcpy(StorageInfo.SN, TcpbattSN, BATT_SN_LEN);
- StorageInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
- StorageInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
- StorageInfo.dataLength[1] = DataLen & 0xFF;
- StorageInfo.StorageMsg.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
- StorageInfo.StorageMsg.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; // month
- StorageInfo.StorageMsg.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; // day
- StorageInfo.StorageMsg.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; // hour
- StorageInfo.StorageMsg.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
- StorageInfo.StorageMsg.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
- StorageInfo.StorageMsg.msgMark = DataIdx;
- StorageInfo.StorageMsg.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
- StorageInfo.StorageMsg.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF; // month
- StorageInfo.StorageMsg.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF; // day
- StorageInfo.StorageMsg.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; // hour
- StorageInfo.StorageMsg.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
- StorageInfo.StorageMsg.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
- StorageInfo.StorageMsg.RelayState = battRelayState;
- StorageInfo.StorageMsg.FanState = battFanState;
- StorageInfo.StorageMsg.HeatState = battHeatState;
- StorageInfo.StorageMsg.ConvertState = battConverState;
- StorageInfo.CRC = bcc_chk((uint8 *)&StorageInfo, sizeof(StorageInfo) - 1);
- memcpy(SendBuffer, &StorageInfo, sizeof(StorageInfo));
- *PtrSendAddr = (uint32)SendBuffer;
- break;
- }
- default:
- break;
- }
- }
- void GetUtc8Time(UTC8TimeType *UTC8TimeTcp)
- {
- char *AtCmdAsk = (char *)("AT+CCLK?\r\n");
- uint8 AtCmdLen = mstrlen(AtCmdAsk);
- uint8 ReadLen = 0;
- uint8 *retptr = NULL;
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, AtCmdAsk, AtCmdLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- if (ReadLen > 0)
- {
- if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
- {
- retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("+CCLK:"));
- UTC8TimeTcp->year = CharToHex(*(retptr + 8)) * 10 + CharToHex(*(retptr + 9));
- UTC8TimeTcp->month = CharToHex(*(retptr + 11)) * 10 + CharToHex(*(retptr + 12));
- UTC8TimeTcp->day = CharToHex(*(retptr + 14)) * 10 + CharToHex(*(retptr + 15));
- UTC8TimeTcp->hour = CharToHex(*(retptr + 17)) * 10 + CharToHex(*(retptr + 18));
- UTC8TimeTcp->minute = CharToHex(*(retptr + 20)) * 10 + CharToHex(*(retptr + 21));
- UTC8TimeTcp->second = CharToHex(*(retptr + 23)) * 10 + CharToHex(*(retptr + 24));
- }
- }
- }
- static void TcpDataInfoRecvHandle(uint8 *DataRecv,uint16 DataRecvLen)
- {
- uint8 Tcp_Cmd;
- uint8 *Ptr=NULL,*retptr=NULL;
- uint8 TcpCmdAnswer[31];
- uint16 TcpDataLen = 0;
- uint16 NumCalTemp = 1;
- retptr = (uint8 *)strstr((char *)DataRecv, (char *)("\r\n##"));
- if(retptr==NULL)return;
- for(uint8 i=0;i<5;i++)
- {
- if(*(retptr - i - 1)=='D')
- {
- break;
- }
- TcpDataLen = TcpDataLen + CharToHex(*(retptr - i - 1))*NumCalTemp;
- NumCalTemp = NumCalTemp*10;
- }
- if (TcpDataLen>0)
- {
- Ptr = retptr + 2;
- if ((*(Ptr + 0) == TCP_START_SYM1) && (*(Ptr + 1) == TCP_START_SYM2)) //服务器起始信息
- {
- Tcp_Cmd = *(Ptr + 2); //命令标志
- // if (*(Ptr + 3) == 0xFE)
- // {
- // TCPWorkState = 0x01;//需要暂停发送,进行命令应答的标志
- // }
- switch (Tcp_Cmd)
- {
- case TCP_QUERY_SYM:
- break;
- case TCP_SETCMD_SYM:
- break;
- case TCP_CONCMD_SYM:
- {
- TcpCmdAnswer[0] = TCP_START_SYM1;
- TcpCmdAnswer[1] = TCP_START_SYM1;
- TcpCmdAnswer[2] = TCP_CONCMD_SYM;
- if (*(Ptr + 30) == 0x80) //远程锁定命令
- {
- TcpCmdAnswer[3] = 0x01;
- memcpy(&TcpCmdAnswer[4], (Ptr + 4), BATT_SN_LEN);
- TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
- TcpCmdAnswer[22] = 0x00;
- TcpCmdAnswer[23] = 0x06;
- memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
- TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
- if (*(Ptr + 31) == 0x01) // 0x01代表锁定
- {
- battSeparateEnable = 1;
- battSeparateEnableState = 1;
- tcpipConnectionSend(SocketId, TcpCmdAnswer, 31 );
- }
- else if (*(Ptr + 31) == 0x02) // 0x02代表解锁
- {
- battSeparateEnable = 1;
- battSeparateEnableState = 0;
- tcpipConnectionSend(SocketId, TcpCmdAnswer, 31);
- }
- }
- }
- default:
- {
- break;
- }
- }
- }
- }
- }
- static sint8 tcpipConnectionSend(uint8 TcpConnectId,uint8 * SendDataPtr,uint16 SendDataLen)
- {
- sint8 outValue = -1;
- sint8 ATRet = -1;
- uint8 ReadLen = 0;
- char AtCmdSend[10] = {0};
- uint8 AtCmdSendTotalLen = 0;
- sprintf(AtCmdSend, "%d,%d\r\n", TcpConnectId, SendDataLen);
- AtCmdSendTotalLen = mstrlen(AtCmdSend);
- AtcmdTransmit(AT_SEND, AtCmdSend, AtCmdSendTotalLen, &ATRet);
- if (ATRet == 0)
- {
- memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
- UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
- if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
- {
- outValue = 0;
- }
- }
- return outValue;
- }
|