Skip to content

Commit

Permalink
实车与模拟器功能联调
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolimy committed Jan 31, 2023
1 parent 36ec4ba commit 4ca2941
Showing 417 changed files with 85,635 additions and 71,836 deletions.
15 changes: 4 additions & 11 deletions Bsp/BC260Y/bsp_BC260Y.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#include "bsp_BC260Y.h"
#include "cmsis_os2.h"

char RxBuffer1[RXBUFFERSIZE]; //接收数据
char RxBuffer3[RXBUFFERSIZE]; //接收数据
uint8_t aRxBuffer1; //接收中断缓冲
uint8_t aRxBuffer3; //接收中断缓冲
char Buffer[RXBUFFERSIZE];
uint8_t Uart1_Rx_Cnt = 0; //接收缓冲计数
uint8_t Uart3_Rx_Cnt = 0; //接收缓冲计数
uint8_t okFlag = 0; //是否查询OK字符标志位
uint8_t MQTTinitOkFlag = 0; //初始化是否OK标志位


/*失败: 0 成功 : 1 */
uint8_t cmdToBC26Y(char *strSource, char *strTarget, uint8_t okCheck)
@@ -158,8 +150,9 @@ void MQTT_Pubdata(char *json)
usartTxFlag = 2;
printf("%s",pubStr);//发布主题

// usartTxFlag = 1;
// printf("send %s",pubStr);//发布主题
usartTxFlag = 1;
printf("send %s",pubStr);//发布主题
memset(pubStr,0x00,sizeof(pubStr)); //清空数组
// HAL_Delay(10);
// printf("%s\r\n",json);
// printf("%c", overCh);
15 changes: 4 additions & 11 deletions Bsp/BC260Y/bsp_BC260Y.h
Original file line number Diff line number Diff line change
@@ -6,20 +6,13 @@
#include "usart.h"
#include "gpio.h"
#include "bsp_CAN.h"
#include "applicationVar.h"

#define RXBUFFERSIZE 16 //最大接收字节数

extern char RxBuffer1[RXBUFFERSIZE]; //接收数据
extern char RxBuffer3[RXBUFFERSIZE]; //接收数据
extern char Buffer[RXBUFFERSIZE]; //接收数据
extern uint8_t aRxBuffer1; //接收中断缓冲
extern uint8_t aRxBuffer3; //接收中断缓冲
extern uint8_t Uart1_Rx_Cnt; //接收缓冲计数
extern uint8_t Uart3_Rx_Cnt; //接收缓冲计数
extern uint8_t okFlag;
extern uint8_t MQTTinitOkFlag;

extern struct RacingCarData racingCarData;


//extern struct RacingCarData racingCarData;

uint8_t BC260Y_init();
uint8_t MQTT_Init();
26 changes: 2 additions & 24 deletions Bsp/CAN/bsp_CAN.c
Original file line number Diff line number Diff line change
@@ -5,27 +5,9 @@
#include "cmsis_os2.h"
#include "applicationVar.h"

#define SPEED_RATIO 4 //主减速比
#define PI 3.14 //圆周率
#define WHEEL_R 0.2286 //车轮半径
#define NUM_OF_TEETH 20.0 //码盘齿数


uint8_t upSpeedFlag = 1;
uint8_t uploadFlag = 1;
struct RacingCarData racingCarData;
extern osEventFlagsId_t getCarDataHandle;

extern void Start_LVGL_Lap_Timer(void *argument);
extern void Start_BC260Y_init(void *argument);
extern void Start_IotUploadTask(void *argument);
extern osThreadId_t BC260Y_initHandle;
extern osThreadId_t LVGL_Lap_TimerHandle;
extern osThreadId_t iotUploadTaskHandle;
extern const osThreadAttr_t iotUploadTask_attributes;
extern const osThreadAttr_t LVGL_Lap_Timer_attributes;
extern const osThreadAttr_t BC260Y_init_attributes;

void CANFilter_Config(void)//无论发啥我都照单全收。
{
CAN_FilterTypeDef sFilterConfig;
@@ -63,16 +45,12 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
appStatus.standByStatus = 0; //关闭待机模式
appStatus.canOpenStatus = 1; //打开实车模式
appStatus.simhubStatus = 0; //关闭模拟器模式
if(!appStatus.initOK_Flag)
{
LVGL_Lap_TimerHandle = osThreadNew(Start_LVGL_Lap_Timer, NULL, &LVGL_Lap_Timer_attributes);
BC260Y_initHandle = osThreadNew(Start_BC260Y_init, NULL, &BC260Y_init_attributes);
}


#if Receiver
decodeCanData(RxMessage.StdId, data);

osEventFlagsSet(getCarDataHandle, 0x07); // 0000 0111
osEventFlagsSet(getCarDataHandle, 0x0f); // 0000 1111
//lv_event_send(ui_speedMeter, SPEED_CHANGED, NULL);
uploadFlag = 1;
#endif
33 changes: 1 addition & 32 deletions Bsp/CAN/bsp_CAN.h
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ void uploadCarData();
#define GUI_UPDATE_EVENT (0x01 << 1)//设置事件掩码的位 1
#define LED_EVENT (0x01 << 2)//设置事件掩码的位 2
#define MQTT_INIT (0x01 << 3)//设置事件掩码的位 3

#if Transmitter
void carDataUpdate();
void canDataPack();
@@ -31,37 +32,5 @@ void canDataPack();
#if Receiver
void decodeCanData(uint32_t canID, uint8_t *canData);
#endif
struct RacingCarData
{

//ID:0X193
uint8_t FrontSpeed; //前轮车速 在这里作为参考车速 1Byte
uint8_t PedalTravel; //油门踏板开度 1Byte
uint8_t brakeTravel; //刹车踏板开度 1Byte
uint8_t carTravel; //车辆跑动距离 1Byte
uint16_t l_motor_torque; //左电机目标转矩 2Byte
uint16_t r_motor_torque; //右电机目标转矩 2Byte

//ID:0X196
uint8_t batAlarm; //电池告警 0~4 无告警:0 一级告警:1(最严重) 二级告警:2 三级告警:3 1Byte
uint8_t batTemp; //电池温度 0-160 offset:-40 1Byte
uint8_t batLevel; //电池电量 0-100 1Byte
uint16_t batVol; //电池电压 0-900 2Byte
uint8_t gearMode; //挡位信息 1Bit 1Byte
uint8_t carMode; //车辆运行模式 1Bit
//ID:0X191
uint16_t lmotorSpeed; //左电机转速 2Bit offset -10000rpm 分辨率:0.5
//ID:0X192
uint8_t lmotorTemp; //左电机温度 1Byte 0~150摄氏度 offset:-50
uint8_t mcu1Temp; //电机控制器1温度 1Byte 0~150摄氏度 offset:-50
//ID:0X194
uint16_t rmotorSpeed; //右电机转速 2Bit offset -10000rpm 分辨率:0.5
//ID:0X195
uint8_t rmotorTemp; //右电机温度
uint8_t mcu2Temp; //电机控制器2温度


};
extern struct RacingCarData racingCarData;
extern uint8_t uploadFlag;
#endif //__BSP_CAN_H__
64 changes: 38 additions & 26 deletions Bsp/WS2812B/bsp_WS2812B.c
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
#include "bsp_CAN.h"
#include "cmsis_os2.h"
#include "SH_Data.h"
#include "applicationVar.h"


#define ONE_PULSE ((htim1.Init.Period+1)/3*2-1)
#define ZERO_PULSE ((htim1.Init.Period+1)/3-1)
@@ -85,43 +87,53 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)

void RPM_LED_Shine()
{
//x / 500
#if canOPEN
uint8_t ledNums, i;
ws2812_init(12);
ledNums = racingCarData.lmotorSpeed / 400;
#if canOPEN
#endif

for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
{
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
}
while(ledNums>10)
#if simhubOPEN
if(appStatus.canOpenStatus)
{
ws2812_green(ledNums);//RGB
osDelay(80);
ws2812_init(12);
osDelay(80);
ledNums = racingCarData.lmotorSpeed / 400;
}
#endif

#if simhubOPEN
uint8_t ledNums, i;
ws2812_init(12);
ledNums = sh_CarData.rpm / (sh_CarData.redRpm / 12);
for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
{
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
}
while(ledNums>10)
{
ws2812_green(ledNums);//RGB
osDelay(80);
ws2812_init(12);
osDelay(80);
ledNums = racingCarData.lmotorSpeed / 400;
}
}

for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
if(appStatus.simhubStatus)
{
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
ledNums = sh_CarData.rpm / (sh_CarData.redRpm / 12);

for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
{
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
}
while(ledNums>10 &&(sh_CarData.rpm > sh_CarData.redRpm) )
{
ws2812_red(ledNums);//RGB
osDelay(80);
ws2812_init(12);
osDelay(80);
ledNums = sh_CarData.rpm / 400;
}
}
while(ledNums>10 &&(sh_CarData.rpm > sh_CarData.redRpm) )

if(appStatus.standByStatus)
{
ws2812_red(ledNums);//RGB
osDelay(80);
ws2812_init(12);
osDelay(80);
ledNums = sh_CarData.rpm / 400;
ws2812_blue(12);//RGB
}

#endif

}
6 changes: 4 additions & 2 deletions Bsp/shApplication/SH_Data.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "SH_Data.h"
#include "Bsp_USB_Composite.h"
#include "applicationVar.h"

#define jsmnUsing 1

uint8_t get_data_flag = 0;
uint8_t buf[1024] __attribute__((section(".CCM_RAM")));
uint8_t buf[1024] ;//__attribute__((section(".CCM_RAM")));
uint32_t data_nums = 0;
struct SH_CarData sh_CarData __attribute__((section(".CCM_RAM")));



