Пример #1
0
genLexDescr( )
#endif
{
	ListNode *p;
	FILE *dlgFile = fopen(OutMetaName(DlgFileName), "w");
	require(dlgFile!=NULL, eMsg1("genLexFile: cannot open %s", OutMetaName(DlgFileName)) );
#if SPECIAL_FOPEN
	special_fopen_actions(OutMetaName(DlgFileName));	             /* MR1 */
#endif
	fprintf(dlgFile, "<<\n");
	fprintf(dlgFile, "/* %s -- DLG Description of scanner\n", DlgFileName);
	fprintf(dlgFile, " *\n");
	fprintf(dlgFile, " * Generated from:");
	{int i; for (i=0; i<NumFiles; i++) fprintf(dlgFile, " %s", FileStr[i]);}
	fprintf(dlgFile, "\n");
	fprintf(dlgFile, " *\n");
	fprintf(dlgFile, " * Terence Parr, Will Cohen, and Hank Dietz: 1989-1994\n");
	fprintf(dlgFile, " * Purdue University Electrical Engineering\n");
	fprintf(dlgFile, " * With AHPCRC, University of Minnesota\n");
	fprintf(dlgFile, " * ANTLR Version %s\n", Version);
	fprintf(dlgFile, " */\n\n");
	if ( GenCC )
	{
		if ( !UserDefdTokens ) fprintf(dlgFile, "#include \"%s\"\n", DefFileName);
		else fprintf(dlgFile, "#include %s\n", UserTokenDefsFile);
		fprintf(dlgFile, "#include \"%s\"\n", ATOKEN_H);
		if ( GenAST ) fprintf(dlgFile, "#include \"%s\"\n", ASTBASE_H);
		if ( HdrAction != NULL ) dumpAction( HdrAction, dlgFile, 0, -1, 0, 1 );
	}
	else
	{
		fprintf(dlgFile, "#include <stdio.h>\n");
		fprintf(dlgFile, "#define ANTLR_VERSION	%s\n", VersionDef);
		if ( strcmp(ParserName, DefaultParserName)!=0 )
			fprintf(dlgFile, "#define %s %s\n", DefaultParserName, ParserName);
		if ( strcmp(ParserName, DefaultParserName)!=0 )
			fprintf(dlgFile, "#include \"%s\"\n", RemapFileName);
		if ( HdrAction != NULL ) dumpAction( HdrAction, dlgFile, 0, -1, 0, 1 );
		if ( FoundGuessBlk )
		{
			fprintf(dlgFile, "#define ZZCAN_GUESS\n");
			fprintf(dlgFile, "#include <setjmp.h>\n");
		}
		if ( OutputLL_k > 1 ) fprintf(dlgFile, "#define LL_K %d\n", OutputLL_k);
		if ( DemandLookahead ) fprintf(dlgFile, "#define DEMAND_LOOK\n");
		fprintf(dlgFile, "#include \"antlr.h\"\n");
		if ( GenAST ) {
			fprintf(dlgFile, "#include \"ast.h\"\n");
		}
		if ( UserDefdTokens )
			fprintf(dlgFile, "#include %s\n", UserTokenDefsFile);
		/* still need this one as it has the func prototypes */
		fprintf(dlgFile, "#include \"%s\"\n", DefFileName);
		fprintf(dlgFile, "#include \"dlgdef.h\"\n");
		fprintf(dlgFile, "LOOKAHEAD\n");
		fprintf(dlgFile, "void zzerraction()\n");
		fprintf(dlgFile, "{\n");
		fprintf(dlgFile, "\t(*zzerr)(\"%s\");\n", DLGErrorString);
		fprintf(dlgFile, "\tzzadvance();\n");
		fprintf(dlgFile, "\tzzskip();\n");
		fprintf(dlgFile, "}\n");
	}
	fprintf(dlgFile, ">>\n\n");

	/* dump all actions */

/* MR1									                                    */
/* MR1  11-Apr-97	Provide mechanism for inserting code into DLG class     */
/* MR1	 	   	  via <<%%lexmember ....>> & <<%%lexprefix ...>>            */
/* MR1				                					    */
          if (LexActions != NULL) {
            for (p = LexActions->next; p!=NULL; p=p->next)
		{
/* MR1 */	fprintf(dlgFile, "<<%%%%lexaction\n");
			dumpAction( (char *)p->elem, dlgFile, 0, -1, 0, 1 );
			fprintf(dlgFile, ">>\n\n");
		}
	  };

/* MR1 */ if (GenCC) {
/* MR1 */   fprintf(dlgFile,"<<%%%%parserclass %s>>\n\n",CurrentClassName);
/* MR1 */ };

/* MR1 */ if (LexPrefixActions != NULL) {
/* MR1 */   for (p = LexPrefixActions->next; p!=NULL; p=p->next)
/* MR1 */       {
/* MR1 */               fprintf(dlgFile, "<<%%%%lexprefix\n");
/* MR1 */               dumpAction( (char *)p->elem, dlgFile, 0, -1, 0, 1 );
/* MR1 */               fprintf(dlgFile, ">>\n\n");
/* MR1 */       }
/* MR1 */ };

/* MR1 */ if (LexMemberActions != NULL) {
/* MR1 */   for (p = LexMemberActions->next; p!=NULL; p=p->next)
/* MR1 */       {
/* MR1 */               fprintf(dlgFile, "<<%%%%lexmember\n");
/* MR1 */               dumpAction( (char *)p->elem, dlgFile, 0, -1, 0, 1 );
/* MR1 */               fprintf(dlgFile, ">>\n\n");
/* MR1 */       }
/* MR1 */ };

	/* dump all regular expression rules/actions (skip sentinel node) */
	if ( ExprOrder == NULL ) {
		warnNoFL("no regular expressions found in grammar");
	}
	else dumpLexClasses(dlgFile);
	fprintf(dlgFile, "%%%%\n");
	fclose( dlgFile );
}
Пример #2
0
void ControllerThread::Main() {
    PTime tBase; // base time for tStep multiplier
    PTimeInterval tStep(1); // 1ms, loop step (1Hz); up to 14 bytes per step for 115200 serial line
    PTime tNow; // current time
    PTime tThen; // expected execution time
    unsigned short i = 0; // multiplier for tStep

    // initialize
    PTRACE(1, "Arduino initialization");
    char buffer[256];
    PINDEX iRead = 0;
    PINDEX len   = 0;
    // reset serial port
    pserial->ClearDTR();
    pserial->ClearRTS();
    pserial->ClearBreak();
    pserial->SetDTR();
    pserial->SetRTS();

    // drop junk from serial port
    do {
        if (shutdown.Wait(0)) {
            return;
        };
        pserial->Read(buffer, 256); // flush serial data
    } while (pserial->GetLastReadCount());
    memset(buffer, 0, 256);

    // waiting for 3 heat beat
    do {
        if (shutdown.Wait(0)) {
            return;
        };
        pserial->Read(buffer, 256);
        iRead = pserial->GetLastReadCount();
        if (iRead == 2 && buffer[0] == 0 && buffer[1] == 0) {
            len += iRead;
            PTRACE(1, "HeatBeat from Arduino #" << len/2);
        };
    } while(len < 6);
    PTRACE(1, "Arduino initialization done");
    fReady = PTrue;

    // reset Arduino
    pushAction(0xFF, CMD_RESET);
    pushAction(0xFF, CMD_SETBASE0); // X1
    pushAction(0xFF, calibrationTable[0]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE1); // Y1
    pushAction(0xFF, calibrationTable[1]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE2); // X2
    pushAction(0xFF, calibrationTable[2]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE3); // Y2
    pushAction(0xFF, calibrationTable[3]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE4); // LT
    pushAction(0xFF, calibrationTable[4]->GetAt(10000));
    pushAction(0xFF, CMD_SETBASE5); // RT
    pushAction(0xFF, calibrationTable[5]->GetAt(10000));
    pushAction(0xFF, CMD_RESET);
    // main loop
    do {
        bool fNewActions = false;
        BYTE naction;
        PInt32l value;
        /*
         * get x, y, button and other events
         */
        PTRACE(6, "Main\t" << dumpAction("actions before population: "));
        while(popAction(&naction, &value)) {
            PIntArray *actionQueue = actionQueuePool[naction];

            fNewActions = true;
            PTRACE(6, "Main\tadd new value to actionQueuePool[" << (int)naction << "] with queue size " << actionQueue->GetSize());
            actionQueue->SetAt(actionQueue->GetSize(), value);
        };
        if (fNewActions) {
            PTRACE(6, "Main\t" << dumpAction("actions after population: "));
            summarizeActions(); // summarize action events by type
            PTRACE(6, "Main\t" << dumpAction("actions after summarization: "));
        };
        /*
         * process actions:
         * send current state to arduino
         * then receive state from arduino
         * and update actions after sucsessful transmit
         */
        processActions();
        /*
         * wait next tStep ms
         */
        i++;
        tThen = tBase + tStep * i;
        tNow = PTime();
        // reset multiplier
        if (i >= 255) {
            i = 0;
            tBase = tThen;
        };
        // step was too long (tThen less than tNow)
        if (tNow.Compare(tThen) != LessThan) {
            PTRACE(6, "Main\tnow: " << tNow.AsString("h:m:s.uuuu") << " then: " << tThen.AsString("h:m:s.uuuu") << " i: " << (int)i << " diff: " << (tNow - tThen).GetMilliSeconds() << "ms");
            i += (tNow - tThen).GetMilliSeconds() / tStep.GetMilliSeconds() + 1; // number of steps + 1 step
            tThen = tBase + tStep * i;
            PTRACE(6, "Main\tcorrected then: " << tThen.AsString("h:m:s.uuuu") << " i: " << (int)i);
        };
        PTRACE(7, "Main\tstep " << (tThen - tNow).GetMilliSeconds() << "ms"); 
    } while(!shutdown.Wait((tThen - tNow).GetMilliSeconds()));
}