Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / NxMessageDecoder.cpp
1 /*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
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
20 * IN THE SOFTWARE.
21 */
22
23 #include "NxMessageDecoder.h"
24 #include "NxMessage.h"
25 #include "AUXMessageProtocol.h"
26 #include "NxPacketDecoder.h"
27 #include "NxPacketSet.h"
28 #include <iostream>
29 using std::cout;
30 using std::endl;
31
32 NxMessageDecoder::NxMessageDecoder() :
33 verbose_(false)
34 {
35 protocol_ = new AUXMessageProtocol();
36 packet_decoder_ = new NxPacketDecoder();
37 packet_set_ = new NxPacketSet();
38 }
39
40 NxMessageDecoder::~NxMessageDecoder()
41 {
42 delete protocol_;
43 delete packet_decoder_;
44 delete packet_set_;
45 }
46
47 void NxMessageDecoder::verbose(bool verbose)
48 {
49 verbose_ = verbose;
50 protocol_->verbose(verbose);
51 packet_decoder_->verbose(verbose);
52 packet_set_->verbose(verbose);
53 }
54
55 // input data - the MDO/MSEO for each data beat
56 // output msg - pointer will be set if NxMessage is available
57 // return true if no error
58 bool NxMessageDecoder::accept(uint32_t data, NxMessage* &msg)
59 {
60 AUXMessageProtocol::Outcome outcome;
61 bool ret = protocol_->evaluate((data & 3), outcome);
62 if (ret) {
63 ret = protocol_->act((data >> 2), *packet_set_);
64 if (ret) {
65 if (outcome == AUXMessageProtocol::ADD_LAST_MESSAGE) {
66 // decode the NxPacketSet information into a NXMessage
67 if (verbose_) {
68 cout << "END OF MESSAGE - Starting Decode."
69 << endl;
70 }
71 ret = packet_decoder_->decode(*packet_set_,
72 msg);
73 }
74 }
75 }
76
77 return ret;
78 }
This page took 0.040366 seconds and 4 git commands to generate.