Skip to content

ocpp: Replaced JSON-C implementation with native Zephyr JSON #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev/ev/ocpp
Choose a base branch
from

Conversation

SanjayyyV
Copy link
Collaborator

@SanjayyyV SanjayyyV commented Jun 30, 2025

  • Native Zephyr JSON support for OCPP Subsystem
  • Modified the kconfig to depend on JSON_LIBRARY instead of JSONC
  • Due to the lack of support for encoding and parsing mixed types arrays and encoding optional fields in zephyr JSON, those functionalities have been implemented with the help of string functions.

@SanjayyyV SanjayyyV force-pushed the dev-ocpp-json branch 2 times, most recently from 8e04b49 to af62e5d Compare July 2, 2025 06:42
#ifndef __OCPP_J_
#define __OCPP_J_

#define MAX_UID_LEN 38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a common macro with size limitation of 128, 256, 512 bytes

#define MAX_GETCONFIGURATION_RESP_LEN 92
#define MAX_OCPP_RPC_MESSAGE_LEN 512

#define BOOTNOTIF_REQ_FIELDS 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/REQ/MIN

#define MAX_OCPP_RPC_MESSAGE_LEN 512

#define BOOTNOTIF_REQ_FIELDS 2
#define BOOTNOTIF_TOTAL_FIELDS 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/TOTAL/MAX

struct ocpp_meter_val_msg {
int connector_id;
int transaction_id;
struct ocpp_meter_value meter_value[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encode struct ocpp_meter_value here


struct ocpp_meter_value {
char *timestamp;
struct ocpp_sampled_value sampled_value[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encode struct ocpp_sampled_value inside here

.dummy = true,
};

ret = json_obj_encode_buf(descr, ARRAY_SIZE(descr), &msg,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the expected json out is empty {} pass, (descr NULL, 0, NULL, ...

#define SAMPLED_VALUE_REQ_FIELDS 2
#define SAMPLED_VALUE_TOTAL_FIELDS 3

struct authorize_payload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use generic struct json_common_payload_field_str { char * val} for authorize_payload, heartbeat_payload, ocpp_status_resp_msg

char *current_time;
};

struct start_txn_payload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use generic struct json_common_payload_field_int { int val} for start_txn_payload, remote_stop_txn_payload, unlock_connector_payload

char *id_tag;
};

struct ocpp_heartbeat_msg {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never hit to use this struct

if the intention is get empty {} json as read from the code replace snippet to

ret = json_obj_encode_buf(descr, ARRAY_SIZE(descr), &msg, tmp_buf, sizeof(tmp_buf));
to
ret = json_obj_encode_buf(NULL, 0, NULL, tmp_buf, sizeof(tmp_buf));

int transaction_id;
};

struct getconfig_payload {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make struct name consistent.. all of here used only for json, may json_ or j_ prefix

@SanjayyyV SanjayyyV requested a review from ssekar15 July 3, 2025 04:00
SanjayyyV added 2 commits July 3, 2025 16:58
Replaced external JSON-C usage with native Zephyr JSON APIs
across OCPP subsystem. Added buffer sizing macros and field
stripping logic to handle optional fields safely during encoding and
parsing.

Signed-off-by: Sanjay Vallimanalan <[email protected]>
Updated prj.conf to use CONFIG_JSON_LIBRARY instead of CONFIG_JSONC.

Signed-off-by: Sanjay Vallimanalan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants