浏览代码

[Bug fix][Modularization][Module_OcppBackend]

2020.11.12 / Folus Wen

Actions:
1. EVSE/Projects/define.h OCPP 2.0 share memory struct down size.
2. When connection establish callback set OCPP connected status to true.
3. EVSE/Modularization/ocppfiles/MessageHandler.c sendStatusNotificationRequest() fix CCS & GB reference wrong variable.
4. EVSE/Modularization/ocppfiles/MessageHandler.c LWS_Send() sent out condition change to reference backend server connected status.

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 4 年之前
父节点
当前提交
6f4f70e003

文件差异内容过多而无法显示
+ 662 - 102
EVSE/Modularization/ocpp20/MessageHandler.c


+ 12 - 227
EVSE/Modularization/ocpp20/Module_OcppBackend20.c

@@ -20,7 +20,7 @@ struct StartTime
 //==========================================
 void ReceivedMessage(void *in, size_t len);
 int SendBufLen=0;//(1024*4);//(1024*3);
-unsigned char SendBuffer[1024*4]={0};
+unsigned char SendBuffer[1024*20]={0};
 static int ConnectionEstablished=0;
 static int TransactionMessageResend = 1;  // the number of retry to submit a transaction-related message when the Central System fails to process it.
 static int TransactionQueueNum = 0;
@@ -54,7 +54,7 @@ int SendData(struct lws *wsi)
 {
     int n;
     int len;
-    unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + 4096 + LWS_SEND_BUFFER_POST_PADDING] = {0};
+    unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + (1024*20) + LWS_SEND_BUFFER_POST_PADDING] = {0};
 
     // Only disable isWebsocketSendable operation initiated by charger
     if((strstr((char*)SendBuffer, "\"Authorize\"") != NULL)
@@ -86,7 +86,7 @@ int SendData(struct lws *wsi)
     return n;
 }
 
