Buffering working
This commit is contained in:
parent
c11e733ee9
commit
0fd46456df
4 changed files with 155 additions and 4 deletions
|
|
@ -15,9 +15,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(ui->actionReconnect, &QAction::triggered, this, &MainWindow::reconnect);
|
||||
connect(&ctrl, &ShimLCController::newConfigAv, this, &MainWindow::updateAvDevices);
|
||||
connect(&ctrl, &ShimLCController::newStatusAv, this, &MainWindow::updateStatus);
|
||||
connect(&ctrl, &ShimLCController::newDataAv, this, &MainWindow::updateSeries);
|
||||
|
||||
// Status Timer
|
||||
connect(&statusTimer, &QTimer::timeout, &ctrl, &ShimLCController::updateStatus);
|
||||
connect(&statusTimer, &QTimer::timeout, &ctrl, &ShimLCController::updateBuf);
|
||||
|
||||
spinner->setRoundness(70.0);
|
||||
spinner->setMinimumTrailOpacity(15.0);
|
||||
|
|
@ -37,12 +38,13 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
//mainChart->setAnimationOptions(QChart::SeriesAnimations);
|
||||
|
||||
// Example...
|
||||
auto series = new QLineSeries;
|
||||
/*
|
||||
for (int i = 0; i < 500; i++) {
|
||||
QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
|
||||
p.ry() += QRandomGenerator::global()->bounded(20);
|
||||
*series << p;
|
||||
}
|
||||
*/
|
||||
mainChart->addSeries(series);
|
||||
mainChart->createDefaultAxes();
|
||||
}
|
||||
|
|
@ -92,7 +94,7 @@ void MainWindow::updateAvDevices()
|
|||
ui->detectorSelectorBox->clear();
|
||||
foreach(LCPort item, ctrl.configuration.detectors)
|
||||
ui->detectorSelectorBox->addItem(QString("Port %1: %2").arg(item.port).arg(item.name));
|
||||
statusTimer.start(3000);
|
||||
statusTimer.start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::updateStatus()
|
||||
|
|
@ -115,3 +117,20 @@ void MainWindow::updateStatus()
|
|||
ui->detectorNmSpinBox->setValue(ctrl.lastStatus.detector[ui->detectorSelectorBox->currentIndex()].waveLen1);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::updateSeries()
|
||||
{
|
||||
for(int i = 0; i<ctrl.bufst[0].vals.length(); i++)
|
||||
{
|
||||
double data_point = ctrl.bufst[0].vals.at(i);
|
||||
if(graph_bounds[0] > data_point)
|
||||
graph_bounds[0] = data_point;
|
||||
if(graph_bounds[1] < data_point)
|
||||
graph_bounds[1] = data_point;
|
||||
QPointF p((qreal) series->count(), data_point);
|
||||
*series << p;
|
||||
}
|
||||
ctrl.bufst[0].vals.clear();
|
||||
mainChart->axisX()->setRange(0, series->count());
|
||||
mainChart->axisY()->setRange(graph_bounds[0], graph_bounds[1]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "zoomablechartview.h"
|
||||
#include "viewdebugstatus.h"
|
||||
#include "QtWaitingSpinner/waitingspinnerwidget.h"
|
||||
#include <QLineSeries>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
|
|
@ -34,6 +35,8 @@ private:
|
|||
ViewDebugStatus vdebug{};
|
||||
ZoomableChart* mainChart = nullptr;
|
||||
WaitingSpinnerWidget* spinner = nullptr;
|
||||
QLineSeries* series = new QLineSeries;
|
||||
float graph_bounds[2] = {1e12,-1e12};
|
||||
|
||||
QTimer statusTimer = QTimer(this);
|
||||
|
||||
|
|
@ -42,5 +45,6 @@ private slots:
|
|||
void reconnect();
|
||||
void updateAvDevices();
|
||||
void updateStatus();
|
||||
void updateSeries();
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -510,6 +510,13 @@ void ShimLCController::updatePif()
|
|||
ids[ID_PIF] = cmd.readFile("lpif.", &data, 4236);
|
||||
}
|
||||
|
||||
void ShimLCController::updateBuf()
|
||||
{
|
||||
connect(&cmd, &ShimLCCommandStack::dataAvailable, this, &ShimLCController::parseLbuf);
|
||||
ids[ID_BUF] = cmd.readFile("lbuf.0", &data, 1000);
|
||||
|
||||
}
|
||||
|
||||
void ShimLCController::reconnect(QSettings *settings)
|
||||
{
|
||||
// Signal reconnect to CMD stack (clears stack, deletes pending commands etc)
|
||||
|
|
@ -692,6 +699,7 @@ void ShimLCController::parseEnv(uint32_t idVal)
|
|||
data.replace(42, 2, "\x14\x00");
|
||||
|
||||
cmd.writeFile("lenv.", &data);
|
||||
disconnect(&cmd, &ShimLCCommandStack::dataAvailable, this, &ShimLCController::parseEnv);
|
||||
}
|
||||
|
||||
void ShimLCController::parseChk(uint32_t idVal)
|
||||
|
|
@ -702,6 +710,7 @@ void ShimLCController::parseChk(uint32_t idVal)
|
|||
|
||||
qDebug() << "Re-Uploading lchk";
|
||||
cmd.writeFile("lchk.", &data);
|
||||
disconnect(&cmd, &ShimLCCommandStack::dataAvailable, this, &ShimLCController::parseChk);
|
||||
}
|
||||
|
||||
void ShimLCController::parsePif(uint32_t idVal)
|
||||
|
|
@ -715,4 +724,106 @@ void ShimLCController::parsePif(uint32_t idVal)
|
|||
cmd.setVal("BUFEND", nullptr);
|
||||
cmd.setVal(cbmSet("BUFSTR", 1), nullptr);
|
||||
cmd.setVal("KEYLOK -3", nullptr);
|
||||
disconnect(&cmd, &ShimLCCommandStack::dataAvailable, this, &ShimLCController::parsePif);
|
||||
}
|
||||
|
||||
void ShimLCController::parseLbuf(uint32_t idVal)
|
||||
{
|
||||
// TODO: proper handling!
|
||||
if(ids[ID_BUF] != idVal)
|
||||
return;
|
||||
|
||||
qDebug() << "Collecting new Buffer data... Len: " << data.length();
|
||||
int i = 4;
|
||||
while(i < data.length())
|
||||
{
|
||||
bool earlyReturn = 0;
|
||||
bool wthmode = 0;
|
||||
quint8 b = 0;
|
||||
quint8 cur_ctrl = data.at(i);
|
||||
|
||||
while((i < data.length()) && ((cur_ctrl & 0x80u) != 0) && (not earlyReturn))
|
||||
{
|
||||
switch(cur_ctrl)
|
||||
{
|
||||
case 0xC1u:
|
||||
// "CBM data Start event"
|
||||
bufst[cur_buf].curFlag |= 0x80u; // Set CBM data bit (highest bit)
|
||||
// curRT??? TODO?
|
||||
bufst[cur_buf].period = qFromLittleEndian<quint16>(data.mid(i+1, 2));
|
||||
i += 5;
|
||||
earlyReturn = 1;
|
||||
break;
|
||||
case 0xC2u:
|
||||
// "CBM data Stop event"
|
||||
bufst[cur_buf].curFlag &= 0x7fu; // Unset CBM data bit (highest bit)
|
||||
i += 1;
|
||||
earlyReturn = 1;
|
||||
break;
|
||||
case 0xC4u:
|
||||
// "Rate event"
|
||||
bufst[cur_buf].period = qFromLittleEndian<quint16>(data.mid(i+1, 2));
|
||||
i += 3;
|
||||
earlyReturn = 1;
|
||||
break;
|
||||
case 0xC5u:
|
||||
// "Fact Event"
|
||||
bufst[cur_buf].convFact = qFromLittleEndian<qfloat16>(data.mid(i+1, 2));
|
||||
qDebug() << "New conv Fact: " << bufst[cur_buf].convFact;
|
||||
bufst[cur_buf].gainFact = qFromLittleEndian<qfloat16>(data.mid(i+5, 2));
|
||||
i += 9;
|
||||
earlyReturn = 1;
|
||||
break;
|
||||
case 0xC8u:
|
||||
// "Data reset event"
|
||||
bufst[cur_buf].curValue = 0;
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
if(0xA0u == (cur_ctrl & 0xE0u)) // If 0b101xxxxx
|
||||
{
|
||||
b = (quint8)(cur_ctrl << 5);
|
||||
wthmode = 1;
|
||||
}
|
||||
else
|
||||
bufst[cur_buf].curFlag |= (cur_ctrl & 0x1Fu);
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if(i < data.length())
|
||||
cur_ctrl = data.at(i);
|
||||
}
|
||||
if((not earlyReturn) && (i < data.length()))
|
||||
{
|
||||
cur_ctrl = data.at(i);
|
||||
quint8 upper3 = (quint8)((cur_ctrl >> 5) & 3u); // upper 3 bytes
|
||||
if(wthmode)
|
||||
bufst[cur_buf].databuf[upper3] = (quint8)((cur_ctrl & 0x1Fu) | b);
|
||||
else
|
||||
{
|
||||
if((cur_ctrl & 0x10u) == 0)
|
||||
for(int j = 0; j < 4; j++)
|
||||
bufst[cur_buf].databuf[j] = 0;
|
||||
else
|
||||
for(int j = 0; j < 4; j++)
|
||||
bufst[cur_buf].databuf[j] = 0xFFu;
|
||||
bufst[cur_buf].databuf[upper3] = (quint8)((cur_ctrl & 0x1Fu) | (bufst[cur_buf].databuf[3] & 0xE0u));
|
||||
}
|
||||
|
||||
i++;
|
||||
while(upper3 > 0)
|
||||
{
|
||||
upper3 -= 1;
|
||||
bufst[cur_buf].databuf[upper3] = data.at(i);
|
||||
i++;
|
||||
}
|
||||
int num = bufst[cur_buf].curValue + qFromLittleEndian<qint32>(bufst[cur_buf].databuf);
|
||||
bufst[cur_buf].curValue = num;
|
||||
double data = (double)num * (double)bufst[cur_buf].convFact;
|
||||
bufst[cur_buf].vals.append(data);
|
||||
}
|
||||
}
|
||||
disconnect(&cmd, &ShimLCCommandStack::dataAvailable, this, &ShimLCController::parseLbuf);
|
||||
data.clear();
|
||||
emit newDataAv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,6 +213,17 @@ struct LCconfiguration
|
|||
// TODO: Implement the rest of the options
|
||||
};
|
||||
|
||||
struct BufSt
|
||||
{
|
||||
quint8 curFlag = 0;
|
||||
double curValue = 0.0;
|
||||
quint16 period = 0;
|
||||
float convFact = 0;
|
||||
float gainFact = 0;
|
||||
quint8 databuf[4]{};
|
||||
QList<double> vals{};
|
||||
};
|
||||
|
||||
class CmdVal : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -271,6 +282,7 @@ private:
|
|||
#define ID_ENV 2
|
||||
#define ID_CHK 3
|
||||
#define ID_PIF 4
|
||||
#define ID_BUF 4
|
||||
|
||||
class ShimLCController : public QObject
|
||||
{
|
||||
|
|
@ -282,9 +294,11 @@ public:
|
|||
void updateEnv();
|
||||
void updateChk();
|
||||
void updatePif();
|
||||
void updateBuf();
|
||||
void reconnect(QSettings *settings);
|
||||
LCconfiguration configuration{};
|
||||
LCStatus lastStatus{};
|
||||
BufSt bufst[6]{};
|
||||
|
||||
explicit ShimLCController(QObject *parent = nullptr);
|
||||
~ShimLCController();
|
||||
|
|
@ -293,6 +307,7 @@ signals:
|
|||
void newConfigAv();
|
||||
void newStatusAv();
|
||||
void connectionStateChanged(QAbstractSocket::SocketState state);
|
||||
void newDataAv();
|
||||
|
||||
private:
|
||||
void parseLcnf(uint32_t idVal);
|
||||
|
|
@ -300,9 +315,11 @@ private:
|
|||
void parseEnv(uint32_t idVal);
|
||||
void parseChk(uint32_t idVal);
|
||||
void parsePif(uint32_t idVal);
|
||||
uint32_t ids[5]; // 0 - config / 1 - status / 2 - env / 3 - chk / 4 - PIF
|
||||
void parseLbuf(uint32_t idVal);
|
||||
uint32_t ids[6]; // 0 - config / 1 - status / 2 - env / 3 - chk / 4 - PIF / 5 - BUF
|
||||
ShimLCCommandStack cmd{};
|
||||
QByteArray data{};
|
||||
int cur_buf = 0;
|
||||
};
|
||||
|
||||
#endif // SHIMLCCONTROLLER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue