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

[Improve][Modularization][Module_OcppBackend / Module_OcppBackendPHl]

2022.01.28 / Folus Wen

Actions:
1. TCCI data transfer message fix.

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 3 жил өмнө
parent
commit
f5b9d55fc9

+ 122 - 330
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -125,7 +125,7 @@ struct ClientTime
 	struct timespec StopTransaction;
 	struct timespec MeterValues[CONNECTOR_QUANTITY];
 	struct timespec RemoteStartWait;
-	struct timespec YesCustomCallReader;
+	struct timespec TcciQueryDeduct;
 }clientTime;
 
 typedef union
@@ -1301,6 +1301,84 @@ int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
 	return isSuccess;
 }
 
+int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[8192];
+
+	sprintf(sqlStr, "insert into report_deduct_info(transactionId, creditNo, deductResult, isDonateInvoice, isUploaded) values('%d', '%s', '%d', '%d', '0');", txId, creditNo, deductResult, isDonateInvoice);
+
+	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		result = FAIL;
+		DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
+	}
+
+	sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
+	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		result = FAIL;
+		DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
+	}
+
+	return result;
+}
+
+int OCPP_update_deduct_info(int txId, char *creditNo)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[8192];
+
+	sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
+
+	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		result = FAIL;
+		DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
+	}
+
+	return result;
+}
+
+int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
+{
+	json_object *deductData = json_object_new_object();
+
+	json_object_object_add(deductData, "txId", json_object_new_int(atoi(columnValue[1])));
+	json_object_object_add(deductData, "creditNo", json_object_new_string(columnValue[2]));
+	json_object_object_add(deductData, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
+	json_object_object_add(deductData, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
+
+	sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
+	sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"ID_CreditDeductResult");
+	sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(deductData, JSON_C_TO_STRING_PLAIN));
+	json_object_put(deductData);
+
+	ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
+
+	return 0;
+}
+
+void OCPP_query_deduct_info()
+{
+    int rc = 0;
+
+    char sql[100];
+    char zErrMsg[100];
+
+    sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
+
+    /* Execute SQL statement */
+    rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
+
+    if( rc != SQLITE_OK )
+    {
+    	DEBUG_INFO("SQL error: %s\n", zErrMsg);
+    }
+}
+
 //==========================================
 // Check time passed since today
 //==========================================
@@ -4420,23 +4498,26 @@ void CheckSystemValue(void)
 	{
 		//parameter for test
 		sendHeartbeatRequest(0);
-	    //==============================================
+	    //===========================
 		// Reset Waiting Time
-		//==============================================
+		//===========================
 		HeartBeatWithNOResponse += 1;
 	}
 
 	//===============================
-	// send YES CallReader
+	// Credit deduct report
 	//===============================
-	if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->YesCustomData.CallReaderReq == 1) && (getDiffSecNow(clientTime.YesCustomCallReader) >= 5))
+	if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
+	{
+		OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice);
+
+		ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
+	}
+
+	if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
 	{
-		sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
-		sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"call_reader");
-		sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data," ");
-		ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
-		//ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
-		refreshStartTimer(&clientTime.YesCustomCallReader);
+		OCPP_query_deduct_info();
+		refreshStartTimer(&clientTime.TcciQueryDeduct);
 	}
 
 	for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
@@ -10828,255 +10909,6 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
 			json_object_put(response);
 		}
