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, EpsonTmU220, 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
- #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
93 94 95 96 |
# File 'app/models/extface/driver.rb', line 93 def check_status errors.add :base, :not_implemented false end |
#flush ⇒ Object
70 71 72 73 74 75 |
# File 'app/models/extface/driver.rb', line 70 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
83 84 85 86 |
# File 'app/models/extface/driver.rb', line 83 def notify() raise "No job given" unless @job @job.notify() end |
#pull(timeout = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/models/extface/driver.rb', line 62 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/extface/driver.rb', line 42 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 end on. do |event, data| r.unsubscribe @job.connected! end end end end else raise "No job given" end end |
#rpush(buffer) ⇒ Object
77 78 79 80 81 |
# File 'app/models/extface/driver.rb', line 77 def rpush(buffer) Extface.redis_block do |r| r.rpush buffer_key, buffer end end |
#set_job(job) ⇒ Object
88 89 90 91 |
# File 'app/models/extface/driver.rb', line 88 def set_job(job) @job = job return check_status end |