1 |
/** @file |
/** @file |
2 |
* $Source: /repository/PamOffLineSW/techmodel/McmdReader.cpp,v $ |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/McmdReader.cpp,v $ |
3 |
* $Id: McmdReader.cpp,v 1.7 2008-03-06 18:33:36 messineo Exp $ |
* $Id: McmdReader.cpp,v 1.1.1.1 2008/09/23 07:20:26 mocchiut Exp $ |
4 |
* $Author: messineo $ |
* $Author: mocchiut $ |
5 |
* |
* |
6 |
* Implementation of the McmdReader class. |
* Implementation of the McmdReader class. |
7 |
*/ |
*/ |
25 |
*/ |
*/ |
26 |
std::string McmdReader::GetVersionInfo(void) const { |
std::string McmdReader::GetVersionInfo(void) const { |
27 |
return |
return |
28 |
"$Header: /repository/PamOffLineSW/techmodel/McmdReader.cpp,v 1.7 2008-03-06 18:33:36 messineo Exp $\n"; |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/McmdReader.cpp,v 1.1.1.1 2008/09/23 07:20:26 mocchiut Exp $\n"; |
29 |
} |
} |
30 |
|
|
31 |
/** |
/** |
88 |
TClonesArray &recs = *(Mcmd->Records); |
TClonesArray &recs = *(Mcmd->Records); |
89 |
|
|
90 |
int start=0; |
int start=0; |
91 |
|
// while(start < (length)) { |
92 |
|
// printf(" %i => %X \n",start,(UINT8)mysubData[start]); |
93 |
|
// start++; |
94 |
|
// }; |
95 |
|
// start=0; |
96 |
|
|
97 |
while(start < (length-2-obt_len-subTrailer_len-subTrailer_len-subPckCRC_len)) |
while(start < (length-2-obt_len-subTrailer_len-subTrailer_len-subPckCRC_len)) |
98 |
|
// while(start < (length-2)) |
99 |
{ |
{ |
100 |
|
// printf(" 1data %X \n",(UINT8)mysubData[start]); |
101 |
//Read the OBT preceeding the subpacket then calculate a partial CRC for it |
//Read the OBT preceeding the subpacket then calculate a partial CRC for it |
102 |
//and update the partialCRC |
//and update the partialCRC |
103 |
for(int m=start; m<obt_len; m++){ |
for(int m=start; m<start+obt_len; m++){ |
104 |
OBT[m-start]=mysubData[m]; |
OBT[m-start]=mysubData[m]; |
105 |
} |
} |
106 |
start+=obt_len; |
start+=obt_len; |
107 |
|
|
108 |
|
// printf(" 2data %X \n",(UINT8)mysubData[start]); |
109 |
|
// printf(" 2data %X \n",(UINT8)mysubData[start]+1); |
110 |
subCRC = CM_Compute_CRC16(0, (BYTE*)&OBT, obt_len); |
subCRC = CM_Compute_CRC16(0, (BYTE*)&OBT, obt_len); |
111 |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&OBT, obt_len); |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&OBT, obt_len); |
112 |
//Read the header for the subPacket and read mcmdLength |
//Read the header for the subPacket and read mcmdLength |
113 |
//12 is the total lenght of subHeader + subTrailer |
//12 is the total lenght of subHeader + subTrailer |
114 |
for(int m=start; m<subHeader_len; m++){ |
for(int m=start; m<start+subHeader_len; m++){ |
115 |
subHeader[m-start]=mysubData[m]; |
subHeader[m-start]=mysubData[m]; |
116 |
} |
} |
117 |
start+=subHeader_len; |
start+=subHeader_len; |
118 |
|
|
119 |
|
// printf(" 3data %X \n",(UINT8)mysubData[start]); |
120 |
|
// printf(" 3data %X \n",(UINT8)mysubData[start+1]); |
121 |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)&subHeader, subHeader_len); |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)&subHeader, subHeader_len); |
122 |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&subHeader, subHeader_len); |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&subHeader, subHeader_len); |
123 |
dataLength = (((0x0fff)&((UINT16)subHeader[4]))<<8|((UINT16)subHeader[5])*2) - subHeader_len - subTrailer_len; |
dataLength = (((0x0fff)&((UINT16)subHeader[4]))<<8|((UINT16)subHeader[5])*2) - subHeader_len - subTrailer_len; |
124 |
|
// printf(" datalenght = %i subh 4 %X subd 5 %X \n",dataLength,(UINT8)subHeader[4],(UINT8)subHeader[5]); |
125 |
//the line below is exactly how it was in the original version |
//the line below is exactly how it was in the original version |
126 |
if (dataLength < 0) break; //it should throw an exception ***TBD*** |
if (dataLength < 0) break; //it should throw an exception ***TBD*** |
127 |
//I add also this check |
//I add also this check |
131 |
oss<<"MCMD: Error in the MCMD Packet lenght, it is not " <<length; |
oss<<"MCMD: Error in the MCMD Packet lenght, it is not " <<length; |
132 |
msg=oss.str(); |
msg=oss.str(); |
133 |
PamOffLineSW::mainLogUtil->logWarning(msg); |
PamOffLineSW::mainLogUtil->logWarning(msg); |
134 |
break; //it should throw an exception ***TBD*** |
break; //it should throw an exception ***TBD*** |
135 |
} |
} |
136 |
|
|
137 |
//read subpacket data according to data length then calculate partial CRC for data |
//read subpacket data according to data length then calculate partial CRC for data |
138 |
//and update the partialCRC |
//and update the partialCRC |
139 |
|
|
140 |
subData = new char[dataLength]; |
subData = new char[dataLength]; |
141 |
for(int m=start; m<dataLength; m++){ |
for(int m=start; m<start+dataLength; m++){ |
142 |
subData[m-start]=mysubData[m]; |
subData[m-start]=mysubData[m]; |
143 |
} |
} |
144 |
start+=dataLength; |
start+=dataLength; |
145 |
|
|
146 |
|
// printf(" 4data %X \n",(UINT8)mysubData[start]); |
147 |
|
// printf(" 4data %X \n",(UINT8)mysubData[start+1]); |
148 |
for (int jj = 0; jj < dataLength ; jj++){ |
for (int jj = 0; jj < dataLength ; jj++){ |
149 |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)(subData+jj), 1); |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)(subData+jj), 1); |
150 |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)(subData+jj), 1); |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)(subData+jj), 1); |
152 |
|
|
153 |
//Read the CRC inside of MCMD |
//Read the CRC inside of MCMD |
154 |
//To check sum of all sub packet data, module 256 ****TBD**** |
//To check sum of all sub packet data, module 256 ****TBD**** |
155 |
for(int m=start; m<subTrailer_len; m++){ |
for(int m=start; m<start+subTrailer_len; m++){ |
156 |
subTrailer[m-start]=mysubData[m]; |
subTrailer[m-start]=mysubData[m]; |
157 |
} |
} |
158 |
start+=subTrailer_len; |
start+=subTrailer_len; |
159 |
|
// printf(" 5data %X \n",(UINT8)mysubData[start]); |
160 |
|
// printf(" 5data %X \n",(UINT8)mysubData[start+1]); |
161 |
|
|
162 |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)&subTrailer, 2); |
subCRC = CM_Compute_CRC16(subCRC, (BYTE*)&subTrailer, 2); |
163 |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&subTrailer, 2); |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&subTrailer, 2); |
164 |
//Read the CRC of subPacket |
//Read the CRC of subPacket |
165 |
for(int m=start; m<subPckCRC_len; m++){ |
for(int m=start; m<start+subPckCRC_len; m++){ |
166 |
subPckCRC[m-start]=mysubData[m]; |
subPckCRC[m-start]=mysubData[m]; |
167 |
} |
} |
168 |
start+=subPckCRC_len; |
start+=subPckCRC_len; |
170 |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&subPckCRC, 2); |
partialCRC = CM_Compute_CRC16(partialCRC, (BYTE*)&subPckCRC, 2); |
171 |
readCRC = (((BYTE)subPckCRC[0])<<8) + ((BYTE)subPckCRC[1]); |
readCRC = (((BYTE)subPckCRC[0])<<8) + ((BYTE)subPckCRC[1]); |
172 |
|
|
173 |
//finally check if the RecordCRC is correct |
//finally check if the RecordCRC is correct |
174 |
//and finally update the partialCRC |
//and finally update the partialCRC |
175 |
//TO DO - if one CRC is wrong also the total one will be corrupted |
//TO DO - if one CRC is wrong also the total one will be corrupted |
176 |
|
// printf(" subCRC %X readCRC %X \n",subCRC,readCRC); |
177 |
if (subCRC == readCRC){ |
if (subCRC == readCRC){ |
178 |
rec = new(recs[i++]) McmdRecord(); //aggiungo un nuovo McmdRecord all'evento |
rec = new(recs[i++]) McmdRecord(); //aggiungo un nuovo McmdRecord all'evento |
179 |
rec->MCMD_RECORD_OBT = (((UINT32)OBT[0]<<24)&0xFF000000) + (((UINT32)OBT[1]<<16)&0x00FF0000) + (((UINT32)OBT[2]<<8)&0x0000FF00) + (((UINT32)OBT[3])&0x000000FF); |
rec->MCMD_RECORD_OBT = (((UINT32)OBT[0]<<24)&0xFF000000) + (((UINT32)OBT[1]<<16)&0x00FF0000) + (((UINT32)OBT[2]<<8)&0x0000FF00) + (((UINT32)OBT[3])&0x000000FF); |
199 |
if(start!=length-2) |
if(start!=length-2) |
200 |
{ |
{ |
201 |
oss.str(""); |
oss.str(""); |
202 |
oss<<"MCMD: Error in the MCMD Packet lenght, it is not " <<length; |
oss<<"MCMD: Error in the MCMD Packet lenght (start!=length-2), it is not " <<length; |
203 |
msg=oss.str(); |
msg=oss.str(); |
204 |
PamOffLineSW::mainLogUtil->logWarning(msg); |
PamOffLineSW::mainLogUtil->logWarning(msg); |
205 |
} |
} |
206 |
|
|
207 |
//in the end compare the calculated partial CRC with the MCMD packet CRC |
//in the end compare the calculated partial CRC with the MCMD packet CRC |
208 |
readCRC = (((UINT16)(mysubData[length - 2]<<8))&0xFF00) + (((UINT16)mysubData[length - 1])&0x00FF); |
readCRC = (((UINT16)(mysubData[length - 2]<<8))&0xFF00) + (((UINT16)mysubData[length - 1])&0x00FF); |
209 |
|
//readCRC = (((UINT16)(mysubData[length - 1]<<8))&0xFF00) + (((UINT16)mysubData[length])&0x00FF); |
210 |
// if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for MCMD Packet "); |
// |
211 |
|
// printf(" CICCIOEND readCRC %X partialCRC %X \n",(UINT16)readCRC,(UINT16)partialCRC); |
212 |
|
// if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for MCMD Packet "); |
213 |
if (partialCRC != readCRC) |
if (partialCRC != readCRC) |
214 |
{ |
{ |
215 |
oss.str(""); |
oss.str(""); |
217 |
msg=oss.str(); |
msg=oss.str(); |
218 |
PamOffLineSW::mainLogUtil->logWarning(msg); |
PamOffLineSW::mainLogUtil->logWarning(msg); |
219 |
throw WrongCRCException_PKTUsed(" Wrong CRC for MCMD Packet. "); |
throw WrongCRCException_PKTUsed(" Wrong CRC for MCMD Packet. "); |
220 |
} |
}; |
221 |
} |
} |