Skip to content

Commit

Permalink
fix error while handling transceive data
Browse files Browse the repository at this point in the history
  • Loading branch information
atitan committed Apr 5, 2018
1 parent 48c1d7f commit 74dce47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions lib/fubuki/protocols/a.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ def request(wakeup = false)
Fubuki.reader.config_reset

command = wakeup ? PICC_WUPA : PICC_REQA
status, _received_data, valid_bits = transceive(command, crc: false, framing_bit: 0x07)
status, received_data, valid_bits = transceive(command, crc: false, framing_bit: 7)

status == :status_ok && valid_bits == 0 # REQA or WUPA command return 16 bits(full byte)
# REQA or WUPA command return 16 bits(full byte)
return false unless status == :status_ok && valid_bits == 0

received_data
end

def wakeup
Expand Down
18 changes: 10 additions & 8 deletions lib/fubuki/readers/mfrc522.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def config_reset
transceiver_baud_rate(:rx, 106)

# Set PCD timer value for 302us default timer
internal_timer(@timer)
# 256 ticks = 77.4ms
internal_timer(256)
end

# Control transceive timeout value
Expand Down Expand Up @@ -181,22 +182,23 @@ def mifare_crypto1_deauthenticate
end

# Append CRC to buffer and check CRC or Mifare acknowledge
def transceive(protocol, send_data, accept_timeout: false, crc: true, framing_bit: 0)
def transceive(protocol, send_data, crc: true, framing_bit: 0)
unless crc || @built_in_crc_disabled
raise UsageError, 'Built-in CRC enabled while CRC is not wanted'
end

send_data = send_data.dup
send_data = [send_data] if send_data.is_a?(Integer)
if send_data.is_a?(Array)
send_data = send_data.dup
else
send_data = [send_data]
end
send_data.append_crc16(protocol) if @built_in_crc_disabled && crc

puts "Sending Data: #{send_data.to_bytehex}" if ENV['DEBUG']

# Transfer data
status, received_data, valid_bits = communicate_with_picc(PCD_Transceive, send_data, framing_bit)
return if status == :status_picc_timeout && accept_timeout
raise PICCTimeoutError if status == :status_picc_timeout
raise CommunicationError, status if status != :status_ok
return status if status != :status_ok

puts "Received Data: #{received_data.to_bytehex}" if ENV['DEBUG']
puts "Valid bits: #{valid_bits}" if ENV['DEBUG']
Expand All @@ -206,7 +208,7 @@ def transceive(protocol, send_data, accept_timeout: false, crc: true, framing_bi
raise IncorrectCRCError unless received_data.check_crc16(protocol, true)
end

return received_data, valid_bits
return status, received_data, valid_bits
end

def collision_detail
Expand Down

0 comments on commit 74dce47

Please sign in to comment.