/******************************************************************************* * TmsLib.h TMS Client library functions * T.Barnaby, BEAM Ltd, 2007-03-14 ******************************************************************************* */ #include #include #include #include #include #include namespace Tms { TmsCycleParams::TmsCycleParams(BString baseDir){ obaseDir = baseDir; } BError TmsCycleParams::getCycleTypes(BList& typeList){ BError err; BDir dir; BIter i; BString n; BEntryFile f; typeList.clear(); if(err = dir.open(obaseDir)){ return err; } dir.setWild("*_0.spt"); dir.setSort(1); for(dir.start(i); !dir.isEnd(i); dir.next(i)){ if(!f.open(obaseDir + "/" + dir.entryName(i))){ f.read(); n = f.findValue("cycleType:"); typeList.append(n); } } return err; } BError TmsCycleParams::getFileNames(BList& fileList){ BError err; BDir dir; BIter i; fileList.clear(); if(err = dir.open(obaseDir)){ return err; } dir.setWild("*.spt"); dir.setSort(1); for(dir.start(i); !dir.isEnd(i); dir.next(i)){ fileList.append(dir.entryName(i)); } return err; } BError TmsCycleParams::getCycleParams(BString fileName, Tms::CycleParam& param){ BError err; BIter i; BString pathName; BEntryFile file; int n; UInt32 p; BString str; BList strList; pathName = obaseDir + "/" + fileName; if(err = file.open(pathName)){ err.set(err.getErrorNo(), BString("Unable to open file: ") + pathName); return err; } if(err = file.read()){ err.set(err.getErrorNo(), BString("Unable to read file: ") + pathName); return err; } param.cycleType = file.findValue("cycleType:"); param.info = file.findValue("info:"); param.channel = file.findValue("channel:").retInt(); param.pllInitialFrequency = file.findValue("pllInitialFrequency:").retInt(); param.pllInitialFrequencyDelay = file.findValue("pllInitialFrequencyDelay:").retInt(); param.pllFrefGain = file.findValue("pllFrefGain:").retInt(); param.pllGain = file.findValue("pllGain:").retInt(); param.pllDdsMinimum = file.findValue("pllDdsMinimum:").retInt(); param.pllDdsMaximum = file.findValue("pllDdsMaximum:").retInt(); param.frefPhaseDelay.resize(40); for(n = 0; n < 40; n++){ param.frefPhaseDelay[n] = file.findValue(BString("frefPhaseDelay") + n + ":").retInt(); } param.stateTable.resize(0); for(n = 0; n < 14; n++){ if(!file.find(BString("stateTable") + n + ".state:")) break; param.stateTable.resize(n + 1); param.stateTable[n].state = file.findValue(BString("stateTable") + n + ".state:").retInt(); param.stateTable[n].numBunches = file.findValue(BString("stateTable") + n + ".numBunches:").retInt(); str = file.findValue(BString("stateTable") + n + ".phaseTable:"); strList = str.getTokenList(","); param.stateTable[n].phaseTable.resize(tmsPhaseTableSize); for(p = 0, strList.start(i); (p < tmsPhaseTableSize) && (p < strList.number()); p++, strList.next(i)){ param.stateTable[n].phaseTable[p] = strList[i].retInt(); } } return err; } BError TmsCycleParams::setCycleParams(Tms::CycleParam param){ BError err; unsigned int n; unsigned int p; BString s; BFile file; BString fileName; fileName = obaseDir + "/" + param.cycleType + "_" + param.channel + ".spt"; if(err = file.open(fileName, "w")){ err.set(err.getErrorNo(), BString("Unable to open file: ") + fileName); return err; } file.printf("cycle_type: %s\n", param.cycleType.retStr()); file.printf("info: %s\n", param.info.retStr()); file.printf("channel: %u\n", param.channel); file.printf("pllInitialFrequency: %u\n", param.pllInitialFrequency); file.printf("pllInitialFrequencyDelay: %u\n", param.pllInitialFrequencyDelay); file.printf("pllFrefGain: %u\n", param.pllFrefGain); file.printf("pllGain: %u\n", param.pllGain); file.printf("pllDdsMinimum: %u\n", param.pllDdsMinimum); file.printf("pllDdsMaximum: %u\n", param.pllDdsMaximum); for(n = 0; n < param.frefPhaseDelay.size(); n++){ file.printf("frefPhaseDelay%d: %u\n", n, param.frefPhaseDelay[n]); } for(n = 0; n < param.stateTable.size(); n++){ file.printf("stateTable%d.state: 0x%x\n", n, param.stateTable[n].state); file.printf("stateTable%d.numBunches: %u\n", n, param.stateTable[n].numBunches); for(p = 0; p < param.stateTable[n].phaseTable.size(); p++){ file.printf("stateTable%d.phaseTable%d: 0x%x\n", n, p, param.stateTable[n].phaseTable[p]); } } file.close(); return err; } BError TmsCycleParams::deleteCycleParams(BString cycleType, UInt32 puChannel){ BError err; BDir dir; BIter i; BString n; BEntryFile f; BString pn; if(err = dir.open(obaseDir)){ return err; } if(puChannel) dir.setWild(BString("*_") + puChannel + ".spt"); else dir.setWild("*_*.spt"); for(dir.start(i); !dir.isEnd(i); dir.next(i)){ pn = obaseDir + "/" + dir.entryName(i); printf("Test: %s\n", pn.retStr()); if(!f.open(pn)){ f.read(); n = f.findValue("cycleType:"); if(n == cycleType){ unlink(pn); } } } #ifdef ZAP err.set(ErrorNotImplemented, "Not Implemented"); #endif return err; } }