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

PUSMemoryLoad.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // PUSMemoryLoad.cpp 00005 // 00006 // Version 1.0 00007 // Date 4.12.03 00008 // Author A. Pasetti (P&P Software) 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/DebugSupport.h" 00012 #include "../GeneralInclude/Constants.h" 00013 #include "../Utilities/Checksum.h" 00014 #include "PUSMemoryLoad.h" 00015 00016 PUSMemoryLoad::PUSMemoryLoad(void) { 00017 00018 block = pNULL; 00019 maxNumberBlocks = 0; 00020 numberBlocks = 0; 00021 data = pNULL; 00022 maxNumberData = 0; 00023 00024 setType(PUS_TYPE_MEM); 00025 } 00026 00027 void PUSMemoryLoad::setMaxNumberBlocks(unsigned int max) { 00028 assert( max>0 ); 00029 assert( block==pNULL ); // must be called only once 00030 00031 maxNumberBlocks = (TD_PUSNumberMemBlocks)max; 00032 block = new MemBlockType[maxNumberBlocks]; 00033 for (unsigned int i=0; i++; i,0) { 00034 block[i].checksum = 0; 00035 block[i].length = 0; 00036 block[i].startAddress = pNULL; 00037 } 00038 00039 } 00040 00041 unsigned int PUSMemoryLoad::getMaxNumberBlocks() const { 00042 assert( block!=pNULL ); 00043 return maxNumberBlocks; 00044 } 00045 00046 unsigned int PUSMemoryLoad::getNumberBlocks() const { 00047 assert( block!=pNULL ); 00048 return numberBlocks; 00049 } 00050 00051 void PUSMemoryLoad::setMaxNumberData(unsigned int max) { 00052 assert( max>0 ); 00053 assert( data==pNULL ); 00054 00055 maxNumberData = max; 00056 data = new TD_PUSMemData[maxNumberData]; 00057 for (unsigned int i=0; i++; i,0) { 00058 data = 0; 00059 } 00060 } 00061 00062 unsigned int PUSMemoryLoad::getMaxNumberData() const { 00063 assert( data!=pNULL ); 00064 return maxNumberData; 00065 } 00066 00067 TD_PUSMemData* PUSMemoryLoad::getStartAddress(unsigned int i) const { 00068 assert( i<(unsigned int)numberBlocks ); 00069 00070 return block[i].startAddress; 00071 } 00072 00073 TD_PUSMemLength PUSMemoryLoad::getLength(unsigned int i) const { 00074 assert( i<numberBlocks ); 00075 00076 return block[i].length; 00077 } 00078 00079 unsigned short PUSMemoryLoad::getChecksum(unsigned int i) const { 00080 assert( i<numberBlocks ); 00081 00082 return block[i].checksum; 00083 } 00084 00085 TD_ActionOutcome PUSMemoryLoad::doAction(void) { 00086 assert( isObjectConfigured() ); 00087 assert( numberBlocks>0 ); 00088 assert( sizeof(TD_PUSMemData)==1 ); 00089 00090 unsigned int counter; 00091 00092 // Do checksum check (if the checksum is required) 00093 counter = 0; 00094 for (unsigned int i=0; i<(unsigned int)numberBlocks; i++) { 00095 assert( counter<maxNumberData ); 00096 if ( block[i].checksum==0 ) { 00097 counter = counter + block[i].length; 00098 continue; 00099 } 00100 00101 if ( doChecksum((unsigned char*)(data+counter), 00102 (block[i].length*sizeof(TD_PUSMemData)))!=block[i].checksum ) 00103 return MEM_LOAD_PRE_CHECKSUM_FAILED; 00104 00105 counter = counter + block[i].length; 00106 } 00107 00108 // Write memory data 00109 counter = 0; 00110 for (unsigned int i=0; i<numberBlocks; i++) { 00111 TD_PUSMemData* writeLocation = block[i].startAddress; 00112 for (TD_PUSMemLength j=0; j<block[i].length; j++) { 00113 assert( counter<maxNumberData ); 00114 *(writeLocation+j) = *(TD_PUSMemData*)(data+counter); 00115 counter = counter + 1; 00116 } 00117 } 00118 00119 // Verify checksum (if required) 00120 if ( !isCompletionAckRequired() ) 00121 return ACTION_SUCCESS; 00122 00123 for (unsigned int i=0; i<numberBlocks; i++) 00124 if ( !verifyChecksum((unsigned char*)block[i].startAddress, 00125 block[i].length*sizeof(TD_PUSMemData),block[i].checksum) ) 00126 return MEM_LOAD_POST_CHECKSUM_FAILED; 00127 00128 return ACTION_SUCCESS; 00129 } 00130 00131 00132 bool PUSMemoryLoad::isObjectConfigured(void) { 00133 return ( PUSTelecommand::isObjectConfigured() && 00134 (block!=pNULL) && 00135 (data!=pNULL) ); 00136 } 00137
Copyright 2003 P&P Software GmbH - All Rights Reserved