瀏覽代碼

修改了温度查表函数,未测试

CHENJIE-PC\QiXiang_CHENJIE 3 年之前
父節點
當前提交
6a753407ea
共有 5 個文件被更改,包括 76 次插入70 次删除
  1. 4 4
      inc/AppFunc.h
  2. 2 2
      inc/AppSignal.h
  3. 64 58
      src/AppFunc.c
  4. 2 2
      src/AppSignal.c
  5. 4 4
      src/AppTaskControl.c

+ 4 - 4
inc/AppFunc.h

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-12 15:03:02
+ * @LastEditTime : 2021-12-16 11:10:28
  * @Description  : file content
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppFunc.h
  */
@@ -48,13 +48,14 @@ static void setDefaultAppDataInfo(void);
 static void setDefaultBcuDataInfo(void);
 UINT16 encryptionAlgorithm(UINT16 plainText);
 UINT16 GetErrorNum(UINT16 *ErrorArray, UINT8 Errorlen);
+UINT16 LookRT_u32u16(UINT32 u0);
 UINT8 bcc_chk(UINT8 *data, UINT16 length);
-UINT8 LookUpRTtable(UINT32 R_value);
 UINT8 PutErrorNum(UINT16 *ErrorArray, UINT8 Errorlen, UINT16 ErrorNum);
 UINT8 UDSNegtiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 negCode);
 UINT8 UDSPositiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 posCode);
 void BattLockFunc(void);
 void BattWorkDelayFunc(UINT8 battWorkCurrentState);
+void BmsProtectStateDecode(UINT8 *DischargeProtect, UINT8 *ChargeProtect);
 void CANEncodeFunction(UINT32 ID, UINT8 *msgData);
 void CanMsgTx1000ms(void);
 void ErrorNumHandleFunc(void);
@@ -68,5 +69,4 @@ void relayControlFunc(UINT16 BuzzerPeriod, float DutyRatio);
 void SaveAppConfig(void);
 void SaveAppData(void);
 void SaveBcuData(void);
-void UDS_Service(CAN_Msg_Type *CanRxMsg);
-void BmsProtectStateDecode(UINT8 *DischargeProtect, UINT8 *ChargeProtect);
+void UDS_Service(CAN_Msg_Type *CanRxMsg);

+ 2 - 2
inc/AppSignal.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-14 11:23:33
+ * @LastEditTime : 2021-12-16 11:06:14
  * @Description  : Global variable definition H file
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
  */
@@ -105,4 +105,4 @@ extern AppSocketConnectionContext socContext; //网络连接状态
 extern osMutexId_t Error_Mutex;
 extern process_app gProcess_app;
 extern QueueHandle_t GpsRecvHandle;
-extern QueueHandle_t UartWriteCmdHandle;
+extern QueueHandle_t UartWriteCmdHandle;

+ 64 - 58
src/AppFunc.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-11-09 12:08:17
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-06 16:15:03
+ * @LastEditTime : 2021-12-16 11:13:32
  * @Description  : file content
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppFunc.c
  */
@@ -408,14 +408,14 @@ void BattWorkDelayFunc(UINT8 battWorkCurrentState)
 	return;
 }
 /**
- * @brief : R-T查表函数 (需优化)
+ * @brief : RT查表函数
  * @param {UINT32} R_value
  * @return {*}
  */
-UINT8 LookUpRTtable(UINT32 R_value)
+UINT16 LookRT_u32u16(UINT32 u0)
 {
-	UINT8 Temp_Table1[23] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22};
-	UINT8 Temp_Table2[217] = {23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+	const UINT8 table[240] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+							  24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
 							  49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
 							  84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
 							  115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
@@ -423,70 +423,76 @@ UINT8 LookUpRTtable(UINT32 R_value)
 							  169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
 							  196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
 							  223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239};
-	UINT32 R_Table1[23] = {202269, 191063, 180554, 170694, 161438, 152746, 144580, 136905, 129687, 122898, 116508,
-						   110493, 104827, 99488, 94455, 89710, 85233, 81008, 77019, 73252, 69693, 66329, 63148};
-	UINT16 R_Table2[217] = {
-		60140, 57293, 54599, 52049, 49633, 47343, 45174, 43117, 41166, 39315, 37558, 35891, 34307, 32802, 31373,
-		30014, 28722, 27493, 26324, 25211, 24152, 23144, 22183, 21268, 20395, 19564, 18771, 18015, 17293, 16604,
-		15947, 15319, 14720, 14147, 13600, 13077, 12577, 12098, 11641, 11203, 10784, 10383, 10000, 9632, 9280, 8942,
-		8619, 8309, 8012, 7727, 7454, 7191, 6940, 6698, 6466, 6244, 6030, 5825, 5627, 5438, 5255, 5080, 4911, 4749, 4593,
-		4443, 4299, 4160, 4026, 3898, 3773, 3654, 3539, 3428, 3321, 3218, 3119, 3023, 2931, 2841, 2755, 2672, 2592, 2515,
-		2441, 2369, 2299, 2232, 2167, 2104, 2044, 1985, 1928, 1874, 1821, 1769, 1720, 1672, 1626, 1581, 1537, 1495, 1455,
-		1415, 1377, 1340, 1305, 1270, 1236, 1204, 1172, 1142, 1112, 1083, 1056, 1029, 1002, 977, 952, 928, 905, 883, 861,
-		839, 819, 799, 779, 760, 742, 724, 707, 690, 674, 658, 642, 627, 613, 599, 585, 571, 558, 546, 533, 521, 509, 498, 487,
-		476, 466, 455, 445, 436, 426, 417, 408, 399, 391, 382, 374, 366, 359, 351, 344, 337, 330, 323, 316, 310, 304, 298, 292,
-		286, 280, 274, 269, 264, 259, 254, 249, 244, 239, 234, 230, 226, 221, 217, 213, 209, 205, 201, 198, 194, 190, 187, 183,
-		180, 177, 174, 171, 168, 165, 162, 159, 156, 153, 151, 148, 145, 143, 141, 138, 136, 133, 131, 129, 127, 125};
-	if (R_value > R_Table2[0])
-	{
-		if (R_value <= R_Table1[22]) //判断是否超出表尾
+	const UINT32 bp0[240] = {202269, 191063, 180554, 170694, 161438, 152746, 144580, 136905, 129687, 122898, 116508,
+							 110493, 104827, 99488, 94455, 89710, 85233, 81008, 77019, 73252, 69693, 66329, 63148, 60140,
+							 57293, 54599, 52049, 49633, 47343, 45174, 43117, 41166, 39315, 37558, 35891, 34307, 32802, 31373,
+							 30014, 28722, 27493, 26324, 25211, 24152, 23144, 22183, 21268, 20395, 19564, 18771, 18015, 17293, 16604,
+							 15947, 15319, 14720, 14147, 13600, 13077, 12577, 12098, 11641, 11203, 10784, 10383, 10000, 9632, 9280, 8942,
+							 8619, 8309, 8012, 7727, 7454, 7191, 6940, 6698, 6466, 6244, 6030, 5825, 5627, 5438, 5255, 5080, 4911, 4749, 4593,
+							 4443, 4299, 4160, 4026, 3898, 3773, 3654, 3539, 3428, 3321, 3218, 3119, 3023, 2931, 2841, 2755, 2672, 2592, 2515,
+							 2441, 2369, 2299, 2232, 2167, 2104, 2044, 1985, 1928, 1874, 1821, 1769, 1720, 1672, 1626, 1581, 1537, 1495, 1455,
+							 1415, 1377, 1340, 1305, 1270, 1236, 1204, 1172, 1142, 1112, 1083, 1056, 1029, 1002, 977, 952, 928, 905, 883, 861,
+							 839, 819, 799, 779, 760, 742, 724, 707, 690, 674, 658, 642, 627, 613, 599, 585, 571, 558, 546, 533, 521, 509, 498, 487,
+							 476, 466, 455, 445, 436, 426, 417, 408, 399, 391, 382, 374, 366, 359, 351, 344, 337, 330, 323, 316, 310, 304, 298, 292,
+							 286, 280, 274, 269, 264, 259, 254, 249, 244, 239, 234, 230, 226, 221, 217, 213, 209, 205, 201, 198, 194, 190, 187, 183,
+							 180, 177, 174, 171, 168, 165, 162, 159, 156, 153, 151, 148, 145, 143, 141, 138, 136, 133, 131, 129, 127, 125};
+	UINT16 MaxLen = 240;
+	UINT32 bpIdx = 0;
+	UINT32 iLeft = 0;
+	UINT32 iRght = 0;
+	UINT16 y = 0;
+	UINT32 yL_0d0 = 0;
+	UINT32 yR_0d0 = 0;
+	UINT32 maxIndex = MaxLen - 1;
+	if (u0 <= bp0[0U])
+	{
+		iLeft = 0U;
+		iRght = 0U;
+	}
+	else if (u0 < bp0[maxIndex])
+	{
+		//对折法寻找u0的位置
+		bpIdx = maxIndex >> 1U;
+		iLeft = 0U;
+		iRght = maxIndex;
+		while ((iRght - iLeft) > 1)
 		{
-			return Temp_Table1[22];
-		}
-		else if (R_value >= R_Table1[0]) //判断是否超出表头
-		{
-			return Temp_Table1[0];
-		}
-		else
-		{
-			for (int i = 0; i < 23 - 1; i++)
+			if (u0 < bp0[bpIdx])
 			{
-				if ((R_value <= R_Table1[i]) && (R_value > R_Table1[i + 1])) //中间判断
-				{
-					return Temp_Table1[i];
-				}
-				else
-				{
-					continue;
-				}
+				iRght = bpIdx;
 			}
+			else
+			{
+				iLeft = bpIdx;
+			}
+			bpIdx = (iRght + iLeft) >> 1U;
 		}
-	} // R-1
+	}
 	else
 	{
-		if (R_value <= R_Table2[216]) //判断是否超出表尾
-		{
-			return Temp_Table2[216];
-		}
-		else if (R_value >= R_Table2[0]) //判断是否超出表头
+		iLeft = maxIndex;
+		iRght = maxIndex;
+	}
+	//找到位置以后计算插值
+	if (iLeft != iRght)
+	{
+		//线性插值
+		yR_0d0 = table[iLeft + 1U];
+		yL_0d0 = table[iLeft];
+		if (yR_0d0 >= yL_0d0)
 		{
-			return Temp_Table2[0];
+			y = ((UINT16)((UINT32)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
 		}
 		else
 		{
-			for (int i = 0; i < 217 - 1; i++)
-			{
-				if ((R_value < R_Table2[i]) && (R_value >= R_Table2[i + 1])) //中间判断
-				{
-					return Temp_Table2[i + 1];
-				}
-				else
-				{
-					continue;
-				}
-			}
+			y = ((UINT16)(yL_0d0 - ((UINT32)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
 		}
-	} // R-2
+	}
+	else
+	{
+		y = (UINT16)table[iLeft];
+	}
+	return y;
 }
 /**
  * @brief : tcp校验函数

+ 2 - 2
src/AppSignal.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-14 11:23:07
+ * @LastEditTime : 2021-12-16 11:06:25
  * @Description  : Global variable definition c file,此文件存放App使用到的全局变量
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppSignal.c
  */
@@ -106,4 +106,4 @@ AppAlgorithmData BcuDataInfo;
 
 AppSocketConnectionContext socContext = {-1, 0}; //网络连接状态
 
-process_app gProcess_app; //全局工作状态
+process_app gProcess_app; //全局工作状态

+ 4 - 4
src/AppTaskControl.c

@@ -145,19 +145,19 @@ void GetAdcValue(UINT8 num)
     {
     case FAST_CHARGE_TEMP:
         NB_ADC_Get(&adcValue, FAST_CHARGE_TEMP);
-        fastChargeTemp = LookUpRTtable(adcValue);
+        fastChargeTemp = (UINT8)LookRT_u32u16(adcValue);
         break;
     case NORMAL_CHARGE_TEMP:
         NB_ADC_Get(&adcValue, NORMAL_CHARGE_TEMP);
-        normalChargeTemp = LookUpRTtable(adcValue);
+        normalChargeTemp = (UINT8)LookRT_u32u16(adcValue);
         break;
     case OTHER_TEMP_1:
         NB_ADC_Get(&adcValue, OTHER_TEMP_1);
-        heatTemp1 = LookUpRTtable(adcValue);
+        heatTemp1 = (UINT8)LookRT_u32u16(adcValue);
         break;
     case OTHER_TEMP_2:
         NB_ADC_Get(&adcValue, OTHER_TEMP_2);
-        heatTemp2 = LookUpRTtable(adcValue);
+        heatTemp2 = (UINT8)LookRT_u32u16(adcValue);
         break;
     case VBAT:
         NB_ADC_Get(&adcValue, VBAT);