2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 #include "Application.h"
24 #include "NxMessageDecoder.h"
25 #include "NxMessage.h"
26 #include "FManDebugLogVisitor.h"
27 #include "FullAddressVisitor.h"
28 #include "SizedAddress.h"
41 Application::Application() :
42 verbose_(false), summary_(false), data_counter_(0), msg_counter_(0)
46 Application::~Application()
48 vector
<NxMessageVisitor
*>::iterator it
;
49 for (it
= visitors_
.begin(); it
!= visitors_
.end(); it
++) {
55 // Enable the Full Address Log for the Application
56 void Application::enableFullAddrLog()
58 NxMessageVisitor
* v
= new FullAddressVisitor();
59 visitors_
.push_back(v
);
62 // Enable the FMan Detail Log for the Application
63 void Application::enableFmanLog()
65 NxMessageVisitor
* v
= new FManDebugLogVisitor();
66 visitors_
.push_back(v
);
69 // Main application entry
70 bool Application::process(const string
& fn
)
74 // test if file is available
75 ifstream
infile(fn
.c_str());
77 cout
<< "Input Filename: \"" << fn
<< "\" cannot be opened! ";
84 cout
<< "Input Filename: \"" << fn
<< "\" - ";
87 // determine format for file
90 cout
<< "Binary" << endl
;
92 ret
= processBinFile_(fn
);
95 cout
<< "Text" << endl
;
97 ret
= processTextFile_(fn
);
100 if (ret
&& summary_
) {
107 // Determine if the name file contains Binary formatted data
108 bool Application::isBinFile_(const string
&fn
) const
110 char data
[12]; // if text then expecting 0x12345678\n
112 // open the file as binary and read the first 12 bytes
113 ifstream
infile(fn
.c_str(), std::ios::in
| std::ios::binary
);
114 infile
.read(data
, 12);
116 bool text_file
= ((data
[0] == '0') && (data
[1] == 'x')
117 && ((data
[10] == '\n') || (data
[10] == ' ')));
121 // Open the named text file and process the Nexus data
122 bool Application::processTextFile_(const string
&fn
)
127 // open the file and feed the data to the decoder
128 ifstream
infile(fn
.c_str());
129 while (!infile
.eof()) {
130 infile
>> hex
>> data
;
131 ret
= process_(data
);
132 if (!ret
) { // error, so quit
141 // Open the named text file and process the Nexus data
142 bool Application::processBinFile_(const string
&fn
)
145 uint8_t byte
[sizeof(uint32_t)];
148 // open the file and feed the data to the decoder
149 ifstream
infile(fn
.c_str(), std::ios::in
| std::ios::binary
);
150 while (!infile
.eof()) {
151 infile
.read((char*) &byte
, sizeof(uint32_t));
152 // Nexus binary files are Big Endian data
153 data
= byte
[0] << 24;
154 data
|= byte
[1] << 16;
155 data
|= byte
[2] << 8;
157 ret
= process_(data
);
158 if (!ret
) { // error, so quit
167 // Process the Nexus data
168 bool Application::process_(const uint32_t data
)
172 NxMessage
*msg
= (NxMessage
*) 0;
176 cout
<< dec
<< data_counter_
<< ": MDO/MSEO: 0x" << hex
177 << setfill('0') << setw(8) << data
<< endl
;
180 ret
= decoder_
.accept(data
, msg
);
184 // we have a message to output
185 cout
<< "Message # " << dec
<< msg_counter_
<< endl
;
186 cout
<< msg
->asString() << endl
;
188 // count the messages
190 msg_count_
[msg
->tcodeString()]++;
193 // Send all the visitors
194 vector
<NxMessageVisitor
*>::iterator it
;
195 for (it
= visitors_
.begin(); it
!= visitors_
.end();
199 cout
<< (*it
)->asString() << endl
;
202 // nothing else to do for now so delete the message
204 msg
= (NxMessage
*) 0;
207 // error somewhere - quit
209 cout
<< "NxMessageDecoder Failed. Quitting." << endl
;
216 // output a summary report on number of messages by type
217 void Application::summarize()
219 cout
<< endl
<< "***********************" << endl
;
220 cout
<< "Message Counts by TCODE" << endl
;
222 map
<string
, uint32_t>::const_iterator iter
;
223 for (iter
= msg_count_
.begin(); iter
!= msg_count_
.end(); ++iter
) {
224 cout
<< iter
->first
<< "\t" << dec
<< setw(10) << setfill(' ')
225 << iter
->second
<< endl
;
This page took 0.033407 seconds and 4 git commands to generate.