1 Star 0 Fork 0

xiongqiumin/DataGather

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Config.cpp 6.40 KB
一键复制 编辑 原始数据 按行查看 历史
xiongqiumin 提交于 2020-12-23 17:45 . init
#include <Windows.h>
#include <QApplication>
#include <QFile>
#include <QDataStream>
#include <QVector>
#include "USB9982\USB9982.h"
#include "Config.h"
//magicFileList
QVector<int> magicFileList()
{
QVector<int> list;
list << 9 << 9 << 6;
list << sizeof(Config) << sizeof(Param_HRF9828) << sizeof(Param_USB9982) << sizeof(SaveConfig);
return list;
}
//Param_HRF9828
Param_HRF9828::Param_HRF9828()
{
RangeIndex = 0;
DAQFreq = 1000;
T0_Freq = 1000;
T0_Duty = 50;
T1_Freq = 1000;
T1_Duty = 50;
T2_Freq = 1000;
T2_Duty = 50;
AO.fill(0);
DO.fill(false);
for (int i = 0; i < 24; i++)
Names[i] = QString::asprintf("AO%02d", i);
for (int i = 0; i < 14; i++)
Names[24 + i] = QString::asprintf("DO%02d", i);
for (int i = 0; i < 24; i++)
Names[24 + 14 + i] = QString::asprintf("AI%02d", i);
for (int i = 0; i < 14; i++)
Names[48 + 14 + i] = QString::asprintf("DI%02d", i);
for (int i = 0; i < (int)Coefs.size(); i++)
Coefs[i] = 1;
for(int i = 0; i < 14; i++)
Coefs[i] = 42;
Coefs[14] = 867;
Coefs[16] = 200;
Coefs[18] = 200;
Coefs[19] = 200;
Coefs[20] = 100;
Coefs[22] = 200;
}
QDataStream &operator<<(QDataStream &s, const Param_HRF9828 &param)
{
s << param.RangeIndex;
s << param.DAQFreq;
s << param.T0_Freq;
s << param.T0_Duty;
s << param.T1_Freq;
s << param.T1_Duty;
s << param.T2_Freq;
s << param.T2_Duty;
for (size_t i = 0; i < param.AO.size(); i++)
s << param.AO[i];
for (size_t i = 0; i < param.DO.size(); i++)
s << param.DO[i];
for (size_t i = 0; i < param.Names.size(); i++)
s << param.Names[i];
for (size_t i = 0; i < param.Coefs.size(); i++)
s << param.Coefs[i];
return s;
}
QDataStream &operator >> (QDataStream &s, Param_HRF9828 &param)
{
s >> param.RangeIndex;
s >> param.DAQFreq;
s >> param.T0_Freq;
s >> param.T0_Duty;
s >> param.T1_Freq;
s >> param.T1_Duty;
s >> param.T2_Freq;
s >> param.T2_Duty;
for (size_t i = 0; i < param.AO.size(); i++)
s >> param.AO[i];
for (size_t i = 0; i < param.DO.size(); i++)
s >> param.DO[i];
for (size_t i = 0; i < param.Names.size(); i++)
s >> param.Names[i];
for (size_t i = 0; i < param.Coefs.size(); i++)
s >> param.Coefs[i];
return s;
}
//Param_USB9982
Param_USB9982::Param_USB9982()
{
Enable2G = true;
EnableInt = false;
EnableADD = false;
CHCount = 1;
TriggerMode = 0;
TriggerSource = 0;
TriggerDelay = 100;
TriggerLevel = 2048;
ADGain = 0;
ADDCnt = 1000;
ADDThd = 255;
ClockDeci = 1;
ClockSel = 0;
GatherLength = 25;
PWMFreq = 10000;
GatherTime = 100;
Thres = 128;
}
int Param_USB9982::trigUnit()
{
int samcnt = int(GatherLength * 1024 * 1024 / 1000);
samcnt = samcnt /128;
return samcnt;
}
int Param_USB9982::gatherSize()
{
int samcnt = int(GatherLength * 1024 * 1024 / 1000);
if (TriggerSource != TRIG_MODE_CONTINUE)
{
samcnt = trigUnit() * 128;
}
//如果累加功能使能,重新计算显示最大值和读取长度
if (EnableADD)
{
samcnt = samcnt * ADD_BW; //一次的累加结果,是一次触发长度乘上累加后的位宽
}
samcnt = samcnt / 512 * 512;
if (samcnt < 512)
samcnt = 512;
samcnt *= CHCount;
return samcnt;
}
int Param_USB9982::frameSize()
{
int mm = 1;
if (CHCount == 2 && Enable2G == FALSE)
mm = 2;
int samcnt = gatherSize();
int tcnt = 0;
if (EnableADD) {
tcnt = samcnt / ADD_BW / mm;
}
else
{
tcnt = samcnt / mm;
}
return tcnt;
}
QDataStream &operator<<(QDataStream &s, const Param_USB9982 &param)
{
s << param.Enable2G;
s << param.EnableInt;
s << param.EnableADD;
s << param.CHCount;
s << param.TriggerMode;
s << param.TriggerSource;
s << param.TriggerDelay;
s << param.TriggerLevel;
s << param.ADGain;
s << param.ADDCnt;
s << param.ADDThd;
s << param.ClockDeci;
s << param.ClockSel;
s << param.GatherLength;
s << param.GatherTime;
s << param.PWMFreq;
s << param.Thres;
return s;
}
QDataStream &operator>>(QDataStream &s, Param_USB9982 &param)
{
s >> param.Enable2G;
s >> param.EnableInt;
s >> param.EnableADD;
s >> param.CHCount;
s >> param.TriggerMode;
s >> param.TriggerSource;
s >> param.TriggerDelay;
s >> param.TriggerLevel;
s >> param.ADGain;
s >> param.ADDCnt;
s >> param.ADDThd;
s >> param.ClockDeci;
s >> param.ClockSel;
s >> param.GatherLength;
s >> param.GatherTime;
s >> param.PWMFreq;
s >> param.Thres;
return s;
}
//
SaveConfig::SaveConfig()
{
saveFile = false;
maxSize = 4096;
savePre = "data";
savePath = "save";
}
QDataStream &operator<<(QDataStream &s, const SaveConfig &param)
{
s << param.saveFile;
s << param.savePre;
s << param.savePath;
s << param.maxSize;
return s;
}
QDataStream &operator>>(QDataStream &s, SaveConfig &param)
{
s >> param.saveFile;
s >> param.savePre;
s >> param.savePath;
s >> param.maxSize;
return s;
}
//Config
Config::Config()
{
}
void Config::saveToStream(QDataStream &s)
{
s << hrf9828;
s << usb9982;
s << saveInfo;
}
void Config::loadFromStream(QDataStream &s)
{
s >> hrf9828;
s >> usb9982;
s >> saveInfo;
}
QByteArray Config::backUp()
{
QByteArray buffer;
QDataStream s(&buffer, QIODevice::WriteOnly);
saveToStream(s);
return buffer;
}
void Config::save()
{
QByteArray tmp = backUp();
if (tmp == m_backUp)
return;
QString filename = QApplication::applicationDirPath() + "/Config.dat";
//读取文件
QFile file(filename); //QIODevice::Text
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
QDataStream s(&file);
s << magicFileList();
//save data
saveToStream(s);
file.close();
}
}
void Config::load()
{
QString filename = QApplication::applicationDirPath() + "/Config.dat";
//读取文件
QFile file(filename); //QIODevice::Text
if (file.open(QIODevice::ReadOnly))
{
QVector<int> magicList;
QDataStream s(&file);
s >> magicList;
//load data
if (magicList == magicFileList())
{
loadFromStream(s);
}
file.close();
m_backUp = backUp();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiongqiumin/DataGather.git
[email protected]:xiongqiumin/DataGather.git
xiongqiumin
DataGather
DataGather
master

搜索帮助