Пример #1
0
static void
test_file(bool BinaryF, const char* FileStem)
{
    QUEX_NAME(Buffer)         buffer;
    /* With 'LexatomLoader_Plain()' no conversion takes place. Thus, the file
     * containing the REFERENCE data and the INPUT file are the SAME.        */
    const char*               file_name   = find_reference(FileStem); 
    FILE*                     fh          = fopen(file_name, "rb"); 
    QUEX_NAME(ByteLoader)*               byte_loader = QUEX_NAME(ByteLoader_FILE_new)(fh, true);
    QUEX_NAME(LexatomLoader)*  filler;
    const size_t              MemorySize  = true ? 5 : 16;
    QUEX_TYPE_LEXATOM       memory[MemorySize];

    if( ! fh ) {
        printf("Failed to open '%s'.", file_name);
        hwut_verify(false);
    }

    byte_loader->binary_mode_f = BinaryF;
    filler = QUEX_NAME(LexatomLoader_Plain_new)(byte_loader);

    QUEX_NAME(Buffer_construct)(&buffer, filler, &memory[0], MemorySize, 0, E_Ownership_EXTERNAL);

    /* REFERENCE file and INPUT file are the SAME.                           */
    hwut_verify(basic_functionality(&buffer, file_name));

    filler->delete_self(filler);
}
Пример #2
0
fb_info* find_fbinfo() {
	unsigned int fbref = find_string(gBaseaddr, gBaseaddr, 0x40000, "framebuffer");
	unsigned int** fbinforef = (unsigned int**)(find_reference(gBaseaddr, gBaseaddr, 0x40000, fbref) - 4);
	fb_info* reference = (fb_info*)(**fbinforef + 0x20);
	if (((reference->fbuffer)&0x000fffff)==0) { // OK
		return reference;
	}
	return 0;
}
Пример #3
0
static void
test_file(E_ConverterTestType CTT, const char* Codec, bool LinearF, bool ClueLessStomachF, const char* FileName, const char* FileStem)
{
    QUEX_NAME(Buffer)         buffer;
    QUEX_NAME(Converter)*     converter;
    /* With 'LexatomLoader_Plain()' no conversion takes place. Thus, the file
     * containing the REFERENCE data and the INPUT file are the SAME.        */
    const char*               ref_file_name = find_reference(FileStem); 
#   if 0
    QUEX_NAME(ByteLoader)*    byte_loader   = QUEX_NAME(ByteLoader_FILE_new_from_file_name)(FileName);
#   else
    QUEX_NAME(ByteLoader)*    byte_loader   = QUEX_NAME(ByteLoader_Memory_new_from_file_name)(FileName);
#   endif
    const size_t              MemorySize    = true ? 5 : 16;
    QUEX_TYPE_LEXATOM       memory[MemorySize];
    QUEX_NAME(LexatomLoader)*  filler;  

    switch( CTT ) {
    case TEST_ICU:   converter = QUEX_NAME(Converter_ICU_new)(Codec, 0); break;
    case TEST_ICONV: converter = QUEX_NAME(Converter_IConv_new)(Codec, 0); break;
    default:         __quex_assert(false); 
    }
    __quex_assert(converter);

    if( ClueLessStomachF ) {
        converter->stomach_byte_n = clueless_stomach_byte_n;
    }

    if( ! byte_loader ) {
        printf("Failed to open '%s'.", FileName);
        hwut_verify(false);
    }

    filler = QUEX_NAME(LexatomLoader_Converter_new)(byte_loader, converter, 7);

    /* If file was not opened in binary mode no converter filler is created! */
    __quex_assert(filler); 

    QUEX_NAME(Buffer_construct)(&buffer, filler, &memory[0], MemorySize, 0, 
                                E_Ownership_EXTERNAL);
    if( LinearF ) { 
        __quex_assert(filler->byte_n_per_lexatom != -1);
        __quex_assert(byte_loader->binary_mode_f);
    }
    else {
        __quex_assert(filler->byte_n_per_lexatom == -1);
    }

    /* REFERENCE file and INPUT file are the SAME.                           */
    hwut_verify(basic_functionality(&buffer, ref_file_name));

    filler->delete_self(filler);
    byte_loader->delete_self(byte_loader);
    converter->delete_self(converter);
}
Пример #4
0
void* find_cmd_list_begin() {
    unsigned int reference = find_reference(TARGET_BASEADDR, TARGET_BASEADDR, 0x40000, "save current environment to flash");
    if(reference == 0) {
        printf("Unable to find saveenv description reference\n");
        return 0;
    }

    int i = 0;
    for(i = 0; i < 0x80; i += 4) {
        unsigned int* command = reference-i;
        if(*command == NULL) {
            return command+1;
        }
    }
    return 0;
}
Пример #5
0
unsigned int find_offset(unsigned int dataaddr, unsigned int base, unsigned int size, unsigned char** what) {
	unsigned char* data = (unsigned char *)dataaddr;
	int i = 0;
	unsigned char* top = what[2];
	unsigned char* name = what[0];
	unsigned char* signature = what[1];
	unsigned int dbase = dataaddr;

	// First find the string
	unsigned int address = find_string(dataaddr, base, size, signature);
	if(address == 0) return NULL;

	// Next find where that string is referenced
	unsigned int reference = find_reference(dataaddr, base, size, address);
	if(reference == 0) return NULL;
	reference -= base;

	// Finally find the top of that function
	unsigned int function = find_top(dataaddr, base, size, reference);

	return function;
}
HIDDEN void
killtree_callback(struct db_i *dbip, struct directory *dp, void *ptr)
{
    struct killtree_data *gktdp = (struct killtree_data *)ptr;
    int ref_exists = 0;

    if (dbip == DBI_NULL)
	return;

    /* don't bother checking for references if the -f or -a flags are
     * presented to force a full kill and all references respectively.
     */
    if (!gktdp->force && !gktdp->killrefs)
	ref_exists = find_reference(dbip, gktdp->top, dp->d_namep);

    /* if a reference exists outside of the subtree we're killing, we
     * don't kill this object or it'll create invalid reference
     * elsewhere in the database.  do nothing.
     */
    if (ref_exists)
	return;

    if (gktdp->print) {
	if (!gktdp->killrefs)
	    bu_vls_printf(gktdp->gedp->ged_result_str, "%s ", dp->d_namep);
	else {
	    if ((size_t)(gktdp->ac + 2) >= gktdp->av_capacity) {
		gktdp->av = (char **)bu_realloc(gktdp->av, sizeof(char *) * (gktdp->av_capacity + AV_STEP), "realloc av");
		gktdp->av_capacity += AV_STEP;
	    }
	    gktdp->av[gktdp->ac++] = bu_strdup(dp->d_namep);
	    gktdp->av[gktdp->ac] = (char *)0;

	    bu_vls_printf(gktdp->gedp->ged_result_str, "%s ", dp->d_namep);
	}
    } else {
	_dl_eraseAllNamesFromDisplay(gktdp->gedp->ged_gdp->gd_headDisplay, gktdp->gedp->ged_wdbp->dbip, gktdp->gedp->ged_free_vlist_callback, dp->d_namep, 0, gktdp->gedp->freesolid);

	bu_vls_printf(gktdp->gedp->ged_result_str, "KILL %s:  %s\n",
		      (dp->d_flags & RT_DIR_COMB) ? "COMB" : "Solid",
		      dp->d_namep);

	if (!gktdp->killrefs) {
	    if (db_delete(dbip, dp) != 0 || db_dirdelete(dbip, dp) != 0) {
		bu_vls_printf(gktdp->gedp->ged_result_str, "an error occurred while deleting %s\n", dp->d_namep);
	    }
	} else {
	    if ((size_t)(gktdp->ac + 2) >= gktdp->av_capacity) {
		gktdp->av = (char **)bu_realloc(gktdp->av, sizeof(char *) * (gktdp->av_capacity + AV_STEP), "realloc av");
		gktdp->av_capacity += AV_STEP;
	    }
	    gktdp->av[gktdp->ac++] = bu_strdup(dp->d_namep);
	    gktdp->av[gktdp->ac] = (char *)0;

	    if (db_delete(dbip, dp) != 0 || db_dirdelete(dbip, dp) != 0) {
		bu_vls_printf(gktdp->gedp->ged_result_str, "an error occurred while deleting %s\n", dp->d_namep);

		/* Remove from list */
		bu_free((void *)gktdp->av[--gktdp->ac], "killtree_callback");
		gktdp->av[gktdp->ac] = (char *)0;
	    }
	}
    }
}
Пример #7
0
int main(void)
{
		
	setup();
	uint16_t increment = 0;	
	
	//DDRD &= ~(1<<PD4);	no longer needed
	//PORTD |= (1<<PD4);
		
    while(1)
    {
		
		/* measure supply voltage and warn user if voltage drops too low */
			if(ISR_flag.check_supply)	//measure supply voltage every 10ms
			{	
				check_supply_voltage();
				ISR_flag.check_supply = 0;	//clear flag	
			}

		/* poll the inputs and look for any falling edges indicating button presses or other input signals */
			if(ISR_flag.check_inputs)
			{
				poll_inputs();
				ISR_flag.check_inputs = 0;	//clear flag	
				
			/* Detect a long button press by incrementing a variable every ms the button is pressed
			 * This is necessary to avoid false triggering due to EMI from the motor lines.
			 */	
				if(!(DOOR_BUTTON_PINREG & (1<<DOOR_BUTTON_PIN)))
				{
					increment++;
				}else{
					increment = 0;	// reset the count if the button is released.
				}
			}
			
		/* check for a 1000ms long button press 
		 * Again, this is necessary to avoid false triggering due to motor interference 
		 */
			if(increment >= 1000)
			{
				increment = 0;				
				command.delayed_lock = 1;	//activate the delayed lock sequence
				delayed_lock_tick = 0;		//reset the timer for the delayed lock sequence
			}
		
		
		/* check, if status is unknown or a reference command has been issued
		 * If that is the case, ignore any other commands and find the reference point first!
		 *
		 * Note, that command.reference is not implemented yet. There was no need for this until now (10/Aug/15)
		 */
			if( ((!status.locked) && (!status.unlocked)) || (command.reference) )
			{
				if((command.lock)||(command.unlock)||(command.reference))
				{	
					if(input_status_current[6])	//find out, if gear magnet is already near the reed contact
					{
						find_reference(0,500,2000);	
					}else{
						find_reference(1,500,2000);
					}	
					command.lock = 0;
					command.unlock = 0;
					command.reference = 0;	
					command.delayed_lock = 0;			
				}
			}else
			
			{ 	
			/* open the door */
				if (command.unlock && !command.block_unlock && !command.reference)
				{
					command.block_lock = 1;	//prevent any other lock commands while this is active
					enable_stepper(1);

					if(!status.open)		//Door is not open yet, move to "open" position
					{
						if(move_to_position(OPEN)==1)	//set status.open once at "open" position 
						{
							status.open = 1;
						}
						ms_100_tick = 0;	//reset the 100ms tick until at "open" position 
						
					}else if(ms_100_tick<=35)
					{
						//wait 3.5s at "open" position before turning back to "neutral". This lets the user open the door by pushing it
					}

					if((ms_100_tick>35)&&(status.open))	//Door is "open" and we waited for 3.5s
					{
						
						if(move_to_position(NEUTRAL)==1)	//move back to "neutral" position and reset all status and command bits.
						{
							command.unlock = 0;
							command.block_lock = 0;
							status.open = 0;
							status.locked = 0;
							status.unlocked = 1;
							status.error = 0;
							status.reached_endstop = 0;
							command.delayed_lock = 0;

							enable_stepper(0);
						}
					}
				} else

			/* lock the door */	
				if (command.lock && !command.block_lock && !command.reference)
				{
					/* locking is the same as a reference turn, so we use every lock command to re-reference our position
					 * to account for stupid users turning the gear by hand
					 */
						enable_stepper(1);	
						command.block_unlock = 1;		//block any other actions while locking the door
						
						if(!status.reached_endstop && (position > (-2000)))		//turn CCW until either endstop is reached or 2000 steps have passed
						{
							move_to_position(-2000);
							ms_100_tick = 0;	
							
						} 
						else if (position <= (-2000))		//2000 steps have passed without reaching the endstop -> something went wrong
						{
							command.lock = 0;
							command.block_unlock = 0;
							status.locked = 0;
							status.unlocked = 0;
							status.error = 1;
							command.delayed_lock = 0;
							
							enable_stepper(0);
						}
						else if(ms_100_tick<=1){		//endstop reached, reset the position to 0 while waiting a bit 
							position = 0;
						} 
						
						if((ms_100_tick>3)&&(status.reached_endstop))	//return to "neutral" position after 300ms
						{
							if(move_to_position(NEUTRAL)==1)	//reset status and command bits after coming back to the "neutral" position
							{
								command.lock = 0;
								command.block_unlock = 0;
								status.reached_endstop = 0;
								status.locked = 1;
								status.unlocked = 0;
								status.error = 0;
								enable_stepper(0);
								command.delayed_lock = 0;
							}
	
						}							
				} 
				else
				
			/* someone locked the door by hand and triggered the endstop. Set status to "locked" */
				if (!command.lock && !command.unlock && !command.reference)
				{
					if(status.reached_endstop)
					{
						status.open = 0;
						status.unlocked = 0;
						status.locked = 1;
					}
				}
					
			}	
			
			
			
			
		/* delayed lock has been triggered. Start the countdown */
			if (command.delayed_lock && status.unlocked && !status.open && !command.block_unlock && !command.block_lock && !command.lock && !command.unlock)
			{
				if(delayed_lock_tick < 150)		//wait for 15s and set "status.delayed_lock". This triggers the flashing yellow LED 
				{
					status.delayed_lock = 1;
					switch_LED(0,'B');			
				}else
				{
					status.delayed_lock = 0;
					command.delayed_lock = 0;
					command.lock = 1;			//15s have passed, give the "lock" command to lock the door
				}
			}
			
		/* Switch LEDs according to the status bits.
		 *
		 * This needs to be streamlined, it is way to complicated
		 */	
			if(status.delayed_lock)		//Override any other LED configurations while "status.delayed_lock" is active
			{
				flash_LED(25,(180-delayed_lock_tick),'Y');
				switch_LED(0,'B');
			}else
			{

				if(status.error || ( (!status.unlocked)&&(!status.locked)))
				{
					flash_LED(10,20,'Y');
					flash_LED(10,20,'B');
					set_status('E');
				}
				if(status.open)
				{
					flash_LED(25,40,'B');
					switch_LED(0,'Y');
					set_status('U');
				}
				if(status.unlocked && !status.open)
				{
					switch_LED(0,'Y');
					switch_LED(1,'B');
					set_status('U');
				}
				if(status.locked && !status.open)
				{
					switch_LED(0,'B');
					switch_LED(1,'Y');
					set_status('L');
				}
			
			}	
    }
}