How can I determine who the sender is when using UDP Receive block?

4 views (last 30 days)
Using the UDP Receive block (v. R2022a), I want to receive messages from multiple senders on one port and be able to determine who the sender is by outputting their IP address to the model. To do this I started by making a copy of the UDP receive block S-Function code and adding in lines to for a third output that will give us the remote address. It looks like there is a function that gets the sender's address and port:
size_t num_bytesRcvd = (size_t) ( udpSock->receive(buffer, ( numBytesAvail<UDP_MAX_WIDTH )? numBytesAvail:UDP_MAX_WIDTH, !RcvFromAny, fmAddArg, remoteAddress, &remotePort) );
And they get passed to this slmsg_ssMessageSend function:
if ( num_bytesRcvd > 0 ){
temp.IP_Address[0] = ((char *)&remoteAddress)[0];
temp.IP_Address[1] = ((char *)&remoteAddress)[1];
temp.IP_Address[2] = ((char *)&remoteAddress)[2];
temp.IP_Address[3] = ((char *)&remoteAddress)[3];
temp.IP_Port = remotePort;
...
slmsg_ssMessageSend(S, 0, &temp, 0);
Which I can't find anywhere in any of Matlab's files either.
The main issue I'm having now is trying to recompile the new UDP receive block we created. There are some header files included that aren't provided in the Matlab tree on my machine, so I can't figure out a way to do this without the header files. Does anyone have any recommendations to use the (old or new) UDP receive block to acheive the goal of outputting the sender address? Thanks in advance!
Examples of header files not included:
#include "messages/slMessagesSfcnBridge.h"
#include "SimulinkBlock/block_rtwcg.hpp"
#include "SimulinkBlock/SimType.hpp"
#include "cg_ir/facade/FixptConstructionFacade.hpp"
#include "cg_ir/const.hpp"
#include "cg_ir/expr.hpp"
#include "cg_ir/region.hpp"
#include "cg_ir/factory.hpp"
#include "cg_ir/builder/FcnBuilder.hpp"
#include "cg_ir/value/StaticMatrixValueCG.hpp" // for StaticMatrix...
#include "cg_ir/value/ValueTools.hpp"

Answers (1)

Garmit Pant
Garmit Pant on 1 Sep 2023
Hello Erica,
I understand that you are trying to receive messages from multiple senders on a single “UDP Receive” block and want to track the IP address of the sender of each message.
Please know that as per my findings, you don’t need to use an “S-Function” block to write custom code to get the IP aAddress of the sender. You can use the “UDP Receive block” from the Simulink Real-Time/IP Library to do so.
In this case, you need to enable the Enable Simulink messages parameter of the “UDP Receive” block that is set to ‘off’ by default. Doing so, you can display the sender’s IP address through the message received by the Receive block.
Also, please note that you will require Simulink R2022a or later releases for this.
For further understanding, you can refer to the following MathWorks Documentation:
I hope this helps!

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!