Skip to content

Commit

Permalink
add can send len
Browse files Browse the repository at this point in the history
  • Loading branch information
Neyzoter committed Apr 24, 2019
1 parent 53686c3 commit 4e6bb70
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
7 changes: 4 additions & 3 deletions HARDWARE/QUEUE/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
* @note 队列存储ADC和CAN数据,数据长度以ADC长度设置
* @{
*/
#define UDP_SEND_SIZE (8*40 + PACKAGE_HEAD_FRAME_LENGTH) /*!< UDP数据包最大大小 540 = 8 * 60 + PACKAGE_HEAD_FRAME_LENGTH>*/
#define QUEUE_SIZE 700 /*!< 队列正常容量,必须比UDP_SEND_SIZE大一些,不然会在被后面的信息覆盖>*/
#define ARR_SIZE (QUEUE_SIZE + UDP_SEND_SIZE+52) /*!< 队列最大容量>*/
#define ADC_SEND_SIZE (8*40 + PACKAGE_HEAD_FRAME_LENGTH) /*!< ADC数据包最大大小 540 = 8 * 60 + PACKAGE_HEAD_FRAME_LENGTH>*/
#define CAN_SEND_SIZE (25 * 8 + PACKAGE_HEAD_FRAME_LENGTH) /*!< CAN数据包最大大小 540 = 8 * 60 + PACKAGE_HEAD_FRAME_LENGTH>*/
#define QUEUE_SIZE 700 /*!< 队列正常容量,必须比ADC_SEND_SIZE大一些,不然会在被后面的信息覆盖>*/
#define ARR_SIZE (QUEUE_SIZE + ADC_SEND_SIZE+52) /*!< 队列最大容量>*/
/**
* @}
*/
Expand Down
55 changes: 42 additions & 13 deletions HARDWARE/WIFI/userwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
u8 Time_Sync_Flag = 0; //最近时钟是否同步
volatile u8 Wifi_Send_EN = 1; //数据采集和发送使能,是CAN和ADC采集的总开关
u8 CAN_Get_EN = CAN1_ENABLE_BIT_SLC|CAN2_ENABLE_BIT_SLC; //CAN数据发送使能(第0位使能can1,第1位使能can2),默认开启(必须满足Wifi_Send_EN=1,才能采集)
u8 ADC_Get_EN = 1; //ADC数据采集使能,默认开启(必须满足Wifi_Send_EN=1,才能采集)
u8 ADC_Get_EN = 0; //ADC数据采集使能,默认开启(必须满足Wifi_Send_EN=1,才能采集)
Queue adc_queue; //ADC数据存储
Queue can_queue; //can数据存储
u8 localDestIp_txrx[4] = {255,255,255,255};
Expand Down Expand Up @@ -95,14 +95,14 @@ void wifi_send_package_test()
int Head;
uint32 Length;
u8 temp= DATA_AUTO_CHECK_EN;
for(int i =0;i<UDP_SEND_SIZE;i++)
for(int i =0;i<ADC_SEND_SIZE;i++)
{
queue_put(&adc_queue,i);
}

Length = queue_length(adc_queue);
queue_addtime_addIO(&adc_queue,Length, nodeId, DIGITAL_INPUT1,DIGITAL_INPUT2,ADC_DATA_PACKAGE);
if(adc_queue.head + UDP_SEND_SIZE > QUEUE_SIZE ) queue_oversize(&adc_queue,adc_queue.head + UDP_SEND_SIZE - QUEUE_SIZE);
if(adc_queue.head + ADC_SEND_SIZE > QUEUE_SIZE ) queue_oversize(&adc_queue,adc_queue.head + ADC_SEND_SIZE - QUEUE_SIZE);
Head = adc_queue.head;
adc_queue.head = adc_queue.tail;

Expand Down Expand Up @@ -193,7 +193,7 @@ u8 wifi_send_package()
Time_Sync_Flag = 0;//时钟同步位清零
}
/* ADC队列已满*/
if(queue_length(adc_queue) >= (UDP_SEND_SIZE - PACKAGE_HEAD_FRAME_LENGTH )){
if(queue_length(adc_queue) >= (ADC_SEND_SIZE - PACKAGE_HEAD_FRAME_LENGTH )){

Adc_Length = queue_length(adc_queue);
queue_addtime_addIO(&adc_queue,Adc_Length,nodeId, DIGITAL_INPUT1,DIGITAL_INPUT2,ADC_DATA_PACKAGE); // head <- head-10;
Expand All @@ -218,21 +218,15 @@ u8 wifi_send_package()
delay_ms(WIFI_MODUEL_WAIT_MSTIME);
}
/* CAN队列已满*/
if( queue_length(can_queue) >= (UDP_SEND_SIZE - PACKAGE_HEAD_FRAME_LENGTH )){
if( queue_length(can_queue) >= (CAN_SEND_SIZE - PACKAGE_HEAD_FRAME_LENGTH )){
Can_Length = queue_length(can_queue);
queue_addtime_addIO(&can_queue,Can_Length, nodeId, DIGITAL_INPUT1,DIGITAL_INPUT2,CAN_DATA_PACKAGE);
Can_Head = can_queue.head;
can_queue.head = can_queue.tail;
if(Can_Head + Can_Length + PACKAGE_HEAD_FRAME_LENGTH > QUEUE_SIZE ) {
queue_oversize(&can_queue,Can_Head + Can_Length + PACKAGE_HEAD_FRAME_LENGTH - QUEUE_SIZE);
}
//! 是否打印出要发出去的CAN数据
#if PRINTF_CAN_QUEUE_DATA
for(int i =0 ;i < Can_Length+PACKAGE_HEAD_FRAME_LENGTH;i++){
printf("%x ",can_queue.arr[(Can_Head+i)%QUEUE_SIZE]);
}
printf("\r\n");
#endif

temp = DATA_AUTO_CHECK_EN;
DATA_AUTO_CHECK_EN = 0;
/* 发送到远程服务器*/
Expand All @@ -249,6 +243,25 @@ u8 wifi_send_package()
temp = DATA_AUTO_CHECK_EN;
DATA_AUTO_CHECK_EN = 0;
/* CAN数据发送到局域网*/
//! 是否打印出要发出去的CAN数据
#if CHECK_CAN_STATUS_PRINTF
// for(int i =0 ;i < Can_Length+PACKAGE_HEAD_FRAME_LENGTH;i++){
// printf("%x ",can_queue.arr[(Can_Head+i)%QUEUE_SIZE]);
// }
// printf("\r\n");
//校验时间最低位是否正确
printf("%x ?= %x\r\n",can_queue.arr[(Can_Head+4)%QUEUE_SIZE],can_queue.arr[(Can_Head+15)%QUEUE_SIZE]);
if(can_queue.arr[(Can_Head+15)%QUEUE_SIZE] != can_queue.arr[(Can_Head+4)%QUEUE_SIZE]){
printf("Time Check Error\r\n");
}
//校验数据长度

u32 count = can_queue.arr[(Can_Head+8)%QUEUE_SIZE] + 255 * can_queue.arr[(Can_Head+9)%QUEUE_SIZE];
printf("count : %d ?= Can_Length : %d\r\n",count,Can_Length);
if(count != Can_Length){
printf("Len Check Error\r\n");
}
#endif
rsi_send_ludp_data(localSocketDescriptor_txrx, &can_queue.arr[Can_Head],Can_Length+PACKAGE_HEAD_FRAME_LENGTH, RSI_PROTOCOL_UDP_V4, (uint8 *)localDestIp_txrx, localDestSocket_txrx, &bytes_sent);
DATA_AUTO_CHECK_EN = temp;
}else if(queue_length(can_queue) > 0){ /* CAN队列中数据存储时间过长,以us为单位,就发出来*/
Expand All @@ -260,7 +273,23 @@ u8 wifi_send_package()
can_queue.head = can_queue.tail;
if(Can_Head + Can_Length + PACKAGE_HEAD_FRAME_LENGTH > QUEUE_SIZE ) {
queue_oversize(&can_queue,Can_Head + Can_Length + PACKAGE_HEAD_FRAME_LENGTH - QUEUE_SIZE);
};
};
//! 是否打印出要发出去的CAN数据
#if CHECK_CAN_STATUS_PRINTF
// for(int i =0 ;i < Can_Length+PACKAGE_HEAD_FRAME_LENGTH;i++){
// printf("%x ",can_queue.arr[(Can_Head+i)%QUEUE_SIZE]);
// }
// printf("\r\n");
//校验时间最低位是否正确
if(can_queue.arr[(Can_Head+15)%QUEUE_SIZE] != can_queue.arr[(Can_Head+4)%QUEUE_SIZE]){
printf("Time Check Error\r\n");
}
//校验数据长度
u32 count = can_queue.arr[(Can_Head+8)%QUEUE_SIZE] + 255 * can_queue.arr[(Can_Head+9)%QUEUE_SIZE];
if(count != Can_Length){
printf("Len Check Error\r\n");
}
#endif
temp = DATA_AUTO_CHECK_EN;
DATA_AUTO_CHECK_EN = 0;
/* 发送到远程服务器*/
Expand Down
11 changes: 10 additions & 1 deletion HARDWARE/WIFI/userwifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ typedef enum{
* @}
*/

/** @defgroup 是否打印
* @{
*/
#define CHECK_CAN_STATUS_PRINTF 1 /*!< 校验CAN数据>*/
#define PRINTF_WIFI_SEND2MODULE_TIME 0 /*!< 打印udp发送时间间隔>*/
/**
* @}
*/

/** @defgroup CAN超时发送
* @{
*/
Expand All @@ -65,7 +74,7 @@ typedef enum{
/** @defgroup WIFI模组等待的时间
* @{
*/
#define WIFI_MODUEL_WAIT_MSTIME 2 /*!< 用于防止缓存区被重写>*/
#define WIFI_MODUEL_WAIT_MSTIME 5 /*!< 用于防止缓存区被重写>*/
/**
* @}
*/
Expand Down
2 changes: 1 addition & 1 deletion USER/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int main(void)
// CAN2_Send_Msg((u8 *)&SYSTEMTIME,4);
// CAN1_Receive_Msg(CanBuf);
// delay_ms(1000);
wifi_send_package();//发送数据,每次时钟更新后或者数据到达一定数量UDP_SEND_SIZE 8bytes时间+2bytes数字IO+8*N bytes ADC信号
wifi_send_package();//发送数据,每次时钟更新后或者数据到达一定数量ADC_SEND_SIZE 8bytes时间+2bytes数字IO+8*N bytes ADC信号
// testAdc();
// receive_udp_package();\\stm32_wifi_ap_1_x\../HARDWARE/WIFI/userwifi.c\adc_queue.tail
// wifi_send_package_test();
Expand Down

0 comments on commit 4e6bb70

Please sign in to comment.