Jelajahi Sumber

2020-02-21 /Kathy Yeh
1. add OCPP Configuration enum in define.h
2. modify offline StartTransaction TransactionId issue
3. modify Transaction queue resent logic
4. modify Meter Value phase for DC model
5. sync OCPP KEY MaxEnergyOnInvaildId to SysConfig offlineMaxChargeEnergy
6. modify OCPP KEY ConnectorPhaseRotation default Value

Kathy_Yeh 5 tahun lalu
induk
melakukan
1c4e864ea6

+ 4 - 7
EVSE/Modularization/ocppfiles/JsonParser.c

@@ -70,7 +70,7 @@ static FunCallErrorPtr funcallerror[] = {	handleError	};
 
 void ReceivedMessage(void *in, size_t len)
 {
-	DEBUG_INFO("ReceivedMessage\n");
+	printf("ReceivedMessage\n");
 	char tempin[1024*4];
 	int MsgType = 0;
 	char UniqueId[37],Action[33],Payload[10241],ErrorCode[129],ErrorDescription[513];
@@ -99,7 +99,7 @@ void ReceivedMessage(void *in, size_t len)
 	//char *str = "[ ]";
 	if(strcmp((const char *)tempin,"[ ]") == 0)
 	{
-	    DEBUG_INFO("Message is empty arrary. \n");
+		printf("Message is empty arrary. \n");
 	    return;
 	}
 
@@ -128,10 +128,7 @@ void ReceivedMessage(void *in, size_t len)
 			return;
 		}
 
-		#if 1
-		// check Transaction-related messages
 		CheckTransactionPacket(UniqueId);
-		#endif
 
 		switch (MsgType)
 		{
@@ -291,7 +288,7 @@ void ReceivedMessage(void *in, size_t len)
 	}
 	else
 	{
-		DEBUG_WARN("Message is null. cant parse messgae. \n");
+		printf("Message is null. cant parse messgae. \n");
 	}
 
 }
@@ -378,7 +375,7 @@ void CallErrorHandler(char *id, char *errorCode, char *errorDescription,char *pa
 
 	if(callErrorfptr == NULL)
 	{
-		DEBUG_ERROR("callErrorfptr is null\n");
+		printf("callErrorfptr is null\n");
 	}
 
 	if ( callErrorfptr )

+ 243 - 87
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -134,6 +134,12 @@ static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;	// Sys
 int authenrequest = FALSE;
 int authorizeRetryTimes = 0;  //number of  Retry times
 
+//===============================
+// OCPP StartTransaction transactionId variables
+//===============================
+static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
+
+
 //===============================
 // OCPP other variables
 //===============================
@@ -818,7 +824,7 @@ static char * UnitOfMeasureStr[] = {
 	MACROSTR(Percent)
 };
 
-
+#if 0
 /*Configuration enum*/
 enum CoreProfile {
 	 AllowOfflineTxForUnknownId=0,
@@ -857,6 +863,7 @@ enum CoreProfile {
 	 WebSocketPingInterval,
 	 _CoreProfile_CNT
 };
+#endif
 
 enum LocalAuthListManagementProfile{
 	LocalAuthListEnabled=0,
@@ -2582,7 +2589,14 @@ int sendStopTransactionRequest(int gun_index)
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
-	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
+	{
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
+	}
+	else
+	{
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
+	}
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
 
@@ -2617,6 +2631,7 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
 	}
 	else
 	{
@@ -2628,12 +2643,14 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
+
 	}// END FOR AC ELSE
 
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
-	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
+	//strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
 
@@ -2665,6 +2682,8 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
+
 	}
 	else
 	{
@@ -2676,12 +2695,14 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
+
 	}// END FOR AC ELSE
 
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
-	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
+	//strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
 
@@ -2713,6 +2734,8 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
+
 	}
 	else
 	{
@@ -2724,12 +2747,14 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
+
 	}// END FOR AC ELSE
 
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
-	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
+	//strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
 
@@ -2761,6 +2786,7 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
 	}
 	else
 	{
@@ -2772,12 +2798,13 @@ int sendStopTransactionRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
 	}// END FOR AC ELSE
 
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
-	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
+	//strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
 	strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
 
@@ -2812,7 +2839,7 @@ int sendStopTransactionRequest(int gun_index)
 		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
 		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
 		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
-		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L1_N]);
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
 		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
 		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
 
@@ -3023,6 +3050,8 @@ int sendMeterValuesRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
+
 	}
 	else
 	{
@@ -3034,12 +3063,14 @@ int sendMeterValuesRequest(int gun_index)
 			}
 		}
 
+		strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
+
 	}// END FOR AC ELSE
 
 	strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
 	strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
 	strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
-	strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
+	//strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
 	strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
 	strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
 
@@ -3073,6 +3104,8 @@ int sendMeterValuesRequest(int gun_index)
 	    	    sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
 	    	 }
 	    }
+
+	    strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
 	 }
 	 else
 	 {
@@ -3084,13 +3117,14 @@ int sendMeterValuesRequest(int gun_index)
 	    	 }
 		 }
 
+		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
 	 }//END FOR AC ELSE
 
 
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
-	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1]);
+	 //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
 
@@ -3123,6 +3157,8 @@ int sendMeterValuesRequest(int gun_index)
 	     		sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
 	     	}
 	     }
+
+	     strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
 	}
 	else
 	{
@@ -3134,13 +3170,15 @@ int sendMeterValuesRequest(int gun_index)
 	     	}
 	     }
 
+	     strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
+
 	 }// END FOR AC ELSE
 
 
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
-	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
+	 //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
 
@@ -3172,6 +3210,8 @@ int sendMeterValuesRequest(int gun_index)
 	 			sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
 			 }
 		 }
+
+		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
 	 }
 	 else
 	 {
@@ -3182,13 +3222,15 @@ int sendMeterValuesRequest(int gun_index)
 				 sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
 			 }
 		 }
+
+		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
 	 }//END FOR AC ELSE
 
 
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
-	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
+	// strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
 	 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
 
@@ -3226,7 +3268,7 @@ int sendMeterValuesRequest(int gun_index)
 		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
 		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
 		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
-		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
+		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
 		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
 		 strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
 	 }
@@ -3547,12 +3589,8 @@ int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connector
 							,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
 							,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
 
-
-			//int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
-
-		#if 1 // remove temporally
-		int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
-
+		int len = nPeriod;
+		//Last Period StartPriod is less than diffSeconds
 		if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
 		{
 
@@ -3573,10 +3611,10 @@ int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connector
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
 				}
-				else
+				else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
 				{
 					sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
-							, (((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
+							, (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))   //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
 				}
@@ -3584,17 +3622,12 @@ int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connector
 			}
 		}
 
-
-		#endif
-
-
 		sprintf(message + strlen(message), "]}}]");
 
 
 	}
 
 	LWS_Send(message);
-
 	result = TRUE;
 	return result;
 }
@@ -4862,11 +4895,9 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
     char comfirmstr[20];
     //float totallimit =0.0;
     float MinChargingRate =0.0;
-	double diff_t;
-	struct tm tp;
-    //int clearflag = FALSE;
-    FILE *fptr1;//, *fptr2;
-    //char temp[] = "../Storage/OCPP/temp.json";
+	//double diff_t;
+	//struct tm tp;
+    FILE *fptr1;
 	int c = 0;
 	//int i = 0;
 	char * pch;
@@ -5077,13 +5108,14 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
 
 
   			  	//
+#if 0
   			  	strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
   			  	tp.tm_isdst = -1;
   			  	time_t utc = mktime(&tp);
   			  	// current time
   			  	time_t t = time(NULL);
-
-  			  	diff_t = difftime(t, utc);
+#endif
+  			  	//diff_t = difftime(t, utc);
 
   			  	//parsing strings to words
   			  	i = 0;
@@ -5294,14 +5326,15 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   	  	  	  		tempminChargingRateFloat = 0.0;
   	  	  	  	}
 
-
+#if 0
   	  	  	  	//
   	  	  	  	strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
   	  	  	  	tp.tm_isdst = -1;
   	  	  	  	time_t utc = mktime(&tp);
   	  	  	  	// current time
   	  	  	  	time_t t = time(NULL);
-  	  	  	  	diff_t = difftime(t, utc);
+  	  	  	  	//diff_t = difftime(t, utc);
+#endif
 
   	  	  	  	//parsing strings to words
   	  	  	  	i = 0;
@@ -5568,15 +5601,17 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   				  		tempminChargingRateFloat = 0.0;
   				  	}
 
+#if 0
   				  	//
   				  	strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
   				  	tp.tm_isdst = -1;
   				  	time_t utc = mktime(&tp);
   				  	time_t t = time(NULL);
-  				  	diff_t = difftime(t, utc);
+  				  	//diff_t = difftime(t, utc);
+#endif
 
-  				  	DEBUG_INFO("diff_t=%f\n",diff_t);
-  				  	DEBUG_INFO(" debug  5 -1\n");
+  				  	//DEBUG_INFO("diff_t=%f\n",diff_t);
+  				  	//DEBUG_INFO(" debug  5 -1\n");
   				  	//parsing strings to words
   				  	i = 0;
   				  	loc = strstr(sLineWord, "chargingSchedulePeriod");
@@ -5819,12 +5854,14 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   	  			  	  	tempminChargingRateFloat = 0.0;
   	  			  	}
 
+#if 0
   	  			  	//
   	  			  	strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
   	  			  	tp.tm_isdst = -1;
   	  			  	time_t utc = mktime(&tp);
   	  			  	time_t t = time(NULL);
-  	  			  	diff_t = difftime(t, utc);
+  	  			  	//diff_t = difftime(t, utc);
+#endif
 
   	  			  	//DEBUG_INFO("diff_t=%f\n",diff_t);
 
@@ -6093,14 +6130,16 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   				  	  		tempminChargingRateFloat = 0.0;
   				  	  	}
 
+#if 0
   				  	   	//
   				  	  	strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
   				  	  	tp.tm_isdst = -1;
   				  	  	time_t utc = mktime(&tp);
   				  	  	time_t t = time(NULL);
-  				  	  	diff_t = difftime(t, utc);
+  				  	  	//diff_t = difftime(t, utc);
+#endif
 
-  				  	  	DEBUG_INFO("diff_t=%f\n",diff_t);
+  				  	  	//DEBUG_INFO("diff_t=%f\n",diff_t);
   				  	  	//parsing strings to words
   				  	  	i = 0;
   				  	  	loc = strstr(sLineWord, "chargingSchedulePeriod");
@@ -6618,69 +6657,123 @@ void* GetDiagnosticsProcess(void* data)
 				   protocol, user, password, host, &port, path);
 	}
 
-	if(strcmp(protocol,"ftp")!=0)
+	if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
 	{
-		DEBUG_INFO("protocol is not ftp!\n");
+		DEBUG_INFO("protocol is not ftp/http ! \n");
 		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
 		goto end;
 
 	}
 
-  	sscanf(host,"%[^/]%s",host1, path1);
-	sprintf(ftppath,"%s", path1);
-
-	DEBUG_INFO("protocol =%s\n",protocol);
-	DEBUG_INFO("user =%s\n",user);
-	DEBUG_INFO("password =%s\n",password);
-	DEBUG_INFO("host1 =%s\n",host1);
-	DEBUG_INFO("port =%d\n",port);
-	DEBUG_INFO("path1 =%s\n",path1);
-	DEBUG_INFO("ftppath=%s\n",ftppath);
 
-	int ftppathlen=strlen(ftppath);
-	int i=1;
-	char filenametemp[50];
-	while(i < ftppathlen)
+	if(strncmp(locationstr,"http", 4) == 0)
 	{
-	  int len=ftppathlen-i;
-	   if(ftppath[len]== 47) // '/' ascll code: 47
-	   {
-		   DEBUG_INFO("find '/' all right\n");
-	     break;
-	   }
-	   i=i+1;
+		sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
+			    	    			         protocol, host, path);
 
-	}
+		//sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
+			    	    	//	         protocol, user, password, host, path);
+		sprintf(ftppath,"/%s", path);
 
-	memset(filenametemp, 0, sizeof(filenametemp));
-	strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
-	filenametemp[i+1] = 0;
+		DEBUG_INFO("protocol =%s\n",protocol);
 
+		DEBUG_INFO("host =%s\n",host);
 
-	    //httpDownLoadFile(host, ftppath, fname);
-	memset(ftpbuf, 0, sizeof(ftpbuf));
+		DEBUG_INFO("path =%s\n",path);
+		DEBUG_INFO("ftppath=%s\n",ftppath);
+		int ftppathlen=strlen(ftppath);
+		int i=1;
+		char filenametemp[50];
+		while(i < ftppathlen)
+		{
+			int len=ftppathlen-i;
+			if(ftppath[len]== 47) // '/' ascll code: 47
+			{
+				DEBUG_INFO("compare '/' all right\n");
+			    break;
+			}
+			i=i+1;
+		}
 
