浏览代码

giant调试

Ye Jin 6 月之前
父节点
当前提交
25a8228e99

+ 3 - 0
User project/1.FrameLayer/Source/main.c

@@ -38,6 +38,7 @@
 #include "app.h"
 #include "Temp.h"
 #include "enviolo_can.h"
+#include "giant_can.h"
 #include "profiler.h"
 /***************************
 *********************************************
@@ -81,6 +82,8 @@ int main(void) /* parasoft-suppress GJB5369-4_2_1_10 "mismatch" */
     profiler_init();
     //Enviolo gear sensor init
     GearBox_Init();
+    //ganir control data init
+    giant_Init();
     /* Timer enable */
     hw_voTimEn();
     /* Interrupts of peripherals enable*/

+ 7 - 0
User project/3.BasicFunction/Include/giant_can.h

@@ -47,6 +47,11 @@
 #define MG_PASSIVEDATA2      0x5
 #define MG_PASSIVEDATA3      0x6
 #define MG_PASSIVEDATA4      0x7
+//mode
+#define AD_SERVICEMODE       0x6
+#define AD_CHECKMODE         0xB
+#define AD_OFFMODE           0xC
+#define AD_ERRORMODE         0xD
 /***************************************
  *
  *          Type  Definations
@@ -105,10 +110,12 @@ extern GiantControlParams_Struct_t stGiantControlParams;
  *          Function  Definations
  *
  ***************************************/
+void giant_Init(void);
 void giant_10msTask(void);
 void giant_DataProcess(void);
 void giant_SendDriveChainPassiveData(UBYTE remoteMG, UBYTE DataAddr);
 void giant_SendDriveChainActiveData(UBYTE functiongroup, UBYTE dataaddr);
+void giant_CANRxData_Process(void);
 /************************************************************************/
 
 #endif

+ 3 - 0
User project/3.BasicFunction/Source/can.c

@@ -62,6 +62,7 @@ ULONG    CRC32_Calculate(const UBYTE pData[], UWORD Length)
 #include "gd32f30x.h"
 #include "hwsetup.h"
 #include "enviolo_can.h"
+#include "giant_can.h"
 static const ULONG Crc32Table[256] = {
     0x00000000U, 0x04C11DB7U, 0x09823B6EU, 0x0D4326D9U, 0x130476DCU, 0x17C56B6BU, 0x1A864DB2U, 0x1E475005U, 0x2608EDB8U, 0x22C9F00FU, 0x2F8AD6D6U, 0x2B4BCB61U,
     0x350C9B64U, 0x31CD86D3U, 0x3C8EA00AU, 0x384FBDBDU, 0x4C11DB70U, 0x48D0C6C7U, 0x4593E01EU, 0x4152FDA9U, 0x5F15ADACU, 0x5BD4B01BU, 0x569796C2U, 0x52568B75U,
@@ -375,6 +376,8 @@ void CanRx_Process(void)
     CAN_RxData_Process(&CAN_RxBuf_Struct_BMS, 500);
     CAN_RxData_Process(&CAN_RxBuf_Struct_HMI, 500);
     CAN_RxData_Process(&CAN_RxBuf_Struct_CDL, 500);
+    
+    giant_CANRxData_Process();
 }
 
 void DataProcess(UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE Data[]) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */

+ 56 - 37
User project/3.BasicFunction/Source/giant_can.c

@@ -39,18 +39,33 @@ GiantControlParams_Struct_t stGiantControlParams;
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
+void giant_Init(void)
+{
+    stGiantControlParams.RidingModeEn = 0;
+    stGiantControlParams.AdjustingMode = 0x0B;//check mode
+}
 void giant_10msTask(void)
 {
     static UBYTE giant_10mscount = 0;
     
+    if(power_stPowStateOut.powerstate == POWER_OFF)
+    {
+        return;
+    }
+    
     giant_10mscount++;
     if(giant_10mscount >= 5)
     {
         giant_10mscount = 0;
-        for(int i=0;i<9;i++)
-        {
-            giant_SendDriveChainActiveData(FG_NORMALDATA, i);
-        }
+        
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x0);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x1);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x2);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x3);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x4);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x6);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x7);
+        giant_SendDriveChainActiveData(FG_NORMALDATA, 0x8);
         giant_SendDriveChainActiveData(FG_NORMALDATA, 0xF);
     }
 }
@@ -125,26 +140,6 @@ void giant_DataProcess(void)
                             
                             stGiantControlParams.RidingModeEn = ((pRxMsg2->rx_data[3] & 0x80)>>7);//Riding mode
                             stGiantControlParams.AdjustingMode = (pRxMsg2->rx_data[3] & 0x1F);//Adjusting mode
-                            if((stGiantControlParams.AdjustingMode  >= 0x6) && (stGiantControlParams.AdjustingMode  <= 0xA))//Service mode
-                            {
-                              
-                            }
-                            else if(stGiantControlParams.AdjustingMode  == 0xB)//Check mode
-                            {
-                              
-                            }
-                            else if(stGiantControlParams.AdjustingMode  == 0xC)//Off mode
-                            {
-                              
-                            }
-                            else if(stGiantControlParams.AdjustingMode  == 0xD)//error state
-                            {
-                                
-                            }
-                            else
-                            {
-                              
-                            }
                             
                             if((pRxMsg2->rx_data[4] & 0x04) == 0x04)//Reset odometer distance and odometer time
                             {
@@ -285,10 +280,15 @@ void giant_DataProcess(void)
                 }
                 case MG_ACTIVEDATA1:
                 {
-                    for(int i=0;i<8;i++)
+                    for(int i=0;i<5;i++)
                     {
                         giant_SendDriveChainActiveData(FG_RESPONSEDATA, i);
                     }
+                    
+                    for(int j=6;j<8;j++)
+                    {
+                        giant_SendDriveChainActiveData(FG_RESPONSEDATA, j);
+                    }
                     break;
                 }
                 case MG_ACTIVEDATA2:
@@ -386,15 +386,7 @@ void giant_SendDriveChainPassiveData(UBYTE remoteMG, UBYTE DataAddr)
         {
             len = 4;
             data[0] = 0x1;//success
-            if(remoteMG == MG_HEARTBEAT)
-            {
-                data[1] = 0x00;
-                data[2] = 0x00;
-            }
-            else
-            {
-                memcpy(&data[1], &ass_stParaCong.uwWheelPerimeter, 2);//circumference
-            }
+            memcpy(&data[1], &stGiantControlParams.WheelCircumference, 2);//circumference
             data[3] = (UBYTE)ass_stParaCong.swDeltPerimeter;
             break;
         }
@@ -555,17 +547,44 @@ void giant_SendDriveChainActiveData(UBYTE functiongroup, UBYTE dataaddr)
     CAN_SendData(ID, data, len);
 }
 
-void giant_CanProcess(void)
+void giant_CANRxData_Process(void)
 {
     if(stGiantControlParams.RefreshFlag)
     {
         stGiantControlParams.RefreshFlag = FALSE;
         
-        if((stGiantControlParams.AdjustingMode  == 0xC) || (stGiantControlParams.ManualSleepEn) || (stGiantControlParams.AutomaticSleepEn) || ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 3000))//Off state
+        if((stGiantControlParams.AdjustingMode  == 0xC) || (stGiantControlParams.ManualSleepEn) || (stGiantControlParams.AutomaticSleepEn) || ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 1500))//Off state
         {
             power_stPowStateOut.powerstate = POWER_OFF;
             power_stPowStateOut.blPowerStartupFlg = FALSE;
-        }   
+        }
+        
+        if((stGiantControlParams.AdjustingMode >= AD_SERVICEMODE) && (stGiantControlParams.AdjustingMode <= AD_ERRORMODE))
+        {
+            MC_ControlCode.GearSt = MC_GearSt_OFF;
+        }
+        else if(stGiantControlParams.AssistRatio == 0)
+        {
+            MC_ControlCode.GearSt = MC_GearSt_OFF;
+        }
+        else if(stGiantControlParams.RidingModeEn == 0)
+        {
+            MC_ControlCode.GearSt = MC_GearSt_OFF;
+        }
+        else if(stGiantControlParams.WalkEn == 1)
+        {
+            MC_ControlCode.GearSt = MC_GearSt_WALK;
+        }
+        else
+        {
+            MC_ControlCode.GearSt = MC_GearSt_Torque_ECO;
+        }
+        MC_RunInfo.GearSt = (UBYTE)MC_ControlCode.GearSt;
+        
+        if(stGiantControlParams.AdjustingMode == AD_CHECKMODE)
+        {
+            ass_stParaCong.uwWheelPerimeter = stGiantControlParams.WheelCircumference;
+        }
     }
 }
 /*************************************************************************

+ 15 - 15
User project/3.BasicFunction/Source/power.c

@@ -106,21 +106,21 @@ void power_voPowerManagement(UWORD uwPowerPara, ULONG SysTickCnt, ULONG OBC_Butt
         case POWER_ON_END: // 电源键按下进入POWER_OFF,或待机设定时候后自动进入POWER_OFF
         {
             //The key pushed down for "uwPowerShutTouchTimeCnt" to POWER_OFF
-            if (iGpio_Read(HW_GPIO_POWERSTATE_PIN) != 0)
-            {
-                power_stPowStateOut.uwPowerShutdnCnt++;
-                if (power_stPowStateOut.uwPowerShutdnCnt >= ulPowerOFFDelayTime)
-                {
-                    power_stPowStateOut.powerstate = POWER_OFF;
-                    power_stPowStateOut.blPowerStartupFlg = FALSE;
-                    //Send power off command
-                    SendData(ID_MC_BC, MODE_REPORT, 0x1808, (uint8_t *)"SHUTDOWN");
-                }
-            }
-            else
-            {
-                power_stPowStateOut.uwPowerShutdnCnt = 0;
-            }
+//            if (iGpio_Read(HW_GPIO_POWERSTATE_PIN) != 0)
+//            {
+//                power_stPowStateOut.uwPowerShutdnCnt++;
+//                if (power_stPowStateOut.uwPowerShutdnCnt >= ulPowerOFFDelayTime)
+//                {
+//                    power_stPowStateOut.powerstate = POWER_OFF;
+//                    power_stPowStateOut.blPowerStartupFlg = FALSE;
+//                    //Send power off command
+//                    SendData(ID_MC_BC, MODE_REPORT, 0x1808, (uint8_t *)"SHUTDOWN");
+//                }
+//            }
+//            else
+//            {
+//                power_stPowStateOut.uwPowerShutdnCnt = 0;
+//            }
 
             //Do not auto power off
             if(ulAutoPowerOffDelayTime == 0)