p8: match to the response provided by the firmware when checking responses (added...
[deb_libcec.git] / src / lib / adapter / Pulse-Eight / USBCECAdapterMessage.h
1 #pragma once
2 /*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
7 *
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 *
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 *
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
27 *
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
32 */
33
34 #include "lib/adapter/AdapterCommunication.h"
35
36 namespace CEC
37 {
38 class CCECAdapterMessage
39 {
40 public:
41 /*!
42 * @brief Create an empty message.
43 */
44 CCECAdapterMessage(void);
45
46 /*!
47 * @brief Create a message with a command that is to be transmitted over the CEC line.
48 * @param command The command to transmit.
49 * @param iLineTimeout The line timeout to use when sending this message.
50 */
51 CCECAdapterMessage(const cec_command &command, uint8_t iLineTimeout = 3);
52
53 /*!
54 * @return the message as human readable string.
55 */
56 std::string ToString(void) const;
57
58 /*!
59 * @brief Translate the messagecode into a human readable string.
60 * @param msgCode The messagecode to translate.
61 * @return The messagecode as string.
62 */
63 static const char *ToString(cec_adapter_messagecode msgCode);
64
65 /*!
66 * @brief Get the byte at the given position.
67 * @param pos The position to get.
68 * @return The requested byte, or 0 when it's out of range.
69 */
70 uint8_t At(uint8_t pos) const;
71 uint8_t operator[](uint8_t pos) const;
72
73 /*!
74 * @return The size of the packet in bytes.
75 */
76 uint8_t Size(void) const;
77
78 /*!
79 * @return True when empty, false otherwise.
80 */
81 bool IsEmpty(void) const;
82
83 /*!
84 * @brief Clear this message and reset everything to the initial values.
85 */
86 void Clear(void);
87
88 /*!
89 * @brief Shift the message by the given number of bytes.
90 * @param iShiftBy The number of bytes to shift.
91 */
92 void Shift(uint8_t iShiftBy);
93
94 /*!
95 * @brief Append the given message to this message.
96 * @param data The message to append.
97 */
98 void Append(CCECAdapterMessage &data);
99
100 /*!
101 * @brief Append the given datapacket to this message.
102 * @param data The packet to add.
103 */
104 void Append(cec_datapacket &data);
105
106 /*!
107 * @brief Adds a byte to this message. Does not escape the byte.
108 * @param byte The byte to add.
109 */
110 void PushBack(uint8_t byte);
111
112 /*!
113 * @brief Adds a byte to this message and escapes the byte if needed.
114 * @param byte The byte to add.
115 */
116 void PushEscaped(uint8_t byte);
117
118 /*!
119 * @brief Adds a byte to this message.
120 * @param byte The byte to add.
121 * @return True when a full message was received, false otherwise.
122 */
123 bool PushReceivedByte(uint8_t byte);
124
125 /*!
126 * @return The messagecode inside this adapter message, or MSGCODE_NOTHING if there is none.
127 */
128 cec_adapter_messagecode Message(void) const;
129
130 /*!
131 * @return The messagecode (if provided) that this message is responding to
132 */
133 cec_adapter_messagecode ResponseTo(void) const;
134
135 /*!
136 * @return True when this message is a transmission, false otherwise.
137 */
138 bool IsTranmission(void) const;
139
140 /*!
141 * @return True when the EOM bit is set, false otherwise.
142 */
143 bool IsEOM(void) const;
144
145 /*!
146 * @return True when the ACK bit is set, false otherwise.
147 */
148 bool IsACK(void) const;
149
150 /*!
151 * @return True when this message has been replied with an error code, false otherwise.
152 */
153 bool IsError(void) const;
154
155 /*!
156 * @return True when this message has been replied with an error code and needs to be retried, false otherwise.
157 */
158 bool NeedsRetry(void) const;
159
160 /*!
161 * @return The logical address of the initiator, or CECDEVICE_UNKNOWN if unknown.
162 */
163 cec_logical_address Initiator(void) const;
164
165 /*!
166 * @return The logical address of the destination, or CECDEVICE_UNKNOWN if unknown.
167 */
168 cec_logical_address Destination(void) const;
169
170 /*!
171 * @return True when this message contains a start message, false otherwise.
172 */
173 bool HasStartMessage(void) const;
174
175 /*!
176 * @brief Push this adapter message to the end of the given cec_command.
177 * @param command The command to push this message to.
178 * @return True when a full CEC message was received, false otherwise.
179 */
180 bool PushToCecCommand(cec_command &command) const;
181
182 /*!
183 * @return The response messagecode.
184 */
185 cec_adapter_messagecode Reply(void) const;
186
187 uint8_t maxTries; /**< the maximum number of times to try to send this message */
188 cec_datapacket response; /**< the response to this message */
189 cec_datapacket packet; /**< the actual data */
190 cec_adapter_message_state state; /**< the current state of this message */
191 int32_t transmit_timeout; /**< the timeout to use when sending this message */
192 uint8_t lineTimeout; /**< the default CEC line timeout to use when sending this message */
193
194 private:
195 bool bNextByteIsEscaped; /**< true when the next byte that is added will be escaped, false otherwise */
196 };
197 }