00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // CC_TelecommandManager.cpp 00005 // 00006 // Version 1.0 00007 // Date 4.12.02 (Version 1.0) 00008 // Author A. Pasetti (P&P Software) 00009 // 00010 // Change Record: 00011 00012 #include "../GeneralInclude/CompilerSwitches.h" 00013 #include "../GeneralInclude/DebugSupport.h" 00014 #include "../GeneralInclude/Constants.h" 00015 #include "../GeneralInclude/ClassId.h" 00016 #include "../Base/CC_RootObject.h" 00017 #include "../System/ObsClock.h" 00018 #include "CC_TelecommandManager.h" 00019 #include "TelecommandLoader.h" 00020 00021 CC_TelecommandManager::CC_TelecommandManager(void) { 00022 pTcList =pNULL; 00023 tcListSize=0; 00024 pTcLoader =pNULL; 00025 tcCounter =0; 00026 setClassId(ID_TELECOMMANDMANAGER); 00027 } 00028 00029 void CC_TelecommandManager::reset(void) { 00030 assert(pTcList!=pNULL); 00031 00032 for (unsigned int i=0; i<tcListSize; i++) { 00033 if (pTcList[i]!=pNULL) { 00034 CC_RootObject::getEventRepository()->create(pTcList[i],EVT_TC_ABORTED); 00035 pTcLoader->release(pTcList[i]); 00036 pTcList[i]=pNULL; 00037 } 00038 } 00039 00040 tcCounter=0; 00041 } 00042 00043 void CC_TelecommandManager::setPendingTelecommandListSize(unsigned int listSize) { 00044 assert(tcListSize==0); // should not be called more than once 00045 assert(listSize>0); 00046 00047 tcListSize=listSize; 00048 pTcList=new Telecommand*[tcListSize]; 00049 00050 for (unsigned int i=0;i<tcListSize;i++) 00051 pTcList[i]=pNULL; 00052 } 00053 00054 unsigned int CC_TelecommandManager::getPendingTelecommandListSize(void) { 00055 assert(tcListSize>0); 00056 00057 return tcListSize; 00058 } 00059 00060 void CC_TelecommandManager::load(Telecommand *pTelecommand) { 00061 assert (isObjectConfigured()); 00062 assert (pTelecommand!=pNULL); 00063 00064 if (!pTelecommand->isValid()) { 00065 CC_RootObject::getEventRepository()->create(pTelecommand,EVT_TC_NOT_VALID); 00066 pTcLoader->release(pTelecommand); 00067 return; 00068 } 00069 00070 // Check whether list of pending telecommands is full 00071 if (tcCounter==tcListSize) { 00072 CC_RootObject::getEventRepository()->create(pTelecommand,EVT_TC_LIST_FULL); 00073 pTcLoader->release(pTelecommand); 00074 return; 00075 } 00076 00077 // Try to insert telecommand in the list of pending telecommands 00078 for (unsigned int i=0;i<tcListSize;i++) { 00079 if (!pTcList[i]) { 00080 pTcList[i]=pTelecommand; 00081 CC_RootObject::getEventRepository()->create(pTelecommand,EVT_TC_LOADED); 00082 tcCounter++; 00083 return; 00084 } 00085 } 00086 00087 assert(false); // this should never be reached 00088 } 00089 00090 unsigned int CC_TelecommandManager::getPendingTelecommands(void) { 00091 assert(isObjectConfigured()); 00092 00093 return tcCounter; 00094 } 00095 00096 Telecommand* CC_TelecommandManager::getPendingTelecommand(unsigned int i) { 00097 assert(isObjectConfigured()); 00098 assert(i<tcListSize); 00099 00100 return pTcList[i]; 00101 } 00102 00103 void CC_TelecommandManager::abort(Telecommand *pTelecommand) { 00104 assert(isObjectConfigured() && (pTelecommand!=pNULL)); 00105 00106 for (unsigned int i=0;i<tcListSize;i++) { 00107 if (pTcList[i]==pTelecommand) { 00108 CC_RootObject::getEventRepository()->create(pTelecommand,EVT_TC_ABORTED); 00109 pTcLoader->release(pTcList[i]); 00110 pTcList[i]=pNULL; 00111 tcCounter--; 00112 return; 00113 } 00114 } 00115 } 00116 00117 void CC_TelecommandManager::abort(TD_TelecommandId telecomandId) { 00118 assert(isObjectConfigured() && telecomandId>0); 00119 00120 for (unsigned int i=0;i<tcListSize;i++) { 00121 if (pTcList[i]->getTelecommandId()==telecomandId) { 00122 CC_RootObject::getEventRepository()->create(pTcList[i],EVT_TC_ABORTED); 00123 pTcLoader->release(pTcList[i]); 00124 pTcList[i]=pNULL; 00125 tcCounter--; 00126 } 00127 } 00128 } 00129 00130 void CC_TelecommandManager::setTelecommandLoader(TelecommandLoader *pTcLoader) { 00131 assert(pTcLoader!=pNULL); 00132 00133 this->pTcLoader=pTcLoader; 00134 } 00135 00136 TelecommandLoader *CC_TelecommandManager::getTelecommandLoader(void) { 00137 assert(pTcLoader!=pNULL); 00138 00139 return pTcLoader; 00140 } 00141 00142 void CC_TelecommandManager::setObsClock(ObsClock *pObsClock) { 00143 assert(pObsClock!=pNULL); 00144 00145 this->pObsClock=pObsClock; 00146 } 00147 00148 ObsClock *CC_TelecommandManager::getObsClock(void) { 00149 assert(pObsClock!=pNULL); 00150 00151 return pObsClock; 00152 } 00153 00154 void CC_TelecommandManager::activate(void) { 00155 assert(isObjectConfigured()); 00156 TD_ActionOutcome tcOutcome; 00157 00158 for (unsigned int i=0;i<tcListSize;i++) { 00159 if (pTcList[i]!=pNULL && pTcList[i]->getTimeTag()<=pObsClock->getTime()) { 00160 if (pTcList[i]->canExecute()) { 00161 tcOutcome = pTcList[i]->execute(); 00162 if (tcOutcome != ACTION_SUCCESS) 00163 CC_RootObject::getEventRepository()->create(pTcList[i],EVT_TC_EXEC_FAIL); 00164 else 00165 CC_RootObject::getEventRepository()->create(pTcList[i],EVT_TC_EXEC_SUCC); 00166 } else 00167 CC_RootObject::getEventRepository()->create(pTcList[i],EVT_TC_EXEC_CHECK_FAIL); 00168 00169 pTcLoader->release(pTcList[i]); 00170 pTcList[i]=pNULL; 00171 tcCounter--; 00172 } 00173 } 00174 } 00175 00176 bool CC_TelecommandManager::isObjectConfigured(void) { 00177 return (CC_RootObject::isObjectConfigured() && 00178 pTcLoader!=pNULL && pObsClock!=pNULL && tcListSize!=pNULL); 00179 }