Librador Beta ready.

This commit is contained in:
Chris Esposito 2018-04-26 13:04:08 +10:00
parent 494b0f2a36
commit 83bc540fe6
66 changed files with 3077 additions and 37 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -238,3 +238,26 @@ void MainWindow::plot_from_librador(std::vector<double> *from_librador, double s
graph->setData(xaxis, yaxis);
ui->widget->replot();
}
void MainWindow::on_pushButton_15_clicked()
{
double sampleRate = 3000000;
if((current_channel == 1) || (current_channel == 2)){
std::vector<uint8_t> *from_librador_uint8 = (librador_get_digital_data(current_channel, 1, sampleRate, 0.1));
if(from_librador_uint8 != NULL){
std::vector<double> from_librador(from_librador_uint8->begin(), from_librador_uint8->end());
plot_from_librador(&from_librador, sampleRate, ui->widget->graph(0));
}
} else {
std::vector<uint8_t> *from_librador_ch1_uint8 = (librador_get_digital_data(1, 1, sampleRate, 0.1));
std::vector<uint8_t> *from_librador_ch2_uint8 = (librador_get_digital_data(2, 1, sampleRate, 0.1));
if(from_librador_ch1_uint8 != NULL){
std::vector<double> from_librador_ch1(from_librador_ch1_uint8->begin(), from_librador_ch1_uint8->end());
plot_from_librador(&from_librador_ch1, sampleRate, ui->widget->graph(0));
}
if(from_librador_ch2_uint8 != NULL){
std::vector<double> from_librador_ch2(from_librador_ch2_uint8->begin(), from_librador_ch2_uint8->end());
plot_from_librador(&from_librador_ch2, sampleRate, ui->widget->graph(1));
}
}
}

View File

@ -64,6 +64,8 @@ private slots:
void on_pushButton_14_clicked();
void on_pushButton_15_clicked();
private:
Ui::MainWindow *ui;
};

View File

@ -293,6 +293,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_15">
<property name="text">
<string>Get Digital (1s)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_14">
<property name="text">

View File

