extface 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffc7be7748574fcff49cfea02aab44e7f4f97760
4
- data.tar.gz: 426759fdcff98ca0979ef600877c42674f9b4733
3
+ metadata.gz: 1b4af1253c55c88d821b794698c562d77438ea05
4
+ data.tar.gz: 65742b57205bea9b06f7ab0d3ad0143412437880
5
5
  SHA512:
6
- metadata.gz: 4cf1335ec7f7cf50da17e1816213b740a675e5d0b6223f13b9d4145ff14a14d50c6411b4ec29808568b9d39f456b1d657f160122c64da8596f5dfb0439d86ad9
7
- data.tar.gz: 6821ca4e6a6e1078740eebc9c7d30a4dd899e204eb1c979eca3dd695080b35141c7eaff4bf036969151031c830dd4a2483b124396c357264e348391bd597361d
6
+ metadata.gz: 8facf9db5877c6102d22da94fe1fb4631af1835558fd0f573c1df81fd329fe52e12c5b4368191fad8e6e59e4f65f3369372a64069bd8048f0afb6806c7a63d7e
7
+ data.tar.gz: 078de35e90e207440b1ece29bf390848663f8078d3180f1f19bb75e00e948d2d9e50567c423c3e708c0088b543520be52900160a1971da667d2231ef33a57bbc
@@ -73,9 +73,9 @@ module Extface
73
73
  while data
74
74
  response.stream.write data
75
75
  r.publish(job.id, "OK")
76
- if (Time.now - start) > 3.seconds
77
- p "Will continue next time"
78
- #break
76
+ if (Time.now - start) > 1.8.seconds
77
+ p "############ Will continue next time"
78
+ break
79
79
  end
80
80
  list, data = r.blpop(job.id, timeout: 1)
81
81
  end
@@ -18,7 +18,8 @@ module Extface
18
18
  REPORT = false #only transmit data that must be parsed by handler, CDR, report devices
19
19
 
20
20
  RESPONSE_TIMEOUT = 3 #seconds
21
- INVALID_FRAME_RETRIES = 6 #seconds
21
+ INVALID_FRAME_RETRIES = 6 #count
22
+ BUSY_WAIT_CYCLES = 12 #count
22
23
 
23
24
  FLAG_TRUE = "\xff\xff"
24
25
  FLAG_FALSE = "\x00\x00"
@@ -33,33 +34,36 @@ module Extface
33
34
  len = frame_match.captures.first.ord
34
35
  skip = frame_match.pre_match.length
35
36
  bytes_processed = skip + 7 + len # 6 pre + 1 check sum
36
- rpush buffer[skip..bytes_processed]
37
+ if bytes_processed <= buffer.length #packet in buffer
38
+ rpush buffer[skip..bytes_processed]
39
+ else
40
+ bytes_processed = skip #not whole packet, just remove trail
41
+ end
37
42
  end
38
43
  return bytes_processed
39
44
  end
40
45
 
41
46
  def open_receipt(variant = nil)
42
47
  fsend Receipt::OPEN_RECEIPT
43
- status = printer_status!
44
48
  unless variant.blank?
45
49
  fsend Receipt::PRINT_RECEIPT, variant
46
- status = printer_status!
47
50
  end
51
+ status = get_printer_status
48
52
  end
49
53
 
50
54
  def close_receipt
51
55
  fsend Receipt::CLOSE_RECEIPT
52
- status = printer_status!
56
+ status = get_printer_status
53
57
  end
54
58
 
55
59
  def send_comment(text)
56
60
  fsend Receipt::PRINT_RECEIPT, Receipt::Variant::COMMENT + text
57
- status = printer_status!
61
+ status = get_printer_status
58
62
  end
59
63
 
60
64
  def send_plu(plu_data)
61
65
  fsend Receipt::PRINT_RECEIPT, Receipt::Variant::PLU + plu_data
62
- status = printer_status!
66
+ status = get_printer_status
63
67
  end
64
68
 
65
69
  def send_payment(type_num = 0, value = nil) # 0, 1, 2, 3
@@ -70,6 +74,7 @@ module Extface
70
74
  4.times{ |shift| value_bytes.insert 0, ((value_units >> shift*8) & 0xff).chr }
71
75
  end
72
76
  fsend Receipt::PRINT_RECEIPT, "" << (9 + type_num).chr << value_bytes
77
+ status = get_printer_status
73
78
  end
74
79
 
75
80
  def non_fiscal_test
@@ -129,40 +134,45 @@ module Extface
129
134
  device.session("Z Report") do |s|
130
135
  s.notify "Z Report Start"
131
136
  s.fsend Reports::DAILY_REPORT, FLAG_TRUE
132
- status = s.printer_status!
137
+ status = s.get_printer_status
133
138
  s.notify "Z Report End"
134
139
  end
135
140
  end
136
141
 
137
142
  def x_report_session
138
143
  device.session("Z Report") do |s|
139
- s.notify "Z Report Start"
144
+ s.notify "X Report Start"
140
145
  s.fsend Reports::DAILY_REPORT, FLAG_FALSE
141
- status = s.printer_status!
142
- s.notify "Z Report End"
146
+ status = s.get_printer_status
147
+ s.notify "X Report End"
143
148
  end
144
149
  end
145
150
 
146
151
  def cancel_doc_session
147
152
  device.session("Doc cancel") do |s|
148
153
  s.notify "Doc Cancel Start"
149
- #s.fsend Sales::CANCEL_DOC
154
+ # cancel old one by open/close new one
155
+ s.open_receipt
156
+ s.close_receipt
150
157
  s.notify "Doc Cancel End"
151
158
  end
152
159
  end
153
160
 
154
-
155
- def printer_status!
161
+ def check_ready!
156
162
  fsend Info::GET_STATUS
157
163
  raise errors.full_messages.join(", ") if errors.any?
158
- status = PrinterStatus.new(fsend(Info::GET_PRINTER_STATUS))
159
- raise errors.full_messages.join(", ") if errors.any?
160
- status
164
+ end
165
+
166
+ def get_printer_status
167
+ PrinterStatus.new(fsend(Info::GET_PRINTER_STATUS))
161
168
  end
162
169
 
163
170
  def check_status
164
171
  flush
165
- fsend(Info::GET_STATUS)
172
+ status = get_printer_status
173
+ #TODO check for:
174
+ #1. sold PLUs dangerously high -> solution PLU Report (0x32)
175
+ #2. open bon and transaction count
166
176
  errors.empty?
167
177
  end
168
178
 
@@ -181,6 +191,12 @@ module Extface
181
191
  def fsend(cmd, data = "") #return data or nil
182
192
  packet_data = build_packet(cmd, data)
183
193
  result = false
194
+ BUSY_WAIT_CYCLES.times do |retries|
195
+ push build_packet(Info::GET_STATUS)
196
+ if status = frecv(RESPONSE_TIMEOUT)
197
+ break if status.ready?
198
+ end
199
+ end
184
200
  INVALID_FRAME_RETRIES.times do |retries|
185
201
  errors.clear
186
202
  push packet_data
@@ -244,6 +260,10 @@ module Extface
244
260
  @ready || true
245
261
  end
246
262
 
263
+ def busy?
264
+ !ready?
265
+ end
266
+
247
267
  private
248
268
  def check_sum_validation
249
269
  sum = 0
@@ -317,42 +337,55 @@ module Extface
317
337
  class PrinterStatus
318
338
 
319
339
  def initialize(status)
340
+ @status = status
320
341
  end
321
342
 
322
343
  def start_bon_flag?
344
+ @status[2,2] == "\xff\xff"
323
345
  end
324
346
 
325
347
  def end_bon_flag?
348
+ @status[4,2] == "\xff\xff"
326
349
  end
327
350
 
328
351
  def last_transaction
352
+ @status[8,2]
329
353
  end
330
-
354
+
331
355
  def transaction_count
356
+ @status[10,2]
332
357
  end
333
358
 
334
359
  def last_transaction_sum
360
+ @status[12,4]
335
361
  end
336
362
 
337
363
  def all_transaction_sum
364
+ @status[16,4]
338
365
  end
339
366
 
340
367
  def total_sum
368
+ @status[20,4]
341
369
  end
342
370
 
343
371
  def stl_discount_flag?
372
+ @status[24,2] == '\xff\xff'
344
373
  end
345
374
 
346
375
  def last_recept_number
376
+ @status[26,2]
347
377
  end
348
378
 
349
379
  def last_invoice_number
380
+ @status[34,2] + @status[28,4]
350
381
  end
351
382
 
352
383
  def available_invoice_numbers
384
+ @status[36,2]
353
385
  end
354
386
 
355
387
  def plu_count_in_memory
388
+ @status[32,2]
356
389
  end
357
390
  end
358
391
  end
@@ -1,3 +1,3 @@
1
1
  module Extface
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vangelov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-25 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails