• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.rftest;
18 
19 import android.os.PersistableBundle;
20 
21 import androidx.annotation.IntDef;
22 import androidx.annotation.Nullable;
23 
24 import com.google.uwb.support.base.Params;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /** Defines parameters for RF test operation */
30 public abstract class RfTestParams extends Params {
31     public static final String PROTOCOL_NAME = "rftest";
32 
33     @Override
getProtocolName()34     public final String getProtocolName() {
35         return PROTOCOL_NAME;
36     }
37 
38     /** Checks if the {@link PersistableBundle} is based on the rftest protocol. */
isCorrectProtocol(PersistableBundle bundle)39     public static boolean isCorrectProtocol(PersistableBundle bundle) {
40         return isProtocol(bundle, PROTOCOL_NAME);
41     }
42 
43     /** Checks if the protocolName is rftest . */
isCorrectProtocol(String protocolName)44     public static boolean isCorrectProtocol(String protocolName) {
45         return protocolName.equals(PROTOCOL_NAME);
46     }
47 
48     /** Session Id */
49     @Retention(RetentionPolicy.SOURCE)
50     @IntDef(value = {SESSION_ID_RFTEST})
51     public @interface SessionId {
52     }
53 
54     public static final int SESSION_ID_RFTEST = 0x00;
55 
56     /** Session Type */
57     @Retention(RetentionPolicy.SOURCE)
58     @IntDef(value = {SESSION_TYPE_RFTEST})
59     public @interface SessionType {
60     }
61 
62     public static final int SESSION_TYPE_RFTEST = 0xD0;
63 
64     /** Randomized PSDU default value 0 */
65     @Retention(RetentionPolicy.SOURCE)
66     @IntDef(
67             value = {
68                     NO_RANDOMIZATION,
69                     RANDOMIZE_PSDU,
70             })
71     public @interface RandomizePsdu {
72     }
73 
74     public static final int NO_RANDOMIZATION = 0;
75     public static final int RANDOMIZE_PSDU = 1;
76 
77     /** Ranging bit field default value 0 */
78     @Retention(RetentionPolicy.SOURCE)
79     @IntDef(
80             value = {
81                     DISABLE_PHR,
82                     ENABLE_PHR,
83             })
84     public @interface PhrRangingBit {
85     }
86 
87     public static final int DISABLE_PHR = 0;
88     public static final int ENABLE_PHR = 1;
89 
90     /** STS INDEX increment default value 0 */
91     @Retention(RetentionPolicy.SOURCE)
92     @IntDef(
93             value = {
94                     NO_AUTO_INCR,
95                     AUTO_INCR_STS_INDEX,
96             })
97     public @interface StsIndexAutoIncr {
98     }
99 
100     public static final int NO_AUTO_INCR = 0;
101     public static final int AUTO_INCR_STS_INDEX = 1;
102 
103     /** STS bitmap default value 0 */
104     @Retention(RetentionPolicy.SOURCE)
105     @IntDef(
106             value = {
107                     NO_STS_DETECT_BITMAP,
108                     REPORT_STS_DETECT_BITMAP,
109             })
110     public @interface StsDetectBitmap {
111     }
112 
113     public static final int NO_STS_DETECT_BITMAP = 0;
114     public static final int REPORT_STS_DETECT_BITMAP = 1;
115 
116     /** RF Test command */
117     @IntDef(
118             value = {
119                     TEST_PERIODIC_TX,
120                     TEST_PER_RX,
121                     TEST_RX,
122                     TEST_LOOPBACK,
123                     TEST_SS_TWR,
124                     TEST_SR_RX,
125             })
126     public @interface RfTestOperationType {
127     }
128 
129     public static final int TEST_PERIODIC_TX = 0;
130     public static final int TEST_PER_RX = 1;
131     public static final int TEST_RX = 2;
132     public static final int TEST_LOOPBACK = 3;
133     public static final int TEST_SS_TWR = 4;
134     public static final int TEST_SR_RX = 5;
135 
136     @Nullable
intArrayToByteArray(@ullable int[] values)137     public static byte[] intArrayToByteArray(@Nullable int[] values) {
138         if (values == null) {
139             return null;
140         }
141         byte[] bytes = new byte[values.length];
142         for (int i = 0; i < values.length; i++) {
143             bytes[i] = (byte) values[i];
144         }
145         return bytes;
146     }
147 
148     @Nullable
byteArrayToIntArray(@ullable byte[] bytes)149     public static int[] byteArrayToIntArray(@Nullable byte[] bytes) {
150         if (bytes == null) {
151             return null;
152         }
153 
154         int[] values = new int[bytes.length];
155         for (int i = 0; i < values.length; i++) {
156             values[i] = bytes[i];
157         }
158         return values;
159     }
160 }
161