Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

DC_PUSDataReportingPacket.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // DC_PUSDataReportingPacket.cpp 00005 // 00006 // Version 1.0 00007 // Date 04.11.03 00008 // Author A. Pasetti (P&P Software) 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/Constants.h" 00012 #include "../GeneralInclude/ClassId.h" 00013 #include "../GeneralInclude/DebugSupport.h" 00014 #include "../Base/CC_RootObject.h" 00015 #include "../Data/DataPool.h" 00016 #include "../System/ObsClock.h" 00017 #include "../Telemetry/DC_PUSDataReportingPacket.h" 00018 00019 #include <string.h> 00020 00021 DC_PUSDataReportingPacket::DC_PUSDataReportingPacket(void) { 00022 setClassId(ID_PUSDATAREPORTINGPACKET); 00023 enabled = false; 00024 00025 defBuffer = pNULL; 00026 defBufferSize = 0; 00027 defBufferCounter = 0; 00028 00029 valBuffer = pNULL; 00030 valBufferSize = 0; 00031 00032 indSID = 0; 00033 indCollectionInterval = sizeof(TD_SID); 00034 indNPAR1 = indCollectionInterval+sizeof(TD_PUSCollectionInterval); 00035 indNFA = 0; 00036 00037 F = pNULL; 00038 faDescSize = 0; 00039 FAcounter = 0; 00040 00041 setType(PUS_TYPE_DATA_REP); 00042 } 00043 00044 TD_PUSCollectionInterval DC_PUSDataReportingPacket::getCollectionInterval() { 00045 assert( defBuffer!=pNULL ); 00046 TD_PUSCollectionInterval temp; 00047 memcpy(&temp,defBuffer+indCollectionInterval,sizeof(TD_PUSCollectionInterval)); 00048 return temp; 00049 } 00050 00051 TD_PUSNumberOfParameters DC_PUSDataReportingPacket::getNPAR1() { 00052 assert( defBuffer!=pNULL ); 00053 TD_PUSNumberOfParameters temp; 00054 memcpy(&temp,defBuffer+indNPAR1,sizeof(TD_PUSNumberOfParameters)); 00055 return temp; 00056 } 00057 00058 unsigned char DC_PUSDataReportingPacket::getNFA() { 00059 assert( defBuffer!=pNULL ); 00060 return *(unsigned char*)(defBuffer+indNFA); 00061 } 00062 00063 TD_SID DC_PUSDataReportingPacket::getSID() { 00064 assert( defBuffer!=pNULL ); 00065 TD_SID temp; 00066 memcpy(&temp,defBuffer+indSID,sizeof(TD_SID)); 00067 return temp; 00068 } 00069 00070 void DC_PUSDataReportingPacket::setEnabled(bool enabledStatus) { 00071 enabled = enabledStatus; 00072 } 00073 00074 bool DC_PUSDataReportingPacket::isEnabled() const { 00075 return enabled; 00076 } 00077 00078 void DC_PUSDataReportingPacket::reset() { 00079 assert( F!=pNULL ); 00080 00081 for (unsigned int i=0; i<faDescSize; i++) 00082 if ( F[i].nrep!=0 ) { 00083 F[i].counter = getCollectionInterval()/F[i].nrep; 00084 F[i].rep = 0; 00085 } 00086 00087 setEnabled(DISABLED); 00088 } 00089 00090 void DC_PUSDataReportingPacket::setDefinitionBuffer(unsigned int i, unsigned char val) { 00091 assert( isObjectConfigured() ); 00092 assert( i<defBufferSize ); 00093 00094 if ( (i>=defBufferSize) || (FAcounter>=faDescSize) ) { 00095 getEventRepository()->create(this,EVT_ILLEGAL_PUS_REP_PACKET); 00096 return; 00097 } 00098 00099 defBuffer[i] = val; 00100 defBufferCounter = i; 00101 00102 if ( i<(indNPAR1+sizeof(TD_PUSNumberOfParameters)-1) ) 00103 return; 00104 00105 if ( i==(indNPAR1+sizeof(TD_PUSNumberOfParameters)-1) ) { // process the NPAR1 field 00106 F[0].npar = getNPAR1(); 00107 F[0].nrep = 1; 00108 F[0].counter = getCollectionInterval(); 00109 F[0].rep = 0; 00110 F[0].ind = i+1; 00111 F[0].size = 0; 00112 F[0].val = 0; 00113 FAcounter = 0; 00114 return; 00115 } 00116 00117 assert( i>(indNPAR1+sizeof(TD_PUSNumberOfParameters)-1) ); 00118 assert( i>=F[0].ind ); 00119 00120 unsigned int j = i-F[0].ind; // j=0 when the first byte of the first par is processed 00121 if ( j<getNPAR1()*sizeof(TD_DataPoolId) ) { 00122 if ( ((j+1)%sizeof(TD_DataPoolId))==0 ) { 00123 // process the j-th parameter that is sampled only once per collection interval 00124 TD_DataPoolId id; 00125 memcpy(&id,(defBuffer+i-sizeof(TD_DataPoolId)+1),sizeof(TD_DataPoolId)); 00126 if ( getDataPool()->isFloat(id) ) 00127 F[0].size += sizeof(TD_Float); 00128 else 00129 F[0].size += sizeof(TD_Integer); 00130 } 00131 return; 00132 } 00133 00134 if ( i==(F[0].ind+F[0].npar*sizeof(TD_DataPoolId)) ) { 00135 indNFA = i; 00136 return; 00137 } 00138 00139 assert( i>indNFA ); 00140 00141 if ( i==(indNFA+1) ) { 00142 FAcounter = 1; 00143 F[1].val = F[0].val+F[0].size*F[0].nrep; 00144 F[1].ind = i+1+sizeof(TD_PUSNumberOfParameters); 00145 } else if ( i==(F[FAcounter].ind+F[FAcounter].npar*sizeof(TD_DataPoolId)) ) { 00146 FAcounter++; // process the FAcounter-th FA 00147 assert(FAcounter<faDescSize); 00148 if ( FAcounter>=faDescSize ) { 00149 getEventRepository()->create(this,EVT_ILLEGAL_PUS_REP_PACKET); 00150 return; 00151 } 00152 F[FAcounter].val = F[FAcounter-1].val+F[FAcounter-1].size*F[FAcounter-1].nrep; 00153 F[FAcounter].ind = i+1+sizeof(TD_PUSNumberOfParameters); 00154 } 00155 00156 assert(FAcounter>0); 00157 00158 if ( i==(F[FAcounter].ind-1-sizeof(TD_PUSNumberOfParameters)) ) { // this is the NREP field of the FA 00159 F[FAcounter].nrep = val; 00160 F[FAcounter].rep = 0; 00161 F[FAcounter].counter = getCollectionInterval()/val; 00162 F[FAcounter].size = 0; 00163 return; 00164 } 00165 00166 if ( i<(F[FAcounter].ind-1) ) { 00167 return; 00168 } 00169 00170 if ( i==F[FAcounter].ind-1 ) { // this is end of the NPAR2 field of the FA 00171 memcpy(&F[FAcounter].npar,(defBuffer+i-sizeof(TD_PUSNumberOfParameters)+1),sizeof(TD_PUSNumberOfParameters)); 00172 return; 00173 } 00174 00175 j = i-F[FAcounter].ind; // j=0 when the first byte of the first par in the FA is processed 00176 if ( j<F[FAcounter].npar*sizeof(TD_DataPoolId) ) { 00177 if ( ((j+1)%sizeof(TD_DataPoolId))==0 ) { 00178 // process the j-th parameter of the FAcounter-th fixed-length array 00179 TD_DataPoolId id; 00180 memcpy(&id,(defBuffer+i-sizeof(TD_DataPoolId)+1),sizeof(TD_DataPoolId)); 00181 if ( getDataPool()->isFloat(id) ) 00182 F[FAcounter].size += sizeof(TD_Float); 00183 else 00184 F[FAcounter].size += sizeof(TD_Integer); 00185 } 00186 return; 00187 } 00188 00189 assert(false); 00190 } 00191 00192 unsigned int DC_PUSDataReportingPacket::getDefinitionBufferLength(void) { 00193 assert( defBuffer!=pNULL ); 00194 return (defBufferCounter+1); 00195 } 00196 00197 unsigned char DC_PUSDataReportingPacket::getDefinitionBuffer(unsigned int i) { 00198 assert( i<defBufferCounter ); 00199 return defBuffer[i]; 00200 } 00201 00202 TD_DataPoolId DC_PUSDataReportingPacket::getParameterId(unsigned int faIndex, unsigned int parPos) { 00203 assert( faIndex<=FAcounter ); 00204 assert( parPos<F[faIndex].npar ); 00205 00206 TD_DataPoolId temp; 00207 memcpy(&temp,(defBuffer+F[faIndex].ind+parPos*sizeof(TD_DataPoolId)),sizeof(TD_DataPoolId)); 00208 00209 return temp; 00210 } 00211 00212 void DC_PUSDataReportingPacket::update() { 00213 assert( isObjectConfigured() ); 00214 assert( (getSubType()==PUS_ST_DATA_REP_PAR_HK_REP) || 00215 (getSubType()==PUS_ST_DATA_REP_PAR_DG_REP) ); 00216 00217 if ( !isEnabled() ) 00218 return; 00219 00220 setTimeTag(getObsClock()->getTime()); 00221 00222 // Copy SID in the first locations of the packet value buffer 00223 for (unsigned int i=0; i<sizeof(TD_SID); i++) 00224 valBuffer[i]=defBuffer[i]; 00225 00226 // Write mode field into packet value buffer 00227 bool dummy = PUS_DATA_REP_MODE; // use of dummy avoids compiler warning due to PUS_DATA_REP_MODE being a constant 00228 if ( dummy ) 00229 valBuffer[sizeof(TD_SID)]=0; 00230 00231 // Compute initial offset in the packet value buffer (the first parameter value 00232 // is written at location valBufferInitialOffset) 00233 unsigned short valBufferInitialOffset = sizeof(TD_SID)+(PUS_DATA_REP_MODE?1:0); 00234 00235 for (unsigned short i=0; i<=FAcounter; i++) { 00236 00237 if ( F[i].counter==0 ) 00238 F[i].counter = getCollectionInterval()/F[i].nrep; 00239 00240 F[i].counter--; 00241 00242 if ( F[i].counter==0 ) { 00243 unsigned int pos = valBufferInitialOffset+F[i].val+F[i].rep*F[i].size; 00244 if ( (pos+(F[i].rep+1)*F[i].size)>=valBufferSize ) { // check if next frame fits in value buffer 00245 getEventRepository()->create(this,EVT_PUS_DATA_REP_PACKET_TOO_LARGE); 00246 break; 00247 } 00248 for (unsigned char j=0; j<F[i].npar; j++) { 00249 TD_DataPoolId id = getParameterId(i,j); 00250 if ( getDataPool()->isFloat(id) ) { 00251 TD_Float flTemp = getDataPool()->getFloatValue(id); 00252 memcpy(valBuffer+pos,&flTemp,sizeof(TD_Float)); 00253 assert( pos<valBufferSize ); 00254 pos += sizeof(TD_Float); 00255 } else { 00256 TD_Integer intTemp = getDataPool()->getIntegerValue(id); 00257 memcpy(valBuffer+pos,&intTemp,sizeof(TD_Integer)); 00258 assert( pos<valBufferSize ); 00259 pos += sizeof(TD_Integer); 00260 } 00261 } 00262 00263 F[i].rep++; 00264 00265 if ( F[i].rep==F[i].nrep ) 00266 F[i].rep=0; 00267 } 00268 } 00269 } 00270 00271 unsigned int DC_PUSDataReportingPacket::getNumberOfBytes (void) { 00272 assert( isObjectConfigured() ); 00273 assert( (getSubType()==PUS_ST_DATA_REP_PAR_HK_REP) || 00274 (getSubType()==PUS_ST_DATA_REP_PAR_HK_REP) ); 00275 00276 if ( !isEnabled() ) 00277 return 0; 00278 00279 if ( F[0].counter!=0 ) 00280 return 0; 00281 00282 return (sizeof(TD_SID)+(PUS_DATA_REP_MODE?1:0)+F[FAcounter].val+ 00283 F[FAcounter].size*F[FAcounter].nrep); 00284 } 00285 00286 unsigned char DC_PUSDataReportingPacket::getUnsignedByte(unsigned int n) { 00287 assert( isObjectConfigured() ); 00288 assert( (getSubType()==PUS_ST_DATA_REP_PAR_HK_REP) || 00289 (getSubType()==PUS_ST_DATA_REP_PAR_HK_REP) ); 00290 assert( n<valBufferSize ); 00291 00292 return valBuffer[n]; 00293 } 00294 00295 unsigned char* DC_PUSDataReportingPacket::getStartAddress(void) { 00296 assert( valBuffer!=pNULL ); 00297 return valBuffer; 00298 } 00299 00300 bool DC_PUSDataReportingPacket::isFastAcquisitionImplemented(void) { 00301 return true; 00302 } 00303 00304 void DC_PUSDataReportingPacket::setDefinitionBufferSize(unsigned int size) { 00305 assert( size>0 ); 00306 assert( defBuffer==pNULL ); // should only be called once 00307 00308 defBufferSize = size; 00309 defBuffer = new unsigned char[defBufferSize]; 00310 for (unsigned short i=0; i<defBufferSize; i++) 00311 defBuffer[i] = 0; 00312 } 00313 00314 unsigned int DC_PUSDataReportingPacket::getDefinitionBufferSize() { 00315 return defBufferSize; 00316 } 00317 00318 void DC_PUSDataReportingPacket::setValueBufferSize(unsigned int size) { 00319 assert( size>0 ); 00320 assert( valBuffer==pNULL ); // should only be called once 00321 00322 valBufferSize = size; 00323 valBuffer = new unsigned char[valBufferSize]; 00324 for (unsigned int i=0; i<valBufferSize; i++) 00325 valBuffer[i] = 0; 00326 } 00327 00328 unsigned int DC_PUSDataReportingPacket::getValueBufferSize() { 00329 return valBufferSize; 00330 } 00331 00332 void DC_PUSDataReportingPacket::setMaxNumberFA(unsigned int n) { 00333 assert( F==pNULL ); // should only be called once 00334 00335 // recall F[0] is used to store information about parameters sampled once per collection interval 00336 faDescSize = (unsigned char)(n+1); 00337 F = new FaDescType[faDescSize]; 00338 for (unsigned char i=0; i<faDescSize; i++) { 00339 F[i].counter = 0; 00340 F[i].ind = 0; 00341 F[i].npar = 0; 00342 F[i].nrep = 0; 00343 F[i].rep = 0; 00344 F[i].size = 0; 00345 F[i].val = 0; 00346 } 00347 } 00348 00349 unsigned int DC_PUSDataReportingPacket::getMaxNumberFA() { 00350 assert( faDescSize>0 ); 00351 return (faDescSize-1); 00352 } 00353 00354 bool DC_PUSDataReportingPacket::isObjectConfigured(void) { 00355 return (PUSTelemetryPacket::isObjectConfigured() && F!=pNULL && 00356 valBuffer!=pNULL && defBuffer!=pNULL); 00357 }
Copyright 2003 P&P Software GmbH - All Rights Reserved