Class: Extface::Driver
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Extface::Driver
- Defined in:
- app/models/extface/driver.rb
Direct Known Subclasses
Driver::Base::Fiscal, Driver::Base::Print, Driver::Fidelio::Fias, GenericPos
Defined Under Namespace
Classes: DaisyFx1200, EltradeTmU220, GenericEscPos, GenericPos, StarScp700, StarTsp200
Constant Summary collapse
- NAME =
human driver name
'Extface Driver Base'
- 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
- PRINT =
responds to #push(data) and #pull
false
- FISCAL =
POS, slip printers
false
- REPORT =
cash registers, fiscal printers
false
- DRIVER_TYPES =
only transmit data that must be parsed by handler, CDR, report devices
['RAW', 'PRINT', 'FISCAL', 'REPORT'].freeze
Class Method Summary collapse
-
.has_serial_config ⇒ Object
helper for serial devices, provides config for speed, boud rate, parity etc..
Instance Method Summary collapse
- #check_status ⇒ Object
- #flush ⇒ Object
-
#handle(buffer) ⇒ Object
called on every push message received, buffer contains all not processed data.
- #notify(message) ⇒ Object
- #pre_handle(buffer) ⇒ Object
- #pull(timeout = nil) ⇒ Object
- #push(buffer) ⇒ Object
- #rpush(buffer) ⇒ Object
- #serial? ⇒ Boolean
- #set_job(job) ⇒ Object
Class Method Details
.has_serial_config ⇒ Object
helper for serial devices, provides config for speed, boud rate, parity etc..
27 28 29 30 31 32 33 |
# File 'app/models/extface/driver.rb', line 27 def has_serial_config #helper for serial devices, provides config for speed, boud rate, parity etc.. has_one :serial_config, inverse_of: :driver accepts_nested_attributes_for :serial_config define_method :serial? do true end end |
Instance Method Details
#check_status ⇒ Object
111 112 113 114 |
# File 'app/models/extface/driver.rb', line 111 def check_status errors.add :base, :not_implemented false end |
#flush ⇒ Object
88 89 90 91 92 93 |
# File 'app/models/extface/driver.rb', line 88 def flush Extface.redis_block do |r| r.del device.uuid r.del buffer_key end end |
#handle(buffer) ⇒ Object
called on every push message received, buffer contains all not processed data
37 38 39 40 |
# File 'app/models/extface/driver.rb', line 37 def handle(buffer) $stdout.puts "Extface:#{device.uuid} PUSH #{buffer}" return buffer.length # return number of bytes processed end |
#notify(message) ⇒ Object
101 102 103 104 |
# File 'app/models/extface/driver.rb', line 101 def notify() raise "No job given" unless @job @job.notify() end |
#pre_handle(buffer) ⇒ Object
42 43 44 45 |
# File 'app/models/extface/driver.rb', line 42 def pre_handle(buffer) logger.debug "<-- #{buffer.bytes.map{ |b| '%02X' % b }.join(' ')}" if development? handle(buffer) end |
#pull(timeout = nil) ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/models/extface/driver.rb', line 80 def pull(timeout = nil) element = nil Extface.redis_block do |r| list, element = r.blpop(buffer_key, :timeout => timeout) end element end |
#push(buffer) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/extface/driver.rb', line 47 def push(buffer) if @job #retry if current device job is not @job (waiting on queue) wait_on_queue = 2 #stop me writing endless things if current_device_job = device.jobs(true).active.try(:first) if current_device_job != @job wait_on_queue = 20 #FIXME! p "#### current_job is not first_on_queue" end end begin Timeout.timeout(Extface.device_timeout) do Extface.redis_block do |r| r.subscribe(@job.id) do |on| #blocking until delivered on.subscribe do |channel, subscriptions| @job.rpush buffer logger.debug "--> #{buffer.bytes.map{ |b| '%02X' % b }.join(' ')}" if development? end on. do |event, data| r.unsubscribe @job.connected! end end end end rescue Timeout::Error (wait_on_queue -= 1) > 0 ? retry : raise("Timeout waiting on queue") #let it be! end else raise "No job given" end end |
#rpush(buffer) ⇒ Object
95 96 97 98 99 |
# File 'app/models/extface/driver.rb', line 95 def rpush(buffer) Extface.redis_block do |r| r.rpush buffer_key, buffer end end |
#serial? ⇒ Boolean
116 |
# File 'app/models/extface/driver.rb', line 116 def serial?; false; end |
#set_job(job) ⇒ Object
106 107 108 109 |
# File 'app/models/extface/driver.rb', line 106 def set_job(job) @job = job return check_status end |