void CBlockEvaluator::SetBleedCount(int N, bool MakeConnects) { if (N!=m_pBleeds.GetSize()) { N=Range(0, N, MaxNdBleeds); for (int a=N; a<m_pBleeds.GetSize(); a++) { m_pNd->DoDirectDisConnect(&m_pBleeds[a]->m_SnkIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); RemBlk(m_pBleeds[a]); delete m_pBleeds[a]; } int NOld=m_pBleeds.GetSize(); m_pBleeds.SetSize(N); for (int a=NOld; a<N; a++) { Strng Tg, Nm; Tg.Set("%s%i", BleedIOTag, a+1); m_pBleeds[a] = new CBleedBase(m_pNd, a, Tg()); m_pBleeds[a]->Open(1); m_pBleeds[a]->SetEnable(true); if (MakeConnects) m_pNd->DoDirectConnect(&m_pBleeds[a]->m_SnkIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); AddBlk(m_pBleeds[a], MaxNdMakeups*2+a); } SortBlocks(); } }
void CBlockEvaluator::SetMakeupCount(int N, bool MakeConnects) { if (N!=m_pMakeups.GetSize()) { N=Range(0, N, m_nMaxNdMakeups); for (int a=N; a<m_pMakeups.GetSize(); a++) { //m_pMakeups[a]->SetEnable(false); m_pNd->DoDirectDisConnect(&m_pMakeups[a]->m_SrcIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); //m_pMakeups[a]->m_SrcIO.ManageNdDirectIOs(false); RemBlk(m_pMakeups[a]); delete m_pMakeups[a]; } int NOld=m_pMakeups.GetSize(); m_pMakeups.SetSize(N); for (int a=NOld; a<N; a++) { Strng Tg, Nm; Tg.Set("%s%i", MakeupIOTag, a+1); m_pMakeups[a] = new CMakeupBase(m_pNd, a, Tg()); m_pMakeups[a]->Open(1); m_pMakeups[a]->SetEnable(true); if (MakeConnects) m_pNd->DoDirectConnect(&m_pMakeups[a]->m_SrcIO);// m_pMakeups[a]->m_SrcIO.DoDisConnect(); AddBlk(m_pMakeups[a], 1+a); } SortBlocks(); } }
FP Flow::Tg(FP NewT) { FP TestT; if(t0 > NewT && NewT > 0.) { TestT = NewT/t0; Lambda = Test(TAUf, TestT); return Tg(); } else { return -1; } }
bool CMOOSSerialPort::CommsLoop() { char pTmp[DEFAULT_COMMS_SPACE]; char pAccumulator[2*DEFAULT_COMMS_SPACE]; int nInStore = 0; double dfTimeOut = 0.1; while(!m_bQuit) { int nRead = ReadNWithTimeOut(pTmp,DEFAULT_COMMS_SPACE,dfTimeOut); if(nRead!=-1) { if((nInStore+nRead)>int(sizeof(pAccumulator))) { //oops... MOOSTrace("Comms Loop Accumulator Overflow, reseting\n"); nInStore = 0; continue; } //append to the accumulator memcpy(pAccumulator+nInStore,pTmp,nRead); //we have more in the cupboard! nInStore+=nRead; //lock m_InBoxLock.Lock(); char * pTelegramEnd = NULL; do { //A device will by default use the termination character <CR> //But we now allow for setting of a termination character //to allow for flexibility in a reply. pTelegramEnd = (char*)memchr(pAccumulator,GetTermCharacter(),nInStore); if(pTelegramEnd!=NULL) { //how long is the telegram? int nTelegramLength = pTelegramEnd - pAccumulator + 1; //make a buffer that is one larger to preserve the last character //in case we are interested in it. char bBiggerBuff[2*DEFAULT_COMMS_SPACE+1]; //copy the telegram to a buffer size that is 1 larger memcpy(bBiggerBuff, pAccumulator, nTelegramLength); //terminate it as a string //*pTelegramEnd = '\0'; bBiggerBuff[nTelegramLength] = '\0'; //copy it //std::string sTelegram((char*)pAccumulator); std::string sTelegram((char*)bBiggerBuff); MOOSRemoveChars(sTelegram,"\r\n"); if(IsVerbose()) { MOOSTrace("Telegram = %s\n",sTelegram.c_str()); } //shuffle accumulator memmove(pAccumulator, pAccumulator+nTelegramLength, sizeof(pAccumulator)-nTelegramLength); //we have less in our store now! nInStore-=nTelegramLength; //make a telegram CMOOSSerialTelegram Tg(sTelegram,MOOSTime()); //stuff it m_InBox.push_front(Tg); } }while(pTelegramEnd !=NULL); //whatch we don't exhibit disgraceful behaviour! while(m_InBox.size()>MOOS_SERIAL_INBOX_MAX_SIZE) { m_InBox.pop_back(); } //and unlock m_InBoxLock.UnLock(); } else { } } return true; }