PDA

View Full Version : rpcSourceAddr() or vmStat(VM_NET,ID)


Keith Taft
12-13-2009, 10:43 PM
I would like to be able to read the node ID of the message being sent but am unable to implement it properly. I am running script in Portal 2.2.29. I am also unable to use mCast out of portal, but rpc using hard coded node address works.

You can see my efforts to make this work but it never gets to "made it this far". It does get to "Here!" and then seems to stop.

def setButtonCount(newCount,iNode):
"""Set the new button count"""
global buttonCount
print "Here!"
print "newCount = " + str(newCount)
#vmStat(VM_NET,ID)
print "ID = " + str(vmStat(VM_NET,ID))
#print str(rpcSourceAddr())
print "made it this far"

Can you shed some light on these issues?

Thanks - Keith

kbanks
12-14-2009, 01:58 PM
It probably doesn't like the


print "ID = " + str(vmStat(VM_NET,ID))


vmStat() is usually called externally (usually by Portal).

If you (yourself, in your script) want to know your channel, call built-in getChannel(). If you want to know your Network ID, call getNetId().

It's also not necessary to "str()" those values to print them.

If you want to know your own SNAP Address, that is readable via localAddr().

If inside an RPC handler you want to know the SNAP Address of who invoked the RPC, call rpcSourceAddr().

Note that SNAP Addresses are "binary strings", and usually not directly printable. Take a look at the "hex" routines in hexSupport.py too.

Keith Taft
12-14-2009, 09:14 PM
When I add "print localAddr()" to a script, I get an error message.

The message is:

An error occurred while creating the SNAPpy Image:

name 'localAddr' is not defined.

What am I doing wrong?

Keith Taft
12-14-2009, 09:45 PM
I have also used the rpcSourceAddr() in Portal inside the rpc handler script and it just stops the code at that point. You can see in my original message the attempts to comment out statements to make the code run through. I have tried to print without the str() function and it doesn't make any difference. I am still stuck for the moment.

Thanks - Keith

kbanks
12-15-2009, 01:52 PM
The message is:

An error occurred while creating the SNAPpy Image:

name 'localAddr' is not defined.

What am I doing wrong?

My guess here would be you are "checking" or "loading" the script as a Portal script instead of as a SNAPpy script.

Be sure you are setting the "platform" drop down correctly at the top of the Edit window (if you are using the "Check Script" function). Be sure not to (attempt to) load Node scripts into Portal, and vice/versa.

kbanks
12-15-2009, 02:00 PM
I have also used the rpcSourceAddr() in Portal inside the rpc handler script and it just stops the code at that point. You can see in my original message the attempts to comment out statements to make the code run through. I have tried to print without the str() function and it doesn't make any difference. I am still stuck for the moment.


In Portal scripts you use the predefined variable remoteAddr instead of calling rpcSourceAdd().

Keith Taft
12-16-2009, 01:05 AM
Hi:

I need to run under the portal platform in order to run the CTypes calls. I am still unable to get the node ID using the different codes suggested. Do you have a code example running under portal that returns a nodes' ID? A Snappy script code example that discovers its' own Node ID running in a RF Engine would also be helpful. Perhaps I can figure out what I am doing wrong from an example's code.

-Thanks

mgenti
12-16-2009, 08:23 AM
An example that uses the remoteAddr in a Portal script is portalMcastCounter.py script that is included with the default installation. You could modify this script to print the remoteAddr to verify which node sent the last count.

It is important to note that names in Python and SNAPpy are case sensitive. If you are having problems accessing a variable double check your spelling and capitalization.

kbanks
12-16-2009, 10:45 AM
import binascii

def testFunc(pin):
print binascii.hexlify(remoteAddr)+"reported pin = "+str(pin)


I verified this from the Portal command line using:

rpc("\xbb\x16\x02","callback","testFunc2","readPin",1)

(Your node address will of course be different)

Note that you do not have to do anything on the node end for "remoteAddr" to work. The protocol itself contains source and destination address fields.

kbanks
12-16-2009, 10:48 AM
from synapse.hexSupport import *

def test():
dumpHex(localAddr())


You can test this using the INTERCEPT STDOUT button, and then invoking the function.