-static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
+static int OCPP20Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
 {
 	char 	buf[256]={0}, hash[20]={0}, key_b64[40]={0}, tempin[65536]={0}, sstr[65536]={0};
 	uint8_t auth_b64[256]={0}, boxId[128]={0}, password[64]={0};
@@ -335,13 +335,13 @@ static struct lws_protocols protocols[] =
 {
 	{
 		"ocpp2.0",
-		OCPP16Callback,
+		OCPP20Callback,
 		65536,//65536,//10240,
 		65536,//65536,//10240,
 	},
 	{
 		"ocpp2.0",
-		OCPP16Callback,
+		OCPP20Callback,
 		65536,//65536,//10240,
 		65536,//65536,//10240,
 	},
@@ -808,27 +808,10 @@ int showqueue()
 int sentqueue(){
 	FILE *fp;
 	int result = FALSE; // 1: TRUE  0:FALSE
-	int temptransactionId = 0, gettransactionId = 0;
-	int tempconnectorId = 0;
-	//int gunIndex = 0;
-	char guid[37]={0};
-	char tempdata[65]={0};
-	char key_value[65]={0};
-	int IsStopTransaction = FALSE;
-	//int IsconnectorIdNULL = FALSE;
-	//int IsIdtagNULL = FALSE;
 	char str[QUEUE_MESSAGE_LENGTH]={0};
-	char strcomposite[QUEUE_MESSAGE_LENGTH]={0};
 	char rmFileCmd[100]={0};
-	char connectorStr[2]={0};
 	struct stat stats;
-	char sstr[28]={0};
-	unsigned char IdtagStr[20]={0};
-	unsigned char timestampStr[30]={0};
-	int tempmeterStart = 0;
-	int tempreservationId = 0;
-	int c = 0;
-	char *loc;
+	json_object *queueJson;
 
 	DEBUG_INFO("Sent queue.\n");
 
@@ -855,213 +838,15 @@ int sentqueue(){
 		return FALSE;
 	}
 
-	if( fgets (str, QUEUE_MESSAGE_LENGTH, fp)!=NULL ) {
-
-		//---- writing content to stdout ---//
-
-		//*********************Start: StopTransaction***************************/
-		loc = strstr(str, "StopTransaction");
-		c = 0;
-		memset(sstr ,0, ARRAY_SIZE(sstr) );
-		if(loc != NULL)
-		{
-			IsStopTransaction = TRUE;
-		}
+	if( fgets (str, QUEUE_MESSAGE_LENGTH, fp)!=NULL )
+	{
+		queueJson = json_tokener_parse(str+2);
 
-		memset(connectorStr,0,ARRAY_SIZE(connectorStr));
-		strncpy(connectorStr, str, 1);
-		tempconnectorId = atoi(connectorStr);
-		//*********************End: StopTransaction***************************/
-
-	#if 0
-		//*********************Start:connectorId***************************/
-		loc = strstr(str, "connectorId");
-		c = 0;
-		memset(sstr ,0, ARRAY_SIZE(sstr) );
-		if(loc != NULL)
+		if(!is_error(queueJson))
 		{
-			while (loc[strlen("connectorId")+2+c] != ',')
-			{
-				sstr[c] = loc[strlen("connectorId")+2+c];
-				c++;
-			}
-			sstr[c] = '\0';
-			tempconnectorId = atoi(sstr);
-		}
-	//	else
-	//	{
-	//		IsconnectorIdNULL = TRUE;
-	//	}
-		//*********************End:connectorId***************************/
-	#endif
-
-		//*********************Start:idTag***************************/
-		loc = strstr(str, "idTag");
-		c = 0;
-		memset(sstr ,0, ARRAY_SIZE(sstr) );
-		if(loc != NULL)
-		{
-			while (loc[3+strlen("idTag")+c] != '\"')
-			{
-				sstr[c] = loc[3+strlen("idTag")+c];
-				c++;
-			}
-			sstr[c] = '\0';
-			strcpy((char*)IdtagStr, sstr);
-		}
-	//	else
-	//	{
-	//		IsIdtagNULL = TRUE;
-	//	}
-		//*********************End:idTag***************************/
-
-
-		//*********************Start: StartTransaction***************************/
-		loc = strstr(str, "StartTransaction");
-		c = 0;
-		memset(sstr ,0, ARRAY_SIZE(sstr) );
-		if(loc != NULL)
-		{
-			// [2,0200000000000000000000000001584415776,StartTransaction,{connectorId:1,idTag:123,meterStart:100,reservationId:0,timestamp:2020-03-17T03:29:36Z}]
-			//DEBUG_INFO("\n sent queue StartTransaction\n");
-			if(tempconnectorId > 0)
-			{
-				sprintf(tempdata, "StartTransaction,%d", (tempconnectorId-1));
-			}
-
-			//GUID
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			c=0;
-			while (str[6+c] != '\"')
-			{
-				sstr[c] = str[6+c];
-				c++;
-			}
-			sstr[c] = '\0';
-			strcpy(guid, sstr);
-
-
-			//Idtag
-			loc = strstr(str, "idTag");
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			c=0;
-			while (loc[3+strlen("idTag")+c] != '\"')
-			{
-				sstr[c] = loc[3+strlen("idTag")+c];
-				c++;
-			}
-			sstr[c] = '\0';
-			strcpy((char*)IdtagStr, sstr);
-
-			//meterStart
-			loc = strstr(str, "meterStart");
-			c = 0;
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			if(loc != NULL)
-			{
-				while (loc[strlen("meterStart")+2+c] != ',')
-				{
-					sstr[c] = loc[strlen("meterStart")+2+c];
-					c++;
-				}
-				sstr[c] = '\0';
-				tempmeterStart = atoi(sstr);
-
-			}
-
-			//reservationId
-			loc = strstr(str, "reservationId");
-			c = 0;
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			if(loc != NULL)
-			{
-				while (loc[strlen("reservationId")+2+c] != ',')
-				{
-					sstr[c] = loc[strlen("reservationId")+2+c];
-					c++;
-				}
-				sstr[c] = '\0';
-				tempreservationId = atoi(sstr);
-
-			}
-
-			//timestamp
-			loc = strstr(str, "timestamp");
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			c=0;
-			while (loc[3+strlen("timestamp")+c] != '\"')
-			{
-				sstr[c] = loc[3+strlen("timestamp")+c];
-				c++;
-			}
-			sstr[c] = '\0';
-			strcpy((char*)timestampStr, sstr);
-
-
-			if(hashmap_operation(HASH_OP_GET, guid, key_value) == TRUE)
-			{
-				//DEBUG_INFO("\n 1. sent queue guid=%s\n",guid);
-			}
-			else
-			{
-				hashmap_operation(HASH_OP_ADD, guid, tempdata);
-				FillStartTransaction(tempconnectorId, IdtagStr, tempmeterStart, tempreservationId, timestampStr);
-				//DEBUG_INFO("\n 2. sent queue guid=%s\n",guid);
-			}
+			LWS_Send(str+2);
 		}
-		//*********************End: StartTransaction***************************/
-
-
-		//****************transactionId********************/
-		 c=0;
-		 loc = strstr(str, "transactionId");
-		 memset(sstr ,0, ARRAY_SIZE(sstr) );
-		 if(loc != NULL)
-		 {
-
-			 while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
-			 {
-				sstr[c] = loc[strlen("transactionId")+2+c];
-				c++;
-			 }
-
-			sstr[c] = '\0';
-			temptransactionId = atoi(sstr);
-
-			//gettransactionId = GetTransactionId(tempconnectorId, IdtagStr);
-
-			//From StartTransaction取得IdTag, 存到 StartTransactionIdTagTemp,主要是 給Queue中StopTransaction使用(StartTransaction. StopTransaction不同卡號 ),取得真正的TransactionId
-			GetStartTransactionIdTag(tempconnectorId-1);
-			gettransactionId = GetTransactionId(tempconnectorId, (uint8_t *)StartTransactionIdTagTemp, IsStopTransaction);
-
-			DEBUG_INFO("queue map transactionId   = %d\n",gettransactionId);
-			DEBUG_INFO("original  connectorId     = %d\n", tempconnectorId);
-			DEBUG_INFO("original  transactionId   = %d\n",temptransactionId);
-			DEBUG_INFO("StartTransactionIdTagTemp = %s\n", StartTransactionIdTagTemp);
-			if((gettransactionId != 0)&&(temptransactionId != gettransactionId))
-			{
-				//replace transactionId of metervalue or stopTransaction
-				strncpy(strcomposite,str, (loc-str)+2+strlen("transactionId"));
-				sprintf(strcomposite+((loc-str)+2+strlen("transactionId")),"%d",gettransactionId);
-				strcat(strcomposite, loc+strlen("transactionId")+2+c); // 把 字串中transactionId後面的字串串接到 strcomposite後面
-				LWS_Send(strcomposite+2); // skip 2 bytes String -> Connector ID,
-			}
-			else
-			{
-				LWS_Send(str+2);  // skip 2 bytes String -> Connector ID
-				gettransactionId = temptransactionId;
-			}
-
-			DEBUG_INFO("Final transactionId       = %d\n", gettransactionId);
-			if(IsStopTransaction == TRUE)//if((IsStopTransaction == TRUE)&&(gettransactionId != 0))
-			{
-				SetTransactionIdZero(gettransactionId);
-			}
-		 }
-		 else
-		 {
-			 LWS_Send(str+2);
-		 }
+		json_object_put(queueJson);
 
 		result = TRUE;
 	}

+ 12 - 6
EVSE/Modularization/ocpp20/Module_OcppBackend20.h

@@ -50,10 +50,16 @@
 #define is_error(ptr) 				((unsigned long)ptr > (unsigned long)-4000L)
 #define PASS						1
 #define FAIL						-1
-#define YES							1
-#define NO							0
-#define ON							1
-#define OFF							0
+
+typedef enum {
+	NO=0,
+	YES
+}Logic_Value;
+
+typedef enum {
+	OFF=0,
+	ON
+}Switch_Value;
 
 #ifndef SPEC_LATEST_SUPPORTED
 	#define SPEC_LATEST_SUPPORTED 	13
@@ -76,7 +82,7 @@
 #define QUEUE_OPERATION_SENT		3
 #define QUEUE_OPERATION_ADD			4
 #define QUEUE_OPERATION_STORE		5
-#define QUEUE_MESSAGE_LENGTH		3584
+#define QUEUE_MESSAGE_LENGTH		1024*20
 
 struct yuarel {
 	char *scheme; /* scheme, without ":" and "//" */
@@ -136,7 +142,7 @@ extern char * strtrim( char * s );
 
 extern struct lws 					*wsi_client;
 extern struct lws_context 			*context;
-extern unsigned char 				SendBuffer[4096];
+extern unsigned char 				SendBuffer[1024*20];
 extern int 							SendBufLen;
 extern char 						OcppPath[160];
 extern char 						OcppProtocol[10];

+ 10 - 29
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -3510,7 +3510,6 @@ S_FAULT                 =12
 			{
 				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
 				{
-
 					if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
 					{
 						currentStatus = 1; //OCPP Status: Preparing
@@ -3519,14 +3518,10 @@ S_FAULT                 =12
 					{
 						currentStatus = 0; //OCPP Status: Available
 					}
-
-
-
 				}
 				else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
-				                         ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
-								) //S_PRECHARGE
-
+				          ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
+						) //S_PRECHARGE
 				{
 					currentStatus = 1; //OCPP Status: Preparing
 				}
@@ -3554,9 +3549,7 @@ S_FAULT                 =12
 				{
 					currentStatus = 6; //OCPP Status: Reserved
 				}
-
 			} //end of the same index
-
 		}//end of for CHAdeMO_QUANTITY
 
 	}
@@ -3586,13 +3579,10 @@ S_FAULT                 =12
 					{
 						currentStatus = 0; //OCPP Status: Available
 					}
-
-
 				}
-				else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
-				                         ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
-								) //S_PRECHARGE
-
+				else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
+				          ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
+						) //S_PRECHARGE
 				{
 					currentStatus = 1; //OCPP Status: Preparing
 				}
