#include "SysConfigger.h"


ZZ_SysConfigger::ZZ_SysConfigger(QObject* parent /*= nullptr*/)
{
#ifdef _DEBUG
	m_qstrDeviceSettingsFilePath = "E:/WorkSpace/git/IRIS_FODIS/IRIS_FODIS/Settings/DeviceSettings.ini";
#else
	m_qstrDeviceSettingsFilePath = "/home/data/Setting/DeviceSettings.ini";
#endif // DEBUG

	m_qsDeviceSettings = NULL;
}


ZZ_SysConfigger::~ZZ_SysConfigger()
{

}


void ZZ_SysConfigger::Initialize()
{
	if (m_qsDeviceSettings != NULL)
	{
		delete m_qsDeviceSettings;
	}
	m_qsDeviceSettings = new QSettings(m_qstrDeviceSettingsFilePath, QSettings::IniFormat);
}

//void ZZ_SysConfigger::SetContext(OneFSContext struOFSC)
//{
//	m_struOneFSContext = struOFSC;
//}

bool ZZ_SysConfigger::LoadSettings_FS(OneFSContext &struOFSC)
{
	bool bRes = true;
	////
	QString qstrTemp = m_qsDeviceSettings->value(QString("FS/Model"), "Null").toString();
	if(qstrTemp == "Null")
	{ 
		//qDebug() << "FS Model Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.ucDeviceModel = ZZ_MISCDEF::IRIS::GetIndex(qstrTemp.toStdString());
	////
	qstrTemp = m_qsDeviceSettings->value(QString("FS/Port"), "Null").toString();
	if (qstrTemp == "Null")
	{
		qDebug() << "FS Port Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.strInterface = qstrTemp.toStdString();
	////
	qstrTemp = m_qsDeviceSettings->value(QString("FS/UID"), "Null").toString();
	if (qstrTemp == "Null")
	{
		qDebug() << "FS UID Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.strSN = qstrTemp.toStdString();
	////
	float fAEMax = m_qsDeviceSettings->value(QString("FS/AEMax"), -1).toFloat();
	if (fAEMax == -1)
	{
		qDebug() << "FS AEMax Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.fMaxFactor = fAEMax;
	////
	float fAEMin = m_qsDeviceSettings->value(QString("FS/AEMin"), -1).toFloat();
	if (fAEMin == -1)
	{
		qDebug() << "FS AEMin Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.fMinFactor = fAEMin;
	////
	long lDepth = m_qsDeviceSettings->value(QString("FS/Depth"), -1).toInt();
	if (lDepth == -1)
	{
		qDebug() << "FS Depth Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.lDepth = lDepth;
	////
	double dMSI= m_qsDeviceSettings->value(QString("FS/MinSI"), -1).toDouble();
	if (dMSI == -1)
	{
		qDebug() << "FS MinSI Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struOneFSContext.dMinSamplingInterval = dMSI;
	////
	struOFSC = m_struOneFSContext;
	////
	return bRes;
}

bool ZZ_SysConfigger::LoadSettings_GPS(GPSInfo &struGPSC)
{
	bool bRes = true;
	////
	QString qstrTemp = m_qsDeviceSettings->value(QString("GPS/Port"), "Null").toString();
	if (qstrTemp == "Null")
	{
		qDebug() << "GPS Port Value Err.";
		printf("FS Model Value Err.");
		return false;
	}
	m_struGPSContext.qstrInterfaceName = qstrTemp;
	////
    qstrTemp = m_qsDeviceSettings->value(QString("GPS/Baud"), "Null").toString();
	if (qstrTemp == "Null")
	{
		//qDebug() << "GPS Port Value Err.";
		printf("GPS Port Value Err.");
		return false;
	}
	m_struGPSContext.iBaud = qstrTemp.toInt();
	////
	struGPSC = m_struGPSContext;
	////
	return true;
}
