• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.hdmi;
18 
19 import libcore.util.EmptyArray;
20 
21 import java.util.Arrays;
22 
23 /**
24  * A class to encapsulate HDMI-CEC message used for the devices connected via
25  * HDMI cable to communicate with one another. A message is defined by its
26  * source and destination address, command (or opcode), and optional parameters.
27  */
28 public final class HdmiCecMessage {
29     public static final byte[] EMPTY_PARAM = EmptyArray.BYTE;
30 
31     private final int mSource;
32     private final int mDestination;
33 
34     private final int mOpcode;
35     private final byte[] mParams;
36 
37     /**
38      * Constructor.
39      */
HdmiCecMessage(int source, int destination, int opcode, byte[] params)40     public HdmiCecMessage(int source, int destination, int opcode, byte[] params) {
41         mSource = source;
42         mDestination = destination;
43         mOpcode = opcode & 0xFF;
44         mParams = Arrays.copyOf(params, params.length);
45     }
46 
47     /**
48      * Return the source address field of the message. It is the logical address
49      * of the device which generated the message.
50      *
51      * @return source address
52      */
getSource()53     public int getSource() {
54         return mSource;
55     }
56 
57     /**
58      * Return the destination address field of the message. It is the logical address
59      * of the device to which the message is sent.
60      *
61      * @return destination address
62      */
getDestination()63     public int getDestination() {
64         return mDestination;
65     }
66 
67     /**
68      * Return the opcode field of the message. It is the type of the message that
69      * tells the destination device what to do.
70      *
71      * @return opcode
72      */
getOpcode()73     public int getOpcode() {
74         return mOpcode;
75     }
76 
77     /**
78      * Return the parameter field of the message. The contents of parameter varies
79      * from opcode to opcode, and is used together with opcode to describe
80      * the action for the destination device to take.
81      *
82      * @return parameter
83      */
getParams()84     public byte[] getParams() {
85         return mParams;
86     }
87 
88     @Override
toString()89     public String toString() {
90         StringBuffer s = new StringBuffer();
91         s.append(String.format("<%s> src: %d, dst: %d",
92                 opcodeToString(mOpcode), mSource, mDestination));
93         if (mParams.length > 0) {
94             s.append(", params:");
95             for (byte data : mParams) {
96                 s.append(String.format(" %02X", data));
97             }
98         }
99         return s.toString();
100     }
101 
opcodeToString(int opcode)102     private static String opcodeToString(int opcode) {
103         switch (opcode) {
104             case Constants.MESSAGE_FEATURE_ABORT:
105                 return "Feature Abort";
106             case Constants.MESSAGE_IMAGE_VIEW_ON:
107                 return "Image View On";
108             case Constants.MESSAGE_TUNER_STEP_INCREMENT:
109                 return "Tuner Step Increment";
110             case Constants.MESSAGE_TUNER_STEP_DECREMENT:
111                 return "Tuner Step Decrement";
112             case Constants.MESSAGE_TUNER_DEVICE_STATUS:
113                 return "Tuner Device Staus";
114             case Constants.MESSAGE_GIVE_TUNER_DEVICE_STATUS:
115                 return "Give Tuner Device Status";
116             case Constants.MESSAGE_RECORD_ON:
117                 return "Record On";
118             case Constants.MESSAGE_RECORD_STATUS:
119                 return "Record Status";
120             case Constants.MESSAGE_RECORD_OFF:
121                 return "Record Off";
122             case Constants.MESSAGE_TEXT_VIEW_ON:
123                 return "Text View On";
124             case Constants.MESSAGE_RECORD_TV_SCREEN:
125                 return "Record Tv Screen";
126             case Constants.MESSAGE_GIVE_DECK_STATUS:
127                 return "Give Deck Status";
128             case Constants.MESSAGE_DECK_STATUS:
129                 return "Deck Status";
130             case Constants.MESSAGE_SET_MENU_LANGUAGE:
131                 return "Set Menu Language";
132             case Constants.MESSAGE_CLEAR_ANALOG_TIMER:
133                 return "Clear Analog Timer";
134             case Constants.MESSAGE_SET_ANALOG_TIMER:
135                 return "Set Analog Timer";
136             case Constants.MESSAGE_TIMER_STATUS:
137                 return "Timer Status";
138             case Constants.MESSAGE_STANDBY:
139                 return "Standby";
140             case Constants.MESSAGE_PLAY:
141                 return "Play";
142             case Constants.MESSAGE_DECK_CONTROL:
143                 return "Deck Control";
144             case Constants.MESSAGE_TIMER_CLEARED_STATUS:
145                 return "Timer Cleared Status";
146             case Constants.MESSAGE_USER_CONTROL_PRESSED:
147                 return "User Control Pressed";
148             case Constants.MESSAGE_USER_CONTROL_RELEASED:
149                 return "User Control Release";
150             case Constants.MESSAGE_GIVE_OSD_NAME:
151                 return "Give Osd Name";
152             case Constants.MESSAGE_SET_OSD_NAME:
153                 return "Set Osd Name";
154             case Constants.MESSAGE_SET_OSD_STRING:
155                 return "Set Osd String";
156             case Constants.MESSAGE_SET_TIMER_PROGRAM_TITLE:
157                 return "Set Timer Program Title";
158             case Constants.MESSAGE_SYSTEM_AUDIO_MODE_REQUEST:
159                 return "System Audio Mode Request";
160             case Constants.MESSAGE_GIVE_AUDIO_STATUS:
161                 return "Give Audio Status";
162             case Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE:
163                 return "Set System Audio Mode";
164             case Constants.MESSAGE_REPORT_AUDIO_STATUS:
165                 return "Report Audio Status";
166             case Constants.MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
167                 return "Give System Audio Mode Status";
168             case Constants.MESSAGE_SYSTEM_AUDIO_MODE_STATUS:
169                 return "System Audio Mode Status";
170             case Constants.MESSAGE_ROUTING_CHANGE:
171                 return "Routing Change";
172             case Constants.MESSAGE_ROUTING_INFORMATION:
173                 return "Routing Information";
174             case Constants.MESSAGE_ACTIVE_SOURCE:
175                 return "Active Source";
176             case Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS:
177                 return "Give Physical Address";
178             case Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS:
179                 return "Report Physical Address";
180             case Constants.MESSAGE_REQUEST_ACTIVE_SOURCE:
181                 return "Request Active Source";
182             case Constants.MESSAGE_SET_STREAM_PATH:
183                 return "Set Stream Path";
184             case Constants.MESSAGE_DEVICE_VENDOR_ID:
185                 return "Device Vendor Id";
186             case Constants.MESSAGE_VENDOR_COMMAND:
187                 return "Vendor Commandn";
188             case Constants.MESSAGE_VENDOR_REMOTE_BUTTON_DOWN:
189                 return "Vendor Remote Button Down";
190             case Constants.MESSAGE_VENDOR_REMOTE_BUTTON_UP:
191                 return "Vendor Remote Button Up";
192             case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID:
193                 return "Give Device Vendor Id";
194             case Constants.MESSAGE_MENU_REQUEST:
195                 return "Menu REquest";
196             case Constants.MESSAGE_MENU_STATUS:
197                 return "Menu Status";
198             case Constants.MESSAGE_GIVE_DEVICE_POWER_STATUS:
199                 return "Give Device Power Status";
200             case Constants.MESSAGE_REPORT_POWER_STATUS:
201                 return "Report Power Status";
202             case Constants.MESSAGE_GET_MENU_LANGUAGE:
203                 return "Get Menu Language";
204             case Constants.MESSAGE_SELECT_ANALOG_SERVICE:
205                 return "Select Analog Service";
206             case Constants.MESSAGE_SELECT_DIGITAL_SERVICE:
207                 return "Select Digital Service";
208             case Constants.MESSAGE_SET_DIGITAL_TIMER:
209                 return "Set Digital Timer";
210             case Constants.MESSAGE_CLEAR_DIGITAL_TIMER:
211                 return "Clear Digital Timer";
212             case Constants.MESSAGE_SET_AUDIO_RATE:
213                 return "Set Audio Rate";
214             case Constants.MESSAGE_INACTIVE_SOURCE:
215                 return "InActive Source";
216             case Constants.MESSAGE_CEC_VERSION:
217                 return "Cec Version";
218             case Constants.MESSAGE_GET_CEC_VERSION:
219                 return "Get Cec Version";
220             case Constants.MESSAGE_VENDOR_COMMAND_WITH_ID:
221                 return "Vendor Command With Id";
222             case Constants.MESSAGE_CLEAR_EXTERNAL_TIMER:
223                 return "Clear External Timer";
224             case Constants.MESSAGE_SET_EXTERNAL_TIMER:
225                 return "Set External Timer";
226             case Constants.MESSAGE_REPORT_SHORT_AUDIO_DESCRIPTOR:
227                 return "Repot Short Audio Descriptor";
228             case Constants.MESSAGE_REQUEST_SHORT_AUDIO_DESCRIPTOR:
229                 return "Request Short Audio Descriptor";
230             case Constants.MESSAGE_INITIATE_ARC:
231                 return "Initiate ARC";
232             case Constants.MESSAGE_REPORT_ARC_INITIATED:
233                 return "Report ARC Initiated";
234             case Constants.MESSAGE_REPORT_ARC_TERMINATED:
235                 return "Report ARC Terminated";
236             case Constants.MESSAGE_REQUEST_ARC_INITIATION:
237                 return "Request ARC Initiation";
238             case Constants.MESSAGE_REQUEST_ARC_TERMINATION:
239                 return "Request ARC Termination";
240             case Constants.MESSAGE_TERMINATE_ARC:
241                 return "Terminate ARC";
242             case Constants.MESSAGE_CDC_MESSAGE:
243                 return "Cdc Message";
244             case Constants.MESSAGE_ABORT:
245                 return "Abort";
246             default:
247                 return String.format("Opcode: %02X", opcode);
248         }
249     }
250 }
251 
252