app/models/extface/driver/datecs/fp550.rb in extface-0.4.6k vs app/models/extface/driver/datecs/fp550.rb in extface-0.4.6
- old
+ new
@@ -4,35 +4,15 @@
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
-
- TAX_GROUPS_MAP = {
- 1 => "\xc0",
- 2 => "\xc1",
- 3 => "\xc2",
- 4 => "\xc3",
- 5 => "\xc4",
- 6 => "\xc5",
- 7 => "\xc6",
- 8 => "\xc7"
- }
-
- PAYMENT_TYPE_MAP = {
- 1 => "P",
- 2 => "N",
- 3 => "C",
- 4 => "D",
- 5 => "B"
- }
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") || buffer.index("\x16") || buffer.index("\x15")
+ if i = buffer.index(/[\x03\x16\x15]/) # find position of frame possible delimiter
rpush buffer[0..i] # this will make data available for #pull(timeout) method
return i+1 # return number of bytes processed
end
end
@@ -95,12 +75,12 @@
fsend(Info::GET_STATUS, 'X') # get 6 bytes status
errors.empty?
end
#fiscal
- def open_fiscal_doc(operator = "1", password = "000000")
- fsend Sales::START_FISCAL_DOC, "#{operator.presence || "1"},#{password.presence || "000000"},00001"
+ def open_fiscal_doc(operator = "1", password = "1")
+ fsend Sales::START_FISCAL_DOC, "#{operator.presence || "1"},#{password.presence || "1"},00001"
@fiscal_session = true
end
def close_fiscal_doc
raise "Not in fiscal session" unless @fiscal_session
@@ -150,11 +130,11 @@
end
def cancel_doc_session
device.session("Doc cancel") do |s|
s.notify "Doc Cancel Start"
- s.fsend Sales::CANCEL_FISCAL_DOC
+ s.fsend Sales::CANCEL_DOC
s.paper_cut
s.notify "Doc Cancel End"
end
end
@@ -183,11 +163,11 @@
errors.add :base, "#{NAKS_MAX_COUNT} NAKs Received. Abort!"
break
end
elsif !resp.ack?
invalid_frames += 1
- if invalid_frames > INVALID_FRAME_RETRIES
+ if nak_messages > INVALID_FRAME_RETRIES
errors.add :base, "#{INVALID_FRAME_RETRIES} Broken Packets Received. Abort!"
break
end
end
push packet_data unless resp.ack?
@@ -229,29 +209,15 @@
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 & 0x01).zero?
+ errors.add :base, "Syntax Error" unless (status_0 & 0x02).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
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 sequence_number
@seq ||= 0x1f
@seq += 1
@seq = 0x1f if @seq == 0x7f
@@ -260,11 +226,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)
@@ -282,10 +248,9 @@
def ack?; !!@ack; end #should wait, response is yet to come
def nak?; !!@nak; end #should retry command with same seq
private
-
def unpacked? # is it packed or unpacked message?
@ack || @nak
end
def bcc_validation
\ No newline at end of file