/usr/lib/neard/tools/test-adapter is in neard-tools 0.16-0.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #!/usr/bin/python
import sys
import dbus
import neardutils
bus = dbus.SystemBus()
def extract_list(list):
val = "["
for i in list:
val += " " + str(i)
val += " ]"
return val
def usage():
print("Usage: %s <command>" % (sys.argv[0]) )
print("")
print(" list")
print(" powered nfcX [on/off]")
print(" poll nfcX [on/off] [Initiator/Target/Dual]")
sys.exit(1)
if (len(sys.argv) < 2):
usage()
if (sys.argv[1] == "list"):
if (len(sys.argv) < 3):
objects = neardutils.get_managed_objects()
for path, interfaces in objects.iteritems():
if "org.neard.Adapter" not in interfaces:
continue
print(" [ %s ]" % (path))
props = interfaces["org.neard.Adapter"]
for (key, value) in props.items():
if (key == "Protocols"):
val = extract_list(value)
print(" %s = %s" % (key, val))
elif key in ["Powered", "Polling"]:
if value == dbus.Boolean(1):
val = "true"
else:
val = "false"
print(" %s = %s" % (key, val))
else:
print(" %s = %s" % (key, value))
sys.exit(0)
if (sys.argv[1] == "powered"):
if (len(sys.argv) < 4):
usage()
else:
path = "/org/neard/" + sys.argv[2]
adapter_path = neardutils.find_adapter(path).object_path
adapter = dbus.Interface(bus.get_object("org.neard", adapter_path),
"org.freedesktop.DBus.Properties")
if (sys.argv[3] == "on"):
value = dbus.Boolean(1)
elif (sys.argv[3] == "off"):
value = dbus.Boolean(0)
else:
value = dbus.Boolean(sys.argv[3])
try:
adapter.Set("org.neard.Adapter", "Powered", value)
except dbus.DBusException, error:
print "%s: %s" % (error._dbus_error_name, error.message)
sys.exit(0)
if (sys.argv[1] == "poll"):
if (len(sys.argv) < 4):
usage()
else:
path = "/org/neard/" + sys.argv[2]
adapter = neardutils.find_adapter(path)
if (sys.argv[3] == "on"):
if (len(sys.argv) == 4):
mode = "Initiator"
else:
mode = sys.argv[4]
try:
adapter.StartPollLoop(mode)
except dbus.DBusException, error:
print "%s: %s" % (error._dbus_error_name, error.message)
elif (sys.argv[3] == "off"):
try:
adapter.StopPollLoop()
except dbus.DBusException, error:
print "%s: %s" % (error._dbus_error_name, error.message)
else:
usage()
sys.exit(0)
usage()
|