giant_can.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * @file giant_can.h
  3. * @author Ye Jin
  4. * @brief giant can protocol
  5. * @version 0.1
  6. * @date 2025-01-09
  7. *
  8. * @copyright Copyright (c) 2025
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #ifndef GIANT_CAN_H
  16. #define GIANT_CAN_H
  17. #include "typedefine.h"
  18. /****************************************
  19. *
  20. * Definitions & Macros
  21. *
  22. ****************************************/
  23. #define MAXFRAME_SIZE 16
  24. //DriveChain Dir -for updata
  25. #define MC_FILEMAINDIR 0x0006
  26. #define MC_FILESUBDIR 0x0100
  27. //Data Frame- Function group
  28. #define FG_NETWORKMANAGER 0x0
  29. #define FG_EVENT 0x1
  30. #define FG_RESPONSEDATA 0x2
  31. #define FG_NORMALDATA 0x3
  32. //Node group
  33. #define NODE_ALL 0x0
  34. #define NODE_SERVICETOOL 0x1
  35. #define NODE_USERINTERFACE 0x2
  36. #define NODE_DRIVECHAIN 0x6
  37. #define NODE_MOTINOVA 0x7
  38. #define NODE_ENERGYPACK 0xC
  39. #define NODE_GIANTAPP 0xF
  40. //Data Frame-Data behavior
  41. #define DB_ACTIVEDATA 0x0
  42. #define DB_PASSIVEDATA 0x1
  43. //Remote Frame- motion group
  44. #define MG_HEARTBEAT 0x0
  45. #define MG_CONFIRMATION 0x1
  46. #define MG_ACTIVEDATA1 0x2
  47. #define MG_ACTIVEDATA2 0x3
  48. #define MG_PASSIVEDATA1 0x4
  49. #define MG_PASSIVEDATA2 0x5
  50. #define MG_PASSIVEDATA3 0x6
  51. #define MG_PASSIVEDATA4 0x7
  52. //mode
  53. #define AD_SERVICEMODE_S 0x6
  54. #define AD_SERVICEMODE_E 0xA
  55. #define AD_CHECKMODE 0xB
  56. #define AD_OFFMODE 0xC
  57. #define AD_ERRORMODE 0xD
  58. /***************************************
  59. *
  60. * Type Definations
  61. *
  62. ***************************************/
  63. /**
  64. * @brief Rx Standard Data ID
  65. *
  66. */
  67. typedef struct
  68. {
  69. UBYTE ucFrameSize; //缓冲区数组:缓冲区大小
  70. UBYTE ucFrameWrInde; //缓冲区数组:写索引
  71. UBYTE ucFrameRdInde; //缓冲区数组:读索引
  72. UBYTE ucFrameCnt; //缓冲区数组:数据计数
  73. } CANFrame_Info_Struct_t;
  74. typedef struct
  75. {
  76. ULONG id; /*!< standard format frame identifier */
  77. UBYTE rx_ff; /*!< format of frame, standard or extended format */
  78. UBYTE rx_ft; /*!< type of frame, data or remote */
  79. UBYTE rx_dlen; /*!< data length */
  80. UBYTE rx_data[8]; /*!< receive data */
  81. } CAN_ReceiveFrame_Struct_t;
  82. typedef struct
  83. {
  84. UBYTE FunctionGroup;//2 bits
  85. UBYTE NodeGroup;//4 bits
  86. UBYTE DataBehaviors;//1 bit
  87. UBYTE DataAddress;//4 bits
  88. } GiantStandardDataFrameID_Struct_t;
  89. typedef struct
  90. {
  91. UBYTE MotionGroup;//3 bits
  92. UBYTE RequireNodeGroup;//4 bits
  93. UBYTE ResponseNodeGroup;//4 bits
  94. } GiantStandardRemoteFrameID_Struct_t;
  95. typedef struct
  96. {
  97. UWORD RefreshFlag;
  98. UBYTE Error;
  99. UBYTE ManualSleepEn;
  100. UBYTE AutomaticSleepEn;//1-ignore,0-keep
  101. UBYTE InactivateErrorDetection;
  102. UBYTE ThrottleEn;
  103. UBYTE BrakeleEn;
  104. UBYTE WalkEn;
  105. UBYTE ThrottlePowerPercentage;
  106. UBYTE RidingModeEn;
  107. UBYTE AdjustingMode;
  108. UBYTE StartMode;
  109. UWORD WheelCircumference;
  110. UBYTE MaximumTorque;
  111. UBYTE Acceleration;
  112. UBYTE AssistRatio;
  113. UBYTE MaximumPower;
  114. UWORD SpeedLimitation;
  115. UBYTE CommSleep;
  116. } GiantControlParams_Struct_t;
  117. /*****************************************
  118. *
  119. * Exported variable
  120. *
  121. ****************************************/
  122. //extern GiantStandardDataFrameID_Struct_t stGiantStandardDataFrameID_rx;
  123. //extern GiantStandardRemoteFrameID_Struct_t stGiantStandardRemoteFrameID_rx;
  124. extern GiantControlParams_Struct_t stGiantControlParams;
  125. //extern CANFrame_Info_Struct_t stCANFrame_InfoRx;
  126. //extern CAN_ReceiveFrame_Struct_t stCAN_ReceiveFrame_Buf_Rx[MAXFRAME_SIZE];
  127. /***************************************
  128. *
  129. * Function Definations
  130. *
  131. ***************************************/
  132. void giant_Init(void);
  133. void giant_10msTask(void);
  134. void CANFrame_Rx_ISR(void);
  135. void giant_CANRxData_Process(void);
  136. void giant_SendDriveChainPassiveData(UBYTE remoteMG, UBYTE DataAddr);
  137. void giant_SendDriveChainActiveData(UBYTE functiongroup, UBYTE dataaddr);
  138. void giant_SendRemote(UBYTE motiongroup);
  139. void giant_SendExtendData(UBYTE dataaddr, UBYTE datatype, UBYTE *data, UBYTE len);
  140. void giant_DataProcess(void);
  141. SLONG giant_slPolynomial(const SWORD *value);
  142. /************************************************************************/
  143. #endif
  144. /************************************************************************
  145. End of this File (EOF):
  146. Do not put anything after this part!
  147. *************************************************************************/