-
Notifications
You must be signed in to change notification settings - Fork 0
Find the RfidTag if there is a mismatch #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # frozen_string_literal: true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should either be moved into |
||
|
|
||
| # Utility to work with RFID tag TIDs | ||
| class RfidTid | ||
| def initialize(tid) | ||
| @tid = sanitize(tid) | ||
| end | ||
|
|
||
| def xtid? | ||
| e2? && bit_set?(8) | ||
| end | ||
|
|
||
| def security? | ||
| e2? && bit_set?(9) | ||
| end | ||
|
|
||
| def file? | ||
| e2? && bit_set?(10) | ||
| end | ||
|
|
||
| def designer | ||
| bits[11, 9].to_i | ||
| end | ||
|
|
||
| def model_number | ||
| bits[20, 12].to_i | ||
| end | ||
|
|
||
| def to_s | ||
| @tid | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def e2? | ||
| @tid.starts_with?('E2') | ||
| end | ||
|
|
||
| def sanitize(tid) | ||
| tid = tid.upcase | ||
| return tid if plausible?(tid) | ||
| tid.scan(/(\w{2})(\w{2})/).map(&:reverse).join.tap do |reversed| | ||
| raise ArgumentError, 'Implausible TID' unless plausible?(reversed) | ||
| end | ||
| end | ||
|
|
||
| def plausible?(tid) | ||
| tid =~ /\AE2[0-9A-F]{22}\z/ | ||
| end | ||
|
|
||
| def bit_set?(idx) | ||
| bits[idx] == '1' | ||
| end | ||
|
|
||
| def bits | ||
| @bits ||= @tid.to_i(16).to_s(2) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # frozen_string_literal: true | ||
| require 'rfid_tid' | ||
|
|
||
| RSpec.describe RfidTid do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above: the spec shouldn't be duplicated either. |
||
|
|
||
| it 'ensures big endianness' do | ||
| expect(RfidTid.new('80E2051100208A267E868E08').to_s).to eq('E28011052000268A867E088E') | ||
| expect(RfidTid.new('E28011052000268A867E088E').to_s).to eq('E28011052000268A867E088E') | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this approach is that the specification doesn't guarantee that this will be present or that the media ID will be an RFID TID. Ideally, when running the sync, the card and customer account mappings are only soft-deleted (via
acts_as_paranoid) and when finding them here, we then use thewith_deletedscope. That way we don't need to make any assumptions about the request.