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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Sep 23 07:20:28 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: v0r00
CVS Tags: start
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
Imported sources, 23/09/2008

1 /** @file
2 * $Source: /repository/PamOffLineSW/techmodel/TmtcReader.cpp,v $
3 * $Id: TmtcReader.cpp,v 1.7 2008-03-06 18:33:36 messineo Exp $
4 * $Author: messineo $
5 *
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 "$Header: /repository/PamOffLineSW/techmodel/TmtcReader.cpp,v 1.7 2008-03-06 18:33:36 messineo Exp $\n";
32 }
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 subData[m]=mysubData[m + (TMTC_SUB_LENGTH+TMTC_SUBCRC_LENGTH)*i ];
74 }
75
76 CRCbuff[0]=mysubData[TMTC_SUB_LENGTH*i];
77
78 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&subData, TMTC_SUB_LENGTH);
79 partialCRC = CM_Compute_CRC16(partialCRC, (UINT8*)&CRCbuff, TMTC_SUBCRC_LENGTH);
80
81 //This == CRCBuff is not really parametric take care if have to change the static lengths
82 if((UINT8)(CM_Compute_CRC16(0, (UINT8*)&subData, TMTC_SUB_LENGTH)) == (UINT8)CRCbuff[0])
83 {
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
107
108 // if(partialCRC != readCRC) throw WrongCRCException(" Wrong Global CRC for TMTC Packet ");
109 if (partialCRC != readCRC)
110 {
111 oss.str("");
112 oss<<"Wrong CRC for TMTC Packet: "<<" CRC COMPUTED= "<< partialCRC<<" CRC READ= "<< readCRC;
113 msg=oss.str();
114 PamOffLineSW::mainLogUtil->logWarning(msg);
115 throw WrongCRCException_PKTUsed(" Wrong CRC for TMTC Packet. ");
116 }
117 }
118
119
120
121

  ViewVC Help
Powered by ViewVC 1.1.23