Bläddra i källkod

2022-06-27 / Alston Lin
Actions
1. Fix the problem of counting the number of modules

Files
1. As follow commit history

root 2 år sedan
förälder
incheckning
839bd46f24
1 ändrade filer med 34 tillägg och 79 borttagningar
  1. 34 79
      EVSE/Modularization/Infypwr_PsuCommObj.c

+ 34 - 79
EVSE/Modularization/Infypwr_PsuCommObj.c

@@ -253,17 +253,8 @@ void ReceiveDataFromCanBus()
 	PwrFrame *PwrFrameMsg;
 	byte group, address;
 	byte _totalModuleCount = 0;
-	bool colFinished = false;
-
-	for (byte i = 0; i < 2; i++)
-	{
-		infy_pow_info[i].psuCount = 0;
-		for (byte j = 0; j < 12; j++)
-		{
-			infy_pow_info[i].serialNumber[j] = 0xFF;
-			infy_pow_info[i].targetNumber[j] = 0xFF;
-		}
-	}
+	byte _totalModuleCountBuf = 0;
+	byte checkTotalCount = 0;
 
 	while(1)
 	{
@@ -300,35 +291,6 @@ void ReceiveDataFromCanBus()
                     {
                         group = frame.data[2];
                         byte SN = address;
-                        bool isfind = false;
-
-                        if (group < 4 && !colFinished)
-                        {
-                            for(byte _index = 0; _index < infy_pow_info[group].psuCount; _index++)
-                            {
-                                if (infy_pow_info[group].serialNumber[_index] == SN)
-                                {
-                                    isfind = true;
-                                    break;
-                                }
-                            }
-
-                            if (!isfind)
-                            {
-                                infy_pow_info[group].serialNumber[infy_pow_info[group].psuCount] = SN;
-                                infy_pow_info[group].targetNumber[infy_pow_info[group].psuCount] = infy_pow_info[group].psuCount;
-                                infy_pow_info[group].psuCount++;
-                            }
-
-                            byte subPcount = 0;
-                            for (byte i = 0; i < 4; i++)
-                            {
-                                subPcount += infy_pow_info[i].psuCount;
-                            }
-
-                            if (subPcount > 0 && subPcount == _totalModuleCount)
-                                colFinished = true;
-                        }
 
                         short temp = frame.data[4];
                         int status = (frame.data[5] << 16) + (frame.data[6] << 8) + frame.data[7];
@@ -339,24 +301,38 @@ void ReceiveDataFromCanBus()
 
                     case PSU_RCmd_SysModuleCount:
                     {
-                        // 回傳模組數量
-                        group = address;
-
-                        byte count = frame.data[2];
-                        if (group == SYSTEM_CMD)
-                        {
-                            _totalModuleCount = count;
-                        }
-
-                        return_module_count(group, count);
+						// 回傳模組數量
+						group = address;
+
+						byte count = frame.data[2];
+						if (group == SYSTEM_CMD && _totalModuleCount == 0 && count != 0)
+						{
+							if (_totalModuleCountBuf != count)
+							{
+								checkTotalCount = 0;
+								_totalModuleCountBuf = count;
+							}
+							else
+							{
+								if (checkTotalCount >= 10)
+								{
+									printf("***** Total Count = %d ***** \n", count);
+									_totalModuleCount = count;
+								}
+								else
+									checkTotalCount++;
+							}
+						}
+
+						if (group == SYSTEM_CMD)
+							return_module_count(group, _totalModuleCount);
+						else
+							return_module_count(group, count);
                     }
                         break;
 
                     case PSU_RCmd_ModuleCapability:
                     {
-                        if (!colFinished)
-                            break;
-
                         // 回傳輸出能力 : 最大電壓,最小電壓,最大電流,額定功率
                         short maxVol = ((frame.data[0] << 8) + frame.data[1]) * 10;
                         short minVol = ((frame.data[2] << 8) + frame.data[3]) * 10;
@@ -366,8 +342,11 @@ void ReceiveDataFromCanBus()
                         if (maxCur > MODULE_MAX_VOL)
                         	maxCur = MODULE_MAX_VOL;
                         return_available_cap(address, maxVol, minVol, maxCur, totalPow);
-    //					PRINTF_LIB_FUNC("address = %d, maxVol = %d, minVol = %d, maxCur = %d, totalPow = %d \n",
-    //							address, maxVol, minVol, maxCur, totalPow);
+
+                        if (_totalModuleCount != 0)
+                        	_totalModuleCount = 0;
+//    					printf("address = %d, maxVol = %d, minVol = %d, maxCur = %d, totalPow = %d \n",
+//    							address, maxVol, minVol, maxCur, totalPow);
                     }
                         break;
 
@@ -397,9 +376,6 @@ void ReceiveDataFromCanBus()
                         break;
                     case PSU_RCmd_ModuleIAvailable:
                     {
-                        if (!colFinished)
-                            break;
-
                         // 回傳降載後的電流
                         address = frame.can_id & 0x000000FF;
 
@@ -413,9 +389,6 @@ void ReceiveDataFromCanBus()
 
                     case PSU_RCmd_ModuleMiscInfo:
                     {
-                        if (!colFinished)
-                            break;
-
                         address = frame.can_id & 0x000000FF;
                         float ReturnValue;
                         byte value[4];
@@ -443,9 +416,6 @@ void ReceiveDataFromCanBus()
 
                     case PSU_RCmd_ModuleVersion:
                     {
-                        if (!colFinished)
-                            break;
-
                         // 回傳版號 : 無系統回覆功能
                         address = frame.can_id & 0x000000FF;
 
@@ -466,9 +436,6 @@ void ReceiveDataFromCanBus()
 
                     case PSU_RCmd_ModuleInputVoltage:
                     {
-                        if (!colFinished)
-                            break;
-
                         // 回傳三向輸入電壓
                         address = frame.can_id & 0x000000FF;
 
@@ -482,9 +449,6 @@ void ReceiveDataFromCanBus()
                         break;
                     case PSU_RCmd_ModuleOutputVolCur_F:
                     {
-                    	if (!colFinished)
-							break;
-
 						byte vol[4], cur[4];
 
 						memcpy(vol, frame.data, 4);
@@ -506,9 +470,6 @@ void ReceiveDataFromCanBus()
                 {
                     case Nexton_PSU_DcOutputValue:
                     {
-                        if (!colFinished)
-                            break;
-
                         /*Test mode used*/
                         // 回傳輸出值與入風口溫度
                         address = frame.can_id & 0x000000FF;
@@ -524,9 +485,6 @@ void ReceiveDataFromCanBus()
                         break;
                     case Nexton_PSU_StatusEvent:
                     {
-                        if (!colFinished)
-                            break;
-
                         /*Test mode used*/
                         // 回傳輸出值與入風口溫度
                         address = frame.can_id & 0x000000FF;
@@ -544,9 +502,6 @@ void ReceiveDataFromCanBus()
                         break;
                     case Nexton_PSU_AcInputValue:
                     {
-                        if (!colFinished)
-                            break;
-
                         /*Test mode used*/
                         // 回傳輸出值與入風口溫度
                         address = frame.can_id & 0x000000FF;