Less crashes.

This commit is contained in:
Chris Esposito 2018-04-24 15:03:16 +10:00
parent 669a2a6f94
commit 494b0f2a36
5 changed files with 72 additions and 7 deletions

View File

@ -75,11 +75,11 @@ void MainWindow::on_pushButton_5_clicked()
{ {
double sampleRate = 375000; double sampleRate = 375000;
if((current_channel == 1) || (current_channel == 2)){ if((current_channel == 1) || (current_channel == 2)){
std::vector<double> *from_librador = (librador_get_analog_data(current_channel, 0.05, sampleRate, 0.1, 0)); std::vector<double> *from_librador = (librador_get_analog_data(current_channel, 1, sampleRate, 0.1, 0));
plot_from_librador(from_librador, sampleRate, ui->widget->graph(0)); plot_from_librador(from_librador, sampleRate, ui->widget->graph(0));
} else { } else {
std::vector<double> *from_librador_ch1 = (librador_get_analog_data(1, 0.05, sampleRate, 0.1, 0)); std::vector<double> *from_librador_ch1 = (librador_get_analog_data(1, 1, sampleRate, 0.1, 0));
std::vector<double> *from_librador_ch2 = (librador_get_analog_data(2, 0.05, sampleRate, 0.1, 0)); std::vector<double> *from_librador_ch2 = (librador_get_analog_data(2, 1, sampleRate, 0.1, 0));
plot_from_librador(from_librador_ch1, sampleRate, ui->widget->graph(0)); plot_from_librador(from_librador_ch1, sampleRate, ui->widget->graph(0));
plot_from_librador(from_librador_ch2, sampleRate, ui->widget->graph(1)); plot_from_librador(from_librador_ch2, sampleRate, ui->widget->graph(1));
} }
@ -198,11 +198,18 @@ void MainWindow::on_pushButton_14_clicked()
if((current_channel == 1) || (current_channel == 2)){ if((current_channel == 1) || (current_channel == 2)){
std::vector<double> *from_librador = (librador_get_analog_data_sincelast(current_channel, 10, sampleRate, 0.1, 0)); std::vector<double> *from_librador = (librador_get_analog_data_sincelast(current_channel, 10, sampleRate, 0.1, 0));
plot_from_librador(from_librador, sampleRate, ui->widget->graph(0)); plot_from_librador(from_librador, sampleRate, ui->widget->graph(0));
} else {
std::vector<double> *from_librador_ch1 = (librador_get_analog_data_sincelast(1, 10, sampleRate, 0.1, 0));
std::vector<double> *from_librador_ch2 = (librador_get_analog_data_sincelast(2, 10, sampleRate, 0.1, 0));
plot_from_librador(from_librador_ch1, sampleRate, ui->widget->graph(0));
plot_from_librador(from_librador_ch2, sampleRate, ui->widget->graph(1));
} }
} }
void MainWindow::plot_from_librador(std::vector<double> *from_librador, double sampleRate, QCPGraph *graph) void MainWindow::plot_from_librador(std::vector<double> *from_librador, double sampleRate, QCPGraph *graph)
{ {
qDebug() << "check1";
if(from_librador == NULL){ if(from_librador == NULL){
qDebug() << "from_librador NULL!"; qDebug() << "from_librador NULL!";
return; return;

View File

@ -738,7 +738,37 @@ librador.o: librador.cpp librador.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qversiontagging.h \ /home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qversiontagging.h \
librador_internal.h \ librador_internal.h \
usbcallhandler.h \ usbcallhandler.h \
../../../Desktop_Interface/build_linux/libusb/libusb.h ../../../Desktop_Interface/build_linux/libusb/libusb.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/QThread \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qthread.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobject.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobjectdefs.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qnamespace.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobjectdefs_impl.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstring.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qchar.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qbytearray.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qrefcount.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qarraydata.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringliteral.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringalgorithms.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringview.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringbuilder.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qlist.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qalgorithms.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qiterator.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qhashfunctions.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qpair.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qbytearraylist.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringlist.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qregexp.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringmatcher.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qcoreevent.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qscopedpointer.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qmetatype.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qvarlengtharray.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qcontainerfwd.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobject_impl.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o librador.o librador.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o librador.o librador.cpp
o1buffer.o: o1buffer.cpp o1buffer.h o1buffer.o: o1buffer.cpp o1buffer.h

View File

@ -58,10 +58,14 @@ int librador_setup_usb(){
int librador_avr_debug(){ int librador_avr_debug(){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->avrDebug(); return internal_librador_object->usb_driver->avrDebug();
} }
std::vector<double> * librador_get_analog_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){ std::vector<double> * librador_get_analog_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){
VECTOR_API_INIT_CHECK
VECTOR_USB_INIT_CHECK
double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second(); double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second();
if(samples_per_second == 0){ if(samples_per_second == 0){
@ -77,6 +81,10 @@ std::vector<double> * librador_get_analog_data(int channel, double timeWindow_se
} }
std::vector<double> * librador_get_analog_data_sincelast(int channel, double timeWindow_max_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){ std::vector<double> * librador_get_analog_data_sincelast(int channel, double timeWindow_max_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){
VECTOR_API_INIT_CHECK
VECTOR_USB_INIT_CHECK
double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second(); double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second();
if(samples_per_second == 0){ if(samples_per_second == 0){
@ -94,6 +102,7 @@ std::vector<double> * librador_get_analog_data_sincelast(int channel, double tim
int librador_reset_usb(){ int librador_reset_usb(){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
delete internal_librador_object->usb_driver; delete internal_librador_object->usb_driver;
internal_librador_object->usb_driver = new usbCallHandler(LABRADOR_VID, LABRADOR_PID); internal_librador_object->usb_driver = new usbCallHandler(LABRADOR_VID, LABRADOR_PID);
return 0; return 0;
@ -101,6 +110,7 @@ int librador_reset_usb(){
int librador_update_signal_gen_settings(int channel, unsigned char *sampleBuffer, int numSamples, double usecs_between_samples, double amplitude_v, double offset_v){ int librador_update_signal_gen_settings(int channel, unsigned char *sampleBuffer, int numSamples, double usecs_between_samples, double amplitude_v, double offset_v){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
int error = internal_librador_object->usb_driver->update_function_gen_settings(channel, sampleBuffer, numSamples, usecs_between_samples, amplitude_v, offset_v); int error = internal_librador_object->usb_driver->update_function_gen_settings(channel, sampleBuffer, numSamples, usecs_between_samples, amplitude_v, offset_v);
if(error){ if(error){
return error-1000; return error-1000;
@ -109,21 +119,25 @@ int librador_update_signal_gen_settings(int channel, unsigned char *sampleBuffer
int librador_set_power_supply_voltage(double voltage){ int librador_set_power_supply_voltage(double voltage){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->set_psu_voltage(voltage); return internal_librador_object->usb_driver->set_psu_voltage(voltage);
} }
int librador_set_device_mode(int mode){ int librador_set_device_mode(int mode){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->set_device_mode(mode); return internal_librador_object->usb_driver->set_device_mode(mode);
} }
int librador_set_oscilloscope_gain(double gain){ int librador_set_oscilloscope_gain(double gain){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->set_gain(gain); return internal_librador_object->usb_driver->set_gain(gain);
} }
int librador_set_digital_out(int channel, bool state_on){ int librador_set_digital_out(int channel, bool state_on){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
static uint8_t channelStates[4] = {0, 0, 0, 0}; static uint8_t channelStates[4] = {0, 0, 0, 0};
channel--; channel--;
if((channel < 0) || (channel > 3)){ if((channel < 0) || (channel > 3)){
@ -136,21 +150,25 @@ int librador_set_digital_out(int channel, bool state_on){
int librador_reset_device(){ int librador_reset_device(){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->reset_device(false); return internal_librador_object->usb_driver->reset_device(false);
} }
int librador_jump_to_bootloader(){ int librador_jump_to_bootloader(){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->reset_device(true); return internal_librador_object->usb_driver->reset_device(true);
} }
uint16_t librador_get_device_firmware_version(){ uint16_t librador_get_device_firmware_version(){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->get_firmware_version(); return internal_librador_object->usb_driver->get_firmware_version();
} }
uint8_t librador_get_device_firmware_variant(){ uint8_t librador_get_device_firmware_variant(){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->get_firmware_variant(); return internal_librador_object->usb_driver->get_firmware_variant();
} }
@ -186,6 +204,8 @@ unsigned char generator_triangle(double x)
int send_convenience_waveform(int channel, double frequency_Hz, double amplitude_v, double offset_v, unsigned char (*sample_generator)(double)) int send_convenience_waveform(int channel, double frequency_Hz, double amplitude_v, double offset_v, unsigned char (*sample_generator)(double))
{ {
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
if((amplitude_v + offset_v) > 9.6){ if((amplitude_v + offset_v) > 9.6){
return -1; return -1;
//Voltage range too high //Voltage range too high
@ -224,21 +244,25 @@ int send_convenience_waveform(int channel, double frequency_Hz, double amplitude
int librador_send_sin_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){ int librador_send_sin_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_sin); return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_sin);
} }
int librador_send_square_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){ int librador_send_square_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_square); return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_square);
} }
int librador_send_triangle_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){ int librador_send_triangle_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_triangle); return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_triangle);
} }
int librador_send_sawtooth_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){ int librador_send_sawtooth_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_sawtooth); return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_sawtooth);
} }

View File

@ -7,6 +7,11 @@
#define LABRADOR_PID 0xba94 #define LABRADOR_PID 0xba94
#define CHECK_API_INITIALISED if(internal_librador_object == NULL) return -420; #define CHECK_API_INITIALISED if(internal_librador_object == NULL) return -420;
#define CHECK_USB_INITIALISED if(!internal_librador_object->usb_driver->connected) return -420420;
#define VECTOR_API_INIT_CHECK if(internal_librador_object == NULL) return NULL;
#define VECTOR_USB_INIT_CHECK if(!internal_librador_object->usb_driver->connected) return NULL;
class usbCallHandler; class usbCallHandler;

View File

@ -298,7 +298,7 @@ int usbCallHandler::avrDebug(void){
} }
std::vector<double>* usbCallHandler::getMany_double(int channel, int numToGet, int interval_samples, int delay_sample, int filter_mode){ std::vector<double>* usbCallHandler::getMany_double(int channel, int numToGet, int interval_samples, int delay_sample, int filter_mode){
std::vector<double>* temp_to_return; std::vector<double>* temp_to_return = NULL;
buffer_read_write_mutex.lock(); buffer_read_write_mutex.lock();
switch(deviceMode){ switch(deviceMode){
@ -327,8 +327,7 @@ buffer_read_write_mutex.lock();
} }
std::vector<double> *usbCallHandler::getMany_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode){ std::vector<double> *usbCallHandler::getMany_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode){
std::vector<double>* temp_to_return; std::vector<double>* temp_to_return = NULL;
buffer_read_write_mutex.lock(); buffer_read_write_mutex.lock();
switch(deviceMode){ switch(deviceMode){
case 0: case 0: