Skip to content

Commit 4ca2941

Browse files
committed
实车与模拟器功能联调
1 parent 36ec4ba commit 4ca2941

417 files changed

Lines changed: 85635 additions & 71836 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Bsp/BC260Y/bsp_BC260Y.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
#include "bsp_BC260Y.h"
22
#include "cmsis_os2.h"
33

4-
char RxBuffer1[RXBUFFERSIZE]; //接收数据
5-
char RxBuffer3[RXBUFFERSIZE]; //接收数据
6-
uint8_t aRxBuffer1; //接收中断缓冲
7-
uint8_t aRxBuffer3; //接收中断缓冲
8-
char Buffer[RXBUFFERSIZE];
9-
uint8_t Uart1_Rx_Cnt = 0; //接收缓冲计数
10-
uint8_t Uart3_Rx_Cnt = 0; //接收缓冲计数
11-
uint8_t okFlag = 0; //是否查询OK字符标志位
12-
uint8_t MQTTinitOkFlag = 0; //初始化是否OK标志位
4+
135

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

161-
// usartTxFlag = 1;
162-
// printf("send %s",pubStr);//发布主题
153+
usartTxFlag = 1;
154+
printf("send %s",pubStr);//发布主题
155+
memset(pubStr,0x00,sizeof(pubStr)); //清空数组
163156
// HAL_Delay(10);
164157
// printf("%s\r\n",json);
165158
// printf("%c", overCh);

Bsp/BC260Y/bsp_BC260Y.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
#include "usart.h"
77
#include "gpio.h"
88
#include "bsp_CAN.h"
9+
#include "applicationVar.h"
910

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

12-
extern char RxBuffer1[RXBUFFERSIZE]; //接收数据
13-
extern char RxBuffer3[RXBUFFERSIZE]; //接收数据
14-
extern char Buffer[RXBUFFERSIZE]; //接收数据
15-
extern uint8_t aRxBuffer1; //接收中断缓冲
16-
extern uint8_t aRxBuffer3; //接收中断缓冲
17-
extern uint8_t Uart1_Rx_Cnt; //接收缓冲计数
18-
extern uint8_t Uart3_Rx_Cnt; //接收缓冲计数
19-
extern uint8_t okFlag;
20-
extern uint8_t MQTTinitOkFlag;
2112

22-
extern struct RacingCarData racingCarData;
13+
14+
15+
//extern struct RacingCarData racingCarData;
2316

2417
uint8_t BC260Y_init();
2518
uint8_t MQTT_Init();

Bsp/CAN/bsp_CAN.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,9 @@
55
#include "cmsis_os2.h"
66
#include "applicationVar.h"
77

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

13-
14-
uint8_t upSpeedFlag = 1;
15-
uint8_t uploadFlag = 1;
16-
struct RacingCarData racingCarData;
179
extern osEventFlagsId_t getCarDataHandle;
1810

