summaryrefslogtreecommitdiff
path: root/src/tripcomputer/ctripcomputer.h
blob: 62747c79e10607e9d76e93515db88e7776f0c4d0 (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
150
151
152
153
154
155
156
157
/**
* @licence app begin@
* SPDX license identifier: MPL-2.0
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroën
*
* \file ctripcomputer.h
*
* \brief This file is part of lbs-fuel-stop-advisor.
*        It contains the declaration of the trip computer class
*
* \author Philippe Colliot <philippe.colliot@mpsa.com>
*
* \version 0.1
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), 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/.
*
* For further information see http://www.genivi.org/.
*
* List of changes:
* <date>, <name>, <description of change>
* <date>, <name>, <description of change>
*
* @licence end@
*/

#ifndef CTRIPCOMPUTER_H
#define CTRIPCOMPUTER_H

#include "ctripcomputertypes.h"


#define GET_UNDEFINED_VALUE(a) (static_cast<typeof(a)>(pow(2,8*pow(2,sizeof(a)))-1))

class CTripComputer
{
public:
    enum TRIPCOMPUTER_Constants {
        TRIPCOMPUTER_ODOMETER = 0x0020,
        TRIPCOMPUTER_FUEL_LEVEL = 0x0021,
        TRIPCOMPUTER_DISTANCE = 0x0030,
        TRIPCOMPUTER_TIME = 0x0031,
        TRIPCOMPUTER_AVERAGE_FUEL_CONSUMPTION_PER_DISTANCE = 0x0032,
        TRIPCOMPUTER_AVERAGE_SPEED = 0x0033,
        TRIPCOMPUTER_TANK_DISTANCE = 0x0034,
        TRIPCOMPUTER_INSTANT_FUEL_CONSUMPTION_PER_DISTANCE = 0x0035
    };

    enum {
        TRIP_NUMBER = 2,
        TRIP_NUMBER_1 = 0,
        SAMPLING_TIME = 1, /*!< Sampling time of 1 sec. */
        INSTANT_FUEL_CONSUMPTION_COEFFICIENT = 10/SAMPLING_TIME, /*!< Time constant for the instant fuel consumption. */
        LAST_QUARTER_FUEL_CONSUMPTION_COEFFICIENT = 90/SAMPLING_TIME, /*!< Time constant for the last quarter fuel consumption. */
        DISTANCE_THRESHOLD = 40000, /*!< Threshold for trip data calculation in cm. */
        INSTANT_FUEL_CONSUMPTION_MAX_VALUE = 300, /*!< in tenth of liters per 100 km. */
        INSTANT_FUEL_CONSUMPTION_START_VALUE = 50, /*!< To set an initial value of 50 µl/m (5 l/100), in order to avoid wrong tank distance the first time. */
        CONVERT_SECOND_IN_MILLISECOND = 1000,
        CONVERT_HOUR_IN_SECOND = 3600,
        CONVERT_METER_IN_CENTIMER = 100,
        CONVERT_KM_IN_METER = 1000,
        CONVERT_KM_IN_HM = 10,
        CONVERT_100KM_IN_CM = 100*CONVERT_KM_IN_METER*CONVERT_METER_IN_CENTIMER,
        CONVERT_LITER_IN_MICROLITER = 1000000,
        CONVERT_LITER_IN_DL = 10,
        CONVERT_DL_IN_MICROLITER = CONVERT_LITER_IN_MICROLITER/CONVERT_LITER_IN_DL
    };

    /*!
     *  \brief Constructor.
     *
     */
    CTripComputer();

    /*!
     *  \brief Initialization.
     *
     */
    void Initialize(uint16_t instantFuelConsumptionStartValue);

    /*!
     *  \brief Refresh the input values of the trips, calculate and update the trip number output values
     *
     *  \param tripComputerInput : basic input data
     */
    void RefreshTripComputerInput(tripComputerInput_t tripComputerInput);

    /*!
     *  \brief Get the version of the trip computer
     *
     *  \return The version
     */
    version_t GetVersion();

    /*!
     *  \brief Get the supported trip numbers
     *
     *   \return Supported trip numbers
     */
    uint8_t GetSupportedTripNumbers();

    /*!
     *  \brief Get the trip values of a given trip number
     *
     *  \param number : number of the trip
     *
     *  \return dictionary of trip values
     */
    tupleVariantTripComputer_t GetTripData(const uint8_t &number);

    /*!
     *  \brief Get the data not depending of a trip
     *
     *
     *  \return dictionary of trip values
     */
    tupleVariantTripComputer_t GetInstantData();

    /*!
     *  \brief Reset a given trip
     *
     *  \param number : number of the trip
     *
     */
    void ResetTrip(const uint8_t &number);

    /*!
     *  \brief Set the units used for each value
     *
     *  \param data : dictionary of unit per value
     *
     */
    void SetUnits(const tupleInt32_t &data);

    /*!
     *  \brief Get the basic data of a given trip (for testing)
     *
     *  \param number : number of the trip
     *
     *  \return trip data
     */
    tripBasicData_t GetTripBasicData(const uint8_t &number);


private:
    version_t m_version;
    uint8_t m_tripNumbers;
    vector<trip_t> m_tripData;
    tupleInt32_t m_units;
    bool m_firstRefresh;
    tripComputerInput_t m_lastTripComputerInput;
};

#endif // CTRIPCOMPUTER_H