hardsploit_gui 2.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 +4 -4
- data/lib/Firmware/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
- data/lib/HardsploitAPI/HardsploitAPI.rb +5 -6
- data/lib/HardsploitAPI/HardsploitAPI_CONSTANT.rb +1 -1
- data/lib/HardsploitAPI/HardsploitAPI_ERROR.rb +38 -0
- data/lib/HardsploitAPI/HardsploitAPI_FIRMWARE.rb +3 -3
- data/lib/HardsploitAPI/HardsploitAPI_I2C.rb +145 -3
- data/lib/HardsploitAPI/HardsploitAPI_PROGRESS.rb +28 -0
- data/lib/HardsploitAPI/HardsploitAPI_SPI.rb +195 -5
- data/lib/HardsploitAPI/HardsploitAPI_USB_COMMUNICATION.rb +0 -1
- data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD.rb +1 -1
- data/lib/class/Generic_commands.rb +31 -36
- data/lib/class/HardsploitGUI.rb +5 -4
- data/lib/class/I2C/I2c_export.rb +6 -9
- data/lib/class/I2C/I2c_import.rb +15 -28
- data/lib/class/I2C/I2c_settings.rb +20 -8
- data/lib/class/Progress_bar.rb +31 -0
- data/lib/class/SPI/Spi_export.rb +6 -9
- data/lib/class/SPI/Spi_import.rb +33 -32
- data/lib/class/SPI/Spi_settings.rb +50 -4
- data/lib/db/hs.db +0 -0
- data/lib/gui/gui_chip_editor.rb +120 -127
- data/lib/gui/gui_i2c_settings.rb +34 -5
- data/lib/gui/gui_progress_bar.rb +84 -0
- data/lib/gui/gui_spi_settings.rb +175 -49
- data/lib/gui_designer/gui_chip_editor.ui +134 -141
- data/lib/gui_designer/gui_i2c_settings.ui +35 -4
- data/lib/gui_designer/gui_progress_bar.ui +83 -0
- data/lib/gui_designer/gui_spi_settings.ui +159 -34
- data/lib/hardsploit.rb +12 -3
- data/lib/logs/error.log +1 -0
- data/lib/startHardsploit.rb +10 -0
- metadata +8 -3
- data/lib/gui_designer/gui_processing.ui +0 -81
@@ -79,9 +79,9 @@ class Generic_commands < Qt::Widget
|
|
79
79
|
'0.50' => 150,
|
80
80
|
'0.29' => 255
|
81
81
|
}
|
82
|
-
@generic_command_gui.cbx_action.insertItem(3, 'Concatenate')
|
83
82
|
when 'I2C'
|
84
83
|
@chip_settings = I2C.find_by(i2c_chip: @chip.chip_id)
|
84
|
+
@generic_command_gui.cbx_action.insertItem(3, 'Concatenate')
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -175,39 +175,34 @@ class Generic_commands < Qt::Widget
|
|
175
175
|
bytesCmd1 = Byte.where(byte_cmd: Cmd.find_by(cmd_name: @generic_command_gui.tbl_cmd.selectedItems[0].text).cmd_id)
|
176
176
|
bytesCmd2 = Byte.where(byte_cmd: Cmd.find_by(cmd_name: @generic_command_gui.tbl_cmd.selectedItems[1].text).cmd_id)
|
177
177
|
if check_concatenation_size(bytesCmd1, bytesCmd2)
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
byte2.byte_iteration = b2.byte_iteration
|
206
|
-
byte2.byte_cmd = Cmd.ids.last
|
207
|
-
byte2.byte_type = 1
|
208
|
-
byte2.save
|
178
|
+
# Save cmd
|
179
|
+
cmd = Cmd.new
|
180
|
+
cmd.cmd_name = 'New concatenation'
|
181
|
+
cmd.cmd_desc = "Concatenation of #{@generic_command_gui.tbl_cmd.selectedItems[0].text} and #{@generic_command_gui.tbl_cmd.selectedItems[1].text} commands"
|
182
|
+
cmd.cmd_bus = @bus_id
|
183
|
+
cmd.cmd_chip = @chip.chip_id
|
184
|
+
cmd.save
|
185
|
+
# Save cmd bytes
|
186
|
+
bytesCmd1.each do |b1|
|
187
|
+
byte = Byte.new
|
188
|
+
byte.byte_index = b1.byte_index
|
189
|
+
byte.byte_value = b1.byte_value
|
190
|
+
byte.byte_description = b1.byte_description
|
191
|
+
byte.byte_iteration = b1.byte_iteration
|
192
|
+
byte.byte_cmd = Cmd.ids.last
|
193
|
+
byte.save
|
194
|
+
end
|
195
|
+
bytesCmd2.each do |b2|
|
196
|
+
byte2 = Byte.new
|
197
|
+
byte2.byte_index = Byte.last.byte_index + 1
|
198
|
+
byte2.byte_value = b2.byte_value
|
199
|
+
byte2.byte_description = b2.byte_description
|
200
|
+
byte2.byte_iteration = b2.byte_iteration
|
201
|
+
byte2.byte_cmd = Cmd.ids.last
|
202
|
+
byte2.save
|
203
|
+
end
|
204
|
+
feed_cmd_array
|
209
205
|
end
|
210
|
-
feed_cmd_array
|
211
206
|
rescue Exception => msg
|
212
207
|
logger = Logger.new($logFilePath)
|
213
208
|
logger.error msg
|
@@ -215,7 +210,7 @@ class Generic_commands < Qt::Widget
|
|
215
210
|
end
|
216
211
|
|
217
212
|
def check_concatenation_size(bytesCmd1, bytesCmd2)
|
218
|
-
checkSize =
|
213
|
+
checkSize = []
|
219
214
|
bytesCmd1.each do |b1|
|
220
215
|
checkSize.push(b1.byte_value)
|
221
216
|
end
|
@@ -228,9 +223,9 @@ class Generic_commands < Qt::Widget
|
|
228
223
|
lowByte = checkSize[i]
|
229
224
|
highByte = checkSize[i + 1]
|
230
225
|
commandType = checkSize[i + 2]
|
231
|
-
count
|
226
|
+
count += (lowByte.to_i(16) + (highByte.to_i(16)<<8))
|
232
227
|
if commandType.to_i(16) % 2 == 0 #WRITE
|
233
|
-
i
|
228
|
+
i += ((lowByte.to_i(16) + (highByte.to_i(16)<<8)) + 3)
|
234
229
|
else #READ
|
235
230
|
i = (i + 3)
|
236
231
|
end
|
data/lib/class/HardsploitGUI.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
require_relative '../HardsploitAPI/HardsploitAPI'
|
9
9
|
class HardsploitGUI < Qt::MainWindow
|
10
|
-
VERSION = "2.
|
10
|
+
VERSION = "2.1"
|
11
11
|
slots 'load_tree(int, int)'
|
12
12
|
slots 'load_chip_action(QTreeWidgetItem*, int)'
|
13
13
|
slots 'feed_chip_array()'
|
@@ -155,9 +155,10 @@ class HardsploitGUI < Qt::MainWindow
|
|
155
155
|
settings_lvl = Qt::TreeWidgetItem.new
|
156
156
|
settings_lvl.setText(0, "Settings")
|
157
157
|
parent_node.addChild(settings_lvl)
|
158
|
-
|
159
|
-
import_lvl.
|
160
|
-
|
158
|
+
# Not implemented yet
|
159
|
+
#import_lvl = Qt::TreeWidgetItem.new
|
160
|
+
#import_lvl.setText(0, "Import")
|
161
|
+
#parent_node.addChild(import_lvl)
|
161
162
|
export_lvl = Qt::TreeWidgetItem.new
|
162
163
|
export_lvl.setText(0, "Export")
|
163
164
|
parent_node.addChild(export_lvl)
|
data/lib/class/I2C/I2c_export.rb
CHANGED
@@ -54,15 +54,16 @@ class I2c_export < Qt::Widget
|
|
54
54
|
return 0 if control_export_settings('partial').zero?
|
55
55
|
end
|
56
56
|
Firmware.new(@api, 'I2C')
|
57
|
-
|
57
|
+
$pgb = Progress_bar.new("I²C: Exporting...")
|
58
|
+
$pgb.show
|
58
59
|
if sender.objectName == 'btn_full_export'
|
59
60
|
@api.i2c_Generic_Dump(@chip_settings.i2c_frequency, @chip_settings.i2c_address_w.to_i(16), 0, @chip_settings.i2c_total_size - 1, @chip_settings.i2c_total_size)
|
60
61
|
close_file
|
61
|
-
control_export_result('full', @chip_settings.i2c_total_size - 1
|
62
|
+
control_export_result('full', @chip_settings.i2c_total_size - 1)
|
62
63
|
else
|
63
64
|
@api.i2c_Generic_Dump(@chip_settings.i2c_frequency, @chip_settings.i2c_address_w.to_i(16), @i2c_export_gui.lie_start.text.to_i, @i2c_export_gui.lie_stop.text.to_i, @chip_settings.i2c_total_size)
|
64
65
|
close_file
|
65
|
-
control_export_result('partial', @i2c_export_gui.lie_stop.text.to_i
|
66
|
+
control_export_result('partial', @i2c_export_gui.lie_stop.text.to_i)
|
66
67
|
end
|
67
68
|
@i2c_export_gui.btn_export.setEnabled(false)
|
68
69
|
@i2c_export_gui.btn_full_export.setEnabled(false)
|
@@ -72,20 +73,16 @@ class I2c_export < Qt::Widget
|
|
72
73
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while full export operation. Consult the logs for more details').exec
|
73
74
|
end
|
74
75
|
|
75
|
-
def control_export_result(type, stop
|
76
|
-
time = Time.new - time
|
76
|
+
def control_export_result(type, stop)
|
77
77
|
if type == 'partial'
|
78
78
|
toCompare = ((stop - @i2c_export_gui.lie_start.text.to_i) + 1)
|
79
79
|
else
|
80
80
|
toCompare = @chip_settings.i2c_total_size
|
81
81
|
end
|
82
82
|
file_size = File.size(@filepath)
|
83
|
-
if toCompare
|
84
|
-
Qt::MessageBox.new(Qt::MessageBox::Information, 'Information', "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in #{time.round(4)} s)").exec
|
85
|
-
else
|
83
|
+
if toCompare != file_size
|
86
84
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Error', 'Dump error: Size does not match').exec
|
87
85
|
end
|
88
|
-
p "DUMP #{((file_size / time)).round(2)}Bytes/s (#{(file_size)}Bytes in #{time.round(4)} s)"
|
89
86
|
end
|
90
87
|
|
91
88
|
def control_export_settings(type)
|
data/lib/class/I2C/I2c_import.rb
CHANGED
@@ -20,13 +20,13 @@ class I2c_import < Qt::Widget
|
|
20
20
|
@i2c_import_gui.lbl_chip.setText(chip.chip_reference)
|
21
21
|
inputRestrict(@i2c_import_gui.lie_start, 0)
|
22
22
|
@api = api
|
23
|
+
@chip = chip
|
23
24
|
@chip_settings = I2C.find_by(i2c_chip: chip.chip_id)
|
24
25
|
end
|
25
26
|
|
26
27
|
def select_import_file
|
27
28
|
@filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
|
28
29
|
unless @filepath.nil?
|
29
|
-
$file = File.open("#{@filepath}", 'w')
|
30
30
|
@i2c_import_gui.btn_import.setEnabled(true)
|
31
31
|
end
|
32
32
|
rescue Exception => msg
|
@@ -35,22 +35,13 @@ class I2c_import < Qt::Widget
|
|
35
35
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
|
36
36
|
end
|
37
37
|
|
38
|
-
def close_file
|
39
|
-
unless $file.nil?
|
40
|
-
$file.close
|
41
|
-
end
|
42
|
-
rescue Exception => msg
|
43
|
-
logger = Logger.new($logFilePath)
|
44
|
-
logger.error msg
|
45
|
-
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
|
46
|
-
end
|
47
|
-
|
48
38
|
def import
|
49
39
|
return 0 if control_import_settings.zero?
|
50
40
|
start = @i2c_import_gui.lie_start.text.to_i
|
51
41
|
Firmware.new(@api, 'I2C')
|
52
|
-
|
53
|
-
|
42
|
+
$pgb = Progress_bar.new("I2C: Importing...")
|
43
|
+
$pgb.show
|
44
|
+
@api.i2c_Generic_Import(@chip_settings.i2c_frequency, @chip_settings.i2c_address_w.to_i(16), start, @chip_settings.i2c_page_size, @chip_settings.i2c_total_size, @filepath, @chip_settings.i2c_write_page_latency/1000.0)
|
54
45
|
rescue Exception => msg
|
55
46
|
logger = Logger.new($logFilePath)
|
56
47
|
logger.error msg
|
@@ -58,33 +49,29 @@ class I2c_import < Qt::Widget
|
|
58
49
|
end
|
59
50
|
|
60
51
|
def control_import_settings
|
61
|
-
|
52
|
+
@chip_settings = I2C.find_by(i2c_chip: @chip.chip_id)
|
62
53
|
if @chip_settings.nil?
|
63
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C
|
54
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', 'No settings saved for this chip').exec
|
64
55
|
return 0
|
65
56
|
end
|
66
57
|
if @chip_settings.i2c_total_size.nil?
|
67
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C
|
68
|
-
return 0
|
69
|
-
end
|
70
|
-
if @chip_settings.i2c_frequency.nil? || @chip_settings.i2c_address_w.nil?
|
71
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C settings', 'Write base address or frequency settings missing').exec
|
58
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', 'Total size setting missing').exec
|
72
59
|
return 0
|
73
60
|
end
|
74
|
-
if @chip_settings.
|
75
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', '
|
61
|
+
if @chip_settings.i2c_page_size.nil?
|
62
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', 'Page size setting missing').exec
|
76
63
|
return 0
|
77
64
|
end
|
78
|
-
if @
|
79
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing
|
65
|
+
if @chip_settings.i2c_write_page_latency.nil?
|
66
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', 'Write page latency setting missing').exec
|
80
67
|
return 0
|
81
68
|
end
|
82
|
-
if
|
83
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, '
|
69
|
+
if @chip_settings.i2c_frequency.nil? || @chip_settings.i2c_address_w.nil?
|
70
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', 'Write base address or frequency settings missing').exec
|
84
71
|
return 0
|
85
72
|
end
|
86
|
-
if
|
87
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, '
|
73
|
+
if @i2c_import_gui.lie_start.text.empty?
|
74
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing start address', 'Please fill the Start address field').exec
|
88
75
|
return 0
|
89
76
|
end
|
90
77
|
return 1
|
@@ -18,6 +18,8 @@ class I2c_settings < Qt::Widget
|
|
18
18
|
@i2c_settings_gui.setupUi(self)
|
19
19
|
@i2c_settings_gui.lbl_chip.setText(chip.chip_reference)
|
20
20
|
inputRestrict(@i2c_settings_gui.lie_total_size, 0)
|
21
|
+
inputRestrict(@i2c_settings_gui.lie_page_size, 0)
|
22
|
+
inputRestrict(@i2c_settings_gui.lie_write_page_latency, 0)
|
21
23
|
inputRestrict(@i2c_settings_gui.lie_address_r, 3)
|
22
24
|
inputRestrict(@i2c_settings_gui.lie_address_w, 3)
|
23
25
|
@i2c_settings_gui.tbl_bus_scan.resizeColumnsToContents
|
@@ -40,9 +42,11 @@ class I2c_settings < Qt::Widget
|
|
40
42
|
|
41
43
|
def feed_settings_form
|
42
44
|
unless @chip_settings.nil?
|
43
|
-
@i2c_settings_gui.cbx_frequency.setCurrentIndex(@i2c_settings_gui.cbx_frequency.findText(@chip_settings.i2c_frequency.to_s))
|
44
|
-
@i2c_settings_gui.lie_address_r.setText(@chip_settings.i2c_address_r)
|
45
45
|
@i2c_settings_gui.lie_address_w.setText(@chip_settings.i2c_address_w)
|
46
|
+
@i2c_settings_gui.lie_address_r.setText(@chip_settings.i2c_address_r)
|
47
|
+
@i2c_settings_gui.cbx_frequency.setCurrentIndex(@i2c_settings_gui.cbx_frequency.findText(@chip_settings.i2c_frequency.to_s))
|
48
|
+
@i2c_settings_gui.lie_write_page_latency.setText(@chip_settings.i2c_write_page_latency.to_s)
|
49
|
+
@i2c_settings_gui.lie_page_size.setText(@chip_settings.i2c_page_size.to_s)
|
46
50
|
@i2c_settings_gui.lie_total_size.setText(@chip_settings.i2c_total_size.to_s)
|
47
51
|
end
|
48
52
|
rescue Exception => msg
|
@@ -53,9 +57,11 @@ class I2c_settings < Qt::Widget
|
|
53
57
|
|
54
58
|
def create
|
55
59
|
@chip_settings = I2C.create(
|
56
|
-
i2c_frequency: @i2c_settings_gui.cbx_frequency.currentText,
|
57
|
-
i2c_address_r: @i2c_settings_gui.lie_address_r.text,
|
58
60
|
i2c_address_w: @i2c_settings_gui.lie_address_w.text,
|
61
|
+
i2c_address_r: @i2c_settings_gui.lie_address_r.text,
|
62
|
+
i2c_frequency: @i2c_settings_gui.cbx_frequency.currentText,
|
63
|
+
i2c_write_page_latency: @i2c_settings_gui.lie_write_page_latency.text,
|
64
|
+
i2c_page_size: @i2c_settings_gui.lie_page_size.text,
|
59
65
|
i2c_total_size: @i2c_settings_gui.lie_total_size.text,
|
60
66
|
i2c_chip: @chip.chip_id
|
61
67
|
)
|
@@ -67,14 +73,20 @@ class I2c_settings < Qt::Widget
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def update
|
70
|
-
if @chip_settings.
|
71
|
-
@chip_settings.update(
|
76
|
+
if @chip_settings.i2c_address_w != @i2c_settings_gui.lie_address_w.text
|
77
|
+
@chip_settings.update(i2c_address_w: @i2c_settings_gui.lie_address_w.text)
|
72
78
|
end
|
73
79
|
if @chip_settings.i2c_address_r != @i2c_settings_gui.lie_address_r.text
|
74
80
|
@chip_settings.update(i2c_address_r: @i2c_settings_gui.lie_address_r.text)
|
75
81
|
end
|
76
|
-
if @chip_settings.
|
77
|
-
@chip_settings.update(
|
82
|
+
if @chip_settings.i2c_frequency != @i2c_settings_gui.cbx_frequency.currentText.to_i
|
83
|
+
@chip_settings.update(i2c_frequency: @i2c_settings_gui.cbx_frequency.currentText.to_i)
|
84
|
+
end
|
85
|
+
if @chip_settings.i2c_write_page_latency != @i2c_settings_gui.lie_write_page_latency.text
|
86
|
+
@chip_settings.update(i2c_write_page_latency: @i2c_settings_gui.lie_write_page_latency.text)
|
87
|
+
end
|
88
|
+
if @chip_settings.i2c_page_size != @i2c_settings_gui.lie_page_size.text
|
89
|
+
@chip_settings.update(i2c_page_size: @i2c_settings_gui.lie_page_size.text)
|
78
90
|
end
|
79
91
|
if @chip_settings.i2c_total_size != @i2c_settings_gui.lie_total_size.text
|
80
92
|
@chip_settings.update(i2c_total_size: @i2c_settings_gui.lie_total_size.text)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#===================================================
|
2
|
+
# Hardsploit GUI - By Opale Security
|
3
|
+
# www.opale-security.com || www.hardsploit.io
|
4
|
+
# License: GNU General Public License v3
|
5
|
+
# License URI: http://www.gnu.org/licenses/gpl.txt
|
6
|
+
#===================================================
|
7
|
+
|
8
|
+
require_relative '../gui/gui_progress_bar'
|
9
|
+
class Progress_bar < Qt::Widget
|
10
|
+
|
11
|
+
def initialize(status)
|
12
|
+
super()
|
13
|
+
@pgb_ui = Ui_Progress_bar.new
|
14
|
+
centerWindow(self)
|
15
|
+
@pgb_ui.setupUi(self)
|
16
|
+
self.update_status(status)
|
17
|
+
self.display_time("Total duration:")
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_status(status)
|
21
|
+
@pgb_ui.lbl_status.setText(status)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_value(value)
|
25
|
+
@pgb_ui.pgb.setValue(value) if value <= 100 && value >= 0
|
26
|
+
end
|
27
|
+
|
28
|
+
def display_time(time)
|
29
|
+
@pgb_ui.lbl_time.setText(time)
|
30
|
+
end
|
31
|
+
end
|
data/lib/class/SPI/Spi_export.rb
CHANGED
@@ -70,15 +70,16 @@ class Spi_export < Qt::Widget
|
|
70
70
|
return 0 if control_export_settings('partial').zero?
|
71
71
|
end
|
72
72
|
Firmware.new(@api, 'SPI')
|
73
|
-
|
73
|
+
$pgb = Progress_bar.new("SPI: Exporting...")
|
74
|
+
$pgb.show
|
74
75
|
if sender.objectName == 'btn_full_export'
|
75
76
|
@api.spi_Generic_Dump(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], @chip_settings.spi_command_read, 0, @chip_settings.spi_total_size - 1, @chip_settings.spi_total_size.to_i)
|
76
77
|
close_file
|
77
|
-
control_export_result('full', @chip_settings.spi_total_size - 1
|
78
|
+
control_export_result('full', @chip_settings.spi_total_size - 1)
|
78
79
|
else
|
79
80
|
@api.spi_Generic_Dump(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], @chip_settings.spi_command_read, @spi_export_gui.lie_start.text.to_i, @spi_export_gui.lie_stop.text.to_i, @chip_settings.spi_total_size.to_i)
|
80
81
|
close_file
|
81
|
-
control_export_result('partial', @spi_export_gui.lie_stop.text.to_i
|
82
|
+
control_export_result('partial', @spi_export_gui.lie_stop.text.to_i)
|
82
83
|
end
|
83
84
|
@spi_export_gui.btn_export.setEnabled(false)
|
84
85
|
@spi_export_gui.btn_full_export.setEnabled(false)
|
@@ -88,20 +89,16 @@ class Spi_export < Qt::Widget
|
|
88
89
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while full export operation. Consult the logs for more details').exec
|
89
90
|
end
|
90
91
|
|
91
|
-
def control_export_result(type, stop
|
92
|
-
time = Time.new - time
|
92
|
+
def control_export_result(type, stop)
|
93
93
|
if type == 'partial'
|
94
94
|
toCompare = ((stop - @spi_export_gui.lie_start.text.to_i) + 1)
|
95
95
|
else
|
96
96
|
toCompare = @chip_settings.spi_total_size
|
97
97
|
end
|
98
98
|
file_size = File.size(@filepath)
|
99
|
-
if toCompare
|
100
|
-
Qt::MessageBox.new(Qt::MessageBox::Information, 'Information', "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in #{time.round(4)} s)").exec
|
101
|
-
else
|
99
|
+
if toCompare != file_size
|
102
100
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Error', 'Dump error: Size does not match').exec
|
103
101
|
end
|
104
|
-
p "DUMP #{((file_size / time)).round(2)}Bytes/s (#{(file_size)}Bytes in #{time.round(4)} s)"
|
105
102
|
end
|
106
103
|
|
107
104
|
def control_export_settings(type)
|
data/lib/class/SPI/Spi_import.rb
CHANGED
@@ -20,6 +20,7 @@ class Spi_import < Qt::Widget
|
|
20
20
|
@spi_import_gui.lbl_chip.setText(chip.chip_reference)
|
21
21
|
inputRestrict(@spi_import_gui.lie_start, 0)
|
22
22
|
@api = api
|
23
|
+
@chip = chip
|
23
24
|
@chip_settings = Spi.find_by(spi_chip: chip.chip_id)
|
24
25
|
@speeds = {
|
25
26
|
'25.00' => 3,
|
@@ -41,70 +42,70 @@ class Spi_import < Qt::Widget
|
|
41
42
|
|
42
43
|
def select_import_file
|
43
44
|
@filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
|
44
|
-
unless @filepath.nil?
|
45
|
-
$file = File.open("#{@filepath}", 'w')
|
46
|
-
@spi_import_gui.btn_import.setEnabled(true)
|
47
|
-
end
|
45
|
+
@spi_import_gui.btn_import.setEnabled(true) unless @filepath.nil?
|
48
46
|
rescue Exception => msg
|
49
47
|
logger = Logger.new($logFilePath)
|
50
48
|
logger.error msg
|
51
49
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
|
52
50
|
end
|
53
51
|
|
54
|
-
def close_file
|
55
|
-
unless $file.nil?
|
56
|
-
$file.close
|
57
|
-
end
|
58
|
-
rescue Exception => msg
|
59
|
-
logger = Logger.new($logFilePath)
|
60
|
-
logger.error msg
|
61
|
-
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
|
62
|
-
end
|
63
|
-
|
64
52
|
def import
|
65
53
|
return 0 if control_import_settings.zero?
|
66
54
|
start = @spi_import_gui.lie_start.text.to_i
|
67
55
|
Firmware.new(@api, 'SPI')
|
68
|
-
|
69
|
-
|
56
|
+
$pgb = Progress_bar.new("SPI: Importing...")
|
57
|
+
$pgb.show
|
58
|
+
if @chip_settings.spi_is_flash.zero?
|
59
|
+
flash = false
|
60
|
+
else
|
61
|
+
flash = true
|
62
|
+
end
|
63
|
+
@api.spi_Generic_Import(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], start, @chip_settings.spi_page_size, @chip_settings.spi_total_size, @filepath, @chip_settings.spi_command_write, @chip_settings.spi_write_page_latency/1000.0, @chip_settings.spi_command_write_enable, @chip_settings.spi_command_erase, @chip_settings.spi_erase_time, flash)
|
70
64
|
rescue Exception => msg
|
71
65
|
logger = Logger.new($logFilePath)
|
72
66
|
logger.error msg
|
73
67
|
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while partial import operation. Consult the logs for more details').exec
|
74
68
|
end
|
75
69
|
|
76
|
-
def control_import_result(type, stop, pathfile, time)
|
77
|
-
# TO COME
|
78
|
-
end
|
79
|
-
|
80
70
|
def control_import_settings
|
81
|
-
|
71
|
+
@chip_settings = Spi.find_by(spi_chip: @chip.chip_id)
|
82
72
|
if @chip_settings.nil?
|
83
73
|
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'No settings saved for this chip').exec
|
84
74
|
return 0
|
85
75
|
end
|
86
76
|
if @chip_settings.spi_total_size.nil? || @chip_settings.spi_page_size.nil?
|
87
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Total size or page size
|
77
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Total size or page size missing').exec
|
88
78
|
return 0
|
89
79
|
end
|
90
|
-
if @chip_settings.
|
91
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Read command or frequency
|
80
|
+
if @chip_settings.spi_command_read.nil? || @chip_settings.spi_frequency.nil?
|
81
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Read command or frequency missing').exec
|
92
82
|
return 0
|
93
83
|
end
|
94
|
-
if @chip_settings.
|
95
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI
|
84
|
+
if @chip_settings.spi_command_write.nil?
|
85
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Write command missing').exec
|
96
86
|
return 0
|
97
87
|
end
|
98
|
-
if @
|
99
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing
|
88
|
+
if @chip_settings.spi_write_page_latency.nil?
|
89
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI setting', 'SPI write page latency missing').exec
|
100
90
|
return 0
|
101
91
|
end
|
102
|
-
if
|
103
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, '
|
92
|
+
if @chip_settings.spi_is_flash.nil?
|
93
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI setting', 'SPI flash nature missing').exec
|
104
94
|
return 0
|
95
|
+
else
|
96
|
+
if @chip_settings.spi_is_flash == 1
|
97
|
+
if @chip_settings.spi_erase_time.nil? || @chip_settings.spi_command_erase.nil?
|
98
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI setting', 'SPI erase time or command missing').exec
|
99
|
+
return 0
|
100
|
+
end
|
101
|
+
end
|
105
102
|
end
|
106
|
-
if
|
107
|
-
Qt::MessageBox.new(Qt::MessageBox::Warning, '
|
103
|
+
if @chip_settings.spi_mode.nil?
|
104
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI setting', 'Mode missing').exec
|
105
|
+
return 0
|
106
|
+
end
|
107
|
+
if @spi_import_gui.lie_start.text.empty?
|
108
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing start address', 'Please fill the Start address field').exec
|
108
109
|
return 0
|
109
110
|
end
|
110
111
|
return 1
|