Class: Extface::Driver
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Extface::Driver
- Defined in:
- app/models/extface/driver.rb
Direct Known Subclasses
Defined Under Namespace
Classes: DaisyFx1200, EltradeTmU220, 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
- #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
99 100 101 102 |
# File 'app/models/extface/driver.rb', line 99 def check_status errors.add :base, :not_implemented false end |
#flush ⇒ Object
76 77 78 79 80 81 |
# File 'app/models/extface/driver.rb', line 76 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
89 90 91 92 |
# File 'app/models/extface/driver.rb', line 89 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
68 69 70 71 72 73 74 |
# File 'app/models/extface/driver.rb', line 68 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 |
# File 'app/models/extface/driver.rb', line 47 def push(buffer) if @job 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 else raise "No job given" end end |
#rpush(buffer) ⇒ Object
83 84 85 86 87 |
# File 'app/models/extface/driver.rb', line 83 def rpush(buffer) Extface.redis_block do |r| r.rpush buffer_key, buffer end end |
#set_job(job) ⇒ Object
94 95 96 97 |
# File 'app/models/extface/driver.rb', line 94 def set_job(job) @job = job return check_status end |