blob: 4a5acf5a146d4669487a81aacc214db7f42f6ba9 [file] [log] [blame]
Amy Zhanga046eee2021-01-12 14:44:58 -08001/**
2 * Copyright 2021, 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#define LOG_TAG "TunerLnb"
18
19#include "TunerLnb.h"
20
Amy Zhang077cc1f2021-01-14 18:54:07 -080021using ::android::hardware::tv::tuner::V1_0::LnbPosition;
22using ::android::hardware::tv::tuner::V1_0::LnbTone;
23using ::android::hardware::tv::tuner::V1_0::LnbVoltage;
Amy Zhanga046eee2021-01-12 14:44:58 -080024using ::android::hardware::tv::tuner::V1_0::Result;
25
26namespace android {
27
28TunerLnb::TunerLnb(sp<ILnb> lnb, int id) {
29 mLnb = lnb;
30 mId = id;
31}
32
33TunerLnb::~TunerLnb() {
34 mLnb = NULL;
35 mId = -1;
36}
37
38Status TunerLnb::setCallback(
39 const shared_ptr<ITunerLnbCallback>& tunerLnbCallback) {
40 if (mLnb == NULL) {
41 ALOGE("ILnb is not initialized");
42 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
43 }
44
45 if (tunerLnbCallback == NULL) {
46 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::INVALID_ARGUMENT));
47 }
48
49 sp<ILnbCallback> lnbCallback = new LnbCallback(tunerLnbCallback);
50 Result status = mLnb->setCallback(lnbCallback);
Amy Zhanga046eee2021-01-12 14:44:58 -080051 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
52}
53
Amy Zhang077cc1f2021-01-14 18:54:07 -080054Status TunerLnb::setVoltage(int voltage) {
55 if (mLnb == NULL) {
56 ALOGE("ILnb is not initialized");
57 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
58 }
59
60 Result status = mLnb->setVoltage(static_cast<LnbVoltage>(voltage));
61 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
Amy Zhanga046eee2021-01-12 14:44:58 -080062}
63
Amy Zhang077cc1f2021-01-14 18:54:07 -080064Status TunerLnb::setTone(int tone) {
65 if (mLnb == NULL) {
66 ALOGE("ILnb is not initialized");
67 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
68 }
69
70 Result status = mLnb->setTone(static_cast<LnbTone>(tone));
71 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
Amy Zhanga046eee2021-01-12 14:44:58 -080072}
73
Amy Zhang077cc1f2021-01-14 18:54:07 -080074Status TunerLnb::setSatellitePosition(int position) {
75 if (mLnb == NULL) {
76 ALOGE("ILnb is not initialized");
77 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
78 }
79
80 Result status = mLnb->setSatellitePosition(static_cast<LnbPosition>(position));
81 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
Amy Zhanga046eee2021-01-12 14:44:58 -080082}
83
Amy Zhang077cc1f2021-01-14 18:54:07 -080084Status TunerLnb::sendDiseqcMessage(const vector<uint8_t>& diseqcMessage) {
85 if (mLnb == NULL) {
86 ALOGE("ILnb is not initialized");
87 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
88 }
89
90 Result status = mLnb->sendDiseqcMessage(diseqcMessage);
91 return Status::fromServiceSpecificError(static_cast<int32_t>(status));
Amy Zhanga046eee2021-01-12 14:44:58 -080092}
93
94Status TunerLnb::close() {
Amy Zhang077cc1f2021-01-14 18:54:07 -080095 if (mLnb == NULL) {
96 ALOGE("ILnb is not initialized");
97 return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
98 }
99
Amy Zhang14a60e82021-02-11 15:22:52 -0800100 Result res = mLnb->close();
101 mLnb = NULL;
102
103 if (res != Result::SUCCESS) {
104 return Status::fromServiceSpecificError(static_cast<int32_t>(res));
105 }
106 return Status::ok();
Amy Zhanga046eee2021-01-12 14:44:58 -0800107}
108
109/////////////// ILnbCallback ///////////////////////
110
111Return<void> TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) {
112 if (mTunerLnbCallback != NULL) {
113 mTunerLnbCallback->onEvent((int)lnbEventType);
114 }
115 return Void();
116}
117
118Return<void> TunerLnb::LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) {
119 if (mTunerLnbCallback != NULL && diseqcMessage != NULL) {
120 vector<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage));
121 mTunerLnbCallback->onDiseqcMessage(msg);
122 }
123 return Void();
124}
125} // namespace android