Inet framework: Send message from one host to another - wifi

I am new to Omnet++ and I am trying to simulate a Wifi network. I have successfully created a network consisting of an AP and some nodes and all the nodes are able to connect to the AP.
What I want to do is that once all the nodes are connected to the AP, a node (based on its IP address) should send a message to another node in the network. I have created the .msg file with all the required fields and it is successfully compiled by the message compiler to the corresponding _m.h and _m.cc files. I want this message to be sent to the other node.
How to proceed with this? Iknow it has to do something with the handleMessage() function but I can't find the file containing that function.
Thanks in advance for any kind of help.

To send the initial message you will have to use the send() when you initialize you node.
From the tictoc tutorial:
void Txc1::initialize()
{
// Initialize is called at the beginning of the simulation.
// To bootstrap the tic-toc-tic-toc process, one of the modules needs
// to send the first message. Let this be `tic'.
// Am I Tic or Toc?
if (strcmp("tic", getName()) == 0)
{
// create and send first message on gate "out". "tictocMsg" is an
// arbitrary string which will be the name of the message object.
cMessage *msg = new cMessage("tictocMsg");
send(msg, "out");
}
}
Then you want the nodes to be able to react. Their reaction can be silent -- just accept the message and delete it, or send another message in return.
For that you will need to implement the handleMessage() function inside the nodes .cc file.
void Txc1::handleMessage(cMessage *msg)
{
// The handleMessage() method is called whenever a message arrives
// at the module. Here, we just send it to the other module, through
// gate `out'. Because both `tic' and `toc' does the same, the message
// will bounce between the two.
send(msg, "out");
}

You can find the function in the .cc file in the same project or folder. Normally the name of the .cc file is close to the name of the .ned file that caries the details of the host or node or whatever you call it in your project.

Related

anylogic agent communication and message sending

