Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / FManDebugLogVisitor.cpp
diff --git a/converter/nexus/FManDebugLogVisitor.cpp b/converter/nexus/FManDebugLogVisitor.cpp
new file mode 100644 (file)
index 0000000..341fd17
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2013 Freescale Semiconductor, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <inttypes.h>
+#include <sstream>
+#include <iomanip>
+
+#include "FManDebugLogVisitor.h"
+#include "NxMessageVisitor.h"
+#include "NxMessage.h"
+#include "FManDebugLog.h"
+
+using std::ostringstream;
+using std::endl;
+using std::hex;
+using std::dec;
+using std::setfill;
+using std::setw;
+
+FManDebugLogVisitor::FManDebugLogVisitor()
+{
+       for (int i = 0; i < MAX_FMAN_LOGS; i++) {
+               log_[i] = new FManDebugLog();
+               log_[i]->setFManID(i);
+               already_reported_[i] = false;
+       }
+}
+
+FManDebugLogVisitor::~FManDebugLogVisitor()
+{
+       for (int i = 0; i < MAX_FMAN_LOGS; i++) {
+               delete log_[i];
+       }
+}
+
+void FManDebugLogVisitor::visit(NxDPFMInCircuitTraceMessage *m)
+{
+       // select the correct log
+       int fmsel = m->getFmsel();
+       if ( fmsel < 0 || fmsel >= MAX_FMAN_LOGS) {
+               return;
+       }
+       FManDebugLog *log = log_[fmsel];
+
+       // if this is the first beat then reset the log
+       int beatcnt = m->getBtcnt();
+       if (beatcnt == 0) {
+               already_reported_[fmsel] = false;
+               log->reset();
+       }
+
+       // capture the context data - always 4 words
+       const uint32_t *context = m->getContext();
+       for (int i = 0; i < 4; i++) {
+               log->addContextData(context[i]);
+       }
+
+       // begin parsing the log on the last beat
+       bool lastbeat = m->getLbeat();
+       if (lastbeat) {
+               log->setLastContextData();
+               log->parseContextData();
+       }
+       useful_visit_ = true;
+}
+
+// output message information as a string
+string FManDebugLogVisitor::asString() const
+{
+       ostringstream os;
+       if (useful_visit_) {
+               for (int i = 0; i < MAX_FMAN_LOGS; i++) {
+                       if (log_[i]->logComplete() && !already_reported_[i]) {
+                               os << log_[i]->asString();
+                               already_reported_[i] = true;
+                       }
+               }
+       }
+       return os.str();
+}
This page took 0.0237 seconds and 4 git commands to generate.