Commit ec8f27cd authored by Andrey Filippov's avatar Andrey Filippov

added permissions handling and readonly mode

parent 82409d0a
...@@ -31,7 +31,7 @@ __maintainer__ = "Oleg Dzhimiev" ...@@ -31,7 +31,7 @@ __maintainer__ = "Oleg Dzhimiev"
__email__ = "oleg@elphel.com" __email__ = "oleg@elphel.com"
__status__ = "Released" __status__ = "Released"
import array, fcntl import array, fcntl, os, errno
import argparse # http://docs.python.org/2/howto/argparse.html import argparse # http://docs.python.org/2/howto/argparse.html
IOCTL_GPIOGET = 0x8000 IOCTL_GPIOGET = 0x8000
...@@ -39,20 +39,26 @@ IOCTL_GPIOSET = 0x8001 ...@@ -39,20 +39,26 @@ IOCTL_GPIOSET = 0x8001
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-d', '--device', default="/dev/ttyUSB0", help='USB device. Default: /dev/ttyUSB0') parser.add_argument('-d', '--device', default="/dev/ttyUSB0", help='USB device. Default: /dev/ttyUSB0')
parser.add_argument("gpio_value", help="hex value for GPIO. Example (GPIO[3:0]): 0xf - all 1's, 0x0 - all 0's") parser.add_argument("gpio_value", default=None, nargs='?', help="hex value for GPIO. Example (GPIO[3:0]): 0xf - all 1's, 0x0 - all 0's. If not specified - read GPIO only")
parser.add_argument('-m', '--mask', default="0xff",help='hex value for masking out GPIO bits: 1 - enable rewrite, 0 - disable. Example (GPIO[3:0]): -m 0xf') parser.add_argument('-m', '--mask', default="0xff",help='hex value for masking out GPIO bits: 1 - enable rewrite, 0 - disable. Example (GPIO[3:0]): -m 0xf')
args = parser.parse_args() args = parser.parse_args()
device=args.device device=args.device
mask = int(args.mask,0) if args.gpio_value is None:
gpio = (int(args.gpio_value,0)<<16)|mask mask=0
gpio=0xff
else:
mask = int(args.mask,0)
gpio = (int(args.gpio_value,0)<<16)|mask
print ('Target GPIO value:'),gpio print ('Target GPIO value: 0x%x, mask: 0x%x'%(gpio,mask))
exit (0)
try: try:
fd = open(device, 'r+') fd = open(device, 'r+')
except: except IOError, ioex:
raise Exception(str(device)+' is not present') if (errno.errorcode[ioex.errno]=='EACCES'):
print "\nDid you forget to use 'sudo' ?\n"
raise Exception(str(device)+' - '+os.strerror(ioex.errno))
buf = array.array('l', [0]) buf = array.array('l', [0])
fcntl.ioctl(fd, IOCTL_GPIOGET, buf, 1) fcntl.ioctl(fd, IOCTL_GPIOGET, buf, 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment