1 /* 2 * Copyright (C) 2023 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 package com.google.uwb.support.radar; 18 19 import static com.google.uwb.support.fira.FiraParams.PREAMBLE_DURATION_T32_SYMBOLS; 20 import static com.google.uwb.support.fira.FiraParams.PREAMBLE_DURATION_T64_SYMBOLS; 21 22 import android.os.PersistableBundle; 23 24 import androidx.annotation.IntDef; 25 import androidx.annotation.IntRange; 26 27 import com.google.uwb.support.base.FlagEnum; 28 import com.google.uwb.support.base.Params; 29 30 import java.lang.annotation.Retention; 31 import java.lang.annotation.RetentionPolicy; 32 33 /** Defines parameters for radar operation */ 34 public abstract class RadarParams extends Params { 35 public static final String PROTOCOL_NAME = "radar"; 36 37 @Override getProtocolName()38 public final String getProtocolName() { 39 return PROTOCOL_NAME; 40 } 41 42 /** Checks if the {@link PersistableBundle} is based on the radar protocol. */ isCorrectProtocol(PersistableBundle bundle)43 public static boolean isCorrectProtocol(PersistableBundle bundle) { 44 return isProtocol(bundle, PROTOCOL_NAME); 45 } 46 47 /** Checks if the protocolName is radar . */ isCorrectProtocol(String protocolName)48 public static boolean isCorrectProtocol(String protocolName) { 49 return protocolName.equals(PROTOCOL_NAME); 50 } 51 52 /** Session Type */ 53 @Retention(RetentionPolicy.SOURCE) 54 @IntDef(value = {SESSION_TYPE_RADAR}) 55 public @interface SessionType {} 56 57 public static final int SESSION_TYPE_RADAR = 0xA1; 58 59 @Retention(RetentionPolicy.SOURCE) 60 @IntRange(from = 0) 61 public @interface BurstPeriod {} 62 63 @Retention(RetentionPolicy.SOURCE) 64 @IntRange(from = 0, to = 65535) 65 public @interface SweepPeriod {} 66 67 @Retention(RetentionPolicy.SOURCE) 68 @IntRange(from = 0, to = 255) 69 public @interface SweepsPerBurst {} 70 71 @Retention(RetentionPolicy.SOURCE) 72 @IntRange(from = 0) 73 public @interface SamplesPerSweep {} 74 75 public static final int SAMPLES_PER_SWEEP_DEFAULT = 64; 76 77 @Retention(RetentionPolicy.SOURCE) 78 @IntRange(from = -32768, to = 32767) 79 public @interface SweepOffset {} 80 81 public static final int SWEEP_OFFSET_DEFAULT = 0; 82 83 /** Preamble duration: Default is 128 symbols */ 84 @Retention(RetentionPolicy.SOURCE) 85 @IntDef( 86 value = { 87 PREAMBLE_DURATION_T32_SYMBOLS, 88 PREAMBLE_DURATION_T64_SYMBOLS, 89 PREAMBLE_DURATION_T128_SYMBOLS, 90 PREAMBLE_DURATION_T256_SYMBOLS, 91 PREAMBLE_DURATION_T512_SYMBOLS, 92 PREAMBLE_DURATION_T1024_SYMBOLS, 93 PREAMBLE_DURATION_T2048_SYMBOLS, 94 PREAMBLE_DURATION_T4096_SYMBOLS, 95 PREAMBLE_DURATION_T8192_SYMBOLS, 96 PREAMBLE_DURATION_T16384_SYMBOLS, 97 PREAMBLE_DURATION_T32768_SYMBOLS, 98 }) 99 public @interface PreambleDuration {} 100 101 public static final int PREAMBLE_DURATION_T128_SYMBOLS = 0x2; 102 public static final int PREAMBLE_DURATION_T256_SYMBOLS = 0x3; 103 public static final int PREAMBLE_DURATION_T512_SYMBOLS = 0x4; 104 public static final int PREAMBLE_DURATION_T1024_SYMBOLS = 0x5; 105 public static final int PREAMBLE_DURATION_T2048_SYMBOLS = 0x6; 106 public static final int PREAMBLE_DURATION_T4096_SYMBOLS = 0x7; 107 public static final int PREAMBLE_DURATION_T8192_SYMBOLS = 0x8; 108 public static final int PREAMBLE_DURATION_T16384_SYMBOLS = 0x9; 109 public static final int PREAMBLE_DURATION_T32768_SYMBOLS = 0xA; 110 111 /** UWB Channel selections */ 112 @Retention(RetentionPolicy.SOURCE) 113 @IntRange(from = 9, to = 127) 114 public @interface PreambleCodeIndex {} 115 116 @Retention(RetentionPolicy.SOURCE) 117 @IntRange(from = 1, to = 255) 118 public @interface SessionPriority {} 119 120 public static final int SESSION_PRIORITY_DEFAULT = 50; 121 122 /** Unlimited number of bursts */ 123 public static final int NUMBER_OF_BURSTS_DEFAULT = 0; 124 125 /** Bits Per Sample (details below) */ 126 @Retention(RetentionPolicy.SOURCE) 127 @IntDef( 128 value = { 129 BITS_PER_SAMPLES_32, 130 BITS_PER_SAMPLES_48, 131 BITS_PER_SAMPLES_64, 132 }) 133 public @interface BitsPerSample {} 134 135 public static final int BITS_PER_SAMPLES_32 = 0x0; 136 public static final int BITS_PER_SAMPLES_48 = 0x1; 137 public static final int BITS_PER_SAMPLES_64 = 0x2; 138 139 @Retention(RetentionPolicy.SOURCE) 140 @IntRange(from = 0, to = 65535) 141 public @interface NumberOfBursts {} 142 143 /** Radar Data Type (details below) */ 144 @Retention(RetentionPolicy.SOURCE) 145 @IntDef( 146 value = { 147 RADAR_DATA_TYPE_RADAR_SWEEP_SAMPLES, 148 }) 149 public @interface RadarDataType {} 150 151 public static final int RADAR_DATA_TYPE_RADAR_SWEEP_SAMPLES = 0; 152 153 public enum RadarCapabilityFlag implements FlagEnum { 154 HAS_RADAR_SWEEP_SAMPLES_SUPPORT(1); 155 156 private final long mValue; 157 RadarCapabilityFlag(long value)158 RadarCapabilityFlag(long value) { 159 mValue = value; 160 } 161 162 @Override getValue()163 public long getValue() { 164 return mValue; 165 } 166 } 167 } 168