summaryrefslogtreecommitdiff
path: root/enhanced-position-service/test/enhanced-position-client.cpp
blob: b68c1e251d42c6f70885e1aa790b3e404b54e6da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**************************************************************************
* @licence app begin@
*
* SPDX-License-Identifier: MPL-2.0
*
* \ingroup EnhancedPositionService
* \author Marco Residori <marco.residori@xse.de>
*
* \copyright Copyright (C) 2014, XS Embedded GmbH
* 
* \license
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @licence end@
**************************************************************************/

#include <signal.h>
#include <stdio.h>

#include "enhanced-position-client.h"
#include "positioning-constants.h"
#include "log.h"

using namespace std;
DBus::BusDispatcher dispatcher;
DBus::DefaultTimeout *timeout;

DLT_DECLARE_CONTEXT(gCtx);

EnhancedPositionClient::EnhancedPositionClient(DBus::Connection &connection, const char *path, const char *name)
  : DBus::ObjectProxy(connection, path, name)
{
}

void EnhancedPositionClient::PositionUpdate(const std::vector< uint16_t >& changedValues)
{
  LOG_INFO_MSG(gCtx,"Position Update");
  
  // retrieve the data 
  std::map< uint16_t, ::DBus::Variant > posData = GetData(changedValues);

  for (int i = 0; i < changedValues.size(); i++)
  {
    if (changedValues[i] == POS_LATITUDE)
    {
      LOG_INFO(gCtx,"LAT=%lf", posData[POS_LATITUDE].reader().get_double());
    }

    if (changedValues[i] == POS_LONGITUDE)
    {
      LOG_INFO(gCtx,"LON=%lf", posData[POS_LONGITUDE].reader().get_double());
    }

    if (changedValues[i] == POS_ALTITUDE)
    {
      LOG_INFO(gCtx,"ALT=%lf", posData[POS_ALTITUDE].reader().get_double());
    }

    if (changedValues[i] == POS_SPEED)
    {
      LOG_INFO(gCtx,"SPEED=%lf", posData[POS_SPEED].reader().get_double());
    }

    if (changedValues[i] == POS_CLIMB)
    {
      LOG_INFO(gCtx,"CLIMB=%lf", posData[POS_CLIMB].reader().get_double());
    }

    if (changedValues[i] == POS_HEADING)
    {
      LOG_INFO(gCtx,"HEADING=%lf", posData[POS_HEADING].reader().get_double());
    }
  }

}

void EnhancedPositionClient::RotationRateUpdate(const std::vector< uint16_t >& changedValues)
{
  LOG_INFO_MSG(gCtx,"RotationRateUpdate");
}

void EnhancedPositionClient::AccuracyUpdate(const std::vector< uint16_t >& changedValues)
{
  LOG_INFO_MSG(gCtx,"AccuracyUpdate");
}

void EnhancedPositionClient::SatelliteInfoUpdate(const std::vector< uint16_t >& changedValues)
{
  LOG_INFO_MSG(gCtx,"SatelliteInfoUpdate");
}

void EnhancedPositionClient::StatusUpdate(const std::vector< uint16_t >& changedValues)
{
  LOG_INFO_MSG(gCtx,"StatusUpdate");
}

void signalhandler(int sig)
{
  LOG_INFO_MSG(gCtx,"Signal received");
  dispatcher.leave();
}

int main()
{
  DLT_REGISTER_APP("ENHPOS", "EnhancedPositionClient");
  DLT_REGISTER_CONTEXT(gCtx,"EPCL", "Global Context"); // EPCL = EnhancedPositionService Client Application

  LOG_INFO_MSG(gCtx,"Starting EnhancedPositionClient...");

  signal(SIGTERM, signalhandler);
  signal(SIGINT, signalhandler);

  DBus::default_dispatcher = &dispatcher;

  // increase DBus-C++ frequency
  new DBus::DefaultTimeout(100, false, &dispatcher);

  DBus::Connection conn = DBus::Connection::SessionBus();

  EnhancedPositionClient client(conn, 
                                "/org/genivi/positioning/EnhancedPosition",
                                "org.genivi.positioning.EnhancedPosition");

  // dispatch
  dispatcher.enter();

  return 0;
}