19-
extern void Start_LVGL_Lap_Timer(void *argument);
20-
extern void Start_BC260Y_init(void *argument);
21-
extern void Start_IotUploadTask(void *argument);
22-
extern osThreadId_t BC260Y_initHandle;
23-
extern osThreadId_t LVGL_Lap_TimerHandle;
24-
extern osThreadId_t iotUploadTaskHandle;
25-
extern const osThreadAttr_t iotUploadTask_attributes;
26-
extern const osThreadAttr_t LVGL_Lap_Timer_attributes;
27-
extern const osThreadAttr_t BC260Y_init_attributes;
28-
2911
void CANFilter_Config(void)//无论发啥我都照单全收。
3012
{
3113
CAN_FilterTypeDef sFilterConfig;
@@ -63,16 +45,12 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
6345
appStatus.standByStatus = 0; //关闭待机模式
6446
appStatus.canOpenStatus = 1; //打开实车模式
6547
appStatus.simhubStatus = 0; //关闭模拟器模式
66-
if(!appStatus.initOK_Flag)
67-
{
68-
LVGL_Lap_TimerHandle = osThreadNew(Start_LVGL_Lap_Timer, NULL, &LVGL_Lap_Timer_attributes);
69-
BC260Y_initHandle = osThreadNew(Start_BC260Y_init, NULL, &BC260Y_init_attributes);
70-
}
48+
7149

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

75-
osEventFlagsSet(getCarDataHandle, 0x07); // 0000 0111
53+
osEventFlagsSet(getCarDataHandle, 0x0f); // 0000 1111
7654
//lv_event_send(ui_speedMeter, SPEED_CHANGED, NULL);
7755
uploadFlag = 1;
7856
#endif

Bsp/CAN/bsp_CAN.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void uploadCarData();
2323
#define GUI_UPDATE_EVENT (0x01 << 1)//设置事件掩码的位 1
2424
#define LED_EVENT (0x01 << 2)//设置事件掩码的位 2
2525
#define MQTT_INIT (0x01 << 3)//设置事件掩码的位 3
26+
2627
#if Transmitter
2728
void carDataUpdate();
2829
void canDataPack();
@@ -31,37 +32,5 @@ void canDataPack();
3132
#if Receiver
3233
void decodeCanData(uint32_t canID, uint8_t *canData);
3334
#endif
34-
struct RacingCarData
35-
{
36-
37-
//ID:0X193
38-
uint8_t FrontSpeed; //前轮车速 在这里作为参考车速 1Byte
39-
uint8_t PedalTravel; //油门踏板开度 1Byte
40-
uint8_t brakeTravel; //刹车踏板开度 1Byte
41-
uint8_t carTravel; //车辆跑动距离 1Byte
42-
uint16_t l_motor_torque; //左电机目标转矩 2Byte
43-
uint16_t r_motor_torque; //右电机目标转矩 2Byte
4435

45-
//ID:0X196
46-
uint8_t batAlarm; //电池告警 0~4 无告警:0 一级告警:1(最严重) 二级告警:2 三级告警:3 1Byte
47-
uint8_t batTemp; //电池温度 0-160 offset:-40 1Byte
48-
uint8_t batLevel; //电池电量 0-100 1Byte
49-
uint16_t batVol; //电池电压 0-900 2Byte
50-
uint8_t gearMode; //挡位信息 1Bit 1Byte
51-
uint8_t carMode; //车辆运行模式 1Bit
52-
//ID:0X191
53-
uint16_t lmotorSpeed; //左电机转速 2Bit offset -10000rpm 分辨率:0.5
54-
//ID:0X192
55-
uint8_t lmotorTemp; //左电机温度 1Byte 0~150摄氏度 offset:-50
56-
uint8_t mcu1Temp; //电机控制器1温度 1Byte 0~150摄氏度 offset:-50
57-
//ID:0X194
58-
uint16_t rmotorSpeed; //右电机转速 2Bit offset -10000rpm 分辨率:0.5
59-
//ID:0X195
60-
uint8_t rmotorTemp; //右电机温度
61-
uint8_t mcu2Temp; //电机控制器2温度
62-
63-
64-
};
65-
extern struct RacingCarData racingCarData;
66-
extern uint8_t uploadFlag;
6736
#endif //__BSP_CAN_H__

Bsp/WS2812B/bsp_WS2812B.c

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "bsp_CAN.h"
44
#include "cmsis_os2.h"
55
#include "SH_Data.h"
6+
#include "applicationVar.h"
7+
68

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

8688
void RPM_LED_Shine()
8789
{
88-
//x / 500
89-
#if canOPEN
9090
uint8_t ledNums, i;
9191
ws2812_init(12);
92-
ledNums = racingCarData.lmotorSpeed / 400;
92+
#if canOPEN
93+
#endif
9394

94-
for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
95-
{
96-
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
97-
}
98-
while(ledNums>10)
95+
#if simhubOPEN
96+
if(appStatus.canOpenStatus)
9997
{
100-
ws2812_green(ledNums);//RGB
101-
osDelay(80);
102-
ws2812_init(12);
103-
osDelay(80);
10498
ledNums = racingCarData.lmotorSpeed / 400;
105-
}
106-
#endif
10799

108-
#if simhubOPEN
109-
uint8_t ledNums, i;
110-
ws2812_init(12);
111-
ledNums = sh_CarData.rpm / (sh_CarData.redRpm / 12);
100+
for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
101+
{
102+
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
103+
}
104+
while(ledNums>10)
105+
{
106+
ws2812_green(ledNums);//RGB
107+
osDelay(80);
108+
ws2812_init(12);
109+
osDelay(80);
110+
ledNums = racingCarData.lmotorSpeed / 400;
111+
}
112+
}
112113

113-
for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
114+
if(appStatus.simhubStatus)
114115
{
115-
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
116+
ledNums = sh_CarData.rpm / (sh_CarData.redRpm / 12);
117+
118+
for(i = 0; i < ledNums; i++)//Öð¸öµãÁÁLED
119+
{
120+
ws2812_set_RGB(i*25, (12-i)*5, (12-i)*2, i);//RGB
121+
}
122+
while(ledNums>10 &&(sh_CarData.rpm > sh_CarData.redRpm) )
123+
{
124+
ws2812_red(ledNums);//RGB
125+
osDelay(80);
126+
ws2812_init(12);
127+
osDelay(80);
128+
ledNums = sh_CarData.rpm / 400;
129+
}
116130
}
117-
while(ledNums>10 &&(sh_CarData.rpm > sh_CarData.redRpm) )
131+
132+
if(appStatus.standByStatus)
118133
{
119-
ws2812_red(ledNums);//RGB
120-
osDelay(80);
121-
ws2812_init(12);
122-
osDelay(80);
123-
ledNums = sh_CarData.rpm / 400;
134+
ws2812_blue(12);//RGB
124135
}
136+
125137
#endif
126138

127139
}

