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 #include <android-base/logging.h>
18 #include <gflags/gflags.h>
19 #include "host/libs/config/cuttlefish_config.h"
20 #include "host/libs/location/GnssClient.h"
21 
22 DEFINE_int32(instance_num, 1, "Which instance to read the configs from");
23 DEFINE_double(latitude, 37.8000064, "location latitude");
24 DEFINE_double(longitude, -122.3989209, "location longitude");
25 DEFINE_double(elevation, 2.5, "location elevation/altitude");
26 
27 namespace cuttlefish {
28 namespace {
29 
UpdateLocationCvdMain(int argc,char ** argv)30 int UpdateLocationCvdMain(int argc, char** argv) {
31   ::android::base::InitLogging(argv, android::base::StderrLogger);
32   google::ParseCommandLineFlags(&argc, &argv, true);
33 
34   auto config = CuttlefishConfig::Get();
35   if (!config) {
36     LOG(ERROR) << "Failed to obtain config object";
37     return 1;
38   }
39 
40   auto instance = config->ForInstance(FLAGS_instance_num);
41   auto server_port = instance.gnss_grpc_proxy_server_port();
42   std::string socket_name =
43       std::string("localhost:") + std::to_string(server_port);
44   LOG(INFO) << "Server port: " << server_port << " socket: " << socket_name
45             << std::endl;
46 
47   GnssClient gpsclient(
48       grpc::CreateChannel(socket_name, grpc::InsecureChannelCredentials()));
49 
50   GpsFixArray coordinates;
51   GpsFix location;
52   location.longitude=FLAGS_longitude;
53   location.latitude=FLAGS_latitude;
54   location.elevation=FLAGS_elevation;
55   coordinates.push_back(location);
56   auto status = gpsclient.SendGpsLocations(1000,coordinates);
57   CHECK(status.ok()) << "Failed to send gps location data \n";
58   if (!status.ok()) {
59     return 1;
60   }
61   return 0;
62 }
63 
64 }  // namespace
65 }  // namespace cuttlefish
66 
main(int argc,char ** argv)67 int main(int argc, char** argv) {
68   return cuttlefish::UpdateLocationCvdMain(argc, argv);
69 }
70