/[PAMELA software]/chewbacca/PamOffLineSW/techmodel/TmtcReader.cpp
ViewVC logotype

Annotation of /chewbacca/PamOffLineSW/techmodel/TmtcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Oct 1 09:53:45 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: v1r02, v1r00, v1r01, v10RED, v9r00, v9r01, HEAD
Changes since 1.1: +9 -8 lines
Bugs in TmtcReader.cpp and McmdReader.cpp fixed

1 mocchiut 1.1 /** @file
2 mocchiut 1.2 * $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/TmtcReader.cpp,v $
3     * $Id: TmtcReader.cpp,v 1.1.1.1 2008/09/23 07:20:28 mocchiut Exp $
4     * $Author: mocchiut $
5 mocchiut 1.1 *
6     * Implementation of the TmtcReader class.
7     * ToBeDone:
8     * Control the CRC for the entire data Packet not just for single records
9     */
10    
11     extern "C" {
12     #include "CRC.h"
13     }
14     #include "ReaderAlgorithms.h"
15     using namespace pamela::techmodel;
16    
17    
18     /**
19     * Constructor.
20     */
21     TmtcReader::TmtcReader(void):
22     TechmodelAlgorithm(PacketType::Tmtc, "TechmodelTmtcReader") {
23     Tmtc = new TmtcEvent();
24     }
25    
26     /**
27     * Get a string with the version info of the algorithm.
28     */
29     std::string TmtcReader::GetVersionInfo(void) const {
30     return
31 mocchiut 1.2 "$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/TmtcReader.cpp,v 1.1.1.1 2008/09/23 07:20:28 mocchiut Exp $\n";
32 mocchiut 1.1 }
33    
34     /**
35     * Initialize the algorithm with a special run. This will initialize the
36     * event reader routines for all packet types.
37     */
38     void TmtcReader::Init(PamelaRun *run) {
39     run->WriteSubPacket(this, &Tmtc, Tmtc->Class());
40     }
41    
42     /**
43     * Unpack the Tmtc event
44     */
45     void TmtcReader::PKT_RunEvent(char* mysubData, long int length) throw (WrongCRCException_PKTUsed){
46    
47     stringstream oss;
48     string msg;
49     int k;
50     /* The ' k ' indexs the number of recs.
51     * It is needed to be indipendent from ' i ' because in case of CRC error the single record is skipped and ' i ' increase by one, but correct records to be stored are still ' i '.
52     */
53     k = 0;
54    
55     char subData[TMTC_SUB_LENGTH]={0};
56     char CRCbuff[TMTC_SUBCRC_LENGTH]={0};
57     // char eventCRC[TMTC_CRC_LENGTH]={0};
58    
59     int numRecords = (length-TMTC_CRC_LENGTH)/(TMTC_SUB_LENGTH + TMTC_SUBCRC_LENGTH); //subtract the last two bytes because are the final CRC
60     long int start=0;
61    
62     TmtcRecord* rec;
63     Tmtc->Records->Clear();
64     TClonesArray &recs = *(Tmtc->Records);
65    
66     UINT16 partialCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
67     UINT16 readCRC = 0; //partial CRC updated as mcmd packet is read (to compare with the last two bytes of this event)
68    
69     for(int i=0; i < numRecords; i++)
70     {
71     start=(TMTC_SUB_LENGTH+TMTC_SUBCRC_LENGTH)*i;
72     for(int m=0; m<TMTC_SUB_LENGTH; m++){
73 mocchiut 1.2 subData[m]=mysubData[m + start];
74 mocchiut 1.1 }
75    
76 mocchiut 1.2 CRCbuff[0]=mysubData[start + TMTC_SUB_LENGTH];
77 mocchiut 1.1
78     partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&subData, TMTC_SUB_LENGTH);
79     partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&CRCbuff, TMTC_SUBCRC_LENGTH);
80 mocchiut 1.2 if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&subData, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0])
81     {
82 mocchiut 1.1
83     //This == CRCBuff is not really parametric take care if have to change the static lengths
84     rec = new(recs[k++]) TmtcRecord(); //add a new TmtcRecord
85     rec->TM_RECORD_OBT = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF);
86     rec->TM_DIAG_AND_BILEVEL_ACQ = (((UINT16)subData[4]<<8)&0x0000FF00) + (((UINT16)subData[5])&0x000000FF);
87    
88     for(int j = 0; j < 16; j++) {
89     rec->TM_TH_ANA[j] = ((((UINT16)subData[6 + 2*j]<<8)&0xFF00) + (((UINT16)subData[7 + 2*j])&0x00FF)); //20 is the size of TM_DEA_ANA(16) + OBT(4)
90     }
91    
92     for(int j = 0; j < 6; j++) {
93     rec->TM_DEA_ANA[j] = subData[38+j];
94     }
95     }
96     else
97     {
98     oss.str("");
99     oss << "TMTC: Wrong CRC on Subpacket "<< i <<" int TMTC Packet starting at position " << start;
100     msg=oss.str();
101     PamOffLineSW::mainLogUtil->logAll(msg);
102     }
103     }
104     // readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);
105     readCRC = (((UINT16)(mysubData[length - 2]<<8))&0xFF00) + (((UINT16)mysubData[length - 1])&0x00FF);
106 mocchiut 1.2 // readCRC = (((UINT16)(mysubData[length - 1]<<8))&0xFF00) + (((UINT16)mysubData[length])&0x00FF);
107 mocchiut 1.1
108    
109     // if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for TMTC Packet ");
110     if (partialCRC != readCRC)
111     {
112     oss.str("");
113     oss<<"Wrong CRC for TMTC Packet: "<<" CRC COMPUTED= "<< partialCRC<<" CRC READ= "<< readCRC;
114     msg=oss.str();
115     PamOffLineSW::mainLogUtil->logWarning(msg);
116     throw WrongCRCException_PKTUsed(" Wrong CRC for TMTC Packet. ");
117     }
118     }
119    
120    
121    
122    

  ViewVC Help
Powered by ViewVC 1.1.23