Class: Driver::Fidelio::Fias

Inherits:
Extface::Driver
  • Object
show all
Defined in:
app/models/extface/driver/fidelio/fias.rb

Constant Summary collapse

NAME =
'Fidelio FIAS Simple Posting (TCP/IP)'.freeze
GROUP =
Extface::RAW_DRIVER
DEVELOPMENT =

driver is not ready for production (not passing all tests or has major bugs)

true
RAW =

Select driver features

true
false
FISCAL =

POS, slip printers

false
REPORT =

cash registers, fiscal printers

false
STX =

only transmit data that must be parsed by handler, CDR, report devices

0x02
ETX =
0x03

Instance Method Summary collapse

Instance Method Details

#build_packet(data = "") ⇒ Object



69
70
71
72
73
74
75
76
# File 'app/models/extface/driver/fidelio/fias.rb', line 69

def build_packet(data = "")
  "".b.tap() do |packet|
    packet << STX
    packet << data
    packet << "|DA#{Date.today.strftime("%y%m%d")}|TI#{Time.now.strftime("%H%M%S")}|"
    packet << ETX
  end
end

#check_statusObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/extface/driver/fidelio/fias.rb', line 53

def check_status
  flush
  push build_packet("LS")
  if status = pull(3)
    tags = inspect_frame(status)
    if tags.include? "ASUR"
      err_tag = tags.find{ |t| t.starts_with? "CT" } 
      errors.add :base, err_tag[2..-1]
    end
    errors.empty?
  else
    errors.add :base, "No data received from device"
    return false
  end
end

#handle(buffer) ⇒ Object



17
18
19
20
21
22
# File 'app/models/extface/driver/fidelio/fias.rb', line 17

def handle(buffer)
  if i = buffer.index(/\x03/)   # 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

#ps(room, price) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/extface/driver/fidelio/fias.rb', line 24

def ps(room, price)
  push build_packet("PS|RN#{room}|PTC|TA#{(price*100).to_i}")
  if status = pull(3)
    tags = inspect_frame(status)
    if tags.include? "ASUR"
      err_tag = tags.find{ |t| t.starts_with? "CT" } 
      errors.add :base, "FIAS ERROR: #{err_tag[2..-1]}"
    end
  else
    errors.add :base, "No data received from device"
  end
  errors.empty?
end

#test(params = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/extface/driver/fidelio/fias.rb', line 38

def test(params = {})
  device.session("Simple Post") do |s|
    s.push build_packet("PS|RN101|PTC|TA200")
    if status = pull(3)
      tags = inspect_frame(status)
      if tags.include? "ASUR"
        err_tag = tags.find{ |t| t.starts_with? "CT" } 
        raise "FIAS ERROR: #{err_tag[2..-1]}"
      end
    else
      raise "No data received from device"
    end
  end
end