-    if(port == 0)
-    	port = 21;
-	//isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
+		memset(filenametemp, 0, sizeof(filenametemp));
+		strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
+		filenametemp[i+1] = 0;
+			//sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
 
 
-    do{
-    	 isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
-    	 sleep(retryIntervalInt);
-    }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
+		do{
+			isSuccess = httpUploadFile(host, ftppath, filenametemp, locationstr);
+			sleep(retryIntervalInt);
+		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
+
+		//	isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
+
+		if(!isSuccess)
+		{
+			//BulldogUtil.sleepMs(interval*1000);
+			DEBUG_INFO("Diagnostics fail.\n");
+			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
+		}
+		else
+		{
+			DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
+			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
+			//isUpdateRequest = TRUE;
+		}
 
-	if(!isSuccess)
-	{
-	   //BulldogUtil.sleepMs(interval*1000);
-		DEBUG_INFO("Diagnostics fail.\n");
-		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
 	}
 	else
 	{
-		DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
-		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
-		//isUpdateRequest = TRUE;
+		sscanf(host,"%[^/]%s",host1, path1);
+		sprintf(ftppath,"%s", path1);
+
+		DEBUG_INFO("protocol =%s\n",protocol);
+		DEBUG_INFO("user =%s\n",user);
+		DEBUG_INFO("password =%s\n",password);
+		DEBUG_INFO("host1 =%s\n",host1);
+		DEBUG_INFO("port =%d\n",port);
+		DEBUG_INFO("path1 =%s\n",path1);
+		DEBUG_INFO("ftppath=%s\n",ftppath);
+
+		int ftppathlen=strlen(ftppath);
+		int i=1;
+		char filenametemp[50];
+		while(i < ftppathlen)
+		{
+			int len=ftppathlen-i;
+			if(ftppath[len]== 47) // '/' ascll code: 47
+			{
+				 DEBUG_INFO("find '/' all right\n");
+			     break;
+			}
+			i=i+1;
+		}
+
+		memset(filenametemp, 0, sizeof(filenametemp));
+		strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
+		filenametemp[i+1] = 0;
+		memset(ftpbuf, 0, sizeof(ftpbuf));
+
+		if(port == 0)
+		   port = 21;
+
+		do{
+		    isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
+		    sleep(retryIntervalInt);
+		}while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
+
+		if(!isSuccess)
+		{
+			//BulldogUtil.sleepMs(interval*1000);
+			DEBUG_INFO("Diagnostics fail.\n");
+			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
+		}
+		else
+		{
+			DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
+			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
+				//isUpdateRequest = TRUE;
+		}
 	}
 
 end:
@@ -10385,6 +10478,9 @@ void handleStartTransactionResponse(char *payload, int gun_index)
 	sstr[c] = '\0';
 	ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
 	transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
+	TransactionId[gun_index] = transactionIdInt;
+	DEBUG_INFO("gun_index: %d\n", gun_index);
+	DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
 	ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
 	ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
 
@@ -10402,7 +10498,7 @@ DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].Res
 
 	}
 
-	DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
+	//DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
 }
 
 void handleStatusNotificationResponse(char *payload, int gun_index)
@@ -10575,6 +10671,7 @@ int initialConfigurationTable(void)
 	ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
 	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
 	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
+	ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
 
 	// MeterValuesAlignedData
 	ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
@@ -10620,7 +10717,7 @@ int initialConfigurationTable(void)
 	// ConnectorPhaseRotation
 	ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
 	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
-	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
+	strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
 
 	// ConnectorPhaseRotationMaxLength
 	ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
@@ -10980,6 +11077,7 @@ void getKeyValue(char *keyReq)
 	    	 }
 
 	    	 strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
+	    	 ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
 	    	 isKnowKey = TRUE;
 	    }
 
@@ -11805,6 +11903,7 @@ void processUnkownKey(void)
     		else
     		{
     			 sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
+    			 ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
     			 isSuccess = ConfigurationStatus_Accepted;
     		}
     	}
@@ -12382,6 +12481,53 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 
 }
 
+int httpUploadFile(char *location, char *path, char *filename,char *url)
+{
+	char rmFileCmd[100]={0};
+    char FilePath[100]={0};
+	char ftpbuf[200];
+	int systemresult;
+
+	DEBUG_INFO("filename=%s\n",filename);
+	DEBUG_INFO("url=%s\n",url);
+	sprintf(FilePath,"%s","../mnt/upload_file.txt");
+
+	if((access(FilePath,F_OK))!=-1)
+	{
+		DEBUG_INFO("filename=%s exist.\n",FilePath);
+		sprintf(rmFileCmd,"rm -f %s",FilePath);
+		system(rmFileCmd);
+	}
+
+	FILE *fp = fopen("../mnt/upload_file.txt", "w+");
+
+	if(fp == NULL)
+	{
+		DEBUG_INFO("log is NULL\n");
+		return 0;
+	}
+	else
+	{
+		fprintf(fp, "%s\n", url);
+		fprintf(fp, "%s\n", filename);
+		fclose(fp);
+	}
+
+	memset(ftpbuf, 0, sizeof(ftpbuf));
+	sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
+			//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
+	systemresult = system(ftpbuf);
+
+	DEBUG_INFO("systemresult=%d\n",systemresult);
+	if(systemresult != 0)
+	{
+		DEBUG_INFO("http DownLoad error!\n");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
 {
 	 struct hostent* server;
@@ -12961,6 +13107,16 @@ void SetHeartBeatWithNOResponse(void)
 	HeartBeatWithNOResponse = 0;
 }
 
+int GetTransactionId(int gunindex)
+{
+	return TransactionId[gunindex];
+}
+
+void SetTransactionIdZero(int gunindex)
+{
+	TransactionId[gunindex] = 0;
+}
+
 int InternetDisconnect(void)
 {
 	//DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
@@ -14357,7 +14513,7 @@ void GetChargingProfileRequest(int gunindex)
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
-	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
+	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
 	  				ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
 	  				strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );

+ 139 - 138
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -1,138 +1,139 @@
-#ifndef MessageHandler_H
-#define MessageHandler_H
-
-struct StructPeriod
-{
-	int		StartPeriod;
-	float 	Limit;//0.1;
-	int		NumberPhases;
-};
-
-struct StructProfile
-{
-	int	Duration;
-	int TotalPeriod;
-	struct StructPeriod	Period[10];
-};
-
-
-//===============================================
-// Common routine
-//===============================================
-int initialConfigurationTable(void);
-
-//==========================================
-// send request routine
-//==========================================
-int sendAuthorizeRequest(int gun_index);
-int sendBootNotificationRequest(void);
-int sendDataTransferRequest(int gun_index);
-int sendDiagnosticsStatusNotificationRequest(char *status);
-int sendFirmwareStatusNotificationRequest(char *status);
-int sendHeartbeatRequest(int gun_index);
-int sendStartTransactionRequest(int gun_index);
-int sendStatusNotificationRequest(int gun_index);
-int sendStopTransactionRequest(int gun_index);
-int sendMeterValuesRequest(int gun_index);
-
-
-//==========================================
-// send confirm routine
-//==========================================
-int sendCancelReservationConfirmation(char *uuid,char *payload);
-int sendChangeAvailabilityConfirmation(char *uuid,char *payload);
-int sendChangeConfigurationConfirmation(char *uuid,char *payload);
-int sendClearCacheConfirmation(char *uuid,char *payload);
-int sendClearChargingProfileConfirmation(char *uuid,char *payload);
-int sendDataTransferConfirmation(char *uuid,char *payload);
-int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod);
-int sendGetConfigurationConfirmation(char *uuid);
-int sendGetDiagnosticsConfirmation(char *uuid,char *payload);
-int sendGetLocalListVersionConfirmation(char *uuid,char *payload);
-int sendRemoteStartConfirmation(char *uuid,char *payload);
-int sendRemoteStopTransactionConfirmation(char *uuid,char *payload);
-int sendReserveNowTransactionConfirmation(char *uuid,char *payload);
-int sendResetConfirmation(char *uuid,char *payload);
-int sendSendLocalListConfirmation(char *uuid,char *payload);
-int sendSetChargingProfileConfirmation(char *uuid,char *payload);
-int sendTriggerMessageConfirmation(char *uuid,char *payload);
-int sendUnlockConnectorConfirmation(char *uuid,char *payload);
-int sendUpdateFirmwareConfirmation(char *uuid);
-//==========================================
-// send CallError routine
-//==========================================
-void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription);
-
-//==========================================
-// Handle server request routine  Start
-//==========================================
-int handleCancelReservationRequest(char *uuid, char *payload);
-int handleChangeAvailabilityRequest(char *uuid, char *payload);
-int handleChangeConfigurationRequest(char *uuid, char *payload);
-int handleClearCacheRequest(char *uuid, char *payload);
-int handleClearChargingProfileRequest(char *uuid, char *payload);
-int handleDataTransferRequest(char *uuid, char *payload);
-//long long diff_tm(struct tm *a, struct tm *b);
-int handleGetCompositeScheduleRequest(char *uuid, char *payload);
-int handleGetConfigurationRequest(char *uuid, char *payload);
-int handleGetDiagnosticsRequest(char *uuid, char *payload);
-int handleGetLocalListVersionRequest(char *uuid, char *payload);
-int handleRemoteStartRequest(char *uuid, char *payload);
-int handleRemoteStopTransactionRequest(char *uuid, char *payload);
-int handleReserveNowTransactionRequest(char *uuid, char *payload);
-int handleResetRequest(char *uuid, char *payload);
-int handleSendLocalListRequest(char *uuid, char *payload);
-int handleSetChargingProfileRequest(char *uuid, char *payload);
-int handleTriggerMessageRequest(char *uuid, char *payload);
-int handleUnlockConnectorRequest(char *uuid, char *payload);
-int handleUpdateFirmwareRequest(char *uuid, char *payload);
-void handleAuthorizeResponse(char *payload, int gun_index);
-void handleBootNotificationResponse(char *payload, int gun_index);
-void handleDataTransferResponse(char *payload, int gun_index);
-void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index);
-void handleFirmwareStatusNotificationResponse(char *payload, int gun_index);
-void handleHeartbeatResponse(char *payload, int gun_index);
-void handleMeterValuesResponse(char *payload, int gun_index);
-void handleStartTransactionResponse(char *payload, int gun_index);
-void handleStatusNotificationResponse(char *payload, int gun_index);
-void handleStopTransactionnResponse(char *payload, int gun_index);
-
-//==========================================
-// Handle Error routine
-//==========================================
-void handleError(char *id, char *errorCode, char *errorDescription,char *payload);
-
-//===============================================
-// Common routine
-//===============================================
- void getKeyValue(char *keyReq);
- int  setKeyValue(char *key, char *value);
- int updateSetting(char *key, char *value);
-#if 0
- json_object * getJSONfromFile(char *filename);
-#endif
- int httpDownLoadFile(char *location, char *path, char *filename,char *url);
- int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url);
- void *UpdateFirmwareProcess(void* data);
- void* GetDiagnosticsProcess(void* data);
- int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
- int get_file_contents(const char* filename, char** outbuffer);
- //void Send(struct json_object *message);
- void LWS_Send(char * str);
-extern int queue_operation(int type, char *frontUUID, char *frontData);
-char *GetOcppServerURL();
-char *GetOcppPath();
-int GetOcppPort();
- //===============================================
- // sqlite related routine
- //===============================================
- int SettingChargingRecord(int target, int transactionId);
- int addBuff(int gun_idx, int user_id, int cmd_sn);
- void OCPP_getListVerion();
- int OCPP_cleanLocalList();
- int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
- int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
- void OCPP_getIdTag(char *idTag);
- void OCPP_deleteIdTag(char *idTag);
- void GetChargingProfileRequest(int gunindex);
-#endif
+#ifndef MessageHandler_H
+#define MessageHandler_H
+
+struct StructPeriod
+{
+	int		StartPeriod;
+	float 	Limit;//0.1;
+	int		NumberPhases;
+};
+
+struct StructProfile
+{
+	int	Duration;
+	int TotalPeriod;
+	struct StructPeriod	Period[10];
+};
+
+
+//===============================================
+// Common routine
+//===============================================
+int initialConfigurationTable(void);
+
+//==========================================
+// send request routine
+//==========================================
+int sendAuthorizeRequest(int gun_index);
+int sendBootNotificationRequest(void);
+int sendDataTransferRequest(int gun_index);
+int sendDiagnosticsStatusNotificationRequest(char *status);
+int sendFirmwareStatusNotificationRequest(char *status);
+int sendHeartbeatRequest(int gun_index);
+int sendStartTransactionRequest(int gun_index);
+int sendStatusNotificationRequest(int gun_index);
+int sendStopTransactionRequest(int gun_index);
+int sendMeterValuesRequest(int gun_index);
+
+
+//==========================================
+// send confirm routine
+//==========================================
+int sendCancelReservationConfirmation(char *uuid,char *payload);
+int sendChangeAvailabilityConfirmation(char *uuid,char *payload);
+int sendChangeConfigurationConfirmation(char *uuid,char *payload);
+int sendClearCacheConfirmation(char *uuid,char *payload);
+int sendClearChargingProfileConfirmation(char *uuid,char *payload);
+int sendDataTransferConfirmation(char *uuid,char *payload);
+int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod);
+int sendGetConfigurationConfirmation(char *uuid);
+int sendGetDiagnosticsConfirmation(char *uuid,char *payload);
+int sendGetLocalListVersionConfirmation(char *uuid,char *payload);
+int sendRemoteStartConfirmation(char *uuid,char *payload);
+int sendRemoteStopTransactionConfirmation(char *uuid,char *payload);
+int sendReserveNowTransactionConfirmation(char *uuid,char *payload);
+int sendResetConfirmation(char *uuid,char *payload);
+int sendSendLocalListConfirmation(char *uuid,char *payload);
+int sendSetChargingProfileConfirmation(char *uuid,char *payload);
+int sendTriggerMessageConfirmation(char *uuid,char *payload);
+int sendUnlockConnectorConfirmation(char *uuid,char *payload);
+int sendUpdateFirmwareConfirmation(char *uuid);
+//==========================================
+// send CallError routine
+//==========================================
+void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription);
+
+//==========================================
+// Handle server request routine  Start
+//==========================================
+int handleCancelReservationRequest(char *uuid, char *payload);
+int handleChangeAvailabilityRequest(char *uuid, char *payload);
+int handleChangeConfigurationRequest(char *uuid, char *payload);
+int handleClearCacheRequest(char *uuid, char *payload);
+int handleClearChargingProfileRequest(char *uuid, char *payload);
+int handleDataTransferRequest(char *uuid, char *payload);
+//long long diff_tm(struct tm *a, struct tm *b);
+int handleGetCompositeScheduleRequest(char *uuid, char *payload);
+int handleGetConfigurationRequest(char *uuid, char *payload);
+int handleGetDiagnosticsRequest(char *uuid, char *payload);
+int handleGetLocalListVersionRequest(char *uuid, char *payload);
+int handleRemoteStartRequest(char *uuid, char *payload);
+int handleRemoteStopTransactionRequest(char *uuid, char *payload);
+int handleReserveNowTransactionRequest(char *uuid, char *payload);
+int handleResetRequest(char *uuid, char *payload);
+int handleSendLocalListRequest(char *uuid, char *payload);
+int handleSetChargingProfileRequest(char *uuid, char *payload);
+int handleTriggerMessageRequest(char *uuid, char *payload);
+int handleUnlockConnectorRequest(char *uuid, char *payload);
+int handleUpdateFirmwareRequest(char *uuid, char *payload);
+void handleAuthorizeResponse(char *payload, int gun_index);
+void handleBootNotificationResponse(char *payload, int gun_index);
+void handleDataTransferResponse(char *payload, int gun_index);
+void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index);
+void handleFirmwareStatusNotificationResponse(char *payload, int gun_index);
+void handleHeartbeatResponse(char *payload, int gun_index);
+void handleMeterValuesResponse(char *payload, int gun_index);
+void handleStartTransactionResponse(char *payload, int gun_index);
+void handleStatusNotificationResponse(char *payload, int gun_index);
+void handleStopTransactionnResponse(char *payload, int gun_index);
+
+//==========================================
+// Handle Error routine
+//==========================================
+void handleError(char *id, char *errorCode, char *errorDescription,char *payload);
+
+//===============================================
+// Common routine
+//===============================================
+ void getKeyValue(char *keyReq);
+ int  setKeyValue(char *key, char *value);
+ int updateSetting(char *key, char *value);
+ int httpDownLoadFile(char *location, char *path, char *filename,char *url);
+ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url);
+ void *UpdateFirmwareProcess(void* data);
+ void* GetDiagnosticsProcess(void* data);
+ int httpUploadFile(char *location, char *path, char *filename,char *url);
+ int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
+ int get_file_contents(const char* filename, char** outbuffer);
+ //void Send(struct json_object *message);
+ void LWS_Send(char * str);
+extern int queue_operation(int type, char *frontUUID, char *frontData);
+char *GetOcppServerURL();
+char *GetOcppPath();
+int GetOcppPort();
+int GetTransactionId(int gunindex);
+void SetTransactionIdZero(int gunindex);
+void GetChargingProfileRequest(int gunindex);
+ //===============================================
+ // sqlite related routine
+ //===============================================
+ int SettingChargingRecord(int target, int transactionId);
+ int addBuff(int gun_idx, int user_id, int cmd_sn);
+ void OCPP_getListVerion();
+ int OCPP_cleanLocalList();
+ int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
+ int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status);
+ void OCPP_getIdTag(char *idTag);
+ void OCPP_deleteIdTag(char *idTag);
+
+#endif

