Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 1 | /** |
| 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 Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 21 | using ::android::hardware::tv::tuner::V1_0::LnbPosition; |
| 22 | using ::android::hardware::tv::tuner::V1_0::LnbTone; |
| 23 | using ::android::hardware::tv::tuner::V1_0::LnbVoltage; |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 24 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | TunerLnb::TunerLnb(sp<ILnb> lnb, int id) { |
| 29 | mLnb = lnb; |
| 30 | mId = id; |
| 31 | } |
| 32 | |
| 33 | TunerLnb::~TunerLnb() { |
| 34 | mLnb = NULL; |
| 35 | mId = -1; |
| 36 | } |
| 37 | |
| 38 | Status 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 Zhang | d48a2a6 | 2021-04-12 21:39:19 -0700 | [diff] [blame] | 51 | if (status != Result::SUCCESS) { |
| 52 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 53 | } |
| 54 | return Status::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 57 | Status TunerLnb::setVoltage(int voltage) { |
| 58 | if (mLnb == NULL) { |
| 59 | ALOGE("ILnb is not initialized"); |
| 60 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 61 | } |
| 62 | |
| 63 | Result status = mLnb->setVoltage(static_cast<LnbVoltage>(voltage)); |
Amy Zhang | d48a2a6 | 2021-04-12 21:39:19 -0700 | [diff] [blame] | 64 | if (status != Result::SUCCESS) { |
| 65 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 66 | } |
| 67 | return Status::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 70 | Status TunerLnb::setTone(int tone) { |
| 71 | if (mLnb == NULL) { |
| 72 | ALOGE("ILnb is not initialized"); |
| 73 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 74 | } |
| 75 | |
| 76 | Result status = mLnb->setTone(static_cast<LnbTone>(tone)); |
Amy Zhang | d48a2a6 | 2021-04-12 21:39:19 -0700 | [diff] [blame] | 77 | if (status != Result::SUCCESS) { |
| 78 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 79 | } |
| 80 | return Status::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 83 | Status TunerLnb::setSatellitePosition(int position) { |
| 84 | if (mLnb == NULL) { |
| 85 | ALOGE("ILnb is not initialized"); |
| 86 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 87 | } |
| 88 | |
| 89 | Result status = mLnb->setSatellitePosition(static_cast<LnbPosition>(position)); |
Amy Zhang | d48a2a6 | 2021-04-12 21:39:19 -0700 | [diff] [blame] | 90 | if (status != Result::SUCCESS) { |
| 91 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 92 | } |
| 93 | return Status::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 96 | Status TunerLnb::sendDiseqcMessage(const vector<uint8_t>& diseqcMessage) { |
| 97 | if (mLnb == NULL) { |
| 98 | ALOGE("ILnb is not initialized"); |
| 99 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 100 | } |
| 101 | |
| 102 | Result status = mLnb->sendDiseqcMessage(diseqcMessage); |
Amy Zhang | d48a2a6 | 2021-04-12 21:39:19 -0700 | [diff] [blame] | 103 | if (status != Result::SUCCESS) { |
| 104 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 105 | } |
| 106 | return Status::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | Status TunerLnb::close() { |
Amy Zhang | 077cc1f | 2021-01-14 18:54:07 -0800 | [diff] [blame] | 110 | if (mLnb == NULL) { |
| 111 | ALOGE("ILnb is not initialized"); |
| 112 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 113 | } |
| 114 | |
Amy Zhang | 14a60e8 | 2021-02-11 15:22:52 -0800 | [diff] [blame] | 115 | Result res = mLnb->close(); |
| 116 | mLnb = NULL; |
| 117 | |
| 118 | if (res != Result::SUCCESS) { |
| 119 | return Status::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 120 | } |
| 121 | return Status::ok(); |
Amy Zhang | a046eee | 2021-01-12 14:44:58 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /////////////// ILnbCallback /////////////////////// |
| 125 | |
| 126 | Return<void> TunerLnb::LnbCallback::onEvent(const LnbEventType lnbEventType) { |
| 127 | if (mTunerLnbCallback != NULL) { |
| 128 | mTunerLnbCallback->onEvent((int)lnbEventType); |
| 129 | } |
| 130 | return Void(); |
| 131 | } |
| 132 | |
| 133 | Return<void> TunerLnb::LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) { |
| 134 | if (mTunerLnbCallback != NULL && diseqcMessage != NULL) { |
| 135 | vector<uint8_t> msg(begin(diseqcMessage), end(diseqcMessage)); |
| 136 | mTunerLnbCallback->onDiseqcMessage(msg); |
| 137 | } |
| 138 | return Void(); |
| 139 | } |
| 140 | } // namespace android |