blob: 9080f597626f2bd1f6d237a6404ef00c88e6546a [file] [log] [blame]
Amy Zhange5a9da22020-06-01 19:12:29 -07001/*
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
19Return<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
27Return<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
33AssertionResult 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
42AssertionResult 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
51AssertionResult LnbTests::openLnbByName(string lnbName) {
52 Result status;
53 mService->openLnbByName(lnbName, [&](Result result, uint32_t /*lnbId*/, const sp<ILnb>& lnb) {
54 mLnb = lnb;
55 status = result;
56 });
57
58 return AssertionResult(status == Result::SUCCESS);
59}
60
61AssertionResult LnbTests::setLnbCallback() {
62 if (!mLnb) {
63 ALOGW("[vts] Open Lnb first");
64 return failure();
65 }
66 mLnbCallback = new LnbCallback();
67 auto callbackStatus = mLnb->setCallback(mLnbCallback);
68 return AssertionResult(callbackStatus.isOk());
69}
70
71AssertionResult LnbTests::setVoltage(LnbVoltage voltage) {
72 if (!mLnb) {
73 ALOGW("[vts] Open Lnb first");
74 return failure();
75 }
76 Result status = mLnb->setVoltage(voltage);
77 return AssertionResult(status == Result::SUCCESS);
78}
79
80AssertionResult LnbTests::setTone(LnbTone tone) {
81 if (!mLnb) {
82 ALOGW("[vts] Open Lnb first");
83 return failure();
84 }
85 Result status = mLnb->setTone(tone);
86 return AssertionResult(status == Result::SUCCESS);
87}
88
89AssertionResult LnbTests::setSatellitePosition(LnbPosition position) {
90 if (!mLnb) {
91 ALOGW("[vts] Open Lnb first");
92 return failure();
93 }
94 Result status = mLnb->setSatellitePosition(position);
95 return AssertionResult(status == Result::SUCCESS);
96}
97
98AssertionResult LnbTests::sendDiseqcMessage(vector<uint8_t> diseqcMsg) {
99 if (!mLnb) {
100 ALOGW("[vts] Open Lnb first");
101 return failure();
102 }
103 Result status = mLnb->sendDiseqcMessage(diseqcMsg);
104 return AssertionResult(status == Result::SUCCESS);
105}
106
107AssertionResult LnbTests::closeLnb() {
108 if (!mLnb) {
109 ALOGW("[vts] Open Lnb first");
110 return failure();
111 }
112 Result status = mLnb->close();
113 mLnb = nullptr;
114 mLnbCallback = nullptr;
115 return AssertionResult(status == Result::SUCCESS);
116}