Pārlūkot izejas kodu

4G振动测试代码

LAPTOP-KB7QFH2U\ChenJie-PC 2 gadi atpakaļ
vecāks
revīzija
5bb97ef849

+ 1 - 1
code/app/AppGlobalVar.c

@@ -20,7 +20,7 @@
 
 #define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"
-AppConfigBody AppConfigInfo = {false, true, {defaultSn}, {0}};
+AppConfigBody AppConfigInfo = {true, false, {defaultSn}, {0}};
 #define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"
 

+ 88 - 1
code/app/AppTaskCan.c

@@ -12,10 +12,19 @@
 #include "AppFuncLib.h"
 #ifdef APP_CAN_ENABLE
 static uint8 BattSendFlg = 0;
+uint8 getDataFlg = false;
 static void UDSAnsFunc(uint8 *rawData);
 static void UdsAns(bool PosFlg, uint8 UdsService, uint8 UdsSubService, uint8 Idx, uint8 *AnsData, uint8 AnsDataLen);
 static void BattSendFunc(void);
-
+static void vtimerCallback_Can(TimerHandle_t pxTimer)
+{
+	uint32 ulTimerID;
+	ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
+	if (ulTimerID == 0)
+	{
+		getDataFlg = true;
+	}
+}
 void CanTask(void *pvParameters)
 {
 	uint32 timerCANIdle = 0x00;
@@ -24,8 +33,21 @@ void CanTask(void *pvParameters)
 	CanIf_bRxFlag = false;
 	Can_Msg_Type_Data CanRxMsg;
 	CanRecvQueueHandle1 = xQueueCreate(100, sizeof(Can_Msg_Type_Data));
+	TimerHandle_t CanmonitorTimer1ms;
+	CanmonitorTimer1ms = xTimerCreate("monitor1ms", 2, pdTRUE, (void *)0, vtimerCallback_Can);
+	xTimerStart(CanmonitorTimer1ms, 0);
 	BaseType_t ret = pdFALSE;
 	GsensorInit();
+	real_T S0[SIZE_FFT];
+	real_T S1[SIZE_FFT];
+	real_T S2[SIZE_FFT];
+	uint16 fftIdx = 0;
+	Can_Msg_Type CanTxMsg;
+	CanTxMsg.idFrame = CAN_EXTENDED_ID_TYPE;
+	CanTxMsg.length = 8;
+	uint8 xyzTrans[8] = {0};
+	uint32 CanIdFFT_test = 0x1C01EAED;
+	CanTxMsg.id = CanIdFFT_test;
 	while (1)
 	{
 		Can_MainFunction_Read();
@@ -60,6 +82,71 @@ void CanTask(void *pvParameters)
 			BcuRxDiagnose();
 			timerCounterNow = TimerCounter;
 		}
+		if (getDataFlg)
+		{
+			getDataFlg = false;
+			SL_SC7A20_Read_XYZ_Data(xyzData);
+			S0[fftIdx] = (real_T)xyzData[0];
+			S1[fftIdx] = (real_T)xyzData[1];
+			S2[fftIdx] = (real_T)xyzData[2];
+			fftIdx++;
+			uint16 xyzDatacache[3] = {0};
+			memcpy(xyzDatacache, xyzData, 3 * sizeof(uint16));
+			for (uint8 i = 0; i < 3; i++)
+			{
+				if (xyzDatacache[i] > 0x8000) // 数据为负
+				{
+					xyzDatacache[i] = 20000U + (sint16)xyzDatacache[i];
+				}
+				else
+				{
+					xyzDatacache[i] = xyzDatacache[i] + 20000U;
+				}
+			}
+			xyzTrans[2] = xyzDatacache[0]>>8;
+			xyzTrans[3] = xyzDatacache[0];
+			xyzTrans[4] = xyzDatacache[1]>>8;
+			xyzTrans[5] = xyzDatacache[1];
+			xyzTrans[6] = xyzDatacache[2]>>8;
+			xyzTrans[7] = xyzDatacache[2];
+			xyzTrans[0] = 0x00;
+			xyzTrans[1] = fftIdx;
+			CanTxMsg.sdu = xyzTrans;
+			if(fftIdx%2==0)
+			{
+				CanIf_SendMessage(CAN1, CanTxMsg);
+			}
+		}
+		if (fftIdx >= SIZE_FFT)
+		{
+			fft(S0, sizeof(S0) / sizeof(real_T), 500, returnFreq[0], returnP[0]); // 250 max
+			fft(S1, sizeof(S1) / sizeof(real_T), 500, returnFreq[1], returnP[1]);
+			fft(S2, sizeof(S2) / sizeof(real_T), 500, returnFreq[2], returnP[2]);
+			fftIdx = 0;
+			for(uint8 i=0;i<3;i++)
+			{
+				xyzTrans[2] = ((uint16)(returnFreq[i][0]*10))>>8;
+				xyzTrans[3] = ((uint16)(returnFreq[i][0]*10));
+				xyzTrans[4] = ((uint16)(returnFreq[i][1]*10))>>8;
+				xyzTrans[5] = ((uint16)(returnFreq[i][1]*10));
+				xyzTrans[6] = ((uint16)(returnFreq[i][2]*10))>>8;
+				xyzTrans[7] = ((uint16)(returnFreq[i][2]*10));
+				xyzTrans[0] = 0x01;
+				xyzTrans[1] = i;
+				CanTxMsg.sdu = xyzTrans;
+				CanIf_SendMessage(CAN1, CanTxMsg);
+				xyzTrans[2] = ((sint16)(returnP[i][0]*10))>>8;
+				xyzTrans[3] = ((sint16)(returnP[i][0]*10));
+				xyzTrans[4] = ((sint16)(returnP[i][1]*10))>>8;
+				xyzTrans[5] = ((sint16)(returnP[i][1]*10));
+				xyzTrans[6] = ((sint16)(returnP[i][2]*10))>>8;
+				xyzTrans[7] = ((sint16)(returnP[i][2]*10));
+				xyzTrans[0] = 0x02;
+				xyzTrans[1] = i;
+				CanTxMsg.sdu = xyzTrans;
+				CanIf_SendMessage(CAN1, CanTxMsg);
+			}
+		}
 	}
 }
 // 注意解码超限问题

