Эх сурвалжийг харах

[Improve][Modularization][Module_PowerSharing]

2022.04.13 / Folus Wen

Actions:
1. Available current distribution logic improve.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 2 жил өмнө
parent
commit
dec145a996

+ 23 - 20
EVSE/Modularization/Module_PowerSharing.c

@@ -151,18 +151,18 @@ void dM(uint8_t *data, uint16_t len, uint8_t isRX)
 
 	if(isRX)
 	{
-		DEBUG_INFO("- RX --------------------------------------------\n");
+		DEBUG_INFO_CLIENT("- RX --------------------------------------------\n");
 	}
 	else
 	{
-		DEBUG_INFO("- TX --------------------------------------------\n");
+		DEBUG_INFO_CLIENT("- TX --------------------------------------------\n");
 	}
 
 	memset(output, 0x00, ARRAY_SIZE(output));
 	for(uint16_t idx=0;idx<16;idx++)
 		sprintf((char*)output, "%s %02X", output, idx);
-	DEBUG_INFO("%s\n", output);
-	DEBUG_INFO("-------------------------------------------------\n");
+	DEBUG_INFO_CLIENT("%s\n", output);
+	DEBUG_INFO_CLIENT("-------------------------------------------------\n");
 
 	for(uint16_t idx = 0;idx<len;idx++)
 	{
@@ -178,8 +178,8 @@ void dM(uint8_t *data, uint16_t len, uint8_t isRX)
 			sprintf((char*)output, "%s %02X", output, data[idx]);
 		}
 	}
-	DEBUG_INFO("%s\n", output);
-	DEBUG_INFO("-------------------------------------------------\n");
+	DEBUG_INFO_CLIENT("%s\n", output);
+	DEBUG_INFO_CLIENT("-------------------------------------------------\n");
 #endif
 }
 
@@ -686,6 +686,7 @@ int conn_update_status(int socketFd, Connector_Info *connectorInfo, uint8_t conn
 				}
 
 				if((ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].isGunConnected != connectorInfo[gun_index].isGunConnected?YES:NO) ||
+				   (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent != connectorInfo[gun_index].availableSharingCurrent) ||
 				   (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].presentOutputCurrent != connectorInfo[gun_index].presentOutputCurrent))
 				{
 					DEBUG_INFO("Conn-%d gun_%d connected: %s\n", idx, gun_index, (connectorInfo[gun_index].isGunConnected?"Yes":"No"));
@@ -741,7 +742,7 @@ void create_cmd_getStatus(struct Message *out)
 	out->buffer[2] = SHARING_CMD_GET_STATUS;
 	out->buffer[out->size-1] = chksumCal(out);
 
-	dM(out->buffer, out->size, FALSE);
+	//dM(out->buffer, out->size, FALSE);
 }
 
 void create_cmd_SetAvailableCurrent(struct Message *out, int socketFd)
@@ -766,7 +767,7 @@ void create_cmd_SetAvailableCurrent(struct Message *out, int socketFd)
 		}
 	}
 	out->buffer[out->size-1] = chksumCal(out);
-	dM(out->buffer, out->size, FALSE);
+	//dM(out->buffer, out->size, FALSE);
 }
 
 int tcpSocketServer(void)
@@ -829,7 +830,7 @@ int tcpSocketServer(void)
 					{
 						if((input.size = recv(dupFd, input.buffer, sizeof(input.buffer), 0)) > 0)
 						{
-							dM(input.buffer, input.size, YES);
+							//dM(input.buffer, input.size, YES);
 
 							if(isValidCheckSum(&input))
 							{
@@ -934,7 +935,7 @@ int tcpSocketServer(void)
 			}
 		}
 
-		sleep(1);
+		usleep(500000);
 	}
 
 	return FAIL;
@@ -1202,7 +1203,7 @@ int tcpSocketClient(void)
 				cntSocketErr++;
 			}
 		}
-		sleep(1);
+		usleep(500000);
 	}
 	close(sockfd);
 
