dd пре 3 месеци
родитељ
комит
3b7781d21e

+ 86 - 0
3.BasicFunction/Include/uart_TORG4BBSensor.h

@@ -0,0 +1,86 @@
+/**
+  ******************************************************************************
+  * @file    uart_TORG4BBSensor.h
+  * @author
+  * @version V1.0.0
+  * @date    05-02-2025
+  * @brief   TORG4BBSensor function.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __UART_TORG4BBSENSOR_H
+#define __UART_TORG4BBSENSOR_H
+/* Includes ------------------------------------------------------------------*/
+#include "usart.h"
+
+#define TORG4BBCADENCE_LPF_GAIN                 80
+#define TORG4BBTORQUE_TIMEOUT_UNIT               10  //ms
+#define TORG4BBTORQUE_TIMEOUT_TIME               100  //ms
+#define TORG4BBTORQUE_NUMBERS_PULSES             9  //一周9个磁石
+/* Define to variables declare---------------------------------------------------*/
+//先发送低位后高位
+typedef struct
+{
+    SWORD swTemp;//温度
+    UWORD uwTorqueReg;//力矩
+    UWORD uwTorqueRegLast;//力矩last
+    UBYTE ucForwardCnt; //踏频脉冲
+    UBYTE ucForwardCntLast; //踏频脉冲last
+    UWORD uwFlyWheelSpeedCnt;//后飞轮电机转速Cnt
+    UWORD uwFlyWheelSpeed;//后飞轮转速rpm
+} TORG4BBInfo_Struct_t;
+
+typedef struct
+{
+    UWORD uwTorqueRegOffset;//力矩零点
+    UWORD uwTorqueReg2Pu;
+    UWORD uwTorqueLPFgain;
+    UWORD uwMaxTimeOutCnt;
+
+    UWORD uwTimeOutCnt;
+    UWORD uwTorquePu;//力矩
+    UWORD uwTorqueLPFPu;
+    UWORD uwTorqueLPFPuLast;
+} TORG4BB_OUT;
+
+/* Public variables declare---------------------------------------------------*/
+extern TORG4BBInfo_Struct_t stTORG4BBInfo;
+/*Private function declare---------------------------------------------------*/
+void TORG4BB_Init(void);
+void TORG4BB_USART_DataProcess(USART_Buf_TypeDef* ptUartTx, UBYTE* Data);
+void TORG4BB_USART_RxData_Process(USART_Buf_TypeDef* ptUartTx, UBYTE* buf, UWORD dataCount);
+void TORG4BB_Torque_Handler(void);
+uint32_t TORG4BB_Get_CAD_PORT(void);
+SWORD TORG4BB_Get_Temp(void);
+
+#endif
+
+/*---------------------------- file end -------------------------------------*/

+ 213 - 0
3.BasicFunction/Source/uart_TORG4BBSensor.c

