app/models/extface/driver/daisy_fx1200.rb in extface-0.5.0 vs app/models/extface/driver/daisy_fx1200.rb in extface-0.5.1
- old
+ new
@@ -17,10 +17,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
+ NO_RESP_MAX_COUNT = 3
TAX_GROUPS_MAP = {
1 => "\xc0",
2 => "\xc1",
3 => "\xc2",
@@ -42,16 +43,13 @@
has_serial_config
include Extface::Driver::Daisy::CommandsFx1200
def handle(buffer) #buffer is filled with multiple pushes, wait for full frame (ACKs)STX..PA2..PA1..ETX
- if frame_len = buffer.index("\x03") || buffer.index("\x16") || buffer.index("\x15")
- rpush buffer[0..frame_len]
- return frame_len+1 # return number of bytes processed
- else
- #TODO check buffer.length
- return 0 #no bytes processed
+ if i = buffer.index("\x03") || buffer.index("\x16") || buffer.index("\x15")
+ rpush buffer[0..i]
+ return i + 1 # return number of bytes processed
end
end
#tests
def non_fiscal_test
@@ -207,10 +205,12 @@
def fsend(cmd, data = "") #return data or nil
packet_data = build_packet(cmd, data)
result = false
invalid_frames = 0
nak_messages = 0
+ no_resp = 0
+ flush # fix mysterious double packet response, #TODO send 2 commands and then read 2 responses may fail
push packet_data
ACKS_MAX_WAIT.times do |retries|
errors.clear
if resp = frecv(RESPONSE_TIMEOUT)
if resp.valid?
@@ -234,9 +234,16 @@
errors.add :base, "#{INVALID_FRAME_RETRIES} Broken Packets Received. Abort!"
break
end
end
push packet_data unless resp.ack?
+ end
+ else
+ no_resp += 1
+ if no_resp > NO_RESP_MAX_COUNT
+ p "No reply in #{NO_RESP_MAX_COUNT * RESPONSE_TIMEOUT} seconds. Abort!"
+ errors.add :base, "No reply in #{NO_RESP_MAX_COUNT * RESPONSE_TIMEOUT} seconds. Abort!"
+ return result
end
end
errors.add :base, "#{ACKS_MAX_WAIT} ACKs Received. Abort!"
end
return result
\ No newline at end of file