@@ -915,29 +915,14 @@ struct UdpardRxRPCPort
915915};
916916
917917/// A service dispatcher is a collection of RPC-service RX ports.
918- ///
919- /// In Cyphal/UDP, each node has a specific IP multicast group address where RPC-service transfers destined to that
920- /// node are sent to. This is similar to subject (topic) multicast group addressed except that the node-ID takes
921- /// the place of the subject-ID. The IP multicast group address is derived from the local node-ID.
922- /// This address is available in the field named "udp_ip_endpoint".
923- /// The application is expected to open a separate socket bound to that endpoint per redundant interface,
924- /// and then feed the UDP datagrams received from these sockets into udpardRxRPCDispatcherReceive,
925- /// collecting UdpardRxRPCTransfer instances at the output.
926- ///
927918/// Anonymous nodes (nodes without a node-ID of their own) cannot use RPC-services.
928919struct UdpardRxRPCDispatcher
929920{
930921 /// The local node-ID has to be stored to facilitate correctness checking of incoming transfers.
931- /// This value shall not be modified after initialization. If the local node needs to change its node-ID,
932- /// this dispatcher instance must be destroyed and a new one created instead.
922+ /// This value shall not be modified.
933923 /// READ-ONLY
934924 UdpardNodeID local_node_id ;
935925
936- /// The IP address and UDP port number where UDP/IP datagrams carrying RPC-service transfers destined to this node
937- /// will be sent.
938- /// READ-ONLY
939- struct UdpardUDPIPEndpoint udp_ip_endpoint ;
940-
941926 /// Refer to UdpardRxMemoryResources.
942927 struct UdpardRxMemoryResources memory ;
943928
@@ -956,23 +941,29 @@ struct UdpardRxRPCTransfer
956941
957942/// To begin receiving RPC-service requests and/or responses, the application should do this:
958943///
959- /// 1. Create a new UdpardRxRPCDispatcher instance.
944+ /// 1. Create a new UdpardRxRPCDispatcher instance and initialize it by calling udpardRxRPCDispatcherInit .
960945///
961- /// 2. Initialize it by calling udpardRxRPCDispatcherInit. Observe that a valid node-ID is required here.
962- /// If the application has to perform a plug-and-play node-ID allocation, it has to complete that beforehand.
963- /// The dispatcher is not needed to perform PnP node-ID allocation.
946+ /// 2. Announce its interest in specific RPC-services (requests and/or responses) by calling
947+ /// udpardRxRPCDispatcherListen per each. This can be done at any later point as well.
964948///
965- /// 3. Per redundant network interface:
966- /// - Create a new socket bound to the IP multicast group address and UDP port number specified in the
967- /// udp_ip_endpoint field of the initialized RPC dispatcher instance. The library will determine the
968- /// endpoint to use based on the node-ID.
949+ /// 3. When the local node-ID is known, invoke udpardRxRPCDispatcherStart to inform the library of the
950+ /// node-ID value of the local node, and at the same time obtain the address of the UDP/IP multicast group
951+ /// to bind the socket(s) to. This step can be taken before or after the RPC-service port registration.
952+ /// If the application has to perform a plug-and-play node-ID allocation, it has to complete that beforehand
953+ /// (the dispatcher is not needed for PnP node-ID allocation).
969954///
970- /// 4. Announce its interest in specific RPC-services (requests and/or responses) by calling
971- /// udpardRxRPCDispatcherListen per each. This can be done at any later point as well.
955+ /// 4. Having obtained the UDP/IP endpoint in the previous step, do per redundant network interface:
956+ /// - Create a new socket bound to the IP multicast group address and UDP port number obtained earlier.
957+ /// The multicast group address depends on the local node-ID.
972958///
973959/// 5. Read data from the sockets continuously and forward each received UDP datagram to
974960/// udpardRxRPCDispatcherReceive, along with the index of the redundant interface
975- /// the datagram was received on. Only those services that were announced in step 4 will be processed.
961+ /// the datagram was received on. Only those services that were announced in step 3 will be processed.
962+ ///
963+ /// The reason the local node-ID has to be specified via a separate call is to allow the application to set up the
964+ /// RPC ports early, without having to be aware of its own node-ID. This is useful for applications that perform
965+ /// plug-and-play node-ID allocation. Applications where PnP is not needed will simply call both functions
966+ /// at the same time during early initialization.
976967///
977968/// There is no resource deallocation function ("free") for the RPC dispatcher. This is because the dispatcher
978969/// does not own any resources. To dispose of a dispatcher safely, the application shall invoke
@@ -983,9 +974,31 @@ struct UdpardRxRPCTransfer
983974///
984975/// The time complexity is constant. This function does not invoke the dynamic memory manager.
985976int_fast8_t udpardRxRPCDispatcherInit (struct UdpardRxRPCDispatcher * const self ,
986- const UdpardNodeID local_node_id ,
987977 const struct UdpardRxMemoryResources memory );
988978
979+ /// This function must be called exactly once to complete the initialization of the RPC dispatcher.
980+ /// It takes the node-ID of the local node, which is used to derive the UDP/IP multicast group address
981+ /// to bind the sockets to, which is returned via the out parameter.
982+ ///
983+ /// In Cyphal/UDP, each node has a specific IP multicast group address where RPC-service transfers destined to that
984+ /// node are sent to. This is similar to subject (topic) multicast group addressed except that the node-ID takes
985+ /// the place of the subject-ID. The IP multicast group address is derived from the local node-ID.
986+ ///
987+ /// The application is expected to open a separate socket bound to that endpoint per redundant interface,
988+ /// and then feed the UDP datagrams received from these sockets into udpardRxRPCDispatcherReceive,
989+ /// collecting UdpardRxRPCTransfer instances at the output.
990+ ///
991+ /// This function shall not be called more than once per dispatcher. If the local node needs to change its node-ID,
992+ /// this dispatcher instance must be destroyed and a new one created instead.
993+ ///
994+ /// The return value is 0 on success.
995+ /// The return value is a negated UDPARD_ERROR_ARGUMENT if any of the input arguments are invalid.
996+ ///
997+ /// The time complexity is constant. This function does not invoke the dynamic memory manager.
998+ int_fast8_t udpardRxRPCDispatcherStart (struct UdpardRxRPCDispatcher * const self ,
999+ const UdpardNodeID local_node_id ,
1000+ struct UdpardUDPIPEndpoint * const out_udp_ip_endpoint );
1001+
9891002/// This function lets the application register its interest in a particular service-ID and kind (request/response)
9901003/// by creating an RPC-service RX port. The port pointer shall retain validity until its unregistration or until
9911004/// the dispatcher is destroyed. The service instance shall not be moved or destroyed.
0 commit comments