Files
CCU621M/app/plat_comm/ocpp/bs_ocpp_json_data.c
T

1446 lines
51 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "plat_comm/ocpp/bs_ocpp_json_data.h"
#include "plat_comm/plat_comm_task.h"
#if BS_OCPP_EN //OCPP平台使能
const char ocpp_str_null[] = "str_null";
const char ocpp_cmd_str[][30] = {
"null",
"BootNotification", //引导通知 桩->平台
"StatusNotification", //状态通知 桩->平台
"Heartbeat", //心跳 桩->平台
"Authorize", //授权 桩->平台
"MeterValues", //采样信息上传 桩->平台
"StartTransaction", //充电准备通知 桩->平台
"StopTransaction", //停止充电 桩->平台
"RemoteStartTransaction",//平台下发启动充电 平台->桩
"RemoteStopTransaction", //平台下发停止充电 平台->桩
"UnlockConnector", //解枪锁 平台->桩
"UpdateFirmware", //固件升级 平台->桩
"Reset", //重启 平台->桩
"CancelReservation", //取消已经预定的充电桩 平台->桩
"ChangeAvailability", //设置枪可用状态 平台->桩
"ChangeConfiguration", //更改参数配置 平台->桩
"TriggerMessage", //平台下发数据召测 平台->桩
"GetConfiguration", //平台获取参数配置 平台->桩
"ClearCache", //清楚桩内缓存 一般为白名单 平台->桩
"SendLocalList", //平台下发本地缓存列表
"GetLocalListVersion", //获取卡号版本
"GetDiagnostics", //获取诊断日志文件
"DiagnosticsStatusNotification", /* 诊断上传状态 桩->平台 */
"FirmwareStatusNotification" /* 固件升级状态 桩->平台 */
};
//状态错误信息
const char *StatusNotification_ocpp_errorCode[] = {
"ConnectorLockFailure", //连接器锁定故障
"EVCommunicationError", //EV通讯故障
"GroundFailure", //接地故障
"HighTemperature", //高温
"InternalError", //内部错误
"LocalListConflict", //本地列表冲突
"NoError", //无错误
"OtherError", //其他错误
"OverCurrentFailure", //过电流故障
"PowerMeterFailure", //功率表故障
"PowerSwitchFailure", //电源开关故障
"ReaderFailure", //读卡器故障
"ResetFailure", //重置失败
"UnderVoltage", //电压过低
"OverVoltage", //电压过高
"WeakSignal" //信号弱
};
//状态信息
const char *StatusNotification_statusCode[] = {
"Available", //空闲
"Preparing", //准备
"Charging", //充电
"SuspendedEVSE", //暂停EVSE
"SuspendedEV", //暂停EV
"Finishing", //完成
"Reserved", //预留
"Unavailable", //不空闲
"Faulted" //故障
};
//平台启动充电 应答回复
const char *RemoteStartTransactionResponse_statusCode[] = {
"Accepted", //接受,
"Rejected" //拒绝
};
//平台停止充电 应答回复
const char *StopTransactionRequest_reason[] = {
"EmergencyStop", //紧急停止
"EVDisconnected", //电动汽车断开连接
"HardReset", //硬重置
"Local", //本地操作
"Other", //其他原因
"PowerLoss", //断电
"Reboot", //重启
"Remote", //远程操作
"SoftReset", //软重置
"UnlockCommand", //解锁命令
"DeAuthorized" //取消授权
};
//接枪锁 应答回复
const char *UnlockConnectorResponse_stateCode[] = {
"Unlocked",
"UnlockFailed",
"NotSupported"
};
/* DiagnosticsStatusNotification.status:与 BS_ocpp_ctrl.h 中 OCPP_DIAG_NOTIFY_PENDING_E 取值一致 */
const char *DiagnosticsStatusNotification_status[] = {
"Idle",
"Uploading",
"Uploaded",
"UploadFailed"
};
/* FirmwareStatusNotification.status:与 BS_ocpp_ctrl.h 中 OCPP_FW_NOTIFY_PENDING_E 取值一致 */
const char *FirmwareStatusNotification_status[] = {
"Idle", //空闲
"Downloading", //下载中
"Downloaded", //下载完成
"Installing", //安装中
"Installed", //安装完成
"DownloadFailed", //下载失败
"InstallationFailed" //安装失败
};
#if 1 //发送组帧
cJSON* BootNotification_json(BootNotificationRequest *json_data)
{
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "chargePointVendor", json_data->chargePointVendor);
cJSON_AddStringToObject(body, "chargePointModel", json_data->chargePointModel);
//选择项
if(strlen(json_data->chargePointSerialNumber) != 0)
cJSON_AddStringToObject(body, "chargePointSerialNumber", json_data->chargePointSerialNumber);
if(strlen(json_data->chargeBoxSerialNumber) != 0)
cJSON_AddStringToObject(body, "chargeBoxSerialNumber", json_data->chargeBoxSerialNumber);
if(strlen(json_data->firmwareVersion) != 0)
cJSON_AddStringToObject(body, "firmwareVersion", json_data->firmwareVersion);
if(strlen(json_data->iccid) != 0)
cJSON_AddStringToObject(body, "iccid", json_data->iccid);
if(strlen(json_data->imsi) != 0)
cJSON_AddStringToObject(body, "imsi", json_data->imsi);
if(strlen(json_data->meterType) != 0)
cJSON_AddStringToObject(body, "meterType", json_data->meterType);
if(strlen(json_data->meterSerialNumber) != 0)
cJSON_AddStringToObject(body, "meterSerialNumber", json_data->meterSerialNumber);
return body;
}
cJSON* StatusNotification_json(StatusNotificationRequest *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddNumberToObject(body, "connectorId", json_data->connectorId);//连接器ID
cJSON_AddStringToObject(body, "errorCode", json_data->errorCode);
cJSON_AddStringToObject(body, "status", json_data->status);
//可选(OCPP 1.6info 非 required;无有效字符串时不输出键,禁止字面量 "null"
if (strlen(json_data->info) != 0 && strcmp(json_data->info, "null") != 0)
cJSON_AddStringToObject(body, "info", json_data->info);
if(strlen(json_data->timestamp) != 0)
cJSON_AddStringToObject(body, "timestamp", json_data->timestamp);
if(strlen(json_data->vendorId) != 0)
cJSON_AddStringToObject(body, "vendorId", json_data->vendorId);
if(strlen(json_data->vendorErrorCode) != 0)
cJSON_AddStringToObject(body, "vendorErrorCode", json_data->vendorErrorCode);
return body;
}
cJSON* MeterValues_json(MeterValuesRequest *json_data){
int i,k;
cJSON* body,*meterValueArray,*meterValueItem ,*sampledValueArray,*sampledValueItem;
//必须项
body = cJSON_CreateObject();
cJSON_AddNumberToObject(body, "connectorId", json_data->connectorId);//连接器ID
cJSON_AddNumberToObject(body, "transactionId", json_data->transactionId);//可选 当前充电事务的唯一标识符。这是可选字段,只有在当前有正在进行的充电事务时才有值。
meterValueArray = cJSON_CreateArray(); //创建 meterValue 数组
cJSON_AddItemToObject(body,"meterValue", meterValueArray);
for (k = 0; k < MeterValuesRequest_MV_NUM; k++)
{
if(strlen(json_data->meterValue[k].timestamp) == 0)
break;
meterValueItem = cJSON_CreateObject(); //向 meterValue 数组添加一个对象(含 timestamp 和 sampledValue
cJSON_AddItemToArray(meterValueArray, meterValueItem);
cJSON_AddStringToObject(meterValueItem, "timestamp", json_data->meterValue[k].timestamp);
sampledValueArray = cJSON_CreateArray();
cJSON_AddItemToObject(meterValueItem, "sampledValue", sampledValueArray);
for (i = 0; i < MeterValuesRequest_SV_NUM; i++)
{
if(strlen(json_data->meterValue[k].sampledValue[i].value) == 0)
break;
sampledValueItem = cJSON_CreateObject();
cJSON_AddItemToArray(sampledValueArray, sampledValueItem);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].value) != 0)
cJSON_AddStringToObject(sampledValueItem, "value", json_data->meterValue[k].sampledValue[i].value);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].context) != 0)
cJSON_AddStringToObject(sampledValueItem, "context", json_data->meterValue[k].sampledValue[i].context);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].format) != 0)
cJSON_AddStringToObject(sampledValueItem, "format", json_data->meterValue[k].sampledValue[i].format);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].measurand) != 0)
cJSON_AddStringToObject(sampledValueItem, "measurand", json_data->meterValue[k].sampledValue[i].measurand);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].phase) != 0)
cJSON_AddStringToObject(sampledValueItem, "phase", json_data->meterValue[k].sampledValue[i].phase);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].location) != 0)
cJSON_AddStringToObject(sampledValueItem, "location", json_data->meterValue[k].sampledValue[i].location);
if(strlen((char *)json_data->meterValue[k].sampledValue[i].unit) != 0)
cJSON_AddStringToObject(sampledValueItem, "unit", json_data->meterValue[k].sampledValue[i].unit);
}
}
return body;
}
cJSON* RemoteStartTransaction_json(RemoteStartTransactionResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* RemoteStopTransaction_json(RemoteStopTransactionResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* StartTransaction_json(StartTransactionRequest *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddNumberToObject(body, "connectorId", json_data->connectorId);
cJSON_AddNumberToObject(body, "meterStart", json_data->meterStart);
cJSON_AddStringToObject(body, "idTag", json_data->idTag);
cJSON_AddStringToObject(body, "timestamp", json_data->timestamp);
//可选
if(json_data->reservationId != 0)
cJSON_AddNumberToObject(body, "reservationId", json_data->reservationId);
return body;
}
cJSON* StopTransaction_json(StopTransactionRequest *json_data){
int i,k;
cJSON *body,*transactionDataArray,*transactionDataTtem,*sampledValueArray,*sampledValueItem;
//必须项
body = cJSON_CreateObject();
cJSON_AddNumberToObject(body, "meterStop", json_data->meterStop);
cJSON_AddNumberToObject(body, "transactionId", json_data->transactionId);
cJSON_AddStringToObject(body, "timestamp", json_data->timestamp);
//可选
cJSON_AddStringToObject(body, "idTag", json_data->idTag);
cJSON_AddStringToObject(body, "reason", json_data->reason);
//return body;
transactionDataArray = cJSON_CreateArray(); //创建 数组
cJSON_AddItemToObject(body,"transactionData", transactionDataArray);
for (k = 0; k < StopTransactionRequest_TD_NUM; k++)
{
if(strlen(json_data->transactionData[k].timestamp) == 0)
break;
transactionDataTtem = cJSON_CreateObject(); //向 meterValue 数组添加一个对象(含 timestamp 和 sampledValue
cJSON_AddItemToArray(transactionDataArray, transactionDataTtem);
cJSON_AddStringToObject(transactionDataTtem, "timestamp", json_data->transactionData[k].timestamp);
sampledValueArray = cJSON_CreateArray();
cJSON_AddItemToObject(transactionDataTtem, "sampledValue", sampledValueArray);
for (i = 0; i < StopTransactionRequest_SV_NUM; i++)
{
if(strlen(json_data->transactionData[k].sampledValue[i].value) == 0)
break;
sampledValueItem = cJSON_CreateObject();
cJSON_AddItemToArray(sampledValueArray, sampledValueItem);
cJSON_AddStringToObject(sampledValueItem, "value", json_data->transactionData[k].sampledValue[i].value);
if(strlen(json_data->transactionData[k].sampledValue[i].context) != 0)
cJSON_AddStringToObject(sampledValueItem, "context", json_data->transactionData[k].sampledValue[i].context);
if(strlen(json_data->transactionData[k].sampledValue[i].format) != 0)
cJSON_AddStringToObject(sampledValueItem, "format", json_data->transactionData[k].sampledValue[i].format);
if(strlen(json_data->transactionData[k].sampledValue[i].measurand) != 0)
cJSON_AddStringToObject(sampledValueItem, "measurand", json_data->transactionData[k].sampledValue[i].measurand);
if(strlen(json_data->transactionData[k].sampledValue[i].phase) != 0)
cJSON_AddStringToObject(sampledValueItem, "phase", json_data->transactionData[k].sampledValue[i].phase);
if(strlen(json_data->transactionData[k].sampledValue[i].location) != 0)
cJSON_AddStringToObject(sampledValueItem, "location", json_data->transactionData[k].sampledValue[i].location);
if(strlen(json_data->transactionData[k].sampledValue[i].unit) != 0)
cJSON_AddStringToObject(sampledValueItem, "unit", json_data->transactionData[k].sampledValue[i].unit);
}
}
return body;
}
cJSON* Authorize_json(AuthorizeRequest *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "idTag", json_data->idTag);
//可选
return body;
}
cJSON* UnlockConnector_json(UnlockConnectorResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
return body;
}
cJSON* UpdateFirmware_json(){
cJSON* body;
//必须项
body = cJSON_CreateObject();
return body;
}
cJSON* Reset_json(ResetResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* CancelReservation_json(CancelReservationResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* ChangeAvailability_json(ChangeAvailabilityResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* ChangeConfiguration_json(ChangeConfigurationResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* TriggerMessage_json(TriggerMessageResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* GetConfiguration_json(GetConfigurationResponse *json_data){
cJSON* body,*unknownKeyArray,*configurationKeyArry,*configurationKeyItem;
int k;
//必须项
body = cJSON_CreateObject();
unknownKeyArray = cJSON_CreateArray(); //创建 meterValue 数组
cJSON_AddItemToObject(body,"unknownKey", unknownKeyArray);
for (k = 0; k < GetConfiguration_NUM; k++)
{
if(strlen(json_data->unknownKey[k]) == 0)
break;
cJSON_AddItemToArray(unknownKeyArray, cJSON_CreateString(json_data->unknownKey[k]));
}
configurationKeyArry = cJSON_CreateArray(); //创建 meterValue 数组
cJSON_AddItemToObject(body,"configurationKey", configurationKeyArry);
for (k = 0; k < GetConfiguration_NUM; k++)
{
if(strlen(json_data->configurationKey[k].key) == 0)
break;
configurationKeyItem = cJSON_CreateObject();
cJSON_AddItemToArray(configurationKeyArry, configurationKeyItem);
cJSON_AddStringToObject(configurationKeyItem,"key", json_data->configurationKey[k].key);
cJSON_AddBoolToObject(configurationKeyItem,"readonly", json_data->configurationKey[k].readonly ? 1 : 0);
cJSON_AddStringToObject(configurationKeyItem,"value", json_data->configurationKey[k].value);
}
//可选
return body;
}
cJSON* ClearCache_json(ClearCacheResponse *json_data){
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* SendLocalList_json(SendLocalListResponse *json_data)
{
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "status", json_data->status);
//可选
return body;
}
cJSON* GetLocalListVersion_json(GetLocalListVersionResponse *json_data)
{
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddNumberToObject(body, "listVersion", json_data->listVersion);
//可选
return body;
}
cJSON* GetDiagnostics_json(GetDiagnosticsResponse *json_data)
{
cJSON* body;
//必须项
body = cJSON_CreateObject();
cJSON_AddStringToObject(body, "fileName", json_data->fileName);
//可选
return body;
}
cJSON* DiagnosticsStatusNotification_json(DiagnosticsStatusNotificationRequest *json_data)
{
cJSON *body = cJSON_CreateObject();
if (body != NULL && json_data != NULL) {
cJSON_AddStringToObject(body, "status", json_data->status);
}
return body;
}
cJSON* FirmwareStatusNotification_json(FirmwareStatusNotificationRequest *json_data)
{
return DiagnosticsStatusNotification_json((DiagnosticsStatusNotificationRequest *)json_data);
}
cJSON* j_get_ocpp_json(OCPP_CMD cmd , void *data){
cJSON* body;
switch (cmd)
{
case OCPP_BootNotification:
body = BootNotification_json((BootNotificationRequest *)data);
break;
case OCPP_StatusNotification:
body = StatusNotification_json((StatusNotificationRequest *)data);
break;
case OCPP_MeterValues:
body = MeterValues_json((MeterValuesRequest *)data);
break;
case OCPP_StartTransaction:
body = StartTransaction_json((StartTransactionRequest *)data);
break;
case OCPP_StopTransaction:
body = StopTransaction_json((StopTransactionRequest *)data);
break;
case OCPP_Authorize:
body = Authorize_json((AuthorizeRequest *)data);
break;
case OCPP_UnlockConnector:
body = UnlockConnector_json((UnlockConnectorResponse *)data);
break;
case OCPP_RemoteStartTransaction:
body = RemoteStartTransaction_json((RemoteStartTransactionResponse *)data);
break;
case OCPP_RemoteStopTransaction:
body = RemoteStopTransaction_json((RemoteStopTransactionResponse *)data);
break;
case OCPP_UpdateFirmware:
body = UpdateFirmware_json();
break;
case OCPP_Reset:
body = Reset_json((ResetResponse *)data);
break;
case OCPP_CancelReservation:
body = CancelReservation_json((CancelReservationResponse *)data);
break;
case OCPP_ChangeAvailability:
body = ChangeAvailability_json((ChangeAvailabilityResponse *)data);
break;
case OCPP_ChangeConfiguration:
body = ChangeConfiguration_json((ChangeConfigurationResponse *)data);
break;
case OCPP_TriggerMessage:
body = TriggerMessage_json((TriggerMessageResponse *)data);
break;
case OCPP_GetConfiguration:
body = GetConfiguration_json((GetConfigurationResponse *)data);
break;
case OCPP_ClearCache:
body = ClearCache_json((ClearCacheResponse *)data);
break;
case OCPP_SendLocalList:
body = SendLocalList_json((SendLocalListResponse *)data);
break;
case OCPP_GetLocalListVersion:
body = GetLocalListVersion_json((GetLocalListVersionResponse *)data);
break;
case OCPP_GetDiagnostics:
body = GetDiagnostics_json((GetDiagnosticsResponse *)data);
break;
case OCPP_DiagnosticsStatusNotification:
body = DiagnosticsStatusNotification_json((DiagnosticsStatusNotificationRequest *)data);
break;
case OCPP_FirmwareStatusNotification:
body = FirmwareStatusNotification_json((FirmwareStatusNotificationRequest *)data);
break;
default:
break;
}
return body;
}
#endif
#if 1 // 接收解帧
//登录数据解析
static int ocpp_register_res(cJSON* root , BootNotificationResponse *data)
{
cJSON *mag;
memset(data , 0,sizeof(BootNotificationResponse));
mag = cJSON_GetObjectItem(root,"currentTime");
if(mag != NULL) {
memcpy(data->currentTime , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----currentTime = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"interval");
if(mag != NULL) {
data->interval = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----interval = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"status");
if(mag != NULL) {
memcpy(data->status , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----status = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//平台下发启动充电命令数据解析
static int ocpp_RemoteStartTransaction_unpack(cJSON* root , RemoteStartTransactionRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(RemoteStartTransactionRequest));
mag = cJSON_GetObjectItem(root,"idTag");
if(mag != NULL) {
memcpy(data->idTag , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----idTag = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"connectorId");
if(mag != NULL) {
data->connectorId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----connectorId = %d\n",mag->valueint);
#endif
}
cJSON *chargingProfile = cJSON_GetObjectItem(root,"chargingProfile");
if(chargingProfile == NULL) return 1;
mag = cJSON_GetObjectItem(chargingProfile,"chargingProfileId");
if(mag != NULL) {
data->chargingProfile.chargingProfileId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----chargingProfileId = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(chargingProfile,"transactionId");
if(mag != NULL) {
data->chargingProfile.transactionId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----transactionId = %d\n",mag->valueint);
#endif
}
mag = cJSON_GetObjectItem(chargingProfile,"stackLevel");
if(mag != NULL) {
data->chargingProfile.stackLevel = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----stackLevel = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(chargingProfile,"chargingProfilePurpose");
if(mag != NULL) {
memcpy(data->chargingProfile.chargingProfilePurpose , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----chargingProfilePurpose = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(chargingProfile,"chargingProfileKind");
if(mag != NULL) {
memcpy(data->chargingProfile.chargingProfileKind , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----chargingProfileKind = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(chargingProfile,"recurrencyKind");
if(mag != NULL) {
memcpy(data->chargingProfile.recurrencyKind , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----recurrencyKind = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(chargingProfile,"validFrom");
if(mag != NULL) {
memcpy(data->chargingProfile.validFrom , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----validFrom = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(chargingProfile,"validTo");
if(mag != NULL) {
memcpy(data->chargingProfile.validTo , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----validTo = %s\n",mag->valuestring);
#endif
}
cJSON *chargingSchedule = cJSON_GetObjectItem(chargingProfile,"chargingSchedule");
if(chargingSchedule == NULL) return 1;
mag = cJSON_GetObjectItem(chargingSchedule,"duration");
if(mag != NULL) {
data->chargingProfile.chargingSchedule.duration = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----duration = %d\n",mag->valueint);
#endif
}
mag = cJSON_GetObjectItem(chargingSchedule,"startSchedule");
if(mag != NULL) {
memcpy(data->chargingProfile.chargingSchedule.startSchedule , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----startSchedule = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(chargingSchedule,"chargingRateUnit");
if(mag != NULL) {
memcpy(data->chargingProfile.chargingSchedule.chargingRateUnit , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----chargingRateUnit = %s\n",mag->valuestring);
#endif
}
cJSON *chargingSchedulePeriod = cJSON_GetObjectItem(chargingSchedule,"chargingSchedulePeriod");
if(chargingSchedulePeriod == NULL) return 1;
int periodCount = cJSON_GetArraySize(chargingSchedulePeriod);
// if (periodCount > MAX_PERIODS) {
// printf("Too many charging periods (max %d)\n", MAX_PERIODS);
// return false;
// }
for (int i = 0; i < periodCount; i++) {
cJSON* period = cJSON_GetArrayItem(chargingSchedulePeriod, i);
mag = cJSON_GetObjectItem(period,"startPeriod");
if(mag != NULL) {
data->chargingProfile.chargingSchedule.chargingSchedulePeriod[i].startPeriod = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----startPeriod = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(period,"limit");
if(mag != NULL) {
data->chargingProfile.chargingSchedule.chargingSchedulePeriod[i].limit = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----limit = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(period,"numberPhases");
if(mag != NULL) {
data->chargingProfile.chargingSchedule.chargingSchedulePeriod[i].numberPhases = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----numberPhases = %d\n",mag->valueint);
#endif
}
}
return 1;
}
//平台下发停止充电命令数据解析
static int ocpp_RemoteStopTransaction_unpack(cJSON* root , RemoteStopTransactionRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(RemoteStopTransactionRequest));
mag = cJSON_GetObjectItem(root,"transactionId");
if(mag != NULL) {
data->transactionId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----transactionId = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//启动充电命令应答数据解析
static int ocpp_StartTransaction_unpack(cJSON* root , StartTransactionResponse *data)
{
cJSON *mag;
memset(data , 0,sizeof(StartTransactionResponse));
mag = cJSON_GetObjectItem(root,"transactionId");
if(mag != NULL) {
data->transactionId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----transactionId = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
cJSON *idTagInfo = cJSON_GetObjectItem(root,"idTagInfo");
if(idTagInfo == NULL) return 0;
mag = cJSON_GetObjectItem(idTagInfo,"status");
if(mag != NULL) {
memcpy(data->idTagInfo.status , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----status = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(idTagInfo,"expiryDate");
if(mag != NULL) {
memcpy(data->idTagInfo.expiryDate , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----expiryDate = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(idTagInfo,"parentIdTag");
if(mag != NULL) {
memcpy(data->idTagInfo.parentIdTag , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----parentIdTag = %s\n",mag->valuestring);
#endif
}
return 1;
}
//停止充电命令应答数据解析
static int ocpp_StopTransaction_unpack(cJSON* root , StopTransactionResponse *data)
{
cJSON *mag;
memset(data , 0,sizeof(StopTransactionResponse));
cJSON *idTagInfo = cJSON_GetObjectItem(root,"idTagInfo");
if(idTagInfo == NULL) return 1;
mag = cJSON_GetObjectItem(idTagInfo,"status");
if(mag != NULL) {
memcpy(data->idTagInfo.status , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----status = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(idTagInfo,"expiryDate");
if(mag != NULL) {
memcpy(data->idTagInfo.expiryDate , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----expiryDate = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(idTagInfo,"parentIdTag");
if(mag != NULL) {
memcpy(data->idTagInfo.parentIdTag , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----parentIdTag = %s\n",mag->valuestring);
#endif
}
return 1;
}
//鉴权数据应答数据解析
static int ocpp_Authorize_unpack(cJSON* root , AuthorizeResponse *data)
{
cJSON *mag;
memset(data , 0,sizeof(AuthorizeResponse));
cJSON *idTagInfo = cJSON_GetObjectItem(root,"idTagInfo");
if(idTagInfo == NULL) return 0;
mag = cJSON_GetObjectItem(idTagInfo,"status");
if(mag != NULL) {
memcpy(data->idTagInfo.status , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----status = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(idTagInfo,"expiryDate");
if(mag != NULL) {
memcpy(data->idTagInfo.expiryDate , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----expiryDate = %s\n",mag->valuestring);
#endif
}
mag = cJSON_GetObjectItem(idTagInfo,"parentIdTag");
if(mag != NULL) {
memcpy(data->idTagInfo.parentIdTag , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----parentIdTag = %s\n",mag->valuestring);
#endif
}
return 1;
}
//固件升级
static int ocpp_UpdateFirmware_unpack(cJSON* root , UpdateFirmwareRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(UpdateFirmwareRequest));
mag = cJSON_GetObjectItem(root,"location");
if(mag != NULL) {
memcpy(data->location , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----location = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"retrieveDate");
if(mag != NULL) {
memcpy(data->retrieveDate , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----retrieveDate = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"retries");
if(mag != NULL) {
data->retries = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----retries = %d\n",mag->valueint);
#endif
}
mag = cJSON_GetObjectItem(root,"retryInterval");
if(mag != NULL) {
data->retryInterval = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----retryInterval = %d\n",mag->valueint);
#endif
}
return 1;
}
//远程重启
static int ocpp_ResetRequest_unpack(cJSON* root , ResetRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(ResetRequest));
mag = cJSON_GetObjectItem(root,"type");
if(mag != NULL) {
memcpy(data->type , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----type = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//取消充电枪预定
static int ocpp_CancelReservation_unpack(cJSON* root , CancelReservationRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(CancelReservationRequest));
mag = cJSON_GetObjectItem(root,"reservationId");
if(mag != NULL) {
data->reservationId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----reservationId = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//设置枪可用状态
static int ocpp_ChangeAvailability_unpack(cJSON* root , ChangeAvailabilityRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(ChangeAvailabilityRequest));
mag = cJSON_GetObjectItem(root,"connectorId");
if(mag != NULL) {
data->connectorId = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----connectorId = %d\n",mag->valueint);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"type");
if(mag != NULL) {
memcpy(data->type , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----type = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//更改参数配置
static int ocpp_ChangeConfiguration_unpack(cJSON* root , ChangeConfigurationRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(ChangeConfigurationRequest));
mag = cJSON_GetObjectItem(root,"key");
if(mag != NULL) {
memcpy(data->key , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----key = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
mag = cJSON_GetObjectItem(root,"value");
if(mag != NULL) {
memcpy(data->value , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----value = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//平台下发数据召测命令
static int ocpp_TriggerMessage_unpack(cJSON* root , TriggerMessageRequest *data)
{
cJSON *mag;
memset(data , 0,sizeof(TriggerMessageRequest));
mag = cJSON_GetObjectItem(root,"connectorId");
if(mag != NULL) {
data->connectorId = mag->valueint;
//memcpy(data->connectorId , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----connectorId = %d\n",mag->valueint);
#endif
}
mag = cJSON_GetObjectItem(root,"requestedMessage");
if(mag != NULL) {
memcpy(data->requestedMessage , mag->valuestring , strlen(mag->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----requestedMessage = %s\n",mag->valuestring);
#endif
}
else {
return 0; //没有必选项 则直接退出
}
return 1;
}
//平台下发读取参数命令
static int ocpp_GetConfiguration_unpack(cJSON* root , GetConfigurationRequest *data)
{
cJSON *mag,*mag1;
int key_size;
memset(data , 0,sizeof(GetConfigurationRequest));
mag = cJSON_GetObjectItem(root,"key");
key_size = cJSON_GetArraySize(mag);
for (int i = 0; i < key_size; i++)
{
mag1 = cJSON_GetArrayItem(mag,i); //获取秘钥
memcpy(data->key[i],mag1->valuestring,strlen(mag1->valuestring));
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----key = %d,%s\n",i,mag1->valuestring);
#endif
}
return 1;
}
static int ocpp_SendLocalList_unpack(cJSON* root, SendLocalListRequest *data)
{
cJSON *mag, *mag1, *localListArray, *listItem, *idTagInfoObj;
int i;
// 清零初始化
memset(data, 0, sizeof(SendLocalListRequest));
// 解析必选字段 listVersion
mag = cJSON_GetObjectItem(root, "listVersion");
if (mag != NULL) {
data->listVersion = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----listVersion = %d\n", mag->valueint);
#endif
}
else {
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("Error: Missing required field 'listVersion'\n");
#endif
return 0; // 必选字段缺失,返回错误
}
// 解析必选字段 updateType
mag = cJSON_GetObjectItem(root, "updateType");
if (mag != NULL && mag->valuestring != NULL) {
int updateTypeLen = strlen(mag->valuestring);
int maxLen = OCPP_CiString30 - 1; // 预留1字节给'\0'
int copyLen = (updateTypeLen < maxLen) ? updateTypeLen : maxLen;
memcpy(data->updateType, mag->valuestring, copyLen);
data->updateType[copyLen] = '\0'; // 确保字符串以'\0'结尾
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----updateType = %s\n", data->updateType);
#endif
}
else {
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("Error: Missing required field 'updateType'\n");
#endif
return 0; // 必选字段缺失,返回错误
}
// 解析可选的 localAuthorizationList 数组
localListArray = cJSON_GetObjectItem(root, "localAuthorizationList");
if (localListArray != NULL && cJSON_IsArray(localListArray)) {
int arraySize = cJSON_GetArraySize(localListArray);
data->List_num = arraySize;
if (arraySize > 0) {
// 动态分配内存
data->list = (LocalAuthorizationList*)OCPP_MALLOC(arraySize * sizeof(LocalAuthorizationList));
if (data->list == NULL) {
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("Error: Memory allocation failed for localAuthorizationList\n");
#endif
data->List_num = 0;
return 0; // 内存分配失败
}
// 清零分配的内存
memset(data->list, 0, arraySize * sizeof(LocalAuthorizationList));
// 遍历数组,解析每个元素
for (i = 0; i < arraySize; i++) {
listItem = cJSON_GetArrayItem(localListArray, i);
if (listItem == NULL) {
continue; // 跳过无效项
}
// 解析 idTag
mag = cJSON_GetObjectItem(listItem, "idTag");
if (mag != NULL && mag->valuestring != NULL) {
int idTagLen = strlen(mag->valuestring);
int maxIdTagLen = OCPP_CiString30 - 1;
int copyIdTagLen = (idTagLen < maxIdTagLen) ? idTagLen : maxIdTagLen;
memcpy(data->list[i].idTag, mag->valuestring, copyIdTagLen);
data->list[i].idTag[copyIdTagLen] = '\0';
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----item[%d].idTag = %s\n", i, data->list[i].idTag);
#endif
}
else {
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("Warning: Missing required field 'idTag' in item %d\n", i);
#endif
// idTag是必须的,如果缺失,跳过此元素但保留已分配的空间
continue;
}
// 解析可选的 idTagInfo
idTagInfoObj = cJSON_GetObjectItem(listItem, "idTagInfo");
if (idTagInfoObj != NULL) {
// 解析 expiryDate
mag = cJSON_GetObjectItem(idTagInfoObj, "expiryDate");
if (mag != NULL && mag->valuestring != NULL) {
int expiryDateLen = strlen(mag->valuestring);
int maxExpiryDateLen = OCPP_DATE_LEN - 1;
int copyExpiryDateLen = (expiryDateLen < maxExpiryDateLen) ? expiryDateLen : maxExpiryDateLen;
memcpy(data->list[i].idTagInfo.expiryDate, mag->valuestring, copyExpiryDateLen);
data->list[i].idTagInfo.expiryDate[copyExpiryDateLen] = '\0';
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----item[%d].idTagInfo.expiryDate = %s\n", i, data->list[i].idTagInfo.expiryDate);
#endif
}
// 解析 parentIdTag
mag = cJSON_GetObjectItem(idTagInfoObj, "parentIdTag");
if (mag != NULL && mag->valuestring != NULL) {
int parentIdTagLen = strlen(mag->valuestring);
int maxParentIdTagLen = OCPP_CiString20 - 1;
int copyParentIdTagLen = (parentIdTagLen < maxParentIdTagLen) ? parentIdTagLen : maxParentIdTagLen;
memcpy(data->list[i].idTagInfo.parentIdTag, mag->valuestring, copyParentIdTagLen);
data->list[i].idTagInfo.parentIdTag[copyParentIdTagLen] = '\0';
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----item[%d].idTagInfo.parentIdTag = %s\n", i, data->list[i].idTagInfo.parentIdTag);
#endif
}
// 解析 status (必需字段)
mag = cJSON_GetObjectItem(idTagInfoObj, "status");
if (mag != NULL && mag->valuestring != NULL) {
int statusLen = strlen(mag->valuestring);
int maxStatusLen = OCPP_CiString20 - 1;
int copyStatusLen = (statusLen < maxStatusLen) ? statusLen : maxStatusLen;
memcpy(data->list[i].idTagInfo.status, mag->valuestring, copyStatusLen);
data->list[i].idTagInfo.status[copyStatusLen] = '\0';
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----item[%d].idTagInfo.status = %s\n", i, data->list[i].idTagInfo.status);
#endif
}
else {
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("Warning: Missing required field 'status' in idTagInfo for item %d\n", i);
#endif
// status是idTagInfo中的必需字段,但idTagInfo本身是可选的,所以如果存在idTagInfo但缺少status,我们继续处理
}
}
}
}
}
else {
// localAuthorizationList 是可选的,不存在时正常处理
data->List_num = 0;
data->list = NULL;
}
return 1; // 成功
}
static int ocpp_GetDiagnostics_unpack(cJSON* root, GetDiagnosticsRequest *data)
{
cJSON *mag;
// 解析必选字段 location
mag = cJSON_GetObjectItem(root, "location");
if (mag != NULL && cJSON_IsString(mag)) {
strncpy(data->location, mag->valuestring, sizeof(data->location)-1);
data->location[sizeof(data->location)-1] = '\0'; // 确保字符串终止
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----location = %s\n", data->location);
#endif
}
else {
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("Error: Missing required field 'location'\n");
#endif
return 0; // 必选字段缺失,返回错误
}
// 解析可选字段 retries
mag = cJSON_GetObjectItem(root, "retries");
if (mag != NULL && cJSON_IsNumber(mag)) {
data->retries = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----retries = %d\n", data->retries);
#endif
}
// 解析可选字段 retryInterval
mag = cJSON_GetObjectItem(root, "retryInterval");
if (mag != NULL && cJSON_IsNumber(mag)) {
data->retryInterval = mag->valueint;
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----retryInterval = %d\n", data->retryInterval);
#endif
}
// 解析可选字段 startTime
mag = cJSON_GetObjectItem(root, "startTime");
if (mag != NULL && cJSON_IsString(mag)) {
strncpy(data->startTime, mag->valuestring, sizeof(data->startTime)-1);
data->startTime[sizeof(data->startTime)-1] = '\0';
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----startTime = %s\n", data->startTime);
#endif
}
// 解析可选字段 stopTime
mag = cJSON_GetObjectItem(root, "stopTime");
if (mag != NULL && cJSON_IsString(mag)) {
strncpy(data->stopTime, mag->valuestring, sizeof(data->stopTime)-1);
data->stopTime[sizeof(data->stopTime)-1] = '\0';
#if OCPP_LOGMSG_DEBUG_EN >1
Plat_Comm_LOG("----stopTime = %s\n", data->stopTime);
#endif
}
return 1; // 解析成功
}
int get_ocpp_data(OCPP_CMD cmd , void *data ,cJSON *root)
{
int ret ;
switch (cmd)
{
case OCPP_BootNotification:
ret = ocpp_register_res(root,(BootNotificationResponse *)data);
break;
case OCPP_RemoteStartTransaction:
ret = ocpp_RemoteStartTransaction_unpack(root,(RemoteStartTransactionRequest *)data);
break;
case OCPP_RemoteStopTransaction:
ret = ocpp_RemoteStopTransaction_unpack(root,(RemoteStopTransactionRequest *)data);
break;
case OCPP_StartTransaction:
ret = ocpp_StartTransaction_unpack(root,(StartTransactionResponse *)data);
break;
case OCPP_StopTransaction:
ret = ocpp_StopTransaction_unpack(root,(StopTransactionResponse *)data);
break;
case OCPP_Authorize:
ret = ocpp_Authorize_unpack(root,(AuthorizeResponse *)data);
break;
case OCPP_UpdateFirmware:
ret = ocpp_UpdateFirmware_unpack(root,(UpdateFirmwareRequest *)data);
break;
case OCPP_Reset:
ret = ocpp_ResetRequest_unpack(root,(ResetRequest *)data);
break;
case OCPP_CancelReservation:
ret = ocpp_CancelReservation_unpack(root,(CancelReservationRequest *)data);
break;
case OCPP_ChangeAvailability:
ret = ocpp_ChangeAvailability_unpack(root,(ChangeAvailabilityRequest *)data);
break;
case OCPP_ChangeConfiguration:
ret = ocpp_ChangeConfiguration_unpack(root,(ChangeConfigurationRequest *)data);
break;
case OCPP_TriggerMessage:
ret = ocpp_TriggerMessage_unpack(root,(TriggerMessageRequest *)data);
break;
case OCPP_GetConfiguration:
ret = ocpp_GetConfiguration_unpack(root,(GetConfigurationRequest *)data);
break;
case OCPP_SendLocalList:
ret = ocpp_SendLocalList_unpack(root,(SendLocalListRequest *)data);
break;
case OCPP_GetDiagnostics:
ret = ocpp_GetDiagnostics_unpack(root,(GetDiagnosticsRequest *)data);
break;
default:
break;
}
return ret;
}
#endif
//获取ocpp 命令码 字符串地址
const char *s_get_ocpp_cmd_str(OCPP_CMD cmd){
int count = sizeof(ocpp_cmd_str) / sizeof(ocpp_cmd_str[0]);
if((U8_T)cmd > count) //cmd 命令值不匹配
return NULL;
return &ocpp_cmd_str[cmd][0];
}
//获取ocpp 字符串 枚举位置
OCPP_CMD e_get_recv_json_cmd(char* cmd_str)
{
OCPP_CMD cmd = OCPP_NULL;
int i,count = sizeof(ocpp_cmd_str) / sizeof(ocpp_cmd_str[0]);
for (i = 0; i < count; i++)
{
// Plat_Comm_LOG("----(%d)str len= %d,%d\n",i,strlen(ocpp_cmd_str[i]),strlen(cmd_str));
// Plat_Comm_LOG("----(%d)str is= (%s),(%s)\n",i,ocpp_cmd_str[i],cmd_str);
if(strstr(ocpp_cmd_str[i],cmd_str))
{
cmd = i;
break;
}
}
return cmd;
}
//获取ocpp 枚举字符串数据内容
const char *s_get_ocpp_enum_data_str(OCPP_ENUM_DATA_TYPE type ,int cmd){
switch (type)
{
case OCPP_StatusNotification_errorCode:
return &StatusNotification_ocpp_errorCode[cmd][0];
case OCPP_StatusNotification_statusCode:
return &StatusNotification_statusCode[cmd][0];
case OCPP_RemoteStartTransactionResponse_statusCode:
case OCPP_RemoteStopTransactionResponse_statusCode:
return &RemoteStartTransactionResponse_statusCode[cmd][0];
case OCPP_StopTransactionRequest_reason:
return &StopTransactionRequest_reason[cmd][0];
case OCPP_UnlockConnectorResponse_stateCode:
return &UnlockConnectorResponse_stateCode[cmd][0];
case OCPP_DiagnosticsStatusNotification_status:
if (cmd >= 0 && cmd < (int)(sizeof(DiagnosticsStatusNotification_status) / sizeof(DiagnosticsStatusNotification_status[0]))) {
return &DiagnosticsStatusNotification_status[cmd][0];
}
return &ocpp_str_null[0];
case OCPP_FirmwareStatusNotification_status:
if (cmd >= 0 && cmd < (int)(sizeof(FirmwareStatusNotification_status) / sizeof(FirmwareStatusNotification_status[0]))) {
return &FirmwareStatusNotification_status[cmd][0];
}
return &ocpp_str_null[0];
default:
return &ocpp_str_null[0];
break;
}
}
#endif