-		else if(strstr(tempmessageId, "refund_status") != NULL)
-		{
-			json_object *data;
-			data = json_tokener_parse(tempdata);
-			if(!is_error(data))
-			{
-				json_object_object_add(response, "status", json_object_new_string("Accepted"));
-
-				if(json_object_object_get(data, "status") != NULL)
-				{
-					//DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
-					if(strcmp(json_object_get_string(json_object_object_get(data, "status")), "T") || strcmp(json_object_get_string(json_object_object_get(data, "status")), "F"))
-					{
-						sprintf((char *)ShmOCPP16Data->YesCustomData.RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
-					}
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("status data can not get."));
-				}
-
-				if(json_object_object_get(data, "chargeDate") != NULL)
-				{
-					sprintf((char *)ShmOCPP16Data->YesCustomData.RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
-				}
-
-				if(json_object_object_get(data, "holdAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "chargeAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "refundAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "page") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
-						ShmOCPP16Data->YesCustomData.RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("page data can not get."));
-				}
-
-				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
-				{
-					ShmOCPP16Data->YesCustomData.RefundStatusReq = 1;
-					DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
-							ShmOCPP16Data->YesCustomData.RefundStatus.status,
-							ShmOCPP16Data->YesCustomData.RefundStatus.chargeDate,
-							ShmOCPP16Data->YesCustomData.RefundStatus.holdAmt,
-							ShmOCPP16Data->YesCustomData.RefundStatus.chargeAmt,
-							ShmOCPP16Data->YesCustomData.RefundStatus.refundAmt,
-							ShmOCPP16Data->YesCustomData.RefundStatus.page);
-				}
-			}
-			else
-			{
-				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
-			}
-			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
-			json_object_put(response);
-		}
-		else if(strstr(tempmessageId, "deduct_status") != NULL)
-		{
-			json_object *data;
-			data = json_tokener_parse(tempdata);
-			if(!is_error(data))
-			{
-				json_object_object_add(response, "status", json_object_new_string("Accepted"));
-
-				if(json_object_object_get(data, "status") != NULL)
-				{
-					//DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
-					if((strcmp(json_object_get_string(json_object_object_get(data, "status")), "T")==0) || (strcmp(json_object_get_string(json_object_object_get(data, "status")), "F")==0))
-					{
-						sprintf((char*)ShmOCPP16Data->YesCustomData.DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
-					}
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("status data can not get."));
-				}
-
-				if(json_object_object_get(data, "autoLoadAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "beforeAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "chargeAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "afterAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
-						ShmOCPP16Data->YesCustomData.DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "page") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
-						ShmOCPP16Data->YesCustomData.DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("page data can not get."));
-				}
-
-				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
-				{
-					ShmOCPP16Data->YesCustomData.DeductStatusReq = 1;
-					DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
-									ShmOCPP16Data->YesCustomData.DeductStatus.status,
-									ShmOCPP16Data->YesCustomData.DeductStatus.autoLoadAmt,
-									ShmOCPP16Data->YesCustomData.DeductStatus.beforeAmt,
-									ShmOCPP16Data->YesCustomData.DeductStatus.chargeAmt,
-									ShmOCPP16Data->YesCustomData.DeductStatus.afterAmt,
-									ShmOCPP16Data->YesCustomData.DeductStatus.page);
-				}
-			}
-			else
-			{
-				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
-			}
-
-			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
-			json_object_put(response);
-		}
 		else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
 		{
 			json_object *data;
@@ -11087,7 +10919,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(json_object_object_get(data, "stationName") != NULL)
 				{
-					sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
+					sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
 				}
 				else
 				{
@@ -11095,34 +10927,11 @@ int handleDataTransferRequest(char *uuid, char *payload)
 					json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
 				}
 
-				/*if(json_object_object_get(data, "station_id") != NULL)
-				{
-					sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
-				}
-
-				if(json_object_object_get(data, "charge_id") != NULL)
-				{
-					for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
-					{
-						sprintf((char*)ShmOCPP16Data->YesCustomData.ChargerInfo.charge_id[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(data, "charge_id"), idx)));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
-				}*/
-
 				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
 				{
-					ShmOCPP16Data->YesCustomData.ChargerInfoReq = 1;
+					ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
 					DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
-									ShmOCPP16Data->YesCustomData.ChargerInfo.station_name);
+									ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
 				}
 			}
 			else
@@ -11144,7 +10953,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(json_object_object_get(data, "weatherId") != NULL)
 				{
-					ShmOCPP16Data->YesCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
+					ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
 				}
 				else
 				{
@@ -11154,7 +10963,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(json_object_object_get(data, "Temperature") != NULL)
 				{
-					ShmOCPP16Data->YesCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
+					ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
 				}
 				else
 				{
@@ -11164,10 +10973,10 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
 				{
-					ShmOCPP16Data->YesCustomData.WeatherInfoReq = 1;
+					ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
 					DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
-									ShmOCPP16Data->YesCustomData.WeatherInfo.weatherId,
-									ShmOCPP16Data->YesCustomData.WeatherInfo.temperature
+									ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
+									ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
 									);
 				}
 			}
@@ -11180,7 +10989,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
 			json_object_put(response);
 		}
