1 /* 2 * Copyright (C) 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 use crate::uci::uci_hrcv::UciResponse; 18 use crate::uci::{HalCallback, JNICommand}; 19 use android_hardware_uwb::aidl::android::hardware::uwb::UwbStatus::UwbStatus; 20 use std::array::TryFromSliceError; 21 use std::option::Option; 22 use tokio::sync::{mpsc, oneshot}; 23 use uwb_uci_packets::StatusCode; 24 25 #[derive(Debug, thiserror::Error)] 26 pub enum UwbErr { 27 #[error("StatusCoode error: {0:?}")] 28 StatusCode(StatusCode), 29 #[error("UWBStatus error: {0:?}")] 30 UwbStatus(UwbStatus), 31 #[error("Binder error: {0}")] 32 Binder(#[from] binder::Status), 33 #[error("JNI error: {0}")] 34 Jni(#[from] jni::errors::Error), 35 #[error("IO error: {0}")] 36 Io(#[from] std::io::Error), 37 #[error("SendError for JNICommand: {0}")] 38 SendJNICommand( 39 #[from] mpsc::error::SendError<(JNICommand, Option<oneshot::Sender<UciResponse>>)>, 40 ), 41 #[error("SendError for HalCallback: {0}")] 42 SendHalCallback(#[from] mpsc::error::SendError<HalCallback>), 43 #[error("RecvError: {0}")] 44 RecvError(#[from] oneshot::error::RecvError), 45 #[error("Could not parse: {0}")] 46 Parse(#[from] uwb_uci_packets::Error), 47 #[error("Could not specialize: {0:?}")] 48 Specialize(Vec<u8>), 49 #[error("Could not convert: {0:?}")] 50 ConvertToArray(#[from] TryFromSliceError), 51 #[error("The dispatcher does not exist")] 52 NoneDispatcher, 53 #[error("Invalid args")] 54 InvalidArgs, 55 #[error("Exit")] 56 Exit, 57 #[error("Could not connect to HAL")] 58 HalUnavailable(#[from] binder::StatusCode), 59 #[error("Could not convert")] 60 ConvertToEnum(#[from] std::num::TryFromIntError), 61 #[error("Unknown error")] 62 Undefined, 63 } 64 65 impl UwbErr { failed() -> Self66 pub fn failed() -> Self { 67 UwbErr::UwbStatus(UwbStatus::FAILED) 68 } 69 refused() -> Self70 pub fn refused() -> Self { 71 UwbErr::UwbStatus(UwbStatus::REFUSED) 72 } 73 } 74