1515#include <string.h>
1616#include <stdlib.h>
1717#include <stdbool.h>
18-
1918static void initState (state_t * state , char * name , stateTransition_t * (* action )(), int numTrans );
2019static void initTransition (stateTransition_t * transition , state_t * target , int (* action )() );
2120
@@ -150,7 +149,7 @@ static int initPumpdown(state_t *pumpdown) {
150149
151150static int initPropulsion (state_t * propulsion ) {
152151
153- initTransition (propulsion -> transitions [0 ], findState (BRAKING_NAME ), genTranAction );
152+ initTransition (propulsion -> transitions [0 ], findState (BRAKING_NAME ), genBraking );
154153 initTransition (propulsion -> transitions [1 ], findState (RUN_FAULT_NAME ), genRunFault );
155154 addTransition (PROPULSION_NAME , propulsion -> transitions [0 ]);
156155 addTransition (PROPULSION_NAME , propulsion -> transitions [1 ]);
@@ -162,7 +161,7 @@ static int initPropulsion(state_t *propulsion) {
162161
163162static int initBraking (state_t * braking ) {
164163
165- initTransition (braking -> transitions [0 ], findState (STOPPED_NAME ), genTranAction );
164+ initTransition (braking -> transitions [0 ], findState (STOPPED_NAME ), genStopped );
166165 initTransition (braking -> transitions [1 ], findState (RUN_FAULT_NAME ), genRunFault );
167166 addTransition (BRAKING_NAME , braking -> transitions [0 ]);
168167 addTransition (BRAKING_NAME , braking -> transitions [1 ]);
@@ -174,7 +173,7 @@ static int initBraking(state_t *braking) {
174173}
175174
176175static int initServPrecharge (state_t * servPrecharge ) {
177- initTransition (servPrecharge -> transitions [0 ], findState (RUN_FAULT_NAME ), genTranAction );
176+ initTransition (servPrecharge -> transitions [0 ], findState (RUN_FAULT_NAME ), genRunFault );
178177 addTransition (SERV_PRECHARGE_NAME , servPrecharge -> transitions [0 ]);
179178 servPrecharge -> fault = servPrecharge -> transitions [0 ];
180179
@@ -186,17 +185,18 @@ static int initServPrecharge(state_t *servPrecharge) {
186185static int initCrawl (state_t * crawl ) {
187186
188187 initTransition (crawl -> transitions [0 ], findState (POST_RUN_NAME ), genPostRun );
189- initTransition (crawl -> transitions [1 ], findState (RUN_FAULT_NAME ), genTranAction );
188+ initTransition (crawl -> transitions [1 ], findState (RUN_FAULT_NAME ), genRunFault );
190189 addTransition (CRAWL_NAME , crawl -> transitions [0 ]);
191- addTransition (CRAWL_NAME , crawl -> fault = crawl -> transitions [1 ]);
190+ addTransition (CRAWL_NAME , crawl -> transitions [1 ] );
192191
192+ crawl -> fault = crawl -> transitions [1 ];
193193 crawl -> next = crawl -> transitions [0 ];
194194 crawl -> begin = genCrawl ;
195195 return 0 ;
196196}
197197
198198static int initStopped (state_t * stopped ) {
199- initTransition (stopped -> transitions [0 ], findState (RUN_FAULT_NAME ), genTranAction );
199+ initTransition (stopped -> transitions [0 ], findState (RUN_FAULT_NAME ), genRunFault );
200200 addTransition (STOPPED_NAME , stopped -> transitions [0 ]);
201201 stopped -> fault = stopped -> transitions [0 ];
202202 stopped -> next = NULL ;
@@ -205,7 +205,7 @@ static int initStopped(state_t *stopped) {
205205}
206206
207207static int initPostRun (state_t * postRun ) {
208- initTransition (postRun -> transitions [1 ], findState (RUN_FAULT_NAME ), genTranAction );
208+ initTransition (postRun -> transitions [0 ], findState (RUN_FAULT_NAME ), genRunFault );
209209 addTransition (POST_RUN_NAME , postRun -> transitions [0 ]);
210210 postRun -> fault = postRun -> transitions [0 ];
211211 postRun -> next = NULL ;
@@ -214,10 +214,11 @@ static int initPostRun(state_t *postRun) {
214214}
215215
216216static int initSafeToApproach (state_t * safeToApproach ) {
217- initTransition (safeToApproach -> transitions [0 ], findState (NON_RUN_FAULT_NAME ), genTranAction );
218- addTransition (SAFE_TO_APPROACH_NAME ,
219- safeToApproach -> fault = safeToApproach -> transitions [0 ]);
220- safeToApproach -> next = NULL ;
217+ initTransition (safeToApproach -> transitions [0 ], findState (NON_RUN_FAULT_NAME ), genNonRunFault );
218+ addTransition (SAFE_TO_APPROACH_NAME , safeToApproach -> transitions [0 ]);
219+ safeToApproach -> fault = safeToApproach -> transitions [0 ];
220+ safeToApproach -> next = NULL ;
221+ safeToApproach -> begin = genTranAction ;
221222 return 0 ;
222223}
223224
@@ -262,10 +263,12 @@ void runStateMachine(void) {
262263 if (strcmp (stateMachine .overrideStateName , BLANK_NAME ) != 0 ) {
263264 state_t * tempState = findState (stateMachine .overrideStateName );
264265 if (tempState != NULL ) {
266+ printf ("TEMP STATE NAME: %s\n" , tempState -> name );
265267 stateTransition_t * trans = findTransition (stateMachine .currState , stateMachine .overrideStateName );
266268 if (trans != NULL ) {
267269 trans -> action ();
268270 } else {
271+ printf ("begin func\n" );
269272 tempState -> begin ();
270273 }
271274 stateMachine .currState = tempState ;
@@ -277,7 +280,7 @@ void runStateMachine(void) {
277280 /* execute the state and check if we should be transitioning */
278281 stateTransition_t * transition = stateMachine .currState -> action ();
279282 if (transition != NULL ) {
280- printf ("transAction->%s\n" , transition -> target -> name );
283+ /* printf("transAction->%s\n", transition->target->name);*/
281284 if (transition -> action () == 0 ) {
282285 printf ("here we are\n" );
283286 stateMachine .currState = transition -> target ;
@@ -324,9 +327,9 @@ void buildStateMachine(void) {
324327 initPumpdown (stateMachine .allStates [1 ]);
325328 initPropulsion (stateMachine .allStates [2 ]);
326329 initBraking (stateMachine .allStates [3 ]);
327- initStopped (stateMachine .allStates [4 ]);
328- initServPrecharge (stateMachine .allStates [5 ]);
329- initCrawl (stateMachine .allStates [6 ]);
330+ initServPrecharge (stateMachine .allStates [4 ]);
331+ initCrawl (stateMachine .allStates [5 ]);
332+ initStopped (stateMachine .allStates [6 ]);
330333 initPostRun (stateMachine .allStates [7 ]);
331334 initSafeToApproach (stateMachine .allStates [8 ]);
332335
0 commit comments