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 "AUXMessageProtocol.h"
30 AUXMessageProtocol::AUXMessageProtocol() :
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();
40 // setup the state transitions based on IEEE-ISTO 5001 2003 page 91
41 idle_
->initialize_transitions(start_message_
, end_packet_
, end_message_
,
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_
,
52 // pick an initial state
53 current_state_
= idle_
;
56 AUXMessageProtocol::~AUXMessageProtocol()
59 delete start_message_
;
60 delete normal_transfer_
;
64 current_state_
= (MSEState
*) 0;
67 // process the MSE and return the outcome
68 bool AUXMessageProtocol::evaluate(uint32_t mse
, Outcome
&outcome
)
72 cout
<< "MSE:" << mse
;
73 cout
<< " " << current_state_
->name() << " -> ";
75 current_state_
= current_state_
->nextState(mse
);
76 outcome
= current_state_
->outcome();
78 cout
<< current_state_
->name() << " Action: "
79 << outcomeText(outcome
) << endl
;
81 current_state_
= current_state_
->nextState(mse
);
82 outcome
= current_state_
->outcome();
88 // perform the action on the MDO for this state
89 bool AUXMessageProtocol::act(uint32_t mdo
, NxPacketSet
&pkt_set
)
92 cout
<< "MDO: 0x" << std::hex
<< std::setfill('0')
93 << std::setw(8) << mdo
<< endl
;
96 // let the specific state handle the data
97 bool ret
= current_state_
->act(mdo
, pkt_set
);
101 // return text representing the outcome
102 const char * AUXMessageProtocol::outcomeText(Outcome outcome
) const
105 case DISCARD
: // MDO is invalid
108 case ADD_NEW_MESSAGE
: // MDO begins first packet of mew message
109 return "ADD NEW MESSAGE";
111 case ADD_CURRENT
: // MDO adds to current packet
112 return "ADD CURRENT";
114 case ADD_LAST_PACKET
: // MDO ends the current packet
115 return "ADD LAST PACKET";
117 case ADD_LAST_MESSAGE
: // MDO ends the current message
118 return "ADD LAST MESSAGE";
121 return "UNKNOWN"; // This is an error condition!
This page took 0.032735 seconds and 4 git commands to generate.