star_ethernet 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: e938547b2a7d713bbf3c3836d34dff3f74657c478ed1485c4c20e4bfd809d237
4
- data.tar.gz: bfc8e7fcea483a1277a2f1fd19266864e48c95842f4e14107d8134731b1eddd8
3
+ metadata.gz: ffdd17f529891d6acc685e8232ffdddf6508bb7799047f0e84d788ac421de508
4
+ data.tar.gz: e5f31029a81b0204a7576f381ea6c77877e743c4916224bcaa7e9df326a36c36
5
5
  SHA512:
6
- metadata.gz: 826a49de39fc81da15c921acfb42714c05dd7e8e05daab6183a0ccc0515b1dcf99961a74a638f87095ea0b25ad78c65a3339559c592d66c92cc073269f7fb4db
7
- data.tar.gz: 56fc58ba54b5ed7343236beaf96ee5dcd75c6765745ef0cde2926b1f9da0d8a8946b53bf5dc3ca2400e3bb7fcf0f6e29606c56edd9ec0ba48007349fe9811f1c
6
+ metadata.gz: 0b4069788d3c4f78c551a18fcdefea416a1ff31db056f04efdef7fe172fcfaeecc3a392d62e74adaf5cf3c348a3ccf0ddcdd6d808892974eab59d39f996003be
7
+ data.tar.gz: 114cce192bcbcbb191e73ceb6da005240a823d11149cd5f725c6c2f0226b159fba4b64cf815e19c3bb7361b4aa41301b2e39a47551dd55804aa4350877e922cc
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- star_ethernet (0.1.3)
4
+ star_ethernet (0.1.4)
5
+ net-telnet
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  diff-lcs (1.3)
11
+ net-telnet (0.1.1)
10
12
  rake (12.3.2)
11
13
  rspec (3.8.0)
12
14
  rspec-core (~> 3.8.0)
data/lib/star_ethernet.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'star_ethernet/command'
2
+ require 'star_ethernet/config'
2
3
  require 'star_ethernet/printer'
3
4
  require 'star_ethernet/status'
4
5
  require 'star_ethernet/status_item'
@@ -6,4 +7,7 @@ require 'star_ethernet/version'
6
7
  require 'star_ethernet/exceptions'
7
8
 
8
9
  module StarEthernet
10
+ def self.configuration
11
+ @config ||= StarEthernet::Config.new
12
+ end
9
13
  end
@@ -20,6 +20,60 @@ module StarEthernet
20
20
  end
21
21
 
22
22
 
23
+ def self.normal_font_size
24
+ self.set_cancel_the_double_wide_high(0x00, 0x00)
25
+ end
26
+
27
+ def self.double_font_size
28
+ self.set_cancel_the_double_wide_high(0x01, 0x01)
29
+ end
30
+
31
+ def self.triple_font_size
32
+ self.set_cancel_the_double_wide_high(0x02, 0x02)
33
+ end
34
+
35
+ def self.quadruple_font_size
36
+ self.set_cancel_the_double_wide_high(0x03, 0x03)
37
+ end
38
+
39
+ def self.quintuple_font_size
40
+ self.set_cancel_the_double_wide_high(0x04, 0x04)
41
+ end
42
+
43
+ def self.sextuple_font_size
44
+ self.set_cancel_the_double_wide_high(0x05, 0x05)
45
+ end
46
+
47
+
48
+ def self.align_left
49
+ specify_position_alignment(0x00)
50
+ end
51
+
52
+ def self.align_center
53
+ specify_position_alignment(0x01)
54
+ end
55
+
56
+ def self.align_right
57
+ specify_position_alignment(0x02)
58
+ end
59
+
60
+ def self.full_cut_current_line
61
+ auto_cutter(0x00)
62
+ end
63
+
64
+ def self.partial_cut_current_line
65
+ auto_cutter(0x01)
66
+ end
67
+
68
+ def self.full_cut_after_line_buffer
69
+ auto_cutter(0x02)
70
+ end
71
+
72
+ def self.partial_cut_after_line_buffer
73
+ auto_cutter(0x03)
74
+ end
75
+
76
+
23
77
  # Standard Command
