mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 18:50:44 +00:00
Fix FPIcon Waveform regression
This commit is contained in:
parent
fedd464878
commit
16672fcd4a
@ -165,7 +165,7 @@ void EventList::AddWaveform(qint64 start, qint16 *data, int recs, qint64 duratio
|
||||
// EventStoreType *edata = m_data.data();
|
||||
|
||||
EventStoreType raw;
|
||||
// qint16 *ep = data + recs;
|
||||
// qint16 *ep = data + recs;
|
||||
qint16 *sp = data;
|
||||
// EventStoreType *dp = &edata[r];
|
||||
|
||||
@ -173,11 +173,10 @@ void EventList::AddWaveform(qint64 start, qint16 *data, int recs, qint64 duratio
|
||||
EventDataType min = m_min, max = m_max, val, gain = m_gain;
|
||||
|
||||
for (int i=0; i < recs; ++i ) {
|
||||
m_data[i] = raw = *sp;
|
||||
m_data[r++] = raw = *sp++;
|
||||
val = EventDataType(raw) * gain + m_offset;
|
||||
if (min > val) { min = val; }
|
||||
if (max < val) { max = val; }
|
||||
sp++;
|
||||
}
|
||||
// for (sp = data; sp < ep; ++sp) {
|
||||
// *dp++ = raw = *sp;
|
||||
|
@ -183,6 +183,7 @@ int FPIconLoader::OpenMachine(Machine *mach, QString &path, Profile *profile)
|
||||
if (qprogress) { qprogress->setValue(0); }
|
||||
|
||||
QStringList summary, log, flw, det;
|
||||
Sessions.clear();
|
||||
|
||||
for (int i = 0; i < flist.size(); i++) {
|
||||
QFileInfo fi = flist.at(i);
|
||||
@ -307,28 +308,8 @@ quint32 convertDate(quint32 timestamp)
|
||||
minute = (timestamp >> 6) & 0x3f;
|
||||
hour = (timestamp >> 12) & 0x1f;
|
||||
|
||||
// in >> a1;
|
||||
// in >> a2;
|
||||
// t1 = a2 << 8 | a1;
|
||||
|
||||
// if (t1 == 0xfafe) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// day = t1 & 0x1f;
|
||||
// month = (t1 >> 5) & 0x0f;
|
||||
// year = 2000 + ((t1 >> 9) & 0x3f);
|
||||
|
||||
// in >> a1;
|
||||
// in >> a2;
|
||||
|
||||
// ts = ((a2 << 8) | a1) << 1;
|
||||
// ts |= (t1 >> 15) & 1;
|
||||
|
||||
// second = (ts & 0x3f);
|
||||
// minute = (ts >> 6) & 0x3f;
|
||||
// hour = (ts >> 12) & 0x1f;
|
||||
QDateTime dt = QDateTime(QDate(year, month, day), QTime(hour, minute, second), Qt::UTC);
|
||||
Q_ASSERT(dt.isValid());
|
||||
|
||||
return dt.toTime_t();
|
||||
}
|
||||
@ -351,6 +332,7 @@ quint32 convertFLWDate(quint32 timestamp)
|
||||
minute = (timestamp >> 6) & 0x3f;
|
||||
hour = (timestamp >> 12) & 0x1f;
|
||||
QDateTime dt = QDateTime(QDate(year, month, day), QTime(hour, minute, second), Qt::UTC);
|
||||
Q_ASSERT(dt.isValid());
|
||||
|
||||
return dt.toTime_t();
|
||||
}
|
||||
@ -488,16 +470,20 @@ bool FPIconLoader::OpenFLW(Machine *mach, QString filename, Profile *profile)
|
||||
Session *s1 = nullptr;
|
||||
sess = nullptr;
|
||||
|
||||
for (sit = Sessions.begin(); sit != Sessions.end(); sit++) {
|
||||
s1 = sit.value();
|
||||
qint64 z = qAbs(s1->first() - ti);
|
||||
|
||||
if (z < 3600000) {
|
||||
if ((k < 0) || (k > z)) {
|
||||
k = z;
|
||||
sess = s1;
|
||||
sit = Sessions.end();
|
||||
int cnt=0;
|
||||
if (Sessions.begin() != sit) {
|
||||
do {
|
||||
sit --;
|
||||
s1 = sit.value();
|
||||
qint64 z = qAbs(sit.key() - ts);
|
||||
if (z < 3600) {
|
||||
if ((k < 0) || (k > z)) {
|
||||
k = z;
|
||||
sess = s1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (sit != Sessions.begin());
|
||||
}
|
||||
|
||||
if (sess) {
|
||||
@ -590,6 +576,7 @@ bool FPIconLoader::OpenFLW(Machine *mach, QString filename, Profile *profile)
|
||||
QDir dir;
|
||||
QString newname = QString("FLW%1.FPH").arg(ts);
|
||||
dir.mkpath(backup);
|
||||
dir.cd(backup);
|
||||
if (!dir.exists(newname)) {
|
||||
file.copy(backup+newname);
|
||||
}
|
||||
@ -643,12 +630,11 @@ bool FPIconLoader::OpenSummary(Machine *mach, QString filename, Profile *profile
|
||||
|
||||
QByteArray data;
|
||||
data = file.readAll();
|
||||
//long size=data.size(),pos=0;
|
||||
|
||||
QDataStream in(data);
|
||||
in.setVersion(QDataStream::Qt_4_6);
|
||||
in.setVersion(QDataStream::Qt_4_8);
|
||||
in.setByteOrder(QDataStream::LittleEndian);
|
||||
|
||||
quint16 t1;//,t2;
|
||||
quint32 ts;
|
||||
//QByteArray line;
|
||||
unsigned char a1, a2, a3, a4, a5, p1, p2, p3, p4, p5, j1, j2, j3 , j4, j5, j6, j7, x1, x2;
|
||||
@ -783,6 +769,10 @@ bool FPIconLoader::OpenDetail(Machine *mach, QString filename, Profile *profile)
|
||||
htxt >> type;
|
||||
|
||||
QByteArray index = file.read(0x800);
|
||||
if (index.size()!=0x800) {
|
||||
// faulty file..
|
||||
return false;
|
||||
}
|
||||
QDataStream in(index);
|
||||
quint32 ts;
|
||||
|
||||
@ -895,6 +885,7 @@ bool FPIconLoader::OpenDetail(Machine *mach, QString filename, Profile *profile)
|
||||
QString backup = PROFILE.Get(mach->properties[STR_PROP_BackupPath])+"FPHCARE/ICON/"+serial.right(serial.size()-4)+"/";
|
||||
QDir dir;
|
||||
QString newname = QString("DET%1.FPH").arg(ts);
|
||||
|
||||
dir.mkpath(backup);
|
||||
dir.cd(backup);
|
||||
if (!dir.exists(newname)) {
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "machine.h"
|
||||
@ -388,16 +390,16 @@ void Machine::queSaveList(Session * sess)
|
||||
}
|
||||
|
||||
} else {
|
||||
savelistMutex.lock();
|
||||
listMutex.lock();
|
||||
m_savelist.append(sess);
|
||||
savelistMutex.unlock();
|
||||
listMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
Session *Machine::popSaveList()
|
||||
{
|
||||
Session *sess = nullptr;
|
||||
savelistMutex.lock();
|
||||
listMutex.lock();
|
||||
|
||||
if (!m_savelist.isEmpty()) {
|
||||
sess = m_savelist.at(0);
|
||||
@ -405,7 +407,7 @@ Session *Machine::popSaveList()
|
||||
m_donetasks++;
|
||||
}
|
||||
|
||||
savelistMutex.unlock();
|
||||
listMutex.unlock();
|
||||
return sess;
|
||||
}
|
||||
|
||||
@ -471,7 +473,9 @@ void SaveThread::run()
|
||||
emit UpdateProgress(i);
|
||||
}
|
||||
sess->UpdateSummaries();
|
||||
machine->saveMutex.lock();
|
||||
sess->Store(path);
|
||||
machine->saveMutex.unlock();
|
||||
|
||||
sess->TrashEvents();
|
||||
} else {
|
||||
@ -487,6 +491,60 @@ void SaveThread::run()
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SaveTask:public ImportTask
|
||||
{
|
||||
public:
|
||||
SaveTask(Session * s, Machine * m): sess(s), mach(m) {}
|
||||
virtual ~SaveTask() {}
|
||||
virtual void run();
|
||||
|
||||
protected:
|
||||
Session * sess;
|
||||
Machine * mach;
|
||||
};
|
||||
|
||||
void SaveTask::run()
|
||||
{
|
||||
sess->UpdateSummaries();
|
||||
mach->saveMutex.lock();
|
||||
sess->Store(p_profile->Get(mach->properties[STR_PROP_Path]));
|
||||
mach->saveMutex.unlock();
|
||||
sess->TrashEvents();
|
||||
}
|
||||
|
||||
void Machine::queTask(ImportTask * task)
|
||||
{
|
||||
if (PROFILE.session->multithreading()) {
|
||||
m_tasklist.push_back(task);
|
||||
return;
|
||||
}
|
||||
|
||||
task->run();
|
||||
return;
|
||||
}
|
||||
|
||||
void Machine::runTasks()
|
||||
{
|
||||
if (!PROFILE.session->multithreading()) {
|
||||
Q_ASSERT(m_tasklist.isEmpty());
|
||||
return;
|
||||
}
|
||||
QThreadPool * threadpool = QThreadPool::globalInstance();
|
||||
int m_totaltasks=m_tasklist.size();
|
||||
int m_currenttask=0;
|
||||
while (!m_tasklist.isEmpty()) {
|
||||
if (threadpool->tryStart(m_tasklist.at(0))) {
|
||||
m_tasklist.pop_front();
|
||||
float f = float(m_currenttask) / float(m_totaltasks) * 100.0;
|
||||
qprogress->setValue(f);
|
||||
m_currenttask++;
|
||||
}
|
||||
QApplication::processEvents();
|
||||
}
|
||||
QThreadPool::globalInstance()->waitForDone(-1);
|
||||
}
|
||||
|
||||
bool Machine::Save()
|
||||
{
|
||||
//int size;
|
||||
@ -507,62 +565,11 @@ bool Machine::Save()
|
||||
cnt++;
|
||||
|
||||
if ((*s)->IsChanged()) {
|
||||
m_savelist.push_back(*s);
|
||||
queTask(new SaveTask(*s, this));
|
||||
}
|
||||
}
|
||||
|
||||
savelistCnt = 0;
|
||||
savelistSize = m_savelist.size();
|
||||
|
||||
if (!PROFILE.session->multithreading()) {
|
||||
for (int i = 0; i < savelistSize; i++) {
|
||||
|
||||
// Update progress bar
|
||||
if ((i % 10) == 0) {
|
||||
qprogress->setValue(0 + (float(savelistCnt) / float(savelistSize) * 100.0));
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
Session *s = m_savelist.at(i);
|
||||
s->UpdateSummaries();
|
||||
s->Store(path);
|
||||
s->TrashEvents();
|
||||
|
||||
savelistCnt++;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int threads = QThread::idealThreadCount();
|
||||
savelistSem = new QSemaphore(threads);
|
||||
savelistSem->acquire(threads);
|
||||
QVector<SaveThread *>thread;
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
thread.push_back(new SaveThread(this, path));
|
||||
QObject::connect(thread[i], SIGNAL(UpdateProgress(int)), qprogress, SLOT(setValue(int)));
|
||||
thread[i]->start();
|
||||
}
|
||||
|
||||
while (!savelistSem->tryAcquire(threads, 250)) {
|
||||
if (qprogress) {
|
||||
// qprogress->setValue(66.0+(float(savelistCnt)/float(savelistSize)*33.0));
|
||||
QApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
while (thread[i]->isRunning()) {
|
||||
SaveThread::msleep(250);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
delete thread[i];
|
||||
}
|
||||
|
||||
delete savelistSem;
|
||||
runTasks();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
#include <QRunnable>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QSemaphore>
|
||||
@ -59,6 +60,13 @@ class SaveThread: public QThread
|
||||
void UpdateProgress(int i);
|
||||
};
|
||||
|
||||
class ImportTask:public QRunnable
|
||||
{
|
||||
public:
|
||||
explicit ImportTask() {}
|
||||
virtual ~ImportTask() {}
|
||||
virtual void run() {}
|
||||
};
|
||||
|
||||
/*! \class Machine
|
||||
\brief This Machine class is the Heart of SleepyLib, representing a single Machine and holding it's data
|
||||
@ -149,16 +157,15 @@ class Machine
|
||||
//! \brief The list of sessions that need saving (for multithreaded save code)
|
||||
QList<Session *> m_savelist;
|
||||
|
||||
//yuck
|
||||
QVector<SaveThread *>thread;
|
||||
|
||||
|
||||
volatile int savelistCnt;
|
||||
int savelistSize;
|
||||
QMutex savelistMutex;
|
||||
QMutex listMutex;
|
||||
QSemaphore *savelistSem;
|
||||
|
||||
void lockSaveMutex() { savelistMutex.lock(); }
|
||||
void unlockSaveMutex() { savelistMutex.unlock(); }
|
||||
void lockSaveMutex() { listMutex.lock(); }
|
||||
void unlockSaveMutex() { listMutex.unlock(); }
|
||||
void skipSaveTask() { lockSaveMutex(); m_donetasks++; unlockSaveMutex(); }
|
||||
|
||||
void clearSkipped() { skipped_sessions = 0; }
|
||||
@ -167,6 +174,12 @@ class Machine
|
||||
inline int totalTasks() { return m_totaltasks; }
|
||||
inline void setTotalTasks(int value) { m_totaltasks = value; }
|
||||
inline int doneTasks() { return m_donetasks; }
|
||||
|
||||
|
||||
// much more simpler multithreading...
|
||||
void queTask(ImportTask * task);
|
||||
void runTasks();
|
||||
QMutex saveMutex;
|
||||
protected:
|
||||
QDate firstday, lastday;
|
||||
SessionID highest_sessionid;
|
||||
@ -182,6 +195,9 @@ class Machine
|
||||
|
||||
int skipped_sessions;
|
||||
volatile bool m_save_threads_running;
|
||||
|
||||
QList<ImportTask *> m_tasklist;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,14 +23,6 @@
|
||||
|
||||
class MachineLoader;
|
||||
|
||||
class ImportTask:public QRunnable
|
||||
{
|
||||
public:
|
||||
explicit ImportTask() {}
|
||||
virtual ~ImportTask() {}
|
||||
virtual void run() {}
|
||||
};
|
||||
|
||||
|
||||
/*! \class MachineLoader
|
||||
\brief Base class to derive a new Machine importer from
|
||||
|
@ -142,6 +142,7 @@ bool Session::Store(QString path)
|
||||
base = path + "/" + base;
|
||||
//qDebug() << "Storing Session: " << base;
|
||||
bool a;
|
||||
|
||||
a = StoreSummary(base + ".000"); // if actually has events
|
||||
|
||||
//qDebug() << " Summary done";
|
||||
|
Loading…
Reference in New Issue
Block a user