skullandbones / uTmax

uTmax Linux GUI program for the uTracer3 Thermionic Valve Tester
4 stars 3 forks source link

main: Add file and directory checks from mainwindow #27

Closed skullandbones closed 6 years ago

skullandbones commented 6 years ago

Bug #1: The mainwindow constructor defines the path to where the tube data file and the calibration file are located but fails to check the path exists.

Without the check, an attempt to write a new calibration file silently fails.

Therefore, add a check to ensure the path to the data files exists otherwise exit with an error message.

Bug #2: If no "data.csv" file exists then a file dialog window is opened to select the .csv file which contains the Thermionic Valve / tube data. However, if the "cancel" option is clicked on then a crash occurs.

Analysis found that the NULL QString test for the selected file was not working which allowed the code to think that a file had been selected when in fact the QString was set to NULL by the returning file dialog due to the cancel operation.

A crash occurred because ReadDataFile() thought that it had read in the data when in fact it had read no data.

Bug #3 Writing and reading the calibration file has insufficient checks. Therefore, add checks and debug to assist with diagnosis.

Move the 2 adc_scale lines inside ReadCalibration() because the adc_scale values are dependent on the calibration information.

Bug #4 The constructor of mainwindow was reading the data.csv which can fail. Unfortunately, a constructor cannot return an error code and it is unwise to exit the program from within a constructor. Therefore, move the reading of the data.csv file into the main function of main.cpp.

Also reading and writing the calibration file can fail so move that as well.

In addion move the serial port initialisation into main() to make it cleaner.

Bug #5 When main() returns using return(EXIT_FAILURE), ~MainWindow() runs and crashes because portInUse is NULL.

Therefore, add a NULL check for portInUse in ~MainWindow().

In general, add some debug, warning and critical error message output.

Signed-off-by: Dean Jenkins skullandbones99@gmail.com