| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include "can_debug.h"
- #include "usart_data_handle.h"
- #include "string.h"
- rkfifo_t candebug_rkfifo;
- Debug_buf debug_can;
- void check_can_dev_connect(void)
- {
- if(debug_can.Total_Dev_num != 0)
- {
- for(uint8_t i=0;i<debug_can.Total_Dev_num;i++)
- {
- if(HAL_GetTick() - debug_can.ID_buf[i].ID_time > 5000)
- {
- debug_can.ID_buf[i].connect_status = 2;
- }
- else
- {
- debug_can.ID_buf[i].connect_status = 1;
- }
- }
- }
- }
- int get_data_total_len(uint8_t i)
- {
- uint8_t len = 0;
- len += 4; //ID
- len++; //len
- len++; //status
- len++; //send_fre
- len += i;
- return len;
- }
- void register_can_dev_func(uint8_t *buf)
- {
- #pragma pack(1)
- struct can_dev_temp
- {
- uint32_t ID;
- uint8_t len;
- uint8_t data[8];
- uint32_t time;
- };
- #pragma pack(0)
- struct can_dev_temp temp_a;
- uint8_t i = 0;
- memcpy(&temp_a.ID,buf,sizeof(struct can_dev_temp));
- if(debug_can.Total_Dev_num != 0)
- {
- for(i=0;i<debug_can.Total_Dev_num;i++)
- {
- if(debug_can.ID_buf[i].ID == temp_a.ID)
- {
- break;
- }
- if((i + 1 == debug_can.Total_Dev_num) && (debug_can.Total_Dev_num < MAX_ID_NUM - 1)) //防止超buf
- {
- debug_can.Total_Dev_num++;
- i++;
- break;
- }
- }
- }
- else
- {
- debug_can.Total_Dev_num++;
- }
- debug_can.ID_buf[i].ID = temp_a.ID;
- debug_can.ID_buf[i].len = temp_a.len;
- debug_can.ID_buf[i].send_fre = 1000 / (HAL_GetTick() - debug_can.ID_buf[i].ID_time);
- debug_can.ID_buf[i].ID_time = HAL_GetTick();
- memcpy(&debug_can.ID_buf[i].data[0],&temp_a.data[0],temp_a.len);
- }
- void seek_can_debug_buf_adr(void)
- {
- uint8_t temp_buf[128] = {0}, c = 0, seek_i = 0;
- while (rkfifo_out(&candebug_rkfifo, &c, 1) != 0)
- {
- temp_buf[seek_i] = c;
- if(temp_buf[seek_i] == 'K' && temp_buf[seek_i - 1] == 'V')
- {
- temp_buf[seek_i] = c;
- register_can_dev_func(temp_buf);
- seek_i = 0;
- break;
- }
- else
- {
- seek_i++;
- }
- }
- }
- void put_candata_to_rkfifo_rx(CAN_RxHeaderTypeDef rxhead,uint8_t *data)
- {
- uint32_t cur_time = HAL_GetTick();
- uint8_t tem_buf[30] = {0},i = 0;
- if(rxhead.IDE == CAN_ID_STD)
- memcpy(&tem_buf[i],&rxhead.StdId,4);
- else
- memcpy(&tem_buf[i],&rxhead.ExtId,4);
- i += 4;
- tem_buf[i++] = rxhead.DLC;
- memcpy(&tem_buf[i],&data[0],8);
- i += 8;
- memcpy(&tem_buf[i],&cur_time,4);
- i += 4;
- tem_buf[i++] = 'V';
- tem_buf[i++] = 'K';
- rkfifo_in(&candebug_rkfifo,tem_buf,i);
- }
- void put_candata_to_rkfifo_tx(CAN_TxHeaderTypeDef txhead,uint8_t *data)
- {
- uint32_t cur_time = HAL_GetTick();
- uint8_t tem_buf[30] = {0},i = 0;
- if(txhead.IDE == CAN_ID_STD)
- memcpy(&tem_buf[i],&txhead.StdId,4);
- else
- memcpy(&tem_buf[i],&txhead.ExtId,4);
- i += 4;
- tem_buf[i++] = txhead.DLC;
- memcpy(&tem_buf[i],&data[0],8);
- i += 8;
- memcpy(&tem_buf[i],&cur_time,4);
- i += 4;
- tem_buf[i++] = 'V';
- tem_buf[i++] = 'K';
- rkfifo_in(&candebug_rkfifo,tem_buf,i);
- }
|