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,
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* gStmCarStateNo2Name[] = {
81 const char* gStmLampStateNo2Name[] = {
86 const char* gStmLayoutNo2Name[] = {
98 "restriction.split.main",
99 "restriction.split.sub",
102 stm_state_t g_crr_state;
103 stm_state_t g_prv_state;
104 int g_prv_apps_state_car_stop = 0;
106 void stmInitialize() {
107 // Initialize previous state
108 memset(&g_prv_state, 0, sizeof(g_prv_state));
110 g_prv_state.layer.on_screen.state = gStmLayoutNoNone;
111 g_prv_state.layer.restriction.state = gStmLayoutNoNone;
112 g_prv_state.layer.apps.state = gStmLayoutNoNone;
113 g_prv_state.layer.homescreen.state = gStmLayoutNoNone;
114 g_prv_state.parking_brake.state = gStmParkingBrakeStateNoOn;
115 g_prv_state.car.state = gStmCarStateNoStop;
116 g_prv_state.lamp.state = gStmLampStateNoOff;
118 // Initialize current state
119 g_crr_state = g_prv_state;
122 int stmTransitionState(int event, stm_state_t* state) {
123 int event_no, category_no, area_no;
124 int restriction_state, apps_state, parking_brake_state, car_state, lamp_state;
126 event_no = event & STM_MSK_EVT_NO;
127 category_no = event & STM_MSK_CTG_NO;
128 area_no = event & STM_MSK_ARA_NO;
130 // Backup previous state
131 g_prv_state = g_crr_state;
133 // Get previous state
134 restriction_state = g_prv_state.layer.restriction.state;
135 apps_state = g_prv_state.layer.apps.state;
136 parking_brake_state = g_prv_state.parking_brake.state;
137 car_state = g_prv_state.car.state;
138 lamp_state = g_prv_state.lamp.state;
141 g_crr_state.layer.on_screen.is_changed = STM_FALSE;
142 g_crr_state.layer.restriction.is_changed = STM_FALSE;
143 g_crr_state.layer.apps.is_changed = STM_FALSE;
144 g_crr_state.layer.homescreen.is_changed = STM_FALSE;
145 g_crr_state.parking_brake.is_changed = STM_FALSE;
146 g_crr_state.car.is_changed = STM_FALSE;
147 g_crr_state.lamp.is_changed = STM_FALSE;
150 case STM_EVT_NO_ACTIVATE:
151 switch (category_no) {
152 case STM_CTG_NO_HOMESCREEN:
154 g_crr_state.layer.apps.state = gStmLayoutNoNone;
155 g_crr_state.layer.apps.is_changed = STM_TRUE;
158 g_crr_state.layer.homescreen.state = gStmLayoutNoHs;
159 g_crr_state.layer.homescreen.is_changed = STM_TRUE;
163 case STM_ARA_NO_FULL:
165 switch (apps_state) {
170 g_crr_state.layer.apps.state = gStmLayoutNoMf;
171 g_crr_state.layer.apps.is_changed = STM_TRUE;
175 case STM_ARA_NO_NORMAL:
177 switch (apps_state) {
182 g_crr_state.layer.apps.state = gStmLayoutNoM2;
183 g_crr_state.layer.apps.is_changed = STM_TRUE;
186 g_crr_state.layer.apps.state = gStmLayoutNoM1;
187 g_crr_state.layer.apps.is_changed = STM_TRUE;
190 case STM_ARA_NO_SPLIT_MAIN:
192 switch (apps_state) {
195 g_crr_state.layer.apps.state = gStmLayoutNoS2;
196 g_crr_state.layer.apps.is_changed = STM_TRUE;
205 case STM_CTG_NO_GENERAL:
207 case STM_ARA_NO_NORMAL:
209 switch (apps_state) {
214 g_crr_state.layer.apps.state = gStmLayoutNoG;
215 g_crr_state.layer.apps.is_changed = STM_TRUE;
224 case STM_CTG_NO_SPLITABLE:
226 case STM_ARA_NO_NORMAL:
228 switch (apps_state) {
230 g_crr_state.layer.apps.state = gStmLayoutNoM2;
231 g_crr_state.layer.apps.is_changed = STM_TRUE;
238 g_crr_state.layer.apps.state = gStmLayoutNoS1;
239 g_crr_state.layer.apps.is_changed = STM_TRUE;
243 case STM_ARA_NO_SPLIT_MAIN:
245 switch (apps_state) {
247 g_crr_state.layer.apps.state = gStmLayoutNoS2;
248 g_crr_state.layer.apps.is_changed = STM_TRUE;
251 g_crr_state.layer.apps.state = gStmLayoutNoS2;
252 g_crr_state.layer.apps.is_changed = STM_TRUE;
259 case STM_ARA_NO_SPLIT_SUB:
261 switch (apps_state) {
263 g_crr_state.layer.apps.state = gStmLayoutNoM2;
264 g_crr_state.layer.apps.is_changed = STM_TRUE;
267 g_crr_state.layer.apps.state = gStmLayoutNoM2;
268 g_crr_state.layer.apps.is_changed = STM_TRUE;
271 g_crr_state.layer.apps.state = gStmLayoutNoS2;
272 g_crr_state.layer.apps.is_changed = STM_TRUE;
275 g_crr_state.layer.apps.state = gStmLayoutNoS2;
276 g_crr_state.layer.apps.is_changed = STM_TRUE;
288 case STM_CTG_NO_RESTRICTION:
290 case STM_ARA_NO_RESTRICTION_NORMAL:
292 switch (restriction_state) {
293 case gStmLayoutNoNone:
294 g_crr_state.layer.restriction.state = gStmLayoutNoRestriction;
295 g_crr_state.layer.restriction.is_changed = STM_TRUE;
302 case STM_ARA_NO_RESTRICTION_SPLIT_MAIN:
304 switch (restriction_state) {
305 case gStmLayoutNoNone:
306 g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitMain;
307 g_crr_state.layer.restriction.is_changed = STM_TRUE;
314 case STM_ARA_NO_RESTRICTION_SPLIT_SUB:
316 switch (restriction_state) {
317 case gStmLayoutNoNone:
318 g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitSub;
319 g_crr_state.layer.restriction.is_changed = STM_TRUE;
335 case STM_EVT_NO_DEACTIVATE:
336 switch (category_no) {
337 case STM_CTG_NO_RESTRICTION:
339 switch (restriction_state) {
340 case gStmLayoutNoRestriction:
341 case gStmLayoutNoRestrictionSplitMain:
342 case gStmLayoutNoRestrictionSplitSub:
343 g_crr_state.layer.restriction.state = gStmLayoutNoNone;
344 g_crr_state.layer.restriction.is_changed = STM_TRUE;
355 case STM_EVT_NO_PARKING_BRAKE_OFF:
356 if (gStmParkingBrakeStateNoOff != parking_brake_state) {
357 g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOff;
358 g_crr_state.parking_brake.is_changed = STM_TRUE;
361 case STM_EVT_NO_PARKING_BRAKE_ON:
362 if (gStmParkingBrakeStateNoOn != parking_brake_state) {
363 g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOn;
364 g_crr_state.parking_brake.is_changed = STM_TRUE;
367 case STM_EVT_NO_CAR_STOP:
368 if (gStmCarStateNoStop != car_state) {
369 g_crr_state.layer.apps.state = g_prv_apps_state_car_stop;
370 g_crr_state.layer.apps.is_changed = STM_TRUE;
372 g_crr_state.car.state = gStmCarStateNoStop;
373 g_crr_state.car.is_changed = STM_TRUE;
376 case STM_EVT_NO_CAR_RUN:
377 if (gStmCarStateNoRun != car_state) {
378 g_prv_apps_state_car_stop = apps_state;
379 g_crr_state.layer.apps.state = gStmLayoutNoM1;
380 g_crr_state.layer.apps.is_changed = STM_TRUE;
382 g_crr_state.car.state = gStmCarStateNoRun;
383 g_crr_state.car.is_changed = STM_TRUE;
386 case STM_EVT_NO_LAMP_OFF:
387 if (gStmLampStateNoOff != lamp_state) {
388 g_crr_state.lamp.state = gStmLampStateNoOff;
389 g_crr_state.lamp.is_changed = STM_TRUE;
392 case STM_EVT_NO_LAMP_ON:
393 if (gStmLampStateNoOn != lamp_state) {
394 g_crr_state.lamp.state = gStmLampStateNoOn;
395 g_crr_state.lamp.is_changed = STM_TRUE;
403 // Copy current state for return
404 memcpy(state, &g_crr_state, sizeof(g_crr_state));