From e0b4a720ddcfa91a064e17f3ae2f9aabd190eff2 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 8 Apr 2021 11:54:38 +0200 Subject: [PATCH] - added/updated comments in SV publisher example --- examples/sv_publisher/sv_publisher_example.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/sv_publisher/sv_publisher_example.c b/examples/sv_publisher/sv_publisher_example.c index aa088fe9..48975351 100644 --- a/examples/sv_publisher/sv_publisher_example.c +++ b/examples/sv_publisher/sv_publisher_example.c @@ -1,8 +1,7 @@ /* - * sv_subscriber_example.c - * - * Example program for Sampled Values (SV) subscriber + * sv_publisher_example.c * + * Example program for Sampled Values (SV) publisher */ #include @@ -35,12 +34,16 @@ main(int argc, char** argv) if (svPublisher) { + /* Create first ASDU and add data points */ + SVPublisher_ASDU asdu1 = SVPublisher_addASDU(svPublisher, "svpub1", NULL, 1); int float1 = SVPublisher_ASDU_addFLOAT(asdu1); int float2 = SVPublisher_ASDU_addFLOAT(asdu1); int ts1 = SVPublisher_ASDU_addTimestamp(asdu1); + /* Create second ASDU and add data points */ + SVPublisher_ASDU asdu2 = SVPublisher_addASDU(svPublisher, "svpub2", NULL, 1); int float3 = SVPublisher_ASDU_addFLOAT(asdu2); @@ -57,6 +60,8 @@ main(int argc, char** argv) Timestamp_clearFlags(&ts); Timestamp_setTimeInMilliseconds(&ts, Hal_getTimeInMs()); + /* update the values in the SV ASDUs */ + SVPublisher_ASDU_setFLOAT(asdu1, float1, fVal1); SVPublisher_ASDU_setFLOAT(asdu1, float2, fVal2); SVPublisher_ASDU_setTimestamp(asdu1, ts1, ts); @@ -65,14 +70,22 @@ main(int argc, char** argv) SVPublisher_ASDU_setFLOAT(asdu2, float4, fVal2 * 2); SVPublisher_ASDU_setTimestamp(asdu2, ts2, ts); + /* update the sample counters */ + SVPublisher_ASDU_increaseSmpCnt(asdu1); SVPublisher_ASDU_increaseSmpCnt(asdu2); fVal1 += 1.1f; fVal2 += 0.1f; + /* send the SV message */ SVPublisher_publish(svPublisher); + /* + * For real applications this sleep time has to be adjusted to match the SV sample rate! + * Platform specific functions like usleep or timer interrupt service routines have to be used instead + * to realize the required time accuracy for sending messages. + */ Thread_sleep(50); }