codin_rep 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codin_rep/mock_time_clock.rb +186 -0
- data/lib/codin_rep/version.rb +1 -1
- data/test/coverage/index.html +1164 -10
- data/test/coverage/rcov/index.html +25 -9
- data/test/coverage/rcov/lib-codin_rep-add_employee_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-command_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-communication_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-del_employee_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-employee_command_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-get_afd_header_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-get_records_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-get_time_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-mock_time_clock_rb.html +617 -0
- data/test/coverage/rcov/lib-codin_rep-set_time_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-time_util_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-version_rb.html +2 -2
- data/test/coverage/rcov/lib-codin_rep_rb.html +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/add_employee_test.rb +1 -1
- data/test/unit/del_employee_test.rb +1 -1
- data/test/unit/get_employer_test.rb +1 -1
- data/test/unit/get_records_test.rb +1 -1
- data/test/unit/get_serial_number_test.rb +1 -1
- data/test/unit/get_time_test.rb +1 -1
- data/test/unit/set_time_test.rb +1 -1
- metadata +5 -4
- data/test/mock_time_clock.rb +0 -184
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b899679412c8e4c220ca7c062dbd642d9fa2a4dd
|
4
|
+
data.tar.gz: fdb5f8943e5fb5e05cade78f860829868b16b436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92405274f99579511d1fcaad648b3940dfac116f0356e43c12c2c3c7677cfdb56e3e024d931b63554b776d7b6be5f49e6ec744dcd95eebcaa200fad9a8245dc6
|
7
|
+
data.tar.gz: 95fb2748572ff674fec78633011a6592699590f56197c8a351071f12bdde0ee434853dc0911601725394d00b1543575022f1f9091952b543d68baa4e346fa981
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# codin_rep - Gem para acesso de REPs da Telebyte
|
3
|
+
# Copyright (C) 2016 O.S. Systems Softwares Ltda.
|
4
|
+
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Affero General Public License as
|
7
|
+
# published by the Free Software Foundation, either version 3 of the
|
8
|
+
# License, or (at your option) any later version.
|
9
|
+
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
# Rua Clóvis Gularte Candiota 132, Pelotas-RS, Brasil.
|
19
|
+
# e-mail: contato@ossystems.com.br
|
20
|
+
|
21
|
+
require 'codin_rep'
|
22
|
+
require 'codin_rep/time_util'
|
23
|
+
require 'socket'
|
24
|
+
|
25
|
+
module CodinRep
|
26
|
+
class MockTimeClock
|
27
|
+
include CodinRep
|
28
|
+
|
29
|
+
attr_reader :data, :ip
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@data = OpenStruct.new
|
33
|
+
@ip = '127.0.0.1'
|
34
|
+
@server = TCPServer.new(@ip, 0)
|
35
|
+
@running = false
|
36
|
+
@served_connections = 0
|
37
|
+
@threads = []
|
38
|
+
@threadsMutex = Mutex.new
|
39
|
+
@served_connections = 0
|
40
|
+
@time = true
|
41
|
+
@is_sending_records = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def tcp_port
|
45
|
+
@server.addr[1]
|
46
|
+
end
|
47
|
+
|
48
|
+
def serve(socket)
|
49
|
+
Thread.new do
|
50
|
+
Thread.current.abort_on_exception = true
|
51
|
+
@threadsMutex.synchronize {
|
52
|
+
@threads << Thread.current
|
53
|
+
@served_connections += 1
|
54
|
+
}
|
55
|
+
begin
|
56
|
+
raw_command = []
|
57
|
+
@keep_connected = true
|
58
|
+
@first_connection = true
|
59
|
+
# Read command type
|
60
|
+
while @keep_connected && raw_command = read_from_socket_with_timeout(socket, 9)
|
61
|
+
response = process_command(raw_command, socket)
|
62
|
+
socket.write response
|
63
|
+
@first_connection = false
|
64
|
+
end
|
65
|
+
ensure
|
66
|
+
socket.close unless socket.closed?
|
67
|
+
@threadsMutex.synchronize {
|
68
|
+
@threads.delete(Thread.current)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def start
|
75
|
+
@server_thread = Thread.new do
|
76
|
+
Thread.current.abort_on_exception = true
|
77
|
+
@running = true
|
78
|
+
while @running
|
79
|
+
break if @server.closed?
|
80
|
+
socket = @server.accept
|
81
|
+
serve(socket)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def stop
|
88
|
+
@threadsMutex.synchronize {
|
89
|
+
@threads.each{|thread| thread.kill}
|
90
|
+
@threads = []
|
91
|
+
}
|
92
|
+
@server_thread.kill if @server_thread
|
93
|
+
@server.close unless @server.closed?
|
94
|
+
@server_thread.join
|
95
|
+
@running = false
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
99
|
+
def running?
|
100
|
+
@running
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
def process_command(raw_command, socket)
|
105
|
+
case raw_command
|
106
|
+
when "PGREP009b" # Get time
|
107
|
+
response = 'REP008b' + get_timeclock_time
|
108
|
+
when "PGREP016A" # Set time
|
109
|
+
payload = read_from_socket_with_timeout(socket, 7)
|
110
|
+
response = 'REP008A' + payload
|
111
|
+
set_timeclock_time(payload)
|
112
|
+
when "PGREP009Z"
|
113
|
+
response = 'REP2359' + @data.afd.header.export + "\r\n"
|
114
|
+
@keep_connected = false
|
115
|
+
when "PGREP0289"
|
116
|
+
@afd_read_start_id = read_from_socket_with_timeout(socket, 9).to_i
|
117
|
+
@afd_read_end_id = read_from_socket_with_timeout(socket, 9).to_i
|
118
|
+
@afd_read_current_id = nil
|
119
|
+
@afd_read_finished = false
|
120
|
+
response = "REP0029["
|
121
|
+
when "PGREP009,"
|
122
|
+
if @afd_read_finished
|
123
|
+
response = "REP0029]"
|
124
|
+
@keep_connected = false
|
125
|
+
else
|
126
|
+
if @afd_read_current_id.nil?
|
127
|
+
@afd_read_current_id = @afd_read_start_id
|
128
|
+
response = 'REP3029'
|
129
|
+
elsif @afd_read_current_id == @afd_read_end_id or @afd_read_current_id >= @data.afd.records.size
|
130
|
+
response = 'REP0909'
|
131
|
+
@afd_read_finished = true
|
132
|
+
else
|
133
|
+
response = 'REP0379'
|
134
|
+
end
|
135
|
+
afd_records = ([@data.afd.header] + @data.afd.records)
|
136
|
+
response += afd_records[@afd_read_current_id].export + "\r\n"
|
137
|
+
end
|
138
|
+
@afd_read_current_id += 1
|
139
|
+
when "PGREP075h"
|
140
|
+
payload = read_from_socket_with_timeout(socket, 66)
|
141
|
+
raw_registration, raw_pis, raw_name = payload.scan(/.(.{6})(.{6})(.+)/).flatten
|
142
|
+
registration = convert_bytes_to_string(raw_registration)
|
143
|
+
pis = convert_bytes_to_string(raw_pis)
|
144
|
+
name = raw_name.strip
|
145
|
+
@data.employees << {name: name, pis: pis, registration: registration}
|
146
|
+
response = "REP003h1\0"
|
147
|
+
when "PGREP016j"
|
148
|
+
payload = read_from_socket_with_timeout(socket, 7)
|
149
|
+
raw_registration = payload.scan(/.(.{6})/).flatten[0]
|
150
|
+
registration = convert_bytes_to_string(raw_registration)
|
151
|
+
@data.employees.delete_if{|employee| employee[:registration] == registration}
|
152
|
+
response = "REP003j1\0"
|
153
|
+
when 'PGREP010h', 'PGREP010j'
|
154
|
+
# Don't care for the result of these comands, just disconnect when
|
155
|
+
# possible.
|
156
|
+
@keep_connected = false
|
157
|
+
response = ""
|
158
|
+
else
|
159
|
+
raise StandardError.new("Unknown command \"#{raw_command}\"!")
|
160
|
+
end
|
161
|
+
response
|
162
|
+
end
|
163
|
+
|
164
|
+
def read_from_socket_with_timeout(socket, bytes_to_be_read, timeout_value=5)
|
165
|
+
data_to_receive = nil
|
166
|
+
timeout_value = 600 if @first_connection # use a large timeout on first connection
|
167
|
+
timeout(timeout_value) { data_to_receive = socket.readpartial( bytes_to_be_read ) }
|
168
|
+
return data_to_receive
|
169
|
+
end
|
170
|
+
|
171
|
+
def get_timeclock_time(current_time=nil)
|
172
|
+
current_time ||= @data.time
|
173
|
+
CodinRep::TimeUtil.pack current_time
|
174
|
+
end
|
175
|
+
|
176
|
+
def set_timeclock_time(payload)
|
177
|
+
time = CodinRep::TimeUtil.unpack payload
|
178
|
+
@data.time = time
|
179
|
+
return time
|
180
|
+
end
|
181
|
+
|
182
|
+
def convert_bytes_to_string(bytes)
|
183
|
+
bytes.unpack('H*')[0]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
data/lib/codin_rep/version.rb
CHANGED
data/test/coverage/index.html
CHANGED
@@ -14,14 +14,14 @@
|
|
14
14
|
<img src="./assets/0.10.0/loading.gif" alt="loading"/>
|
15
15
|
</div>
|
16
16
|
<div id="wrapper" style="display:none;">
|
17
|
-
<div class="timestamp">Generated <abbr class="timeago" title="2017-01-
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2017-01-25T17:10:31-02:00">2017-01-25T17:10:31-02:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
21
21
|
<div class="file_list_container" id="AllFiles">
|
22
22
|
<h2>
|
23
23
|
<span class="group_name">All Files</span>
|
24
|
-
(<span class="covered_percent"><span class="red">0.
|
24
|
+
(<span class="covered_percent"><span class="red">0.19%</span></span>
|
25
25
|
covered at
|
26
26
|
<span class="covered_strength">
|
27
27
|
<span class="red">
|
@@ -31,10 +31,10 @@
|
|
31
31
|
</h2>
|
32
32
|
<a name="AllFiles"></a>
|
33
33
|
<div>
|
34
|
-
<b>
|
35
|
-
<b>
|
34
|
+
<b>13</b> files in total.
|
35
|
+
<b>1067</b> relevant lines.
|
36
36
|
<span class="green"><b>2</b> lines covered</span> and
|
37
|
-
<span class="red"><b>
|
37
|
+
<span class="red"><b>1065</b> lines missed </span>
|
38
38
|
</div>
|
39
39
|
<table class="file_list">
|
40
40
|
<thead>
|
@@ -140,6 +140,16 @@
|
|
140
140
|
<td>0.0</td>
|
141
141
|
</tr>
|
142
142
|
|
143
|
+
<tr>
|
144
|
+
<td class="strong"><a href="#eafa662feda24b9dc266cb168febb2abf1d20de2" class="src_link" title="lib/codin_rep/mock_time_clock.rb">lib/codin_rep/mock_time_clock.rb</a></td>
|
145
|
+
<td class="red strong">0.0 %</td>
|
146
|
+
<td>186</td>
|
147
|
+
<td>186</td>
|
148
|
+
<td>0</td>
|
149
|
+
<td>186</td>
|
150
|
+
<td>0.0</td>
|
151
|
+
</tr>
|
152
|
+
|
143
153
|
<tr>
|
144
154
|
<td class="strong"><a href="#1fa9099a69ac9fedd79846842381b07491658c37" class="src_link" title="lib/codin_rep/set_time.rb">lib/codin_rep/set_time.rb</a></td>
|
145
155
|
<td class="red strong">0.0 %</td>
|
@@ -364,7 +374,7 @@
|
|
364
374
|
<div class="file_list_container" id="Libraries">
|
365
375
|
<h2>
|
366
376
|
<span class="group_name">Libraries</span>
|
367
|
-
(<span class="covered_percent"><span class="red">0.
|
377
|
+
(<span class="covered_percent"><span class="red">0.19%</span></span>
|
368
378
|
covered at
|
369
379
|
<span class="covered_strength">
|
370
380
|
<span class="red">
|
@@ -374,10 +384,10 @@
|
|
374
384
|
</h2>
|
375
385
|
<a name="Libraries"></a>
|
376
386
|
<div>
|
377
|
-
<b>
|
378
|
-
<b>
|
387
|
+
<b>13</b> files in total.
|
388
|
+
<b>1067</b> relevant lines.
|
379
389
|
<span class="green"><b>2</b> lines covered</span> and
|
380
|
-
<span class="red"><b>
|
390
|
+
<span class="red"><b>1065</b> lines missed </span>
|
381
391
|
</div>
|
382
392
|
<table class="file_list">
|
383
393
|
<thead>
|
@@ -483,6 +493,16 @@
|
|
483
493
|
<td>0.0</td>
|
484
494
|
</tr>
|
485
495
|
|
496
|
+
<tr>
|
497
|
+
<td class="strong"><a href="#eafa662feda24b9dc266cb168febb2abf1d20de2" class="src_link" title="lib/codin_rep/mock_time_clock.rb">lib/codin_rep/mock_time_clock.rb</a></td>
|
498
|
+
<td class="red strong">0.0 %</td>
|
499
|
+
<td>186</td>
|
500
|
+
<td>186</td>
|
501
|
+
<td>0</td>
|
502
|
+
<td>186</td>
|
503
|
+
<td>0.0</td>
|
504
|
+
</tr>
|
505
|
+
|
486
506
|
<tr>
|
487
507
|
<td class="strong"><a href="#1fa9099a69ac9fedd79846842381b07491658c37" class="src_link" title="lib/codin_rep/set_time.rb">lib/codin_rep/set_time.rb</a></td>
|
488
508
|
<td class="red strong">0.0 %</td>
|
@@ -5292,6 +5312,1140 @@
|
|
5292
5312
|
</pre>
|
5293
5313
|
</div>
|
5294
5314
|
|
5315
|
+
<div class="source_table" id="eafa662feda24b9dc266cb168febb2abf1d20de2">
|
5316
|
+
<div class="header">
|
5317
|
+
<h3>lib/codin_rep/mock_time_clock.rb</h3>
|
5318
|
+
<h4><span class="red">0.0 %</span> covered</h4>
|
5319
|
+
<div>
|
5320
|
+
<b>186</b> relevant lines.
|
5321
|
+
<span class="green"><b>0</b> lines covered</span> and
|
5322
|
+
<span class="red"><b>186</b> lines missed.</span>
|
5323
|
+
</div>
|
5324
|
+
</div>
|
5325
|
+
|
5326
|
+
<pre>
|
5327
|
+
<ol>
|
5328
|
+
|
5329
|
+
<li class="missed" data-hits="0" data-linenumber="1">
|
5330
|
+
|
5331
|
+
|
5332
|
+
<code class="ruby"># -*- coding: utf-8 -*-</code>
|
5333
|
+
</li>
|
5334
|
+
|
5335
|
+
<li class="missed" data-hits="0" data-linenumber="2">
|
5336
|
+
|
5337
|
+
|
5338
|
+
<code class="ruby"># codin_rep - Gem para acesso de REPs da Telebyte</code>
|
5339
|
+
</li>
|
5340
|
+
|
5341
|
+
<li class="missed" data-hits="0" data-linenumber="3">
|
5342
|
+
|
5343
|
+
|
5344
|
+
<code class="ruby"># Copyright (C) 2016 O.S. Systems Softwares Ltda.</code>
|
5345
|
+
</li>
|
5346
|
+
|
5347
|
+
<li class="missed" data-hits="0" data-linenumber="4">
|
5348
|
+
|
5349
|
+
|
5350
|
+
<code class="ruby"></code>
|
5351
|
+
</li>
|
5352
|
+
|
5353
|
+
<li class="missed" data-hits="0" data-linenumber="5">
|
5354
|
+
|
5355
|
+
|
5356
|
+
<code class="ruby"># This program is free software: you can redistribute it and/or modify</code>
|
5357
|
+
</li>
|
5358
|
+
|
5359
|
+
<li class="missed" data-hits="0" data-linenumber="6">
|
5360
|
+
|
5361
|
+
|
5362
|
+
<code class="ruby"># it under the terms of the GNU Affero General Public License as</code>
|
5363
|
+
</li>
|
5364
|
+
|
5365
|
+
<li class="missed" data-hits="0" data-linenumber="7">
|
5366
|
+
|
5367
|
+
|
5368
|
+
<code class="ruby"># published by the Free Software Foundation, either version 3 of the</code>
|
5369
|
+
</li>
|
5370
|
+
|
5371
|
+
<li class="missed" data-hits="0" data-linenumber="8">
|
5372
|
+
|
5373
|
+
|
5374
|
+
<code class="ruby"># License, or (at your option) any later version.</code>
|
5375
|
+
</li>
|
5376
|
+
|
5377
|
+
<li class="missed" data-hits="0" data-linenumber="9">
|
5378
|
+
|
5379
|
+
|
5380
|
+
<code class="ruby"></code>
|
5381
|
+
</li>
|
5382
|
+
|
5383
|
+
<li class="missed" data-hits="0" data-linenumber="10">
|
5384
|
+
|
5385
|
+
|
5386
|
+
<code class="ruby"># This program is distributed in the hope that it will be useful,</code>
|
5387
|
+
</li>
|
5388
|
+
|
5389
|
+
<li class="missed" data-hits="0" data-linenumber="11">
|
5390
|
+
|
5391
|
+
|
5392
|
+
<code class="ruby"># but WITHOUT ANY WARRANTY; without even the implied warranty of</code>
|
5393
|
+
</li>
|
5394
|
+
|
5395
|
+
<li class="missed" data-hits="0" data-linenumber="12">
|
5396
|
+
|
5397
|
+
|
5398
|
+
<code class="ruby"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</code>
|
5399
|
+
</li>
|
5400
|
+
|
5401
|
+
<li class="missed" data-hits="0" data-linenumber="13">
|
5402
|
+
|
5403
|
+
|
5404
|
+
<code class="ruby"># GNU Affero General Public License for more details.</code>
|
5405
|
+
</li>
|
5406
|
+
|
5407
|
+
<li class="missed" data-hits="0" data-linenumber="14">
|
5408
|
+
|
5409
|
+
|
5410
|
+
<code class="ruby"></code>
|
5411
|
+
</li>
|
5412
|
+
|
5413
|
+
<li class="missed" data-hits="0" data-linenumber="15">
|
5414
|
+
|
5415
|
+
|
5416
|
+
<code class="ruby"># You should have received a copy of the GNU Affero General Public License</code>
|
5417
|
+
</li>
|
5418
|
+
|
5419
|
+
<li class="missed" data-hits="0" data-linenumber="16">
|
5420
|
+
|
5421
|
+
|
5422
|
+
<code class="ruby"># along with this program. If not, see <http://www.gnu.org/licenses/>.</code>
|
5423
|
+
</li>
|
5424
|
+
|
5425
|
+
<li class="missed" data-hits="0" data-linenumber="17">
|
5426
|
+
|
5427
|
+
|
5428
|
+
<code class="ruby"></code>
|
5429
|
+
</li>
|
5430
|
+
|
5431
|
+
<li class="missed" data-hits="0" data-linenumber="18">
|
5432
|
+
|
5433
|
+
|
5434
|
+
<code class="ruby"># Rua Clóvis Gularte Candiota 132, Pelotas-RS, Brasil.</code>
|
5435
|
+
</li>
|
5436
|
+
|
5437
|
+
<li class="missed" data-hits="0" data-linenumber="19">
|
5438
|
+
|
5439
|
+
|
5440
|
+
<code class="ruby"># e-mail: contato@ossystems.com.br</code>
|
5441
|
+
</li>
|
5442
|
+
|
5443
|
+
<li class="missed" data-hits="0" data-linenumber="20">
|
5444
|
+
|
5445
|
+
|
5446
|
+
<code class="ruby"></code>
|
5447
|
+
</li>
|
5448
|
+
|
5449
|
+
<li class="missed" data-hits="0" data-linenumber="21">
|
5450
|
+
|
5451
|
+
|
5452
|
+
<code class="ruby">require 'codin_rep'</code>
|
5453
|
+
</li>
|
5454
|
+
|
5455
|
+
<li class="missed" data-hits="0" data-linenumber="22">
|
5456
|
+
|
5457
|
+
|
5458
|
+
<code class="ruby">require 'codin_rep/time_util'</code>
|
5459
|
+
</li>
|
5460
|
+
|
5461
|
+
<li class="missed" data-hits="0" data-linenumber="23">
|
5462
|
+
|
5463
|
+
|
5464
|
+
<code class="ruby">require 'socket'</code>
|
5465
|
+
</li>
|
5466
|
+
|
5467
|
+
<li class="missed" data-hits="0" data-linenumber="24">
|
5468
|
+
|
5469
|
+
|
5470
|
+
<code class="ruby"></code>
|
5471
|
+
</li>
|
5472
|
+
|
5473
|
+
<li class="missed" data-hits="0" data-linenumber="25">
|
5474
|
+
|
5475
|
+
|
5476
|
+
<code class="ruby">module CodinRep</code>
|
5477
|
+
</li>
|
5478
|
+
|
5479
|
+
<li class="missed" data-hits="0" data-linenumber="26">
|
5480
|
+
|
5481
|
+
|
5482
|
+
<code class="ruby"> class MockTimeClock</code>
|
5483
|
+
</li>
|
5484
|
+
|
5485
|
+
<li class="missed" data-hits="0" data-linenumber="27">
|
5486
|
+
|
5487
|
+
|
5488
|
+
<code class="ruby"> include CodinRep</code>
|
5489
|
+
</li>
|
5490
|
+
|
5491
|
+
<li class="missed" data-hits="0" data-linenumber="28">
|
5492
|
+
|
5493
|
+
|
5494
|
+
<code class="ruby"></code>
|
5495
|
+
</li>
|
5496
|
+
|
5497
|
+
<li class="missed" data-hits="0" data-linenumber="29">
|
5498
|
+
|
5499
|
+
|
5500
|
+
<code class="ruby"> attr_reader :data, :ip</code>
|
5501
|
+
</li>
|
5502
|
+
|
5503
|
+
<li class="missed" data-hits="0" data-linenumber="30">
|
5504
|
+
|
5505
|
+
|
5506
|
+
<code class="ruby"></code>
|
5507
|
+
</li>
|
5508
|
+
|
5509
|
+
<li class="missed" data-hits="0" data-linenumber="31">
|
5510
|
+
|
5511
|
+
|
5512
|
+
<code class="ruby"> def initialize</code>
|
5513
|
+
</li>
|
5514
|
+
|
5515
|
+
<li class="missed" data-hits="0" data-linenumber="32">
|
5516
|
+
|
5517
|
+
|
5518
|
+
<code class="ruby"> @data = OpenStruct.new</code>
|
5519
|
+
</li>
|
5520
|
+
|
5521
|
+
<li class="missed" data-hits="0" data-linenumber="33">
|
5522
|
+
|
5523
|
+
|
5524
|
+
<code class="ruby"> @ip = '127.0.0.1'</code>
|
5525
|
+
</li>
|
5526
|
+
|
5527
|
+
<li class="missed" data-hits="0" data-linenumber="34">
|
5528
|
+
|
5529
|
+
|
5530
|
+
<code class="ruby"> @server = TCPServer.new(@ip, 0)</code>
|
5531
|
+
</li>
|
5532
|
+
|
5533
|
+
<li class="missed" data-hits="0" data-linenumber="35">
|
5534
|
+
|
5535
|
+
|
5536
|
+
<code class="ruby"> @running = false</code>
|
5537
|
+
</li>
|
5538
|
+
|
5539
|
+
<li class="missed" data-hits="0" data-linenumber="36">
|
5540
|
+
|
5541
|
+
|
5542
|
+
<code class="ruby"> @served_connections = 0</code>
|
5543
|
+
</li>
|
5544
|
+
|
5545
|
+
<li class="missed" data-hits="0" data-linenumber="37">
|
5546
|
+
|
5547
|
+
|
5548
|
+
<code class="ruby"> @threads = []</code>
|
5549
|
+
</li>
|
5550
|
+
|
5551
|
+
<li class="missed" data-hits="0" data-linenumber="38">
|
5552
|
+
|
5553
|
+
|
5554
|
+
<code class="ruby"> @threadsMutex = Mutex.new</code>
|
5555
|
+
</li>
|
5556
|
+
|
5557
|
+
<li class="missed" data-hits="0" data-linenumber="39">
|
5558
|
+
|
5559
|
+
|
5560
|
+
<code class="ruby"> @served_connections = 0</code>
|
5561
|
+
</li>
|
5562
|
+
|
5563
|
+
<li class="missed" data-hits="0" data-linenumber="40">
|
5564
|
+
|
5565
|
+
|
5566
|
+
<code class="ruby"> @time = true</code>
|
5567
|
+
</li>
|
5568
|
+
|
5569
|
+
<li class="missed" data-hits="0" data-linenumber="41">
|
5570
|
+
|
5571
|
+
|
5572
|
+
<code class="ruby"> @is_sending_records = false</code>
|
5573
|
+
</li>
|
5574
|
+
|
5575
|
+
<li class="missed" data-hits="0" data-linenumber="42">
|
5576
|
+
|
5577
|
+
|
5578
|
+
<code class="ruby"> end</code>
|
5579
|
+
</li>
|
5580
|
+
|
5581
|
+
<li class="missed" data-hits="0" data-linenumber="43">
|
5582
|
+
|
5583
|
+
|
5584
|
+
<code class="ruby"></code>
|
5585
|
+
</li>
|
5586
|
+
|
5587
|
+
<li class="missed" data-hits="0" data-linenumber="44">
|
5588
|
+
|
5589
|
+
|
5590
|
+
<code class="ruby"> def tcp_port</code>
|
5591
|
+
</li>
|
5592
|
+
|
5593
|
+
<li class="missed" data-hits="0" data-linenumber="45">
|
5594
|
+
|
5595
|
+
|
5596
|
+
<code class="ruby"> @server.addr[1]</code>
|
5597
|
+
</li>
|
5598
|
+
|
5599
|
+
<li class="missed" data-hits="0" data-linenumber="46">
|
5600
|
+
|
5601
|
+
|
5602
|
+
<code class="ruby"> end</code>
|
5603
|
+
</li>
|
5604
|
+
|
5605
|
+
<li class="missed" data-hits="0" data-linenumber="47">
|
5606
|
+
|
5607
|
+
|
5608
|
+
<code class="ruby"></code>
|
5609
|
+
</li>
|
5610
|
+
|
5611
|
+
<li class="missed" data-hits="0" data-linenumber="48">
|
5612
|
+
|
5613
|
+
|
5614
|
+
<code class="ruby"> def serve(socket)</code>
|
5615
|
+
</li>
|
5616
|
+
|
5617
|
+
<li class="missed" data-hits="0" data-linenumber="49">
|
5618
|
+
|
5619
|
+
|
5620
|
+
<code class="ruby"> Thread.new do</code>
|
5621
|
+
</li>
|
5622
|
+
|
5623
|
+
<li class="missed" data-hits="0" data-linenumber="50">
|
5624
|
+
|
5625
|
+
|
5626
|
+
<code class="ruby"> Thread.current.abort_on_exception = true</code>
|
5627
|
+
</li>
|
5628
|
+
|
5629
|
+
<li class="missed" data-hits="0" data-linenumber="51">
|
5630
|
+
|
5631
|
+
|
5632
|
+
<code class="ruby"> @threadsMutex.synchronize {</code>
|
5633
|
+
</li>
|
5634
|
+
|
5635
|
+
<li class="missed" data-hits="0" data-linenumber="52">
|
5636
|
+
|
5637
|
+
|
5638
|
+
<code class="ruby"> @threads << Thread.current</code>
|
5639
|
+
</li>
|
5640
|
+
|
5641
|
+
<li class="missed" data-hits="0" data-linenumber="53">
|
5642
|
+
|
5643
|
+
|
5644
|
+
<code class="ruby"> @served_connections += 1</code>
|
5645
|
+
</li>
|
5646
|
+
|
5647
|
+
<li class="missed" data-hits="0" data-linenumber="54">
|
5648
|
+
|
5649
|
+
|
5650
|
+
<code class="ruby"> }</code>
|
5651
|
+
</li>
|
5652
|
+
|
5653
|
+
<li class="missed" data-hits="0" data-linenumber="55">
|
5654
|
+
|
5655
|
+
|
5656
|
+
<code class="ruby"> begin</code>
|
5657
|
+
</li>
|
5658
|
+
|
5659
|
+
<li class="missed" data-hits="0" data-linenumber="56">
|
5660
|
+
|
5661
|
+
|
5662
|
+
<code class="ruby"> raw_command = []</code>
|
5663
|
+
</li>
|
5664
|
+
|
5665
|
+
<li class="missed" data-hits="0" data-linenumber="57">
|
5666
|
+
|
5667
|
+
|
5668
|
+
<code class="ruby"> @keep_connected = true</code>
|
5669
|
+
</li>
|
5670
|
+
|
5671
|
+
<li class="missed" data-hits="0" data-linenumber="58">
|
5672
|
+
|
5673
|
+
|
5674
|
+
<code class="ruby"> @first_connection = true</code>
|
5675
|
+
</li>
|
5676
|
+
|
5677
|
+
<li class="missed" data-hits="0" data-linenumber="59">
|
5678
|
+
|
5679
|
+
|
5680
|
+
<code class="ruby"> # Read command type</code>
|
5681
|
+
</li>
|
5682
|
+
|
5683
|
+
<li class="missed" data-hits="0" data-linenumber="60">
|
5684
|
+
|
5685
|
+
|
5686
|
+
<code class="ruby"> while @keep_connected && raw_command = read_from_socket_with_timeout(socket, 9)</code>
|
5687
|
+
</li>
|
5688
|
+
|
5689
|
+
<li class="missed" data-hits="0" data-linenumber="61">
|
5690
|
+
|
5691
|
+
|
5692
|
+
<code class="ruby"> response = process_command(raw_command, socket)</code>
|
5693
|
+
</li>
|
5694
|
+
|
5695
|
+
<li class="missed" data-hits="0" data-linenumber="62">
|
5696
|
+
|
5697
|
+
|
5698
|
+
<code class="ruby"> socket.write response</code>
|
5699
|
+
</li>
|
5700
|
+
|
5701
|
+
<li class="missed" data-hits="0" data-linenumber="63">
|
5702
|
+
|
5703
|
+
|
5704
|
+
<code class="ruby"> @first_connection = false</code>
|
5705
|
+
</li>
|
5706
|
+
|
5707
|
+
<li class="missed" data-hits="0" data-linenumber="64">
|
5708
|
+
|
5709
|
+
|
5710
|
+
<code class="ruby"> end</code>
|
5711
|
+
</li>
|
5712
|
+
|
5713
|
+
<li class="missed" data-hits="0" data-linenumber="65">
|
5714
|
+
|
5715
|
+
|
5716
|
+
<code class="ruby"> ensure</code>
|
5717
|
+
</li>
|
5718
|
+
|
5719
|
+
<li class="missed" data-hits="0" data-linenumber="66">
|
5720
|
+
|
5721
|
+
|
5722
|
+
<code class="ruby"> socket.close unless socket.closed?</code>
|
5723
|
+
</li>
|
5724
|
+
|
5725
|
+
<li class="missed" data-hits="0" data-linenumber="67">
|
5726
|
+
|
5727
|
+
|
5728
|
+
<code class="ruby"> @threadsMutex.synchronize {</code>
|
5729
|
+
</li>
|
5730
|
+
|
5731
|
+
<li class="missed" data-hits="0" data-linenumber="68">
|
5732
|
+
|
5733
|
+
|
5734
|
+
<code class="ruby"> @threads.delete(Thread.current)</code>
|
5735
|
+
</li>
|
5736
|
+
|
5737
|
+
<li class="missed" data-hits="0" data-linenumber="69">
|
5738
|
+
|
5739
|
+
|
5740
|
+
<code class="ruby"> }</code>
|
5741
|
+
</li>
|
5742
|
+
|
5743
|
+
<li class="missed" data-hits="0" data-linenumber="70">
|
5744
|
+
|
5745
|
+
|
5746
|
+
<code class="ruby"> end</code>
|
5747
|
+
</li>
|
5748
|
+
|
5749
|
+
<li class="missed" data-hits="0" data-linenumber="71">
|
5750
|
+
|
5751
|
+
|
5752
|
+
<code class="ruby"> end</code>
|
5753
|
+
</li>
|
5754
|
+
|
5755
|
+
<li class="missed" data-hits="0" data-linenumber="72">
|
5756
|
+
|
5757
|
+
|
5758
|
+
<code class="ruby"> end</code>
|
5759
|
+
</li>
|
5760
|
+
|
5761
|
+
<li class="missed" data-hits="0" data-linenumber="73">
|
5762
|
+
|
5763
|
+
|
5764
|
+
<code class="ruby"></code>
|
5765
|
+
</li>
|
5766
|
+
|
5767
|
+
<li class="missed" data-hits="0" data-linenumber="74">
|
5768
|
+
|
5769
|
+
|
5770
|
+
<code class="ruby"> def start</code>
|
5771
|
+
</li>
|
5772
|
+
|
5773
|
+
<li class="missed" data-hits="0" data-linenumber="75">
|
5774
|
+
|
5775
|
+
|
5776
|
+
<code class="ruby"> @server_thread = Thread.new do</code>
|
5777
|
+
</li>
|
5778
|
+
|
5779
|
+
<li class="missed" data-hits="0" data-linenumber="76">
|
5780
|
+
|
5781
|
+
|
5782
|
+
<code class="ruby"> Thread.current.abort_on_exception = true</code>
|
5783
|
+
</li>
|
5784
|
+
|
5785
|
+
<li class="missed" data-hits="0" data-linenumber="77">
|
5786
|
+
|
5787
|
+
|
5788
|
+
<code class="ruby"> @running = true</code>
|
5789
|
+
</li>
|
5790
|
+
|
5791
|
+
<li class="missed" data-hits="0" data-linenumber="78">
|
5792
|
+
|
5793
|
+
|
5794
|
+
<code class="ruby"> while @running</code>
|
5795
|
+
</li>
|
5796
|
+
|
5797
|
+
<li class="missed" data-hits="0" data-linenumber="79">
|
5798
|
+
|
5799
|
+
|
5800
|
+
<code class="ruby"> break if @server.closed?</code>
|
5801
|
+
</li>
|
5802
|
+
|
5803
|
+
<li class="missed" data-hits="0" data-linenumber="80">
|
5804
|
+
|
5805
|
+
|
5806
|
+
<code class="ruby"> socket = @server.accept</code>
|
5807
|
+
</li>
|
5808
|
+
|
5809
|
+
<li class="missed" data-hits="0" data-linenumber="81">
|
5810
|
+
|
5811
|
+
|
5812
|
+
<code class="ruby"> serve(socket)</code>
|
5813
|
+
</li>
|
5814
|
+
|
5815
|
+
<li class="missed" data-hits="0" data-linenumber="82">
|
5816
|
+
|
5817
|
+
|
5818
|
+
<code class="ruby"> end</code>
|
5819
|
+
</li>
|
5820
|
+
|
5821
|
+
<li class="missed" data-hits="0" data-linenumber="83">
|
5822
|
+
|
5823
|
+
|
5824
|
+
<code class="ruby"> end</code>
|
5825
|
+
</li>
|
5826
|
+
|
5827
|
+
<li class="missed" data-hits="0" data-linenumber="84">
|
5828
|
+
|
5829
|
+
|
5830
|
+
<code class="ruby"> self</code>
|
5831
|
+
</li>
|
5832
|
+
|
5833
|
+
<li class="missed" data-hits="0" data-linenumber="85">
|
5834
|
+
|
5835
|
+
|
5836
|
+
<code class="ruby"> end</code>
|
5837
|
+
</li>
|
5838
|
+
|
5839
|
+
<li class="missed" data-hits="0" data-linenumber="86">
|
5840
|
+
|
5841
|
+
|
5842
|
+
<code class="ruby"></code>
|
5843
|
+
</li>
|
5844
|
+
|
5845
|
+
<li class="missed" data-hits="0" data-linenumber="87">
|
5846
|
+
|
5847
|
+
|
5848
|
+
<code class="ruby"> def stop</code>
|
5849
|
+
</li>
|
5850
|
+
|
5851
|
+
<li class="missed" data-hits="0" data-linenumber="88">
|
5852
|
+
|
5853
|
+
|
5854
|
+
<code class="ruby"> @threadsMutex.synchronize {</code>
|
5855
|
+
</li>
|
5856
|
+
|
5857
|
+
<li class="missed" data-hits="0" data-linenumber="89">
|
5858
|
+
|
5859
|
+
|
5860
|
+
<code class="ruby"> @threads.each{|thread| thread.kill}</code>
|
5861
|
+
</li>
|
5862
|
+
|
5863
|
+
<li class="missed" data-hits="0" data-linenumber="90">
|
5864
|
+
|
5865
|
+
|
5866
|
+
<code class="ruby"> @threads = []</code>
|
5867
|
+
</li>
|
5868
|
+
|
5869
|
+
<li class="missed" data-hits="0" data-linenumber="91">
|
5870
|
+
|
5871
|
+
|
5872
|
+
<code class="ruby"> }</code>
|
5873
|
+
</li>
|
5874
|
+
|
5875
|
+
<li class="missed" data-hits="0" data-linenumber="92">
|
5876
|
+
|
5877
|
+
|
5878
|
+
<code class="ruby"> @server_thread.kill if @server_thread</code>
|
5879
|
+
</li>
|
5880
|
+
|
5881
|
+
<li class="missed" data-hits="0" data-linenumber="93">
|
5882
|
+
|
5883
|
+
|
5884
|
+
<code class="ruby"> @server.close unless @server.closed?</code>
|
5885
|
+
</li>
|
5886
|
+
|
5887
|
+
<li class="missed" data-hits="0" data-linenumber="94">
|
5888
|
+
|
5889
|
+
|
5890
|
+
<code class="ruby"> @server_thread.join</code>
|
5891
|
+
</li>
|
5892
|
+
|
5893
|
+
<li class="missed" data-hits="0" data-linenumber="95">
|
5894
|
+
|
5895
|
+
|
5896
|
+
<code class="ruby"> @running = false</code>
|
5897
|
+
</li>
|
5898
|
+
|
5899
|
+
<li class="missed" data-hits="0" data-linenumber="96">
|
5900
|
+
|
5901
|
+
|
5902
|
+
<code class="ruby"> true</code>
|
5903
|
+
</li>
|
5904
|
+
|
5905
|
+
<li class="missed" data-hits="0" data-linenumber="97">
|
5906
|
+
|
5907
|
+
|
5908
|
+
<code class="ruby"> end</code>
|
5909
|
+
</li>
|
5910
|
+
|
5911
|
+
<li class="missed" data-hits="0" data-linenumber="98">
|
5912
|
+
|
5913
|
+
|
5914
|
+
<code class="ruby"></code>
|
5915
|
+
</li>
|
5916
|
+
|
5917
|
+
<li class="missed" data-hits="0" data-linenumber="99">
|
5918
|
+
|
5919
|
+
|
5920
|
+
<code class="ruby"> def running?</code>
|
5921
|
+
</li>
|
5922
|
+
|
5923
|
+
<li class="missed" data-hits="0" data-linenumber="100">
|
5924
|
+
|
5925
|
+
|
5926
|
+
<code class="ruby"> @running</code>
|
5927
|
+
</li>
|
5928
|
+
|
5929
|
+
<li class="missed" data-hits="0" data-linenumber="101">
|
5930
|
+
|
5931
|
+
|
5932
|
+
<code class="ruby"> end</code>
|
5933
|
+
</li>
|
5934
|
+
|
5935
|
+
<li class="missed" data-hits="0" data-linenumber="102">
|
5936
|
+
|
5937
|
+
|
5938
|
+
<code class="ruby"></code>
|
5939
|
+
</li>
|
5940
|
+
|
5941
|
+
<li class="missed" data-hits="0" data-linenumber="103">
|
5942
|
+
|
5943
|
+
|
5944
|
+
<code class="ruby"> private</code>
|
5945
|
+
</li>
|
5946
|
+
|
5947
|
+
<li class="missed" data-hits="0" data-linenumber="104">
|
5948
|
+
|
5949
|
+
|
5950
|
+
<code class="ruby"> def process_command(raw_command, socket)</code>
|
5951
|
+
</li>
|
5952
|
+
|
5953
|
+
<li class="missed" data-hits="0" data-linenumber="105">
|
5954
|
+
|
5955
|
+
|
5956
|
+
<code class="ruby"> case raw_command</code>
|
5957
|
+
</li>
|
5958
|
+
|
5959
|
+
<li class="missed" data-hits="0" data-linenumber="106">
|
5960
|
+
|
5961
|
+
|
5962
|
+
<code class="ruby"> when "PGREP009b" # Get time</code>
|
5963
|
+
</li>
|
5964
|
+
|
5965
|
+
<li class="missed" data-hits="0" data-linenumber="107">
|
5966
|
+
|
5967
|
+
|
5968
|
+
<code class="ruby"> response = 'REP008b' + get_timeclock_time</code>
|
5969
|
+
</li>
|
5970
|
+
|
5971
|
+
<li class="missed" data-hits="0" data-linenumber="108">
|
5972
|
+
|
5973
|
+
|
5974
|
+
<code class="ruby"> when "PGREP016A" # Set time</code>
|
5975
|
+
</li>
|
5976
|
+
|
5977
|
+
<li class="missed" data-hits="0" data-linenumber="109">
|
5978
|
+
|
5979
|
+
|
5980
|
+
<code class="ruby"> payload = read_from_socket_with_timeout(socket, 7)</code>
|
5981
|
+
</li>
|
5982
|
+
|
5983
|
+
<li class="missed" data-hits="0" data-linenumber="110">
|
5984
|
+
|
5985
|
+
|
5986
|
+
<code class="ruby"> response = 'REP008A' + payload</code>
|
5987
|
+
</li>
|
5988
|
+
|
5989
|
+
<li class="missed" data-hits="0" data-linenumber="111">
|
5990
|
+
|
5991
|
+
|
5992
|
+
<code class="ruby"> set_timeclock_time(payload)</code>
|
5993
|
+
</li>
|
5994
|
+
|
5995
|
+
<li class="missed" data-hits="0" data-linenumber="112">
|
5996
|
+
|
5997
|
+
|
5998
|
+
<code class="ruby"> when "PGREP009Z"</code>
|
5999
|
+
</li>
|
6000
|
+
|
6001
|
+
<li class="missed" data-hits="0" data-linenumber="113">
|
6002
|
+
|
6003
|
+
|
6004
|
+
<code class="ruby"> response = 'REP2359' + @data.afd.header.export + "\r\n"</code>
|
6005
|
+
</li>
|
6006
|
+
|
6007
|
+
<li class="missed" data-hits="0" data-linenumber="114">
|
6008
|
+
|
6009
|
+
|
6010
|
+
<code class="ruby"> @keep_connected = false</code>
|
6011
|
+
</li>
|
6012
|
+
|
6013
|
+
<li class="missed" data-hits="0" data-linenumber="115">
|
6014
|
+
|
6015
|
+
|
6016
|
+
<code class="ruby"> when "PGREP0289"</code>
|
6017
|
+
</li>
|
6018
|
+
|
6019
|
+
<li class="missed" data-hits="0" data-linenumber="116">
|
6020
|
+
|
6021
|
+
|
6022
|
+
<code class="ruby"> @afd_read_start_id = read_from_socket_with_timeout(socket, 9).to_i</code>
|
6023
|
+
</li>
|
6024
|
+
|
6025
|
+
<li class="missed" data-hits="0" data-linenumber="117">
|
6026
|
+
|
6027
|
+
|
6028
|
+
<code class="ruby"> @afd_read_end_id = read_from_socket_with_timeout(socket, 9).to_i</code>
|
6029
|
+
</li>
|
6030
|
+
|
6031
|
+
<li class="missed" data-hits="0" data-linenumber="118">
|
6032
|
+
|
6033
|
+
|
6034
|
+
<code class="ruby"> @afd_read_current_id = nil</code>
|
6035
|
+
</li>
|
6036
|
+
|
6037
|
+
<li class="missed" data-hits="0" data-linenumber="119">
|
6038
|
+
|
6039
|
+
|
6040
|
+
<code class="ruby"> @afd_read_finished = false</code>
|
6041
|
+
</li>
|
6042
|
+
|
6043
|
+
<li class="missed" data-hits="0" data-linenumber="120">
|
6044
|
+
|
6045
|
+
|
6046
|
+
<code class="ruby"> response = "REP0029["</code>
|
6047
|
+
</li>
|
6048
|
+
|
6049
|
+
<li class="missed" data-hits="0" data-linenumber="121">
|
6050
|
+
|
6051
|
+
|
6052
|
+
<code class="ruby"> when "PGREP009,"</code>
|
6053
|
+
</li>
|
6054
|
+
|
6055
|
+
<li class="missed" data-hits="0" data-linenumber="122">
|
6056
|
+
|
6057
|
+
|
6058
|
+
<code class="ruby"> if @afd_read_finished</code>
|
6059
|
+
</li>
|
6060
|
+
|
6061
|
+
<li class="missed" data-hits="0" data-linenumber="123">
|
6062
|
+
|
6063
|
+
|
6064
|
+
<code class="ruby"> response = "REP0029]"</code>
|
6065
|
+
</li>
|
6066
|
+
|
6067
|
+
<li class="missed" data-hits="0" data-linenumber="124">
|
6068
|
+
|
6069
|
+
|
6070
|
+
<code class="ruby"> @keep_connected = false</code>
|
6071
|
+
</li>
|
6072
|
+
|
6073
|
+
<li class="missed" data-hits="0" data-linenumber="125">
|
6074
|
+
|
6075
|
+
|
6076
|
+
<code class="ruby"> else</code>
|
6077
|
+
</li>
|
6078
|
+
|
6079
|
+
<li class="missed" data-hits="0" data-linenumber="126">
|
6080
|
+
|
6081
|
+
|
6082
|
+
<code class="ruby"> if @afd_read_current_id.nil?</code>
|
6083
|
+
</li>
|
6084
|
+
|
6085
|
+
<li class="missed" data-hits="0" data-linenumber="127">
|
6086
|
+
|
6087
|
+
|
6088
|
+
<code class="ruby"> @afd_read_current_id = @afd_read_start_id</code>
|
6089
|
+
</li>
|
6090
|
+
|
6091
|
+
<li class="missed" data-hits="0" data-linenumber="128">
|
6092
|
+
|
6093
|
+
|
6094
|
+
<code class="ruby"> response = 'REP3029'</code>
|
6095
|
+
</li>
|
6096
|
+
|
6097
|
+
<li class="missed" data-hits="0" data-linenumber="129">
|
6098
|
+
|
6099
|
+
|
6100
|
+
<code class="ruby"> elsif @afd_read_current_id == @afd_read_end_id or @afd_read_current_id >= @data.afd.records.size</code>
|
6101
|
+
</li>
|
6102
|
+
|
6103
|
+
<li class="missed" data-hits="0" data-linenumber="130">
|
6104
|
+
|
6105
|
+
|
6106
|
+
<code class="ruby"> response = 'REP0909'</code>
|
6107
|
+
</li>
|
6108
|
+
|
6109
|
+
<li class="missed" data-hits="0" data-linenumber="131">
|
6110
|
+
|
6111
|
+
|
6112
|
+
<code class="ruby"> @afd_read_finished = true</code>
|
6113
|
+
</li>
|
6114
|
+
|
6115
|
+
<li class="missed" data-hits="0" data-linenumber="132">
|
6116
|
+
|
6117
|
+
|
6118
|
+
<code class="ruby"> else</code>
|
6119
|
+
</li>
|
6120
|
+
|
6121
|
+
<li class="missed" data-hits="0" data-linenumber="133">
|
6122
|
+
|
6123
|
+
|
6124
|
+
<code class="ruby"> response = 'REP0379'</code>
|
6125
|
+
</li>
|
6126
|
+
|
6127
|
+
<li class="missed" data-hits="0" data-linenumber="134">
|
6128
|
+
|
6129
|
+
|
6130
|
+
<code class="ruby"> end</code>
|
6131
|
+
</li>
|
6132
|
+
|
6133
|
+
<li class="missed" data-hits="0" data-linenumber="135">
|
6134
|
+
|
6135
|
+
|
6136
|
+
<code class="ruby"> afd_records = ([@data.afd.header] + @data.afd.records)</code>
|
6137
|
+
</li>
|
6138
|
+
|
6139
|
+
<li class="missed" data-hits="0" data-linenumber="136">
|
6140
|
+
|
6141
|
+
|
6142
|
+
<code class="ruby"> response += afd_records[@afd_read_current_id].export + "\r\n"</code>
|
6143
|
+
</li>
|
6144
|
+
|
6145
|
+
<li class="missed" data-hits="0" data-linenumber="137">
|
6146
|
+
|
6147
|
+
|
6148
|
+
<code class="ruby"> end</code>
|
6149
|
+
</li>
|
6150
|
+
|
6151
|
+
<li class="missed" data-hits="0" data-linenumber="138">
|
6152
|
+
|
6153
|
+
|
6154
|
+
<code class="ruby"> @afd_read_current_id += 1</code>
|
6155
|
+
</li>
|
6156
|
+
|
6157
|
+
<li class="missed" data-hits="0" data-linenumber="139">
|
6158
|
+
|
6159
|
+
|
6160
|
+
<code class="ruby"> when "PGREP075h"</code>
|
6161
|
+
</li>
|
6162
|
+
|
6163
|
+
<li class="missed" data-hits="0" data-linenumber="140">
|
6164
|
+
|
6165
|
+
|
6166
|
+
<code class="ruby"> payload = read_from_socket_with_timeout(socket, 66)</code>
|
6167
|
+
</li>
|
6168
|
+
|
6169
|
+
<li class="missed" data-hits="0" data-linenumber="141">
|
6170
|
+
|
6171
|
+
|
6172
|
+
<code class="ruby"> raw_registration, raw_pis, raw_name = payload.scan(/.(.{6})(.{6})(.+)/).flatten</code>
|
6173
|
+
</li>
|
6174
|
+
|
6175
|
+
<li class="missed" data-hits="0" data-linenumber="142">
|
6176
|
+
|
6177
|
+
|
6178
|
+
<code class="ruby"> registration = convert_bytes_to_string(raw_registration)</code>
|
6179
|
+
</li>
|
6180
|
+
|
6181
|
+
<li class="missed" data-hits="0" data-linenumber="143">
|
6182
|
+
|
6183
|
+
|
6184
|
+
<code class="ruby"> pis = convert_bytes_to_string(raw_pis)</code>
|
6185
|
+
</li>
|
6186
|
+
|
6187
|
+
<li class="missed" data-hits="0" data-linenumber="144">
|
6188
|
+
|
6189
|
+
|
6190
|
+
<code class="ruby"> name = raw_name.strip</code>
|
6191
|
+
</li>
|
6192
|
+
|
6193
|
+
<li class="missed" data-hits="0" data-linenumber="145">
|
6194
|
+
|
6195
|
+
|
6196
|
+
<code class="ruby"> @data.employees << {name: name, pis: pis, registration: registration}</code>
|
6197
|
+
</li>
|
6198
|
+
|
6199
|
+
<li class="missed" data-hits="0" data-linenumber="146">
|
6200
|
+
|
6201
|
+
|
6202
|
+
<code class="ruby"> response = "REP003h1\0"</code>
|
6203
|
+
</li>
|
6204
|
+
|
6205
|
+
<li class="missed" data-hits="0" data-linenumber="147">
|
6206
|
+
|
6207
|
+
|
6208
|
+
<code class="ruby"> when "PGREP016j"</code>
|
6209
|
+
</li>
|
6210
|
+
|
6211
|
+
<li class="missed" data-hits="0" data-linenumber="148">
|
6212
|
+
|
6213
|
+
|
6214
|
+
<code class="ruby"> payload = read_from_socket_with_timeout(socket, 7)</code>
|
6215
|
+
</li>
|
6216
|
+
|
6217
|
+
<li class="missed" data-hits="0" data-linenumber="149">
|
6218
|
+
|
6219
|
+
|
6220
|
+
<code class="ruby"> raw_registration = payload.scan(/.(.{6})/).flatten[0]</code>
|
6221
|
+
</li>
|
6222
|
+
|
6223
|
+
<li class="missed" data-hits="0" data-linenumber="150">
|
6224
|
+
|
6225
|
+
|
6226
|
+
<code class="ruby"> registration = convert_bytes_to_string(raw_registration)</code>
|
6227
|
+
</li>
|
6228
|
+
|
6229
|
+
<li class="missed" data-hits="0" data-linenumber="151">
|
6230
|
+
|
6231
|
+
|
6232
|
+
<code class="ruby"> @data.employees.delete_if{|employee| employee[:registration] == registration}</code>
|
6233
|
+
</li>
|
6234
|
+
|
6235
|
+
<li class="missed" data-hits="0" data-linenumber="152">
|
6236
|
+
|
6237
|
+
|
6238
|
+
<code class="ruby"> response = "REP003j1\0"</code>
|
6239
|
+
</li>
|
6240
|
+
|
6241
|
+
<li class="missed" data-hits="0" data-linenumber="153">
|
6242
|
+
|
6243
|
+
|
6244
|
+
<code class="ruby"> when 'PGREP010h', 'PGREP010j'</code>
|
6245
|
+
</li>
|
6246
|
+
|
6247
|
+
<li class="missed" data-hits="0" data-linenumber="154">
|
6248
|
+
|
6249
|
+
|
6250
|
+
<code class="ruby"> # Don't care for the result of these comands, just disconnect when</code>
|
6251
|
+
</li>
|
6252
|
+
|
6253
|
+
<li class="missed" data-hits="0" data-linenumber="155">
|
6254
|
+
|
6255
|
+
|
6256
|
+
<code class="ruby"> # possible.</code>
|
6257
|
+
</li>
|
6258
|
+
|
6259
|
+
<li class="missed" data-hits="0" data-linenumber="156">
|
6260
|
+
|
6261
|
+
|
6262
|
+
<code class="ruby"> @keep_connected = false</code>
|
6263
|
+
</li>
|
6264
|
+
|
6265
|
+
<li class="missed" data-hits="0" data-linenumber="157">
|
6266
|
+
|
6267
|
+
|
6268
|
+
<code class="ruby"> response = ""</code>
|
6269
|
+
</li>
|
6270
|
+
|
6271
|
+
<li class="missed" data-hits="0" data-linenumber="158">
|
6272
|
+
|
6273
|
+
|
6274
|
+
<code class="ruby"> else</code>
|
6275
|
+
</li>
|
6276
|
+
|
6277
|
+
<li class="missed" data-hits="0" data-linenumber="159">
|
6278
|
+
|
6279
|
+
|
6280
|
+
<code class="ruby"> raise StandardError.new("Unknown command \"#{raw_command}\"!")</code>
|
6281
|
+
</li>
|
6282
|
+
|
6283
|
+
<li class="missed" data-hits="0" data-linenumber="160">
|
6284
|
+
|
6285
|
+
|
6286
|
+
<code class="ruby"> end</code>
|
6287
|
+
</li>
|
6288
|
+
|
6289
|
+
<li class="missed" data-hits="0" data-linenumber="161">
|
6290
|
+
|
6291
|
+
|
6292
|
+
<code class="ruby"> response</code>
|
6293
|
+
</li>
|
6294
|
+
|
6295
|
+
<li class="missed" data-hits="0" data-linenumber="162">
|
6296
|
+
|
6297
|
+
|
6298
|
+
<code class="ruby"> end</code>
|
6299
|
+
</li>
|
6300
|
+
|
6301
|
+
<li class="missed" data-hits="0" data-linenumber="163">
|
6302
|
+
|
6303
|
+
|
6304
|
+
<code class="ruby"></code>
|
6305
|
+
</li>
|
6306
|
+
|
6307
|
+
<li class="missed" data-hits="0" data-linenumber="164">
|
6308
|
+
|
6309
|
+
|
6310
|
+
<code class="ruby"> def read_from_socket_with_timeout(socket, bytes_to_be_read, timeout_value=5)</code>
|
6311
|
+
</li>
|
6312
|
+
|
6313
|
+
<li class="missed" data-hits="0" data-linenumber="165">
|
6314
|
+
|
6315
|
+
|
6316
|
+
<code class="ruby"> data_to_receive = nil</code>
|
6317
|
+
</li>
|
6318
|
+
|
6319
|
+
<li class="missed" data-hits="0" data-linenumber="166">
|
6320
|
+
|
6321
|
+
|
6322
|
+
<code class="ruby"> timeout_value = 600 if @first_connection # use a large timeout on first connection</code>
|
6323
|
+
</li>
|
6324
|
+
|
6325
|
+
<li class="missed" data-hits="0" data-linenumber="167">
|
6326
|
+
|
6327
|
+
|
6328
|
+
<code class="ruby"> timeout(timeout_value) { data_to_receive = socket.readpartial( bytes_to_be_read ) }</code>
|
6329
|
+
</li>
|
6330
|
+
|
6331
|
+
<li class="missed" data-hits="0" data-linenumber="168">
|
6332
|
+
|
6333
|
+
|
6334
|
+
<code class="ruby"> return data_to_receive</code>
|
6335
|
+
</li>
|
6336
|
+
|
6337
|
+
<li class="missed" data-hits="0" data-linenumber="169">
|
6338
|
+
|
6339
|
+
|
6340
|
+
<code class="ruby"> end</code>
|
6341
|
+
</li>
|
6342
|
+
|
6343
|
+
<li class="missed" data-hits="0" data-linenumber="170">
|
6344
|
+
|
6345
|
+
|
6346
|
+
<code class="ruby"></code>
|
6347
|
+
</li>
|
6348
|
+
|
6349
|
+
<li class="missed" data-hits="0" data-linenumber="171">
|
6350
|
+
|
6351
|
+
|
6352
|
+
<code class="ruby"> def get_timeclock_time(current_time=nil)</code>
|
6353
|
+
</li>
|
6354
|
+
|
6355
|
+
<li class="missed" data-hits="0" data-linenumber="172">
|
6356
|
+
|
6357
|
+
|
6358
|
+
<code class="ruby"> current_time ||= @data.time</code>
|
6359
|
+
</li>
|
6360
|
+
|
6361
|
+
<li class="missed" data-hits="0" data-linenumber="173">
|
6362
|
+
|
6363
|
+
|
6364
|
+
<code class="ruby"> CodinRep::TimeUtil.pack current_time</code>
|
6365
|
+
</li>
|
6366
|
+
|
6367
|
+
<li class="missed" data-hits="0" data-linenumber="174">
|
6368
|
+
|
6369
|
+
|
6370
|
+
<code class="ruby"> end</code>
|
6371
|
+
</li>
|
6372
|
+
|
6373
|
+
<li class="missed" data-hits="0" data-linenumber="175">
|
6374
|
+
|
6375
|
+
|
6376
|
+
<code class="ruby"></code>
|
6377
|
+
</li>
|
6378
|
+
|
6379
|
+
<li class="missed" data-hits="0" data-linenumber="176">
|
6380
|
+
|
6381
|
+
|
6382
|
+
<code class="ruby"> def set_timeclock_time(payload)</code>
|
6383
|
+
</li>
|
6384
|
+
|
6385
|
+
<li class="missed" data-hits="0" data-linenumber="177">
|
6386
|
+
|
6387
|
+
|
6388
|
+
<code class="ruby"> time = CodinRep::TimeUtil.unpack payload</code>
|
6389
|
+
</li>
|
6390
|
+
|
6391
|
+
<li class="missed" data-hits="0" data-linenumber="178">
|
6392
|
+
|
6393
|
+
|
6394
|
+
<code class="ruby"> @data.time = time</code>
|
6395
|
+
</li>
|
6396
|
+
|
6397
|
+
<li class="missed" data-hits="0" data-linenumber="179">
|
6398
|
+
|
6399
|
+
|
6400
|
+
<code class="ruby"> return time</code>
|
6401
|
+
</li>
|
6402
|
+
|
6403
|
+
<li class="missed" data-hits="0" data-linenumber="180">
|
6404
|
+
|
6405
|
+
|
6406
|
+
<code class="ruby"> end</code>
|
6407
|
+
</li>
|
6408
|
+
|
6409
|
+
<li class="missed" data-hits="0" data-linenumber="181">
|
6410
|
+
|
6411
|
+
|
6412
|
+
<code class="ruby"></code>
|
6413
|
+
</li>
|
6414
|
+
|
6415
|
+
<li class="missed" data-hits="0" data-linenumber="182">
|
6416
|
+
|
6417
|
+
|
6418
|
+
<code class="ruby"> def convert_bytes_to_string(bytes)</code>
|
6419
|
+
</li>
|
6420
|
+
|
6421
|
+
<li class="missed" data-hits="0" data-linenumber="183">
|
6422
|
+
|
6423
|
+
|
6424
|
+
<code class="ruby"> bytes.unpack('H*')[0]</code>
|
6425
|
+
</li>
|
6426
|
+
|
6427
|
+
<li class="missed" data-hits="0" data-linenumber="184">
|
6428
|
+
|
6429
|
+
|
6430
|
+
<code class="ruby"> end</code>
|
6431
|
+
</li>
|
6432
|
+
|
6433
|
+
<li class="missed" data-hits="0" data-linenumber="185">
|
6434
|
+
|
6435
|
+
|
6436
|
+
<code class="ruby"> end</code>
|
6437
|
+
</li>
|
6438
|
+
|
6439
|
+
<li class="missed" data-hits="0" data-linenumber="186">
|
6440
|
+
|
6441
|
+
|
6442
|
+
<code class="ruby">end</code>
|
6443
|
+
</li>
|
6444
|
+
|
6445
|
+
</ol>
|
6446
|
+
</pre>
|
6447
|
+
</div>
|
6448
|
+
|
5295
6449
|
<div class="source_table" id="1fa9099a69ac9fedd79846842381b07491658c37">
|
5296
6450
|
<div class="header">
|
5297
6451
|
<h3>lib/codin_rep/set_time.rb</h3>
|
@@ -6143,7 +7297,7 @@
|
|
6143
7297
|
<li class="covered" data-hits="1" data-linenumber="22">
|
6144
7298
|
<span class="hits">1</span>
|
6145
7299
|
|
6146
|
-
<code class="ruby"> VERSION = "0.
|
7300
|
+
<code class="ruby"> VERSION = "0.2.0".freeze</code>
|
6147
7301
|
</li>
|
6148
7302
|
|
6149
7303
|
<li class="never" data-hits="" data-linenumber="23">
|