Просмотр исходного кода

[Improve][Modularization][Module_OcppBackend]

2020.11.13 / Folus Wen

Actions:
1. EVSE/Projects/define.h add cost strcut to struct OCPP16Data for pricing & cost.
2. EVSE/Modularization/ocppfiles/MessageHandler.c implement california pricing related message.

Files:
1. As follow commit history

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

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 лет назад
Родитель
Сommit
e7f3b32381
2 измененных файлов с 210 добавлено и 149 удалено
  1. 44 4
      EVSE/Modularization/ocppfiles/MessageHandler.c
  2. 166 145
      EVSE/Projects/define.h

+ 44 - 4
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -7482,11 +7482,19 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			data = json_tokener_parse(tempdata);
 			if(!is_error(data))
 			{
+				memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
+
 				if(json_object_object_get(data, "idToken") != NULL)
+				{
+					sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
 					DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
+				}
 
 				if(json_object_object_get(data, "price") != NULL)
+				{
+					sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
 					DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
+				}
 
 				json_object_object_add(response, "status", json_object_new_string("Accepted"));
 			}
@@ -7497,6 +7505,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			}
 			json_object_put(data);
 
+			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, "RunningCost") != NULL)
@@ -7506,10 +7515,25 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			if(!is_error(data))
 			{
 				if(json_object_object_get(data, "txId") != NULL)
+				{
+					DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
+
+					for(int idx = 0;idx<gunTotalNumber;idx++)
+					{
+						if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
+						{
+							memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
 
-				if(json_object_object_get(data, "description") != NULL)
-					DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
+							ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
 
+							if(json_object_object_get(data, "description") != NULL)
+							{
+								DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
+								sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
+							}
+						}
+					}
+				}
 				json_object_object_add(response, "status", json_object_new_string("Accepted"));
 			}
 			else
@@ -7519,6 +7543,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			}
 			json_object_put(data);
 
+			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, "FinalCost") != NULL)
@@ -7528,11 +7553,25 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			if(!is_error(data))
 			{
 				if(json_object_object_get(data, "txId") != NULL)
+				{
 					DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
 
-				if(json_object_object_get(data, "description") != NULL)
-					DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
+					for(int idx = 0;idx<gunTotalNumber;idx++)
+					{
+						if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
+						{
+							memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
+
+							ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
 
+							if(json_object_object_get(data, "description") != NULL)
+							{
+								DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
+								sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
+							}
+						}
+					}
+				}
 				json_object_object_add(response, "status", json_object_new_string("Accepted"));
 			}
 			else
@@ -7542,6 +7581,7 @@ int handleDataTransferRequest(char *uuid, char *payload)
 			}
 			json_object_put(data);
 
+			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

+ 166 - 145
EVSE/Projects/define.h

@@ -4012,153 +4012,174 @@ struct OCPP16ConfigurationTable
 	struct OCPP16ConfigurationItem 			SmartChargingProfile[5];
 };
 
