summaryrefslogtreecommitdiffstats
path: root/positioning/server/src/Sensor/DeadReckoning_Common.cpp
blob: 9503b34318c36fd32c41231142a0b5cf440c5959 (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
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*******************************************************************************
 *  File name    :DeadReckoning_Common.cpp
 *  System name    :PastModel002
 *  Subsystem name  :DeadReckoning processes
 *  Program name  :DeadReckoning shared process(DEADRECKONING_COMMON)
 *  Module configuration  DeadReckoningMemcmp()        Functions for Common Processing Memory Block Comparisons
 *            DeadReckoningCheckDid()        Common Processing Data ID Check Function
 *            DeadReckoningGetDataMasterOffset()  Get function for common processing data master offset value
 ******************************************************************************/
#include "DeadReckoning_Common.h"
#include <vehicle_service/positioning_base_library.h>

/*************************************************/
/*       Global variable            */
/*************************************************/
static const DEADRECKONING_DID_OFFSET_TBL kGstDidListS[] = {
    /*      Data ID            Offset size    Reserved */
    {  VEHICLE_DID_DR_LONGITUDE,                      DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_LATITUDE,                       DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_ALTITUDE,                       DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_SPEED,                          DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_HEADING,                        DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_GYRO_OFFSET,                    DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_GYRO_SCALE_FACTOR,              DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_GYRO_SCALE_FACTOR_LEVEL,        DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_SPEED_PULSE_SCALE_FACTOR,       DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  VEHICLE_DID_DR_SPEED_PULSE_SCALE_FACTOR_LEVEL, DEADRECKONING_OFFSET_NORMAL,    {0, 0} },
    {  0,                        0,                  {0, 0} }    /* Termination code */
};

/*******************************************************************************
* MODULE   : DeadReckoningMemcmp
* ABSTRACT  : Functions for Common Processing Memory Block Comparisons
* FUNCTION  : Memory block comparison processing
* ARGUMENT  : *vp_data1  : Comparison target address 1
*       : *vp_data2  : Comparison target address 2
*       : uc_size  : Comparison Size
* NOTE    :
* RETURN   : DEADRECKONING_EQ    : No data change
*       : DEADRECKONING_NEQ  : Data change
******************************************************************************/
u_int8 DeadReckoningMemcmp(const void *vp_data1, const void *vp_data2, size_t uc_size) {  // LCOV_EXCL_START 8: dead code.  // NOLINT(whitespace/line_length)
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    u_int8 l_ret = DEADRECKONING_EQ;
    const u_int8 *p_data1 = (const u_int8 *)vp_data1;
    const u_int8 *p_data2 = (const u_int8 *)vp_data1;

    /* Loop by data size */
    while (uc_size > 0) {
        if (*p_data1 != *p_data2) {
            /* Data mismatch */
            l_ret = DEADRECKONING_NEQ;
            break;
        }
        p_data1++;
        p_data2++;
        uc_size--;
    }
    return(l_ret);
}

/*******************************************************************************
* MODULE   : DeadReckoningCheckDid
* ABSTRACT  : Common Processing Data ID Check Function
* FUNCTION  : Check if the specified DID corresponds to the vehicle sensor information
* ARGUMENT  : ul_did  : Data ID
* NOTE    :
* RETURN   : DEADRECKONING_INVALID  :Disabled
*       : DEADRECKONING_EFFECTIVE  :Enabled
******************************************************************************/
int32 DeadReckoningCheckDid(DID ul_did) {
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    int32 i = 0;
    int32 l_ret = DEADRECKONING_INVALID;

    while (0 != kGstDidListS[i].ul_did) {
        if (kGstDidListS[i].ul_did == ul_did) {
            /* DID enabled */
            l_ret = DEADRECKONING_EFFECTIVE;
            break;
        }
        i++;
    }
    return(l_ret);
}

/*******************************************************************************
* MODULE   : DeadReckoningGetDataMasterOffset
* ABSTRACT  : Get function for common processing data master offset value
* FUNCTION  : Get the fixed offset value for a given DID
* ARGUMENT  : ul_did  : Data ID
* NOTE    :
* RETURN   : Offset value(Returns 0 if DID is invalid)
*       :
******************************************************************************/
u_int16  DeadReckoningGetDataMasterOffset(DID ul_did) {
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    int32    i = 0;              /* Generic counters      */
    u_int16    us_ret = 0;            /* Return value of this function    */

    while (0 != kGstDidListS[i].ul_did) {
        if (kGstDidListS[i].ul_did == ul_did) {
            /* DID enabled */
            us_ret = kGstDidListS[i].us_offset;
            break;
        }
        i++;
    }
    return(us_ret);
}
// LCOV_EXCL_STOP