-		else if(strstr(tempmessageId, "set_qrcode") != NULL)
+		else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
 		{
 			json_object *data;
 			data = json_tokener_parse(tempdata);
@@ -11188,42 +10997,21 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			{
 				json_object_object_add(response, "status", json_object_new_string("Accepted"));
 
-				if(json_object_object_get(data, "connectorId") != NULL)
+				if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
 				{
-					if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
-					{
-						int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
-						if(json_object_object_get(data, "qrcode") != NULL)
-						{
-							sprintf((char *)ShmOCPP16Data->YesCustomData.QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
-							ShmOCPP16Data->YesCustomData.SetQrCodeReq = 1;
-							DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
-											idx,
-											ShmOCPP16Data->YesCustomData.QrCode[idx]
-											);
-						}
-						else
-						{
-							json_object_object_add(response, "status", json_object_new_string("Rejected"));
-							json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
-						}
-					}
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
-					}
+					ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
+					DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
 				}
 				else
 				{
 					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
+					json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
 				}
 			}
 			else
 			{
 				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
+				json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
 			}
 
 			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
@@ -15315,28 +15103,32 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 void handleDataTransferResponse(char *payload, int gun_index)
 {
 	json_object *DataTransfer = json_tokener_parse(payload);
-	char status[32];
 
 	if(!is_error(DataTransfer))
 	{
-
 		// Required data
-		sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
-		DEBUG_INFO("Status: %s.\n", status);
+		DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
 
 		// Optional data
 		if(json_object_object_get(DataTransfer, "data") != NULL)
-		DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
-
-		// YES call_reader message confirm
-		if(ShmOCPP16Data->YesCustomData.CallReaderReq == 1)
 		{
-			sprintf((char *)ShmOCPP16Data->YesCustomData.CallReaderStatus, "%s",status);
-			ShmOCPP16Data->YesCustomData.CallReaderConf = 1;
-			ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
-			DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmOCPP16Data->YesCustomData.CallReaderStatus);
+			DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
+			json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
+
+			if(!is_error(Data))
+			{
+				if(json_object_object_get(Data, "msgId") != NULL)
+				{
+					if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
+					{
+						OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
+					}
+				}
+			}
+			json_object_put(Data);
 		}
 	}
+	json_object_put(DataTransfer);
 }
 
 void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)

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

@@ -99,6 +99,13 @@ static char *sqlPeriodEnergy = "create table if not exists ocpp_period_energy (
 							   "occurDatetime text,"
 							   "periodEnergy text);";
 
+static char *sqlReportDeduct = "create table if not exists report_deduct_info ( idx integer primary key,"
+							   "transactionId integer UNIQUE,"
+							   "creditNo text,"
+							   "deductResult text,"
+							   "isDonateInvoice text,"
+							   "isUploaded text);";
+
 //=================================
 // Common routine
 //=================================
@@ -1481,6 +1488,17 @@ int main(void)
 		DEBUG_INFO( "Opened ocpp_period_energy table successfully\n");
 	}
 
+	// Create credit deduct info
+	if(sqlite3_exec(db, sqlReportDeduct, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		DEBUG_INFO( "Create Table report_deduct_info error %s\n",errMsg);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO( "Opened report_deduct_info table successfully\n");
+	}
+
 	if(initialConfigurationTable() != PASS)
 	{
 		DEBUG_WARN("OCPPConfiguration version mismatch, upgrade it.\n");

+ 129 - 337
EVSE/Modularization/ocppph/MessageHandler.c

@@ -126,7 +126,7 @@ struct ClientTime
 	struct timespec StopTransaction;
 	struct timespec MeterValues[CONNECTOR_QUANTITY];
 	struct timespec RemoteStartWait;
-	struct timespec YesCustomCallReader;
+	struct timespec TcciQueryDeduct;
 }clientTime;
 
 typedef union
@@ -808,6 +808,84 @@ int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg
 	return result;
 }
 
