Skip to content

Commit

Permalink
Merge pull request #2741 from smartdevicelink/feature/gps_shift_support
Browse files Browse the repository at this point in the history
Feature/GPS Shift support
  • Loading branch information
ShobhitAd authored Jun 28, 2019
2 parents d9ac61f + a0a5e1e commit 18ca3b7
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2013, Ford Motor Company
Copyright (c) 2019, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -344,6 +344,10 @@ extern const char* activate;
extern const char* set_as_default;
extern const char* origin_app;

// sis data
extern const char* station_short_name;
extern const char* station_location;

// resuming
extern const char* application_commands;
extern const char* application_submenus;
Expand All @@ -367,8 +371,11 @@ extern const char* global_ign_on_counter;
extern const char* connection_info;
extern const char* is_download_complete;

extern const char* shifted;
extern const char* altitude;
extern const char* longitude_degrees;
extern const char* latitude_degrees;

extern const char* address;
extern const char* country_name;
extern const char* country_code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ class RCHelpers {
AppsModules;
static AppsModules GetApplicationsAllowedModules(
application_manager::ApplicationManager& app_mngr);

/**
* @brief RemoveRedundantGPSDataFromVIDataMsg removes redundant GPS data
* params from interior vehicle data response message if one contains radio
* station location data
* @param msg_params Params of the interior vehicle data response message
*/
static void RemoveRedundantGPSDataFromIVDataMsg(
smart_objects::SmartObject& msg_params);
};

} // namespace rc_rpc_plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include "rc_rpc_plugin/commands/mobile/get_interior_vehicle_data_response.h"
#include "rc_rpc_plugin/rc_helpers.h"
#include "utils/macro.h"