+
+struct StrcutSetUserPrice
+{
+	unsigned char 	idToken[20];
+	unsigned char	price[256];
+};
+
+struct StrcutRunningFinalCost
+{
+	int 			txId;
+	unsigned char	description[256];
+};
+
+struct StructCost
+{
+	struct StrcutSetUserPrice		SetUserPrice;
+	struct StrcutRunningFinalCost	RunningCost[CONNECTOR_QUANTITY];
+	struct StrcutRunningFinalCost	FinalCost[CONNECTOR_QUANTITY];
+};
+
 struct OCPP16Data
 {
-        unsigned char                           OcppServerURL[512];     //http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
-        unsigned char                           ChargeBoxId[128];
-        unsigned char                           OcppConnStatus;         //0: disconnected, 1: connected
-        unsigned int                            Timeout_Secs;
-        unsigned short                          Ping_Pong_Interval;
-        union
-        {
-            //Operations Initiated by Charge Point
-            unsigned char CpMsgValue[CONNECTOR_QUANTITY];
-            struct
-            {
-                //CpMsgValue[0]
-                unsigned char DataTransferReq:1;        //bit 0,
-                unsigned char DataTransferConf:1;       //bit 1,
-                unsigned char StartTransactionReq:1;    //bit 2,
-                unsigned char StartTransactionConf:1;   //bit 3,
-                unsigned char StopTransactionReq:1;     //bit 4,
-                unsigned char StopTransactionConf:1;    //bit 5,
-                unsigned char :2;                       //bit 6,7 , reserved
-            } bits[CONNECTOR_QUANTITY];
-        }CpMsg;
-
-        union
-        {
-            //Operations Initiated by Sequence Point
-            unsigned char SpMsgValue[1];
-            struct
-            {
-                //SpMsgValue[0]
-                unsigned char BootNotificationReq :1;               //bit 0,
-                unsigned char BootNotificationConf :1;              //bit 1,
-                unsigned char AuthorizeReq :1;                      //bit 2,
-                unsigned char AuthorizeConf :1;                     //bit 3,
-                unsigned char DiagnosticsStatusNotificationReq :1;  //bit 4,
-                unsigned char DiagnosticsStatusNotificationConf :1; //bit 5,
-                unsigned char FirmwareStatusNotificationReq :1;     //bit 6,
-                unsigned char FirmwareStatusNotificationConf :1;    //bit 7,
-            } bits;
-        } SpMsg;
-
-        union
-        {
-            //Operations Initiated by Central System
-            unsigned char CsMsgValue[3 * (CONNECTOR_QUANTITY)];
-            struct
-            {
-                //CsMsgValue[0]
-                unsigned char CancelReservationReq :1;      //bit 0,
-                unsigned char CancelReservationConf :1;     //bit 1,
-                unsigned char ChangeAvailabilityReq :1;     //bit 2,
-                unsigned char ChangeAvailabilityConf :1;    //bit 3,
-                unsigned char ReserveNowReq :1;             //bit 4,
-                unsigned char ReserveNowConf :1;            //bit 5,
-                unsigned char SetChargingProfileReq :1;     //bit 6,
-                unsigned char SetChargingProfileConf :1;    //bit 7,
-                //CsMsgValue[1]
-                unsigned char TriggerMessageReq :1;         //bit 0,
-                unsigned char TriggerMessageConf :1;        //bit 1,
-                unsigned char UnlockConnectorReq :1;        //bit 2,
-                unsigned char UnlockConnectorConf :1;       //bit 3,
-                unsigned char RemoteStartTransactionReq :1; //bit 4,
-                unsigned char RemoteStartTransactionConf :1;//bit 5,
-                unsigned char RemoteStopTransactionReq :1;  //bit 6,
-                unsigned char RemoteStopTransactionConf :1; //bit 7,
-                //CsMsgValue[2]
-                unsigned char ClearChargingProfileReq :1;   //bit 0,
-                unsigned char ClearChargingProfileConf :1;  //bit 1,
-                unsigned char DataTransferReq :1;           //bit 2,
-                unsigned char DataTransferConf :1;          //bit 3,
-                unsigned char GetCompositeScheduleReq :1;   //bit 4,
-                unsigned char GetCompositeScheduleConf :1;  //bit 5,
-                unsigned char :2;                           //bit 6,7
-            } bits[CONNECTOR_QUANTITY];
-        }CsMsg;
-
-        union
-        {
-            //Operations Initiated by Main System
-            unsigned char MsMsgValue[2];
-            struct
-            {
-                //CsMsgValue[0]
-                unsigned char ChangeConfigurationReq :1;    //bit 0,
-                unsigned char ChangeConfigurationConf :1;   //bit 1,
-                unsigned char ClearCacheReq :1;             //bit 2,
-                unsigned char ClearCacheConf :1;            //bit 3,
-                unsigned char GetConfigurationReq :1;       //bit 4,
-                unsigned char GetConfigurationConf :1;      //bit 5,
-                unsigned char UpdateFirmwareReq :1;         //bit 6,
-                unsigned char UpdateFirmwareConf :1;        //bit 7,
-                //CsMsgValue[1]
-                unsigned char GetDiagnosticsReq :1;         //bit 0,
-                unsigned char GetDiagnosticsConf :1;        //bit 1,
-                unsigned char GetLocalListVersionReq :1;    //bit 2,
-                unsigned char GetLocalListVersionConf :1;   //bit 3,
-                unsigned char ResetReq :1;                  //bit 4,
-                unsigned char ResetConf :1;                 //bit 5,
-                unsigned char SendLocalListReq :1;          //bit 6,
-                unsigned char SendLocalListConf :1;         //bit 7,
-            } bits;
-        } MsMsg;
-
-        union
-        {
-            //Operations triggered by CSU
-            unsigned char CSUMsgValue[CONNECTOR_QUANTITY];
-            struct
-            {
-                //CSUMsgValue[0]
-                unsigned char ChargingProfileReq:1;     //bit 0,
-                unsigned char ChargingProfileConf:1;    //bit 0,
-                unsigned char :6;                       //bit 1,2,3,4,5,6,7 , reserved
-            } bits[CONNECTOR_QUANTITY];
-        }CSUMsg;
-
-		struct StructBootNotification               BootNotification;
-		struct StructHeartbeat                      Heartbeat;
-		struct StructAuthorize                      Authorize;
-		struct StructStartTransaction               StartTransaction[CONNECTOR_QUANTITY];
-		struct StructStopTransaction                StopTransaction[CONNECTOR_QUANTITY];
-		struct StructStatusNotification             StatusNotification[CONNECTOR_QUANTITY];
-		struct StructCancelReservation              CancelReservation[CONNECTOR_QUANTITY];
-		struct StructChangeAvailability             ChangeAvailability[CONNECTOR_QUANTITY];
-		struct StructChangeConfiguration            ChangeConfiguration;
-		struct StructClearCache                     ClearCache;
-		struct StructClearChargingProfile           ClearChargingProfile[CONNECTOR_QUANTITY];
-		struct StructDataTransfer                   DataTransfer[CONNECTOR_QUANTITY];
-		struct StructDiagnosticsStatusNotification  DiagnosticsStatusNotification;
-		struct StructFirmwareStatusNotification     FirmwareStatusNotification;
-		struct StructGetCompositeSchedule           GetCompositeSchedule[CONNECTOR_QUANTITY];
-		struct StructGetConfiguration               GetConfiguration;
-		struct StructGetDiagnostics                 GetDiagnostics;
-		struct StructGetLocalListVersion            GetLocalListVersion;
-		struct StructMeterValues                    MeterValues[CONNECTOR_QUANTITY];
-		struct StructRemoteStartTransaction         RemoteStartTransaction[CONNECTOR_QUANTITY];
-		struct StructRemoteStopTransaction          RemoteStopTransaction[CONNECTOR_QUANTITY];
-		struct StructReserveNow                     ReserveNow[CONNECTOR_QUANTITY];
-		struct StructReset                          Reset;
-		struct StructSendLocalList                  SendLocalList;
-		struct StructSetChargingProfile             SetChargingProfile[CONNECTOR_QUANTITY];
-		struct StructTriggerMessage                 TriggerMessage[CONNECTOR_QUANTITY];
-		struct StructUnlockConnector                UnlockConnector[CONNECTOR_QUANTITY];
-		struct StructUpdateFirmware                 UpdateFirmware;
-		struct OCPP16ConfigurationTable             ConfigurationTable;
-		struct StructChargingProfile                SmartChargingProfile[CONNECTOR_QUANTITY];
+	unsigned char                           OcppServerURL[512];     //http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
+	unsigned char                           ChargeBoxId[128];
+	unsigned char                           OcppConnStatus;         //0: disconnected, 1: connected
+	unsigned int                            Timeout_Secs;
+	unsigned short                          Ping_Pong_Interval;
+	union
+	{
+		//Operations Initiated by Charge Point
+		unsigned char CpMsgValue[CONNECTOR_QUANTITY];
+		struct
+		{
+			//CpMsgValue[0]
+			unsigned char DataTransferReq:1;        //bit 0,
+			unsigned char DataTransferConf:1;       //bit 1,
+			unsigned char StartTransactionReq:1;    //bit 2,
+			unsigned char StartTransactionConf:1;   //bit 3,
+			unsigned char StopTransactionReq:1;     //bit 4,
+			unsigned char StopTransactionConf:1;    //bit 5,
+			unsigned char :2;                       //bit 6,7 , reserved
+		} bits[CONNECTOR_QUANTITY];
+	}CpMsg;
+
+	union
+	{
+		//Operations Initiated by Sequence Point
+		unsigned char SpMsgValue[1];
+		struct
+		{
+			//SpMsgValue[0]
+			unsigned char BootNotificationReq :1;               //bit 0,
+			unsigned char BootNotificationConf :1;              //bit 1,
+			unsigned char AuthorizeReq :1;                      //bit 2,
+			unsigned char AuthorizeConf :1;                     //bit 3,
+			unsigned char DiagnosticsStatusNotificationReq :1;  //bit 4,
+			unsigned char DiagnosticsStatusNotificationConf :1; //bit 5,
+			unsigned char FirmwareStatusNotificationReq :1;     //bit 6,
+			unsigned char FirmwareStatusNotificationConf :1;    //bit 7,
+		} bits;
+	} SpMsg;
+
+	union
+	{
+		//Operations Initiated by Central System
+		unsigned char CsMsgValue[3 * (CONNECTOR_QUANTITY)];
+		struct
+		{
+			//CsMsgValue[0]
+			unsigned char CancelReservationReq :1;      //bit 0,
+			unsigned char CancelReservationConf :1;     //bit 1,
+			unsigned char ChangeAvailabilityReq :1;     //bit 2,
+			unsigned char ChangeAvailabilityConf :1;    //bit 3,
+			unsigned char ReserveNowReq :1;             //bit 4,
+			unsigned char ReserveNowConf :1;            //bit 5,
+			unsigned char SetChargingProfileReq :1;     //bit 6,
+			unsigned char SetChargingProfileConf :1;    //bit 7,
+			//CsMsgValue[1]
+			unsigned char TriggerMessageReq :1;         //bit 0,
+			unsigned char TriggerMessageConf :1;        //bit 1,
+			unsigned char UnlockConnectorReq :1;        //bit 2,
+			unsigned char UnlockConnectorConf :1;       //bit 3,
+			unsigned char RemoteStartTransactionReq :1; //bit 4,
+			unsigned char RemoteStartTransactionConf :1;//bit 5,
+			unsigned char RemoteStopTransactionReq :1;  //bit 6,
+			unsigned char RemoteStopTransactionConf :1; //bit 7,
+			//CsMsgValue[2]
+			unsigned char ClearChargingProfileReq :1;   //bit 0,
+			unsigned char ClearChargingProfileConf :1;  //bit 1,
+			unsigned char DataTransferReq :1;           //bit 2,
+			unsigned char DataTransferConf :1;          //bit 3,
+			unsigned char GetCompositeScheduleReq :1;   //bit 4,
+			unsigned char GetCompositeScheduleConf :1;  //bit 5,
+			unsigned char :2;                           //bit 6,7
+		} bits[CONNECTOR_QUANTITY];
+	}CsMsg;
+
+	union
+	{
+		//Operations Initiated by Main System
+		unsigned char MsMsgValue[2];
+		struct
+		{
+			//CsMsgValue[0]
+			unsigned char ChangeConfigurationReq :1;    //bit 0,
+			unsigned char ChangeConfigurationConf :1;   //bit 1,
+			unsigned char ClearCacheReq :1;             //bit 2,
+			unsigned char ClearCacheConf :1;            //bit 3,
+			unsigned char GetConfigurationReq :1;       //bit 4,
+			unsigned char GetConfigurationConf :1;      //bit 5,
+			unsigned char UpdateFirmwareReq :1;         //bit 6,
+			unsigned char UpdateFirmwareConf :1;        //bit 7,
+			//CsMsgValue[1]
+			unsigned char GetDiagnosticsReq :1;         //bit 0,
+			unsigned char GetDiagnosticsConf :1;        //bit 1,
+			unsigned char GetLocalListVersionReq :1;    //bit 2,
+			unsigned char GetLocalListVersionConf :1;   //bit 3,
+			unsigned char ResetReq :1;                  //bit 4,
+			unsigned char ResetConf :1;                 //bit 5,
+			unsigned char SendLocalListReq :1;          //bit 6,
+			unsigned char SendLocalListConf :1;         //bit 7,
+		} bits;
+	} MsMsg;
+
+	union
+	{
+		//Operations triggered by CSU
+		unsigned char CSUMsgValue[CONNECTOR_QUANTITY];
+		struct
+		{
+			//CSUMsgValue[0]
+			unsigned char ChargingProfileReq:1;     //bit 0,
+			unsigned char ChargingProfileConf:1;    //bit 0,
+			unsigned char :6;                       //bit 1,2,3,4,5,6,7 , reserved
+		} bits[CONNECTOR_QUANTITY];
+	}CSUMsg;
+
+	struct StructBootNotification               BootNotification;
+	struct StructHeartbeat                      Heartbeat;
+	struct StructAuthorize                      Authorize;
+	struct StructStartTransaction               StartTransaction[CONNECTOR_QUANTITY];
+	struct StructStopTransaction                StopTransaction[CONNECTOR_QUANTITY];
+	struct StructStatusNotification             StatusNotification[CONNECTOR_QUANTITY];
+	struct StructCancelReservation              CancelReservation[CONNECTOR_QUANTITY];
+	struct StructChangeAvailability             ChangeAvailability[CONNECTOR_QUANTITY];
+	struct StructChangeConfiguration            ChangeConfiguration;
+	struct StructClearCache                     ClearCache;
+	struct StructClearChargingProfile           ClearChargingProfile[CONNECTOR_QUANTITY];
+	struct StructDataTransfer                   DataTransfer[CONNECTOR_QUANTITY];
+	struct StructDiagnosticsStatusNotification  DiagnosticsStatusNotification;
+	struct StructFirmwareStatusNotification     FirmwareStatusNotification;
+	struct StructGetCompositeSchedule           GetCompositeSchedule[CONNECTOR_QUANTITY];
+	struct StructGetConfiguration               GetConfiguration;
+	struct StructGetDiagnostics                 GetDiagnostics;
+	struct StructGetLocalListVersion            GetLocalListVersion;
+	struct StructMeterValues                    MeterValues[CONNECTOR_QUANTITY];
+	struct StructRemoteStartTransaction         RemoteStartTransaction[CONNECTOR_QUANTITY];
+	struct StructRemoteStopTransaction          RemoteStopTransaction[CONNECTOR_QUANTITY];
+	struct StructReserveNow                     ReserveNow[CONNECTOR_QUANTITY];
+	struct StructReset                          Reset;
+	struct StructSendLocalList                  SendLocalList;
+	struct StructSetChargingProfile             SetChargingProfile[CONNECTOR_QUANTITY];
+	struct StructTriggerMessage                 TriggerMessage[CONNECTOR_QUANTITY];
+	struct StructUnlockConnector                UnlockConnector[CONNECTOR_QUANTITY];
+	struct StructUpdateFirmware                 UpdateFirmware;
+	struct OCPP16ConfigurationTable             ConfigurationTable;
+	struct StructChargingProfile                SmartChargingProfile[CONNECTOR_QUANTITY];
+	struct StructCost							Cost;
 };