|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// 注意解码超限问题
|