+ 198 - 23
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -37,6 +37,7 @@
 #include	"sqlite3.h"
 
 
+
 #if 0
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -113,6 +114,12 @@ static int TransactionQueueNum = 0;
 static int  OfflineTransaction = 0;
 int defaultWaitingTime = 10; //10 second
 
+//===============================
+// OCPP SentQueue TransactionId
+//===============================
+static int SentQueueTransactionId[10]={0};
+
+
 extern int BootNotificationInterval;
 //char guid[37];
 //map_t hashMap;
@@ -396,9 +403,6 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			server_sign = FALSE;
 			break;
 		case LWS_CALLBACK_LOCK_POLL:
-			#ifdef SystemLogMessage
-			//DEBUG_INFO("LWS_CALLBACK_LOCK_POLL\n");
-			#endif
 			break;
 		case LWS_CALLBACK_ADD_POLL_FD:
 			#ifdef SystemLogMessage
@@ -411,14 +415,8 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			#endif
 			break;
 		case LWS_CALLBACK_UNLOCK_POLL:
-			#ifdef SystemLogMessage
-			//DEBUG_INFO("LWS_CALLBACK_UNLOCK_POLL\n");
-			#endif
 			break;
 		case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
-			#ifdef SystemLogMessage
-			//DEBUG_INFO("LWS_CALLBACK_CHANGE_MODE_POLL_FD\n");
-			#endif
 			break;
 		case LWS_CALLBACK_WSI_CREATE:
 			#ifdef SystemLogMessage
@@ -426,9 +424,6 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 			#endif
 			break;
 		case LWS_CALLBACK_GET_THREAD_ID:
-			//#ifdef SystemLogMessage
-			//DEBUG_INFO("LWS_CALLBACK_GET_THREAD_ID\n");
-			//#endif
 			break;
 		case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
 			#ifdef SystemLogMessage
@@ -607,7 +602,7 @@ int ConnectWsServer()
 
 	ConnInfo.port = GetOcppPort();
 
-	ConnInfo.path=(const char *)GetOcppPath();//"/ocpp/RDTEST103";//"/ocpp/OCTT_1";//"/RDTEST103";//"/0591201511030003";//"/RDTEST103";
+	ConnInfo.path=(const char *)GetOcppPath();
 	ConnInfo.host=lws_canonical_hostname(context);
 	ConnInfo.origin="origin";
 	ConnInfo.protocol = protocols[1].name;
@@ -691,10 +686,23 @@ if(fp == NULL) {
 	return FALSE;
 }
 
