summaryrefslogtreecommitdiff
path: root/gnss-service/test/gnss-service-client.c
blob: eddbf285297ae9dd2c1a38a22930934b8e0c448f (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**************************************************************************
* @licence app begin@
*
* SPDX-License-Identifier: MPL-2.0
*
* \ingroup GNSSService
* \author Marco Residori <marco.residori@xse.de>
*
* \copyright Copyright (C) 2013, 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 <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>

#include "gnss.h"
#include "gnss-ext.h"
#include "log.h"

DLT_DECLARE_CONTEXT(gCtx);


static void cbSpatial(const TGNSSSpatial spatial[], uint16_t numElements)
{
    int i;    
    if(spatial == NULL || numElements < 1)
    {
        LOG_ERROR_MSG(gCtx,"cbSpatial failed!");
        return;
    }

    for (i = 0; i<numElements; i++)
    {
        LOG_INFO(gCtx,"Location Update[%d/%d]: timestamp=%llu latitude=%.5f longitude=%.5f altitudeMSL=%.1f hSpeed=%.1f heading=%.1f\n hdop=%.1f usedSatellites=%d sigmaHPosition=%.1f sigmaHSpeed=%.1f sigmaHeading=%.1f fixStatus=%d fixTypeBits=0x%08X",
                 i+1,
                 numElements,
                 spatial[i].timestamp, 
                 spatial[i].latitude,
                 spatial[i].longitude,
                 spatial[i].altitudeMSL,
                 spatial[i].hSpeed,
                 spatial[i].heading,
                 spatial[i].hdop,
                 spatial[i].usedSatellites,
                 spatial[i].sigmaHPosition,
                 spatial[i].sigmaHSpeed,
                 spatial[i].sigmaHeading,
                 spatial[i].fixStatus,
                 spatial[i].fixTypeBits);
    }
}

static void cbSatelliteDetail(const TGNSSSatelliteDetail satelliteDetail[], uint16_t numElements)
{
    int i;    
    if(satelliteDetail == NULL || numElements < 1)
    {
        LOG_ERROR_MSG(gCtx,"cbSatelliteDetail failed!");
        return;
    }

    for (i = 0; i<numElements; i++)
    {
        LOG_INFO(gCtx,"SatelliteDetail Update[%d/%d]: satelliteId=%d azimuth=%d elevation=%d SNR=%d",
                 i+1,
                 numElements,
                 satelliteDetail[i].satelliteId, 
                 satelliteDetail[i].azimuth,
                 satelliteDetail[i].elevation,                                   
                 satelliteDetail[i].SNR);
    }    
}

bool checkMajorVersion(int expectedMajor)
{
    int major = -1;

    gnssGetVersion(&major, 0, 0);

    if(major != expectedMajor)
    {
        LOG_ERROR(gCtx,"Wrong API version: gnssGetVersion returned unexpected value %d != %d",
                  major, 
                  expectedMajor);

        return false;
    }

    return true;
}

void init()
{
    if(!checkMajorVersion(2))
    {
        exit(EXIT_FAILURE);
    }

    if(!gnssInit())
    {
        exit(EXIT_FAILURE);
    }

    if(!gnssExtendedInit())
    {
        exit(EXIT_FAILURE);
    }
}

int main()
{
    init();

    DLT_REGISTER_APP("GNSS", "GNSS-SERVICE-CLIENT");
    DLT_REGISTER_CONTEXT(gCtx,"GCLT", "Global Context");

    LOG_INFO_MSG(gCtx,"Starting gnss-service-client...");

    // register for GNSS
    gnssExtendedRegisterSatelliteDetailCallback(&cbSatelliteDetail);
    gnssExtendedRegisterSpatialCallback(&cbSpatial);

    // enter endless loop
    while(1)
    {
        sleep(1);
    }

    // deregister
    gnssExtendedDeregisterSatelliteDetailCallback(&cbSatelliteDetail);
    gnssExtendedDeregisterSpatialCallback(&cbSpatial);

    gnssExtendedDestroy();
    gnssDestroy();

    return EXIT_SUCCESS;
}