mirror of
https://github.com/RfidResearchGroup/ChameleonMini.git
synced 2026-05-12 11:20:37 -07:00
Added Options
Added GetUID, DumpMFU, Identify, LButton_Long and RButton_Long.
This commit is contained in:
+64
-19
@@ -11,8 +11,8 @@ import datetime
|
||||
def verboseLog(text):
|
||||
formatString = "[{}] {}"
|
||||
timeString = datetime.datetime.utcnow()
|
||||
print(formatString.format(timeString, text), file=sys.stderr)
|
||||
|
||||
print(formatString.format(timeString, text), sys.stderr)
|
||||
|
||||
# Command funcs
|
||||
def cmdInfo(chameleon, arg):
|
||||
return "{}".format(chameleon.cmdVersion()['response'])
|
||||
@@ -27,11 +27,11 @@ def cmdSetting(chameleon, arg):
|
||||
return "Setting has been changed to {}".format(chameleon.cmdSetting()['response'])
|
||||
else:
|
||||
return "Change setting to {} failed: {}".format(arg, result['statusText'])
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
def cmdUID(chameleon, arg):
|
||||
result = chameleon.cmdUID(arg)
|
||||
|
||||
|
||||
if (arg is None):
|
||||
return "{}".format(result['response'])
|
||||
else:
|
||||
@@ -40,8 +40,17 @@ def cmdUID(chameleon, arg):
|
||||
else:
|
||||
return "Setting UID to {} failed: {}".format(arg, result['statusText'])
|
||||
|
||||
def cmdGetUID(chameleon, arg):
|
||||
return "{}".format(chameleon.cmdGetUID()['response'])
|
||||
|
||||
def cmdIdentify(chameleon, arg):
|
||||
return "{}".format(chameleon.cmdIdentify()['response'])
|
||||
|
||||
def cmdDumpMFU(chameleon, arg):
|
||||
return "{}".format(chameleon.cmdDumpMFU()['response'])
|
||||
|
||||
def cmdConfig(chameleon, arg):
|
||||
result = chameleon.cmdConfig(arg)
|
||||
result = chameleon.cmdConfig(chameleon, arg)
|
||||
|
||||
if (arg is None):
|
||||
return "Current configuration: {}".format(result['response'])
|
||||
@@ -62,7 +71,7 @@ def cmdDownload(chameleon, arg):
|
||||
with open(arg, 'wb') as fileHandle:
|
||||
bytesReceived = chameleon.cmdDownloadDump(fileHandle)
|
||||
return "{} Bytes successfully written to {}".format(bytesReceived, arg)
|
||||
|
||||
|
||||
def cmdLog(chameleon, arg):
|
||||
with open(arg, 'wb') as fileHandle:
|
||||
bytesReceived = chameleon.cmdDownloadLog(fileHandle)
|
||||
@@ -70,7 +79,7 @@ def cmdLog(chameleon, arg):
|
||||
|
||||
def cmdLButton(chameleon, arg):
|
||||
result = chameleon.cmdLButton(arg)
|
||||
|
||||
|
||||
if (arg is None):
|
||||
return "Current left button action: {}".format(result['response'])
|
||||
else:
|
||||
@@ -81,9 +90,22 @@ def cmdLButton(chameleon, arg):
|
||||
else:
|
||||
return "Setting left button action to {} failed: {}".format(arg, result['statusText'])
|
||||
|
||||
def cmdLButtonLong(chameleon, arg):
|
||||
result = chameleon.cmdLButtonLong(arg)
|
||||
|
||||
if (arg is None):
|
||||
return "Current long press left button action: {}".format(result['response'])
|
||||
else:
|
||||
if (arg == chameleon.SUGGEST_CHAR):
|
||||
return "Possible long press left button actions: {}".format(", ".join(result['suggestions']))
|
||||
elif (result['statusCode'] in chameleon.STATUS_CODES_SUCCESS):
|
||||
return "Long press left button action has been set to {}".format(chameleon.cmdLButtonLong()['response'])
|
||||
else:
|
||||
return "Setting long press left button action to {} failed: {}".format(arg, result['statusText'])
|
||||
|
||||
def cmdRButton(chameleon, arg):
|
||||
result = chameleon.cmdRButton(arg)
|
||||
|
||||
|
||||
if (arg is None):
|
||||
return "Current right button action: {}".format(result['response'])
|
||||
else:
|
||||
@@ -94,9 +116,22 @@ def cmdRButton(chameleon, arg):
|
||||
else:
|
||||
return "Setting right button action to {} failed: {}".format(arg, result['statusText'])
|
||||
|
||||
def cmdRButtonLong(chameleon, arg):
|
||||
result = chameleon.cmdRButtonLong(arg)
|
||||
|
||||
if (arg is None):
|
||||
return "Current long press right button action: {}".format(result['response'])
|
||||
else:
|
||||
if (arg == chameleon.SUGGEST_CHAR):
|
||||
return "Possible long press right button actions: {}".format(", ".join(result['suggestions']))
|
||||
elif (result['statusCode'] in chameleon.STATUS_CODES_SUCCESS):
|
||||
return "Long press right button action has been set to {}".format(chameleon.cmdRButtonLong()['response'])
|
||||
else:
|
||||
return "Setting long press right button action to {} failed: {}".format(arg, result['statusText'])
|
||||
|
||||
def cmdGreenLED(chameleon, arg):
|
||||
result = chameleon.cmdGreenLED(arg)
|
||||
|
||||
|
||||
if (arg is None):
|
||||
return "Current green LED function: {}".format(result['response'])
|
||||
else:
|
||||
@@ -109,7 +144,7 @@ def cmdGreenLED(chameleon, arg):
|
||||
|
||||
def cmdRedLED(chameleon, arg):
|
||||
result = chameleon.cmdRedLED(arg)
|
||||
|
||||
|
||||
if (arg is None):
|
||||
return "Current red LED function: {}".format(result['response'])
|
||||
else:
|
||||
@@ -119,7 +154,7 @@ def cmdRedLED(chameleon, arg):
|
||||
return "Red LED function has been set to {}".format(chameleon.cmdRedLED()['response'])
|
||||
else:
|
||||
return "Setting red LED function to {} failed: {}".format(arg, result['statusText'])
|
||||
|
||||
|
||||
# Custom class for argparse
|
||||
class CmdListAction(argparse.Action):
|
||||
def __init__(self, option_strings, dest, default=False, required=False,
|
||||
@@ -127,19 +162,19 @@ class CmdListAction(argparse.Action):
|
||||
super(CmdListAction, self).__init__(
|
||||
option_strings=option_strings, dest=dest, nargs=nargs, const=const, default=default,
|
||||
required=required, help=help, metavar=metavar, type=type, choices=choices)
|
||||
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
# Create new attribute cmdList if not exist and append command to list
|
||||
if not hasattr(namespace, "cmdList"):
|
||||
setattr(namespace, "cmdList", [])
|
||||
|
||||
|
||||
namespace.cmdList.append([self.dest, values])
|
||||
|
||||
def main():
|
||||
argParser = argparse.ArgumentParser(description="Controls the Chameleon through the command line")
|
||||
argParser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=0, help="output verbose")
|
||||
argParser.add_argument("-p", "--port", dest="port", metavar="COMPORT", help="specify device's comport")
|
||||
|
||||
|
||||
# Add the commands using custom action that populates a list in the order the arguments are given
|
||||
cmdArgGroup = argParser.add_argument_group(title="Chameleon commands", description="These arguments can appear multiple times and are executed in the order they are given on the command line. "
|
||||
"Some of these arguments can be used with '" + Chameleon.Device.SUGGEST_CHAR + "' as parameter to get a list of suggestions.")
|
||||
@@ -149,13 +184,18 @@ def main():
|
||||
cmdArgGroup.add_argument("-i", "--info", dest="info", action=CmdListAction, nargs=0, help="retrieve the version information")
|
||||
cmdArgGroup.add_argument("-s", "--setting", dest="setting", action=CmdListAction, nargs='?', type=int, choices=Chameleon.VALID_SETTINGS, help="retrieve or set the current setting")
|
||||
cmdArgGroup.add_argument("-U", "--uid", dest="uid", action=CmdListAction, nargs='?', help="retrieve or set the current UID")
|
||||
cmdArgGroup.add_argument("-gu", "--getuid", dest="getuid", action=CmdListAction, nargs='?', help="retrieve UID of device in range")
|
||||
cmdArgGroup.add_argument("-I", "--identify", dest="identify", action=CmdListAction, nargs='?', help="identify device in range")
|
||||
cmdArgGroup.add_argument("-D", "--dumpmfu", dest="dumpmfu", action=CmdListAction, nargs='?', help="dump information about card in range")
|
||||
cmdArgGroup.add_argument("-c", "--config", dest="config", action=CmdListAction, metavar="CFGNAME", nargs='?', help="retrieve or set the current configuration")
|
||||
cmdArgGroup.add_argument("-lb", "--lbutton", dest="lbutton", action=CmdListAction, metavar="ACTION", nargs='?', help="retrieve or set the current left button action")
|
||||
cmdArgGroup.add_argument("-lbl", "--lbuttonlong", dest="lbutton_long", action=CmdListAction, metavar="ACTION", nargs='?', help="retrieve or set the current left button long press action")
|
||||
cmdArgGroup.add_argument("-rb", "--rbutton", dest="rbutton", action=CmdListAction, metavar="ACTION", nargs='?', help="retrieve or set the current right button action")
|
||||
cmdArgGroup.add_argument("-rbl", "--rbuttonlong", dest="rbutton_long", action=CmdListAction, metavar="ACTION", nargs='?', help="retrieve or set the current right button long press action")
|
||||
cmdArgGroup.add_argument("-gl", "--gled", dest="gled", action=CmdListAction, metavar="FUNCTION", nargs='?', help="retrieve or set the current green led function")
|
||||
cmdArgGroup.add_argument("-rl", "--rled", dest="rled", action=CmdListAction, metavar="FUNCTION", nargs='?', help="retrieve or set the current red led function")
|
||||
args = argParser.parse_args()
|
||||
|
||||
|
||||
if (args.verbose):
|
||||
verboseFunc = verboseLog
|
||||
else:
|
||||
@@ -163,7 +203,7 @@ def main():
|
||||
|
||||
# Instantiate device object and connect
|
||||
chameleon = Chameleon.Device(verboseFunc)
|
||||
|
||||
|
||||
if (args.port):
|
||||
if (chameleon.connect(args.port)):
|
||||
# Generate a jumptable and execute all commands in the order they are given on the command line
|
||||
@@ -171,11 +211,16 @@ def main():
|
||||
"setting" : cmdSetting,
|
||||
"info" : cmdInfo,
|
||||
"uid" : cmdUID,
|
||||
"getuid" : cmdGetUID,
|
||||
"identify" : cmdIdentify,
|
||||
"dumpmfu" : cmdDumpMFU,
|
||||
"config" : cmdConfig,
|
||||
"upload" : cmdUpload,
|
||||
"download" : cmdDownload,
|
||||
"log" : cmdLog,
|
||||
"lbutton" : cmdLButton,
|
||||
"lbutton_long" : cmdLButtonLong,
|
||||
"rbutton_long" : cmdRButtonLong,
|
||||
"rbutton" : cmdRButton,
|
||||
"gled" : cmdGreenLED,
|
||||
"rled" : cmdRedLED,
|
||||
@@ -197,9 +242,9 @@ def main():
|
||||
print("List of potential Chameleons connected to the system:")
|
||||
for port in Chameleon.Device.listDevices():
|
||||
print(port)
|
||||
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user