Class: I2c_import
- Inherits:
-
Qt::Widget
- Object
- Qt::Widget
- I2c_import
- Defined in:
- lib/class/I2C/I2c_import.rb
Instance Method Summary collapse
- #control_import_settings ⇒ Object
- #import ⇒ Object
-
#initialize(chip) ⇒ I2c_import
constructor
A new instance of I2c_import.
- #select_import_file ⇒ Object
Constructor Details
#initialize(chip) ⇒ I2c_import
Returns a new instance of I2c_import.
14 15 16 17 18 19 20 21 22 |
# File 'lib/class/I2C/I2c_import.rb', line 14 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 end |
Instance Method Details
#control_import_settings ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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 |
# File 'lib/class/I2C/I2c_import.rb', line 64 def control_import_settings if @chip.i2c_setting.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing I2C setting', 'No settings saved for this chip' ).exec return 0 end if @chip.i2c_setting.total_size.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing I2C setting', 'Total size setting missing' ).exec return 0 end if @chip.i2c_setting.page_size.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing I2C setting', 'Page size setting missing' ).exec return 0 end if @chip.i2c_setting.write_page_latency.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing I2C setting', 'Write page latency setting missing' ).exec return 0 end if @chip.i2c_setting.frequency.nil? || @chip.i2c_setting.address_w.nil? Qt::MessageBox.new( Qt::MessageBox::Warning, 'Missing I2C setting', 'Write base address or frequency settings 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 rescue Exception => msg ErrorMsg.new.unknown(msg) end |
#import ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/class/I2C/I2c_import.rb', line 34 def import return 0 if control_import_settings.zero? Firmware.new('I2C') $pgb = .new("I²C: Exporting...") $pgb.show if [40, 100, 400, 1000].include?(@chip.i2c_setting.frequency) speed = 0 if @chip.i2c_setting.frequency == 100 speed = 1 if @chip.i2c_setting.frequency == 400 speed = 2 if @chip.i2c_setting.frequency == 1000 speed = 3 if @chip.i2c_setting.frequency == 40 i2c = HardsploitAPI_I2C.new(speed: speed) i2c.i2c_Generic_Import( i2cBaseAddress: @chip.i2c_setting.address_w.to_i(16), startAddress: @view.lie_start.text.to_i, pageSize: @chip.i2c_setting.page_size, memorySize: @chip.i2c_setting.total_size, dataFile: @filepath, writePageLatency: @chip.i2c_setting.write_page_latency / 1000.0 ) end rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND ErrorMsg.new.hardsploit_not_found rescue HardsploitAPI::ERROR::USB_ERROR ErrorMsg.new.usb_error rescue HardsploitAPI::ERROR::I2CWrongSpeed ErrorMsg.new.i2c_error rescue Exception => msg ErrorMsg.new.unknown(msg) end |
#select_import_file ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/class/I2C/I2c_import.rb', line 24 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 |