Simplify processing call in commands.
This commit is contained in:
parent
33938e4303
commit
ae0221349a
28
models.py
28
models.py
|
@ -145,6 +145,7 @@ class Command():
|
|||
self.address = kwargs.pop('mode', 'rs232')
|
||||
self.command_name = kwargs.pop('command_name', '')
|
||||
self.time = None
|
||||
self.data_processed = ''
|
||||
if self.command_name:
|
||||
self.rfu = '\x00'
|
||||
self.type_cmd = STANDARD_COMMANDS[self.command_name]['type']
|
||||
|
@ -164,15 +165,10 @@ class Command():
|
|||
self.command = string
|
||||
|
||||
def process_data(self):
|
||||
if self.data_to_process and self.command_name:
|
||||
core_method_name = self.command_name.lower()
|
||||
try:
|
||||
core_method = getattr(core_standard, core_method_name)
|
||||
self.data_processed = core_method(self.data_to_process)
|
||||
except:
|
||||
self.data_processed = ''
|
||||
else:
|
||||
self.data_processed = ''
|
||||
try:
|
||||
getattr(core_standard, self.command_name.lower())(self)
|
||||
except:
|
||||
pass
|
||||
|
||||
def build_message(self):
|
||||
self.sof = '\x02'
|
||||
|
@ -223,6 +219,7 @@ class ReaderCommand(Command):
|
|||
self.address = kwargs.pop('mode', 'rs232')
|
||||
self.command_name = kwargs.pop('command_name', '')
|
||||
self.time = None
|
||||
self.data_processed = ''
|
||||
if self.command_name:
|
||||
self.rfu = '\x00'
|
||||
self.type_cmd = self.reader.commands[self.command_name]['type']
|
||||
|
@ -239,15 +236,10 @@ class ReaderCommand(Command):
|
|||
self.reserved + self.lout + data
|
||||
|
||||
def process_data(self):
|
||||
if self.data_to_process and self.command_name:
|
||||
core_method_name = self.command_name.lower()
|
||||
try:
|
||||
core_method = getattr(self.reader.core, core_method_name)
|
||||
self.data_processed = core_method(self.data_to_process)
|
||||
except:
|
||||
self.data_processed = ''
|
||||
else:
|
||||
self.data_processed = ''
|
||||
try:
|
||||
getattr(self.reader.core, self.command_name.lower())(self)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class Response():
|
||||
|
|
Reference in New Issue