Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / AUXMessageProtocol.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 "AUXMessageProtocol.h"
24 #include "MSEState.h"
25 #include <iostream>
26 #include <iomanip>
27 using std::cout;
28 using std::endl;
29
30 AUXMessageProtocol::AUXMessageProtocol() :
31 verbose_(false)
32 {
33 // create all the states we need
34 idle_ = new MSEIdle();
35 start_message_ = new MSEStartMessage();
36 normal_transfer_ = new MSENormalTransfer();
37 end_packet_ = new MSEEndPacket();
38 end_message_ = new MSEEndMessage();
39
40 // setup the state transitions based on IEEE-ISTO 5001 2003 page 91
41 idle_->initialize_transitions(start_message_, end_packet_, end_message_,
42 idle_);
43 start_message_->initialize_transitions(normal_transfer_, end_packet_,
44 start_message_, end_message_);
45 normal_transfer_->initialize_transitions(normal_transfer_, end_packet_,
46 normal_transfer_/* ? */, end_message_);
47 end_packet_->initialize_transitions(normal_transfer_, end_packet_,
48 end_packet_/* ? */, end_message_);
49 end_message_->initialize_transitions(start_message_, end_packet_,
50 end_message_, idle_);
51
52 // pick an initial state
53 current_state_ = idle_;
54 }
55
56 AUXMessageProtocol::~AUXMessageProtocol()
57 {
58 delete idle_;
59 delete start_message_;
60 delete normal_transfer_;
61 delete end_packet_;
62 delete end_message_;
63
64 current_state_ = (MSEState*) 0;
65 }
66
67 // process the MSE and return the outcome
68 bool AUXMessageProtocol::evaluate(uint32_t mse, Outcome &outcome)
69 {
70 bool ret = true;
71 if (verbose_) {
72 cout << "MSE:" << mse;
73 cout << " " << current_state_->name() << " -> ";
74
75 current_state_ = current_state_->nextState(mse);
76 outcome = current_state_->outcome();
77
78 cout << current_state_->name() << " Action: "
79 << outcomeText(outcome) << endl;
80 } else {
81 current_state_ = current_state_->nextState(mse);
82 outcome = current_state_->outcome();
83 }
84
85 return ret;
86 }
87
88 // perform the action on the MDO for this state
89 bool AUXMessageProtocol::act(uint32_t mdo, NxPacketSet &pkt_set)
90 {
91 if (verbose_) {
92 cout << "MDO: 0x" << std::hex << std::setfill('0')
93 << std::setw(8) << mdo << endl;
94 }
95
96 // let the specific state handle the data
97 bool ret = current_state_->act(mdo, pkt_set);
98 return ret;
99 }
100
101 // return text representing the outcome
102 const char * AUXMessageProtocol::outcomeText(Outcome outcome) const
103 {
104 switch (outcome) {
105 case DISCARD: // MDO is invalid
106 return "DISCARD";
107 break;
108 case ADD_NEW_MESSAGE: // MDO begins first packet of mew message
109 return "ADD NEW MESSAGE";
110 break;
111 case ADD_CURRENT: // MDO adds to current packet
112 return "ADD CURRENT";
113 break;
114 case ADD_LAST_PACKET: // MDO ends the current packet
115 return "ADD LAST PACKET";
116 break;
117 case ADD_LAST_MESSAGE: // MDO ends the current message
118 return "ADD LAST MESSAGE";
119 break;
120 default:
121 return "UNKNOWN"; // This is an error condition!
122 break;
123 };
124 }
This page took 0.032735 seconds and 4 git commands to generate.