summaryrefslogtreecommitdiff
path: root/sensors-service/test/sensors-service-client.c
blob: 76f5cc83ac311aa9c7db681b3fd54dd5397fa715 (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
147
148
149
/**************************************************************************
* @licence app begin@
*
* SPDX-License-Identifier: MPL-2.0
*
* \ingroup SensorsService
* \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 all sns header files here even if they are not yet used.
//this helps us to find syntax error during compilation
#include "sns-init.h"
#include "acceleration.h"
#include "gyroscope.h"
#include "inclination.h"
#include "odometer.h"
#include "reverse-gear.h"
#include "slip-angle.h"
#include "steering-angle.h"
#include "vehicle-data.h"
#include "vehicle-speed.h"
#include "vehicle-state.h"
#include "wheel.h"
#include "log.h"

DLT_DECLARE_CONTEXT(gCtx);

static void cbGyroscope(const TGyroscopeData gyroData[], uint16_t numElements)
{
    if(gyroData == NULL || numElements < 1)
    {
        LOG_ERROR_MSG(gCtx,"error: cbGyroscope failed!");
        return;
    }

    LOG_INFO_MSG(gCtx,"Gyroscope Update");

    LOG_INFO(gCtx,"yawRate=%f", gyroData[0].yawRate);
    LOG_INFO(gCtx,"pitchRate=%f", gyroData[0].pitchRate);
    LOG_INFO(gCtx,"rollRate=%f", gyroData[0].rollRate);
}

static void cbWheel(const TWheelData wheelData[], uint16_t numElements)
{

    if(wheelData == NULL || numElements < 1)
    {
        LOG_ERROR_MSG(gCtx,"error: cbWheel failed!");
        return;
    }

    LOG_INFO_MSG(gCtx,"Wheel Update");
    LOG_INFO(gCtx,"data[0]=%.1f", wheelData[0].data[0]);
    LOG_INFO(gCtx,"data[1]=%.1f", wheelData[0].data[1]);
    LOG_INFO(gCtx,"data[2]=%.1f", wheelData[0].data[2]);
    LOG_INFO(gCtx,"data[3]=%.1f", wheelData[0].data[3]);


}

static void cbVehicleSpeed(const TVehicleSpeedData vehSpeed[], uint16_t numElements)
{
    if(vehSpeed == NULL || numElements < 1)
    {
        LOG_ERROR_MSG(gCtx,"error: cbVehicleSpeed failed!");
        return;
    }

    LOG_INFO_MSG(gCtx,"VehicleSpeed Update");

    LOG_INFO(gCtx,"vehicleSpeed=%f", vehSpeed[0].vehicleSpeed);
}

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

    snsGetVersion(&major, 0, 0);

    if(major != expectedMajor) 
    {
        LOG_ERROR(gCtx,"wrong API version: snsGetVersion returned unexpected value %d != %d", 
                  major, expectedMajor);
        return false;
    }

    return true;
}

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

    assert( snsInit() );
    assert( snsGyroscopeInit() );
    assert( snsWheelInit() );
    assert( snsVehicleSpeedInit() );
}

int main()
{
    init();

    DLT_REGISTER_APP("SNSS", "SENSORS-SERVICE");
    DLT_REGISTER_CONTEXT(gCtx,"SCLT", "Global Context");

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

    //register
    snsWheelRegisterCallback(&cbWheel);
    snsGyroscopeRegisterCallback(&cbGyroscope);
    snsVehicleSpeedRegisterCallback(&cbVehicleSpeed);

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

    //deregister
    snsWheelDeregisterCallback(&cbWheel);
    snsGyroscopeDeregisterCallback(&cbGyroscope);
    snsVehicleSpeedDeregisterCallback(&cbVehicleSpeed);

    snsGyroscopeDestroy();
    snsWheelDestroy();
    snsVehicleSpeedDestroy();
    snsDestroy();

    return EXIT_SUCCESS;
}