+int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[8192];
+
+	sprintf(sqlStr, "insert into report_deduct_info(transactionId, creditNo, deductResult, isDonateInvoice, isUploaded) values('%d', '%s', '%d', '%d', '0');", txId, creditNo, deductResult, isDonateInvoice);
+
+	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		result = FAIL;
+		DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
+	}
+
+	sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
+	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		result = FAIL;
+		DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
+	}
+
+	return result;
+}
+
+int OCPP_update_deduct_info(int txId, char *creditNo)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[8192];
+
+	sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
+
+	if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		result = FAIL;
+		DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
+	}
+
+	return result;
+}
+
+int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
+{
+	json_object *deductData = json_object_new_object();
+
+	json_object_object_add(deductData, "txId", json_object_new_int(atoi(columnValue[1])));
+	json_object_object_add(deductData, "creditNo", json_object_new_string(columnValue[2]));
+	json_object_object_add(deductData, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
+	json_object_object_add(deductData, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
+
+	sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
+	sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"ID_CreditDeductResult");
+	sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(deductData, JSON_C_TO_STRING_PLAIN));
+	json_object_put(deductData);
+
+	ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
+
+	return 0;
+}
+
+void OCPP_query_deduct_info()
+{
+    int rc = 0;
+
+    char sql[100];
+    char zErrMsg[100];
+
+    sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
+
+    /* Execute SQL statement */
+    rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
+
+    if( rc != SQLITE_OK )
+    {
+    	DEBUG_INFO("SQL error: %s\n", zErrMsg);
+    }
+}
+
 //==========================================
 // Check time passed since today
 //==========================================
@@ -3947,16 +4025,19 @@ void CheckSystemValue(void)
 	}
 
 	//===============================
-	// send YES CallReader
+	// Credit deduct report
 	//===============================
-	if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->YesCustomData.CallReaderReq == 1) && (getDiffSecNow(clientTime.YesCustomCallReader) >= 5))
+	if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
 	{
-		sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
-		sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"call_reader");
-		sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data," ");
-		ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
-		//ShmOCPP16Data->YesCustomData.CallReaderReq = 0;
-		refreshStartTimer(&clientTime.YesCustomCallReader);
+		OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo, ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice);
+
+		ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
+	}
+
+	if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
+	{
+		OCPP_query_deduct_info();
+		refreshStartTimer(&clientTime.TcciQueryDeduct);
 	}
 
 	for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
@@ -10332,255 +10413,6 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
 			json_object_put(response);
 		}
