5.1 ChargerConfigurationDatabase

The Charger Configuration Database likely refers to a system for managing configuration settings for multiple charge points. While OCPP 1.6J includes messages like GetConfiguration and ChangeConfiguration to manage individual charge point settings, a charger configuration database could be a centralized repository that stores and manages these configurations across multiple devices.

API Syntax

Description

Input Params

Return Value

UtilitiesGlobalVariablesReset

Function to reset global variables

void

void

Example:


 void OCPPResetAllGlobals(void) 
{
  UtilitiesGlobalVariablesReset();
  UtilitiesLocalStorageResetGlobals();
  OCPPSetChargingProfileResetGlobals();
  OCPPGetCompositeScheduleResetGlobals();
  CPPClearChargingProfileResetGlobals();

API Syntax

Description

Input Params

Return Value

ChargerConfigurationDataBaseInit

Initializes the charger configuration database.

void

void

Example:

void DataBaseInit(void)
{
    ChargerConfigurationDataBaseInit();
    LocalListDataBaseInit();
    AuthorizationCacheDataBaseInit();
    LocalStorageDataBaseInit();
}

API Syntax

Description

Input Params

Return Value

ChargerConfigurationDataBaseClose

Closes the charger configuration database.

void

void

Example:

void DataBaseDeinit(void)
{
    ChargerConfigurationDataBaseClose();
    LocalListDataBaseClose();
    AuthorizationCacheDataBaseClose();
    LocalStorageDataBaseClose();
}

API Syntax

Description

Input Params

Return Value

ChargerConfigurationGetCount

Retrieves the count of records in the charger configuration from the database.

void

void

Example:

    else
    {
        sprintf(sql, "%s", "SELECT * FROM chpr");
        OCPPLogMessage(LOG_INFO, LOG_SENDING, "Sql: %s\n\r", sql);

        cb_data.db_data_counter = 0;
        ChargerConfigurationGetCount();
        keys->array_size = cb_data.total_db_data_required;
        OCPPLogMessage(LOG_INFO, LOG_SENDING, "TOTAL ROWS: %d \n\r", cb_data.total_db_data_required);

        cb_data.update_data = 0;
        ChargerConfigurationExecuteQuerry(sql);
    }


API Syntax

Description

Input Params

Return Value

ChargerConfigurationGetCount

Retrieves the count of records in the charger configuration database.

void

void

Example:

    else
    {
        sprintf(sql, "%s", "SELECT * FROM chpr");
        OCPPLogMessage(LOG_INFO, LOG_SENDING, "Sql: %s\n\r", sql);

        cb_data.db_data_counter = 0;
        ChargerConfigurationGetCount();
        keys->array_size = cb_data.total_db_data_required;
        OCPPLogMessage(LOG_INFO, LOG_SENDING, "TOTAL ROWS: %d \n\r", cb_data.total_db_data_required);

        cb_data.update_data = 0;
        ChargerConfigurationExecuteQuerry(sql);
    }

API Syntax

Description

Input Params

Return Value

ChargerConfigurationGet

Retrieves the charger configuration records based on provided keys.

RX_GETCONFIGURATION_T *keys

void

Example:

    
        /** Update the known array size after accounting for unknown keys */
        rxGetConfiguration.array_size -= rxGetConfiguration.unknown_key_size;

        /** Log the count of known and unknown keys */
        OCPPLogMessage(LOG_INFO, LOG_SENDING, "Known Keys: %d Unknown Keys: %d \n\r", rxGetConfiguration.array_size, rxGetConfiguration.unknown_key_size);

        /** Retrieve configuration data from the database */
        ChargerConfigurationGet(&rxGetConfiguration);

        /** Send the response back to the Central System */
        SendGetChargerConfigResponse();
        return OCPP_PROCESS_REQUEST_OK; /** Return 1 indicating successful processing */
    }

API Syntax

Description

Input Params

Return Value

ChargerConfigurationUpdate

Updates a specific charger configuration key with a new value.

RX_CHANGECONFIGURATION_T key_Value

void