In my model, I have some agents;
"Demand" agent,
"EnergyProducer1" agent
"EnergyProducer2" agent.
When my hourly energy demands are created in the Main agent with a function, the priority for satisfying this demand is belongs to "EnergyProducer1" agent. In this agent, I have a function that calculate energy production based on some situtations. The some part of the inside of this function is following;
**" if (statechartA.isStateActive(Operating.busy)) && ( main.heatLoadDemandPerHour >= heatPowerNominal) {
producedHeatPower = heatPowerNominal;
naturalGasConsumptionA = naturalGasConsumptionNominal;
send("boilerWorking",boiler);
} else ..... "**
Here my question is related to 4th line of the code. If my agent1 fails to satisfy the hourly demand, I have to say agent2 that " to satisfy rest of demand". If I send this message to agent2, its statechart will be active and the function of agent2 will be working. My question is that this all situations will be realized at the same hour ??? İf it is not, is accessing variables and parameters of other agent2 more appropiaote way???
I hope I could explain my problem.
thanks for your help in advance...
**Edited question...
As a general comment on your question, within AnyLogic environment sending messages is alway preferable to directly accessing variable and parameters of another agent.
Specifically in the example presented the send() function will schedule message delivery the next instance after the completion of the current function.
Update: A message in AnyLogic can be any Java class. Sending strings such as "boilerWorking" used in the example is good for general control, however if more information needs to be shared (such as a double value) then it is good practice to create a new Java class (let's call is ModelMessage and follow these instructions) with at least two properties msgStr and msgVal. With this new class sending a message changes from this:
...
send("boilerWorking", boiler);
...
to this:
...
send(new ModelMessage("boilerWorking",42.0), boiler);
...
and firing transitions in the statechart has to be changed to use if expression is true with expression being msg.msgString == "boilerWorking".
More information about Agent communication is available here.

Groovy read file line by line and store it into list

I have a file called apps.txt which has three app names in it
frontendapp
authorizationservice
connectorservice*
In jenkins pipeline i want to perform some operation on them one by one so i am trying to get them in groovy list using this code -
list = readFile.readFileLineByLine("${workspace}/apps.txt").collect {it}
for (item in list) {
println "I need to perform some operations on files"
}
But getting groovy.lang.MissingPropertyException.
If i use file class like this - list = new File("${workspace}/apps.txt").collect {it} then it search for a file on Jenkins master node only and i get fileNotFoundException.
If i use list = readFile("${workspace}/apps.txt").collect {it} then list gets values character by character. How i can get app names from apps.txt inorder to perform operation on each app.
Your attempts are close, but mix things up.
Those are working ways:
def list = new File("${workspace}/apps.txt").text.readLines()
Note the .text call inbetween.
def list = readFile("${workspace}/apps.txt").readLines()
Or with the helper Jenkins provides.
Side note: .collect{it} is just .collect() - and usually is only
needed to copy a list. Since the read lines from the file are already
eagerly read, those are copies.
This work for me in a windows worker
script {
def list = readFile("filesChanged").readLines()
for(item in list){
print item
bat('type '+item)
}
}

CAPL block node from sending messages

I have a CAPL file attached to a CAN node that periodically sends a message using the 'output' function. How can I use a second CAPL file to block the node sending the message (while doing everything that the node does) ?
You can add an output filter to your node, as shown below, to block the messages.
You can create a sysvar in your simulation, which will be used as a switch in your simulated *.can Network node.
You just have to condition the output code to the value of the system variable you created.
if (Sysvar_SimEnabled)
{
output(message);
output(message1);
output(message3);
}
This Sysvar_SimEnabled will be a global variable, thus can be set to any value from another *.can CAPL Network node.
You can stop all your cyclic messages, by canceling timers of Each message
Example:
message can1.0x12 message1;
msTimer tmessage1;
on timer tmessage1
{
output(message1); // sending message
setTimer(tmessage1,100); // set the cyclic time as 100ms
}
on envVar envmessage1
{
if (getValue(envmessage1) == 1)
{
setTimer(tmessage1,100); // set and start the cyclic time as 100ms
}
else
{
cancelTimer(tmessage1); // cancel the cyclic timer
}
}
if you just do envmessage1 = 0 in another node, it will stop the message, like the same for all messages, have to write environment variable, then you can control other Node messages.

CAPL Scripting - CAN C communication (Stop transmitting one message from DBC)

I am working on a CAPL script that has to allow all messages to transmit on a CAN C channel and stop transmitting one particular message from the database file.
Can anyone help with the method/function/code I can use?
Your question is vague, but I'm assuming you are going from one CAN channel to another. For instance, CAN C to CAN D (or CAN 3 to CAN 4), than you could do:
on message CAN3.0x7FF // This would be that one ID that stops at some point
{
message CAN4.0x7FF msg;
msg = this;
// Assuming you are receiving on CAN 3, and looking to transmit on CAN 4
if(this.dir == rx)
{
// Declare a global variable that sets to 1 when you want it to stop
if(MSG_STOP == 0)
output(msg);
}
}
on message CAN3.*
{
message CAN4.* msg;
msg = this;
if (this.dir == rx)
{
output (msg);
}
}
AFAIK, the only way to accomplish this is to disable any automatic transmission of messages (e.g. via the IG or Network IL) and transmit all messages manually from your CAPL script in timer callbacks. Transmission can be done using the output function and based on whichever criteria you define, you can choose not to call output for any messages which should be blocked.
If you are using the Interaction Layer (IL) in your simulation, and the DBC file cyclic times are correctly configured there are some CAPL functions that can be used for fault injection which will allow you to selectively start/stop transmitting certain messages:
on sysvar Sys_m0x461_Send {
/**********************************************************
* FAULT INJECTION Enable/Disable Msg Sending
**********************************************************/
if (#this) {
ILFaultInjectionEnableMsg(Message0x461fromDBC);
}
else {
ILFaultInjectionDisableMsg(Message0x461fromDBC);
}
}
In the example if the system variable (could be linked to a panel control, e.g. checkbox) equals '1' the message will transmit as defined in the DBC, otherwise the message sending is stopped.

Is it possible to pass command-line arguments to a new isolate from spawnUri()

When starting a new isolate with spawnUri(), is it possible to pass command line args into that new isolate?
eg: Command line:
dart.exe app.dart "Hello World"
In app.dart
#import("dart:isolate");
main() {
var options = new Options();
print(options.arguments); // prints ["Hello World"]
spawnUri("other.dart");
}
In other.dart
main() {
var options = new Options();
print(options.arguments); // prints [] when spawned from app.dart.
// Is it possible to supply
// Options from another isolate?
}
Although I can pass data into other.dart through its SendPort, the specific use I want is to use another dart app that hasn't been created with a recievePort callback (such as pub.dart, or any other command-line app).
As far as I can tell the answer is currently no, and it would be hard to simulate via message passing because the options would not be available in main().
I think there are two good feature requests here. One is to be able to pass options on spawn() so that a script can run the same from the root isolate or a spawned isolate.
The other feature, which could be used to implement the first, is a way to pass messages that are handled by libraries before main() is invoked so that objects that main() depends on can be initialized with data from the spawning isolate.
Your example doesn't call print(options.arguments); in other.dart using the current stable SDK.
However
spanUri("other.dart");
spawns an Uri. So how about spawnUri("other.dart?param=value#orViaHash"); and try if you can find the param/value pair via
print(options.executable);
print(options.script);

Resources