app/models/extface/driver/datecs/fp550.rb in extface-0.4.6a vs app/models/extface/driver/datecs/fp550.rb in extface-0.4.6b
- old
+ new
@@ -8,11 +8,12 @@
NAKS_MAX_COUNT = 3 #count
include Extface::Driver::Datecs::CommandsV1
def handle(buffer)
- if i = buffer.index(/[\x03\x16\x15]/) # find position of frame possible delimiter
+ #if i = buffer.index(/[\x03\x16\x15]/) # find position of frame possible delimiter
+ if i = buffer.index("\x03") || buffer.index("\x16") || buffer.index("\x15")
rpush buffer[0..i] # this will make data available for #pull(timeout) method
return i+1 # return number of bytes processed
end
end
@@ -163,11 +164,11 @@
errors.add :base, "#{NAKS_MAX_COUNT} NAKs Received. Abort!"
break
end
elsif !resp.ack?
invalid_frames += 1
- if nak_messages > INVALID_FRAME_RETRIES
+ if invalid_frames > INVALID_FRAME_RETRIES
errors.add :base, "#{INVALID_FRAME_RETRIES} Broken Packets Received. Abort!"
break
end
end
push packet_data unless resp.ack?
@@ -209,11 +210,11 @@
def human_status_errors(status) #6 bytes status
status_0 = status[0].ord
errors.add :base, "Fiscal Device General Error" unless (status_0 & 0x20).zero?
errors.add :base, "Invalid Command" unless (status_0 & 0x02).zero?
errors.add :base, "Date & Time Not Set" unless (status_0 & 0x04).zero?
- errors.add :base, "Syntax Error" unless (status_0 & 0x02).zero?
+ errors.add :base, "Syntax Error" unless (status_0 & 0x01).zero?
status_1 = status[1].ord
errors.add :base, "Unpermitted Command In This Mode" unless (status_1 & 0x02).zero?
errors.add :base, "Field Overflow" unless (status_1 & 0x01).zero?
end
@@ -228,11 +229,11 @@
class Frame
include ActiveModel::Validations
attr_reader :frame, :len, :seq, :cmd, :data, :status, :bcc
- validates_presence_of :frame, unless: :unpacked?
+ validates_presence_of :frame#, unless: :unpacked?
validate :bcc_validation
validate :len_validation
def initialize(buffer)
if match = buffer.match(/\x01(.{1})(.{1})(.{1})(.*)\x04(.{6})\x05(.{4})\x03/nm)
@@ -250,9 +251,22 @@
def ack?; !!@ack; end #should wait, response is yet to come
def nak?; !!@nak; end #should retry command with same seq
private
+ def build_sale_data(item)
+ "".tap() do |data|
+ data << item.text1 unless item.text1.blank?
+ data << "\x0a#{text2}" unless item.text2.blank?
+ data << "\t"
+ data << TAX_GROUPS_MAP[item.tax_group || 2]
+ data << ("%.2f" % item.price)
+ data << "*#{item.qty.to_s}" unless item.qty.blank?
+ data << ",#{item.percent}" unless item.percent.blank?
+ data << "$#{'%.2f' % item.neto}" unless item.neto.blank?
+ end
+ end
+
def unpacked? # is it packed or unpacked message?
@ack || @nak
end
def bcc_validation
\ No newline at end of file