}
stateTable.resize(0);
for(n = 0; n < 14; n++){
if(!eList.find(BString("stateTable") + n + ".state:"))
break;
stateTable.resize(n + 1);
stateTable[n].period = eList.findValue(BString("stateTable") + n + ".period:").retInt();
stateTable[n].state = eList.findValue(BString("stateTable") + n + ".state:").retUInt();
stateTable[n].harmonic = eList.findValue(BString("stateTable") + n + ".harmonic:").retInt();
stateTable[n].numBunches = eList.findValue(BString("stateTable") + n + ".numBunches:").retInt();
stateTable[n].bunchMask = eList.findValue(BString("stateTable") + n + ".bunchMask:").retInt();
str = eList.findValue(BString("stateTable") + n + ".phaseTable:");
strList = str.getTokenList(",");
stateTable[n].phaseTable.resize(tmsPhaseTableSize);
for(p = 0, strList.start(i); (p < tmsPhaseTableSize) && (p < strList.number()); p++, strList.next(i)){
stateTable[n].phaseTable[p] = strList[i].retInt();
}
}
return err;
}
BError CycleParamEdit::readFromFile(BString fileName){
BError err;
BFile file;
BString s;
BString str;
if(err = file.open(fileName, "r")){
err.set(err.getErrorNo(), BString("Unable to open file: ") + fileName);
return err;
}
while(file.readString(s) > 0){
str += s;
}
return setString(str);
}
BError CycleParamEdit::writeToFile(BString fileName){
BError err;
BFile file;
if(err = file.open(fileName, "w")){
err.set(err.getErrorNo(), BString("Unable to open file: ") + fileName);
return err;
}
if(file.writeString(getString()) < 0)
err.set(-errno, strerror(errno));;
file.close();
return err;
}
}
#if TESTBUILD
using namespace Tms;
int main(){
CycleParamState st;
CycleParamEdit cp;
CycleParamEdit cpnew;
BList<CycleParamState> cpl;
unsigned int i;
int s;
TmsPhase pt;
BIter ii;
BString str;
cp.getDefaultState(st);
st.loHarmonic = 8;
st.loPhase = 0.0;
st.bunchMask = 0x3C;
st.mean1Mask = 0x3C;
cpl.append(st);
st.loHarmonic = 8;
st.loPhase = 0.0;
st.bunchMask = 0x3C;
st.mean1Mask = 0x3C;
cpl.append(st);
st.loHarmonic = 16;
st.loPhase = 0.0;
st.bunchMask = 0x3C;
st.mean1Mask = 0x3C;
cpl.append(st);
printf("String: %s\n", st.getString().retStr());
CycleParamState st1;
st1.setString(st.getString());
printf("String: %s\n", st1.getString().retStr());
cp.setStates(cpl);
printf("\nDisplay Settings\n");
cp.getStates(cpl);
for(cpl.start(ii); !cpl.isEnd(ii); cpl.next(ii)){
printf("Settings: %s\n", cpl[ii].getString().retStr());
}
printf("Test getString/setString functions\n");
str = cp.getString();
cpnew.setString(str);
str = cpnew.getString();
printf("%s\n", str.retStr());
printf("Write to file\n");
for(i = 0; i < cp.stateTable.size(); i++){
BFile f(BString("phaseTable") + i + ".txt", "w");
printf("State: %d: %x\n", i, cp.stateTable[i].state);
for(s = 0; s < 512; s++){
#ifndef __Lynx__
pt.value = cp.stateTable[i].phaseTable[s];
#else
pt.value() = cp.stateTable[i].phaseTable[s];
#endif
f.printf("%d ", pt.lo1);
f.printf("%d ", pt.lo2);
f.printf("%d ", pt.gate);
f.printf("%d ", pt.blr);
f.printf("%d ", pt.meanFilter1);
f.printf("%d\n", pt.meanFilter2);
}
}
return 0;
}
#endif