1 /*
2 * Copyright 2020 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 #include "LnbTests.h"
18
onEvent(LnbEventType lnbEventType)19 Return<void> LnbCallback::onEvent(LnbEventType lnbEventType) {
20 android::Mutex::Autolock autoLock(mMsgLock);
21 ALOGD("[vts] lnb event received. Type: %d", lnbEventType);
22 mEventReceived = true;
23 mMsgCondition.signal();
24 return Void();
25 }
26
onDiseqcMessage(const hidl_vec<uint8_t> & diseqcMessage)27 Return<void> LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) {
28 string msg(diseqcMessage.begin(), diseqcMessage.end());
29 ALOGD("[vts] onDiseqcMessage %s", msg.c_str());
30 return Void();
31 }
32
getLnbIds(vector<uint32_t> & ids)33 AssertionResult LnbTests::getLnbIds(vector<uint32_t>& ids) {
34 Result status;
35 mService->getLnbIds([&](Result result, const hidl_vec<uint32_t>& lnbIds) {
36 status = result;
37 ids = lnbIds;
38 });
39 return AssertionResult(status == Result::SUCCESS);
40 }
41
openLnbById(uint32_t lnbId)42 AssertionResult LnbTests::openLnbById(uint32_t lnbId) {
43 Result status;
44 mService->openLnbById(lnbId, [&](Result result, const sp<ILnb>& lnb) {
45 mLnb = lnb;
46 status = result;
47 });
48 return AssertionResult(status == Result::SUCCESS);
49 }
50
openLnbByName(string lnbName,uint32_t & id)51 AssertionResult LnbTests::openLnbByName(string lnbName, uint32_t& id) {
52 Result status;
53 mService->openLnbByName(lnbName, [&](Result result, uint32_t lnbId, const sp<ILnb>& lnb) {
54 mLnb = lnb;
55 id = lnbId;
56 status = result;
57 });
58
59 return AssertionResult(status == Result::SUCCESS);
60 }
61
setLnbCallback()62 AssertionResult LnbTests::setLnbCallback() {
63 if (!mLnb) {
64 ALOGW("[vts] Open Lnb first");
65 return failure();
66 }
67 mLnbCallback = new LnbCallback();
68 auto callbackStatus = mLnb->setCallback(mLnbCallback);
69 return AssertionResult(callbackStatus.isOk());
70 }
71
setVoltage(LnbVoltage voltage)72 AssertionResult LnbTests::setVoltage(LnbVoltage voltage) {
73 if (!mLnb) {
74 ALOGW("[vts] Open Lnb first");
75 return failure();
76 }
77 Result status = mLnb->setVoltage(voltage);
78 return AssertionResult(status == Result::SUCCESS);
79 }
80
setTone(LnbTone tone)81 AssertionResult LnbTests::setTone(LnbTone tone) {
82 if (!mLnb) {
83 ALOGW("[vts] Open Lnb first");
84 return failure();
85 }
86 Result status = mLnb->setTone(tone);
87 return AssertionResult(status == Result::SUCCESS);
88 }
89
setSatellitePosition(LnbPosition position)90 AssertionResult LnbTests::setSatellitePosition(LnbPosition position) {
91 if (!mLnb) {
92 ALOGW("[vts] Open Lnb first");
93 return failure();
94 }
95 Result status = mLnb->setSatellitePosition(position);
96 return AssertionResult(status == Result::SUCCESS);
97 }
98
sendDiseqcMessage(vector<uint8_t> diseqcMsg)99 AssertionResult LnbTests::sendDiseqcMessage(vector<uint8_t> diseqcMsg) {
100 if (!mLnb) {
101 ALOGW("[vts] Open Lnb first");
102 return failure();
103 }
104 Result status = mLnb->sendDiseqcMessage(diseqcMsg);
105 return AssertionResult(status == Result::SUCCESS);
106 }
107
closeLnb()108 AssertionResult LnbTests::closeLnb() {
109 if (!mLnb) {
110 ALOGW("[vts] Open Lnb first");
111 return failure();
112 }
113 Result status = mLnb->close();
114 mLnb = nullptr;
115 mLnbCallback = nullptr;
116 return AssertionResult(status == Result::SUCCESS);
117 }
118