Skip to content

Commit

Permalink
repaired wifi receive bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Neyzoter committed Jul 6, 2019
1 parent 8f79811 commit 7e38db1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 24 deletions.
8 changes: 8 additions & 0 deletions HARDWARE/TIMER/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,17 @@ void TIM3_IRQHandler(void)
//!adc数值缓存
u8 * adcTamp;
MS_TIME ++ ;
// PagingTime++;
//!溢出中断
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET)
{
// if(PagingTime > 11000){
// Wifi_Send_EN = 0;
// CAN_Get_EN = 0;
// ADC_Get_EN = 0;
// queue_clear((Queue *)&adc_queue);
// queue_clear((Queue *)&can_queue);
// }
/**
* 在系统初始化后才能运行的程序
*/
Expand Down
32 changes: 14 additions & 18 deletions HARDWARE/WIFI/userwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,21 @@ u16 localSocketDescriptor_txrx = 2;
* @param None
* @retval None
*/
void receive_udp_package(void)
void receive_udp_package(u8 beenCallByMain)
{
rsi_recvFrameUdp *data_recv=NULL;

u8 RspCode;
unsigned short recvSocket;
RspCode = Check_PKT();
s8 RspCode = Check_PKT();

unsigned short recvSocket;
switch (RspCode)
{
case RSI_RSP_DATA_RECEIVE: //接收到数据
data_recv = (rsi_recvFrameUdp *)&(rsi_app_cb.uCmdRspFrame->uCmdRspPayLoad);
recvSocket = rsi_bytes2R_to_uint16(data_recv->recvSocket);
if(recvSocket ==socketDescriptor_sync)//命令或者时钟同步信息
recvSocket = rsi_bytes2R_to_uint16(data_recv->recvSocket);
if(recvSocket ==socketDescriptor_sync || recvSocket ==localSocketDescriptor_txrx)//命令或者时钟同步信息
{
if(order_anay(data_recv->recvDataBuf) == NEED_RETURN_INFO)//如果返回了1说明,需要回复信息
if(order_anay(data_recv->recvDataBuf, beenCallByMain) == NEED_RETURN_INFO)//如果返回了1说明,需要回复信息
{
AnalRsp[0] = RETURN_INFO;//表示这是返回信息
AnalRsp[1] = data_recv->recvDataBuf[0];//返回传过来的命令
Expand All @@ -79,6 +78,7 @@ void receive_udp_package(void)
break;

}

}

/**
Expand All @@ -105,7 +105,7 @@ void wifi_send_package_test()
DATA_AUTO_CHECK_EN = 0;
//局域网
rsi_send_ludp_data(localSocketDescriptor_txrx, &adc_queue.arr[Head],Length+PACKAGE_HEAD_FRAME_LENGTH, RSI_PROTOCOL_UDP_V4, (uint8 *)localDestIp_txrx, localDestSocket_txrx, &bytes_sent);
receive_udp_package();
receive_udp_package(BEEN_CALL_BY_OTHERS);
delay_ms(1000);
//远程服务器
rsi_send_ludp_data(socketDescriptor_txrx, &adc_queue.arr[Head],Length+PACKAGE_HEAD_FRAME_LENGTH, RSI_PROTOCOL_UDP_V4, (uint8 *)destIp_txrx, destSocket_txrx, &bytes_sent);
Expand Down Expand Up @@ -324,24 +324,19 @@ u8 wifi_send_package(void)
* @param 接收到的命令首地址
* @retval 是否需要返回信息给上位机(NOT_NEED_RETURN_INFO 或 NEED_RETURN_INFO)
*/
u8 order_anay(u8 arr[])
u32 PagingTime = 0;
u8 order_anay(u8 arr[],u8 beenCallByMain)
{
switch(arr[0])
{
case GET_TIME_SYNC_PC://时钟同步信号
if(DATA_AUTO_CHECK_EN)
{
case GET_TIME_SYNC_MAIN_CLOCK:
if(beenCallByMain == BEEN_CALL_BY_OTHERS){
memcpy(&YYMMDD,&arr[1],4);
memcpy(&SYSTEMTIME,&arr[5],4);
Time_Sync_Flag = 1;
INFO_LED_CONV();
}
break;
case GET_TIME_SYNC_MAIN_CLOCK:
memcpy(&YYMMDD,&arr[1],4);
memcpy(&SYSTEMTIME,&arr[5],4);
Time_Sync_Flag = 1;
INFO_LED_CONV();
return NOT_NEED_RETURN_INFO;
case RETURN_INFO://返回了回复信号
return NOT_NEED_RETURN_INFO;//表示不需要返回信息
Expand Down Expand Up @@ -412,6 +407,7 @@ u8 order_anay(u8 arr[])
}
break;
case PAGING://寻呼信号
PagingTime=0;
break;
default:
return NOT_NEED_RETURN_INFO;
Expand Down Expand Up @@ -495,6 +491,6 @@ void Send_Sync_Time(void)
u8 temp= DATA_AUTO_CHECK_EN ;
DATA_AUTO_CHECK_EN= 0;
rsi_send_ludp_data(socketDescriptor_sync,time ,SYNC_TIME_BYTES, RSI_PROTOCOL_UDP_V4, (uint8 *)destIp_sync, destSocket_sync ,&bytes_sent);
receive_udp_package();
receive_udp_package(BEEN_CALL_BY_OTHERS);
DATA_AUTO_CHECK_EN = temp;
}
17 changes: 14 additions & 3 deletions HARDWARE/WIFI/userwifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef enum{
/** @defgroup WIFI模组等待的时间
* @{
*/
#define WIFI_MODUEL_WAIT_MSTIME 2 /*!< 用于防止缓存区被重写>*/
#define WIFI_MODUEL_WAIT_MSTIME 5 /*!< 用于防止缓存区被重写>*/
/**
* @}
*/
Expand Down Expand Up @@ -109,9 +109,20 @@ typedef enum{
/**
* @}
*/
/** @defgroup 是否main调用
* @{
*/
#define BEEN_CALL_BY_MAIN 0x01 /*!< 被main函数调用>*/
#define BEEN_CALL_BY_OTHERS 0x00 /*!< 被其他函数调用>*/
/**
* @}
*/


//!系统时钟
extern u32 SYSTEMTIME;
//!距离上次寻呼的时间
extern u32 PagingTime;
//!年月日
extern u32 YYMMDD;

Expand Down Expand Up @@ -163,12 +174,12 @@ extern volatile u8 DATA_AUTO_CHECK_EN;
//!字节数据发送个数
extern u32 bytes_sent;

void receive_udp_package(void);
void receive_udp_package(u8 beenCallByMain);
void wifi_send_package_test(void);
u8 OpenLudpSocket(u8* destIp,unsigned short destSocket,unsigned short moduleSocket,unsigned short * socketDescriptor);
u8 OpenTcpSocket(u8 *destIp,unsigned short destSocket,unsigned short moduleSocket,unsigned short * socketDescriptor);
u8 wifi_send_package(void);
u8 order_anay(u8 arr[]);
u8 order_anay(u8 arr[],u8 beenCallByMain);
void Send_Sync_Time(void);
#endif

Expand Down
27 changes: 25 additions & 2 deletions HARDWARE/WIFI/wificonf.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ void WIFI_NVIC_Config(void)
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

/**
* @brief 设置WIFI的中断NVIC
* @param None
* @retval None
*/
void WIFI_NVIC_Disable(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=WIFI_INTR_EXTI_CH;
NVIC_InitStructure.NVIC_IRQChannelCmd=DISABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief WIFI模组的引脚配置
* @param None
Expand Down Expand Up @@ -127,6 +138,18 @@ void WIFI_EXTI_Conf(void)
EXTI_Type.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_Type);
}
/**
* @brief 设置MCU接收WiFi信号的外部中断配置
* @param None
* @retval None
*/
void WIFI_EXTI_Disable(void)
{
EXTI_InitTypeDef EXTI_Type;
EXTI_Type.EXTI_Line=WIFI_INTR_EXTI_LINE;
EXTI_Type.EXTI_LineCmd=DISABLE;
EXTI_Init(&EXTI_Type);
}
/**
* @brief SPI的收发
* @param None
Expand All @@ -151,7 +174,7 @@ void EXTI4_IRQHandler(void)
/* 初始化时不能进行自动check*/
if( BOARD_STA == BOARD_RUNNING){
if((DATA_AUTO_CHECK_EN)&&(RSI_WIFI_OPER_MODE == RSI_WIFI_CLIENT_MODE_VAL)){//处于Clien模式,而且要使能自动check
receive_udp_package();
receive_udp_package(BEEN_CALL_BY_OTHERS);
}
}

Expand Down
6 changes: 5 additions & 1 deletion USER/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ int main(void)
u8 RspCode;u16 tcpRecvBuffLen;u8 * pRecvData;
while(1)
{

if( BOARD_STA == BOARD_RUNNING){
if((DATA_AUTO_CHECK_EN)&&(RSI_WIFI_OPER_MODE == RSI_WIFI_CLIENT_MODE_VAL)){//处于Clien模式,而且要使能自动check
receive_udp_package(BEEN_CALL_BY_MAIN);
}
}
// testMaxWifiSpeed();
if(RSI_WIFI_OPER_MODE == RSI_WIFI_CLIENT_MODE_VAL){
if(IAM_MASTER_CLOCK == 'Y'){
Expand Down

0 comments on commit 7e38db1

Please sign in to comment.