1 /*
2  * Copyright (C) 2022 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;
18 
19 import static org.junit.Assert.assertArrayEquals;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 
23 import androidx.test.ext.junit.runners.AndroidJUnit4;
24 import androidx.test.filters.SmallTest;
25 
26 import com.google.uwb.support.ccc.CccParams;
27 import com.google.uwb.support.ccc.CccProtocolVersion;
28 import com.google.uwb.support.ccc.CccPulseShapeCombo;
29 import com.google.uwb.support.ccc.CccSpecificationParams;
30 import com.google.uwb.support.fira.FiraParams;
31 import com.google.uwb.support.fira.FiraProtocolVersion;
32 import com.google.uwb.support.fira.FiraSpecificationParams;
33 import com.google.uwb.support.generic.GenericSpecificationParams;
34 import com.google.uwb.support.radar.RadarParams;
35 import com.google.uwb.support.radar.RadarSpecificationParams;
36 
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 
40 import java.util.EnumSet;
41 import java.util.List;
42 
43 @SmallTest
44 @RunWith(AndroidJUnit4.class)
45 public class GenericTests {
46 
47     @Test
testSpecificationParams()48     public void testSpecificationParams() {
49         FiraProtocolVersion minPhyVersionSupported = new FiraProtocolVersion(1, 0);
50         FiraProtocolVersion maxPhyVersionSupported = new FiraProtocolVersion(2, 0);
51         FiraProtocolVersion minMacVersionSupported = new FiraProtocolVersion(1, 2);
52         FiraProtocolVersion maxMacVersionSupported = new FiraProtocolVersion(1, 2);
53         List<Integer> supportedChannels = List.of(5, 6, 8, 9);
54         EnumSet<FiraParams.AoaCapabilityFlag> aoaCapabilities =
55                 EnumSet.of(FiraParams.AoaCapabilityFlag.HAS_ELEVATION_SUPPORT);
56 
57         EnumSet<FiraParams.DeviceRoleCapabilityFlag> deviceRoleCapabilities =
58                 EnumSet.allOf(FiraParams.DeviceRoleCapabilityFlag.class);
59         boolean hasBlockStridingSupport = true;
60         boolean hasNonDeferredModeSupport = true;
61         boolean hasInitiationTimeSupport = true;
62         EnumSet<FiraParams.MultiNodeCapabilityFlag> multiNodeCapabilities =
63                 EnumSet.allOf(FiraParams.MultiNodeCapabilityFlag.class);
64         EnumSet<FiraParams.PrfCapabilityFlag> prfCapabilities =
65                 EnumSet.allOf(FiraParams.PrfCapabilityFlag.class);
66         EnumSet<FiraParams.RangingRoundCapabilityFlag> rangingRoundCapabilities =
67                 EnumSet.allOf(FiraParams.RangingRoundCapabilityFlag.class);
68         EnumSet<FiraParams.RframeCapabilityFlag> rframeCapabilities =
69                 EnumSet.allOf(FiraParams.RframeCapabilityFlag.class);
70         EnumSet<FiraParams.StsCapabilityFlag> stsCapabilities =
71                 EnumSet.allOf(FiraParams.StsCapabilityFlag.class);
72         EnumSet<FiraParams.PsduDataRateCapabilityFlag> psduDataRateCapabilities =
73                 EnumSet.allOf(FiraParams.PsduDataRateCapabilityFlag.class);
74         EnumSet<FiraParams.BprfParameterSetCapabilityFlag> bprfCapabilities =
75                 EnumSet.allOf(FiraParams.BprfParameterSetCapabilityFlag.class);
76         EnumSet<FiraParams.HprfParameterSetCapabilityFlag> hprfCapabilities =
77                 EnumSet.allOf(FiraParams.HprfParameterSetCapabilityFlag.class);
78         FiraSpecificationParams firaSpecificationParams =
79                 new FiraSpecificationParams.Builder()
80                         .setMinPhyVersionSupported(minPhyVersionSupported)
81                         .setMaxPhyVersionSupported(maxPhyVersionSupported)
82                         .setMinMacVersionSupported(minMacVersionSupported)
83                         .setMaxMacVersionSupported(maxMacVersionSupported)
84                         .setSupportedChannels(supportedChannels)
85                         .setAoaCapabilities(aoaCapabilities)
86                         .setDeviceRoleCapabilities(deviceRoleCapabilities)
87                         .hasBlockStridingSupport(hasBlockStridingSupport)
88                         .hasNonDeferredModeSupport(hasNonDeferredModeSupport)
89                         .hasInitiationTimeSupport(hasInitiationTimeSupport)
90                         .setMultiNodeCapabilities(multiNodeCapabilities)
91                         .setPrfCapabilities(prfCapabilities)
92                         .setRangingRoundCapabilities(rangingRoundCapabilities)
93                         .setRframeCapabilities(rframeCapabilities)
94                         .setStsCapabilities(stsCapabilities)
95                         .setPsduDataRateCapabilities(psduDataRateCapabilities)
96                         .setBprfParameterSetCapabilities(bprfCapabilities)
97                         .setHprfParameterSetCapabilities(hprfCapabilities)
98                         .build();
99 
100         CccProtocolVersion[] protocolVersions =
101                 new CccProtocolVersion[] {
102                     new CccProtocolVersion(1, 0),
103                     new CccProtocolVersion(2, 0),
104                     new CccProtocolVersion(2, 1)
105                 };
106 
107         Integer[] uwbConfigs = new Integer[] {CccParams.UWB_CONFIG_0, CccParams.UWB_CONFIG_1};
108         CccPulseShapeCombo[] pulseShapeCombos =
109                 new CccPulseShapeCombo[] {
110                     new CccPulseShapeCombo(
111                             CccParams.PULSE_SHAPE_SYMMETRICAL_ROOT_RAISED_COSINE,
112                             CccParams.PULSE_SHAPE_SYMMETRICAL_ROOT_RAISED_COSINE),
113                     new CccPulseShapeCombo(
114                             CccParams.PULSE_SHAPE_PRECURSOR_FREE,
115                             CccParams.PULSE_SHAPE_PRECURSOR_FREE),
116                     new CccPulseShapeCombo(
117                             CccParams.PULSE_SHAPE_PRECURSOR_FREE_SPECIAL,
118                             CccParams.PULSE_SHAPE_PRECURSOR_FREE_SPECIAL)
119                 };
120         int ranMultiplier = 200;
121         Integer[] chapsPerSlots =
122                 new Integer[] {CccParams.CHAPS_PER_SLOT_4, CccParams.CHAPS_PER_SLOT_12};
123         Integer[] syncCodes = new Integer[] {10, 23};
124         Integer[] channels = new Integer[] {CccParams.UWB_CHANNEL_5, CccParams.UWB_CHANNEL_9};
125         Integer[] hoppingConfigModes =
126                 new Integer[] {
127                     CccParams.HOPPING_CONFIG_MODE_ADAPTIVE, CccParams.HOPPING_CONFIG_MODE_CONTINUOUS
128                 };
129         Integer[] hoppingSequences =
130                 new Integer[] {CccParams.HOPPING_SEQUENCE_AES, CccParams.HOPPING_SEQUENCE_DEFAULT};
131         CccSpecificationParams.Builder paramsBuilder = new CccSpecificationParams.Builder();
132         for (CccProtocolVersion p : protocolVersions) {
133             paramsBuilder.addProtocolVersion(p);
134         }
135         for (int uwbConfig : uwbConfigs) {
136             paramsBuilder.addUwbConfig(uwbConfig);
137         }
138         for (CccPulseShapeCombo pulseShapeCombo : pulseShapeCombos) {
139             paramsBuilder.addPulseShapeCombo(pulseShapeCombo);
140         }
141         paramsBuilder.setRanMultiplier(ranMultiplier);
142         for (int chapsPerSlot : chapsPerSlots) {
143             paramsBuilder.addChapsPerSlot(chapsPerSlot);
144         }
145         for (int syncCode : syncCodes) {
146             paramsBuilder.addSyncCode(syncCode);
147         }
148         for (int channel : channels) {
149             paramsBuilder.addChannel(channel);
150         }
151         for (int hoppingConfigMode : hoppingConfigModes) {
152             paramsBuilder.addHoppingConfigMode(hoppingConfigMode);
153         }
154         for (int hoppingSequence : hoppingSequences) {
155             paramsBuilder.addHoppingSequence(hoppingSequence);
156         }
157         CccSpecificationParams cccSpecificationParams = paramsBuilder.build();
158 
159         RadarSpecificationParams radarSpecificationParams =
160                 new RadarSpecificationParams.Builder()
161                         .addRadarCapability(
162                                 RadarParams.RadarCapabilityFlag.HAS_RADAR_SWEEP_SAMPLES_SUPPORT)
163                         .build();
164 
165         boolean hasPowerStatsSupport = true;
166         GenericSpecificationParams genericSpecificationParams =
167                 new GenericSpecificationParams.Builder()
168                         .setFiraSpecificationParams(firaSpecificationParams)
169                         .setCccSpecificationParams(cccSpecificationParams)
170                         .setRadarSpecificationParams(radarSpecificationParams)
171                         .hasPowerStatsSupport(hasPowerStatsSupport)
172                         .build();
173         firaSpecificationParams = genericSpecificationParams.getFiraSpecificationParams();
174         cccSpecificationParams = genericSpecificationParams.getCccSpecificationParams();
175         radarSpecificationParams = genericSpecificationParams.getRadarSpecificationParams();
176 
177         assertEquals(minPhyVersionSupported, firaSpecificationParams.getMinPhyVersionSupported());
178         assertEquals(maxPhyVersionSupported, firaSpecificationParams.getMaxPhyVersionSupported());
179         assertEquals(minMacVersionSupported, firaSpecificationParams.getMinMacVersionSupported());
180         assertEquals(maxMacVersionSupported, firaSpecificationParams.getMaxMacVersionSupported());
181         assertEquals(supportedChannels, firaSpecificationParams.getSupportedChannels());
182         assertEquals(aoaCapabilities, firaSpecificationParams.getAoaCapabilities());
183         assertEquals(deviceRoleCapabilities, firaSpecificationParams.getDeviceRoleCapabilities());
184         assertEquals(hasBlockStridingSupport, firaSpecificationParams.hasBlockStridingSupport());
185         assertEquals(
186                 hasNonDeferredModeSupport, firaSpecificationParams.hasNonDeferredModeSupport());
187         assertEquals(hasInitiationTimeSupport, firaSpecificationParams.hasInitiationTimeSupport());
188         assertEquals(multiNodeCapabilities, firaSpecificationParams.getMultiNodeCapabilities());
189         assertEquals(prfCapabilities, firaSpecificationParams.getPrfCapabilities());
190         assertEquals(
191                 rangingRoundCapabilities, firaSpecificationParams.getRangingRoundCapabilities());
192         assertEquals(rframeCapabilities, firaSpecificationParams.getRframeCapabilities());
193         assertEquals(stsCapabilities, firaSpecificationParams.getStsCapabilities());
194         assertEquals(
195                 psduDataRateCapabilities, firaSpecificationParams.getPsduDataRateCapabilities());
196         assertEquals(bprfCapabilities, firaSpecificationParams.getBprfParameterSetCapabilities());
197         assertEquals(hprfCapabilities, firaSpecificationParams.getHprfParameterSetCapabilities());
198 
199         assertArrayEquals(cccSpecificationParams.getProtocolVersions().toArray(), protocolVersions);
200         assertArrayEquals(cccSpecificationParams.getUwbConfigs().toArray(), uwbConfigs);
201         assertArrayEquals(cccSpecificationParams.getPulseShapeCombos().toArray(), pulseShapeCombos);
202         assertEquals(cccSpecificationParams.getRanMultiplier(), ranMultiplier);
203         assertArrayEquals(cccSpecificationParams.getChapsPerSlot().toArray(), chapsPerSlots);
204         assertArrayEquals(cccSpecificationParams.getSyncCodes().toArray(), syncCodes);
205         assertArrayEquals(cccSpecificationParams.getChannels().toArray(), channels);
206         assertArrayEquals(
207                 cccSpecificationParams.getHoppingConfigModes().toArray(), hoppingConfigModes);
208         assertArrayEquals(cccSpecificationParams.getHoppingSequences().toArray(), hoppingSequences);
209 
210         assertEquals(hasPowerStatsSupport, genericSpecificationParams.hasPowerStatsSupport());
211         assertEquals(radarSpecificationParams.getRadarCapabilities().size(), 1);
212         assertTrue(
213                 radarSpecificationParams
214                         .getRadarCapabilities()
215                         .contains(RadarParams.RadarCapabilityFlag.HAS_RADAR_SWEEP_SAMPLES_SUPPORT));
216     }
217 }
218