@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_MainWindow_t {
QByteArrayData data[25];
char stringdata0[538];
QByteArrayData data[26];
char stringdata0[563];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -55,7 +55,8 @@ QT_MOC_LITERAL(20, 415, 23), // "on_comboBox_2_activated"
QT_MOC_LITERAL(21, 439, 23), // "on_comboBox_3_activated"
QT_MOC_LITERAL(22, 463, 24), // "on_pushButton_12_clicked"
QT_MOC_LITERAL(23, 488, 24), // "on_pushButton_13_clicked"
QT_MOC_LITERAL(24, 513, 24) // "on_pushButton_14_clicked"
QT_MOC_LITERAL(24, 513, 24), // "on_pushButton_14_clicked"
QT_MOC_LITERAL(25, 538, 24) // "on_pushButton_15_clicked"
},
"MainWindow\0on_pushButton_clicked\0\0"
@ -73,7 +74,8 @@ QT_MOC_LITERAL(24, 513, 24) // "on_pushButton_14_clicked"
"on_comboBox_2_activated\0on_comboBox_3_activated\0"
"on_pushButton_12_clicked\0"
"on_pushButton_13_clicked\0"
"on_pushButton_14_clicked"
"on_pushButton_14_clicked\0"
"on_pushButton_15_clicked"
};
#undef QT_MOC_LITERAL
@ -83,7 +85,7 @@ static const uint qt_meta_data_MainWindow[] = {
7, // revision
0, // classname
0, 0, // classinfo
21, 14, // methods
22, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@ -91,27 +93,28 @@ static const uint qt_meta_data_MainWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 119, 2, 0x08 /* Private */,
3, 0, 120, 2, 0x08 /* Private */,
4, 0, 121, 2, 0x08 /* Private */,
5, 0, 122, 2, 0x08 /* Private */,
6, 0, 123, 2, 0x08 /* Private */,
7, 0, 124, 2, 0x08 /* Private */,
8, 0, 125, 2, 0x08 /* Private */,
9, 0, 126, 2, 0x08 /* Private */,
10, 0, 127, 2, 0x08 /* Private */,
11, 1, 128, 2, 0x08 /* Private */,
13, 1, 131, 2, 0x08 /* Private */,
14, 1, 134, 2, 0x08 /* Private */,
15, 1, 137, 2, 0x08 /* Private */,
16, 1, 140, 2, 0x08 /* Private */,
18, 0, 143, 2, 0x08 /* Private */,
19, 0, 144, 2, 0x08 /* Private */,
20, 1, 145, 2, 0x08 /* Private */,
21, 1, 148, 2, 0x08 /* Private */,
22, 0, 151, 2, 0x08 /* Private */,
23, 0, 152, 2, 0x08 /* Private */,
24, 0, 153, 2, 0x08 /* Private */,
1, 0, 124, 2, 0x08 /* Private */,
3, 0, 125, 2, 0x08 /* Private */,
4, 0, 126, 2, 0x08 /* Private */,
5, 0, 127, 2, 0x08 /* Private */,
6, 0, 128, 2, 0x08 /* Private */,
7, 0, 129, 2, 0x08 /* Private */,
8, 0, 130, 2, 0x08 /* Private */,
9, 0, 131, 2, 0x08 /* Private */,
10, 0, 132, 2, 0x08 /* Private */,
11, 1, 133, 2, 0x08 /* Private */,
13, 1, 136, 2, 0x08 /* Private */,
14, 1, 139, 2, 0x08 /* Private */,
15, 1, 142, 2, 0x08 /* Private */,
16, 1, 145, 2, 0x08 /* Private */,
18, 0, 148, 2, 0x08 /* Private */,
19, 0, 149, 2, 0x08 /* Private */,
20, 1, 150, 2, 0x08 /* Private */,
21, 1, 153, 2, 0x08 /* Private */,
22, 0, 156, 2, 0x08 /* Private */,
23, 0, 157, 2, 0x08 /* Private */,
24, 0, 158, 2, 0x08 /* Private */,
25, 0, 159, 2, 0x08 /* Private */,
// slots: parameters
QMetaType::Void,
@ -134,6 +137,7 @@ static const uint qt_meta_data_MainWindow[] = {
QMetaType::Void, QMetaType::Int, 17,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
0 // eod
@ -166,6 +170,7 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
case 18: _t->on_pushButton_12_clicked(); break;
case 19: _t->on_pushButton_13_clicked(); break;
case 20: _t->on_pushButton_14_clicked(); break;
case 21: _t->on_pushButton_15_clicked(); break;
default: ;
}
}
@ -196,13 +201,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 21)
if (_id < 22)
qt_static_metacall(this, _c, _id, _a);
_id -= 21;
_id -= 22;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 21)
if (_id < 22)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 21;
_id -= 22;
}
return _id;
}

View File

@ -65,6 +65,7 @@ public:
QComboBox *comboBox_3;
QVBoxLayout *verticalLayout_8;
QPushButton *pushButton_5;
QPushButton *pushButton_15;
QPushButton *pushButton_14;
QHBoxLayout *horizontalLayout_7;
QVBoxLayout *verticalLayout_3;
@ -270,6 +271,11 @@ public:
verticalLayout_8->addWidget(pushButton_5);
pushButton_15 = new QPushButton(centralWidget);
pushButton_15->setObjectName(QStringLiteral("pushButton_15"));
verticalLayout_8->addWidget(pushButton_15);
pushButton_14 = new QPushButton(centralWidget);
pushButton_14->setObjectName(QStringLiteral("pushButton_14"));
@ -442,6 +448,7 @@ public:
comboBox_3->setItemText(2, QApplication::translate("MainWindow", "Both", nullptr));
pushButton_5->setText(QApplication::translate("MainWindow", "Get Scope Data (1s)", nullptr));
pushButton_15->setText(QApplication::translate("MainWindow", "Get Digital (1s)", nullptr));
pushButton_14->setText(QApplication::translate("MainWindow", "Get Scope Data (SinceLast)", nullptr));
label_4->setText(QApplication::translate("MainWindow", "Frequency (Hz)", nullptr));
label_6->setText(QApplication::translate("MainWindow", "Amplitude (V)", nullptr));

View File