Bsp/shApplication/SH_Data.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "SH_Data.h"
22
#include "Bsp_USB_Composite.h"
3+
#include "applicationVar.h"
4+
35
#define jsmnUsing 1
46

57
uint8_t get_data_flag = 0;
6-
uint8_t buf[1024] __attribute__((section(".CCM_RAM")));
8+
uint8_t buf[1024] ;//__attribute__((section(".CCM_RAM")));
79
uint32_t data_nums = 0;
8-
struct SH_CarData sh_CarData __attribute__((section(".CCM_RAM")));
10+
911

1012

1113
//½âÎöÊý¾Ý

Bsp/shApplication/SH_Data.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55
//#include "jansson.h"
66

77

8-
struct SH_CarData
9-
{
10-
uint16_t speed;
11-
uint16_t rpm;
12-
uint16_t redRpm;
13-
uint8_t *Gear;
14-
uint8_t fuel;
15-
uint8_t *bLapTime;
16-
uint8_t *cLapTime;
17-
uint8_t lap;
18-
uint8_t brake;
19-
uint8_t throttle;
20-
21-
};
228

239

2410
extern struct SH_CarData sh_CarData;

Core/Inc/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#define configTICK_RATE_HZ ((TickType_t)1000)
6969
#define configMAX_PRIORITIES ( 56 )
7070
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
71-
#define configTOTAL_HEAP_SIZE ((size_t)15360)
71+
#define configTOTAL_HEAP_SIZE ((size_t)1024*20)
7272
#define configMAX_TASK_NAME_LEN ( 16 )
7373
#define configUSE_TRACE_FACILITY 1
7474
#define configUSE_16_BIT_TICKS 0

Core/Inc/applicationVar.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#include "main.h"
55

