Commit | Line | Data |
---|---|---|
ef7696f5 LOK |
1 | #pragma once |
2 | /* | |
3 | * This file is part of the libCEC(R) library. | |
4 | * | |
16f47961 | 5 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. |
ef7696f5 LOK |
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 | ||
2b44051c | 34 | #include "lib/adapter/AdapterCommunication.h" |
ba65909d | 35 | |
ef7696f5 LOK |
36 | namespace CEC |
37 | { | |
cb8feb41 LOK |
38 | typedef enum cec_adapter_messagecode |
39 | { | |
40 | MSGCODE_NOTHING = 0, | |
41 | MSGCODE_PING, | |
42 | MSGCODE_TIMEOUT_ERROR, | |
43 | MSGCODE_HIGH_ERROR, | |
44 | MSGCODE_LOW_ERROR, | |
45 | MSGCODE_FRAME_START, | |
46 | MSGCODE_FRAME_DATA, | |
47 | MSGCODE_RECEIVE_FAILED, | |
48 | MSGCODE_COMMAND_ACCEPTED, | |
49 | MSGCODE_COMMAND_REJECTED, | |
50 | MSGCODE_SET_ACK_MASK, | |
51 | MSGCODE_TRANSMIT, | |
52 | MSGCODE_TRANSMIT_EOM, | |
53 | MSGCODE_TRANSMIT_IDLETIME, | |
54 | MSGCODE_TRANSMIT_ACK_POLARITY, | |
55 | MSGCODE_TRANSMIT_LINE_TIMEOUT, | |
56 | MSGCODE_TRANSMIT_SUCCEEDED, | |
57 | MSGCODE_TRANSMIT_FAILED_LINE, | |
58 | MSGCODE_TRANSMIT_FAILED_ACK, | |
59 | MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA, | |
60 | MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE, | |
61 | MSGCODE_FIRMWARE_VERSION, | |
62 | MSGCODE_START_BOOTLOADER, | |
63 | MSGCODE_GET_BUILDDATE, | |
64 | MSGCODE_SET_CONTROLLED, | |
65 | MSGCODE_GET_AUTO_ENABLED, | |
66 | MSGCODE_SET_AUTO_ENABLED, | |
67 | MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS, | |
68 | MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS, | |
69 | MSGCODE_GET_LOGICAL_ADDRESS_MASK, | |
70 | MSGCODE_SET_LOGICAL_ADDRESS_MASK, | |
71 | MSGCODE_GET_PHYSICAL_ADDRESS, | |
72 | MSGCODE_SET_PHYSICAL_ADDRESS, | |
73 | MSGCODE_GET_DEVICE_TYPE, | |
74 | MSGCODE_SET_DEVICE_TYPE, | |
75 | MSGCODE_GET_HDMI_VERSION, | |
76 | MSGCODE_SET_HDMI_VERSION, | |
77 | MSGCODE_GET_OSD_NAME, | |
78 | MSGCODE_SET_OSD_NAME, | |
79 | MSGCODE_WRITE_EEPROM, | |
2d418322 | 80 | MSGCODE_GET_ADAPTER_TYPE, |
a582c2bb LOK |
81 | MSGCODE_SET_ACTIVE_SOURCE, |
82 | ||
cb8feb41 LOK |
83 | MSGCODE_FRAME_EOM = 0x80, |
84 | MSGCODE_FRAME_ACK = 0x40, | |
85 | } cec_adapter_messagecode; | |
86 | ||
2d418322 LOK |
87 | typedef enum p8_cec_adapter_type |
88 | { | |
89 | P8_ADAPTERTYPE_UNKNOWN = 0, | |
90 | P8_ADAPTERTYPE_EXTERNAL, | |
91 | P8_ADAPTERTYPE_DAUGHTERBOARD, | |
92 | } p8_cec_adapter_type; | |
93 | ||
ef7696f5 LOK |
94 | class CCECAdapterMessage |
95 | { | |
96 | public: | |
a75e3a5a LOK |
97 | /*! |
98 | * @brief Create an empty message. | |
99 | */ | |
100 | CCECAdapterMessage(void); | |
101 | ||
102 | /*! | |
103 | * @brief Create a message with a command that is to be transmitted over the CEC line. | |
104 | * @param command The command to transmit. | |
33dd87a9 | 105 | * @param iLineTimeout The line timeout to use when sending this message. |
a75e3a5a | 106 | */ |
33dd87a9 | 107 | CCECAdapterMessage(const cec_command &command, uint8_t iLineTimeout = 3); |
a75e3a5a LOK |
108 | |
109 | /*! | |
110 | * @return the message as human readable string. | |
111 | */ | |
2b44051c | 112 | std::string ToString(void) const; |
a75e3a5a LOK |
113 | |
114 | /*! | |
115 | * @brief Translate the messagecode into a human readable string. | |
116 | * @param msgCode The messagecode to translate. | |
117 | * @return The messagecode as string. | |
118 | */ | |
119 | static const char *ToString(cec_adapter_messagecode msgCode); | |
120 | ||
121 | /*! | |
122 | * @brief Get the byte at the given position. | |
123 | * @param pos The position to get. | |
124 | * @return The requested byte, or 0 when it's out of range. | |
125 | */ | |
126 | uint8_t At(uint8_t pos) const; | |
127 | uint8_t operator[](uint8_t pos) const; | |
128 | ||
129 | /*! | |
130 | * @return The size of the packet in bytes. | |
131 | */ | |
132 | uint8_t Size(void) const; | |
133 | ||
134 | /*! | |
135 | * @return True when empty, false otherwise. | |
136 | */ | |
137 | bool IsEmpty(void) const; | |
138 | ||
139 | /*! | |
140 | * @brief Clear this message and reset everything to the initial values. | |
141 | */ | |
142 | void Clear(void); | |
143 | ||
144 | /*! | |
145 | * @brief Shift the message by the given number of bytes. | |
146 | * @param iShiftBy The number of bytes to shift. | |
147 | */ | |
148 | void Shift(uint8_t iShiftBy); | |
149 | ||
150 | /*! | |
151 | * @brief Append the given message to this message. | |
152 | * @param data The message to append. | |
153 | */ | |
154 | void Append(CCECAdapterMessage &data); | |
155 | ||
156 | /*! | |
157 | * @brief Append the given datapacket to this message. | |
158 | * @param data The packet to add. | |
159 | */ | |
160 | void Append(cec_datapacket &data); | |
161 | ||
162 | /*! | |
163 | * @brief Adds a byte to this message. Does not escape the byte. | |
164 | * @param byte The byte to add. | |
165 | */ | |
166 | void PushBack(uint8_t byte); | |
167 | ||
168 | /*! | |
169 | * @brief Adds a byte to this message and escapes the byte if needed. | |
170 | * @param byte The byte to add. | |
171 | */ | |
172 | void PushEscaped(uint8_t byte); | |
173 | ||
174 | /*! | |
175 | * @brief Adds a byte to this message. | |
176 | * @param byte The byte to add. | |
177 | * @return True when a full message was received, false otherwise. | |
178 | */ | |
179 | bool PushReceivedByte(uint8_t byte); | |
180 | ||
181 | /*! | |
182 | * @return The messagecode inside this adapter message, or MSGCODE_NOTHING if there is none. | |
183 | */ | |
184 | cec_adapter_messagecode Message(void) const; | |
185 | ||
3ead056c LOK |
186 | /*! |
187 | * @return The messagecode (if provided) that this message is responding to | |
188 | */ | |
189 | cec_adapter_messagecode ResponseTo(void) const; | |
190 | ||
a75e3a5a LOK |
191 | /*! |
192 | * @return True when this message is a transmission, false otherwise. | |
193 | */ | |
194 | bool IsTranmission(void) const; | |
195 | ||
196 | /*! | |
197 | * @return True when the EOM bit is set, false otherwise. | |
198 | */ | |
199 | bool IsEOM(void) const; | |
200 | ||
201 | /*! | |
202 | * @return True when the ACK bit is set, false otherwise. | |
203 | */ | |
204 | bool IsACK(void) const; | |
205 | ||
206 | /*! | |
815dbda2 LOK |
207 | * @brief Checks whether the given messagecode is an error message. |
208 | * @param code The code to check. | |
209 | * @return True when it's an error, false otherwise. | |
210 | */ | |
211 | static bool MessageCodeIsError(const cec_adapter_messagecode code); | |
212 | ||
213 | /*! | |
214 | * @return True when this message contains an error code, false otherwise. | |
a75e3a5a LOK |
215 | */ |
216 | bool IsError(void) const; | |
217 | ||
815dbda2 LOK |
218 | /*! |
219 | * @return True when this message has been replied with an error code, false otherwise. | |
220 | */ | |
221 | bool ReplyIsError(void) const; | |
222 | ||
a75e3a5a LOK |
223 | /*! |
224 | * @return True when this message has been replied with an error code and needs to be retried, false otherwise. | |
225 | */ | |
226 | bool NeedsRetry(void) const; | |
227 | ||
228 | /*! | |
229 | * @return The logical address of the initiator, or CECDEVICE_UNKNOWN if unknown. | |
230 | */ | |
231 | cec_logical_address Initiator(void) const; | |
232 | ||
233 | /*! | |
234 | * @return The logical address of the destination, or CECDEVICE_UNKNOWN if unknown. | |
235 | */ | |
236 | cec_logical_address Destination(void) const; | |
237 | ||
238 | /*! | |
239 | * @return True when this message contains a start message, false otherwise. | |
240 | */ | |
241 | bool HasStartMessage(void) const; | |
242 | ||
243 | /*! | |
244 | * @brief Push this adapter message to the end of the given cec_command. | |
245 | * @param command The command to push this message to. | |
246 | * @return True when a full CEC message was received, false otherwise. | |
247 | */ | |
248 | bool PushToCecCommand(cec_command &command) const; | |
249 | ||
250 | /*! | |
251 | * @return The response messagecode. | |
252 | */ | |
253 | cec_adapter_messagecode Reply(void) const; | |
254 | ||
a75e3a5a LOK |
255 | cec_datapacket response; /**< the response to this message */ |
256 | cec_datapacket packet; /**< the actual data */ | |
257 | cec_adapter_message_state state; /**< the current state of this message */ | |
258 | int32_t transmit_timeout; /**< the timeout to use when sending this message */ | |
259 | uint8_t lineTimeout; /**< the default CEC line timeout to use when sending this message */ | |
daec0320 | 260 | bool bFireAndForget; /**< true to auto delete, don't wait for a response */ |
a75e3a5a LOK |
261 | |
262 | private: | |
263 | bool bNextByteIsEscaped; /**< true when the next byte that is added will be escaped, false otherwise */ | |
ef7696f5 LOK |
264 | }; |
265 | } |