data variable is human readable and raw_data is frame encoded.
This commit is contained in:
parent
9544d6c85b
commit
f43f11f685
|
@ -32,26 +32,27 @@ def inventory(response):
|
|||
Return a list of dict describing tags.
|
||||
'''
|
||||
tags = list()
|
||||
if not response.data:
|
||||
if not response.raw_data:
|
||||
return tags
|
||||
nb_tags = int(response.data[0].encode('hex'), 16)
|
||||
end = len(response.data)
|
||||
nb_tags = int(response.raw_data[0].encode('hex'), 16)
|
||||
end = len(response.raw_data)
|
||||
index = 1
|
||||
for _ in range(0, nb_tags):
|
||||
tag = dict()
|
||||
if index + 5 <= end:
|
||||
tag['EPCLen'] = int(response.data[index].encode('hex'), 16)
|
||||
tag['EPCLen'] = int(response.raw_data[index].encode('hex'), 16)
|
||||
index += 1
|
||||
else :
|
||||
raise MalformedDataError('Data content is malformed.')
|
||||
if index + 3 + tag['EPCLen'] <= end:
|
||||
tag['EPC'] = response.data[index:index+tag['EPCLen']]
|
||||
tag['EPC'] = response.raw_data[index:index+tag['EPCLen']]
|
||||
index += tag['EPCLen']
|
||||
tag['AntID'] = int(response.data[index].encode('hex'), 16)
|
||||
tag['AntID'] = int(response.raw_data[index].encode('hex'), 16)
|
||||
index += 1
|
||||
tag['NbRead'] = int(response.data[index:index+2].encode('hex'), 16)
|
||||
tag['NbRead'] = \
|
||||
int(response.raw_data[index:index+2].encode('hex'), 16)
|
||||
index += 2
|
||||
else:
|
||||
raise MalformedDataError('Data content is malformed.')
|
||||
tags.append(tag)
|
||||
response.processed_data = tags
|
||||
response.data = tags
|
||||
|
|
12
demo.py
12
demo.py
|
@ -33,7 +33,7 @@ def inventory(reader):
|
|||
response = reader.send(command)
|
||||
command.pretty_print()
|
||||
response.pretty_print()
|
||||
for tag in response.processed_data:
|
||||
for tag in response.data:
|
||||
print "Tag: %s" % tag['EPC'].encode('hex')
|
||||
print "\t Read on logic port: %s" % tag['AntID']
|
||||
print "\t Times read on all logic ports: %s" % tag['NbRead']
|
||||
|
@ -49,7 +49,7 @@ def get_rf_settings(reader):
|
|||
command.pretty_print()
|
||||
response.pretty_print()
|
||||
i = 0
|
||||
for logic_port in response.processed_data:
|
||||
for logic_port in response.data:
|
||||
if logic_port['ScanDelay'] or logic_port['PowerAnt']:
|
||||
print "Logic port: %s" % i
|
||||
print "\tScanDelay: %s ms" % logic_port['ScanDelay']
|
||||
|
@ -69,7 +69,7 @@ def set_rf_settings(reader):
|
|||
}
|
||||
logic_ports = [logic_port]
|
||||
command = models.ReaderCommand(command_name='Set_RFSettings',
|
||||
reader=reader, data_to_process=logic_ports)
|
||||
reader=reader, data=logic_ports)
|
||||
response = reader.send(command)
|
||||
command.pretty_print()
|
||||
response.pretty_print()
|
||||
|
@ -86,7 +86,7 @@ def set_rf_settings_saved(reader):
|
|||
}
|
||||
logic_ports = [logic_port]
|
||||
command = models.ReaderCommand(command_name='Set_RFSettings_Saved',
|
||||
reader=reader, data_to_process=logic_ports)
|
||||
reader=reader, data=logic_ports)
|
||||
response = reader.send(command)
|
||||
command.pretty_print()
|
||||
response.pretty_print()
|
||||
|
@ -128,7 +128,7 @@ def test_4(reader):
|
|||
if __name__ == '__main__':
|
||||
reader = models.RFIDReader()
|
||||
# Detect same tags before and after changing RF parameters
|
||||
# test_1(reader)
|
||||
test_1(reader)
|
||||
|
||||
# Detect same tags before and after changing RF parameters and reader
|
||||
# reboot
|
||||
|
@ -139,4 +139,4 @@ if __name__ == '__main__':
|
|||
# Test reset : Reset_RFSettings besoin d'un reboot
|
||||
# test_4(reader)
|
||||
# Do hard reader reboot
|
||||
test_3(reader)
|
||||
# test_3(reader)
|
||||
|
|
34
models.py
34
models.py
|
@ -151,15 +151,13 @@ class Command():
|
|||
self.type_cmd = STANDARD_COMMANDS[self.command_name]['type']
|
||||
self.code_cmd = STANDARD_COMMANDS[self.command_name]['code']
|
||||
self.reserved = '\xaa\x55'
|
||||
self.raw_data = kwargs.pop('raw_data', '')
|
||||
self.data = kwargs.pop('data', '')
|
||||
data = self.data
|
||||
self.data_to_process = kwargs.pop('data_to_process', None)
|
||||
if self.data_to_process:
|
||||
if self.data:
|
||||
self.process_data()
|
||||
data = self.processed_data
|
||||
self.lout = utils.get_length_on_2_bytes(data)
|
||||
self.lout = utils.get_length_on_2_bytes(self.raw_data)
|
||||
self.command = self.rfu + self.type_cmd + self.code_cmd + \
|
||||
self.reserved + self.lout + data
|
||||
self.reserved + self.lout + self.raw_data
|
||||
|
||||
def set_command(self, string):
|
||||
self.command = string
|
||||
|
@ -219,21 +217,19 @@ class ReaderCommand(Command):
|
|||
self.address = kwargs.pop('mode', 'rs232')
|
||||
self.command_name = kwargs.pop('command_name', '')
|
||||
self.time = None
|
||||
self.processed_data = ''
|
||||
self.data = ''
|
||||
if self.command_name:
|
||||
self.rfu = '\x00'
|
||||
self.type_cmd = self.reader.commands[self.command_name]['type']
|
||||
self.code_cmd = self.reader.commands[self.command_name]['code']
|
||||
self.reserved = '\xaa\x55'
|
||||
self.raw_data = kwargs.pop('raw_data', '')
|
||||
self.data = kwargs.pop('data', '')
|
||||
data = self.data
|
||||
self.data_to_process = kwargs.pop('data_to_process', None)
|
||||
if self.data_to_process:
|
||||
if self.data:
|
||||
self.process_data()
|
||||
data = self.processed_data
|
||||
self.lout = utils.get_length_on_2_bytes(data)
|
||||
self.lout = utils.get_length_on_2_bytes(self.raw_data)
|
||||
self.command = self.rfu + self.type_cmd + self.code_cmd + \
|
||||
self.reserved + self.lout + data
|
||||
self.reserved + self.lout + self.raw_data
|
||||
|
||||
def process_data(self):
|
||||
try:
|
||||
|
@ -275,13 +271,13 @@ class Response():
|
|||
self.code.encode('hex'),
|
||||
self.message.encode('hex')))
|
||||
self.lin = int(self.response[2:4].encode('hex'), 16)
|
||||
self.data = None
|
||||
self.raw_data = None
|
||||
if self.lin:
|
||||
self.data = self.response[4:-2]
|
||||
if len(self.data) != self.lin:
|
||||
self.raw_data = self.response[4:-2]
|
||||
if len(self.raw_data) != self.lin:
|
||||
raise BadLengthMessageException(
|
||||
'Data length %d mismatch mength field %d (message: %s).'
|
||||
% (len(self.data), self.lin,
|
||||
% (len(self.raw_data), self.lin,
|
||||
self.message.encode('hex')))
|
||||
self.status_type = self.response[-2] # Reader 00 or standard 08
|
||||
'''if command.type_cmd != self.status_type:
|
||||
|
@ -306,8 +302,8 @@ class Response():
|
|||
raise UnknownResponseErrorType('Unknown type %s'
|
||||
% self.status_type.encode('hex'))
|
||||
self.time = None
|
||||
self.processed_data = None
|
||||
if self.data:
|
||||
self.data = None
|
||||
if self.raw_data:
|
||||
self.process_data()
|
||||
|
||||
def process_data(self):
|
||||
|
|
|
@ -32,22 +32,22 @@ def get_rfsettings(response):
|
|||
|
||||
Return a list of dict describing logic ports of the reader.
|
||||
'''
|
||||
if not response.data:
|
||||
if not response.raw_data:
|
||||
raise MalformedDataError('Data content is malformed.')
|
||||
if len(response.data) != 64:
|
||||
if len(response.raw_data) != 64:
|
||||
raise MalformedDataError('Data content is malformed.')
|
||||
logic_ports = list()
|
||||
for i in range(0, 16):
|
||||
logic_port = dict()
|
||||
logic_port['ScanDelay'] = int(response.data[i * 4:(i * 4) + 2]
|
||||
logic_port['ScanDelay'] = int(response.raw_data[i * 4:(i * 4) + 2]
|
||||
.encode('hex'), 16) * 10 # 0 ms ≤ ScanDelay ≤ 655350 ms ()
|
||||
power_ant_nb = int(response.data[(i * 4) + 2:(i * 4) + 4]
|
||||
power_ant_nb = int(response.raw_data[(i * 4) + 2:(i * 4) + 4]
|
||||
.encode('hex'), 16)
|
||||
logic_port['AntNb'] = power_ant_nb & 0x000f
|
||||
logic_port['PowerAnt'] = (power_ant_nb >> 4) / 10
|
||||
#[0E6h ≤ PowerAnt ≤ 136h] soit [23 dBm ≤ PowerAnt ≤ 31 dBm] (URF)
|
||||
logic_ports.append(logic_port)
|
||||
response.processed_data = logic_ports
|
||||
response.data = logic_ports
|
||||
|
||||
|
||||
def set_rfsettings(command):
|
||||
|
@ -57,9 +57,9 @@ def set_rfsettings(command):
|
|||
Return a string representing the data from a list of dict describing
|
||||
logic ports of the reader..
|
||||
'''
|
||||
if not command.data_to_process:
|
||||
if not command.data:
|
||||
raise MalformedDataError('Data content is malformed.')
|
||||
logic_ports = command.data_to_process
|
||||
logic_ports = command.data
|
||||
data = ''
|
||||
i = 0
|
||||
for logic_port in logic_ports:
|
||||
|
@ -74,7 +74,7 @@ def set_rfsettings(command):
|
|||
i += 1
|
||||
for _ in range(i, 16):
|
||||
data += '\x00\x00\x00\x00'
|
||||
command.processed_data = data
|
||||
command.raw_data = data
|
||||
|
||||
|
||||
def set_rfsettings_saved(command):
|
||||
|
|
Reference in New Issue