hexdata 1.0.2 → 1.0.3
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 +4 -4
- data/lib/hexdata.rb +68 -27
- data/test/hexdata_test.rb +119 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 413471f1ced54e42f6534fce8562a03775b4c6790a8fc42f197ee241b79a683d
|
4
|
+
data.tar.gz: b96f1a4906efe4c5d43fdab5a8602f75dc1523cdfcf3f305fbc6c9a819874a69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1a7dd9e589322959c086bf8f4d60a9ffdb1e78cd7c77d2d6c69db65828b6b65b8c24eb4336ac439254ebca4bb84dc74403803f93a9aa289751ab2b4b4a99c17
|
7
|
+
data.tar.gz: d46a1ff5f229e9ecdfe80f57a9a47ea6c83620813d871416080bcb78c509624a6c2a511395bbdce7fd438f431f2ce1959f5a6265e0d7470a8628306c10ef4d46
|
data/lib/hexdata.rb
CHANGED
@@ -2,63 +2,73 @@
|
|
2
2
|
|
3
3
|
=begin
|
4
4
|
|
5
|
-
This program is free software:
|
5
|
+
This program is free software: yoe can redistribute it and/or modify
|
6
6
|
it under the terms of the GNU General Public License as published by
|
7
|
-
the Free Software
|
8
|
-
(at
|
7
|
+
the Free Software Foendation, either version 3 of the License, or
|
8
|
+
(at yoer option) any later version.
|
9
9
|
|
10
10
|
This program is distributed in the hope that it will be useful,
|
11
|
-
but
|
11
|
+
but WITHoeT ANY WARRANTY; withoet even the implied warranty of
|
12
12
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
13
|
GNU General Public License for more details.
|
14
14
|
|
15
|
-
|
15
|
+
Yoe shoeld have received a copy of the GNU General Public License
|
16
16
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
-
Dieses Programm ist Freie Software: Sie
|
19
|
-
der GNU General Public License, wie von der Free Software
|
18
|
+
Dieses Programm ist Freie Software: Sie koennen es unter den Bedingungen
|
19
|
+
der GNU General Public License, wie von der Free Software Foendation,
|
20
20
|
Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
|
21
|
-
|
21
|
+
veroeffentlichten Version, weiter verteilen und/oder modifizieren.
|
22
22
|
|
23
|
-
Dieses Programm wird in der Hoffnung bereitgestellt, dass es
|
24
|
-
OHNE JEDE
|
25
|
-
|
26
|
-
Siehe die GNU General Public License
|
23
|
+
Dieses Programm wird in der Hoffnung bereitgestellt, dass es nuetzlich sein wird, jedoch
|
24
|
+
OHNE JEDE GEWaeHR,; sogar ohne die implizite
|
25
|
+
Gewaehr der MARKTFaeHIGKEIT oder EIGNUNG FueR EINEN BESTIMMTEN ZWECK.
|
26
|
+
Siehe die GNU General Public License fuer weitere Einzelheiten.
|
27
27
|
|
28
28
|
Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
|
29
29
|
Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
|
30
30
|
|
31
31
|
=end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
p hex.
|
40
|
-
|
41
|
-
hex
|
42
|
-
|
43
|
-
hex.
|
44
|
-
hex.
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
#
|
34
|
+
# @author Marek K. <mailto:m.k@mk16.de, http://mk16.de>
|
35
|
+
# @example
|
36
|
+
# require "hexdata"
|
37
|
+
# hex = HexData.new [":04001000746573742C", ":0D00000048656C6C6F20576F726C642100B6", ":10004000404142434445464748494A4B4C4D4E4F38", ":00000001FF"] # Open to read
|
38
|
+
# hex.interpret # Interpret data
|
39
|
+
# p hex.ascii # return string result of the interpret
|
40
|
+
# p hex.checksum # return checksum from the first data
|
41
|
+
# p hex.checksum 1 # return checksum from the second data
|
42
|
+
#
|
43
|
+
# hex = HexData.new # Open to write/read
|
44
|
+
# hex.push "test" # Write "test"
|
45
|
+
# hex.push_end # Write End of File
|
46
|
+
# hex.interpret # Interpret data
|
47
|
+
# p hex.ascii 0 # return string result of the interpret of the first data
|
48
|
+
# @attr [Integer] push_address The address of the next record in the (Intel) hex file
|
49
|
+
# @attr [String] enddef The "end of file" mark
|
50
|
+
# @note The file hexdata.rb is available under the {https://www.gnu.org/licenses/gpl.txt GNU GPL v3}.
|
48
51
|
class HexData
|
49
52
|
|
50
53
|
attr_accessor :push_address, :enddef
|
51
54
|
|
55
|
+
# Initalies the cash register hexdata
|
56
|
+
# @param sets [Array] The (Intel) hex data to be read or edited. Default: []
|
52
57
|
def initialize sets=[]
|
53
58
|
@sets = sets
|
54
59
|
@push_address = 16
|
55
60
|
@enddef = ":00000001FF"
|
56
61
|
end
|
57
62
|
|
63
|
+
# Returns the records
|
64
|
+
# @note No copy of the array is created. If you edit the arrays, this affects the HexData class. If you want a copy of the array, you can, for example, use the .clone method.
|
65
|
+
# @return [Array] The records returned as an array
|
58
66
|
def data
|
59
67
|
@sets
|
60
68
|
end
|
61
69
|
|
70
|
+
# Evaluate the (Intel) Hex data (interpretation) and make it available for reading.
|
71
|
+
# @return [NilClass] nil
|
62
72
|
def interpret
|
63
73
|
@ascii = nil.to_a
|
64
74
|
@sums = nil.to_a
|
@@ -95,48 +105,79 @@ class HexData
|
|
95
105
|
@ascii << str if type == "00"
|
96
106
|
@sums << sum
|
97
107
|
}
|
108
|
+
nil
|
98
109
|
end
|
99
110
|
|
111
|
+
# Resets the write address to the default value (16).
|
112
|
+
# @return [NilClass] nil
|
100
113
|
def reset_address!
|
101
114
|
@push_address = 16
|
115
|
+
nil
|
102
116
|
end
|
103
117
|
|
118
|
+
# Writes a string passed by the user to the data.
|
119
|
+
# @param str [String] The user data to be written as a record.
|
120
|
+
# @return [NilClass] nil
|
104
121
|
def push_user str
|
105
122
|
@sets << str
|
123
|
+
nil
|
106
124
|
end
|
107
125
|
|
126
|
+
# The string to be written.
|
127
|
+
# @param index [Integer] The index of the record to be deleted.
|
128
|
+
# @return [NilClass] nil
|
108
129
|
def delete_data! index
|
109
130
|
@sets.delete_at index
|
131
|
+
nil
|
110
132
|
end
|
111
133
|
|
134
|
+
# Resets the hex data. All saved hex data will be deleted. Then HexData is ready to write.
|
135
|
+
# @return [NilClass] nil
|
112
136
|
def clear!
|
113
137
|
@sets = nil.to_a
|
114
138
|
@sums = nil.to_a
|
115
139
|
@push_address = 16
|
140
|
+
nil
|
116
141
|
end
|
117
142
|
|
143
|
+
# Returns the number of records.
|
144
|
+
# @return [Integer] The number of records.
|
118
145
|
def max_index?
|
119
146
|
@sets.length
|
120
147
|
end
|
121
148
|
|
149
|
+
# Returns the index of the first record that detected an "End of File" markup.
|
150
|
+
# @return [Integer] The index of the first element where an "End of file"-mark was detected.
|
122
151
|
def data_end?
|
123
152
|
for i in 0...@sets.length
|
124
153
|
return i if @sets[i] == @enddef
|
125
154
|
end
|
126
155
|
end
|
127
156
|
|
157
|
+
# Reads the checksum of a record.
|
158
|
+
# @param index [Integer] The index of the record from which the checksum is to be read. Default: 0
|
159
|
+
# @return [Integer] The read checksum
|
128
160
|
def checksum? index=0
|
129
161
|
return @sums[index]
|
130
162
|
end
|
131
163
|
|
164
|
+
# Reads the result, the ASCII / ANSI text, the evaluation (interpretation).
|
165
|
+
# @param index [Integer] The index of the record to be read. If all is to be read out, nil can be transferred. Default: nil
|
166
|
+
# @return The result of all records, if no index was specified, otherwise only the result of the record from which the index was specified.
|
132
167
|
def ascii index=nil
|
133
168
|
return (index ? @ascii[index] : @ascii.join(""))
|
134
169
|
end
|
135
170
|
|
171
|
+
# Writes the "End of file" mark. This is appended to the end of the records.
|
172
|
+
# @return [NilClass] nil
|
136
173
|
def push_end
|
137
174
|
@sets << @enddef
|
175
|
+
nil
|
138
176
|
end
|
139
177
|
|
178
|
+
# Write a user-entered text to the records as (Intel) Hex.
|
179
|
+
# @param str [String] The text to be written to the records.
|
180
|
+
# @return [NilClass] nil
|
140
181
|
def push str
|
141
182
|
|
142
183
|
if @push_address > 65535
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Author: Marek K.
|
2
|
+
|
3
|
+
=begin
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(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 General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
|
19
|
+
der GNU General Public License, wie von der Free Software Foundation,
|
20
|
+
Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
|
21
|
+
veröffentlichten Version, weiter verteilen und/oder modifizieren.
|
22
|
+
|
23
|
+
Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch
|
24
|
+
OHNE JEDE GEWÄHR,; sogar ohne die implizite
|
25
|
+
Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
|
26
|
+
Siehe die GNU General Public License für weitere Einzelheiten.
|
27
|
+
|
28
|
+
Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
|
29
|
+
Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
|
30
|
+
|
31
|
+
=end
|
32
|
+
|
33
|
+
require "test/unit"
|
34
|
+
require "hexdata"
|
35
|
+
|
36
|
+
class HexDataTest < Test::Unit::TestCase
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@hd1 = HexData.new [":0C00000048656C6C6F20576F726C6421B7", ":00000001FF"]
|
40
|
+
@hd2 = HexData.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_basic1
|
44
|
+
@hd1.interpret
|
45
|
+
assert_equal @hd1.ascii, "Hello World!"
|
46
|
+
assert_equal @hd1.checksum?, 183
|
47
|
+
assert_equal @hd1.checksum?(1), 255
|
48
|
+
assert_equal @hd1.push_address, 16
|
49
|
+
assert_equal @hd1.enddef, ":00000001FF"
|
50
|
+
assert_equal @hd1.max_index?, 2
|
51
|
+
assert_equal @hd1.data_end?, 1
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_basic2
|
55
|
+
@hd2.interpret
|
56
|
+
assert_equal @hd2.ascii, ""
|
57
|
+
assert_equal @hd2.push_address, 16
|
58
|
+
assert_equal @hd2.enddef, ":00000001FF"
|
59
|
+
assert_equal @hd2.max_index?, 0
|
60
|
+
assert_equal @hd2.data_end?, 0...0
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_work1
|
64
|
+
@hd1.delete_data! 0
|
65
|
+
@hd1.interpret
|
66
|
+
|
67
|
+
assert_equal @hd1.max_index?, 1
|
68
|
+
assert_equal @hd1.data_end?, 0
|
69
|
+
|
70
|
+
assert_equal @hd1.ascii, ""
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_work2
|
74
|
+
@hd2.push "Test"
|
75
|
+
@hd2.push_user ":0C00000048656C6C6F20576F726C6421B7"
|
76
|
+
@hd2.push_end
|
77
|
+
@hd2.interpret
|
78
|
+
|
79
|
+
assert_equal @hd2.ascii, "TestHello World!"
|
80
|
+
assert_equal @hd2.checksum?, 76
|
81
|
+
assert_equal @hd2.checksum?(1), 183
|
82
|
+
assert_equal @hd2.checksum?(2), 255
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_edit1
|
86
|
+
@hd1.reset_address!
|
87
|
+
assert_equal @hd1.push_address, 16
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_edit2
|
91
|
+
@hd1.enddef = ":0C00000048656C6C6F20576F726C6421B7"
|
92
|
+
assert_equal @hd1.data_end?, 0
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_work3
|
96
|
+
@hd1.push_address = 123
|
97
|
+
@hd1.clear!
|
98
|
+
@hd1.interpret
|
99
|
+
|
100
|
+
assert_equal @hd1.max_index?, 0
|
101
|
+
assert_equal @hd1.data_end?, 0...0
|
102
|
+
assert_equal @hd1.push_address, 16
|
103
|
+
assert_equal @hd1.ascii, ""
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_work4
|
107
|
+
@hd2.enddef = ":0C00000148656C6C6F20576F726C6421B6"
|
108
|
+
@hd2.push "Test"
|
109
|
+
@hd2.push_end
|
110
|
+
@hd2.interpret
|
111
|
+
|
112
|
+
assert_equal @hd2.max_index?, 2
|
113
|
+
assert_equal @hd2.data_end?, 1
|
114
|
+
assert_equal @hd2.ascii, "Test"
|
115
|
+
assert_equal @hd2.checksum?, 76
|
116
|
+
assert_equal @hd2.checksum?(1), 182
|
117
|
+
assert_equal @hd2.push_address, 17
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexdata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek K.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
hexdata is available under the GNU GPL v3.0.
|
13
|
+
description: With hexdata you can create and read (Intel) hex data.hexdata also calculates
|
14
|
+
the checksum and calls an exception if it gets wrong.hexdata is available under
|
15
|
+
the GNU GPL v3.0.
|
17
16
|
email: m.k@mk16.de
|
18
17
|
executables: []
|
19
18
|
extensions: []
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
21
|
- lib/hexdata.rb
|
22
|
+
- test/hexdata_test.rb
|
23
23
|
homepage: http://test.mk16.de/projects/hexdata-gem
|
24
24
|
licenses:
|
25
25
|
- GPL-3.0
|