app/models/extface/driver/daisy_fx1200.rb in extface-0.4.8 vs app/models/extface/driver/daisy_fx1200.rb in extface-0.4.9
- old
+ new
@@ -16,10 +16,11 @@
RESPONSE_TIMEOUT = 3 #seconds
INVALID_FRAME_RETRIES = 6 #count (bad length, bad checksum)
ACKS_MAX_WAIT = 60 #count / nothing is forever
NAKS_MAX_COUNT = 3 #count
+ BAD_SEQ_MAX_COUNT = 3
TAX_GROUPS_MAP = {
1 => "\xc0",
2 => "\xc1",
3 => "\xc2",
@@ -241,15 +242,25 @@
end
return result
end
def frecv(timeout) # return RespFrame or nil
- if frame_bytes = pull(timeout)
- return RespFrame.new(frame_bytes.b)
- else
- errors.add :base, "No data received from device"
- return nil
+ rframe = nil
+ BAD_SEQ_MAX_COUNT.times do
+ if frame_bytes = pull(timeout)
+ rframe = RespFrame.new(frame_bytes.b)
+ if rframe.seq.ord == sequence_number(false) #accept only current sequence number as reply
+ break
+ else
+ errors.add :base, "Sequence mismatch"
+ rframe = nil #invalidate mismatch sequence frame for the last retry
+ end
+ else
+ errors.add :base, "No data received from device"
+ break
+ end
end
+ return rframe
end
private
def build_sale_data(item)
"".tap() do |data|
\ No newline at end of file