+ 1 - 20
code/app/AppTaskGps.c

@@ -33,14 +33,10 @@ void GpsTask(void *pvParameters)
 	TimerHandle_t monitorTimer1ms;
 	monitorTimer1ms = xTimerCreate("monitor1ms", 1, pdTRUE, (void *)0, vtimerCallback);
 	xTimerStart(monitorTimer1ms, 0);
-	real_T S0[SIZE_FFT];
-	real_T S1[SIZE_FFT];
-	real_T S2[SIZE_FFT];
-	uint8 fftIdx = 0;
 	while(1)
 	{
 		memset(GpsRecvPtr,0,sizeof(GpsRecvPtr));
-		UART_Receive_Data(UART_LPUART2,GpsRecvPtr,&pReadLen,1);
+		UART_Receive_Data(UART_LPUART2,GpsRecvPtr,&pReadLen,10);
 		if(pReadLen>0)
 		{
 			GpsDataDecode(GpsRecvPtr);
@@ -58,21 +54,6 @@ void GpsTask(void *pvParameters)
 				Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5,STD_OFF);
 			}
 		}
-		if (timerCounterGetdata % 10 == 0)
-		{
-			SL_SC7A20_Read_XYZ_Data(xyzData);
-			S0[fftIdx] = (real_T)xyzData[0];
-			S1[fftIdx] = (real_T)xyzData[1];
-			S2[fftIdx] = (real_T)xyzData[2];
-			fftIdx++;
-		}
-		if (fftIdx >= SIZE_FFT)
-		{
-			fftIdx = 0;
-			fft(S0, sizeof(S0) / sizeof(real_T), 100, returnFreq[0], returnP[0]); // 50 max
-			fft(S1, sizeof(S1) / sizeof(real_T), 100, returnFreq[1], returnP[1]);
-			fft(S2, sizeof(S2) / sizeof(real_T), 100, returnFreq[2], returnP[2]);
-		}
 	}
 }
 void GpsDataDecode(uint8 *msg)

+ 0 - 3
code/app/lib/AppFuncLib.c

@@ -891,9 +891,6 @@ void fft(real_T *S, uint16_T N, real_T freq, real_T *returnFreq, real_T *returnP
 	creal_T X[SIZE_FFT];
 	creal_T W[SIZE_FFT];
 	real_T Y1[SIZE_FFT];
-
-//	real_T Y2[SIZE_FFT / 2 + 1];
-//	real_T F[SIZE_FFT / 2 + 1];
 	fft_type fft_data[SIZE_FFT / 2 + 1];
     uint16_T i = 0;
     uint16_T j = 0;

+ 1 - 1
code/app/lib/AppFuncLib.h

@@ -45,7 +45,7 @@ int _sprintf(char *dst, const char *format, ...);
 uint16 crc_chk(uint8 *data, uint8 length);
 
 /*********************************************************************************************/
-#define SIZE_FFT 64
+#define SIZE_FFT 256
 typedef struct _fft_Freq
 {
 	real_T freq;

+ 3 - 3
code/main.c

@@ -83,10 +83,10 @@ int main(void)
 	SEGGER_RTT_printf("boot\n");
 #endif
 	UartInit();
-	xTaskCreate(MainTask, (const char *const)"MainTask", 4096, (void *)0, main_TASK_PRIORITY + 6, MainTask_Handle);
+	xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, MainTask_Handle);
 	//xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, Uart0Task_Handle);
-	xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
-	xTaskCreate(GpsTask, (const char *const)"GpsTask", 2048, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
+	xTaskCreate(CanTask, (const char *const)"CanTask", 8192, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
+	xTaskCreate(GpsTask, (const char *const)"GpsTask", 512, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
 	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, &Uart_4G_Task_Handle);
 	vTaskStartScheduler();