@@ -0,0 +1,213 @@
+/**
+  ******************************************************************************
+  * @file    uart_TORG4BBSensor.h
+  * @author
+  * @version V1.0.0
+  * @date    05-02-2025
+  * @brief   TORG4BBSensor function.
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+/* Includes ------------------------------------------------------------------*/
+#include "uart_TORG4BBSensor.h"
+#include "FuncLayerAPI.h"
+#include "mathtool.h"
+#include "syspar.h"
+/******************************
+ *
+ *  Parameter
+ *
+ ******************************/
+static LPF_OUT scm_stTORG4BBTorLpf;
+TORG4BBInfo_Struct_t stTORG4BBInfo;
+TORG4BB_OUT stTORG4BB_stTorSensorOut;
+/******************************
+ *
+ *  Functions
+ *
+ ******************************/
+/***************************************************************
+ Function: TORG4BB_Init;
+ Description:Data Init
+ Call by:
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+void TORG4BB_Init(void)
+{
+#if (TORG4BBTORQU_ENABLE == 1)
+    stTORG4BB_stTorSensorOut.uwTorqueRegOffset = 217;//0.7/3.3*1024
+    stTORG4BB_stTorSensorOut.uwTorqueReg2Pu = (((SQWORD)3300 << 14) >> 10) / 35 * 10 / TORQUEBASE;
+    stTORG4BB_stTorSensorOut.uwTorqueLPFgain = TORG4BBCADENCE_LPF_GAIN;
+    stTORG4BB_stTorSensorOut.uwMaxTimeOutCnt = TORG4BBTORQUE_TIMEOUT_TIME / TORG4BBTORQUE_TIMEOUT_UNIT;
+
+    stTORG4BB_stTorSensorOut.uwTimeOutCnt = 0;
+    stTORG4BBInfo.uwTorqueReg = stTORG4BB_stTorSensorOut.uwTorqueRegOffset;
+
+    mth_voLPFilterCoef(1000000/2, 100, &scm_stTORG4BBTorLpf.uwKx);
+#endif
+}
+/***************************************************************
+ Function: TORG4BB_USART_DataProcess;
+ Description:Get TORG4BBSensor Data
+ Call by:
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+void TORG4BB_USART_DataProcess(USART_Buf_TypeDef* ptUartTx, UBYTE* Data)
+{
+    stTORG4BBInfo.ucForwardCntLast = stTORG4BBInfo.ucForwardCnt;
+    stTORG4BBInfo.uwTorqueRegLast = stTORG4BBInfo.uwTorqueReg;
+
+    stTORG4BBInfo.swTemp = (SWORD)(Data[1] - 30);
+    stTORG4BBInfo.uwTorqueReg = (((Data[4] & 0xC0)<<2) + Data[2]);
+    stTORG4BBInfo.ucForwardCnt = Data[3] & 0x7F;
+    stTORG4BBInfo.uwFlyWheelSpeedCnt = (((Data[4] & 0x1F)<<8) + Data[5]);
+    stTORG4BBInfo.uwFlyWheelSpeed = 30000/(stTORG4BBInfo.uwFlyWheelSpeedCnt*TORG4BBTORQUE_NUMBERS_PULSES);//rpm 1/(Cnt*0.2*TORG4BBTORQUE_NUMBERS_PULSES/1000/60)
+}
+/***************************************************************
+ Function: TORG4BB_USART_RxData_Process;
+ Description: Get Uart Data following the protocol
+ Call by:
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+void TORG4BB_USART_RxData_Process(USART_Buf_TypeDef* ptUartTx, UBYTE* buf, UWORD dataCount)
+{
+#if (TORG4BBTORQU_ENABLE == 1)
+    static UBYTE Data[255];
+    //UWORD Cmd, ID;
+    UWORD i;
+    UBYTE checksum = 0;
+    
+    if(dataCount == 8)
+    {
+        if(buf[0] == 0xFF)//起始
+        {
+            for(i=0; i<(dataCount-1); i++)//数据
+            {
+                Data[i] = buf[i];
+                checksum += buf[i];
+            }
+
+            if(checksum == buf[dataCount-1])// 校验和正常
+            {
+                TORG4BB_USART_DataProcess(ptUartTx, Data);
+            }
+        }
+    }
+#endif
+}
+/***************************************************************
+ Function: TORG4BB_Torque_Handler;
+ Description: Get TORG4BB_Torque Data
+ Call by:
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+void TORG4BB_Torque_Handler(void)
+{
+    if(stTORG4BBInfo.uwTorqueReg < stTORG4BB_stTorSensorOut.uwTorqueRegOffset)
+    {
+        stTORG4BB_stTorSensorOut.uwTorquePu = 0;
+    }
+    else
+    {
+        stTORG4BB_stTorSensorOut.uwTorquePu = (stTORG4BBInfo.uwTorqueReg - stTORG4BB_stTorSensorOut.uwTorqueRegOffset) * stTORG4BB_stTorSensorOut.uwTorqueReg2Pu;
+    }
+
+    //通信超时,清除力矩
+    if(stTORG4BBInfo.uwTorqueRegLast == stTORG4BBInfo.uwTorqueReg)
+    {
+        if(stTORG4BB_stTorSensorOut.uwTimeOutCnt < stTORG4BB_stTorSensorOut.uwMaxTimeOutCnt)
+        {
+            stTORG4BB_stTorSensorOut.uwTimeOutCnt++;
+        }
+        else
+        {
+            stTORG4BB_stTorSensorOut.uwTorquePu = 0;
+        }
+    }
+    else
+    {
+        stTORG4BB_stTorSensorOut.uwTimeOutCnt = 0;
+    }
+
+    //mth_voLPFilter(stTORG4BB_stTorSensorOut.uwTorquePu, &scm_stTORG4BBTorLpf);
+    //stTORG4BB_stTorSensorOut.uwTorqueLPFPu = scm_stTORG4BBTorLpf.slY.sw.hi;
+    stTORG4BB_stTorSensorOut.uwTorqueLPFPuLast = stTORG4BB_stTorSensorOut.uwTorqueLPFPu;
+    stTORG4BB_stTorSensorOut.uwTorqueLPFPu = (stTORG4BB_stTorSensorOut.uwTorqueLPFPu * stTORG4BB_stTorSensorOut.uwTorqueLPFgain +
+            stTORG4BB_stTorSensorOut.uwTorquePu * (100 - stTORG4BB_stTorSensorOut.uwTorqueLPFgain)) /
+           100;
+
+    torsensor_stTorSensorOut.uwTorqueReg = stTORG4BBInfo.uwTorqueReg;
+    torsensor_stTorSensorOut.uwTorquePu = stTORG4BB_stTorSensorOut.uwTorquePu;
+    torsensor_stTorSensorOut.uwTorqueLPFPu = stTORG4BB_stTorSensorOut.uwTorqueLPFPu;
+}
+/***************************************************************
+ Function: TORG4BB_Get_CAD_PORT;
+ Description: Get TORG4BB_Candance pulse timing
+ Call by:
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+uint32_t TORG4BB_Get_CAD_PORT(void)
+{
+    if((stTORG4BBInfo.ucForwardCnt > stTORG4BBInfo.ucForwardCntLast) || ((stTORG4BBInfo.ucForwardCnt == 1) && (stTORG4BBInfo.ucForwardCntLast == 127)))
+    {
+        return 0x0000;
+    }
+    else
+    {
+        return 0x0200;
+    }
+}
+/***************************************************************
+ Function: TORG4BB_Get_Temp;
+ Description: Get TORG4BB temp
+ Call by:
+ Input Variables: N/A
+ Output/Return Variables: N/A
+ Subroutine Call: N/A;
+ Reference: N/A
+****************************************************************/
+SWORD TORG4BB_Get_Temp(void)
+{
+    return stTORG4BBInfo.swTemp;
+}
+/************************ (C) END OF FILE *********************************/