6+
7+
#define RXBUFFERSIZE 16 //最大接收字节数
8+
69
struct appStatus_t{
710
uint8_t standByStatus; //待机模式 1为待机模式
811
uint8_t canOpenStatus; //实车模式 1为实车模式
@@ -11,10 +14,66 @@ struct appStatus_t{
1114
};
1215

1316

14-
extern struct appStatus_t appStatus;
17+
struct RacingCarData
18+
{
19+
20+
//ID:0X193
21+
uint8_t FrontSpeed; //前轮车速 在这里作为参考车速 1Byte
22+
uint8_t PedalTravel; //油门踏板开度 1Byte
23+
uint8_t brakeTravel; //刹车踏板开度 1Byte
24+
uint8_t carTravel; //车辆跑动距离 1Byte
25+
uint16_t l_motor_torque; //左电机目标转矩 2Byte
26+
uint16_t r_motor_torque; //右电机目标转矩 2Byte
27+
28+
//ID:0X196
29+
uint8_t batAlarm; //电池告警 0~4 无告警:0 一级告警:1(最严重) 二级告警:2 三级告警:3 1Byte
30+
uint8_t batTemp; //电池温度 0-160 offset:-40 1Byte
31+
uint8_t batLevel; //电池电量 0-100 1Byte
32+
uint16_t batVol; //电池电压 0-900 2Byte
33+
uint8_t gearMode; //挡位信息 1Bit 1Byte
34+
uint8_t carMode; //车辆运行模式 1Bit
35+
//ID:0X191
36+
uint16_t lmotorSpeed; //左电机转速 2Bit offset -10000rpm 分辨率:0.5
37+
//ID:0X192
38+
uint8_t lmotorTemp; //左电机温度 1Byte 0~150摄氏度 offset:-50
39+
uint8_t mcu1Temp; //电机控制器1温度 1Byte 0~150摄氏度 offset:-50
40+
//ID:0X194
41+
uint16_t rmotorSpeed; //右电机转速 2Bit offset -10000rpm 分辨率:0.5
42+
//ID:0X195
43+
uint8_t rmotorTemp; //右电机温度
44+
uint8_t mcu2Temp; //电机控制器2温度
1545

46+
};
47+
48+
struct SH_CarData
49+
{
50+
uint16_t speed;
51+
uint16_t rpm;
52+
uint16_t redRpm;
53+
uint8_t *Gear;
54+
uint8_t fuel;
55+
uint8_t *bLapTime;
56+
uint8_t *cLapTime;
57+
uint8_t lap;
58+
uint8_t brake;
59+
uint8_t throttle;
60+
61+
};
1662

1763

64+
extern struct RacingCarData racingCarData;
65+
extern struct appStatus_t appStatus;
66+
extern uint8_t uploadFlag;
67+
68+
extern char RxBuffer1[RXBUFFERSIZE]; //接收数据
69+
extern char RxBuffer3[RXBUFFERSIZE]; //接收数据
70+
extern char Buffer[RXBUFFERSIZE]; //接收数据
71+
extern uint8_t aRxBuffer1; //接收中断缓冲
72+
extern uint8_t aRxBuffer3; //接收中断缓冲
73+
extern uint8_t Uart1_Rx_Cnt; //接收缓冲计数
74+
extern uint8_t Uart3_Rx_Cnt; //接收缓冲计数
75+
extern uint8_t okFlag;
76+
extern uint8_t MQTTinitOkFlag;
1877

1978

2079
#endif //_APPLICATIONVAR_H_

Core/Src/applicationVar.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,25 @@
44
struct appStatus_t appStatus;
55

66

7+
#define SPEED_RATIO 4 //主减速比
8+
#define PI 3.14 //圆周率
9+
#define WHEEL_R 0.2286 //车轮半径
10+
#define NUM_OF_TEETH 20.0 //码盘齿数
11+
12+
13+
uint8_t upSpeedFlag = 1;
14+
uint8_t uploadFlag = 1;
15+
struct RacingCarData racingCarData;
16+
17+
char RxBuffer1[RXBUFFERSIZE]; //接收数据
18+
char RxBuffer3[RXBUFFERSIZE]; //接收数据
19+
uint8_t aRxBuffer1; //接收中断缓冲
20+
uint8_t aRxBuffer3; //接收中断缓冲
21+
char Buffer[RXBUFFERSIZE];
22+
uint8_t Uart1_Rx_Cnt = 0; //接收缓冲计数
23+
uint8_t Uart3_Rx_Cnt = 0; //接收缓冲计数
24+
uint8_t okFlag = 0; //是否查询OK字符标志位
25+
uint8_t MQTTinitOkFlag = 0; //初始化是否OK标志位
26+
27+
28+
struct SH_CarData sh_CarData ;//__attribute__((section(".CCM_RAM")));

0 commit comments

Comments
 (0)