1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

Refactor naming of json_t variables

Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
Steffen Vogel 2023-06-29 06:02:36 +00:00
parent 31eabd7b9d
commit f409e05c35
6 changed files with 66 additions and 66 deletions

View file

@ -48,7 +48,7 @@ public:
};
// Parse the config json
static ASDUData parse(json_t *signal_json, std::optional<ASDUData> last_data, bool duplicate_ioa_is_sequence);
static ASDUData parse(json_t *json_signal, std::optional<ASDUData> last_data, bool duplicate_ioa_is_sequence);
// Does this data include a timestamp
bool hasTimestamp() const;

View file

@ -178,13 +178,13 @@ public:
int windowSizeIn = 0; // Size of window in samples
json_t *pairings_json = nullptr;
json_t *json_pairings = nullptr;
MultiSignalHook::parse(json);
result = json_unpack_ex(json, &json_error, 0, "{ s: i , s: o, s?: b, s?: b, s?: b, s?: b, s?: b, s? : s, s? : s }",
"window_size", &windowSizeIn,
"pairings", &pairings_json,
"pairings", &json_pairings,
"add_channel_name", &channelNameEnable,
"active_power", &calcActivePower,
"reactive_power", &calcReactivePower,
@ -223,16 +223,16 @@ public:
throw ConfigError(json, "node-config-hook-dft-angle-unit", "Angle unit {} not recognized", angleUnitC);
// Pairings
if (!json_is_array(pairings_json))
throw ConfigError(pairings_json, "node-config-hook-power", "Pairings are expected as json array");
if (!json_is_array(json_pairings))
throw ConfigError(json_pairings, "node-config-hook-power", "Pairings are expected as json array");
size_t i = 0;
json_t *pairings_json_value;
json_array_foreach(pairings_json, i, pairings_json_value) {
json_t *json_pairings_value;
json_array_foreach(json_pairings, i, json_pairings_value) {
const char *voltageNameC = nullptr;
const char *currentNameC = nullptr;
json_unpack_ex(pairings_json_value, &json_error, 0, "{ s: s, s: s}",
json_unpack_ex(json_pairings_value, &json_error, 0, "{ s: s, s: s}",
"voltage", &voltageNameC,
"current", &currentNameC
);

View file

@ -35,7 +35,7 @@ static timespec cp56time2a_to_timespec(CP56Time2a cp56time2a) {
return time;
}
ASDUData ASDUData::parse(json_t *signal_json, std::optional<ASDUData> last_data, bool duplicate_ioa_is_sequence) {
ASDUData ASDUData::parse(json_t *json_signal, std::optional<ASDUData> last_data, bool duplicate_ioa_is_sequence) {
json_error_t err;
char const *asdu_type_name = nullptr;
int with_timestamp = -1;
@ -43,13 +43,13 @@ ASDUData ASDUData::parse(json_t *signal_json, std::optional<ASDUData> last_data,
std::optional<int> ioa_sequence_start = std::nullopt;
int ioa = -1;
if (json_unpack_ex(signal_json, &err, 0, "{ s?: s, s?: b, s?: s, s: i }",
if (json_unpack_ex(json_signal, &err, 0, "{ s?: s, s?: b, s?: s, s: i }",
"asdu_type", &asdu_type_name,
"with_timestamp", &with_timestamp,
"asdu_type_id", &asdu_type_id,
"ioa", &ioa
))
throw ConfigError(signal_json, err, "node-config-node-iec60870-5-104");
throw ConfigError(json_signal, err, "node-config-node-iec60870-5-104");
// Increase the ioa if it is found twice to make it a sequence
if ( duplicate_ioa_is_sequence &&
@ -671,7 +671,7 @@ int SlaveNode::parse(json_t *json, const uuid_t sn_uuid)
json_error_t err;
auto signals = getOutputSignals();
json_t *out_json = nullptr;
json_t *json_out = nullptr;
char const *address = nullptr;
int apci_t0 = -1;
int apci_t1 = -1;
@ -681,7 +681,7 @@ int SlaveNode::parse(json_t *json, const uuid_t sn_uuid)
int apci_w = -1;
ret = json_unpack_ex(json, &err, 0, "{ s?: o, s?: s, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i }",
"out", &out_json,
"out", &json_out,
"address", &address,
"port", &server.local_port,
"ca", &server.common_address,
@ -718,28 +718,28 @@ int SlaveNode::parse(json_t *json, const uuid_t sn_uuid)
if (address)
server.local_address = address;
json_t *signals_json = nullptr;
json_t *json_signals = nullptr;
int duplicate_ioa_is_sequence = false;
if (out_json) {
if (json_out) {
output.enabled = true;
ret = json_unpack_ex(out_json, &err, 0, "{ s: o, s?: b }",
"signals", &signals_json,
ret = json_unpack_ex(json_out, &err, 0, "{ s: o, s?: b }",
"signals", &json_signals,
"duplicate_ioa_is_sequence", &duplicate_ioa_is_sequence
);
if (ret)
throw ConfigError(out_json, err, "node-config-node-iec60870-5-104");
throw ConfigError(json_out, err, "node-config-node-iec60870-5-104");
}
if (signals_json) {
json_t *signal_json;
if (json_signals) {
json_t *json_signal;
size_t i;
std::optional<ASDUData> last_data = std::nullopt;
json_array_foreach(signals_json, i, signal_json) {
json_array_foreach(json_signals, i, json_signal) {
auto signal = signals ? signals->getByIndex(i) : Signal::Ptr{};
auto asdu_data = ASDUData::parse(signal_json, last_data, duplicate_ioa_is_sequence);
auto asdu_data = ASDUData::parse(json_signal, last_data, duplicate_ioa_is_sequence);
last_data = asdu_data;
SignalData initial_value;

View file

@ -610,17 +610,17 @@ int GooseNode::parse(json_t *json, const uuid_t sn_uuid)
if (ret)
return ret;
json_t *in_json = nullptr;
json_t *out_json = nullptr;
json_t *json_in = nullptr;
json_t *json_out = nullptr;
ret = json_unpack_ex(json, &err, 0, "{ s: o, s: o }",
"in", &in_json,
"out", &out_json
"in", &json_in,
"out", &json_out
);
if (ret)
throw ConfigError(json, err, "node-config-node-iec61850-8-1");
parseInput(in_json);
parseOutput(out_json);
parseInput(json_in);
parseOutput(json_out);
return 0;
}
@ -630,21 +630,21 @@ void GooseNode::parseInput(json_t *json)
int ret;
json_error_t err;
json_t *subscribers_json = nullptr;
json_t *signals_json = nullptr;
json_t *json_subscribers = nullptr;
json_t *json_signals = nullptr;
char const *interface_id = input.interface_id.c_str();
int with_timestamp = true;
ret = json_unpack_ex(json, &err, 0, "{ s: o, s: o, s?: s, s: b }",
"subscribers", &subscribers_json,
"signals", &signals_json,
"subscribers", &json_subscribers,
"signals", &json_signals,
"interface", &interface_id,
"with_timestamp", &with_timestamp
);
if (ret)
throw ConfigError(json, err, "node-config-node-iec61850-8-1");
parseSubscribers(subscribers_json, input.contexts);
parseInputSignals(signals_json, input.mappings);
parseSubscribers(json_subscribers, input.contexts);
parseInputSignals(json_signals, input.mappings);
input.interface_id = interface_id;
input.with_timestamp = with_timestamp;
@ -691,15 +691,15 @@ void GooseNode::parseSubscriber(json_t *json, GooseNode::SubscriberConfig &sc)
void GooseNode::parseSubscribers(json_t *json, std::map<std::string, InputEventContext> &ctx)
{
char const* key;
json_t* subscriber_json;
json_t* json_subscriber;
if (!json_is_object(json))
throw RuntimeError("subscribers is not an object");
json_object_foreach(json, key, subscriber_json) {
json_object_foreach(json, key, json_subscriber) {
SubscriberConfig sc;
parseSubscriber(subscriber_json, sc);
parseSubscriber(json_subscriber, sc);
ctx[key] = InputEventContext { sc };
}
@ -741,19 +741,19 @@ void GooseNode::parseOutput(json_t *json)
int ret;
json_error_t err;
json_t *publishers_json = nullptr;
json_t *signals_json = nullptr;
json_t *json_publishers = nullptr;
json_t *json_signals = nullptr;
char const *interface_id = output.interface_id.c_str();
ret = json_unpack_ex(json, &err, 0, "{ s:o, s:o, s?:s, s?:f }",
"publishers", &publishers_json,
"signals", &signals_json,
"publishers", &json_publishers,
"signals", &json_signals,
"interface", &interface_id,
"resend_interval", &output.resend_interval
);
if (ret)
throw ConfigError(json, err, "node-config-node-iec61850-8-1");
parsePublishers(publishers_json, output.contexts);
parsePublishers(json_publishers, output.contexts);
output.interface_id = interface_id;
}
@ -763,20 +763,20 @@ void GooseNode::parsePublisherData(json_t *json, std::vector<OutputData> &data)
int ret;
json_error_t err;
int index;
json_t* signal_or_value_json;
json_t* json_signal_or_value;
if (!json_is_array(json))
throw RuntimeError("publisher data is not an array");
json_array_foreach(json, index, signal_or_value_json) {
json_array_foreach(json, index, json_signal_or_value) {
char const *mms_type = nullptr;
char const *signal_str = nullptr;
json_t *value_json = nullptr;
json_t *json_value = nullptr;
int bitstring_size = -1;
ret = json_unpack_ex(signal_or_value_json, &err, 0, "{ s:s, s?:s, s?:o, s?:i }",
ret = json_unpack_ex(json_signal_or_value, &err, 0, "{ s:s, s?:s, s?:o, s?:i }",
"mms_type", &mms_type,
"signal", &signal_str,
"value", &value_json,
"value", &json_value,
"mms_bitstring_size", &bitstring_size
);
if (ret)
@ -790,8 +790,8 @@ void GooseNode::parsePublisherData(json_t *json, std::vector<OutputData> &data)
auto signal_data = SignalData {};
if (value_json) {
ret = signal_data.parseJson(goose_type->signal_type, value_json);
if (json_value) {
ret = signal_data.parseJson(goose_type->signal_type, json_value);
if (ret)
throw ConfigError(json, err, "node-config-node-iec61850-8-1");
}
@ -823,7 +823,7 @@ void GooseNode::parsePublisher(json_t *json, PublisherConfig &pc)
int conf_rev = 0;
int time_allowed_to_live = 0;
int burst = 1;
json_t *data_json = nullptr;
json_t *json_data = nullptr;
ret = json_unpack_ex(json, &err, 0, "{ s:s, s:s, s:s, s:s, s:i, s:i, s:i, s?:i, s:o }",
"go_id", &go_id,
"go_cb_ref", &go_cb_ref,
@ -833,7 +833,7 @@ void GooseNode::parsePublisher(json_t *json, PublisherConfig &pc)
"conf_rev", &conf_rev,
"time_allowed_to_live", &time_allowed_to_live,
"burst", &burst,
"data", &data_json
"data", &json_data
);
if (ret)
throw ConfigError(json, err, "node-config-node-iec61850-8-1");
@ -851,18 +851,18 @@ void GooseNode::parsePublisher(json_t *json, PublisherConfig &pc)
pc.time_allowed_to_live = time_allowed_to_live;
pc.burst = burst;
parsePublisherData(data_json, pc.data);
parsePublisherData(json_data, pc.data);
}
void GooseNode::parsePublishers(json_t *json, std::vector<OutputContext> &ctx)
{
int index;
json_t* publisher_json;
json_t* json_publisher;
json_array_foreach(json, index, publisher_json) {
json_array_foreach(json, index, json_publisher) {
PublisherConfig pc;
parsePublisher(publisher_json, pc);
parsePublisher(json_publisher, pc);
ctx.push_back(OutputContext { pc });
}

View file

@ -53,8 +53,8 @@ int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid)
const char *pr = nullptr;
int ord = -1;
int &rexmit = dci.reliability.rexmit.emplace<int>(0);
json_t *ice_json = nullptr;
json_t *fmt_json = nullptr;
json_t *json_ice = nullptr;
json_t *json_format = nullptr;
json_error_t err;
ret = json_unpack_ex(json, &err, 0, "{ s:s, s?:s, s?s, s?i, s?i, s?b, s?o }",
@ -64,8 +64,8 @@ int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid)
"wait_seconds", &wait_seconds,
"max_retransmits", &rexmit,
"ordered", &ord,
"ice", &ice_json,
"format", &fmt_json
"ice", &json_ice,
"format", &json_format
);
if (ret)
throw ConfigError(json, err, "node-config-node-webrtc");
@ -81,10 +81,10 @@ int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid)
if (ord)
dci.reliability.unordered = !ord;
if (ice_json) {
if (json_ice) {
json_t *json_servers = nullptr;
ret = json_unpack_ex(ice_json, &err, 0, "{ s?: o }",
ret = json_unpack_ex(json_ice, &err, 0, "{ s?: o }",
"servers", &json_servers
);
if (ret)
@ -109,8 +109,8 @@ int WebRTCNode::parse(json_t *json, const uuid_t sn_uuid)
}
}
format = fmt_json
? FormatFactory::make(fmt_json)
format = json_format
? FormatFactory::make(json_format)
: FormatFactory::make("villas.binary");
assert(format);

View file

@ -67,10 +67,10 @@ RelayMessage::RelayMessage(json_t *json)
char *pass;
char *realm;
char *expires;
json_t *server_json;
json_t *json_server;
size_t i;
json_array_foreach(json, i, server_json) {
ret = json_unpack(server_json, "{ s:s, s:s, s:s, s:s, s:s }",
json_array_foreach(json, i, json_server) {
ret = json_unpack(json_server, "{ s:s, s:s, s:s, s:s, s:s }",
"url", &url,
"user", &user,
"pass", &pass,