Class: Parallel_import

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/class/PARALLEL/Parallel_import.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, chip) ⇒ Parallel_import

Returns a new instance of Parallel_import.

[View source]

15
16
17
18
19
20
21
22
23
24
# File 'lib/class/PARALLEL/Parallel_import.rb', line 15

def initialize(api, chip)
  super()
  @parallel_import_gui = Ui_Generic_import.new
  centerWindow(self)
  @parallel_import_gui.setupUi(self)
  @parallel_import_gui.lbl_chip.setText(chip.chip_reference)
  inputRestrict(@parallel_import_gui.lie_start, 0)
  @api = api
  @chip_settings = Parallel.find_by(parallel_chip: chip.chip_id)
end

Instance Method Details

#close_fileObject

[View source]

38
39
40
41
42
43
44
45
46
# File 'lib/class/PARALLEL/Parallel_import.rb', line 38

def close_file
  unless $file.nil?
    $file.close
  end
rescue Exception => msg
    logger = Logger.new($logFilePath)
    logger.error msg
    Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
end

#control_import_settingsObject

[View source]

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/class/PARALLEL/Parallel_import.rb', line 60

def control_import_settings
  file_size = File.size("#{@filepath}")
  if @chip_settings.nil?
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'No settings saved for this chip').exec
    return 0
  end
  if @chip_settings.parallel_total_size.nil? || @chip_settings.parallel_word_size.nil?
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'Total size or word size settings missing').exec
    return 0
  end
  if @chip_settings.parallel_page_size.nil? || @chip_settings.parallel_write_latency.nil?
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'Page size or write latency settings missing').exec
    return 0
  end
  if @parallel_import_gui.lie_start.text.empty?
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing start address', 'Please fill the start address field').exec
    return 0
  end
  if file_size > @chip_settings.parallel_total_size
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'The file size is superior to the chip capacity').exec
    return 0
  end
  if file_size > (@chip_settings.parallel_total_size - @parallel_import_gui.lie_start)
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'Starting at this address, the file size is superior to the chip capacity').exec
    return 0
  end
  return 1
end

#importObject

[View source]

48
49
50
51
52
53
54
55
56
57
58
# File 'lib/class/PARALLEL/Parallel_import.rb', line 48

def import
  return 0 if control_import_settings.zero?
  start = @parallel_import_gui.lie_start.text.to_i
  Firmware.new(@api, 'PARALLEL')
  time = Time.new
  # API COMMAND GOES HERE
rescue Exception => msg
    logger = Logger.new($logFilePath)
    logger.error msg
    Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while partial import operation. Consult the logs for more details').exec
end

#select_import_fileObject

[View source]

26
27
28
29
30
31
32
33
34
35
36
# File 'lib/class/PARALLEL/Parallel_import.rb', line 26

def select_import_file
  @filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
  unless @filepath.nil?
    $file = File.open("#{@filepath}", 'w')
    @parallel_import_gui.btn_import.setEnabled(true)
  end
rescue Exception => msg
    logger = Logger.new($logFilePath)
    logger.error msg
    Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
end