3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
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/
34 #include "../platform/util/StdString.h"
35 #include "../platform/util/buffer.h"
36 #include "../platform/threads/mutex.h"
37 #include "../../../include/cectypes.h"
41 typedef enum cec_adapter_message_state
43 ADAPTER_MESSAGE_STATE_UNKNOWN
= 0, /**< the initial state */
44 ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT
, /**< waiting in the send queue of the adapter, or timed out */
45 ADAPTER_MESSAGE_STATE_SENT
, /**< sent and waiting on an ACK */
46 ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED
, /**< sent, but failed to ACK */
47 ADAPTER_MESSAGE_STATE_SENT_ACKED
, /**< sent, and ACK received */
48 ADAPTER_MESSAGE_STATE_INCOMING
, /**< received from another device */
49 ADAPTER_MESSAGE_STATE_ERROR
/**< an error occured */
50 } cec_adapter_message_state
;
52 class CCECAdapterMessage
56 * @brief Create an empty message.
58 CCECAdapterMessage(void);
61 * @brief Create a message with a command that is to be transmitted over the CEC line.
62 * @param command The command to transmit.
63 * @param iLineTimeout The line timeout to use when sending this message.
65 CCECAdapterMessage(const cec_command
&command
, uint8_t iLineTimeout
= 3);
68 * @return the message as human readable string.
70 CStdString
ToString(void) const;
73 * @brief Translate the messagecode into a human readable string.
74 * @param msgCode The messagecode to translate.
75 * @return The messagecode as string.
77 static const char *ToString(cec_adapter_messagecode msgCode
);
80 * @brief Get the byte at the given position.
81 * @param pos The position to get.
82 * @return The requested byte, or 0 when it's out of range.
84 uint8_t At(uint8_t pos
) const;
85 uint8_t operator[](uint8_t pos
) const;
88 * @return The size of the packet in bytes.
90 uint8_t Size(void) const;
93 * @return True when empty, false otherwise.
95 bool IsEmpty(void) const;
98 * @brief Clear this message and reset everything to the initial values.
103 * @brief Shift the message by the given number of bytes.
104 * @param iShiftBy The number of bytes to shift.
106 void Shift(uint8_t iShiftBy
);
109 * @brief Append the given message to this message.
110 * @param data The message to append.
112 void Append(CCECAdapterMessage
&data
);
115 * @brief Append the given datapacket to this message.
116 * @param data The packet to add.
118 void Append(cec_datapacket
&data
);
121 * @brief Adds a byte to this message. Does not escape the byte.
122 * @param byte The byte to add.
124 void PushBack(uint8_t byte
);
127 * @brief Adds a byte to this message and escapes the byte if needed.
128 * @param byte The byte to add.
130 void PushEscaped(uint8_t byte
);
133 * @brief Adds a byte to this message.
134 * @param byte The byte to add.
135 * @return True when a full message was received, false otherwise.
137 bool PushReceivedByte(uint8_t byte
);
140 * @return The messagecode inside this adapter message, or MSGCODE_NOTHING if there is none.
142 cec_adapter_messagecode
Message(void) const;
145 * @return True when this message is a transmission, false otherwise.
147 bool IsTranmission(void) const;
150 * @return True when the EOM bit is set, false otherwise.
152 bool IsEOM(void) const;
155 * @return True when the ACK bit is set, false otherwise.
157 bool IsACK(void) const;
160 * @return True when this message has been replied with an error code, false otherwise.
162 bool IsError(void) const;
165 * @return True when this message has been replied with an error code and needs to be retried, false otherwise.
167 bool NeedsRetry(void) const;
170 * @return The logical address of the initiator, or CECDEVICE_UNKNOWN if unknown.
172 cec_logical_address
Initiator(void) const;
175 * @return The logical address of the destination, or CECDEVICE_UNKNOWN if unknown.
177 cec_logical_address
Destination(void) const;
180 * @return True when this message contains a start message, false otherwise.
182 bool HasStartMessage(void) const;
185 * @brief Push this adapter message to the end of the given cec_command.
186 * @param command The command to push this message to.
187 * @return True when a full CEC message was received, false otherwise.
189 bool PushToCecCommand(cec_command
&command
) const;
192 * @return The response messagecode.
194 cec_adapter_messagecode
Reply(void) const;
196 uint8_t maxTries
; /**< the maximum number of times to try to send this message */
197 cec_datapacket response
; /**< the response to this message */
198 cec_datapacket packet
; /**< the actual data */
199 cec_adapter_message_state state
; /**< the current state of this message */
200 int32_t transmit_timeout
; /**< the timeout to use when sending this message */
201 uint8_t lineTimeout
; /**< the default CEC line timeout to use when sending this message */
204 bool bNextByteIsEscaped
; /**< true when the next byte that is added will be escaped, false otherwise */