ruby_astm 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_astm/lab_interface.rb +75 -33
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8929f2849304da9211d8a1bc5dda4f531d86b1efd93c0961c5911fd850b166c
4
- data.tar.gz: 2582f498e916278c9795fbe3dd9438223e9c890eb19094c50ea8ca4b8bb38f7c
3
+ metadata.gz: 34dfde956008c06eeb01284d7094a1a641eeee761688883c15973d82b27b395b
4
+ data.tar.gz: e82af600dfdb7f790e3f18282a14b2963cd307a9eaa9281b6f00bc1a8c72edd3
5
5
  SHA512:
6
- metadata.gz: 1f646e07f6c22da4abc05758095158743b1e19995beff2f90392369e2445141a3afe2ea620bd977cedc0ec79cd6d2158f5b760c527aed13af401d56c7b3a8c30
7
- data.tar.gz: da45a2cfd005e8353e5df652e536499876684f9cb7eff7f1d89b5d246f982ed640ea47355b838e4c367df545062cf62a7d74049ad4e73618009e05f2e6895926
6
+ metadata.gz: 137bbe38d4e0273d68db494c313a969d6bda3e6ce078e048551364b2f086e7358edde9236ce21aeb8e2484d0d205b92804813b3c1a4858d7dc3da0d5bc59c955
7
+ data.tar.gz: 283cac2f5215effe5d55d379f8984b37caac8bd15fa7aa6d44b6a3e803ce2c28697444203ba4d7bd465fe7231d0ba3f68b396c0cc91e8a6d3a635238e6a50c5c
@@ -22,6 +22,9 @@ module LabInterface
22
22
  mattr_accessor :usb_parity
23
23
  mattr_accessor :mid_frame_end_detected
24
24
 
25
+ ## gather bytes to store for us to test.
26
+ mattr_accessor :test_data_bytes
27
+
25
28
 
26
29
 
27
30
  mattr_accessor :headers
@@ -50,6 +53,8 @@ module LabInterface
50
53
  end
51
54
 
52
55
 
56
+
57
+
53
58
  def terminator
54
59
  "L|1|N\r"
55
60
  end
@@ -91,50 +96,57 @@ module LabInterface
91
96
  end
92
97
 
93
98
  def is_mid_frame_end?(bytes_array)
99
+
100
+ ## if you get 13,10,2 anywhere, ignore that and the subsequent digit.
101
+ bytes_indices_to_delete = []
94
102
  unless bytes_array.blank?
95
- if bytes_array.size >= 6
96
- if bytes_array[-6..-1] == [23,65,52,13,10,2]
97
- self.mid_frame_end_detected = true
98
- return self.mid_frame_end_detected
103
+ bytes_array.each_with_index{|val,key|
104
+ if bytes_array.size >= (key + 2)
105
+ if bytes_array[key..(key+2)] == [13,10,2]
106
+ bytes_indices_to_delete.push(key - 3)
107
+ bytes_indices_to_delete.push(key - 2)
108
+ bytes_indices_to_delete.push(key - 1)
109
+ bytes_indices_to_delete.push(key)
110
+ bytes_indices_to_delete.push(key + 1)
111
+ bytes_indices_to_delete.push(key + 2)
112
+ end
99
113
  end
100
- end
114
+ }
101
115
  end
102
- return false
116
+ bytes_indices_to_delete
103
117
  end
104
118
 
105
- def receive_data(data)
106
-
107
-
108
- begin
119
+ def pre_process_bytes(byte_arr,concat)
109
120
 
121
+ puts byte_arr.to_s
122
+ indices_to_delete = is_mid_frame_end?(byte_arr)
123
+ #puts "indices to delete"
124
+ #puts indices_to_delete.to_s
110
125
 
111
- self.data_buffer ||= ''
112
-
113
- #puts "incoming data bytes."
114
-
115
- concat = ""
116
-
117
- #puts data.bytes.to_a.to_s
118
-
119
-
120
- ## if the bytes end in 13,10,2
121
- ## that means frame ends and restarts
122
- ## ignore those three bytes
123
- byte_arr = data.bytes.to_a
124
- #puts "byte arr is:"
125
- #puts byte_arr
126
-
127
- if is_mid_frame_end?(byte_arr)
128
- #puts "mid frame end is true---------------!!!!!!!!!!"
129
- byte_arr = byte_arr[0..-7]
130
- #puts "byte arr BECOMES mid frame end is true---------------!!!!!!!!!!"
131
- #puts byte_arr.pack('c*')
132
- elsif self.mid_frame_end_detected == true
133
- ## we ignore the frame number.
126
+ if self.mid_frame_end_detected == true
127
+ #puts "deletected mid fram is true, so deleting first byte before delete"
128
+ #puts byte_arr.to_s
134
129
  byte_arr = byte_arr[1..-1]
130
+ #puts "after deleteing"
131
+ #puts byte_arr.to_s
135
132
  self.mid_frame_end_detected = false
136
133
  end
137
134
 
135
+ unless indices_to_delete.blank?
136
+ if byte_arr[(indices_to_delete[-1] + 1)]
137
+ #puts "before deleting frame number "
138
+ #puts byte_arr.to_s
139
+ byte_arr.delete_at((indices_to_delete[-1] + 1))
140
+ #puts "after deleting"
141
+ #puts byte_arr.to_s
142
+ else
143
+ self.mid_frame_end_detected = true
144
+ end
145
+ end
146
+ #puts "byte arr before reject"
147
+ byte_arr = byte_arr.reject.with_index{|c,i| indices_to_delete.include? i}
148
+
149
+
138
150
  byte_arr.each do |byte|
139
151
  x = [byte].pack('c*').force_encoding('UTF-8')
140
152
  if x == "\r"
@@ -148,6 +160,31 @@ module LabInterface
148
160
  concat+=x
149
161
  end
150
162
  end
163
+
164
+ concat
165
+
166
+ end
167
+
168
+ def receive_data(data)
169
+
170
+
171
+ begin
172
+
173
+
174
+ self.data_buffer ||= ''
175
+
176
+ #puts "incoming data bytes."
177
+
178
+ concat = ""
179
+
180
+
181
+ byte_arr = data.bytes.to_a
182
+ self.test_data_bytes ||= []
183
+ self.test_data_bytes.push(byte_arr)
184
+
185
+ concat = pre_process_bytes(byte_arr,concat)
186
+
187
+
151
188
 
152
189
  #puts "concat is:"
153
190
 
@@ -163,6 +200,10 @@ module LabInterface
163
200
  if data.bytes.to_a[-1] == 4
164
201
  #puts "GOT EOT --- PROCESSING BUFFER, AND CLEARING."
165
202
  process_text(self.data_buffer)
203
+ #root_path = File.dirname __dir
204
+ #puts "root path #{root_path}"
205
+ #IO.write((File.join root_path,'test','resources','roche_multi_frame_bytes.txt'),self.test_data_bytes.to_s)
206
+ #puts self.test_data_bytes.flatten.to_s
166
207
  self.data_buffer = ''
167
208
  if self.headers[-1].queries.blank?
168
209
  #puts "no queries in header so sending ack after getting EOT and processing the buffer"
@@ -240,6 +281,7 @@ module LabInterface
240
281
  puts "text is:"
241
282
  puts text
242
283
  text.split("\n").each do |l|
284
+ puts "doing line:#{l}"
243
285
  line = Line.new({:text => l})
244
286
  process_type(line)
245
287
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_astm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bhargav Raut