#include "StdAfx.h" #include ".\scafn.h" #include "IniUtil.h" CScaFn::CScaFn(void) { SCA_SECTION = "DP5 SCA Configuration"; CFG_SECTION = "DP5 Configuration File"; } CScaFn::~CScaFn(void) { } BOOL CScaFn::SplitData(CString strData, CString *varValue, CString strDefault) { long lSep; CString strChan; BOOL bSplitData; bSplitData = FALSE; lSep = strData.Find(";"); if (lSep > 0) { //file has setting, separate comments from data, if any *varValue = strData.Left(lSep - 1).Trim(); bSplitData = TRUE; } else { *varValue = strDefault; bSplitData = FALSE; } return bSplitData; } long CScaFn::varValueToIndex(CString strData) { CString strCase; long lValueToIndex; strCase = strData.MakeUpper(); if (strCase == "OFF") { lValueToIndex = 0; } else if (strCase == "HI") { lValueToIndex = 1; } else if (strCase == "LOW") { lValueToIndex = 2; } else if (strCase == "256") { lValueToIndex = 0; } else if (strCase == "512") { lValueToIndex = 1; } else if (strCase == "1024") { lValueToIndex = 2; } else if (strCase == "2048") { lValueToIndex = 3; } else if (strCase == "4096") { lValueToIndex = 4; } else if (strCase == "8192") { lValueToIndex = 5; } else if (strCase == "100") { lValueToIndex = 0; } else if (strCase == "1000") { lValueToIndex = 1; } else if (strCase == "1") { lValueToIndex = 0; } else if (strCase == "2") { lValueToIndex = 1; } else if (strCase == "3") { lValueToIndex = 2; } else if (strCase == "4") { lValueToIndex = 3; } else if (strCase == "5") { lValueToIndex = 4; } else if (strCase == "6") { lValueToIndex = 5; } else if (strCase == "7") { lValueToIndex = 6; } else if (strCase == "8") { lValueToIndex = 7; } else if (strCase == "HIGH") { lValueToIndex = 1; } else if (strCase == "HIG") { lValueToIndex = 1; } else if (strCase == "LO") { lValueToIndex = 2; } else { lValueToIndex = 0; } return lValueToIndex; } //these must be in the correct order, old sca settings will be deleted and new appended to end void CScaFn::SaveSCASetupINI(CSca sca) { CString strData; long Index; Index = atol(sca.CurIndex); DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAI"); DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAO"); DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAL"); DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAH"); DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAW"); strData = sca.PulseWidth; // + ";"; SaveToIniEx(sca.strIniFilename, CFG_SECTION, "SCAW", strData); } void CScaFn::DeleteIniSettingEx(CString strFilename, CString strSection, CString strKey) { CIniUtil ciu; ciu.DeleteDP5Key(strFilename,strSection,strKey); } void CScaFn::SaveToIniEx(CString strFilename, CString strSection, CString strKey, CString strData) { CIniUtil ciu; CString csCmts; csCmts = ""; ciu.SaveDP5Data(strFilename,strSection,strKey,strData,csCmts); } void CScaFn::SaveSCASettingsINI(CSca sca, long Index) { CString strIdx; CString strData; strIdx.Format("%d",Index); strData = sca.Output[Index - 1]; // + ";"; SaveToIniEx(sca.strIniFilename, SCA_SECTION, "SCAO" + strIdx, strData); strData = sca.Low[Index - 1]; // + ";"; SaveToIniEx(sca.strIniFilename, SCA_SECTION, "SCAL" + strIdx, strData); strData = sca.High[Index - 1]; // + ";"; SaveToIniEx(sca.strIniFilename, SCA_SECTION, "SCAH" + strIdx, strData); } void CScaFn::GetSCASetupINI(CSca *sca) { CString strValue; CString strComment; CString strData; long lIndex; strData = GetFromIniEx(sca->strIniFilename, CFG_SECTION, "SCAW", "100"); sca->PulseWidth = strData; strData = GetFromIniEx(sca->strIniFilename, CFG_SECTION, "SCAI", "1"); sca->CurIndex = strData; sca->HaveCurIndex = (BOOL)(strData.GetLength() > 0); if (sca->HaveCurIndex) { //update sca from latest config data lIndex = atol(sca->CurIndex); strData = GetFromIniEx(sca->strIniFilename, CFG_SECTION, "SCAO", "OFF"); sca->Output[lIndex - 1] = strData; strData = GetFromIniEx(sca->strIniFilename, CFG_SECTION, "SCAL", "0"); sca->Low[lIndex - 1] = strData; strData = GetFromIniEx(sca->strIniFilename, CFG_SECTION, "SCAH", "1023"); sca->High[lIndex - 1] = strData; } } CString CScaFn::GetFromIniEx(CString strFilename, CString strSection, CString strKey, CString strDefault) { CString strData; CIniUtil ciu; CString csData; CString csCmts; if (ciu.GetDP5Data(strFilename,strSection,strKey,&csData,&csCmts)) { strData = csData; } else { strData = strDefault; } return strData; } void CScaFn::GetSCASettingsINI(CSca *sca, long lIndexIn) { CString strValue; CString strComment; CString strIdx; CString strData; long lIndex; strIdx.Format("%d",lIndexIn); sca->Index[lIndexIn - 1] = strIdx; //for future use lIndex = atol(sca->CurIndex); //skip updating data that was updated from the configuration settings //if (sca->HaveCurIndex && (lIndex == Index)) { return; } strData = GetFromIniEx(sca->strIniFilename, SCA_SECTION, "SCAO" + strIdx, "OFF"); sca->Output[lIndexIn - 1] = strData; strData = GetFromIniEx(sca->strIniFilename, SCA_SECTION, "SCAL" + strIdx, "0"); sca->Low[lIndexIn - 1] = strData; strData = GetFromIniEx(sca->strIniFilename, SCA_SECTION, "SCAH" + strIdx, "1023"); sca->High[lIndexIn - 1] = strData; } // 1234567 //expecting data format strCMD=strData; (CMD1=?;) void CScaFn::ReadSCASetting(CSca *sca, CString strSCAInfo) { CString strCmd; CString strData; long lSep; long lTerm; long lIndex; lIndex = atol(sca->CurIndex); lSep = strSCAInfo.Find("="); lTerm = strSCAInfo.Find(";"); if (lSep != 4) { return; } if (lTerm < 6) { return; } strCmd = strSCAInfo.Left(4).MakeUpper(); strData = strSCAInfo.Mid(5, lTerm - 5).MakeUpper(); if (strCmd == "SCAW") { sca->PulseWidth = strData; } else if (strCmd == "SCAI") { sca->CurIndex = strData; sca->HaveCurIndex = TRUE; lIndex = atol(sca->CurIndex); sca->Index[lIndex - 1] = strData; } else if (strCmd == "SCAL") { if (lIndex > 0) { sca->Low[lIndex - 1] = strData; } } else if (strCmd == "SCAH") { if (lIndex > 0) { sca->High[lIndex - 1] = strData; } } else if (strCmd == "SCAO") { if (lIndex > 0) { sca->Output[lIndex - 1] = strData; } } else { //unknown data error } } //reads dpp command string removes and returns byref next dpp config command //functions returns true if command found, false otherwise CString CScaFn::GetNextCMD(CString strCMDList) { CString strCmd; long lNextCmd; strCmd = ""; if (strCMDList.GetLength() < 7) { return strCmd; } //1234=6;8 lNextCmd = strCMDList.Find(";"); if (lNextCmd < 6) { return strCmd; } //0123=5;7 strCmd = strCMDList.Left(lNextCmd+1).MakeUpper(); return strCmd; } void CScaFn::SCACfgParser(CSca *sca, CString strSCASettings) { CString strCMDList; CString strCmd; long idxCMDs; long CMDMax; long lCmdLen; if (strSCASettings.GetLength() < 7) { return; } strCMDList = strSCASettings; strCmd = ""; CMDMax = strSCASettings.GetLength(); CMDMax /= 7; CMDMax++; //loop the max number of times for (idxCMDs=0;idxCMDs<=CMDMax;idxCMDs++) { strCmd = GetNextCMD(strCMDList); lCmdLen = strCmd.GetLength(); if (lCmdLen > 0) { ReadSCASetting(sca, strCmd); strCMDList = strCMDList.Mid(lCmdLen); } else { break; } } } CString CScaFn::SCAString(CString strCmd, CString strData, BOOL bDppMsg) { CString str; str = strCmd.MakeUpper(); str = str + "="; str = str + strData.MakeUpper() + ";"; if (! bDppMsg) { str = str + "\r\n"; } return str; } //these must be in the correct order, old sca settings will be delected and new appended to end CString CScaFn::SCASetupString(CSca sca, BOOL bDppMsg) { CString strData; CString strSCAsus; CString str; strSCAsus = ""; strData = sca.PulseWidth; str = SCAString("SCAW", strData, bDppMsg); strSCAsus = strSCAsus + str; return strSCAsus; } CString CScaFn::SCASettingsString(CSca sca, long Index, BOOL bDppMsg) { CString strIdx; CString strData; CString strSCAsets; CString str; strIdx.Format("%d",Index); strData = sca.Index[Index]; str = SCAString("SCAI", strData, bDppMsg); strSCAsets = strSCAsets + str; strData = sca.Output[Index]; str = SCAString("SCAO", strData, bDppMsg); strSCAsets = strSCAsets + str; strData = sca.Low[Index]; str = SCAString("SCAL", strData, bDppMsg); strSCAsets = strSCAsets + str; strData = sca.High[Index]; str = SCAString("SCAH", strData, bDppMsg); strSCAsets = strSCAsets + str; return strSCAsets; } CString CScaFn::SCAStringALL(CSca sca, BOOL bDppMsg) { long idxSCA; CString strSCA; CString strSetting; strSCA = SCASetupString(sca, bDppMsg); for (idxSCA=0;idxSCAstrIniFilename = ""; strHigh.Format("%d", lChannels - 1); sca->CurIndex = "1"; sca->PulseWidth = "100"; for (idxSCA=0;idxSCAIndex[idxSCA] = strIndex; if (bTest) { sca->Low[idxSCA].Format("%d", ((idxSCA+1) * 1)); sca->High[idxSCA].Format("%d", ((idxSCA+1) * 100)); } else { sca->Low[idxSCA] = "0"; sca->High[idxSCA] = strHigh; } if (idxSCA < 8) { sca->Output[idxSCA] = "OFF"; } } }