第一次提交
This commit is contained in:
633
ETH/UdpServer/User/interface_etherent.c
Normal file
633
ETH/UdpServer/User/interface_etherent.c
Normal file
@@ -0,0 +1,633 @@
|
||||
/*
|
||||
* eth_drive.c
|
||||
*
|
||||
* Created on: 2023<32><33>1<EFBFBD><31>5<EFBFBD><35>
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
|
||||
#include "interface_etherent.h"
|
||||
#include "interface_config.h"
|
||||
#include <string.h>
|
||||
#include "eth_driver.h"
|
||||
#include "eth_driver.h"
|
||||
//*********************************************************************
|
||||
//ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>
|
||||
u8 MACAddr[6]= {0}; //MAC address
|
||||
u8 IPAddr[4] = { 192, 168, 17, 30 }; //IP address
|
||||
u8 GWIPAddr[4] = { 192, 168, 17, 1 }; //Gateway IP address
|
||||
u8 IPMask[4] = { 255, 255, 255, 0 }; //subnet mask
|
||||
u16 srcport = 8011; //source port
|
||||
u16 LocalPort = 8000;
|
||||
u16 DownloadPort = 7811;
|
||||
u8 SocketRecvBuf0[WCHNET_NUM_TCP][RECE_BUF_LEN] = {0}; //socket receive buffer
|
||||
u8 SocketRecvBuf1[RECE_BUF_LEN] = {0}; //socket receive buffer
|
||||
u8 SocketRecvBuf2[RECE_BUF_LEN] = {0}; //socket receive buffer
|
||||
|
||||
u16 Desport = 7900;
|
||||
|
||||
u8 pc_ipAddr[4] = { 192, 168, 17, 2 }; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP address
|
||||
|
||||
u8 tcp_socket[WCHNET_NUM_TCP]; //Save the currently connected socket
|
||||
|
||||
|
||||
SystemDataRecord g_systemDataRecord = {0,0,0,0};
|
||||
|
||||
u8 SocketId = 0;
|
||||
u8 SocketId2 = 1;
|
||||
u8 SocketId3 = 2;
|
||||
u8 SocketId4 = 3;
|
||||
u8 ETHResBuf[500] = {0};
|
||||
u32 ETHUDPTxLen = 0;
|
||||
|
||||
uint8_t portableOcuTimeOutCnt = 0;
|
||||
uint8_t remoteOcuTimeOutCnt = 0;
|
||||
|
||||
uint8_t OwnMasterTimCnt = 0;
|
||||
uint8_t OwnMasterOnline = 0;
|
||||
|
||||
uint8_t portableOcuOnline = 0;
|
||||
uint8_t remoteOcuOnline = 0;
|
||||
|
||||
Timer ethernet_timer_interface;
|
||||
/*********************************************************************
|
||||
* @fn mStopIfError
|
||||
*
|
||||
* @brief check if error.
|
||||
*
|
||||
* @param iError - error constants.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void mStopIfError(u8 iError)
|
||||
{
|
||||
if (iError == WCHNET_ERR_SUCCESS)
|
||||
return;
|
||||
printf("Error: %02X\r\n", (u16) iError);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IAP_EEPROM_ERASE
|
||||
*
|
||||
* @brief erase Data-Flash block, minimal block is 256B
|
||||
*
|
||||
* @param Page_Address - the address of the page being erased.
|
||||
* Length - Erased data length
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void IAP_EEPROM_ERASE(uint32_t Page_Address, u32 Length)
|
||||
{
|
||||
u32 NbrOfPage, EraseCounter;
|
||||
|
||||
FLASH_Unlock_Fast();
|
||||
NbrOfPage = Length / FLASH_PAGE_SIZE;
|
||||
|
||||
for (EraseCounter = 0; EraseCounter < NbrOfPage; EraseCounter++) {
|
||||
FLASH_ErasePage_Fast( Page_Address + (FLASH_PAGE_SIZE * EraseCounter)); //Erase 256B
|
||||
}
|
||||
FLASH_Lock_Fast();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IAP_EEPROM_WRITE
|
||||
*
|
||||
* @brief write Data-Flash data block
|
||||
*
|
||||
* @param StartAddr - the address of the page being written.
|
||||
* Buffer - data buff
|
||||
* Length - written data length
|
||||
*
|
||||
* @return FLASH_Status
|
||||
*/
|
||||
void IAP_EEPROM_WRITE( u32 StartAddr, u8 *Buffer, u32 Length )
|
||||
{
|
||||
u32 address = StartAddr;
|
||||
u32 *p_buff = (u32 *)Buffer;
|
||||
u16 pageNum = Length / FLASH_PAGE_SIZE;
|
||||
u16 lastDataNum = Length % FLASH_PAGE_SIZE;
|
||||
u16 i;
|
||||
|
||||
if(pageNum){ //write by page(256B)
|
||||
FLASH_Unlock_Fast();
|
||||
|
||||
for(i = 0; i < pageNum; i++)
|
||||
FLASH_ProgramPage_Fast((address + FLASH_PAGE_SIZE * i),(p_buff + (FLASH_PAGE_SIZE / 4) * i));
|
||||
|
||||
FLASH_Lock_Fast();
|
||||
}
|
||||
|
||||
if(lastDataNum){ //write by a half word(2B)
|
||||
u8 *p_buff1 = Buffer + FLASH_PAGE_SIZE * pageNum;
|
||||
address = StartAddr + FLASH_PAGE_SIZE * pageNum;
|
||||
FLASH_Unlock();
|
||||
|
||||
for(i = 0; i < lastDataNum; i += 2)
|
||||
FLASH_ProgramHalfWord((address + i), *(u16 *)(p_buff1 + i));
|
||||
|
||||
FLASH_Lock();
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IAP_EEPROM_READ
|
||||
*
|
||||
* @brief read Data-Flash data block
|
||||
*
|
||||
* @param StartAddr - the address of the page being read.
|
||||
* Buffer - data buff
|
||||
* Length - read data length
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void IAP_EEPROM_READ( u32 StartAddr, u8 *Buffer, u32 Length )
|
||||
{
|
||||
u32 address = StartAddr;
|
||||
u32 *p_buff = (u32 *)Buffer;
|
||||
|
||||
while(address < (StartAddr + Length))
|
||||
{
|
||||
*p_buff = (*(u32 *)address);
|
||||
address += 4;
|
||||
p_buff++;
|
||||
}
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_UdpServerRecv
|
||||
*
|
||||
* @brief UDP Receive data function
|
||||
*
|
||||
*@param socinf - socket information.
|
||||
* ipaddr - The IP address from which the data was sent
|
||||
* port - source port
|
||||
* buf - pointer to the data buffer
|
||||
* len - received data length
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_UdpServerRecv(struct _SCOK_INF *socinf, u32 ipaddr, u16 port, u8 *buf, u32 len)
|
||||
{
|
||||
u8 ip_addr[4];
|
||||
//---------------------------------------------------------------------------------------
|
||||
if((0xFF == buf[0]) && (0xBB == buf[1]))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ң<EFBFBD><D2A3><EFBFBD><EFBFBD>
|
||||
{
|
||||
portableOcuOnline = 1;
|
||||
portableOcuTimeOutCnt = 0;
|
||||
}
|
||||
else if((0xFF == buf[0]) && (0xCC == buf[1]))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Զ<EFBFBD>
|
||||
{
|
||||
portableOcuOnline = 1;
|
||||
|
||||
}
|
||||
else if(DF_DownloadDesIPAdress == ip_addr[3])//<2F><>̫<EFBFBD><CCAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_UdpServerRecv
|
||||
*
|
||||
* @brief UDP Receive data function
|
||||
*
|
||||
*@param socinf - socket information.
|
||||
* ipaddr - The IP address from which the data was sent
|
||||
* port - source port
|
||||
* buf - pointer to the data buffer
|
||||
* len - received data length
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_UdpServerRecv1(struct _SCOK_INF *socinf, u32 ipaddr, u16 port, u8 *buf, u32 len)//<2F>˿<EFBFBD>8000
|
||||
{
|
||||
//---------------------------------------------------------------------------------------
|
||||
if( (0x80 == buf[0]) && (0x00 == buf[1]) )
|
||||
{
|
||||
memcpy((uint8_t *)&(un_request_frame.arr[0]),buf, sizeof(UnRequestFrame));
|
||||
printf("read_id = %d \r\n",request_read_id);
|
||||
//20250412 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
str_RequestMessage.ip_adesser[i] = ipaddr & 0xff;
|
||||
ipaddr = ipaddr >> 8;
|
||||
}
|
||||
str_RequestMessage.port = port;
|
||||
|
||||
publishMessage(&un_request_frame, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_UdpServerRecv
|
||||
*
|
||||
* @brief UDP Receive data function
|
||||
*
|
||||
*@param socinf - socket information.
|
||||
* ipaddr - The IP address from which the data was sent
|
||||
* port - source port
|
||||
* buf - pointer to the data buffer
|
||||
* len - received data length
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_UdpServerRecv2(struct _SCOK_INF *socinf, u32 ipaddr, u16 port, u8 *buf, u32 len)//<2F>˿<EFBFBD>7811
|
||||
{
|
||||
u8 ip_addr[4];
|
||||
u16 i = 0;
|
||||
u32 PCLen2 = 0;
|
||||
u8 ENETTxMessage[8] = {0,0,0,0,0,0,0,0};
|
||||
//---------------------------------------------------------------------------------------
|
||||
printf("Remote IP:");
|
||||
for (i = 0; i < 4; i++) {
|
||||
ip_addr[i] = ipaddr & 0xff;
|
||||
printf("%d ", ip_addr[i]);
|
||||
ipaddr = ipaddr >> 8;
|
||||
}
|
||||
printf("srcport = %d len = %d socketid = %d\r\n", port, len,
|
||||
socinf->SockIndex);
|
||||
|
||||
if((buf[0] == 0x01) && (buf[1] == 0x0A))//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>boot<6F><74>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 20230430<33><30><EFBFBD><EFBFBD>
|
||||
{
|
||||
g_systemDataRecord.canBootloaderUpgrade = CAN_BOOTLOADER_UPGRADE;//<2F><><EFBFBD><EFBFBD>boot<6F><74>־
|
||||
IAP_EEPROM_ERASE(DATA_START_ADDR, FLASH_PAGE_SIZE);
|
||||
IAP_EEPROM_WRITE(DATA_START_ADDR, (uint8_t *)&g_systemDataRecord, 4);
|
||||
|
||||
//д<><D0B4><EFBFBD><EFBFBD>־<EFBFBD><D6BE>
|
||||
while(1)
|
||||
{
|
||||
NVIC_SystemReset();//<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
else if((buf[0] == 0x01) && (buf[1] == 0x01))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ״̬
|
||||
{
|
||||
IAP_EEPROM_READ( DATA_START_ADDR, (uint8_t *)&g_systemDataRecord, 4 );
|
||||
|
||||
PCLen2 = 8;
|
||||
ENETTxMessage[0] = 0x01;
|
||||
ENETTxMessage[1] = 0x01;
|
||||
ENETTxMessage[2] = 0;//<2F><><EFBFBD>汾<EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
ENETTxMessage[3] = 1;
|
||||
ENETTxMessage[4] = 0;//<2F>ΰ汾<CEB0>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
ENETTxMessage[5] = 0;
|
||||
ENETTxMessage[6] = 0;
|
||||
ENETTxMessage[7] = NORMAL_ON;//1<><31><EFBFBD>̼<EFBFBD><CCBC><EFBFBD>Bootloader, 0:<3A>̼<EFBFBD><CCBC><EFBFBD>APP
|
||||
|
||||
UdpSendToData(SocketId3,ENETTxMessage,&PCLen2,ip_addr,port);//<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_CreateUdpSocket
|
||||
*
|
||||
* @brief Create UDP Socket
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_CreateUdpSocket(void)
|
||||
{
|
||||
u8 i;
|
||||
SOCK_INF TmpSocketInf;
|
||||
|
||||
// memset((void *) &TmpSocketInf, 0, sizeof(SOCK_INF));
|
||||
// TmpSocketInf.SourPort = srcport;
|
||||
// TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
// TmpSocketInf.RecvStartPoint = (u32) SocketRecvBuf0;
|
||||
// TmpSocketInf.RecvBufLen = UDP_RECE_BUF_LEN;
|
||||
// TmpSocketInf.AppCallBack = WCHNET_UdpServerRecv;
|
||||
// i = WCHNET_SocketCreat(&SocketId, &TmpSocketInf);
|
||||
// printf("WCHNET_SocketCreat %d\r\n", SocketId);
|
||||
// mStopIfError(i);
|
||||
#if KEEPALIVE_ENABLE //Configure keep alive parameters
|
||||
{
|
||||
struct _KEEP_CFG cfg;
|
||||
|
||||
cfg.KLIdle = 20000;
|
||||
cfg.KLIntvl = 15000;
|
||||
cfg.KLCount = 9;
|
||||
WCHNET_ConfigKeepLive(&cfg);
|
||||
}
|
||||
#endif
|
||||
memset(tcp_socket, 0xff, WCHNET_NUM_TCP);
|
||||
|
||||
memset((void *) &TmpSocketInf, 0, sizeof(SOCK_INF));
|
||||
TmpSocketInf.SourPort = srcport;
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
||||
i = WCHNET_SocketCreat(&SocketId, &TmpSocketInf);
|
||||
printf("SocketIdForListen %d\r\n", SocketId);
|
||||
mStopIfError(i);
|
||||
i = WCHNET_SocketListen(SocketId); //listen for connections
|
||||
mStopIfError(i);
|
||||
|
||||
//
|
||||
memset((void *)&TmpSocketInf, 0, sizeof(SOCK_INF));
|
||||
TmpSocketInf.SourPort = LocalPort;
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
TmpSocketInf.RecvStartPoint = (u32) SocketRecvBuf1;
|
||||
TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
|
||||
TmpSocketInf.AppCallBack = WCHNET_UdpServerRecv1;
|
||||
WCHNET_SocketCreat(&SocketId2, &TmpSocketInf);
|
||||
printf("WCHNET_SocketCreat %d\r\n", SocketId2);
|
||||
// WCHNET_ModifyRecvBuf(SocketId, (u32)SocketRecvBuf[SocketId], RECE_BUF_LEN);
|
||||
|
||||
memset((void *) &TmpSocketInf, 0, sizeof(SOCK_INF));
|
||||
TmpSocketInf.SourPort = DownloadPort;
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
TmpSocketInf.RecvStartPoint = (u32) SocketRecvBuf2;
|
||||
TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
|
||||
TmpSocketInf.AppCallBack = WCHNET_UdpServerRecv2;
|
||||
i = WCHNET_SocketCreat(&SocketId3, &TmpSocketInf);
|
||||
printf("WCHNET_SocketCreat %d\r\n", SocketId3);
|
||||
// mStopIfError(i);
|
||||
|
||||
// memset((void *) &TmpSocketInf, 0, sizeof(SOCK_INF));
|
||||
// memcpy((void *) TmpSocketInf.IPAddr, DESIP, 4);
|
||||
// TmpSocketInf.DesPort = desport;
|
||||
// TmpSocketInf.SourPort = srcport++;
|
||||
// TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
||||
// TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
|
||||
// i = WCHNET_SocketCreat(&SocketId4, &TmpSocketInf);
|
||||
// printf("SocketId4 %d\r\n", SocketId4);
|
||||
// mStopIfError(i);
|
||||
// i = WCHNET_SocketConnect(SocketId4); //make a TCP connection
|
||||
// mStopIfError(i);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_HandleSockInt
|
||||
*
|
||||
* @brief Socket Interrupt Handle
|
||||
*
|
||||
* @param socketid - socket id.
|
||||
* intstat - interrupt status
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_HandleSockInt(u8 socketid, u8 intstat)
|
||||
{
|
||||
u8 i;
|
||||
if (intstat & SINT_STAT_RECV) //receive data
|
||||
{
|
||||
}
|
||||
if (intstat & SINT_STAT_CONNECT) //connect successfully
|
||||
{
|
||||
#if KEEPALIVE_ENABLE
|
||||
WCHNET_SocketSetKeepLive(socketid, ENABLE);
|
||||
#endif
|
||||
WCHNET_ModifyRecvBuf(socketid, (u32) SocketRecvBuf0[socketid], RECE_BUF_LEN);
|
||||
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) {
|
||||
if (tcp_socket[i] == 0xff) { //save connected socket id
|
||||
tcp_socket[i] = socketid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("TCP Connect Success\r\n");
|
||||
printf("socket id: %d\r\n",tcp_socket[i]);
|
||||
}
|
||||
if (intstat & SINT_STAT_DISCONNECT) //disconnect
|
||||
{
|
||||
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) { //delete disconnected socket id
|
||||
if (tcp_socket[i] == socketid) {
|
||||
tcp_socket[i] = 0xff;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("TCP Disconnect\r\n");
|
||||
}
|
||||
if (intstat & SINT_STAT_TIM_OUT) //timeout disconnect
|
||||
{
|
||||
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) { //delete disconnected socket id
|
||||
if (tcp_socket[i] == socketid) {
|
||||
tcp_socket[i] = 0xff;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("TCP Timeout\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_HandleGlobalInt
|
||||
*
|
||||
* @brief Global Interrupt Handle
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_HandleGlobalInt(void)
|
||||
{
|
||||
u8 intstat;
|
||||
u16 i;
|
||||
u8 socketint;
|
||||
|
||||
enter_critical_section();
|
||||
|
||||
intstat = WCHNET_GetGlobalInt(); //get global interrupt flag
|
||||
if (intstat & GINT_STAT_UNREACH) //Unreachable interrupt
|
||||
{
|
||||
// printf("GINT_STAT_UNREACH\r\n");
|
||||
}
|
||||
if (intstat & GINT_STAT_IP_CONFLI) //IP conflict
|
||||
{
|
||||
printf("GINT_STAT_IP_CONFLI\r\n");
|
||||
}
|
||||
if (intstat & GINT_STAT_PHY_CHANGE) //PHY status change
|
||||
{
|
||||
i = WCHNET_GetPHYStatus();
|
||||
if (i & PHY_Linked_Status)
|
||||
printf("PHY Link Success\r\n");
|
||||
}
|
||||
if (intstat & GINT_STAT_SOCKET) { //socket related interrupt
|
||||
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) {
|
||||
socketint = WCHNET_GetSocketInt(i);
|
||||
if (socketint)
|
||||
WCHNET_HandleSockInt(i, socketint);
|
||||
}
|
||||
}
|
||||
|
||||
exit_critical_section(0x00);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UDP send, specify the target IP and target port
|
||||
*
|
||||
* @param socketid - socket id value
|
||||
* @param *buf - Address of the sent data
|
||||
* @param(in) *slen - Address of the sent length
|
||||
* @param *sip - destination IP address
|
||||
* @param port - destination port
|
||||
*
|
||||
* @param(out) *slen - actual length sent
|
||||
*
|
||||
* @return @ERR_T
|
||||
*/
|
||||
uint8_t UdpSendToData(uint8_t socketid, uint8_t *buf, uint32_t *slen, uint8_t *sip, uint16_t port)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
uint16_t i = 0;
|
||||
//--------------------------------------------------------------
|
||||
WCHNET_SocketUdpSendTo( socketid, buf, slen,sip, port);//<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
while(slen[0] != 0)//<2F>жϻ<D0B6><CFBB><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;͵ȴ<CDB5>һ<EFBFBD><D2BB>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC>ʱ<EFBFBD><CAB1>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
i++;
|
||||
if(i > DF_EthInfoWiteTime)
|
||||
{
|
||||
i = 0;
|
||||
return DF_SEND_Fail;//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
}
|
||||
}
|
||||
return DF_SEND_Success;
|
||||
}
|
||||
|
||||
/*@brief <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD>ۼ<EFBFBD>У<EFBFBD><D0A3><EFBFBD>루ȡ<EBA3A8><C8A1>8λ<38><CEBB>
|
||||
? @param data <20><>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
? @param len <20><><EFBFBD>ݳ<EFBFBD><DDB3>ȣ<EFBFBD><C8A3><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ֽڣ<D6BD>
|
||||
? @return У<><D0A3><EFBFBD>루<EFBFBD><EBA3A8>8λ<38><CEBB>
|
||||
?*/
|
||||
uint8_t CalculateChecksum(const uint8_t* data, size_t len)
|
||||
{
|
||||
uint32_t checksum = 0; // ʹ<><CAB9>32λ<32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
checksum += data[i]; // <20>ۼ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ֽ<EFBFBD>
|
||||
}
|
||||
return (uint8_t)(checksum & 0xFF); // ȡ<><C8A1>8λ
|
||||
}
|
||||
|
||||
|
||||
// <20><>̫<EFBFBD><CCAB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>źŴ<C5BA><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static void ethernetInterfaceTimerProcess(void *signal_id)
|
||||
{
|
||||
static u_int32_t navigation_output_len = 0;
|
||||
static u_int32_t navigation_output_len1 = 0;
|
||||
//----------------------------------------------------------------------
|
||||
if (signal_id == &navigation_output1)
|
||||
{
|
||||
|
||||
navigation_outputC1.bit_data.frame_header = 0xCCAA;
|
||||
navigation_outputC1.bit_data.frame_type = 0x2700;
|
||||
navigation_outputC1.bit_data.frame_length = 0x4100;
|
||||
navigation_outputC1.bit_data.accumulated ++;
|
||||
|
||||
navigation_outputC1.bit_data.time = 0X00;
|
||||
navigation_outputC1.bit_data.car_speed = 0X00;
|
||||
|
||||
//С<><D0A1>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
navigation_outputC1.bit_data.gyroscope_x_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.gyroscope_x_axis);
|
||||
navigation_outputC1.bit_data.gyroscope_y_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.gyroscope_y_axis);
|
||||
navigation_outputC1.bit_data.gyroscope_z_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.gyroscope_z_axis);
|
||||
navigation_outputC1.bit_data.acceleration_x_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.acceleration_x_axis);
|
||||
navigation_outputC1.bit_data.acceleration_y_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.acceleration_y_axis);
|
||||
navigation_outputC1.bit_data.acceleration_z_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.acceleration_z_axis);
|
||||
|
||||
navigation_outputC1.bit_data.magnetic_x_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.magnetic_x_axis);
|
||||
navigation_outputC1.bit_data.magnetic_y_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.magnetic_y_axis);
|
||||
navigation_outputC1.bit_data.magnetic_z_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.magnetic_z_axis);
|
||||
|
||||
navigation_outputC1.bit_data.lon = SWAP_ENDIAN_32(navigation_output1.bit_data.lon);
|
||||
navigation_outputC1.bit_data.lat = SWAP_ENDIAN_32(navigation_output1.bit_data.lat);
|
||||
navigation_outputC1.bit_data.high = SWAP_ENDIAN_32(navigation_output1.bit_data.high);
|
||||
|
||||
navigation_outputC1.bit_data.gps_speed = SWAP_ENDIAN_16(navigation_output1.bit_data.gps_speed);
|
||||
navigation_outputC1.bit_data.dual_antenna_heading = SWAP_ENDIAN_16(navigation_output1.bit_data.dual_antenna_heading);
|
||||
navigation_outputC1.bit_data.car_speed = SWAP_ENDIAN_16(navigation_output1.bit_data.car_speed);
|
||||
navigation_outputC1.bit_data.time = SWAP_ENDIAN_32(navigation_output1.bit_data.time);
|
||||
navigation_outputC1.bit_data.rtk_state = navigation_output1.bit_data.rtk_state;
|
||||
|
||||
navigation_outputC1.bit_data.crc1 = CalculateChecksum(&navigation_outputC1.arr[0],sizeof(UnInfNavigationOutputC)-1);
|
||||
|
||||
|
||||
for(uint8_t i = 0; i < WCHNET_NUM_TCP; i++)
|
||||
{
|
||||
if(tcp_socket[i] != 0xFF)
|
||||
{
|
||||
if(0 == navigation_output_len1)
|
||||
{
|
||||
navigation_output_len1 = sizeof(navigation_outputC1);
|
||||
}
|
||||
|
||||
i = WCHNET_SocketSend(tcp_socket[i], (uint8_t *)&navigation_outputC1, &navigation_output_len1); //send data
|
||||
if (i == WCHNET_ERR_SUCCESS) {
|
||||
WCHNET_SocketRecv(tcp_socket[i], NULL, &navigation_output_len1); //Clear sent data
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (signal_id == &navigation_output2)
|
||||
{
|
||||
|
||||
navigation_output2.bit_data.frame_header = 0xCCAA;
|
||||
navigation_output2.bit_data.frame_type = 0x2700;
|
||||
navigation_output2.bit_data.frame_length = 0x3100;
|
||||
navigation_output2.bit_data.accumulated ++;
|
||||
|
||||
navigation_output2.bit_data.time = 0X00;
|
||||
navigation_output2.bit_data.car_speed = 0X00;
|
||||
|
||||
//С<><D0A1>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
navigation_output2.bit_data.gyroscope_x_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.gyroscope_x_axis);
|
||||
navigation_output2.bit_data.gyroscope_y_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.gyroscope_y_axis);
|
||||
navigation_output2.bit_data.gyroscope_z_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.gyroscope_z_axis);
|
||||
navigation_output2.bit_data.acceleration_x_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.acceleration_x_axis);
|
||||
navigation_output2.bit_data.acceleration_y_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.acceleration_y_axis);
|
||||
navigation_output2.bit_data.acceleration_z_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.acceleration_z_axis);
|
||||
|
||||
navigation_output2.bit_data.magnetic_x_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.magnetic_x_axis);
|
||||
navigation_output2.bit_data.magnetic_y_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.magnetic_y_axis);
|
||||
navigation_output2.bit_data.magnetic_z_axis = SWAP_ENDIAN_16(navigation_output1.bit_data.magnetic_z_axis);
|
||||
|
||||
navigation_output2.bit_data.lon = SWAP_ENDIAN_32(navigation_output1.bit_data.lon);
|
||||
navigation_output2.bit_data.lat = SWAP_ENDIAN_32(navigation_output1.bit_data.lat);
|
||||
navigation_output2.bit_data.high = SWAP_ENDIAN_32(navigation_output1.bit_data.high);
|
||||
|
||||
navigation_output2.bit_data.gps_speed = SWAP_ENDIAN_16(navigation_output1.bit_data.gps_speed);
|
||||
navigation_output2.bit_data.dual_antenna_heading = SWAP_ENDIAN_16(navigation_output1.bit_data.dual_antenna_heading);
|
||||
navigation_output2.bit_data.car_speed = SWAP_ENDIAN_16(navigation_output1.bit_data.car_speed);
|
||||
navigation_output2.bit_data.time = SWAP_ENDIAN_32(navigation_output1.bit_data.time);
|
||||
navigation_output2.bit_data.rtk_state = navigation_output1.bit_data.rtk_state;
|
||||
|
||||
navigation_output2.bit_data.crc1 = CalculateChecksum(&navigation_output2.arr[0],sizeof(UnInfNavigationOutput)-1);
|
||||
|
||||
if(0 == navigation_output_len)
|
||||
{
|
||||
navigation_output_len = sizeof(navigation_output2);
|
||||
}
|
||||
UdpSendToData(SocketId2, (uint8_t *)&navigation_output2, &navigation_output_len, &str_RequestMessage.ip_adesser[0],str_RequestMessage.port);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ethInterruptProcess(void *signal_id)
|
||||
{
|
||||
/*Ethernet library main task function,
|
||||
* which needs to be called cyclically*/
|
||||
WCHNET_MainTask();
|
||||
/*Query the Ethernet global interrupt,
|
||||
* if there is an interrupt, call the global interrupt handler*/
|
||||
if(WCHNET_QueryGlobalInt())
|
||||
{
|
||||
WCHNET_HandleGlobalInt();
|
||||
}
|
||||
|
||||
timerStart(ðernet_timer_interface, 1,1); //1ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
}
|
||||
|
||||
|
||||
void ethernetInterfaceInit(void)
|
||||
{
|
||||
//-----------------------------------
|
||||
// <20><><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>źţ<C5BA><C5A3><EFBFBD><EFBFBD>ڶ<EFBFBD>ʱ<EFBFBD>ɼ<EFBFBD>
|
||||
subscribe(&navigation_output1, ethernetInterfaceTimerProcess);
|
||||
subscribe(&navigation_output2, ethernetInterfaceTimerProcess);
|
||||
subscribe(ðernet_timer_interface, ethInterruptProcess);
|
||||
timerStart(ðernet_timer_interface, 1,1); //1ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
|
||||
printf( "ethernetInterface: initial OK %d\n",getCurrentTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user