blob: 9338c7341cdefeb098b550cd727fa6f98f009721 [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
Amy Zhang78e3dad2021-04-01 19:25:21 -070051AssertionResult LnbTests::openLnbByName(string lnbName, uint32_t& id) {
Amy Zhange5a9da22020-06-01 19:12:29 -070052 Result status;
Amy Zhang78e3dad2021-04-01 19:25:21 -070053 mService->openLnbByName(lnbName, [&](Result result, uint32_t lnbId, const sp<ILnb>& lnb) {
Amy Zhange5a9da22020-06-01 19:12:29 -070054 mLnb = lnb;
Amy Zhang78e3dad2021-04-01 19:25:21 -070055 id = lnbId;
Amy Zhange5a9da22020-06-01 19:12:29 -070056 status = result;
57 });
58
59 return AssertionResult(status == Result::SUCCESS);
60}
61
62AssertionResult 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
72AssertionResult 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
81AssertionResult 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
90AssertionResult 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
99AssertionResult 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
108AssertionResult 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}