+if(fgetc(fp)==EOF)
+{
+	//DEBUG_INFO("It is end of file");
+	fclose(fp);
+	memset(rmFileCmd, 0, sizeof rmFileCmd);
+	sprintf(rmFileCmd,"rm -f %s","../Storage/OCPP/TransactionRelatedQueue");
+	system(rmFileCmd);
+	result = FALSE;
+
+	return result;
+}
+
 if( fgets (str, 1200, fp)!=NULL ) {
 	/* writing content to stdout */
+	//DEBUG_INFO("str=%s",str);
 
-	if (str[0] == '\n')
+	if ((str[0] == '\n')||(strcmp(str,"")==0))
 	{
 		DEBUG_INFO("It is a blank line");
 		fclose(fp);
@@ -707,7 +715,7 @@ if( fgets (str, 1200, fp)!=NULL ) {
 	}
 	else
 	{
-		 puts(str);
+		 //puts(str);
 		 /*********************uuid***************/
 		 loc = strstr(str, "\"");
 		 memset(sstr ,0, sizeof(sstr) );
@@ -802,6 +810,7 @@ char rmFileCmd[100]={0};
 struct stat stats;
 stat("../Storage/OCPP", &stats);
 
+DEBUG_INFO("delq()\n");
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
@@ -965,9 +974,20 @@ return 0;
 int sentqueue(){
 FILE *fp;
 int result = FALSE; // 1: TRUE  0:FALSE
+int temptransactionId = 0;
+int tempconnectorId = 0;
+int gunIndex = 0;
+char guid[37]={0};
+char tempdata[65]={0};
+char key_value[65]={0};
+int IsStopTransaction = FALSE;
 char str[1200]={0};
+char strcomposite[1200]={0};
 char rmFileCmd[100]={0};
 struct stat stats;
+char sstr[28]={ 0 };
+int c = 0;
+char *loc;
 
 DEBUG_INFO("sentqueue\n");
 stat("../Storage/OCPP", &stats);
@@ -994,11 +1014,153 @@ if(fp == NULL) {
 }
 
 if( fgets (str, 1200, fp)!=NULL ) {
+
 	/* writing content to stdout */
-	//puts(str);
-	//DEBUG_INFO("\n uuid:%s", "");
-	//DEBUG_INFO("\n data:%s", str);
-	LWS_Send(str);
+
+	//*********************StopTransaction***************************/
+	loc = strstr(str, "StopTransaction");
+	c = 0;
+	memset(sstr ,0, sizeof(sstr) );
+	if(loc != NULL)
+	{
+		IsStopTransaction = TRUE;
+    }
+
+
+	//*********************connectorId***************************/
+	loc = strstr(str, "connectorId");
+	c = 0;
+	memset(sstr ,0, sizeof(sstr) );
+	if(loc != NULL)
+	{
+		while (loc[strlen("connectorId")+2+c] != ',')
+		{
+			sstr[c] = loc[strlen("connectorId")+2+c];
+			c++;
+		}
+		sstr[c] = '\0';
+		tempconnectorId = atoi(sstr);
+
+		//DEBUG_INFO("\n tempconnectorId:%d\n", tempconnectorId);
+	}
+
+
+	//*********************StartTransaction***************************/
+	loc = strstr(str, "StartTransaction");
+	c = 0;
+	memset(sstr ,0, sizeof(sstr) );
+	if(loc != NULL)
+	{
+		//DEBUG_INFO("\n sent queue StartTransaction\n");
+		if(tempconnectorId > 0)
+		{
+			sprintf(tempdata, "StartTransaction,%d", (tempconnectorId-1));
+		}
+		else if(tempconnectorId == 0)
+		{
+			sprintf(tempdata, "StartTransaction,%d", 0);
+		}
+
+
+		memset(sstr ,0, sizeof(sstr) );
+		//DEBUG_INFO("\n 0-0. sent queue str=%s\n",str);
+
+		c=0;
+		while (str[4+c] != '\"')
+		{
+		  	sstr[c] = str[4+c];
+		  	c++;
+		}
+		sstr[c] = '\0';
+		strcpy(guid, sstr);
+		//DEBUG_INFO("\n 0. sent queue sstr=%s\n",sstr);
+
+
+
+		if(hashmap_operation(1, guid, key_value) == TRUE)
+		{
+			//DEBUG_INFO("\n 1. sent queue guid=%s\n",guid);
+		}
+		else
+		{
+			hashmap_operation(0, guid, tempdata);
+			//DEBUG_INFO("\n 2. sent queue guid=%s\n",guid);
+
+		}
+	}
+
+
+	//****************transactionId********************/
+	 c=0;
+	 loc = strstr(str, "transactionId");
+	 memset(sstr ,0, sizeof(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);
+		//puts(str);
+		//DEBUG_INFO("\n uuid:%s", "");
+		//DEBUG_INFO("\n data:%s", str);
+		if(IsStopTransaction == TRUE)
+		{
+			for(int i=0; i <10; i++)
+			{
+				//DEBUG_INFO("\n StopTransaction i:%d\n", i);
+				//DEBUG_INFO("\n StopTransaction SentQueueTransactionId[i]:%d\n", SentQueueTransactionId[i]);
+				//DEBUG_INFO("\n sStopTransaction temptransactionId:%d\n", temptransactionId);
+				if(SentQueueTransactionId[i] == temptransactionId)
+				{
+					tempconnectorId = i;
+					gunIndex = i;
+					break;
+				}
+
+
+			}
+		}
+		else
+		{
+			if(tempconnectorId > 0)
+			{
+				SentQueueTransactionId[tempconnectorId-1] = temptransactionId;
+				gunIndex = tempconnectorId-1;
+			}
+		}
+
+		//DEBUG_INFO("\n gunIndex=%d \n",gunIndex);
+		//DEBUG_INFO("\n temptransactionId=%d \n",temptransactionId);
+		//DEBUG_INFO("\n GetTransactionId(gunIndex)=%d \n",GetTransactionId(gunIndex));
+
+		if((GetTransactionId(gunIndex) != 0)&&(temptransactionId != GetTransactionId(gunIndex)))
+		{
+			strncpy(strcomposite,str, (loc-str)+2+strlen("transactionId"));
+			sprintf(strcomposite+((loc-str)+2+strlen("transactionId")),"%d",GetTransactionId(gunIndex));
+			strcat(strcomposite, loc+strlen("transactionId")+2+c);
+			LWS_Send(strcomposite);
+		}
+		else
+		{
+			LWS_Send(str);
+		}
+
+		if((IsStopTransaction == TRUE)&&(GetTransactionId(gunIndex) != 0))
+		{
+			SetTransactionIdZero(gunIndex);
+		}
+
+	 }
+	 else
+	 {
+		 LWS_Send(str);
+	 }
+
 	result = TRUE;
 	//return 1;
 }
@@ -1034,20 +1196,29 @@ void* processTransactionQueue(void* data) {
 			{
 				if((OfflineTransaction == 1) && (TransactionQueueNum != 0))
 				{
-					TransactionQueueInterval = 2;
+					TransactionQueueInterval = 10;//2;
 					sleep(TransactionQueueInterval);
 					sendbuffer = 1;
+					DEBUG_INFO("test 1\n");
 				}
 				else
 				{
 					OfflineTransaction = 0;
 					if(TransactionMessageResend < TransactionMessageAttemptsGet()) //
 					{
-						//DEBUG_INFO("processTransactionQueue queue is not empty!\n");
+						DEBUG_INFO("TransactionMessageResend=%d\n",TransactionMessageResend);
+						DEBUG_INFO("TransactionMessageAttemptsGet=%d\n",TransactionMessageAttemptsGet());
+						DEBUG_INFO("processTransactionQueue queue is not empty!\n");
+
 						TransactionQueueInterval= TransactionMessageRetryIntervalGet()* TransactionMessageResend;
-						sleep(TransactionQueueInterval);
+						DEBUG_INFO("TransactionQueueInterval =%d\n",TransactionQueueInterval);
 						sendbuffer = 1;
 						TransactionMessageResend = TransactionMessageResend + 1;
+						DEBUG_INFO("After ADD,TransactionMessageResend=%d\n",TransactionMessageResend);
+
+						sleep(TransactionQueueInterval);
+
+
 					}
 					else
 					{
@@ -1094,8 +1265,12 @@ void CheckTransactionPacket(char *uuid)
 
 		if (cmpResult == 0)
 		{
-			//DEBUG_INFO("TransactionPacket Compare All right!\n");
+			DEBUG_INFO("TransactionPacket Compare All right!\n");
+			DEBUG_INFO("frontUUID=%s\n",frontUUID);
+			DEBUG_INFO("uuid=%s\n",uuid);
 			queue_operation(2,"","");//delq(); ---> remove temporally
+			TransactionQueueInterval = 0;
+			TransactionMessageResend = 1;
 		}
 
 	}

+ 36 - 35
EVSE/Modularization/ocppfiles/hashmap.c

@@ -14,6 +14,7 @@
 #include <unistd.h>     /*Unix 標準函數定義*/
 #include "SystemLogMessage.h"
 
+
 typedef enum boolean { FALSE, TRUE } BOOL;
 static pthread_mutex_t m;
 
@@ -213,7 +214,7 @@ unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){
 
 	/* Knuth's Multiplicative Method */
 	key = (key >> 3) * 2654435761;
-	DEBUG_INFO("table_size=%d\n",hashMap[0].table_size);
+	printf("table_size=%d\n",hashMap[0].table_size);
 
 	return key % hashMap[0].table_size;//key % m->table_size;
 }
@@ -227,7 +228,7 @@ int hashmap_hash(map_t in, char* key){
 	int i;
 
 	/* If full, return immediately */
-	DEBUG_INFO("hashMap[0].table_size=%d\n",hashMap[0].table_size);
+	printf("hashMap[0].table_size=%d\n",hashMap[0].table_size);
 	if(hashMap[0].size >= (hashMap[0].table_size/2)) return MAP_FULL;
 
 	/* Find the best index */
@@ -237,14 +238,14 @@ int hashmap_hash(map_t in, char* key){
 	for(i = 0; i< MAX_CHAIN_LENGTH; i++){
 		if(hashMap[0].data[curr].in_use == 0)
 		{
-			DEBUG_INFO(" no in_use \n");
+			printf(" no in_use \n");
 			return curr;
 		}
 
 
 		if(hashMap[0].data[curr].in_use == 1 && (strcmp(hashMap[0].data[curr].key,key)==0))
 		{
-			DEBUG_INFO("key use, key exist!!!!\n");
+			printf("key use, key exist!!!!\n");
 			return curr;
 		}
 
@@ -354,7 +355,7 @@ int hashmap_put(map_t in, char* key, any_t value){
 		index = hashmap_hash(in, key);
 	}
 
-	DEBUG_INFO("hash index=%d\n",index);
+	printf("hash index=%d\n",index);
 	/* Set the data */
 	strcpy(hashMap[0].data[index].data, value);
 	strcpy(hashMap[0].data[index].key, key);
@@ -363,9 +364,9 @@ int hashmap_put(map_t in, char* key, any_t value){
 	hashMap[0].data[index].in_use = 1;
 	hashMap[0].size++;
 
-	DEBUG_INFO("hash m->data[index].data=%s\n",hashMap[0].data[index].data);
-	DEBUG_INFO("hash m->data[index].key=%s\n",hashMap[0].data[index].key);
-	DEBUG_INFO("hash m->data[index].in_use=%d\n",hashMap[0].data[index].in_use);
+	printf("hash m->data[index].data=%s\n",hashMap[0].data[index].data);
+	printf("hash m->data[index].key=%s\n",hashMap[0].data[index].key);
+	printf("hash m->data[index].in_use=%d\n",hashMap[0].data[index].in_use);
 
 	return MAP_OK;
 
@@ -410,26 +411,26 @@ int hashmap_get(map_t in, char* key, any_t *arg){
 
 	/* Find data location */
 	curr = hashmap_hash_int(hashMap, key);
-	DEBUG_INFO("MAP_get curr=%d\n",curr);
+	printf("MAP_get curr=%d\n",curr);
 
 	/* Linear probing, if necessary */
 	for(i = 0; i<MAX_CHAIN_LENGTH; i++){
 
 	        int in_use = hashMap[0].data[curr].in_use;
-	        DEBUG_INFO("MAP_get in use=%d\n",in_use);
+	        printf("MAP_get in use=%d\n",in_use);
 	        if (in_use == 1){
-	        	DEBUG_INFO("MAP_get hashMap.data[curr].key=%s\n", hashMap[0].data[curr].key);
-	        	DEBUG_INFO("MAP_get hashMap.data[curr].data=%s\n", hashMap[0].data[curr].data);
+	        	printf("MAP_get hashMap.data[curr].key=%s\n", hashMap[0].data[curr].key);
+	        	printf("MAP_get hashMap.data[curr].data=%s\n", hashMap[0].data[curr].data);
 	            if (strcmp(hashMap[0].data[curr].key,key)==0){
 	            	strcpy(arg, hashMap[0].data[curr].data);
 	                //*arg = (m->data[curr].data);
-	                DEBUG_INFO("MAP_OK curr=%d\n",curr);
+	                printf("MAP_OK curr=%d\n",curr);
 	                return MAP_OK;
 	            }
 			}
 
 			curr = (curr + 1) % hashMap[0].table_size;
-			DEBUG_INFO("MAP_MISSING curr=%d\n",curr);
+			printf("MAP_MISSING curr=%d\n",curr);
 	}
 
 	memset(arg, 0, sizeof arg);
@@ -530,11 +531,11 @@ int hashmap_remove(map_t in, char* key){
 	               // m->data[curr].data = NULL;
 	               // m->data[curr].key = NULL;
 
-	                DEBUG_INFO("remove m->size=%d \n",hashMap[0].size);
+	                printf("remove m->size=%d \n",hashMap[0].size);
 	                /* Reduce the size */
 	                hashMap[0].size--;
 
-	                DEBUG_INFO("remove ok!\n");
+	                printf("remove ok!\n");
 	                return MAP_OK;
 	            }
 			}
@@ -618,11 +619,11 @@ stat("../Storage/OCPP", &stats);
 // Check for directory existence
 if (S_ISDIR(stats.st_mode) == 1)
 {
-	//printf("directory exist \n");
+	//printf("\n directory exist \n");
 }
 else
 {
-	DEBUG_INFO("directory not exist, create dir \n");
+	printf("\n directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -635,12 +636,12 @@ if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
 }
 else
 {
-	DEBUG_INFO("MessageSent not exist\n");
+	printf("MessageSent not exist\n");
 	FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
 
 	if(log == NULL)
 	{
-		DEBUG_ERROR("Can't Create File MessageSent \n");
+		printf("Can't Create File MessageSent \n");
 		return 0;
 	}
 	else
@@ -654,7 +655,7 @@ outfile = fopen ("../Storage/OCPP/MessageSent", "a");
 sprintf(tempstring,"%s,%s\n", uuid,data);
 fputs(tempstring, outfile);
 fclose (outfile);
-DEBUG_INFO("MessageSent add\n");
+//printf("MessageSent add\n");
 return 1;
 }
 
@@ -674,11 +675,11 @@ int MessageSent_get(char *uuid, char *data)
 	// Check for directory existence
 	if (S_ISDIR(stats.st_mode) == 1)
 	{
-		//printf("directory exist \n");
+		//printf("\n directory exist \n");
 	}
 	else
 	{
-		DEBUG_INFO("directory not exist, create dir \n");
+		printf("\n directory not exist, create dir \n");
 		sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 		system(rmFileCmd);
 	}
@@ -691,12 +692,12 @@ int MessageSent_get(char *uuid, char *data)
 	}
 	else
 	{
-		DEBUG_INFO("MessageSent not exist\n");
+		printf("MessageSent not exist\n");
 		FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
 
 		if(log == NULL)
 		{
-			DEBUG_ERROR("Can't Create File MessageSent \n");
+			printf("Can't Create File MessageSent \n");
 			return 0;
 		}
 		else
@@ -709,7 +710,7 @@ int MessageSent_get(char *uuid, char *data)
 	/* opening file for reading */
 	fp = fopen("../Storage/OCPP/MessageSent" , "r");
 	if(fp == NULL) {
-		DEBUG_ERROR("Error opening file");
+		printf("Error opening file");
 		return FALSE;
 	}
 
@@ -719,7 +720,7 @@ int MessageSent_get(char *uuid, char *data)
 
 	if(c == EOF)
 	{
-		DEBUG_INFO("MessageSent is null\n");
+		printf("MessageSent is null\n");
 		//strcpy(uuid,"");
 		strcpy(data,"");
 		result = FALSE;
@@ -750,7 +751,7 @@ int MessageSent_get(char *uuid, char *data)
 
 			if(strcmp(sstr, uuid) == 0)
 			{
-				DEBUG_INFO("uuid:%s compare all right!!!\n", sstr);
+				//printf("\n uuid:%s compare all right!!! ", sstr);
 
 				loc = strstr(str, ",");
 				memset(sstr ,0, sizeof(sstr) );
@@ -762,7 +763,7 @@ int MessageSent_get(char *uuid, char *data)
 				}
 				datastr[e] = '\0';
 
-				DEBUG_INFO("data:%s\n", datastr);
+				//printf("\n data:%s", datastr);
 				//strcpy(uuid,sstr);
 				strcpy(data,datastr);
 				result = TRUE;
@@ -798,7 +799,7 @@ if (S_ISDIR(stats.st_mode) == 1)
 }
 else
 {
-	DEBUG_INFO("\n directory not exist, create dir \n");
+	printf("\n directory not exist, create dir \n");
 	sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
 	system(rmFileCmd);
 }
@@ -811,12 +812,12 @@ if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
 }
 else
 {
-	DEBUG_INFO("MessageSent not exist\n");
+	printf("MessageSent not exist\n");
 	FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
 
 	if(log == NULL)
 	{
-		DEBUG_ERROR("log is NULL\n");
+		printf("log is NULL\n");
 		return 0;
 	}
 	else
@@ -842,7 +843,7 @@ rewind(infile);
 
 if(c == EOF)
 {
-	DEBUG_INFO("MessageSent is  NULL\n");
+	printf("MessageSent is  NULL\n");
 
 	fclose(infile);
 	fclose(outfile);
@@ -890,7 +891,7 @@ else
 	}
 	else
 	{
-		DEBUG_ERROR("Error: unable to rename the file");
+		printf("Error: unable to rename the file");
 	}
 }
 
@@ -924,7 +925,7 @@ int hashmap_operation(int type, map_t in, char* key, any_t value, any_t *arg){
 int hashmap_operation(int type, char *uuid, char *data)
 {
 
-	pthread_mutex_init(&m,NULL);
+	//pthread_mutex_init(&m,NULL);
 	pthread_mutex_lock(&m);
 	int result=0;
 

+ 39 - 0
EVSE/Projects/define.h

@@ -190,6 +190,45 @@ enum OFF_LINE_POLICY
 	OFF_POLICY_NOCHARGE		= 3
 };
 
+/*Configuration enum*/
+enum CoreProfile {
+	 AllowOfflineTxForUnknownId=0,
+	 AuthorizationCacheEnabled,
+	 AuthorizeRemoteTxRequests,
+	 BlinkRepeat,
+	 ClockAlignedDataInterval,
+	 ConnectionTimeOut,
+	 GetConfigurationMaxKeys,
+	 HeartbeatInterval,
+	 LightIntensity,
+	 LocalAuthorizeOffline,
+	 LocalPreAuthorize,
+	 MaxEnergyOnInvalidId,
+	 MeterValuesAlignedData,
+	 MeterValuesAlignedDataMaxLength,
+	 MeterValuesSampledData,
+	 MeterValuesSampledDataMaxLength,
+	 MeterValueSampleInterval,
+	 MinimumStatusDuration,
+	 NumberOfConnectors,
+	 ResetRetries,
+	 ConnectorPhaseRotation,
+	 ConnectorPhaseRotationMaxLength,
+	 StopTransactionOnEVSideDisconnect,
+	 StopTransactionOnInvalidId,
+	 StopTxnAlignedData,
+	 StopTxnAlignedDataMaxLength,
+	 StopTxnSampledData,
+	 StopTxnSampledDataMaxLength,
+	 SupportedFeatureProfiles,
+	 SupportedFeatureProfilesMaxLength,
+	 TransactionMessageAttempts,
+	 TransactionMessageRetryInterval,
+	 UnlockConnectorOnEVSideDisconnect,
+	 WebSocketPingInterval,
+	 _CoreProfile_CNT
+};
+
 
 /**************************************************************************************/
 /****structure SysConfigData => shall store the data to NAND flash****************/