@@ -3620,9 +3610,7 @@ S_FAULT                 =12
 				{
 					currentStatus = 6; //OCPP Status: Reserved
 				}
-
 			} //end of the same index
-
 		} // end of for CCS_QUANTITY
 	}
 	else if(gunType[gun_index] == 'G')
@@ -3651,12 +3639,10 @@ S_FAULT                 =12
 					{
 						currentStatus = 0; //OCPP Status: Available
 					}
-
 				}
-				else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
-				                         ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
-								) //S_PRECHARGE
-
+				else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
+				          ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
+						) //S_PRECHARGE
 				{
 					currentStatus = 1; //OCPP Status: Preparing
 				}
@@ -3685,7 +3671,6 @@ S_FAULT                 =12
 					currentStatus = 6; //OCPP Status: Reserved
 				}
 			} //end of the same index
-
 		} // end of for GB_QUANTITY
 	}
 	else if(gunType[gun_index] == 'O')
@@ -3707,7 +3692,6 @@ S_FAULT                 =12
 					{
 						currentStatus = 0; //OCPP Status: Available
 					}
-
 				}
 				else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
 						  ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
@@ -3768,7 +3752,6 @@ S_FAULT                 =12
 					{
 						currentStatus = 0; //OCPP Status: Available
 					}
-
 				}
 				else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
 				{
@@ -3798,11 +3781,9 @@ S_FAULT                 =12
 				{
 					currentStatus = 6; //OCPP Status: Reserved
 				}
-
 			}//end of the same index
 
 		}//end of for AC_QUANTITY
