Help understanding ping tutorial.

Somewhere in the ping tutorial, we were instructed to add these lines to Ping.cpp:

void Ping::tick() {
  // create and publish a ping message
  auto proto = tx_ping().initProto();
  proto.setMessage(get_message());
  tx_ping().publish();
}

Can someone explain this to me in more detail? I am new to software engineering so I am sure to misunderstand some fundamental things.

Here are a few specific questions:
1.
tx_ping().initProto();
Is this an initializer? I have never seen a c++ initializer look like this. It’s like…an initializer with a method attached to it or something?

How does get_message() know which message in the json file to get? (Does it even get messages from the json file?)

how does tx_ping().publish() know which object (in this case proto) to publish its message?

evan.lavizadeh,

tx_ping() is generated with macros with the Isaac SDK. As such the initialization function is a method associated with this object.

get_message() refers to the “config” section of the json configuration file for the component - see below - and takes “message” as the config string. If this section is not present it uses the default that was provided to the macro that creates the ‘message’ parameter: ISAAC_PARAM(std::string, message, “Hello World!”);

“config”: {
“ping” : {
“ping” : {
“message”: “My own hello world!”,
“tick_period” : “1Hz”

I would suggest you go through the documentation in “Developing Codelets in C++” where the json file structure is explained.

  1. When the TX object is created with the macro ISAAC_PROTO_TX(PingProto, ping); it’s associated with the correct object.

Thank you :)