Class: Spi_import
- Inherits:
-
Qt::Widget
- Object
- Qt::Widget
- Spi_import
- Defined in:
- lib/class/SPI/Spi_import.rb
Instance Method Summary collapse
- #control_import_settings ⇒ Object
- #import ⇒ Object
-
#initialize(chip) ⇒ Spi_import
constructor
A new instance of Spi_import.
- #select_import_file ⇒ Object
Constructor Details
#initialize(chip) ⇒ Spi_import
Returns a new instance of Spi_import.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/class/SPI/Spi_import.rb', line 15 def initialize(chip) super() @view = Ui_Generic_import.new centerWindow(self) @view.setupUi(self) @view.lbl_chip.setText(chip.reference) inputRestrict(@view.lie_start, 0) @chip = chip @speeds = { '25.00' => 3, '18.75' => 4, '15.00' => 5, '12.50' => 6, '10.71' => 7, '9.38' => 8, '7.50' => 10, '5.00' => 15, '3.95' => 19, '3.00' => 25, '2.03' => 37, '1.00' => 75, '0.50' => 150, '0.29' => 255 } end |
Instance Method Details
#control_import_settings ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/class/SPI/Spi_import.rb', line 81 def control_import_settings if @chip.spi_setting.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI settings', 'No settings saved for this chip' ).exec return 0 end if @chip.spi_setting.total_size.nil? || @chip.spi_setting.page_size.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI settings', 'Total size or page size missing' ).exec return 0 end if @chip.spi_setting.command_read.nil? || @chip.spi_setting.frequency.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI settings', 'Read command or frequency missing' ).exec return 0 end if @chip.spi_setting.command_write.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI settings', 'Write command missing' ).exec return 0 end if @chip.spi_setting.write_page_latency.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI setting', 'SPI write page latency missing' ).exec return 0 end if @chip.spi_setting.is_flash.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI setting', 'SPI flash nature missing' ).exec return 0 else if @chip.spi_setting.is_flash == 1 if @chip.spi_setting.erase_time.nil? || @chip.spi_setting.command_erase.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI setting', 'SPI erase time or command missing' ).exec return 0 end end end if @chip.spi_setting.mode.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing SPI setting', 'Mode missing' ).exec return 0 end if @view.lie_start.text.empty? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing start address', 'Please fill the Start address field' ).exec return 0 end return 1 end |
#import ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/class/SPI/Spi_import.rb', line 51 def import return 0 if control_import_settings.zero? spi = HardsploitAPI_SPI.new( speed: @speeds[@chip.spi_setting.frequency], mode: @chip.spi_setting.mode ) Firmware.new('SPI') $pgb = .new("SPI: Importing...") $pgb.show @chip.spi_setting.is_flash.zero? ? flash = false : flash = true spi.spi_Generic_Import( startAddress: @view.lie_start.text.to_i, pageSize: @chip.spi_setting.page_size, memorySize: @chip.spi_setting.total_size, dataFile: @filepath, writeSpiCommand: @chip.spi_setting.command_write, writePageLatency: @chip.spi_setting.write_page_latency / 1000.0, enableWriteSpiCommand: @chip.spi_setting.command_write_enable, clearSpiCommand: @chip.spi_setting.command_erase, clearChipTime: @chip.spi_setting.erase_time, isFLASH: flash ) rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND ErrorMsg.new.hardsploit_not_found rescue HardsploitAPI::ERROR::USB_ERROR ErrorMsg.new.usb_error rescue Exception => msg ErrorMsg.new.unknown(msg) end |
#select_import_file ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/class/SPI/Spi_import.rb', line 41 def select_import_file @filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('*.*')) unless @filepath.nil? @view.btn_import.setEnabled(true) @view.lbl_selected_file.setText("#{@filepath.split("/").last}") end rescue Exception => msg ErrorMsg.new.unknown(msg) end |