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.android.server.uwb.data; 18 19 import com.android.server.uwb.util.UwbUtil; 20 21 import java.util.Arrays; 22 23 public class UwbDlTDoAMeasurement { 24 public byte[] mMacAddress; 25 public int mStatus; 26 public int mMessageType; 27 public int mMessageControl; 28 public int mBlockIndex; 29 public int mRoundIndex; 30 public int mNLoS; 31 public float mAoaAzimuth; 32 public int mAoaAzimuthFom; 33 public float mAoaElevation; 34 public int mAoaElevationFom; 35 public int mRssi; 36 public long mTxTimestamp; 37 public long mRxTimestamp; 38 public float mAnchorCfo; 39 public float mCfo; 40 public long mInitiatorReplyTime; 41 public long mResponderReplyTime; 42 public int mInitiatorResponderTof; 43 public byte[] mAnchorLocation; 44 public byte[] mActiveRangingRounds; 45 UwbDlTDoAMeasurement(byte[] macAddress, int status, int messageType, int messageControl, int blockIndex, int roundIndex, int nLoS, int aoaAzimuth, int aoaAzimuthFom, int aoaElevation, int aoaElevationFom, int rssi, long txTimestamp, long rxTimestamp, int anchorCfo, int cfo, long initiatorReplyTime, long responderReplyTime, int initiatorResponderTof, byte[] anchorLocation, byte[] activeRangingRounds)46 public UwbDlTDoAMeasurement(byte[] macAddress, int status, int messageType, int messageControl, 47 int blockIndex, int roundIndex, int nLoS, int aoaAzimuth, int aoaAzimuthFom, 48 int aoaElevation, int aoaElevationFom, int rssi, long txTimestamp, long rxTimestamp, 49 int anchorCfo, int cfo, long initiatorReplyTime, long responderReplyTime, 50 int initiatorResponderTof, byte[] anchorLocation, byte[] activeRangingRounds) { 51 mMacAddress = macAddress; 52 mStatus = status; 53 mMessageType = messageType; 54 mMessageControl = messageControl; 55 mBlockIndex = blockIndex; 56 mRoundIndex = roundIndex; 57 mNLoS = nLoS; 58 mAoaAzimuth = toFloatFromQ9_7_Format(aoaAzimuth); 59 mAoaAzimuthFom = aoaAzimuthFom; 60 mAoaElevation = toFloatFromQ9_7_Format(aoaElevation); 61 mAoaElevationFom = aoaElevationFom; 62 mRssi = -(rssi / 2); 63 mTxTimestamp = txTimestamp; 64 mRxTimestamp = rxTimestamp; 65 mAnchorCfo = toFloatFromQ6_10_Format(anchorCfo); 66 mCfo = toFloatFromQ6_10_Format(cfo); 67 mInitiatorReplyTime = initiatorReplyTime; 68 mResponderReplyTime = responderReplyTime; 69 mInitiatorResponderTof = initiatorResponderTof; 70 mAnchorLocation = anchorLocation; 71 mActiveRangingRounds = activeRangingRounds; 72 } 73 getMacAddress()74 public byte[] getMacAddress() { 75 return mMacAddress; 76 } 77 getStatus()78 public int getStatus() { 79 return mStatus; 80 } 81 getMessageType()82 public int getMessageType() { 83 return mMessageType; 84 } 85 getMessageControl()86 public int getMessageControl() { 87 return mMessageControl; 88 } 89 getBlockIndex()90 public int getBlockIndex() { 91 return mBlockIndex; 92 } 93 getRoundIndex()94 public int getRoundIndex() { 95 return mRoundIndex; 96 } 97 getNLoS()98 public int getNLoS() { 99 return mNLoS; 100 } 101 getAoaAzimuth()102 public float getAoaAzimuth() { 103 return mAoaAzimuth; 104 } 105 getAoaAzimuthFom()106 public int getAoaAzimuthFom() { 107 return mAoaAzimuthFom; 108 } 109 getAoaElevation()110 public float getAoaElevation() { 111 return mAoaElevation; 112 } 113 getAoaElevationFom()114 public int getAoaElevationFom() { 115 return mAoaElevationFom; 116 } 117 getRssi()118 public int getRssi() { 119 return mRssi; 120 } 121 getTxTimestamp()122 public long getTxTimestamp() { 123 return mTxTimestamp; 124 } 125 getRxTimestamp()126 public long getRxTimestamp() { 127 return mRxTimestamp; 128 } 129 getAnchorCfo()130 public float getAnchorCfo() { 131 return mAnchorCfo; 132 } 133 getCfo()134 public float getCfo() { 135 return mCfo; 136 } 137 getInitiatorReplyTime()138 public long getInitiatorReplyTime() { 139 return mInitiatorReplyTime; 140 } 141 getResponderReplyTime()142 public long getResponderReplyTime() { 143 return mResponderReplyTime; 144 } 145 getInitiatorResponderTof()146 public int getInitiatorResponderTof() { 147 return mInitiatorResponderTof; 148 } 149 getAnchorLocation()150 public byte[] getAnchorLocation() { 151 return mAnchorLocation; 152 } 153 getActiveRangingRounds()154 public byte[] getActiveRangingRounds() { 155 return mActiveRangingRounds; 156 } 157 toFloatFromQ9_7_Format(int value)158 private float toFloatFromQ9_7_Format(int value) { 159 return UwbUtil.convertQFormatToFloat(UwbUtil.twos_compliment(value, 16), 160 9, 7); 161 } 162 toFloatFromQ6_10_Format(int value)163 private float toFloatFromQ6_10_Format(int value) { 164 return UwbUtil.convertQFormatToFloat(UwbUtil.twos_compliment(value, 16), 165 6, 10); 166 } 167 168 @Override toString()169 public String toString() { 170 return "UwbDLTDoAMeasurement{" + 171 "MacAddress=" + Arrays.toString(mMacAddress) + 172 ", Status=" + mStatus + 173 ", MessageType=" + mMessageType + 174 ", MessageControl=" + mMessageControl + 175 ", BlockIndex=" + mBlockIndex + 176 ", RoundIndex=" + mRoundIndex + 177 ", NLos=" + mNLoS + 178 ", AoaAzimuth=" + mAoaAzimuth + 179 ", AoaAzimuthFom=" + mAoaAzimuthFom + 180 ", AoaElevation=" + mAoaElevation + 181 ", AoaElevationFom=" + mAoaElevationFom + 182 ", Rssi=" + mRssi + 183 ", TxTimestamp=" + mTxTimestamp + 184 ", RxTimestamp=" + mRxTimestamp + 185 ", AnchorCfo=" + mAnchorCfo + 186 ", Cfo=" + mCfo + 187 ", InitiatorReplyTime=" + mInitiatorReplyTime + 188 ", ResponderReplyTime=" + mResponderReplyTime + 189 ", InitiatorResponderTof=" + mInitiatorResponderTof + 190 ", AnchorLocation=" + Arrays.toString(mAnchorLocation) + 191 ", ActiveRangingRounds=" + Arrays.toString(mActiveRangingRounds) + 192 '}'; 193 } 194 } 195