Example:

    
                    /*Utilities:*/
                    case '5': /*ChargerConfigurationDataBase*/
                    {
                        RX_CHANGECONFIGURATION_T keyValue;
                        uint32_t timeOutMilliSec = DB_TIMEOUT_MS;
                        LogDebug("APP_LOG", "Enter an DB time Out Values in MilliSec(100): ");
                        result = scanf("%u", &timeOutMilliSec);
                        if (result != 1) 
                        {
                            LogDebug("APP_LOG", "Error reading DB time Out Value\n");
                        }
                        else
                        {
                            LogDebug("APP_LOG", "Received DB time Out Value\n");
                        }
                        
                        SetDatabaseTimeout(timeOutMilliSec);
                        (void)snprintf(keyValue.key, sizeof(keyValue.key), "LocalAuthListEnabled");
                        (void)snprintf(keyValue.value, sizeof(keyValue.value), "1");
                        ChargerConfigurationUpdate(keyValue);
                        char idTag[OCPP_ID_TAG];
                        char status[OCPP_TAGLIST_STATUS];
                        char expiryDate[OCPP_TAGLIST_EXPIRYDATE];
                        char parentIdTag[OCPP_PARENTIDTAG];
                        (void)snprintf(idTag, sizeof(idTag), "23F532C36");

API Syntax

Description

Input Params

Return Value

ChargerConfigurationCheckEnabledKey

Checks if a specific charger configuration key is enabled.

char *key

int

Example:

    
                case 'N': /*StatusNotification*/
                {
                    uint32_t ChargePointError;
                    uint32_t CurrChargePointState;
                    AUTHORIZERESPONSEVAL_T parm;
                    char PrevChargePointStatus[CHARGE_POINT_STATUS_SIZE];
                    u_int32_t connectorId;
                    RX_RESERVENOW_T params;
                    int transactionId;

                    bool AuthorizeRemoteTxRequest = (bool)ChargerConfigurationCheckEnabledKey("AuthorizeRemoteTxRequests");
                    REMOTE_START_STOP_STATUS_T RemoteStartStatus = GetRemoteStartTransactionStatus();

API Syntax

Description

Input Params

Return Value

ChargerConfigurationCheckExistence

Checks if a specific charger configuration key exists in the database.

char *key

int

Example:

                /** Check if the key exists in the charger configuration database */
            else if (ChargerConfigurationCheckExistence(key_value) == 0)
            {
                /** Add to the unknown key list */
                rxGetConfiguration.unknown_key_size++;
                sprintf(rxGetConfiguration.unknown_key[unknown_index++], "%s", key_value);
                OCPPLogMessage(LOG_INFO, LOG_SENDING, "Json key: %s is Unknown\n\r", rxGetConfiguration.unknown_key[unknown_index - 1]);
            }

API Syntax

Description

Input Params

Return Value

LocalListAddUpdateDataBase

Adds or updates entries in the local list database.

RX_SENDLOCALLIST_T *locallist

void

Example:

                                    if(GetTotalRowsInTaglist() < GetLocalAuthListMaxLength())
                                    {
                                        LocalListAddUpdateDataBase(&rxSendLocalList);
                                        OCPPLogMessage(LOG_INFO, LOG_RECEIVED, "Inserted into database successfully\n\r");
                                    }
                                    else
                                    {
                                        sendLocalListFailedFlag = true;
                                        OCPPLogMessage(LOG_INFO, LOG_RECEIVED, "Failed to insert into database\n\r");
                                    }

API Syntax

Description

Input Params

Return Value

LocalListDataBaseInit

Initializes the local list database.

void

void

Example:

void DataBaseInit(void)
{
    ChargerConfigurationDataBaseInit();
    LocalListDataBaseInit();
    AuthorizationCacheDataBaseInit();
    LocalStorageDataBaseInit();
}

API Syntax

Description

Input Params

Return Value

LocalListDataBaseClose

Closes the local list database.

void

void

Example:

void DataBaseDeinit(void)
{
    ChargerConfigurationDataBaseClose();
    LocalListDataBaseClose();
    AuthorizationCacheDataBaseClose();
    LocalStorageDataBaseClose();
}

API Syntax

Description

Input Params

Return Value

LocalListDeleteDataBase

Deletes entries from the local list database.

RX_SENDLOCALLIST_T *locallist

void

Example:

                                OCPPLogMessage(LOG_INFO, LOG_RECEIVED, "This tag is to delete the tag from list\n\r");
                            rxSendLocalList.taglocallist[tp].delet = 1;
                            if (cJSONHasObjectItem(taglist, "idTag"))
                            {
                                sprintf(rxSendLocalList.taglocallist[tp].tagid, "%s", cJSONGetObjectItem(taglist, "idTag")->valuestring);
                                OCPPLogMessage(LOG_INFO, LOG_RECEIVED, "Tag ID: %s\n\r", rxSendLocalList.taglocallist[tp].tagid);
                                LocalListDeleteDataBase(&rxSendLocalList);
                                SetSendLocalListStatus(SEND_LOCAL_LIST_ACCEPTED);
                                OCPPProcessReportToApplication(SEND_LOCALLIST, SEND_LOCAL_LIST_ACCEPTED);
                            }

API Syntax

Description

Input Params

Return Value

GetLocalListTagDataFromDB

Retrieves tag data from the local list database based on the ID tag.

char *idTag, char *status, char *expiryDate, char *parentIdTag

int

Example:

  if(strncmp(localAuthListEnabled, "true", strlen(localAuthListEnabled)) == 0)
            {
                if (GetLocalListTagDataFromDB(IdTag, status, expiryDate, parentIdTag) == 0)
                {
                    LogDebug("APP_LOG", "IdTag:%s available with status:%s.\n", IdTag, status);
                    if(strncmp(status, "Accepted", strlen(status)) == 0)
                    {
                        return LOCALAUTHORIZATION_SUCCESS;
                    }
                    else
                    {
                        return LOCALAUTHORIZATION_FAILED;
                    }
                }
            }

API Syntax

Description

Input Params

Return Value

GetChargerConfigurationWithKey

Retrieves charger configuration values for a specific key.

char *key, char *type, char *value, char *readonly

int

Example:

  case GET_LOCAL_LIST_VERSION:
  {
    /*RX_RESERVENOW_T params;
    char ChargePointStatus[CHARGE_POINT_STATUS_SIZE];*/
    char key[MAX_TYPE_LENGTH] = "LocalAuthListEnabled";
    char type[MAX_TYPE_LENGTH];
    char LocalAuthListEnabled[MAX_TYPE_LENGTH];
    char readonly[MAX_TYPE_LENGTH];

    (void)GetChargerConfigurationWithKey(key, type, LocalAuthListEnabled, readonly);
    if(strcmp(LocalAuthListEnabled, "true") == 0)

API Syntax

Description

Input Params

Return Value

GetAuthCacheListTagDataFromDB

Retrieves tag data from the authorization cache database based on an ID tag.

char *idTag, char *status, char *expiryDate, char *parentIdTag

int

Example:

      char AuthorizationCacheEnabled [MAX_TYPE_LENGTH];
            GetChargerConfigurationWithKey("AuthorizationCacheEnabled", type, AuthorizationCacheEnabled, readonly);
            if(strcmp(AuthorizationCacheEnabled, "true") == 0)
            {
                if (GetAuthCacheListTagDataFromDB(IdTag, status, expiryDate, parentIdTag) == 0)
                {
                    LogDebug("APP_LOG", "IdTag:%s available with status:%s.\n", IdTag, status);
                    if(strcmp(status, "Accepted") == 0)
                    {
                        return LOCALAUTHORIZATION_SUCCESS;
                    }
                    else
                    {
                        return LOCALAUTHORIZATION_FAILED;
                    }
                }
            }

API Syntax

Description

Input Params

Return Value

AuthorizationCacheAddUpdateDataBase

Adds or updates entries in the authorization cache database.

AUTHORIZATIONCACHE_T *authcache

int

Example:

void UpdateAuthorizationCache(char* IdTag, AUTHORIZERESPONSEVAL_T parm)
{
    AUTHORIZATIONCACHE_T authcache;

    authcache.AuthorizationCachelen = 1;
    authcache.tagauthcache->delet = 0;
    sprintf(authcache.tagauthcache[0].tagid, "%s", IdTag);
    sprintf(authcache.tagauthcache[0].taginfo.expiryDate, "%s", parm.idTagInfo.expiryDate);
    sprintf(authcache.tagauthcache[0].taginfo.parentIdTag, "%s", parm.idTagInfo.parentIdTag);
    sprintf(authcache.tagauthcache[0].taginfo.status, "%s", parm.idTagInfo.status);
    authcache.updateType = UPDATETYPE_DIFFERENTIAL;

    LogDebug("APP_LOG", " AuthorizationCache IdTag:%s expiryDate:%s parentIdTag:%s status:%s\n", 
    authcache.tagauthcache[0].tagid,
    authcache.tagauthcache[0].taginfo.expiryDate,
    authcache.tagauthcache[0].taginfo.parentIdTag,
    authcache.tagauthcache[0].taginfo.status
    );
    AuthorizationCacheAddUpdateDataBase(&authcache);
}

API Syntax

Description

Input Params

Return Value

AuthorizationCacheDataBaseInit

Initializes the authorization cache database.

void

void

Example:

void DataBaseInit(void)
{
    ChargerConfigurationDataBaseInit();
    LocalListDataBaseInit();
    AuthorizationCacheDataBaseInit();
    LocalStorageDataBaseInit();
}

API Syntax

Description

Input Params

Return Value

AuthorizationCacheDataBaseClose

Closes the authorization cache database.

void

void

Example:

void DataBaseDeinit(void)
{
    ChargerConfigurationDataBaseClose();
    LocalListDataBaseClose();
    AuthorizationCacheDataBaseClose();
    LocalStorageDataBaseClose();
}

API Syntax

Description

Input Params

Return Value

AuthorizationCacheDeleteDataBase

Deletes entries from the authorization cache database.

AUTHORIZATIONCACHE_T *authcache

void

Example:

void ClearAuthorizationCache(void)
{
    char sql_command[200];
    OCPPLogMessage(LOG_INFO, LOG_SENDING, "---------->AuthorizationCacheDeleteDataBase\n\r");
    sprintf(sql_command, "delete from taglist;");
    OCPPLogMessage(LOG_INFO, LOG_SENDING, "sql: %s\n\r", sql_command);
    AuthCacheExecuteQuerry(sql_command);
}

API Syntax

Description

Input Params

Return Value

ClearAuthorizationCache

Deletes all the entries from the authorization cache database.

void

int

Example:

void ClearAuthorizationCacheHandler(uint16_t responsecode)
{
   if(responsecode == CLEAR_CACHE_ACCEPTED) 
   {
     if(ClearAuthorizationCache() == AUTHORIZATION_CACHE_SUCCESS)
     {
        SetClearCacheStatus(CLEAR_CACHE_ACCEPTED);
     }
     else
     {
        SetClearCacheStatus(CLEAR_CACHE_REJECTED);
     }    
   }
   else
   {
     SetClearCacheStatus(CLEAR_CACHE_REJECTED);
   }
}