24
78
  ## Font style and Character Set
25
79
  def self.select_font(n)
@@ -0,0 +1,20 @@
1
+ module StarEthernet
2
+ class Config
3
+ attr_accessor :raw_socket_print_port, :status_acquisition_port, :asb_status_size,
4
+ :fetch_time_interval, :retry_counts, :asb, :nsb
5
+
6
+ def initialize
7
+ set_default
8
+ end
9
+
10
+ def set_default
11
+ @raw_socket_print_port = 9100
12
+ @status_acquisition_port = 9101
13
+ @asb_status_size = 9
14
+ @fetch_time_interval = 0.1
15
+ @retry_counts = 300
16
+ @asb = false
17
+ @nsb = false
18
+ end
19
+ end
20
+ end
@@ -1,29 +1,24 @@
1
1
  require 'socket'
2
+ require 'net/telnet'
2
3
 
3
4
  require 'star_ethernet/status'
4
5
  require 'star_ethernet/exceptions'
5
6
 
6
7
  module StarEthernet
7
8
  class Printer
8
- RAW_SOCKET_PRINT_PORT = 9100
9
- STATUS_ACQUISITION_PORT = 9101
10
- ASB_STATUS_SIZE = 9
11
- FETCH_TIME_INTERVAL = 0.1
12
- RETRY_COUNTS = 300
13
-
14
9
  attr_reader :status, :host
15
10
 
16
- def initialize(host, nsb: false, asb: false, interval: FETCH_TIME_INTERVAL, retry_counts: RETRY_COUNTS)
17
- @host, @nsb, @asb, @interval, @retry_counts = host, nsb, asb, interval, retry_counts
11
+ def initialize(host)
12
+ @host = host
18
13
  @status = StarEthernet::Status.new(self)
19
14
  end
20
15
 
21
16
  def print(data)
22
17
  begin
23
- socket = socket(RAW_SOCKET_PRINT_PORT)
18
+ socket = socket(StarEthernet.configuration.raw_socket_print_port)
24
19
 
25
- if @nsb
26
- nbs_status = socket.read(ASB_STATUS_SIZE)
20
+ if StarEthernet.configuration.nsb
21
+ nbs_status = socket.read(StarEthernet.configuration.asb_status_size)
27
22
  @status.set_status(nbs_status, 'receive nbs status')
28
23
  end
29
24
 
@@ -37,12 +32,12 @@ module StarEthernet
37
32
 
38
33
  socket.print(StarEthernet::Command.update_asb_etb_status)
39
34
 
40
- @retry_counts.times do |index|
41
- sleep @interval
35
+ StarEthernet.configuration.retry_counts.times do |index|
36
+ sleep StarEthernet.configuration.fetch_time_interval
42
37
  fetch_status('fetch etb status for reserve etb count before printing')
43
38
 
44
- break if etb_incremented?
45
- if index == @retry_counts - 1
39
+ break if @status.etb_incremented?
40
+ if index == StarEthernet.configuration.retry_counts - 1
46
41
  raise StarEthernet::EtbCountUpFailed.new(@status.full_messages)
47
42
  end
48
43
  end
@@ -55,11 +50,12 @@ module StarEthernet
55
50
 
56
51
  socket.print(StarEthernet::Command.end_document)
57
52
 
58
- @retry_counts.times do |index|
59
- sleep @interval
53
+ StarEthernet.configuration.retry_counts.times do |index|
54
+ sleep StarEthernet.configuration.fetch_time_interval
60
55
  fetch_status('fetch etb status for checking print success')
61
- break if etb_incremented?
62
- if index == @retry_counts - 1
56
+
57
+ break if @status.etb_incremented?
58
+ if index == StarEthernet.configuration.retry_counts - 1
63
59
  raise StarEthernet::PrintFailed.new(@status.full_messages)
64
60
  end
65
61
  end
@@ -69,9 +65,9 @@ module StarEthernet
69
65
  end
70
66
 
71
67
  def send_command(data)
72
- socket = socket(RAW_SOCKET_PRINT_PORT)
73
- if @nsb
74
- nbs_status = socket.read(ASB_STATUS_SIZE)
68
+ socket = socket(StarEthernet.configuration.raw_socket_print_port)
69
+ if StarEthernet.configuration.nsb
70
+ nbs_status = socket.read(StarEthernet.configuration.asb_status_size)
75
71
  @status.set_status(nbs_status)
76
72
  end
77
73
  socket.print(data)
@@ -79,36 +75,33 @@ module StarEthernet
79
75
  end
80
76
 
81
77
  def fetch_status(purpose = '')
82
- socket = socket(STATUS_ACQUISITION_PORT)
78
+ socket = socket(StarEthernet.configuration.status_acquisition_port)
83
79
  socket.print(StarEthernet::Command.status_acquisition)
84
- asb_status = socket.read(ASB_STATUS_SIZE)
80
+ asb_status = socket.read(StarEthernet.configuration.asb_status_size)
85
81
  @status.set_status(asb_status, purpose)
86
82
  socket.close
87
83
  @status.current_status
88
84
  end
89
85
 
90
- def etb_incremented?
91
- current_etb == previous_etb + 1
92
- end
93
-
94
- def current_etb
95
- current_status.etb
96
- end
97
-
98
- def previous_etb
99
- previous_status.etb
86
+ def reboot
87
+ telnet.cmd('String' => '98', 'Match' => /(.)*Selection: /)
88
+ telnet.cmd('String' => '2', 'Match' => /(.)*Selection: /)
100
89
  end
101
90
 
102
91
  def current_status
103
92
  @status.current_status
104
93
  end
105
94
 
106
- def previous_status
107
- @status.previous_status
108
- end
109
-
110
95
  def socket(port)
111
96
  TCPSocket.new(@host, port)
112
97
  end
98
+
99
+ def telnet
100
+ telnet = Net::Telnet.new('Host' => @host)
101
+ telnet.waitfor(/(.)*login: /)
102
+ telnet.cmd('String' => 'root', 'Match' => /(.)*Password: /)
103
+ telnet.cmd('String' => 'public', 'Match' => /(.)*Selection: /)
104
+ telnet
105
+ end
113
106
  end
114
107
  end
@@ -17,6 +17,15 @@ module StarEthernet
17
17
  @status_items[-2]
18
18
  end
19
19
 
20
+ def etb_incremented?
21
+ return false if previous_status.nil?
22
+ if previous_status.etb == 31 # ETB overflow
23
+ current_status.etb == 0
24
+ else
25
+ current_status.etb == previous_status.etb + 1
26
+ end
27
+ end
28
+
20
29
  def set_status(status_data, purpose = '')
21
30
  current_status = StatusItem.decode_status(status_data)
22
31
  current_status.purpose = purpose
@@ -1,3 +1,3 @@
1
1
  module StarEthernet
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -32,6 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
+ spec.add_dependency "net-telnet"
36
+
35
37
  spec.add_development_dependency "bundler", "~> 2.0.1"
36
38
  spec.add_development_dependency "rake", "~> 12.3.2"
37
39
  spec.add_development_dependency "rspec", "~> 3.8.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: star_ethernet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinsuke IMAI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-telnet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +91,7 @@ files:
77
91
  - bin/setup
78
92
  - lib/star_ethernet.rb
79
93
  - lib/star_ethernet/command.rb
94
+ - lib/star_ethernet/config.rb
80
95
  - lib/star_ethernet/exceptions.rb
81
96
  - lib/star_ethernet/printer.rb
82
97
  - lib/star_ethernet/status.rb