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");
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(){
saveButtonPressed();
}

View File

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

View File

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

View File

@ -9,40 +9,95 @@ ChannelData const& SingleChannelController::getData() const {
void SingleChannelController::waveformName(QString newName)
{
qDebug() << "newName = " << newName;
newName.append(".tlw");
int length;
#ifdef PLATFORM_ANDROID
QString path("assets:/waveforms/");
QFile file(path.append(newName).append(".tlw"));
#else
QString path = QCoreApplication::applicationDirPath();
QFile file(path.append("/waveforms/").append(newName).append(".tlw"));
#endif
QString waveformFilePath("assets:/waveforms/");
waveformFilePath.append(newName);
qDebug() << "opening" << file.fileName();
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
qFatal("could not open %s", qUtf8Printable(file.fileName()));
QFile fptr(waveformFilePath);
bool success = fptr.open(QIODevice::ReadOnly);
int length = file.readLine().toInt();
m_data.divisibility = file.readLine().toInt();
QByteArray data = file.readLine().trimmed();
file.close();
QByteArray line;
char lengthString[16];
char divisibilityString[16];
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() << "Divisibility = " << m_data.divisibility;
// Length is redundant, could be derived from the sample list.
if (length != data.count('\t') + 1)
qFatal("%s: sample count mismatch", qUtf8Printable(file.fileName()));
QByteArray remainingData = fptr.readAll();
char *dataString = remainingData.data();
m_data.samples.resize(length);
data.replace('\t', '\0');
const char *dataString = data.constData();
QByteArray dataElem;
for (auto &sample : m_data.samples) {
dataElem.setRawData(dataString, strlen(dataString));
sample = static_cast<uint8_t>(dataElem.toInt());
dataString += dataElem.size() + 1;
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);
}
#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 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)
qDebug("DEVICE IS IN MODE 5");
if (channelID == functionGen::ChannelID::CH2)
usbSendControl(0x40, 0xa1, timerPeriod, clkSetting, channelData.samples.size(), channelData.samples.data());
else
@ -513,3 +514,4 @@ void genericUsbDriver::checkConnection(){
void genericUsbDriver::bootloaderJump(){
usbSendControl(0x40, 0xa7, 1, 0, 0, NULL);
}

View File

@ -118,7 +118,7 @@ public:
// UARTS decoding
uartStyleDecoder* m_decoder = NULL;
bool m_isDecoding = true;
// DFT
//DFT
AsyncDFT async_dft;
private:
// File I/O

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,22 +5,59 @@ espoComboBox::espoComboBox(QWidget *parent) : QComboBox(parent)
}
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
QFile file("assets:/waveforms/_list.wfl");
QFile qt_list("assets:/waveforms/_list.wfl");
bool success = qt_list.open(QIODevice::ReadOnly | QIODevice::Text);
if(!success){
qFatal("Could not load _list.wfl");
}
char nameBuffer[255];
QStringList *newNames = new QStringList();
while (!qt_list.atEnd()) {
QByteArray line = qt_list.readLine();
strcpy(nameBuffer, line.data());
strtok(nameBuffer, "\n\r");
newNames->append(nameBuffer);
qDebug() << nameBuffer;
}
this->addItems(*(newNames));
delete newNames;
qt_list.close();
#else
QString path = QCoreApplication::applicationDirPath();
QFile file(path.append("/waveforms/_list.wfl"));
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() << "opening" << file.fileName();
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
qFatal("could not open %s", qUtf8Printable(file.fileName()));
QStringList newNames;
while (!file.atEnd())
newNames.append(file.readLine().trimmed());
this->addItems(newNames);
file.close();
qDebug() << "List loaded!!";
}

View File

@ -103,3 +103,4 @@ void espoSlider::poke(void){
//qDebug() << "Refreshing to voltage" << ((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){
wrapEnabled = enabled;
}