kopia lustrzana https://github.com/f4exb/sdrangel
				
				
				
			Scope: save/load traces memory (1)
							rodzic
							
								
									b397cd3a4b
								
							
						
					
					
						commit
						5d57f40e83
					
				| 
						 | 
				
			
			@ -20,6 +20,10 @@
 | 
			
		|||
#include <vector>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
#include <QByteArray>
 | 
			
		||||
 | 
			
		||||
#include "simpleserializer.h"
 | 
			
		||||
 | 
			
		||||
template<typename T>
 | 
			
		||||
class DoubleBufferSimple
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +93,48 @@ public:
 | 
			
		|||
	unsigned int absoluteFill() const { return m_current - m_data.begin(); }
 | 
			
		||||
	void reset() { m_current = m_data.begin(); }
 | 
			
		||||
 | 
			
		||||
    QByteArray serialize() const
 | 
			
		||||
    {
 | 
			
		||||
        SimpleSerializer s(1);
 | 
			
		||||
 | 
			
		||||
        QByteArray buf(reinterpret_cast<const char*>(m_data.data()), m_data.size()*sizeof(T));
 | 
			
		||||
        s.writeS32(1, m_size);
 | 
			
		||||
        s.writeU32(2, m_current - m_data.begin());
 | 
			
		||||
        s.writeBlob(3, buf);
 | 
			
		||||
 | 
			
		||||
        return s.final();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool deserialize(const QByteArray& data)
 | 
			
		||||
    {
 | 
			
		||||
        SimpleDeserializer d(data);
 | 
			
		||||
 | 
			
		||||
        if(!d.isValid()) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (d.getVersion() == 1)
 | 
			
		||||
        {
 | 
			
		||||
            unsigned int tmpUInt;
 | 
			
		||||
            QByteArray buf;
 | 
			
		||||
 | 
			
		||||
            d.readS32(1, &m_size, m_data.size()/2);
 | 
			
		||||
            m_data.resize(2*m_size);
 | 
			
		||||
            d.readU32(2, &tmpUInt, 0);
 | 
			
		||||
            m_current = m_data.begin() + tmpUInt;
 | 
			
		||||
            d.readBlob(3, &buf);
 | 
			
		||||
            const T* begin = reinterpret_cast<T*>(buf.data());
 | 
			
		||||
            const T* end = begin + (buf.length()/sizeof(T));
 | 
			
		||||
            std::copy(m_data.begin(), begin, end);
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	int m_size;
 | 
			
		||||
	std::vector<T> m_data;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@
 | 
			
		|||
///////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
#include <QColorDialog>
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
 | 
			
		||||
#include "glscopegui.h"
 | 
			
		||||
#include "glscope.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -768,12 +769,43 @@ void GLScopeGUI::on_traceColor_clicked()
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GLScopeGUI::on_memorySave_clicked(bool checked __attribute__((unused)))
 | 
			
		||||
{
 | 
			
		||||
    qDebug("GLScopeGUI::on_memorySave_clicked");
 | 
			
		||||
    QString fileName = QFileDialog::getSaveFileName(this,
 | 
			
		||||
        tr("Open trace memory file"), ".", tr("Trace memory files (*.trcm)"), 0, QFileDialog::DontUseNativeDialog);
 | 
			
		||||
 | 
			
		||||
    if (fileName != "")
 | 
			
		||||
    {
 | 
			
		||||
        QFileInfo fileInfo(fileName);
 | 
			
		||||
 | 
			
		||||
        if (fileInfo.suffix() != "trcm") {
 | 
			
		||||
            fileName += ".trcm";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        qDebug("GLScopeGUI::on_memorySave_clicked: %s", qPrintable(fileName));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GLScopeGUI::on_memoryLoad_clicked(bool checked __attribute__((unused)))
 | 
			
		||||
{
 | 
			
		||||
    qDebug("GLScopeGUI::on_memoryLoad_clicked");
 | 
			
		||||
 | 
			
		||||
    QString fileName = QFileDialog::getOpenFileName(this,
 | 
			
		||||
        tr("Open trace memory file"), ".", tr("Trace memory files (*.trcm)"), 0, QFileDialog::DontUseNativeDialog);
 | 
			
		||||
 | 
			
		||||
    if (fileName != "")
 | 
			
		||||
    {
 | 
			
		||||
        qDebug("GLScopeGUI::on_memoryLoad_clicked: %s", qPrintable(fileName));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GLScopeGUI::on_mem_valueChanged(int value)
 | 
			
		||||
{
 | 
			
		||||
    QString text;
 | 
			
		||||
    text.sprintf("%02d", value);
 | 
			
		||||
    ui->memText->setText(text);
 | 
			
		||||
   	disableLiveMode(value > 0); // block trigger UI line if memory is active
 | 
			
		||||
   	disableLiveMode(value > 0); // live / memory mode toggle
 | 
			
		||||
   	m_scopeVis->setMemoryIndex(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1224,6 +1256,8 @@ void GLScopeGUI::disableLiveMode(bool disable)
 | 
			
		|||
    ui->trigPre->setEnabled(!disable);
 | 
			
		||||
    ui->trigOneShot->setEnabled(!disable);
 | 
			
		||||
    ui->freerun->setEnabled(!disable);
 | 
			
		||||
    ui->memorySave->setEnabled(disable);
 | 
			
		||||
    ui->memoryLoad->setEnabled(disable);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GLScopeGUI::fillTraceData(ScopeVis::TraceData& traceData)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -211,6 +211,8 @@ private slots:
 | 
			
		|||
    void on_traceDelayFine_valueChanged(int value);
 | 
			
		||||
    void on_traceView_toggled(bool checked);
 | 
			
		||||
    void on_traceColor_clicked();
 | 
			
		||||
    void on_memorySave_clicked(bool checked);
 | 
			
		||||
    void on_memoryLoad_clicked(bool checked);
 | 
			
		||||
    void on_mem_valueChanged(int value);
 | 
			
		||||
    // Third row
 | 
			
		||||
    void on_trig_valueChanged(int value);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1102,6 +1102,71 @@ kS/s</string>
 | 
			
		|||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <layout class="QVBoxLayout" name="memoryLoadSaveLayout">
 | 
			
		||||
       <property name="spacing">
 | 
			
		||||
        <number>0</number>
 | 
			
		||||
       </property>
 | 
			
		||||
       <item>
 | 
			
		||||
        <widget class="QPushButton" name="memorySave">
 | 
			
		||||
         <property name="enabled">
 | 
			
		||||
          <bool>false</bool>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="maximumSize">
 | 
			
		||||
          <size>
 | 
			
		||||
           <width>18</width>
 | 
			
		||||
           <height>18</height>
 | 
			
		||||
          </size>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="toolTip">
 | 
			
		||||
          <string>Save traces in memory</string>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="text">
 | 
			
		||||
          <string/>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="icon">
 | 
			
		||||
          <iconset resource="../resources/res.qrc">
 | 
			
		||||
           <normaloff>:/save.png</normaloff>:/save.png</iconset>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="iconSize">
 | 
			
		||||
          <size>
 | 
			
		||||
           <width>16</width>
 | 
			
		||||
           <height>16</height>
 | 
			
		||||
          </size>
 | 
			
		||||
         </property>
 | 
			
		||||
        </widget>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <widget class="QPushButton" name="memoryLoad">
 | 
			
		||||
         <property name="enabled">
 | 
			
		||||
          <bool>false</bool>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="maximumSize">
 | 
			
		||||
          <size>
 | 
			
		||||
           <width>18</width>
 | 
			
		||||
           <height>18</height>
 | 
			
		||||
          </size>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="toolTip">
 | 
			
		||||
          <string>Load traces into memory</string>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="text">
 | 
			
		||||
          <string/>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="icon">
 | 
			
		||||
          <iconset resource="../resources/res.qrc">
 | 
			
		||||
           <normaloff>:/load.png</normaloff>:/load.png</iconset>
 | 
			
		||||
         </property>
 | 
			
		||||
         <property name="iconSize">
 | 
			
		||||
          <size>
 | 
			
		||||
           <width>16</width>
 | 
			
		||||
           <height>16</height>
 | 
			
		||||
          </size>
 | 
			
		||||
         </property>
 | 
			
		||||
        </widget>
 | 
			
		||||
       </item>
 | 
			
		||||
      </layout>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="memLabel">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue