/*..........................................................................*/ int main(int argc, char *argv[]) { QHsmTst_ctor(); /* instantiate the QHsmTst object */ if (argc > 1) { /* file name provided? */ l_outFile = fopen(argv[1], "w"); } if (l_outFile == (FILE *)0) { /* interactive version? */ l_outFile = stdout; /* use the stdout as the output file */ printf("QHsmTst example, built on %s at %s,\n" "QP-nano: %s.\nPress ESC to quit...\n", __DATE__, __TIME__, QP_getVersion()); QHsm_init(the_hsm); /* the top-most initial tran. */ for (;;) { /* event loop */ int c; printf("\n>"); c = _getche(); /* get a character from the console with echo */ printf(": "); if ('a' <= c && c <= 'i') { /* in range? */ Q_SIG(the_hsm) = (QSignal)(c - 'a' + A_SIG); } else if ('A' <= c && c <= 'I') { /* in range? */ Q_SIG(the_hsm) = (QSignal)(c - 'A' + A_SIG); } else if (c == '\33') { /* the ESC key? */ Q_SIG(the_hsm) = TERMINATE_SIG; } else { Q_SIG(the_hsm) = IGNORE_SIG; } QHsm_dispatch(the_hsm); /* dispatch the event */ } } else { /* batch version */ printf("QHsmTst example, built on %s at %s, QP-nano %s\n" "output saved to %s\n", __DATE__, __TIME__, QP_getVersion(), argv[1]); fprintf(l_outFile, "QHsmTst example, QP-nano %s\n", QP_getVersion()); QHsm_init(the_hsm); /* take the initial transitioin */ /* testing of dynamic transitions... */ dispatch(A_SIG); dispatch(B_SIG); dispatch(D_SIG); dispatch(E_SIG); dispatch(I_SIG); dispatch(F_SIG); dispatch(I_SIG); dispatch(I_SIG); dispatch(F_SIG); dispatch(A_SIG); dispatch(B_SIG); dispatch(D_SIG); dispatch(D_SIG); dispatch(E_SIG); dispatch(G_SIG); dispatch(H_SIG); dispatch(H_SIG); dispatch(C_SIG); dispatch(G_SIG); dispatch(C_SIG); dispatch(C_SIG); fclose(l_outFile); } return 0; }
/*..........................................................................*/ int main(int argc, char *argv[]) { int j; QHsmTst_ctor(); /* instantiate the HSM */ if (argc > 1) { /* file name provided? */ l_outFile = fopen(argv[1], "w"); } if (l_outFile == (FILE *)0) { /* interactive version? */ l_outFile = stdout; /* use the stdout as the output file */ printf("QHsmTst example, built on %s at %s,\n" "QP-nano: %s.\nPress ESC to quit...\n", __DATE__, __TIME__, QP_getVersion()); QHsm_init((QHsm *)&HSM_QHsmTst); /* take the initial transitioin */ for (;;) { /* event loop */ int c; printf("\n>"); c = getchar(); printf(": "); /* if ('a' <= c && c <= 'i') { // in range? Q_SIG((QHsm *)&HSM_QHsmTst) = (QSignal)(c - 'a' + A_SIG); } else if ('A' <= c && c <= 'I') { // in range? Q_SIG((QHsm *)&HSM_QHsmTst) = (QSignal)(c - 'A' + A_SIG); } else if (c == '\33') { // the ESC key? Q_SIG((QHsm *)&HSM_QHsmTst) = TERMINATE_SIG; } else { Q_SIG((QHsm *)&HSM_QHsmTst) = IGNORE_SIG; } */ //QHsm_dispatch((QHsm *)&HSM_QHsmTst); /* dispatch the event */ } } else { /* batch version */ printf("QHsmTst example, built on %s at %s, QP-nano %s\n" "output saved to %s\n", __DATE__, __TIME__, QP_getVersion(), argv[1]); fprintf(l_outFile, "QHsmTst example, QP-nano %s\n", QP_getVersion()); QHsm_init((QHsm *)&HSM_QHsmTst); /* take the initial transitioin */ extern storeWait waiting [5]; //init int iterations; int timerCheckPoint = 0; direct = NA; maxFloor = 4; for ( ; timePassed < 3000000; ){ timerCheckPoint = timePassed; //Controller loop switch (direct){ case UP: { if (ordersExistInDir(UP)){ dispatch(GO_UP); dispatch(FLOOR_REACHED); } else { direct = NA; } break; } case DOWN: { if (ordersExistInDir(DOWN)){ dispatch(GO_DOWN); dispatch(FLOOR_REACHED); } else { direct = NA; } break; } case NA: { if (ordersExistInDir(UP)){ dispatch(GO_UP); dispatch(FLOOR_REACHED); } else if (ordersExistInDir(DOWN)){ dispatch(GO_DOWN); dispatch(FLOOR_REACHED); } break; } } //To make the time go if nothing has been done in the elevator if (timerCheckPoint == timePassed){ tick5(); } //printStatus(waiting); //printf("iteration no: %d",iterations); assert(currentFloor <= maxFloor && currentFloor >= 0); } printStatistics(waiting); fclose(l_outFile); } return 0; }