@ -80,6 +80,27 @@ std::vector<double> * librador_get_analog_data(int channel, double timeWindow_se
return internal_librador_object->usb_driver->getMany_double(channel, numToGet, interval_samples, delay_samples, filter_mode);
}
std::vector<uint8_t> * librador_get_digital_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds){
VECTOR_API_INIT_CHECK
VECTOR_USB_INIT_CHECK
double subsamples_per_second = internal_librador_object->usb_driver->get_samples_per_second() * 8;
if(subsamples_per_second == 0){
return NULL;
}
int interval_subsamples = round(subsamples_per_second / sample_rate_hz);
int delay_subsamples = round(delay_seconds * subsamples_per_second);
int numToGet = round(timeWindow_seconds * subsamples_per_second)/interval_subsamples;
printf("interval_subsamples = %d\ndelay_subsamples = %d\nnumToGet=%d\n", interval_subsamples, delay_subsamples, numToGet);
return internal_librador_object->usb_driver->getMany_singleBit(channel, numToGet, interval_subsamples, delay_subsamples);
}
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

View File

@ -39,6 +39,9 @@ uint8_t LIBRADORSHARED_EXPORT librador_get_device_firmware_variant();
std::vector<double> * LIBRADORSHARED_EXPORT librador_get_analog_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode);
std::vector<double> * LIBRADORSHARED_EXPORT librador_get_analog_data_sincelast(int channel, double timeWindow_max_seconds, double sample_rate_hz, double delay_seconds, int filter_mode);
std::vector<uint8_t> * librador_get_digital_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds);
//TODO: flashFirmware();
/*

View File

@ -7,7 +7,7 @@
#define LABRADOR_PID 0xba94
#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 CHECK_USB_INITIALISED if(!internal_librador_object->usb_driver->connected) return -421;
#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;

View File

@ -1,6 +1,7 @@
#include "o1buffer.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
//o1buffer is an object that has o(1) access times for its elements.
@ -15,6 +16,17 @@ o1buffer::~o1buffer(){
free(buffer);
}
int o1buffer::reset(bool hard){
mostRecentAddress = 0;
stream_index_at_last_call = 0;
if(hard){
for (int i=0; i<NUM_SAMPLES_PER_CHANNEL; i++){
buffer[i] = 0;
}
}
return 0;
}
void o1buffer::add(int value, int address){
//Ensure that the address is not too high.
@ -106,6 +118,31 @@ std::vector<double> *o1buffer::getMany_double(int numToGet, int interval_samples
return &convertedStream_double;
}
//Reads each int as 8 bools. Upper 3 bytes are ignored.
std::vector<uint8_t> *o1buffer::getMany_singleBit(int numToGet, int interval_subsamples, int delay_subsamples){
//Resize the vector
convertedStream_digital.resize(numToGet);
//Copy raw samples out.
int tempAddress;
int subsample_current_delay;
uint8_t mask;
uint8_t *data = convertedStream_digital.data();
int tempInt;
for(int i=0;i<numToGet;i++){
subsample_current_delay = delay_subsamples + (interval_subsamples * i);
tempAddress = mostRecentAddress - subsample_current_delay / 8;
mask = 0x01 << (subsample_current_delay % 8);
if(tempAddress < 0){
tempAddress += NUM_SAMPLES_PER_CHANNEL;
}
tempInt = get(tempAddress);
data[i] = (((uint8_t)tempInt) & mask) ? 1 : 0;
}
return &convertedStream_digital;
}
std::vector<double> *o1buffer::getSinceLast(int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode, double scope_gain, bool AC, bool twelve_bit_multimeter){
//Calculate what sample the feasible window begins at

View File

@ -2,6 +2,7 @@
#define O1BUFFER_H
#include <vector>
#include <stdint.h>
#define NUM_SAMPLES_PER_CHANNEL (375000 * 60) //1 minute of samples at 375ksps!
#define MULTIMETER_INVERT
@ -11,6 +12,7 @@ class o1buffer
public:
explicit o1buffer();
~o1buffer();
int reset(bool hard);
void add(int value, int address);
int addVector(int *firstElement, int numElements);
int addVector(char *firstElement, int numElements);
@ -21,6 +23,7 @@ public:
int stream_index_at_last_call = 0;
int distanceFromMostRecentAddress(int index);
std::vector<double> *getMany_double(int numToGet, int interval_samples, int delay_sample, int filter_mode, double scope_gain, bool AC, bool twelve_bit_multimeter);
std::vector<uint8_t> *getMany_singleBit(int numToGet, int interval_subsamples, int delay_subsamples);
std::vector<double> *getSinceLast(int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode, double scope_gain, bool AC, bool twelve_bit_multimeter);
double vcc = 3.3;
double frontendGain = (75.0/1075.0);
@ -28,6 +31,7 @@ public:
private:
int *buffer;
std::vector<double> convertedStream_double;
std::vector<uint8_t> convertedStream_digital;
void updateMostRecentAddress(int newAddress);
double get_filtered_sample(int index, int filter_type, int filter_size, double scope_gain, bool AC, bool twelve_bit_multimeter);
double sampleConvert(int sample, double scope_gain, bool AC, bool twelve_bit_multimeter);

View File

@ -318,14 +318,32 @@ buffer_read_write_mutex.lock();
case 7:
if(channel == 1) temp_to_return = internal_o1_buffer_375_CH1->getMany_double(numToGet, interval_samples, delay_sample, filter_mode, current_scope_gain, current_AC_setting, true);
break;
default:
buffer_read_write_mutex.unlock();
return NULL;
}
buffer_read_write_mutex.unlock();
return temp_to_return;
}
std::vector<uint8_t> * usbCallHandler::getMany_singleBit(int channel, int numToGet, int interval_subsamples, int delay_subsamples){
std::vector<uint8_t>* temp_to_return = NULL;
buffer_read_write_mutex.lock();
switch(deviceMode){
case 1:
if(channel == 1) temp_to_return = internal_o1_buffer_375_CH2->getMany_singleBit(numToGet, interval_subsamples, delay_subsamples);
break;
case 3:
if(channel == 1) temp_to_return = internal_o1_buffer_375_CH1->getMany_singleBit(numToGet, interval_subsamples, delay_subsamples);
break;
case 4:
if(channel == 1) temp_to_return = internal_o1_buffer_375_CH1->getMany_singleBit(numToGet, interval_subsamples, delay_subsamples);
else if (channel == 2) temp_to_return = internal_o1_buffer_375_CH2->getMany_singleBit(numToGet, interval_subsamples, delay_subsamples);
break;
}
buffer_read_write_mutex.unlock();
return temp_to_return;
}
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 = NULL;
buffer_read_write_mutex.lock();
@ -346,9 +364,6 @@ std::vector<double> *usbCallHandler::getMany_sincelast(int channel, int feasible
case 7:
if(channel == 1) temp_to_return = internal_o1_buffer_375_CH1->getSinceLast(feasible_window_begin, feasible_window_end, interval_samples, filter_mode, current_scope_gain, current_AC_setting, false);
break;
default:
buffer_read_write_mutex.unlock();
return NULL;
}
buffer_read_write_mutex.unlock();
return temp_to_return;
@ -370,6 +385,11 @@ int usbCallHandler::set_device_mode(int mode){
send_function_gen_settings(1);
send_function_gen_settings(2);
internal_o1_buffer_375_CH1->reset(false);
internal_o1_buffer_375_CH2->reset(false);
internal_o1_buffer_750->reset(false);
return 0;
}
@ -526,6 +546,10 @@ double usbCallHandler::get_samples_per_second(){
return (double)(375000.0);
case 2:
return (double)(375000.0);
case 3:
return (double)(375000.0);
case 4:
return (double)(375000.0);
case 6:
return (double)(750000.0);
case 7:

View File

@ -66,6 +66,7 @@ public:
int send_device_reset();
double get_samples_per_second();
std::vector<double> *getMany_double(int channel, int numToGet, int interval_samples, int delay_sample, int filter_mode);
std::vector<uint8_t> * getMany_singleBit(int channel, int numToGet, int interval_subsamples, int delay_subsamples);
std::vector<double> *getMany_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode);
bool connected;
//Control Commands

Binary file not shown.