summaryrefslogtreecommitdiffstats
path: root/positioning_base_library/library/src/_pbMisc.cpp
blob: c52b7c624c902ac42fb1bf68523d47a0dc498f82 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
 * @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      : _pbMisc.cpp
 System name    : 05 Integration Platform
 Subsystem name : System common functions
 Title          : System API Time-of-day operations related processing group
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/

#include <vehicle_service/positioning_base_library.h>
#include "WPF_STD_private.h"

/*
 Declaration of constant data type
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
typedef struct {
    DWORD time_on_january1_1970;    /* Time on January 1, 1970 when it expressed */
    /* with the total second number from January 1, 1601 */
} BTIME_INSTANCE;

/*
 Internal function prototype declaration
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static DWORD    FileTimeToSeonds(FILETIME* p_ft);

/*
 Global Variable Definitions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BTIME_INSTANCE            g_instance;    // NOLINT(readability/nolint)  global class instance

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : MiscInit()
 * ABSTRACT  : Time-related processing instance initialization processing
 * NOTE      : Assign and hold 1/1/1970 to FILETIME variables
 * ARGUMENT  : None
 * RETURN    : RET_API        RET_NORMAL        Normal completion Note: Always this value
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
MiscInit(void) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    BTIME_INSTANCE    *p_inst = &g_instance;
    SYSTEMTIME        st;
    FILETIME          ft;
    BOOL              bret;

    /* Set the system time to the default value (January 1, 1970, 00:00:00). */
    st.wYear            = 1970;
    st.wMonth           = 1;
    st.wDayOfWeek       = 0;
    st.wDay             = 1;
    st.wHour            = 0;
    st.wMinute          = 0;
    st.wSecond          = 0;
    st.wMilliseconds    = 0;

    /* Converting System Time to File Time */
    bret = PbSystemTimeToFileTime(&st, &ft);
    if (bret != TRUE) {
        /* If the conversion fails, */
        p_inst->time_on_january1_1970 = 0;                        /* Save to instance with zero elapsed seconds */
    } else {
        /* If the conversion is successful, */
        p_inst->time_on_january1_1970 = FileTimeToSeonds(&ft);    /* Save File Time Elapsed Seconds to Instance */
    }

    return(RET_NORMAL);
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : FileTimeToSeonds()
 * ABSTRACT  : File Time -> Time Conversion Processing
 * NOTE      : Convert the file time to seconds
 * ARGUMENT  : FILETIME        *p_ft        Pointer to the file time structure
 * RETURN    : DWORD        Elapsing time(In seconds)
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static DWORD
FileTimeToSeonds(FILETIME* p_ft) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return 0;
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : MiscTerm()
 * ABSTRACT  : Time-related processing instance release processing
 * NOTE      :
 * ARGUMENT  : None
 * RETURN    : RET_API        RET_NORMAL        Normal completion Note: Always this value
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
MiscTerm(void) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return(RET_NORMAL);
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : Sleep()
 * ABSTRACT  : Sleep Processing
 * NOTE      : Cause the caller to sleep at the number of ticks specified by the argument
 * ARGUMENT  : u_int32        ticks        Sleep time(Specify in ticks)
 *           :                0            Sleep permanently
 *           :                1            Discard the time slice
 * RETURN    : RET_API        Normal completion Note: Always this value
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API
Sleep(u_int32 ticks) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    DWORD        milliseconds;

    switch (ticks) {
        case 0:            /* infinite delay. */
        {
            milliseconds = INFINITE;
            break;
        }
        case 1:            /* the thread to relinquish the remainder of its time slice */
            /* to any other thread of equal priority that is ready to run. */
            /* If there are no other threads of equal priority ready to run, */
            /* the function returns immediately, and the thread continues execution. */
        {
            milliseconds = 0;
            break;
        }
        default:        /* Time tranrate from per 10ms tick count to per milli second. */
            milliseconds = (DWORD)ticks * 10;
            break;
    }
    PbMilliSecSleep(static_cast<u_int32>(milliseconds));

    return(RET_NORMAL);
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : PbMilliSecSleep()
 * ABSTRACT  : Sleep Processing(Units of ms)
 * NOTE      : Cause the caller to sleep at the number of ticks specified by the argument
 * ARGUMENT  : u_int32        ul_mill_time    Sleep time(Specified in millimeters)
 *           :                0            Discard the time slice
 *           :                INFINITE    Sleep permanently
 * RETURN    : RET_API        Normal completion Note: Always this value
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API PbMilliSecSleep(u_int32 ul_mill_time) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    switch (ul_mill_time) {
        case 0:
        {
            /* Discard the time slice */
            sched_yield();
            break;
        }
        case INFINITE:
        {
            /* Abort processing indefinitely */
            while (1) {
                sleep(INFINITE);
            }
        }
        default:
            /* Sleep for Specified Time */
            usleep(ul_mill_time * 1000);
            break;
    }

    return RET_NORMAL;
}
// LCOV_EXCL_STOP

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * MODULE    : SecSleep()
 * ABSTRACT  : Sleep Processing(s unit)
 * NOTE      : Cause the caller to sleep at the number of ticks specified by the argument
 * ARGUMENT  : u_int32        ul_time        Sleep time(Specify in seconds)
 *           :                0            Discard the time slice
 *           :                INFINITE    Sleep permanently
 * RETURN    : RET_API        Normal completion Note: Always this value
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
RET_API SecSleep(u_int32 ul_time) {  // LCOV_EXCL_START 8:dead code
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    switch (ul_time) {
        case 0:
        {
            /* Discard the time slice */
            sched_yield();
            break;
        }
        case INFINITE:
        {
            /* Abort processing indefinitely */
            while (1) {
                sleep(INFINITE);
            }
        }
        default:
            /* Sleep for Specified Time */
            sleep(ul_time);
            break;
    }

    return RET_NORMAL;
}
// LCOV_EXCL_STOP

/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 End of File : _sysMisc.cpp
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/