+ 2 - 0
config_ps_policy.bat

@@ -0,0 +1,2 @@
+@echo off
+C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -Command Set-ExecutionPolicy Unrestricted

+ 37 - 0
gen_fingerprint.bat

@@ -0,0 +1,37 @@
+@echo off
+set dest=..\3.BasicFunction\Include
+set toolPath=%~dp0
+set destnation=%toolPath%%dest%
+
+echo %destnation%
+
+for /F %%t in ('git log -1 --pretty^=format:"%%h"') do (set sha=%%t)
+for /F %%t in ('git log -1 --pretty^=format:"%%ad" --date^=format:"%%Y_%%m%%d%%H:%%M:%%S"') do (set dt=%%t)
+for /F %%t in ('git log -1 --pretty^=format:"%%aN"') do (set commitAuthor=%%t)
+
+set clean="G"
+
+for /F %%t in ('git status -s') do (set clean="%%t")
+
+if %clean% == "G" (
+set fp=%sha%c
+) else (
+set fp=%sha%d
+)
+
+set commitTime=dt
+set compileTime=%date:~,10%
+set compileTime=%compileTime:/=%
+for /F %%t in ('git config user.name') do (set author="%%t")
+
+set fileName=%toolPath%fp.def
+
+echo #define FINGER_PRINT "%fp%" > %fileName%
+echo #define COMMIT_TIME "%dt%" >> %fileName%
+echo #define COMMIT_AUTHOR "%commitAuthor:\=/%" >> %fileName%
+echo #define COMPLIE_TIME "%compileTime%" >> %fileName%
+echo #define COMPLIE_AUTHOR %author:\=/% >> %fileName%
+
+copy "%fileName%" "%toolPath%%dest%"
+
+echo "Fingerprint Generated!"

+ 40 - 0
gen_fingerprint.ps1

@@ -0,0 +1,40 @@
+$destnation = "..\3.BasicFunction\Include"
+
+$toolPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
+
+$destnation = $toolPath + '\' + $destnation
+
+$res = &"git" log --pretty=format:"%h" | Select-Object -First 1
+$sha = $res
+$res = &"git" log --pretty=format:"%at" | Select-Object -First 1
+$dt = ([datetime]'1/1/1970Z').AddSeconds([int]$res)
+$res = &"git" log --pretty=format:"%aN" | Select-Object -First 1
+$commitAuthor = $res
+
+$notClean = &"git" status -s
+
+if ($notClean)
+{
+    $fp = $sha+"d";
+}
+else
+{
+    $fp = $sha+"c"
+}
+
+$commitTime = $dt.ToString("yyyyMMdd HH:mm:ss")
+$compleTime = Get-Date -Format "yyyyMMdd HH:mm:ss"
+$author = &"git" config user.name
+
+$fileName = $toolPath+"\fp.def"
+
+Out-File -FilePath $fileName -InputObject ('#define FINGER_PRINT "' + $fp + '"') -Encoding utf8;
+Out-File -FilePath $fileName -InputObject ('#define COMMIT_TIME "' + $commitTime + '"') -Encoding utf8 -Append;
+Out-File -FilePath $fileName -InputObject ('#define COMMIT_AUTHOR "' + $commitAuthor + '"') -Encoding utf8 -Append;
+out-File -FilePath $fileName -InputObject ('#define COMPLIE_TIME "' + $compleTime + '"') -Encoding utf8 -Append;
+out-File -FilePath $fileName -InputObject ('#define COMPLIE_AUTHOR "' + $author + '"') -Encoding utf8 -Append;
+
+Copy-Item $fileName $destnation
+
+echo "Fingerprint Generated!"
+