1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "satellite_status.h" 17 18 #include <parcel.h> 19 20 #include "common_utils.h" 21 22 namespace OHOS { 23 namespace Location { SatelliteStatus()24SatelliteStatus::SatelliteStatus() 25 { 26 satellitesNumber_ = 0; 27 } 28 SatelliteStatus(SatelliteStatus & satelliteStatus)29SatelliteStatus::SatelliteStatus(SatelliteStatus& satelliteStatus) 30 { 31 satellitesNumber_ = satelliteStatus.GetSatellitesNumber(); 32 satelliteIds_ = satelliteStatus.GetSatelliteIds(); 33 carrierToNoiseDensitys_ = satelliteStatus.GetCarrierToNoiseDensitys(); 34 altitudes_ = satelliteStatus.GetAltitudes(); 35 azimuths_ = satelliteStatus.GetAzimuths(); 36 carrierFrequencies_ = satelliteStatus.GetCarrierFrequencies(); 37 } 38 ReadFromParcel(Parcel & parcel)39void SatelliteStatus::ReadFromParcel(Parcel& parcel) 40 { 41 satellitesNumber_ = parcel.ReadInt64(); 42 for (int i = 0; i < satellitesNumber_; i++) { 43 satelliteIds_.push_back(parcel.ReadInt64()); 44 carrierToNoiseDensitys_.push_back(parcel.ReadDouble()); 45 altitudes_.push_back(parcel.ReadDouble()); 46 azimuths_.push_back(parcel.ReadDouble()); 47 carrierFrequencies_.push_back(parcel.ReadDouble()); 48 } 49 } 50 Marshalling(Parcel & parcel) const51bool SatelliteStatus::Marshalling(Parcel& parcel) const 52 { 53 CHK_PARCEL_RETURN_VALUE(parcel.WriteInt64(satellitesNumber_)); 54 for (int i = 0; i < satellitesNumber_; i++) { 55 CHK_PARCEL_RETURN_VALUE(parcel.WriteInt64(satelliteIds_[i])); 56 CHK_PARCEL_RETURN_VALUE(parcel.WriteDouble(carrierToNoiseDensitys_[i])); 57 CHK_PARCEL_RETURN_VALUE(parcel.WriteDouble(altitudes_[i])); 58 CHK_PARCEL_RETURN_VALUE(parcel.WriteDouble(azimuths_[i])); 59 CHK_PARCEL_RETURN_VALUE(parcel.WriteDouble(carrierFrequencies_[i])); 60 } 61 return true; 62 } 63 Unmarshalling(Parcel & parcel)64std::unique_ptr<SatelliteStatus> SatelliteStatus::Unmarshalling(Parcel& parcel) 65 { 66 std::unique_ptr<SatelliteStatus> status = std::make_unique<SatelliteStatus>(); 67 status->ReadFromParcel(parcel); 68 return status; 69 } 70 } // namespace Location 71 } // namespace OHOS