• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ANDROID_HARDWARE_UWB_UWBCHIP
18 #define ANDROID_HARDWARE_UWB_UWBCHIP
19 
20 #include <vector>
21 #include <android-base/logging.h>
22 
23 
24 #include <aidl/android/hardware/uwb/BnUwbChip.h>
25 #include <aidl/android/hardware/uwb/IUwbClientCallback.h>
26 
27 namespace android {
28 namespace hardware {
29 namespace uwb {
30 namespace impl {
31 using namespace ::aidl::android::hardware::uwb;
32 // Default implementation mean't to be used on simulator targets.
33 class UwbChip : public BnUwbChip {
34   public:
35     UwbChip(const std::string& name);
36     virtual ~UwbChip();
37 
38     ::ndk::ScopedAStatus getName(std::string* name) override;
39     ::ndk::ScopedAStatus open(const std::shared_ptr<IUwbClientCallback>& clientCallback) override;
40     ::ndk::ScopedAStatus close() override;
41     ::ndk::ScopedAStatus coreInit() override;
42     ::ndk::ScopedAStatus getSupportedAndroidUciVersion(int32_t* version) override;
43     ::ndk::ScopedAStatus sendUciMessage(const std::vector<uint8_t>& data,
44                                         int32_t* bytes_written) override;
45 
46     ::ndk::ScopedAStatus sessionInit(int32_t sessionId) override;
eventCallback(uint8_t event,uint8_t status)47   static void eventCallback(uint8_t event, uint8_t status) {
48   if (mClientCallback != nullptr) {
49       auto ret = mClientCallback->onHalEvent((UwbEvent)event,
50                                       (UwbStatus)status);
51       if (!ret.isOk()) {
52           LOG(ERROR) << "Failed to call back into uwb process";
53       }
54     }
55   }
dataCallback(uint16_t data_len,uint8_t * p_data)56   static void dataCallback(uint16_t data_len, uint8_t* p_data) {
57       std::vector<uint8_t> data;
58       data.assign(p_data, p_data + data_len);
59       if (mClientCallback != nullptr) {
60           auto ret = mClientCallback->onUciMessage(data);
61           if (!ret.isOk()) {
62               LOG(ERROR) << "Failed to data call back into uwb process";
63           }
64       }
65   }
66 
67 
68   private:
69     std::string name_;
70     static std::shared_ptr<IUwbClientCallback> mClientCallback;
71 };
72 }  // namespace impl
73 }  // namespace uwb
74 }  // namespace hardware
75 }  // namespace android
76 
77 #endif  // ANDROID_HARDWARE_UWB_UWBCHIP
78