#!/usr/bin/python


#  RFIDIOtconfig.py - shared settings for local RFIDIOt
# 
#  Adam Laurie <adam@algroup.co.uk>
#  http://rfidiot.org/
# 
#  This code is copyright (c) Adam Laurie, 2006, All rights reserved.
#  For non-commercial use only, the following terms apply - for all other
#  uses, please contact the author:
#
#    This code is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This code is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#

import RFIDIOt
import getopt
import sys
import os


debug= False

# help flag (-h) set?
help= False

# change the following sections to match your serial port
# bluetooth connections need at least 1 second timeout to establish connection

# serial port (can be overridden with -l)

# ignored for PCSC
#line= "/dev/ttyS0"
#line= "/dev/ttyS1"
line= "/dev/ttyUSB0"
# for Windows
#line= "COM4"

# reader type (can be overridden with -R)
readertype= RFIDIOt.rfidiot.READER_ACG
#readertype= RFIDIOt.rfidiot.READER_FROSCH
#readertype= RFIDIOt.rfidiot.READER_DEMOTAG
# READER_PCSC is a meta type. Actual subtype will be auto-determined.
#readertype= RFIDIOt.rfidiot.READER_PCSC

# PCSC reader number (can be overridden with -r)
readernum= 0

# serial port speed (can be overridden with -s)
# ignored for PCSC
#speed= 9600
#speed= 57600
speed= 115200
#speed= 230400
#speed= 460800

# reader timeout (can be overriden with -t)
# ignored for PCSC
timeout= 1

def printoptions():
	print '\nOptions:\n'
	print '\t-d\t\tDebug on'
	print '\t-h\t\tPrint detailed help message'
	print '\t-r <num>\tUse PCSC device number <num> (implies -R READER_PCSC)'
	print '\t-R <type>\tReader/writer type (see source of RFIDIOt.py for types)'
	print '\t-l <line>\tLine to use for reader/writer'
	print '\t-L\t\tList available PCSC devices'
	print '\t-s <baud>\tSpeed of reader/writer'
	print '\t-t <seconds>\tTimeout for inactivity of reader/writer'
	print

# check for global overrides
# 'args' will be set to remaining arguments (if any)
try:
	opts, args  = getopt.getopt(sys.argv[1:],'dhr:R:l:Ls:t:')
	for o, a in opts:
		if o == '-d':
			debug= True
		if o == '-h':
			help= True
		if o == '-r':
			readernum= a
			readertype= RFIDIOt.rfidiot.READER_PCSC
		if o == '-R':
			readertype= a
		if o == '-l':
			line= a
		if o == '-L':
			readertype= RFIDIOt.rfidiot.READER_PCSC
			readernum= 0
			card= RFIDIOt.rfidiot(readernum,readertype,line,speed,timeout,debug)
			card.pcsc_listreaders()
			os._exit(True)
		if o == '-s':
			speed= int(a)
		if o == '-t':
			timeout= int(a)
	card= RFIDIOt.rfidiot(readernum,readertype,line,speed,timeout,debug)
except getopt.GetoptError,e:
   		print "RFIDIOtconfig module ERROR: %s" % e
		printoptions()
		args= []
