4 const char* gStmEventName[] = {
16 const int gStmEventNo[] = {
18 STM_EVT_NO_DEACTIVATE,
19 STM_EVT_NO_PARKING_BRAKE_OFF,
20 STM_EVT_NO_PARKING_BRAKE_ON,
21 STM_EVT_NO_ACCEL_PEDAL_OFF,
22 STM_EVT_NO_ACCEL_PEDAL_ON,
23 STM_EVT_NO_TIMER_EXPIRED,
28 const char* gStmCategoryName[] = {
38 const int gStmCategoryNo[] = {
39 STM_CTG_NO_HOMESCREEN,
44 STM_CTG_NO_SYSTEM_ALERT,
45 STM_CTG_NO_RESTRICTION,
48 const char* gStmAreaName[] = {
55 "restriction.split.main",
56 "restriction.split.sub",
59 const int gStmAreaNo[] = {
62 STM_ARA_NO_SPLIT_MAIN,
65 STM_ARA_NO_RESTRICTION_NORMAL,
66 STM_ARA_NO_RESTRICTION_SPLIT_MAIN,
67 STM_ARA_NO_RESTRICTION_SPLIT_SUB,
71 const char* gStmParkingBrakeStateNo2Name[] = {
76 const char* gStmAccelPedalStateNo2Name[] = {
81 const char* gStmCarStateNo2Name[] = {
86 const char* gStmLampStateNo2Name[] = {
91 const char* gStmLayoutNo2Name[] = {
103 "restriction.split.main",
104 "restriction.split.sub",
107 stm_state_t g_crr_state;
108 stm_state_t g_prv_state;
109 int g_prv_restriction_state_car_stop = 0;
110 int g_prv_apps_state_car_stop = 0;
112 void stmInitialize() {
113 // Initialize previous state
114 memset(&g_prv_state, 0, sizeof(g_prv_state));
116 g_prv_state.layer.on_screen.state = gStmLayoutNoNone;
117 g_prv_state.layer.restriction.state = gStmLayoutNoNone;
118 g_prv_state.layer.apps.state = gStmLayoutNoNone;
119 g_prv_state.layer.homescreen.state = gStmLayoutNoNone;
120 g_prv_state.parking_brake.state = gStmParkingBrakeStateNoOn;
121 g_prv_state.accel_pedal.state = gStmAccelPedalStateNoOff;
122 g_prv_state.car.state = gStmCarStateNoStop;
123 g_prv_state.lamp.state = gStmLampStateNoOff;
125 // Initialize current state
126 g_crr_state = g_prv_state;
129 int stmTransitionState(int event, stm_state_t* state) {
130 int event_no, category_no, area_no;
131 int restriction_state, apps_state;
132 int parking_brake_state, accel_pedal_state, car_state, lamp_state;
134 event_no = event & STM_MSK_EVT_NO;
135 category_no = event & STM_MSK_CTG_NO;
136 area_no = event & STM_MSK_ARA_NO;
138 // Backup previous state
139 g_prv_state = g_crr_state;
141 // Get previous state
142 restriction_state = g_prv_state.layer.restriction.state;
143 apps_state = g_prv_state.layer.apps.state;
144 parking_brake_state = g_prv_state.parking_brake.state;
145 accel_pedal_state = g_prv_state.accel_pedal.state;
146 car_state = g_prv_state.car.state;
147 lamp_state = g_prv_state.lamp.state;
150 g_crr_state.layer.on_screen.is_changed = STM_FALSE;
151 g_crr_state.layer.restriction.is_changed = STM_FALSE;
152 g_crr_state.layer.apps.is_changed = STM_FALSE;
153 g_crr_state.layer.homescreen.is_changed = STM_FALSE;
154 g_crr_state.parking_brake.is_changed = STM_FALSE;
155 g_crr_state.accel_pedal.is_changed = STM_FALSE;
156 g_crr_state.car.is_changed = STM_FALSE;
157 g_crr_state.lamp.is_changed = STM_FALSE;
160 case STM_EVT_NO_ACTIVATE:
161 switch (category_no) {
162 case STM_CTG_NO_HOMESCREEN:
164 g_crr_state.layer.apps.state = gStmLayoutNoNone;
165 g_crr_state.layer.apps.is_changed = STM_TRUE;
168 g_crr_state.layer.homescreen.state = gStmLayoutNoHs;
169 g_crr_state.layer.homescreen.is_changed = STM_TRUE;
173 case STM_ARA_NO_FULL:
175 switch (apps_state) {
180 g_crr_state.layer.apps.state = gStmLayoutNoMf;
181 g_crr_state.layer.apps.is_changed = STM_TRUE;
185 case STM_ARA_NO_NORMAL:
187 switch (apps_state) {
192 g_crr_state.layer.apps.state = gStmLayoutNoM2;
193 g_crr_state.layer.apps.is_changed = STM_TRUE;
196 g_crr_state.layer.apps.state = gStmLayoutNoM1;
197 g_crr_state.layer.apps.is_changed = STM_TRUE;
200 case STM_ARA_NO_SPLIT_MAIN:
202 switch (apps_state) {
205 g_crr_state.layer.apps.state = gStmLayoutNoS2;
206 g_crr_state.layer.apps.is_changed = STM_TRUE;
215 case STM_CTG_NO_GENERAL:
217 case STM_ARA_NO_NORMAL:
219 switch (apps_state) {
224 g_crr_state.layer.apps.state = gStmLayoutNoG;
225 g_crr_state.layer.apps.is_changed = STM_TRUE;
234 case STM_CTG_NO_SPLITABLE:
236 case STM_ARA_NO_NORMAL:
238 switch (apps_state) {
240 g_crr_state.layer.apps.state = gStmLayoutNoM2;
241 g_crr_state.layer.apps.is_changed = STM_TRUE;
248 g_crr_state.layer.apps.state = gStmLayoutNoS1;
249 g_crr_state.layer.apps.is_changed = STM_TRUE;
253 case STM_ARA_NO_SPLIT_MAIN:
255 switch (apps_state) {
257 g_crr_state.layer.apps.state = gStmLayoutNoS2;
258 g_crr_state.layer.apps.is_changed = STM_TRUE;
261 g_crr_state.layer.apps.state = gStmLayoutNoS2;
262 g_crr_state.layer.apps.is_changed = STM_TRUE;
269 case STM_ARA_NO_SPLIT_SUB:
271 switch (apps_state) {
273 g_crr_state.layer.apps.state = gStmLayoutNoM2;
274 g_crr_state.layer.apps.is_changed = STM_TRUE;
277 g_crr_state.layer.apps.state = gStmLayoutNoM2;
278 g_crr_state.layer.apps.is_changed = STM_TRUE;
281 g_crr_state.layer.apps.state = gStmLayoutNoS2;
282 g_crr_state.layer.apps.is_changed = STM_TRUE;
285 g_crr_state.layer.apps.state = gStmLayoutNoS2;
286 g_crr_state.layer.apps.is_changed = STM_TRUE;
298 case STM_CTG_NO_RESTRICTION:
300 case STM_ARA_NO_RESTRICTION_NORMAL:
302 switch (restriction_state) {
303 case gStmLayoutNoNone:
304 g_crr_state.layer.restriction.state = gStmLayoutNoRestriction;
305 g_crr_state.layer.restriction.is_changed = STM_TRUE;
312 case STM_ARA_NO_RESTRICTION_SPLIT_MAIN:
314 switch (restriction_state) {
315 case gStmLayoutNoNone:
316 g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitMain;
317 g_crr_state.layer.restriction.is_changed = STM_TRUE;
324 case STM_ARA_NO_RESTRICTION_SPLIT_SUB:
326 switch (restriction_state) {
327 case gStmLayoutNoNone:
328 g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitSub;
329 g_crr_state.layer.restriction.is_changed = STM_TRUE;
345 case STM_EVT_NO_DEACTIVATE:
346 switch (category_no) {
347 case STM_CTG_NO_RESTRICTION:
349 switch (restriction_state) {
350 case gStmLayoutNoRestriction:
351 case gStmLayoutNoRestrictionSplitMain:
352 case gStmLayoutNoRestrictionSplitSub:
353 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
354 g_crr_state.layer.restriction.is_changed = STM_TRUE;
365 case STM_EVT_NO_PARKING_BRAKE_OFF:
366 if (gStmParkingBrakeStateNoOff != parking_brake_state) {
367 g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOff;
368 g_crr_state.parking_brake.is_changed = STM_TRUE;
371 case STM_EVT_NO_PARKING_BRAKE_ON:
372 if (gStmParkingBrakeStateNoOn != parking_brake_state) {
373 g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOn;
374 g_crr_state.parking_brake.is_changed = STM_TRUE;
377 case STM_EVT_NO_ACCEL_PEDAL_OFF:
378 if (gStmAccelPedalStateNoOff != accel_pedal_state) {
379 g_crr_state.accel_pedal.state = gStmAccelPedalStateNoOff;
380 g_crr_state.accel_pedal.is_changed = STM_TRUE;
383 case STM_EVT_NO_ACCEL_PEDAL_ON:
384 if (gStmAccelPedalStateNoOn != accel_pedal_state) {
385 g_crr_state.accel_pedal.state = gStmAccelPedalStateNoOn;
386 g_crr_state.accel_pedal.is_changed = STM_TRUE;
389 case STM_EVT_NO_LAMP_OFF:
390 if (gStmLampStateNoOff != lamp_state) {
391 g_crr_state.lamp.state = gStmLampStateNoOff;
392 g_crr_state.lamp.is_changed = STM_TRUE;
395 case STM_EVT_NO_LAMP_ON:
396 if (gStmLampStateNoOn != lamp_state) {
397 g_crr_state.lamp.state = gStmLampStateNoOn;
398 g_crr_state.lamp.is_changed = STM_TRUE;
407 if (g_crr_state.parking_brake.is_changed
408 || g_crr_state.accel_pedal.is_changed) {
409 if ((gStmParkingBrakeStateNoOff == g_crr_state.parking_brake.state)
410 && (gStmAccelPedalStateNoOn == g_crr_state.accel_pedal.state)){
411 if (gStmCarStateNoRun != car_state) {
412 // Car state is changed stop -> run
413 g_crr_state.car.state = gStmCarStateNoRun;
414 g_crr_state.car.is_changed = STM_TRUE;
416 // Update restriction layer
417 g_prv_restriction_state_car_stop = restriction_state;
418 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
419 g_crr_state.layer.restriction.is_changed = STM_TRUE;
422 g_prv_apps_state_car_stop = apps_state;
423 g_crr_state.layer.apps.state = gStmLayoutNoM1;
424 g_crr_state.layer.apps.is_changed = STM_TRUE;
428 if (gStmCarStateNoStop != car_state) {
429 // Car state is changed run -> stop
430 g_crr_state.car.state = gStmCarStateNoStop;
431 g_crr_state.car.is_changed = STM_TRUE;
433 // Update restriction layer
434 g_crr_state.layer.restriction.state = g_prv_restriction_state_car_stop;
435 g_crr_state.layer.restriction.is_changed = STM_TRUE;
438 g_crr_state.layer.apps.state = g_prv_apps_state_car_stop;
439 g_crr_state.layer.apps.is_changed = STM_TRUE;
444 // Copy current state for return
445 memcpy(state, &g_crr_state, sizeof(g_crr_state));