//½âÎöÊý¾Ý
14 changes: 0 additions & 14 deletions Bsp/shApplication/SH_Data.h
Original file line number Diff line number Diff line change
@@ -5,20 +5,6 @@
//#include "jansson.h"


struct SH_CarData
{
uint16_t speed;
uint16_t rpm;
uint16_t redRpm;
uint8_t *Gear;
uint8_t fuel;
uint8_t *bLapTime;
uint8_t *cLapTime;
uint8_t lap;
uint8_t brake;
uint8_t throttle;

};


extern struct SH_CarData sh_CarData;
2 changes: 1 addition & 1 deletion Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)15360)
#define configTOTAL_HEAP_SIZE ((size_t)1024*20)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
61 changes: 60 additions & 1 deletion Core/Inc/applicationVar.h
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@

#include "main.h"


#define RXBUFFERSIZE 16 //最大接收字节数

struct appStatus_t{
uint8_t standByStatus; //待机模式 1为待机模式
uint8_t canOpenStatus; //实车模式 1为实车模式
@@ -11,10 +14,66 @@ struct appStatus_t{
};


extern struct appStatus_t appStatus;
struct RacingCarData
{

//ID:0X193
uint8_t FrontSpeed; //前轮车速 在这里作为参考车速 1Byte
uint8_t PedalTravel; //油门踏板开度 1Byte
uint8_t brakeTravel; //刹车踏板开度 1Byte
uint8_t carTravel; //车辆跑动距离 1Byte
uint16_t l_motor_torque; //左电机目标转矩 2Byte
uint16_t r_motor_torque; //右电机目标转矩 2Byte

//ID:0X196
uint8_t batAlarm; //电池告警 0~4 无告警:0 一级告警:1(最严重) 二级告警:2 三级告警:3 1Byte
uint8_t batTemp; //电池温度 0-160 offset:-40 1Byte
uint8_t batLevel; //电池电量 0-100 1Byte
uint16_t batVol; //电池电压 0-900 2Byte
uint8_t gearMode; //挡位信息 1Bit 1Byte
uint8_t carMode; //车辆运行模式 1Bit
//ID:0X191
uint16_t lmotorSpeed; //左电机转速 2Bit offset -10000rpm 分辨率:0.5
//ID:0X192
uint8_t lmotorTemp; //左电机温度 1Byte 0~150摄氏度 offset:-50
uint8_t mcu1Temp; //电机控制器1温度 1Byte 0~150摄氏度 offset:-50
//ID:0X194
uint16_t rmotorSpeed; //右电机转速 2Bit offset -10000rpm 分辨率:0.5
//ID:0X195
uint8_t rmotorTemp; //右电机温度
uint8_t mcu2Temp; //电机控制器2温度

};

struct SH_CarData
{
uint16_t speed;
uint16_t rpm;
uint16_t redRpm;
uint8_t *Gear;
uint8_t fuel;
uint8_t *bLapTime;
uint8_t *cLapTime;
uint8_t lap;
uint8_t brake;
uint8_t throttle;

};


extern struct RacingCarData racingCarData;
extern struct appStatus_t appStatus;
extern uint8_t uploadFlag;

extern char RxBuffer1[RXBUFFERSIZE]; //接收数据
extern char RxBuffer3[RXBUFFERSIZE]; //接收数据
extern char Buffer[RXBUFFERSIZE]; //接收数据
extern uint8_t aRxBuffer1; //接收中断缓冲
extern uint8_t aRxBuffer3; //接收中断缓冲
extern uint8_t Uart1_Rx_Cnt; //接收缓冲计数
extern uint8_t Uart3_Rx_Cnt; //接收缓冲计数
extern uint8_t okFlag;
extern uint8_t MQTTinitOkFlag;


#endif //_APPLICATIONVAR_H_
22 changes: 22 additions & 0 deletions Core/Src/applicationVar.c
Original file line number Diff line number Diff line change
@@ -4,3 +4,25 @@
struct appStatus_t appStatus;


#define SPEED_RATIO 4 //主减速比
#define PI 3.14 //圆周率
#define WHEEL_R 0.2286 //车轮半径
#define NUM_OF_TEETH 20.0 //码盘齿数


uint8_t upSpeedFlag = 1;
uint8_t uploadFlag = 1;
struct RacingCarData racingCarData;

char RxBuffer1[RXBUFFERSIZE]; //接收数据
char RxBuffer3[RXBUFFERSIZE]; //接收数据
uint8_t aRxBuffer1; //接收中断缓冲
uint8_t aRxBuffer3; //接收中断缓冲
char Buffer[RXBUFFERSIZE];
uint8_t Uart1_Rx_Cnt = 0; //接收缓冲计数
uint8_t Uart3_Rx_Cnt = 0; //接收缓冲计数
uint8_t okFlag = 0; //是否查询OK字符标志位
uint8_t MQTTinitOkFlag = 0; //初始化是否OK标志位


struct SH_CarData sh_CarData ;//__attribute__((section(".CCM_RAM")));
Loading

0 comments on commit 4ca2941

Please sign in to comment.