1 /*
2  * Copyright (C) 2019 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 android.hdmicec.cts;
18 
19 import java.util.HashMap;
20 import java.util.Map;
21 
22 public enum LogicalAddress {
23     TV(0x0),
24     RECORDER_1(0x1),
25     RECORDER_2(0x2),
26     TUNER_1(0x3),
27     PLAYBACK_1(0x4),
28     AUDIO_SYSTEM(0x5),
29     TUNER_2(0x6),
30     TUNER_3(0x7),
31     PLAYBACK_2(0x8),
32     RECORDER_3(0x9),
33     TUNER_4(0xa),
34     PLAYBACK_3(0xb),
35     RESERVED_1(0xc),
36     RESERVED_2(0xd),
37     SPECIFIC_USE(0xe),
38     BROADCAST(0xf),
39     UNKNOWN(0xf);
40 
41     private final int address;
42     private static Map deviceMap = new HashMap<>();
43 
44     @Override
toString()45     public String toString() {
46         return Integer.toHexString(this.address);
47     }
48 
49     static {
50         for (LogicalAddress device : LogicalAddress.values()) {
deviceMap.put(device.address, device)51             deviceMap.put(device.address, device);
52         }
53     }
54 
getDeviceTypeString()55     public String getDeviceTypeString() {
56         return Integer.toString(getDeviceType());
57     }
58 
getLogicalAddressAsInt()59     public int getLogicalAddressAsInt() {
60         return this.address;
61     }
62 
getDeviceType()63     public int getDeviceType() {
64         switch (this) {
65             case PLAYBACK_1:
66             case PLAYBACK_2:
67             case PLAYBACK_3:
68                 return HdmiCecConstants.CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
69             case TV:
70                 return HdmiCecConstants.CEC_DEVICE_TYPE_TV;
71             case AUDIO_SYSTEM:
72                 return HdmiCecConstants.CEC_DEVICE_TYPE_AUDIO_SYSTEM;
73             case RECORDER_1:
74             case RECORDER_2:
75             case RECORDER_3:
76                 return HdmiCecConstants.CEC_DEVICE_TYPE_RECORDER;
77             case TUNER_1:
78             case TUNER_2:
79             case TUNER_3:
80             case TUNER_4:
81                 return HdmiCecConstants.CEC_DEVICE_TYPE_TUNER;
82             default:
83                 return HdmiCecConstants.CEC_DEVICE_TYPE_RESERVED;
84         }
85     }
86 
getLogicalAddress(int address)87     public static LogicalAddress getLogicalAddress(int address) {
88         return (LogicalAddress) deviceMap.get(address);
89     }
90 
LogicalAddress(int address)91     private LogicalAddress(int address) {
92         this.address = address;
93     }
94 }
95