Revert "Simplify the waveform reading code (#194)"

This reverts commit 591940b225.

Revert "Whitespace cleanup (#192)"

This reverts commit 1b45b0d112.
This commit is contained in:
Chris Esposito 2021-11-16 14:28:55 +11:00
parent 90bc17a2f0
commit 8cc740c6e1
45 changed files with 1309 additions and 1200 deletions

View File

@ -295,3 +295,4 @@ int androidUsbDriver::flashFirmware(void){
mainActivity.callMethod<void>("closeDevice"); mainActivity.callMethod<void>("closeDevice");
return 0; return 0;
} }

0
Desktop_Interface/bin/firmware/labrafirm_0005_02.hex Normal file → Executable file
View File

View File

@ -81,3 +81,4 @@ void daqForm::updateValues(){
void daqForm::trigger_saveButtonPressed(){ void daqForm::trigger_saveButtonPressed(){
saveButtonPressed(); saveButtonPressed();
} }

View File

@ -25,3 +25,4 @@ unsigned char expected_variant;
#ifndef PLATFORM_WINDOWS #ifndef PLATFORM_WINDOWS
struct timeval tv; struct timeval tv;
#endif #endif

View File

@ -47,3 +47,4 @@ extern unsigned char expected_variant;
#define NUM_BYTES_STORED_PER_DAQ_SAMPLE 9 #define NUM_BYTES_STORED_PER_DAQ_SAMPLE 9
#endif // DESKTOP_SETTINGS_H #endif // DESKTOP_SETTINGS_H

View File

@ -9,40 +9,95 @@ ChannelData const& SingleChannelController::getData() const {
void SingleChannelController::waveformName(QString newName) void SingleChannelController::waveformName(QString newName)
{ {
qDebug() << "newName = " << newName;
newName.append(".tlw");
int length;
#ifdef PLATFORM_ANDROID #ifdef PLATFORM_ANDROID
QString path("assets:/waveforms/"); QString waveformFilePath("assets:/waveforms/");
QFile file(path.append(newName).append(".tlw")); waveformFilePath.append(newName);
#else
QString path = QCoreApplication::applicationDirPath();
QFile file(path.append("/waveforms/").append(newName).append(".tlw"));
#endif
qDebug() << "opening" << file.fileName(); QFile fptr(waveformFilePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) bool success = fptr.open(QIODevice::ReadOnly);
qFatal("could not open %s", qUtf8Printable(file.fileName()));
int length = file.readLine().toInt(); QByteArray line;
m_data.divisibility = file.readLine().toInt(); char lengthString[16];
QByteArray data = file.readLine().trimmed(); char divisibilityString[16];
file.close();
line = fptr.readLine();
strcpy(lengthString, line.data());
sscanf(lengthString, "%d", &length);
qDebug() << "lengthString" << lengthString;
line = fptr.readLine();
strcpy(divisibilityString, line.data());
sscanf(divisibilityString, "%d", &m_data.divisibility);
qDebug() << "divisibilityString" << divisibilityString;
qDebug() << "Length = " << length; qDebug() << "Length = " << length;
qDebug() << "Divisibility = " << m_data.divisibility; qDebug() << "Divisibility = " << m_data.divisibility;
// Length is redundant, could be derived from the sample list. QByteArray remainingData = fptr.readAll();
if (length != data.count('\t') + 1) char *dataString = remainingData.data();
qFatal("%s: sample count mismatch", qUtf8Printable(file.fileName()));
m_data.samples.resize(length); m_data.samples.resize(length);
data.replace('\t', '\0'); int dummy;
const char *dataString = data.constData(); char *dataStringCurrent = dataString;
QByteArray dataElem; for (int i = 0; i < length; i++)
for (auto &sample : m_data.samples) { {
dataElem.setRawData(dataString, strlen(dataString)); sscanf(dataStringCurrent, "%d", &dummy);
sample = static_cast<uint8_t>(dataElem.toInt()); dataStringCurrent += strcspn(dataStringCurrent, "\t") + 1;
dataString += dataElem.size() + 1; m_data.samples[i] = static_cast<uint8_t>(dummy);
} }
#else
QByteArray filePath = QCoreApplication::applicationDirPath()
.append("/waveforms/").append(newName).toLocal8Bit();
qDebug() << "opening" << filePath;
FILE *fptr = fopen(filePath.constData(), "r");
if (fptr == NULL)
qFatal("%s could not be opened!", filePath.constData());
char lengthString[16];
fgets(lengthString, 5, fptr);
sscanf(lengthString, "%d", &length);
char divisibilityString[16];
//Bit of bullshit to deal with CRLF line endings on Mac.
do
{
fgets(divisibilityString, 5, fptr);
}
while ((divisibilityString[0] == '\r') || (divisibilityString[0] == '\n'));
sscanf(divisibilityString, "%d", &m_data.divisibility);
qDebug() << "Length = " << length;
qDebug() << "Divisibility = " << m_data.divisibility;
m_data.samples.resize(length);
char *dataString = (char *) malloc(length*5+1);
fgets(dataString, length*5+1, fptr);
int dummy;
char *dataStringCurrent = dataString;
for (int i = 0; i < length; i++)
{
sscanf(dataStringCurrent, "%d", &dummy);
dataStringCurrent += strcspn(dataStringCurrent, "\t") + 1;
m_data.samples[i] = static_cast<uint8_t>(dummy);
}
free(dataString);
fclose(fptr);
#endif
double newMaxFreq = DAC_SPS / (length >> (m_data.divisibility - 1)); double newMaxFreq = DAC_SPS / (length >> (m_data.divisibility - 1));
double newMinFreq = double(CLOCK_FREQ) / 1024.0 / 65535.0 / static_cast<double>(length); double newMinFreq = double(CLOCK_FREQ) / 1024.0 / 65535.0 / static_cast<double>(length);
@ -174,3 +229,4 @@ void DualChannelController::offsetUpdate_CH2(double newOffset)
} }
} }

View File

@ -230,6 +230,7 @@ void genericUsbDriver::sendFunctionGenData(functionGen::ChannelID channelID)
if(deviceMode == 5) if(deviceMode == 5)
qDebug("DEVICE IS IN MODE 5"); qDebug("DEVICE IS IN MODE 5");
if (channelID == functionGen::ChannelID::CH2) if (channelID == functionGen::ChannelID::CH2)
usbSendControl(0x40, 0xa1, timerPeriod, clkSetting, channelData.samples.size(), channelData.samples.data()); usbSendControl(0x40, 0xa1, timerPeriod, clkSetting, channelData.samples.size(), channelData.samples.data());
else else
@ -513,3 +514,4 @@ void genericUsbDriver::checkConnection(){
void genericUsbDriver::bootloaderJump(){ void genericUsbDriver::bootloaderJump(){
usbSendControl(0x40, 0xa7, 1, 0, 0, NULL); usbSendControl(0x40, 0xa7, 1, 0, 0, NULL);
} }

View File

@ -79,3 +79,4 @@ void isoBuffer_file::clearBuffer()
back = 0; back = 0;
} }

View File

@ -98,3 +98,5 @@ uint32_t isoBufferBuffer::capacity() const
{ {
return m_capacity; return m_capacity;
} }

View File

@ -1658,3 +1658,4 @@ void isoDriver::setMaxSpectrum(int maxSpectrum)
{ {
m_spectrumMaxX = static_cast<double>(maxSpectrum); m_spectrumMaxX = static_cast<double>(maxSpectrum);
} }

View File

@ -2473,6 +2473,7 @@ void MainWindow::cursorGroupEnabled(bool enabled)
ui->makeCursorsNicer->setTurnedOn(false); ui->makeCursorsNicer->setTurnedOn(false);
ui->cursorGroup->setEnabled(false); ui->cursorGroup->setEnabled(false);
} }
} }
void MainWindow::on_actionHide_Widget_Oscilloscope_triggered(bool checked) void MainWindow::on_actionHide_Widget_Oscilloscope_triggered(bool checked)

View File

@ -90,3 +90,4 @@ void scopeRangeEnterDialog::delayChanged(double val)
{ {
ui->delayBox->setValue(val); ui->delayBox->setValue(val);
} }

View File

@ -257,3 +257,4 @@ UartParity uartStyleDecoder::parityOf(uint32_t bitField) const
return result ? UartParity::Odd : UartParity::Even; return result ? UartParity::Odd : UartParity::Even;
} }

View File

@ -254,3 +254,4 @@ void bufferControl::poke(void){
updateMode(); updateMode();
updateBuffer(0,0); updateBuffer(0,0);
} }

View File

@ -5,22 +5,59 @@ espoComboBox::espoComboBox(QWidget *parent) : QComboBox(parent)
} }
void espoComboBox::readWaveformList(void) void espoComboBox::readWaveformList(void)
{ {
//This code gets the name of the current directory, regardless of platform.
//This is so the interface knows where to find the waveform data
//QDir *dir = new QDir();
//qDebug() << dir->currentPath();
#ifdef PLATFORM_ANDROID #ifdef PLATFORM_ANDROID
QFile file("assets:/waveforms/_list.wfl"); QFile qt_list("assets:/waveforms/_list.wfl");
#else bool success = qt_list.open(QIODevice::ReadOnly | QIODevice::Text);
QString path = QCoreApplication::applicationDirPath(); if(!success){
QFile file(path.append("/waveforms/_list.wfl")); qFatal("Could not load _list.wfl");
#endif }
qDebug() << "opening" << file.fileName(); char nameBuffer[255];
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) QStringList *newNames = new QStringList();
qFatal("could not open %s", qUtf8Printable(file.fileName()));
while (!qt_list.atEnd()) {
QStringList newNames; QByteArray line = qt_list.readLine();
while (!file.atEnd()) strcpy(nameBuffer, line.data());
newNames.append(file.readLine().trimmed()); strtok(nameBuffer, "\n\r");
this->addItems(newNames); newNames->append(nameBuffer);
file.close(); qDebug() << nameBuffer;
}
this->addItems(*(newNames));
delete newNames;
qt_list.close();
#else
QString dirString = QCoreApplication::applicationDirPath();
dirString.append("/waveforms/_list.wfl");
QByteArray array = dirString.toLocal8Bit();
char* buffer = array.data();
//qDebug() << buffer;
qDebug() << "Attempting to open" << dirString;
FILE *listPtr = fopen(buffer, "r");
QStringList *newNames = new QStringList();
char nameBuffer[255];
if(listPtr == NULL){
qFatal("Could not load _list.wfl");
}
while (fgets(nameBuffer, sizeof(nameBuffer), listPtr) != NULL){
qDebug() << "nameBuffer = " << nameBuffer;
strtok(nameBuffer, "\n\r");
newNames->append(nameBuffer);
}
this->addItems(*(newNames));
delete newNames;
fclose(listPtr);
#endif
qDebug() << "List loaded!!";
} }

View File

@ -103,3 +103,4 @@ void espoSlider::poke(void){
//qDebug() << "Refreshing to voltage" << ((double) (this->value())) / 20; //qDebug() << "Refreshing to voltage" << ((double) (this->value())) / 20;
voltageChanged(((double) (this->value())) / 20); voltageChanged(((double) (this->value())) / 20);
} }

View File

@ -57,3 +57,4 @@ void swipeyStack::cycleStack(int delta){
void swipeyStack::enableWrapping(bool enabled){ void swipeyStack::enableWrapping(bool enabled){
wrapEnabled = enabled; wrapEnabled = enabled;
} }