@@ -1216,6 +1217,11 @@ int balance_check_loop(void)
 {
 	for(;;)
 	{
+		// Get connection info
+		conn_getConectedQuantity();
+		conn_getOnHandCurrent();
+		conn_getConectedConnector();
+
 		// Check conn heart beat
 		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 		{
@@ -1256,7 +1262,6 @@ int balance_check_loop(void)
 				DEBUG_INFO("Detect gun connected re-allocate available current to each connection.\n");
 				ShmPowerSharing->isDetectNewConnected = NO;
 			}
-
 		}
 
 		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
@@ -1270,14 +1275,16 @@ int balance_check_loop(void)
 					{
 						if((ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent-ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].presentOutputCurrent) > 3)
 						{
-							if(ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent >= (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].connectorType==CONNECTOR_TYPE_AC?SHARE_MIN_AC+SHARE_GAP_AC:SHARE_MIN_DC+SHARE_GAP_DC))
-								ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent -= (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].connectorType==CONNECTOR_TYPE_AC?SHARE_GAP_AC:SHARE_GAP_DC);
+							if((ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent - ((ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent-ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].presentOutputCurrent)>>1)) >= (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].connectorType==CONNECTOR_TYPE_AC?SHARE_MIN_AC:SHARE_MIN_DC))
+								ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent -= (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent-ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].presentOutputCurrent)>>1;
+							else
+								ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent = (ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].connectorType==CONNECTOR_TYPE_AC?SHARE_MIN_AC:SHARE_MIN_DC);
 						}
 						else if((abs(ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].presentOutputCurrent-ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent) <= 1) &&
 								(ShmPowerSharing->onHandCurrent > 0))
 
 						{
-							ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent += ShmPowerSharing->onHandCurrent/ShmPowerSharing->connectedConnectorQty;
+							ShmPowerSharing->Connection_Info[idx].connectorInfo[gun_index].availableSharingCurrent += ShmPowerSharing->onHandCurrent/(ShmPowerSharing->connectedConnectorQty==0?1:ShmPowerSharing->connectedConnectorQty);
 						}
 						else
 						{}
@@ -1295,11 +1302,7 @@ int balance_check_loop(void)
 			}
 		}
 
-		conn_getConectedQuantity();
-		conn_getOnHandCurrent();
-		conn_getConectedConnector();
-
-		sleep(1);
+		usleep(100000);
 	}
 
 	return FAIL;

+ 1 - 25
EVSE/Modularization/Module_PowerSharing.h

@@ -66,36 +66,13 @@
 #define LISTEN_PORT_TCP					118
 #define	CONNECTION_LIMIT				5
 #define TIMEOUT_SPEC_HEARTBEAT			180
-#define INTERVAL_SPEC_CHECK_CAPACITY	5
+#define INTERVAL_SPEC_CHECK_CAPACITY	10
 #define INTERVAL_SPEC_POLLING_CMD		1
-#define SHARE_GAP_AC					2
 #define SHARE_MIN_AC					6
-#define SHARE_GAP_DC					10
 #define SHARE_MIN_DC					6
 
 #define ShmPowerShargingKey			LISTEN_PORT_TCP+8000
 
-
-enum ROTARY_SWITCH_LIMIT
-{
-	SWITCH_0_DEBUG=0,
-	SWITCH_1_12A,
-	SWITCH_2_16A,
-	SWITCH_3_20A,
-	SWITCH_4_24A,
-	SWITCH_5_28A,
-	SWITCH_6_32A,
-	SWITCH_7_36A,
-	SWITCH_8_40A,
-	SWITCH_9_48A,
-	SWITCH_A_56A,
-	SWITCH_B_64A,
-	SWITCH_C_72A,
-	SWITCH_D_80A,
-	SWITCH_E_RESERVE,
-	SWITCH_F_SLAVE
-};
-
 enum SHARING_COMMAND
 {
 	SHARING_CMD_GET_STATUS=0x01,
@@ -129,7 +106,6 @@ enum CONNECTOR_TYPE
 	CONNECTOR_TYPE_DC
 };
 
-
 struct Message
 {
 	int			size;