-
 	}
 
 	//it's option
@@ -16471,7 +16452,7 @@ void LWS_Send(char * str)
 	//=====================================================
 	// Check InternetConn 0: disconnected, 1: connected
 	//====================================================
-	if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
+	if(GetOcppConnStatus() == 0)
 	{
 		DEBUG_INFO("offline  now !!!\n");
 		return;
@@ -16493,7 +16474,7 @@ void LWS_SendNow(char * str)
 	//=====================================================
 	// Check InternetConn 0: disconnected, 1: connected
 	//====================================================
-	if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
+	if(GetOcppConnStatus() == 0)
 	{
 		DEBUG_INFO("offline  now !!!\n");
 		return;

+ 1 - 0
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -253,6 +253,7 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 
 			//connected
 			ConnectionEstablished=1;
+			SetOcppConnStatus(TRUE);
 
 			queueNotEmpty = queue_operation(QUEUE_OPERATION_SHOWFRONT,frontUUID, frontData);
 

+ 2 - 2
EVSE/Projects/define.h

@@ -4999,7 +4999,7 @@ struct LogStatusNotification_20
 struct MeterValues_20
 {
 	unsigned int evseId;											// Required. This contains a number (>0) designating an EVSE of the Charging Station. ????(zero) is used to designate the main power meter.
-	struct MeterValueType meterValue[10];							// Required. The sampled meter values with timestamps.
+	struct MeterValueType meterValue[1];							// Required. The sampled meter values with timestamps.
 };
 
 struct NotifyChargingLimit_20
@@ -5234,7 +5234,7 @@ struct TransactionEvent_20
 	struct TransactionType transactionInfo;							// Required. Contains transaction specific information.
 	struct IdTokenType idToken;										// Optional. This contains the identifier for which a transaction has to be/was started.
 	struct EVSEType evse;											// Optional. This identifies which evse (and connector) of the Charging Station is used.
-	struct MeterValueType meterValue[10];							// Optional. This contains the relevant meter values.
+	struct MeterValueType meterValue[1];							// Optional. This contains the relevant meter values.
 	float Response_totalCost;										// Optional. SHALL only be sent when charging has ended. Final total cost of this transaction, including taxes.
 	int Response_chargingPriority;									// Optional. Priority from a business point of view. Default priority is 0,
 	struct IdTokenInfoType Response_idTokenInfo;					// Optional. This contains information about authorization status, expiry and group id. Is required when the transactionEventRequest contained an idToken.

部分文件因为文件数量过多而无法显示