namespace rc_rpc_plugin {
Expand All @@ -49,6 +50,9 @@ GetInteriorVehicleDataResponse::~GetInteriorVehicleDataResponse() {}

void GetInteriorVehicleDataResponse::Run() {
LOG4CXX_AUTO_TRACE(logger_);

RCHelpers::RemoveRedundantGPSDataFromIVDataMsg(
(*message_)[app_mngr::strings::msg_params]);
application_manager_.GetRPCService().SendMessageToMobile(message_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void OnInteriorVehicleDataNotification::Run() {
typedef std::vector<application_manager::ApplicationSharedPtr> AppPtrs;
AppPtrs apps = RCRPCPlugin::GetRCApplications(application_manager_);

RCHelpers::RemoveRedundantGPSDataFromIVDataMsg(
(*message_)[app_mngr::strings::msg_params]);
for (AppPtrs::iterator it = apps.begin(); it != apps.end(); ++it) {
DCHECK(*it);
application_manager::Application& app = **it;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,30 @@ RCHelpers::AppsModules RCHelpers::GetApplicationsAllowedModules(
}
return result;
}

void RCHelpers::RemoveRedundantGPSDataFromIVDataMsg(
smart_objects::SmartObject& msg_params) {
using namespace message_params;
using namespace application_manager::strings;

LOG4CXX_AUTO_TRACE(logger_);
auto& module_data = msg_params[kModuleData];
if (!module_data.keyExists(kRadioControlData) ||
!module_data[kRadioControlData].keyExists(kSisData) ||
!module_data[kRadioControlData][kSisData].keyExists(station_location)) {
return;
}

auto& location_data =
module_data[kRadioControlData][kSisData][station_location];
auto new_location_data =
smart_objects::SmartObject(smart_objects::SmartType_Map);
new_location_data[latitude_degrees] = location_data[latitude_degrees];
new_location_data[longitude_degrees] = location_data[longitude_degrees];
if (location_data.keyExists(altitude)) {
new_location_data[altitude] = location_data[altitude];

location_data = new_location_data;
}
}
} // namespace rc_rpc_plugin
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Ford Motor Company
* Copyright (c) 2019, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -248,7 +248,19 @@ TEST_F(
(*mobile_message)[application_manager::strings::msg_params]
[message_params::kModuleType] = module_type;
smart_objects::SmartObject radio_data;
smart_objects::SmartObject sis_data;
smart_objects::SmartObject gps_data;

gps_data[application_manager::strings::longitude_degrees] = 1.0;
gps_data[application_manager::strings::latitude_degrees] = 1.0;

sis_data[application_manager::strings::station_short_name] =
"dummy_short_name";
sis_data[application_manager::strings::station_location] = gps_data;

radio_data[message_params::kBand] = enums_value::kAM;
radio_data[message_params::kSisData] = sis_data;

std::shared_ptr<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>
command = CreateRCCommand<
rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void OnVehicleDataNotification::Run() {

for (; vehicle_data.end() != it; ++it) {
if (true == (*message_)[strings::msg_params].keyExists(it->first)) {
LOG4CXX_ERROR(logger_, "vehicle_data nanme" << it->first);
LOG4CXX_DEBUG(logger_, "vehicle_data name" << it->first);
auto vehicle_data_value =
(*message_)[strings::msg_params][it->first].asInt();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2019, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of the Ford Motor Company nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "gtest/gtest.h"

#include "application_manager/commands/commands_test.h"
#include "mobile/get_vehicle_data_response.h"
#include "smart_objects/smart_object.h"

namespace test {
namespace components {
namespace commands_test {
namespace mobile_commands_test {
namespace get_vehicle_data_response {

namespace am = ::application_manager;
using am::commands::MessageSharedPtr;
using vehicle_info_plugin::commands::GetVehicleDataResponse;

typedef std::shared_ptr<GetVehicleDataResponse> GetVehicleDataResponsePtr;

class GetVehicleDataResponseTest
: public CommandsTest<CommandsTestMocks::kIsNice> {};

TEST_F(GetVehicleDataResponseTest, GetVehicleDataResponse_SUCCESS) {
MessageSharedPtr message(CreateMessage(smart_objects::SmartType_Map));
GetVehicleDataResponsePtr command(
CreateCommand<GetVehicleDataResponse>(message));

EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, _));
command->Run();
}

} // namespace get_vehicle_data_response
} // namespace mobile_commands_test
} // namespace commands_test
} // namespace components
} // namespace test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Ford Motor Company
* Copyright (c) 2019, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -30,9 +30,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdint.h>
#include <map>
#include <vector>
#include <strings.h>

#include "gtest/gtest.h"
#include "mobile/on_vehicle_data_notification.h"
Expand All @@ -45,6 +43,8 @@
#include "smart_objects/smart_object.h"
#include "utils/custom_string.h"
#include "utils/helpers.h"
#include "vehicle_info_plugin/vehicle_info_app_extension.h"
#include "vehicle_info_plugin/vehicle_info_plugin.h"

namespace test {
namespace components {
Expand All @@ -62,49 +62,75 @@ using am::commands::MessageSharedPtr;
using vehicle_info_plugin::commands::OnVehicleDataNotification;

typedef std::shared_ptr<OnVehicleDataNotification> NotificationPtr;
typedef std::shared_ptr<vehicle_info_plugin::VehicleInfoAppExtension>
VehicleInfoAppExtensionPtr;
typedef DataAccessor<application_manager::ApplicationSet> ApplicationSetDA;

namespace {
const uint32_t kAppId = 1u;
const utils::custom_string::CustomString kAppName("test_app");
} // namespace

class OnVehicleDataNotificationTest
: public CommandsTest<CommandsTestMocks::kIsNice> {
public:
OnVehicleDataNotificationTest()
: command_msg_(CreateMessage(smart_objects::SmartType_Map))
, command_(CreateCommand<OnVehicleDataNotification>(command_msg_)) {}
OnVehicleDataNotificationTest() : mock_app_(CreateMockApp()) {}

MessageSharedPtr command_msg_;
NotificationPtr command_;
protected:
void SetUp() OVERRIDE {
ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId));
ON_CALL(*mock_app_, name()).WillByDefault(ReturnRef(kAppName));

ON_CALL(mock_message_helper_, PrintSmartObject(_))
.WillByDefault(Return(false));
}
MockAppPtr mock_app_;
};

MATCHER_P2(CheckMessageData, key, value, "") {
const bool kIsMobileProtocolTypeCorrect =
(*arg)[am::strings::params][am::strings::protocol_type].asInt() ==
am::commands::CommandImpl::mobile_protocol_type_;

const bool kIsProtocolVersionCorrect =
(*arg)[am::strings::params][am::strings::protocol_version].asInt() ==
am::commands::CommandImpl::protocol_version_;

const bool kIsNotificationCorrect =
(*arg)[am::strings::params][am::strings::message_type].asInt() ==
am::MessageType::kNotification;

const bool kIsConnectionKeyCorrect =
(*arg)[am::strings::params][am::strings::connection_key].asUInt() ==
kAppId;

const bool kAreMsgParamsCorrect =
(*arg)[am::strings::msg_params][key].asInt() == value;

using namespace helpers;
return Compare<bool, EQ, ALL>(true,
kIsMobileProtocolTypeCorrect,
kIsProtocolVersionCorrect,
kIsNotificationCorrect,
kIsConnectionKeyCorrect,
kAreMsgParamsCorrect);
TEST_F(OnVehicleDataNotificationTest, OnVehicleDataNotification_SUCCESS) {
MessageSharedPtr message(CreateMessage(smart_objects::SmartType_Map));
smart_objects::SmartObject gps_data;
gps_data[am::strings::longitude_degrees] = 1.0;
gps_data[am::strings::latitude_degrees] = 1.0;
gps_data[am::strings::shifted] = true;

(*message)[am::strings::msg_params][am::strings::gps] = gps_data;
(*message)[am::strings::msg_params][am::strings::speed] = 0;

NotificationPtr command(CreateCommand<OnVehicleDataNotification>(message));

vehicle_info_plugin::VehicleInfoPlugin vi_plugin;
VehicleInfoAppExtensionPtr vi_app_extention_ptr =
std::make_shared<vehicle_info_plugin::VehicleInfoAppExtension>(
vi_plugin, *mock_app_);
vi_app_extention_ptr->subscribeToVehicleInfo(
mobile_apis::VehicleDataType::VEHICLEDATA_GPS);
vi_app_extention_ptr->subscribeToVehicleInfo(
mobile_apis::VehicleDataType::VEHICLEDATA_SPEED);

EXPECT_CALL(*mock_app_,
QueryInterface(vehicle_info_plugin::VehicleInfoAppExtension::
VehicleInfoAppExtensionUID))
.WillOnce(Return(vi_app_extention_ptr));

application_manager::ApplicationSet apps;
apps.insert(mock_app_);
std::shared_ptr<sync_primitives::Lock> apps_lock =
std::make_shared<sync_primitives::Lock>();
ApplicationSetDA apps_da(apps, apps_lock);
EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(apps_da));

am::VehicleData vehicle_data;
vehicle_data.insert(am::VehicleData::value_type(
am::strings::gps, mobile_apis::VehicleDataType::VEHICLEDATA_GPS));
vehicle_data.insert(am::VehicleData::value_type(
am::strings::gps, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED));
EXPECT_CALL(mock_message_helper_, vehicle_data())
.WillOnce(ReturnRef(vehicle_data));

EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, _));

command->Run();
}

} // namespace on_vehicle_data_notification
Expand Down
8 changes: 8 additions & 0 deletions src/components/application_manager/src/smart_object_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ const char* activate = "activate";
const char* set_as_default = "setAsDefault";
const char* origin_app = "originApp";

// sis data
const char* station_short_name = "stationShortName";
const char* station_location = "stationLocation";

// resuming
const char* application_commands = "applicationCommands";
const char* application_submenus = "applicationSubMenus";
Expand Down Expand Up @@ -339,8 +343,12 @@ const char* time_stamp = "timeStamp";
const char* manual_text_entry = "manualTextEntry";
const char* image_type_supported = "imageTypeSupported";
const char* unexpected_disconnect = "unexpectedDisconnect";

const char* shifted = "shifted";
const char* altitude = "altitude";
const char* longitude_degrees = "longitudeDegrees";
const char* latitude_degrees = "latitudeDegrees";

const char* address = "address";
const char* country_name = "countryName";
const char* country_code = "countryCode";
Expand Down
7 changes: 7 additions & 0 deletions src/components/interfaces/HMI_API.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,13 @@
<param name="speed" type="Float" minvalue="0" maxvalue="500" mandatory="false">
<description>The speed in KPH</description>
</param>
<param name="shifted" type="Boolean" mandatory="false">
<description>
True, if GPS lat/long, time, and altitude have been purposefully shifted (requires a proprietary algorithm to unshift).
False, if the GPS data is raw and un-shifted.
If not provided, then value is assumed False.
</description>
</param>
</struct>

<struct name="SisData">
Expand Down
7 changes: 7 additions & 0 deletions src/components/interfaces/MOBILE_API.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,13 @@
<param name="speed" type="Float" minvalue="0" maxvalue="500" mandatory="true" since="2.0" until="5.0"/>
</history>
</param>
<param name="shifted" type="Boolean" mandatory="false" since="6.0">
<description>
True, if GPS lat/long, time, and altitude have been purposefully shifted (requires a proprietary algorithm to unshift).
False, if the GPS data is raw and un-shifted.
If not provided, then value is assumed False.
</description>
</param>
</struct>

<struct name="VehicleDataResult" since="2.0">
Expand Down

0 comments on commit 18ca3b7

Please sign in to comment.