2

Can I send fake RxFrameNtfs/DatagramNtfs to an app that is connected to the API from a webshell?
I.e. in the modems websh I wish create an ntf:

dgntf = new org.arl.unet.DatagramNtf(from:2,to:1,data:new String("hello"), priority:org.arl.unet.Priority.NORMAL, protocol:0, ttl:2)

And I want to send this to an app connected to the modem with a Python Unetsocket. Essentially what I'm looking for is a simple way to test the Python side that I can use on both a single simulated modem and a physical modem.

moerot
  • 131
  • 5

2 Answers2

3

If I correctly understood what you want is basic python tx.py and rx.py which communicate in both real and simulation environment. Then answer is yes.

For Simulation: You can run the 2-node-network.groovy from samples folder.

//2-node-network.groovy

import org.arl.fjage.*

///////////////////////////////////////////////////////////////////////////////
// display documentation

println '''
2-node network
--------------

Node A: tcp://localhost:1101, http://localhost:8081/
Node B: tcp://localhost:1102, http://localhost:8082/
'''

///////////////////////////////////////////////////////////////////////////////
// simulator configuration

platform = RealTimePlatform   // use real-time mode

// run the simulation forever
simulate {
  node 'A', location: [ 0.km, 0.km, -15.m], web: 8081, api: 1101, stack: "$home/etc/setup"
  node 'B', location: [ 1.km, 0.km, -15.m], web: 8082, api: 1102, stack: "$home/etc/setup"
}

Now open 2 seperate ipython3 terminal to test the functionality.

I would recommend open the rx side first so you don't miss the transmission.

C:\Users\jay_p>ipython3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from unetpy import UnetSocket
   ...: from unetpy import *
   ...: 
   ...: s = UnetSocket('localhost', 1102)
   ...: modem = s.getGateway()

In [2]: rx = modem.receive(RxFrameNtf, 5000) # this will wait till you receive ntf
   ...: # print rx data, you will get this once you tx data from other side             
   ...: print('from node', rx.from_, ':', bytearray(rx.data).decode()) 
Out[2] from node 204 : hello!

On Tx side :

C:\Users\jay_p>ipython3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from unetpy import UnetSocket
   ...: 
   ...: s = UnetSocket('localhost', 1101)

In [2]: s.send('hello!', 0)
Out[2]: True

In [3]: s.close()

You can also run this as tx.py and rx.py. Borrowed from Unet Documentations - section 2.5 .

# tx.py  
from unetpy import UnetSocket

s = UnetSocket('localhost', 1101)                
s.send('hello!', 0)                              
s.close()
# rx.py  
from unetpy import UnetSocket
from unetpy import *

s = UnetSocket('localhost', 1102)
modem = s.getGateway()                               
rx = modem.receive(RxFrameNtf, 5000)                                                
print('from node', rx.from_, ':', bytearray(rx.data).decode())  
s.close()

For real modems, you just need to change the IP address accordingly in the script and it would work flawlessly on modems as well.

Jay Patel
  • 1,374
  • 1
  • 8
  • 17
3

To add on, if you're doing this on a modem and wanted to send from the modem's shell, it's quite simple:

send new org.arl.unet.DatagramNtf(
  recipient: topic(agent("uwlink")),   // to make it appear as if it came from uwlink
  from: 2,
  to: 1,
  data: new String("hello"),
  priority: org.arl.unet.Priority.NORMAL,
  protocol: 0,
  ttl: 2
)
Mandar Chitre
  • 2,110
  • 6
  • 14