@@ -70,6 +70,10 @@ namespace Core::AirPods
7070 {
7171 APD_ASSERT (IsDesiredAdv (data));
7272 _data = data;
73+
74+ auto protocol = AppleCP::As<AppleCP::AirPods>(GetMfrData ());
75+ APD_ASSERT (protocol.has_value ());
76+ _protocol = std::move (protocol.value ());
7377 }
7478
7579 int16_t GetRssi () const
@@ -87,35 +91,35 @@ namespace Core::AirPods
8791 return _data.address ;
8892 }
8993
90- AppleCP::AirPods GetRawData () const
94+ std::vector< uint8_t > GetDesensitizedData () const
9195 {
92- auto protocol = AppleCP::As<AppleCP::AirPods>(GetMfrData ());
93- APD_ASSERT (protocol.has_value ());
94- return protocol.value ();
96+ auto desensitizedData = _protocol.Desensitize ();
97+
98+ std::vector<uint8_t > result (sizeof (desensitizedData), 0 );
99+ std::memcpy (result.data (), &desensitizedData, sizeof (desensitizedData));
100+ return result;
95101 }
96102
97103 DevState GetState () const
98104 {
99- auto protocol = GetRawData ();
100-
101105 DevState state;
102106
103- state.model = protocol .GetModel ();
104- state.side = protocol .GetBroadcastedSide ();
107+ state.model = _protocol .GetModel ();
108+ state.side = _protocol .GetBroadcastedSide ();
105109
106- state.pods .left .battery = protocol .GetLeftBattery ();
107- state.pods .left .isCharging = protocol .IsLeftCharging ();
108- state.pods .left .isInEar = protocol .IsLeftInEar ();
110+ state.pods .left .battery = _protocol .GetLeftBattery ();
111+ state.pods .left .isCharging = _protocol .IsLeftCharging ();
112+ state.pods .left .isInEar = _protocol .IsLeftInEar ();
109113
110- state.pods .right .battery = protocol .GetRightBattery ();
111- state.pods .right .isCharging = protocol .IsRightCharging ();
112- state.pods .right .isInEar = protocol .IsRightInEar ();
114+ state.pods .right .battery = _protocol .GetRightBattery ();
115+ state.pods .right .isCharging = _protocol .IsRightCharging ();
116+ state.pods .right .isInEar = _protocol .IsRightInEar ();
113117
114- state.caseBox .battery = protocol .GetCaseBattery ();
115- state.caseBox .isCharging = protocol .IsCaseCharging ();
118+ state.caseBox .battery = _protocol .GetCaseBattery ();
119+ state.caseBox .isCharging = _protocol .IsCaseCharging ();
116120
117- state.caseBox .isBothPodsInCase = protocol .IsBothPodsInCase ();
118- state.caseBox .isLidOpened = protocol .IsLidOpened ();
121+ state.caseBox .isBothPodsInCase = _protocol .IsBothPodsInCase ();
122+ state.caseBox .isLidOpened = _protocol .IsLidOpened ();
119123
120124 if (state.pods .left .battery .has_value ()) {
121125 state.pods .left .battery = state.pods .left .battery .value () * 10 ;
@@ -132,6 +136,7 @@ namespace Core::AirPods
132136
133137 private:
134138 Bluetooth::AdvertisementWatcher::ReceivedData _data;
139+ AppleCP::AirPods _protocol;
135140
136141 const std::vector<uint8_t >& GetMfrData () const
137142 {
@@ -310,6 +315,12 @@ namespace Core::AirPods
310315 bool OnDevicesUpdated (const Bluetooth::AdvertisementWatcher::ReceivedData &data)
311316 {
312317 Advertisement adv{data};
318+
319+ spdlog::trace (
320+ " AirPods advertisement received. Data: {}" ,
321+ Helper::ToString (adv.GetDesensitizedData ())
322+ );
323+
313324 auto state = adv.GetState ();
314325
315326 if (_leftAdv.has_value () && Clock::now () - _leftAdv->first >= Timeout) {
0 commit comments