-		else if(strstr(tempmessageId, "refund_status") != NULL)
-		{
-			json_object *data;
-			data = json_tokener_parse(tempdata);
-			if(!is_error(data))
-			{
-				json_object_object_add(response, "status", json_object_new_string("Accepted"));
-
-				if(json_object_object_get(data, "status") != NULL)
-				{
-					//DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
-					if(strcmp(json_object_get_string(json_object_object_get(data, "status")), "T") || strcmp(json_object_get_string(json_object_object_get(data, "status")), "F"))
-					{
-						sprintf((char*)ShmOCPP16DataPH->YesCustomData.RefundStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
-					}
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("status data can not get."));
-				}
-
-				if(json_object_object_get(data, "chargeDate") != NULL)
-				{
-					sprintf((char *)ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeDate, "%s", json_object_get_string(json_object_object_get(data,"chargeDate")));
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("chargeDate data can not get."));
-				}
-
-				if(json_object_object_get(data, "holdAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "holdAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.RefundStatus.holdAmt = json_object_get_int(json_object_object_get(data, "holdAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("holdAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("holdAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "chargeAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "refundAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "refundAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.RefundStatus.refundAmt = json_object_get_int(json_object_object_get(data, "refundAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("refundAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("refundAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "page") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "page")) >= 0 && json_object_get_int(json_object_object_get(data, "page")) <= 3)
-						ShmOCPP16DataPH->YesCustomData.RefundStatus.page = json_object_get_int(json_object_object_get(data, "page"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("page data can not get."));
-				}
-
-				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
-				{
-					ShmOCPP16DataPH->YesCustomData.RefundStatusReq = 1;
-					DEBUG_INFO("<<< RefundStatus:{status:%s, chargeDate:%s, holdAmt:%d, chargeAmt:%d, refundAmt:%d, page:%d}\n",
-							ShmOCPP16DataPH->YesCustomData.RefundStatus.status,
-							ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeDate,
-							ShmOCPP16DataPH->YesCustomData.RefundStatus.holdAmt,
-							ShmOCPP16DataPH->YesCustomData.RefundStatus.chargeAmt,
-							ShmOCPP16DataPH->YesCustomData.RefundStatus.refundAmt,
-							ShmOCPP16DataPH->YesCustomData.RefundStatus.page);
-				}
-			}
-			else
-			{
-				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("refund_status content got something wrong."));
-			}
-			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
-			json_object_put(response);
-		}
-		else if(strstr(tempmessageId, "deduct_status") != NULL)
-		{
-			json_object *data;
-			data = json_tokener_parse(tempdata);
-			if(!is_error(data))
-			{
-				json_object_object_add(response, "status", json_object_new_string("Accepted"));
-
-				if(json_object_object_get(data, "status") != NULL)
-				{
-					//DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(data, "status")));
-					if((strcmp(json_object_get_string(json_object_object_get(data, "status")), "T")==0) || (strcmp(json_object_get_string(json_object_object_get(data, "status")), "F")==0))
-					{
-						sprintf((char*)ShmOCPP16DataPH->YesCustomData.DeductStatus.status, "%s", json_object_get_string(json_object_object_get(data, "status")));
-					}
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("status value is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("status data can not get."));
-				}
-
-				if(json_object_object_get(data, "autoLoadAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "autoLoadAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.DeductStatus.autoLoadAmt = json_object_get_int(json_object_object_get(data, "autoLoadAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("autoLoadAmt is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("autoLoadAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "beforeAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "beforeAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.DeductStatus.beforeAmt = json_object_get_int(json_object_object_get(data, "beforeAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("beforeAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("beforeAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "chargeAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "chargeAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.DeductStatus.chargeAmt = json_object_get_int(json_object_object_get(data, "chargeAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("chargeAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("chargeAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "afterAmt") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "afterAmt")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.DeductStatus.afterAmt = json_object_get_int(json_object_object_get(data, "afterAmt"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("afterAmt data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("afterAmt data can not get."));
-				}
-
-				if(json_object_object_get(data, "page") != NULL)
-				{
-					if(json_object_get_int(json_object_object_get(data, "page")) >= 0)
-						ShmOCPP16DataPH->YesCustomData.DeductStatus.page = json_object_get_int(json_object_object_get(data, "page"));
-					else
-					{
-						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("page data is invalid."));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("page data can not get."));
-				}
-
-				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
-				{
-					ShmOCPP16DataPH->YesCustomData.DeductStatusReq = 1;
-					DEBUG_INFO("<<< deduct_status:{status:%s, autoLoadAmt:%d, beforeAmt:%d, chargeAmt:%d, afterAmt:%d, page:%d}\n",
-							ShmOCPP16DataPH->YesCustomData.DeductStatus.status,
-							ShmOCPP16DataPH->YesCustomData.DeductStatus.autoLoadAmt,
-							ShmOCPP16DataPH->YesCustomData.DeductStatus.beforeAmt,
-							ShmOCPP16DataPH->YesCustomData.DeductStatus.chargeAmt,
-							ShmOCPP16DataPH->YesCustomData.DeductStatus.afterAmt,
-							ShmOCPP16DataPH->YesCustomData.DeductStatus.page);
-				}
-			}
-			else
-			{
-				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("deduct_status content got something wrong."));
-			}
-
-			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
-			json_object_put(response);
-		}
 		else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
 		{
 			json_object *data;
@@ -10591,7 +10423,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(json_object_object_get(data, "stationName") != NULL)
 				{
-					sprintf((char *)ShmOCPP16DataPH->YesCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
+					sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
 				}
 				else
 				{
@@ -10599,34 +10431,11 @@ int handleDataTransferRequest(char *uuid, char *payload)
 					json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
 				}
 
-				/*if(json_object_object_get(data, "station_id") != NULL)
-				{
-					sprintf((char *)ShmOCPP16Data->YesCustomData.ChargerInfo.station_id, "%s", json_object_get_string(json_object_object_get(data,"station_id")));
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("station_id data can not get."));
-				}
-
-				if(json_object_object_get(data, "charge_id") != NULL)
-				{
-					for(int idx=0;idx<json_object_array_length(json_object_object_get(data, "charge_id"));idx++)
-					{
-						sprintf((char*)ShmOCPP16Data->YesCustomData.ChargerInfo.charge_id[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(data, "charge_id"), idx)));
-					}
-				}
-				else
-				{
-					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("charge_id data can not get."));
-				}*/
-
 				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
 				{
-					ShmOCPP16DataPH->YesCustomData.ChargerInfoReq = 1;
+					ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
 					DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
-							ShmOCPP16DataPH->YesCustomData.ChargerInfo.station_name);
+							ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
 				}
 			}
 			else
@@ -10648,7 +10457,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(json_object_object_get(data, "weatherId") != NULL)
 				{
-					ShmOCPP16DataPH->YesCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
+					ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
 				}
 				else
 				{
@@ -10658,7 +10467,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(json_object_object_get(data, "Temperature") != NULL)
 				{
-					ShmOCPP16DataPH->YesCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
+					ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
 				}
 				else
 				{
@@ -10668,65 +10477,44 @@ int handleDataTransferRequest(char *uuid, char *payload)
 
 				if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
 				{
-					ShmOCPP16DataPH->YesCustomData.WeatherInfoReq = 1;
+					ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
 					DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
-								ShmOCPP16DataPH->YesCustomData.WeatherInfo.weatherId,
-								ShmOCPP16DataPH->YesCustomData.WeatherInfo.temperature);
+								ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
+								ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
 				}
 			}
-			else
+			else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
 			{
-				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
-			}
-
-			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
-			json_object_put(response);
-		}
-		else if(strstr(tempmessageId, "set_qrcode") != NULL)
-		{
-			json_object *data;
-			data = json_tokener_parse(tempdata);
-			if(!is_error(data))
-			{
-				json_object_object_add(response, "status", json_object_new_string("Accepted"));
-
-				if(json_object_object_get(data, "connectorId") != NULL)
+				json_object *data;
+				data = json_tokener_parse(tempdata);
+				if(!is_error(data))
 				{
-					if((json_object_get_int(json_object_object_get(data, "connectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "connectorId")) <= gunTotalNumber))
+					json_object_object_add(response, "status", json_object_new_string("Accepted"));
+
+					if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
 					{
-						int idx = json_object_get_int(json_object_object_get(data, "connectorId"))-1;
-						if(json_object_object_get(data, "qrcode") != NULL)
-						{
-							sprintf((char *)ShmOCPP16DataPH->YesCustomData.QrCode[idx], "%s", json_object_get_string(json_object_object_get(data,"qrcode")));
-							ShmOCPP16DataPH->YesCustomData.SetQrCodeReq = 1;
-							DEBUG_INFO("<<< set_qrcode:{connectorId:%d, qrcode:%s}\n",
-											idx,
-											ShmOCPP16DataPH->YesCustomData.QrCode[idx]
-											);
-						}
-						else
-						{
-							json_object_object_add(response, "status", json_object_new_string("Rejected"));
-							json_object_object_add(response, "data", json_object_new_string("qrcode data can not get."));
-						}
+						ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
+						DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
 					}
 					else
 					{
 						json_object_object_add(response, "status", json_object_new_string("Rejected"));
-						json_object_object_add(response, "data", json_object_new_string("connectorId data is invalid."));
+						json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
 					}
 				}
 				else
 				{
 					json_object_object_add(response, "status", json_object_new_string("Rejected"));
-					json_object_object_add(response, "data", json_object_new_string("connectorId data can not get."));
+					json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
 				}
+
+				sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
+				json_object_put(response);
 			}
 			else
 			{
 				json_object_object_add(response, "status", json_object_new_string("Rejected"));
-				json_object_object_add(response, "data", json_object_new_string("set_qrcode content got something wrong."));
+				json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
 			}
 
 			sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
@@ -14817,28 +14605,32 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 void handleDataTransferResponse(char *payload, int gun_index)
 {
 	json_object *DataTransfer = json_tokener_parse(payload);
-	char status[32];
 
 	if(!is_error(DataTransfer))
 	{
-
 		// Required data
-		sprintf(status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
-		DEBUG_INFO("Status: %s.\n", status);
+		DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
 
 		// Optional data
 		if(json_object_object_get(DataTransfer, "data") != NULL)
-		DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
-
-		// YES call_reader message confirm
-		if(ShmOCPP16DataPH->YesCustomData.CallReaderReq == 1)
 		{
-			sprintf((char *)ShmOCPP16DataPH->YesCustomData.CallReaderStatus, "%s",status);
-			ShmOCPP16DataPH->YesCustomData.CallReaderConf = 1;
-			ShmOCPP16DataPH->YesCustomData.CallReaderReq = 0;
-			DEBUG_INFO("Report CallReader status to CSU: %s\n",ShmOCPP16DataPH->YesCustomData.CallReaderStatus);
+			DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
+			json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
+
+			if(!is_error(Data))
+			{
+				if(json_object_object_get(Data, "msgId") != NULL)
+				{
+					if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
+					{
+						OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
+					}
+				}
+			}
+			json_object_put(Data);
 		}
 	}
+	json_object_put(DataTransfer);
 }
 
 void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)

+ 18 - 0
EVSE/Modularization/ocppph/Module_OcppBackend.c

@@ -94,6 +94,13 @@ static char *sqlTransaction = "create table if not exists ocpp_transaction_recor
 							  "message_type text,"
 							  "message_content text);";
 
+static char *sqlReportDeduct = "create table if not exists report_deduct_info ( idx integer primary key,"
+							   "transactionId integer UNIQUE,"
+							   "creditNo text,"
+							   "deductResult text,"
+							   "isDonateInvoice text,"
+							   "isUploaded text);";
+
 //=================================
 // Common routine
 //=================================
@@ -1470,6 +1477,17 @@ int main(void)
 		DEBUG_INFO( "Opened ocpp_transaction_record table successfully\n");
 	}
 
+	// Create credit deduct info
+	if(sqlite3_exec(db, sqlReportDeduct, 0, 0, &errMsg) != SQLITE_OK)
+	{
+		DEBUG_INFO( "Create Table report_deduct_info error %s\n",errMsg);
+		return 0;
+	}
+	else
+	{
+		DEBUG_INFO( "Opened report_deduct_info table successfully\n");
+	}
+
 	if(initialConfigurationTable() != PASS)
 	{
 		DEBUG_WARN("OCPPConfiguration version mismatch, upgrade it.\n");

+ 14 - 37
EVSE/Projects/define.h

@@ -4558,31 +4558,9 @@ struct StructSessionTarget
 //===================================
 // YES custom protocol
 //===================================
-struct StructRefundStatus
-{
-    unsigned char status[10];
-    unsigned char chargeDate[32];
-    int holdAmt;
-    int chargeAmt;
-    int refundAmt;
-    int page;
-};
-
-struct StructDeductStatus
-{
-    unsigned char status[10];
-    int autoLoadAmt;
-    int beforeAmt;
-    int chargeAmt;
-    int afterAmt;
-    int page;
-};
-
 struct StructChargerInfo
 {
     unsigned char station_name[64];
-    unsigned char station_id[64];
-    unsigned char charge_id[4][64];
 };
 
 struct StructWeatherInfo
@@ -4591,27 +4569,26 @@ struct StructWeatherInfo
     float temperature;
 };
 
-struct StructYesCustomData
+struct StructCreditDeductResult
+{
+	int txId;
+	unsigned char creditNo[64];
+	unsigned char deductResult:1;
+	unsigned char isDonateInvoice:1;
+};
+
+struct StructTcciCustomData
 {
-    struct StructRefundStatus RefundStatus;
-    struct StructDeductStatus DeductStatus;
     struct StructChargerInfo ChargerInfo;
     struct StructWeatherInfo WeatherInfo;
-    unsigned char QrCode[4][128];
-    unsigned char CallReaderStatus[10];
-
-    unsigned char CallReaderReq:1;
-    unsigned char CallReaderConf:1;
-    unsigned char RefundStatusReq:1;
-    unsigned char RefundStatusConf:1;
-    unsigned char DeductStatusReq:1;
-    unsigned char DeductStatusConf:1;
+    struct StructCreditDeductResult DeductInfo;
+    unsigned char TriggerReaderReq[3];
+
+    unsigned char ReportCreditDeductReq:1;
     unsigned char ChargerInfoReq:1;
     unsigned char ChargerInfoConf:1;
     unsigned char WeatherInfoReq:1;
     unsigned char WeatherInfoConf:1;
-    unsigned char SetQrCodeReq:1;
-    unsigned char SetQrCodeConf:1;
 };
 
 struct OCPP16Data
@@ -4803,7 +4780,7 @@ struct OCPP16Data
     struct StructSignCertificate                    SignCertificate;
     struct StructSignedFirmwareStatusNotification   SignedFirmwareStatusNotification;
     struct StructSessionTarget                      SessionTarget[CONNECTOR_QUANTITY];
-    struct StructYesCustomData                      YesCustomData;
+    struct StructTcciCustomData                     TcciCustomData;
 };