eOSState cMenuSearchResultsForBlacklist::ProcessKey(eKeys Key)
{
   eOSState state = cMenuSearchResults::ProcessKey(Key);

   if (state == osUnknown) {
      switch (Key) {
         case k1...k9:
            state = HasSubMenu()?osContinue:Commands(Key);
            break;
         case kRecord:
         case kRed:
            state = OnRed();
            break;
         case kBlue:
            if (HasSubMenu())
               state = Switch();
            else
               state = osContinue;
            break;
         default:
            break;
      }
   }
   return state;
}
Example #2
0
// usb zu rs232
void USBtoRS232(char * buf)
{
  if(buf[0] == '*'){
    Commands();
    RS232_i=0;
  }
  else
    toRS232Buf[RS232_i++] = buf[0];
}
Example #3
0
// The main program
int main (void) 
{  
	// Initilise the robot to be controled by the script and ensure the robot is powered on
	Initialise();

	// Stop just as a precaution
	Stop();
  
	// Show that the program is running by flashing the LED's
	for(int i = 0; i < LED_FLASHES; i++)
	{
		LEDBothOn;
		DelayAndUpdateSensors(500);
		LEDBothOff;
		DelayAndUpdateSensors(500);
	}
	DelayAndUpdateSensors(500);

	Commands();
    
	// Drive around until a button or unsafe condition is detected and the command is not -1
    while(!(UserButtonPressed)
            && (!sensors[SenCliffL])
            && (!sensors[SenCliffFL])
            && (!sensors[SenCliffFR])
            && (!sensors[SenCliffR])
            && (!sensors[SenChAvailable]
			&& command >= 0)
        )
    {
	
		// Run the drive of the robot for current action
		Drive();
		
		// Update the sensors as the robot has driven
		DelayAndUpdateSensors(20);
		
		// Check for an interupt event
		//CheckInteruptEvent();
    }

    // Stop driving
    Stop();
}
Example #4
0
// move onto the next command
void FinishedCommand()
{
	// Reset the driving variables
	turn_angle 		= 0;
	turn_direction	= 0;
	drive_distance 	= 0;
	speed		 	= 0;
	turning 		= 0;
	interuptEvent	= 0;
	
	distance = 0;
	angle = 0;
	
	// Increment to the next command
	command++;
	
	// Setup for the next command
	Commands();
}
Example #5
0
void TConsole::cmd_run(string arg) {
  stringstream buf;
  buf.str(arg);
  string filename="";
  filename=get_string_with_ws(buf);
  ifstream fin(filename);

  if(!fin.good()) throw string("File '"+filename+"' is not good");
  while(fin.good())
  {
    string str_input="";
    getline(fin, str_input);
    str_input=pname_parser(str_input);
    string cur_name, cur_arg;
    extract_cmd_name_and_arg(str_input, cur_name, cur_arg);
    TCmd* ptr=Commands(cur_name);
    if(ptr)
    {
      (this->**ptr)(cur_arg);
    }
    else throw string("Unknown command: '"+cur_name+"'");
  }
  fin.close();
}
eOSState cMenuSearchResultsForSearch::ProcessKey(eKeys Key)
{
   eOSState state = cMenuSearchResults::ProcessKey(Key);

   if (state == osUnknown) {
      switch (Key) {
         case kRecord:
         case kRed:
            state = OnRed(searchExt);
            break;
         case k1...k9:
            state = HasSubMenu()?osContinue:Commands(Key, searchExt);
            break;
         case kBlue:
            if (HasSubMenu())
               state = Switch();
            else
            {
               modeBlue = (ModeBlueSR)(((int)modeBlue+1)%3);
               if (modeBlue == showTimerPreview &&
                   (!searchExt || (searchExt && (searchExt->useAsSearchTimer == 0 || searchExt->avoidRepeats == 0))))
                  modeBlue = (ModeBlueSR)(((int)modeBlue+1)%3);

               if (modeBlue == showTimerPreview)
                  m_bSort = true; // show always sorted by channel
               BuildList();

               state = osContinue;
            }
            break;
         default:
            break;
      }
   }
   return state;
}
int main(int argc, char *argv[]) {
	//DEBUG:Print Header info
	printf("==========================================\n");
	printf("==CHREC F5 Baseline Arithmetic Benchmark==\n");
	printf("==Version: 0.006                        ==\n");
	printf("==Core function Matrix Multiply         ==\n");
	printf("==========================================\n");

	if( Commands(argc, argv) != 0){printf("Died in arg function!\n"); exit(-1);}

	printf("\nMatrix Sizes:\nMA: %dx%d\nMB: %dx%d\nMC: %dx%d\n\n", nAsize,mAsize,nBsize,mBsize,nCsize,mCsize);

	printf("Using the precision: %d bits\n\n", (int)sizeof(dataType)*8);

	//various loop parameters
	int i = 0;
	int j = 0;
	int z = 0;

	//open file
	output = fopen("output.txt", "a+");
	if( output == NULL){printf("Cannot open file!\n"); exit(-1);}


	//Allocate memory for each matrix
	dataType **matrixA = (dataType **)malloc(nAsize * sizeof(*matrixA));
	if(!(matrixA[0] = (dataType *)malloc(nAsize * mAsize * sizeof(dataType))))
	{
		printf("OUT OF MEMORY!\n");
		free(matrixA[0]);
		free(matrixA);
		exit(-2);
	}
	for( i = 1; i < nAsize; i++) {
		matrixA[i] = matrixA[0] + i * mAsize;
		//DEBUG: printf("Address: %p\n", matrixA[i]);
	}

	dataType **matrixB = (dataType **)malloc(nBsize * sizeof(*matrixB));
	if(!(matrixB[0] = (dataType *)malloc(nBsize * mBsize * sizeof(dataType))))
	{
		printf("OUT OF MEMORY!\n");
		free(matrixB[0]);
		free(matrixB);
		exit(-2);
	}
	i = 0;
	for( i = 1; i < nBsize; i++) {
		matrixB[i] = matrixB[0] + i * mBsize;
	}

	dataType **matrixC = (dataType **)malloc(nCsize * sizeof(*matrixC));
	if(!(matrixC[0] = (dataType *)malloc(nCsize * mCsize * sizeof(dataType))))
	{
		printf("OUT OF MEMORY!\n");
		free(matrixC[0]);
		free(matrixC);
		exit(-2);
	}
	i = 0;
	for( i = 1; i < nCsize; i++) {
			matrixC[i] = matrixC[0] + i * mCsize;
		}


//this block initializes two input matrices with values ranging from 0 to N x M. Replaces the previous version of using a random function
//for actual matrix replaces this code segment with actual matrix
	int i2=0;
	int j2=0;
	for(i2 = 0; i2 < nAsize; i2++){
		for(j2 = 0; j2 < mAsize; j2++){
			matrixA[i2][j2] = (dataType) i2 + j2;
		}
	}
	for(i2 = 0; i2 < nAsize; i2++){
		for(j2 = 0; j2 < mAsize; j2++){
			matrixB[i2][j2] = (dataType) i2 + j2;
		}
	}
	for(i2 = 0; i2 < nAsize; i2++){
		for(j2 = 0; j2 < mAsize; j2++){
			matrixC[i2][j2] = (dataType) 0;
		}
	}

/*
//change format type to support double
//	//DEBUG: Print matrix A
	printf("Matrix A:\n");
	for(i2 = 0; i2 < nAsize; i2++) {
		printf("[");
		for(j2 = 0; j2 < mAsize; j2++) {
			printf(" %g", matrixA[i2][j2]);
		}
		printf(" ]\n");
	}
//	//DEBUG: Print matrix B
	printf("Matrix B:\n");
	for(i2 = 0; i2 < nBsize; i2++) {
		printf("[");
		for(j2 = 0; j2 < mBsize; j2++) {
			printf(" %g", matrixB[i2][j2]);
		}
		printf(" ]\n");
	}
//	//DEBUG: Print matrix C
	printf("Matrix C:\n");
	for(i2 = 0; i2 < nCsize; i2++) {
		printf("[");
		for(j2 = 0; j2 < mCsize; j2++) {
			printf(" %g", matrixC[i2][j2]);
		}
		printf(" ]\n");
	}
*/
    int r=0;
    omp_set_num_threads(8);
	gettimeofday(&startCycles, NULL);       //set timer
	start = time(NULL);

    #pragma omp parallel for private(i,j,z) shared(matrixA, matrixB, matrixC)
    for(r=0; r<runs; r++){              //run matrix multiply "runs" times and find the average time of computation
	//MATRIX MULTIPLICATION
        for( i = 0; i < nAsize; i++){
            for( j = 0; j < mBsize; j++){
                dataType sum = 0;
                for( z = 0; z < mAsize; z++){
                     sum += matrixA[i][z] * matrixB[z][j];
                }
                matrixC[i][j] = sum;
            }
        }
    }
	gettimeofday(&stopCycles, NULL);        //stop timer
	walltime = time(NULL) - start;          //stop timer
	walltime = walltime/runs;

	//Compute Time consumed
	timeUsed = ((double)stopCycles.tv_sec + (double)stopCycles.tv_usec/1000000) -
			((double)startCycles.tv_sec + (double)startCycles.tv_usec/1000000);

    timeUsed=timeUsed/runs;

    //compute ime consumed
	printf("\nFinished calculations.\n");
    printf("Matmul kernel wall clock time = %f sec\n", walltime);
    printf("MFlops = %f\n", (double)(nAsize*nAsize*2)*(double)(nAsize)/walltime/1.0e6);



/*    //DEBUG: Print result matrix
	printf("Result Matrix:\n");
	for(i = 0; i < nCsize; i++){
		printf("[ ");
		for(j = 0; j < mCsize; j++){
			printf("%g ", matrixC[i][j]);
		}
		printf("]\n");
	}
*/
    //print thread info
    printf("\n\n# of threads: %i\n", numThrds);

	//print resulting time
	fprintf(output, "Time:%f:s\n", timeUsed);
	printf("Time used: %f (s)\n", timeUsed);

	//free all the pointers!
	free(matrixA[0]);
	free(matrixA);
	free(matrixB[0]);
	free(matrixB);
	free(matrixC[0]);
	free(matrixC);
	if(fclose(output) != 0){printf("File did not close properly!\n");exit(-1);}

	printf("Program is exiting...\n");

	return 0;
}
Example #8
0
void C_DoCommand (const char *cmd)
{
	size_t argc, argsize;
	char **argv;
	char *args, *arg, *realargs;
	const char *data;
	DConsoleCommand *com;
	int check = -1;

	data = ParseString (cmd);
	if (!data)
		return;

	// Check if this is an action
	if (*com_token == '+')
	{
		check = GetActionBit (MakeKey (com_token + 1));
		//if (Actions[check] < 255)
		//	Actions[check]++;
		if (check != -1)
			Actions[check] = 1;
	}
	else if (*com_token == '-')
	{
		check = GetActionBit (MakeKey (com_token + 1));
		//if (Actions[check])
		//	Actions[check]--;
		if (check != -1)
			Actions[check] = 0;

		if ((check == ACTION_LOOKDOWN || check == ACTION_LOOKUP || check == ACTION_MLOOK) && lookspring)
			AddCommandString ("centerview");
	}

	// Check if this is a normal command
	if (check == -1)
	{
		argc = 1;
		argsize = strlen (com_token) + 1;

		realargs = new char[strlen (data) + 1];
		strcpy (realargs, data);

		while ( (data = ParseString (data)) )
		{
			argc++;
			argsize += strlen (com_token) + 1;
		}

		args = new char[argsize];
		argv = new char *[argc];

		arg = args;
		data = cmd;
		argsize = 0;
		while ( (data = ParseString (data)) )
		{
			strcpy (arg, com_token);
			argv[argsize] = arg;
			arg += strlen (arg);
			*arg++ = 0;
			argsize++;
		}

		// Checking for matching commands follows this search order:
		//	1. Check the Commands map
		//	2. Check the CVars list
		command_map_t::iterator c = Commands().find(StdStringToLower(argv[0]));

		if (c != Commands().end())
		{
			com = c->second;

			if(!safemode
			|| stricmp(argv[0], "if")==0
			|| stricmp(argv[0], "exec")==0)
			{
				com->argc = argc;
				com->argv = argv;
				com->args = realargs;
				com->m_Instigator = consoleplayer().mo;
				com->Run ();
			}
			else
			{
				Printf (PRINT_HIGH, "Not a cvar command \"%s\"\n", argv[0]);
			}
		}
		else
		{
			// Check for any CVars that match the command
			cvar_t *var, *dummy;

			if ( (var = cvar_t::FindCVar (argv[0], &dummy)) )
			{
				if (argc >= 2)
				{
					c = Commands().find("set");
					if (c != Commands().end())
					{
						com = c->second;
						com->argc = argc + 1;
						com->argv = argv - 1;	// Hack
						com->m_Instigator = consoleplayer().mo;
						com->Run();
					}
					else
						Printf(PRINT_HIGH, "set command not found\n");
				}
				else
				{
					c = Commands().find("get");
					if (c != Commands().end())
					{
						com = c->second;
						com->argc = argc + 1;
						com->argv = argv - 1;	// Hack
						com->m_Instigator = consoleplayer().mo;
						com->Run();
					}
					else
						Printf(PRINT_HIGH, "get command not found\n");
				}
			}
			else
			{
				// We don't know how to handle this command
				Printf (PRINT_HIGH, "Unknown command \"%s\"\n", argv[0]);
			}
		}
		delete[] argv;
		delete[] args;
		delete[] realargs;
	}
}
Example #9
0
void C_DoCommand (const char *cmd)
{
	size_t argc, argsize;
	char **argv;
	char *args, *arg, *realargs;
	const char *data;
	DConsoleCommand *com;
	int check = -1;

	data = ParseString (cmd);
	if (!data)
		return;

	// Check if this is an action
	if (*com_token == '+')
	{
		check = GetActionBit (MakeKey (com_token + 1));
		//if (Actions[check] < 255)
		//	Actions[check]++;
		Actions[check] = 1;
	}
	else if (*com_token == '-')
	{
		check = GetActionBit (MakeKey (com_token + 1));
		//if (Actions[check])
		//	Actions[check]--;
		Actions[check] = 0;
		if (check == ACTION_MLOOK && lookspring)
		{
			AddCommandString ("centerview");
		}
	}

	// Check if this is a normal command
	if (check == -1)
	{
		argc = 1;
		argsize = strlen (com_token) + 1;

		realargs = new char[strlen (data) + 1];
		strcpy (realargs, data);

		while ( (data = ParseString (data)) )
		{
			argc++;
			argsize += strlen (com_token) + 1;
		}

		args = new char[argsize];
		argv = new char *[argc];

		arg = args;
		data = cmd;
		argsize = 0;
		while ( (data = ParseString (data)) )
		{
			strcpy (arg, com_token);
			argv[argsize] = arg;
			arg += strlen (arg);
			*arg++ = 0;
			argsize++;
		}

		// Checking for matching commands follows this search order:
		//	1. Check the Commands map
		//	2. Check the CVars list
		command_map_t::iterator c = Commands().find(argv[0]);

		if (c != Commands().end())
		{
			com = c->second;

			if(!safemode
			|| strcmp(argv[0], "if")==0
			|| strcmp(argv[0], "exec")==0)
			{
				com->argc = argc;
				com->argv = argv;
				com->args = realargs;
				com->m_Instigator = consoleplayer().mo;
				com->Run ();
			}
			else
			{
				Printf (PRINT_HIGH, "Not a cvar command \"%s\"\n", argv[0]);
			}
		}
		else
		{
			// Check for any CVars that match the command
			cvar_t *var, *dummy;

			if ( (var = cvar_t::FindCVar (argv[0], &dummy)) )
			{
				if (argc >= 2)
				{
					c = Commands().find("set");

					if(c != Commands().end())
					{
						com = c->second;

						com->argc = argc + 1;
						com->argv = argv - 1;	// Hack
						com->m_Instigator = consoleplayer().mo;
						com->Run ();
					}
					else Printf (PRINT_HIGH, "set command not found\n");
				}
                // [Russell] - Don't make the user feel inadequate, tell
                // them its either enabled, disabled or its other value
                else if (var->cstring()[0] == '1' && !(var->m_Flags & CVAR_NOENABLEDISABLE))
                    Printf (PRINT_HIGH, "\"%s\" is enabled.\n", var->name());
                else if (var->cstring()[0] == '0' && !(var->m_Flags & CVAR_NOENABLEDISABLE))
                    Printf (PRINT_HIGH, "\"%s\" is disabled.\n", var->name());
                else
                    Printf (PRINT_HIGH, "\"%s\" is \"%s\"\n", var->name(), var->cstring());
			}
			else
			{
				// We don't know how to handle this command
				Printf (PRINT_HIGH, "Unknown command \"%s\"\n", argv[0]);
			}
		}
		delete[] argv;
		delete[] args;
		delete[] realargs;
	}
}
Example #10
0
eOSState cMenuSearchMain::ProcessKey(eKeys Key)
{
    bool HadSubMenu = HasSubMenu();
    eOSState state = cOsdMenu::ProcessKey(Key);

    if (exitToMainMenu == 1)
    {
	exitToMainMenu = 0;
	return osBack;
    }

   if (!HasSubMenu() && HadSubMenu)
      UpdateCurrent();

    if (state == osUnknown) {
	switch (Key) {
	 case kFastRew:
	     if (HasSubMenu() && !InWhatsOnMenu && !InFavoritesMenu)
	     {
/*            if (Count())
            {
               CursorUp();
               return ShowSummary();
            }
*/	     }
	     else
            return Shift(-EPGSearchConfig.timeShiftValue);
	 case kFastFwd:
	     if (HasSubMenu() && !InWhatsOnMenu && !InFavoritesMenu)
	     {
/*		 if (Count())
		 {
		     CursorDown();
		     return ShowSummary();
		 }
*/	     }
	     else
		 return Shift(EPGSearchConfig.timeShiftValue);
	 case kRecord:
	 case kRed:
	     if(HasSubMenu()) {
            UpdateCurrent();
            state = Record();
            break;
	     }
	     if (Count())
	     {
		 if (EPGSearchConfig.redkeymode==toggleKeys)
		     state = Record();
		 else
		 {
		     cMenuMyScheduleItem *mi = (cMenuMyScheduleItem *)Get(Current());
		     if (mi) {
			 if (mi->event) {
			     return AddSubMenu(new cMenuSearchCommands(tr("EPG Commands"),mi->event));
			 }
		     }
		 }
	     }
	     break;
	 case k0:
	     if(!HasSubMenu())
	     {
		 toggleKeys = 1 - toggleKeys;
		 SetHelpKeys(true);
	     }
	     state = osContinue;
	     break;
	 case k1...k9:
	     if (!HasSubMenu())
		 return Commands(Key);
	     else
		 state = osContinue;
	     break;
	 case kGreen:
	     if (schedules)
	     {
		 if (HasSubMenu() && !InWhatsOnMenu && !InFavoritesMenu)
		 {
		     if (Count())
		     {
//			 CursorUp();
//			 return ShowSummary();
		     }
		 }
		 else if (toggleKeys == 0 || (toggleKeys == 1 && EPGSearchConfig.toggleGreenYellow == 0))
		 {
		     int ChannelNr = cDevice::CurrentChannel();
		     if (Count()) {
			 cMenuMyScheduleItem* Item = (cMenuMyScheduleItem *)Get(Current());
			 if (Item && Item->event)
			 {
			     cChannel *channel = Channels.GetByChannelID(Item->event->ChannelID(), true, true);
			     if (channel)
				 ChannelNr = channel->Number();
			 }
		     }
		     if (cMenuWhatsOnSearch::currentShowMode == showFavorites)
		     {
			 InFavoritesMenu = true;
			 return AddSubMenu(new cMenuFavorites());
		     }
		     else
		     {
			 InWhatsOnMenu = true;
			 return AddSubMenu(new cMenuWhatsOnSearch(schedules, ChannelNr));
		     }
		 }
		 else
		 {
		     cChannel *channel = Channels.GetByNumber(currentChannel-1,-1);

		     if (channel) {
			 PrepareSchedule(channel);
			 if (channel->Number() != cDevice::CurrentChannel()) {
			     otherChannel = channel->Number();
			 }
			 Display();
		     }
		     SetHelpKeys(true);
		     return osContinue;
		 }
	     }
	 case kYellow:
	     if (schedules)
	     {
		 if (HasSubMenu())
		 {
		     if (Count())
		     {
//			 CursorDown();
//			 return ShowSummary();
		     }
		 }
		 else if (toggleKeys == 0 || (toggleKeys == 1 && EPGSearchConfig.toggleGreenYellow == 0))
		 {
		     cMenuWhatsOnSearch::currentShowMode = showNext;
		     InWhatsOnMenu = true;
		     return AddSubMenu(new cMenuWhatsOnSearch(schedules, cMenuWhatsOnSearch::CurrentChannel()));
		 }
		 else
		 {
		     cChannel *channel = Channels.GetByNumber(currentChannel+1,1);
		     if (channel) {
			 PrepareSchedule(channel);
			 if (channel->Number() != cDevice::CurrentChannel()) {
			     otherChannel = channel->Number();
			 }
			 Display();
		     }
		     SetHelpKeys(true);
		     return osContinue;
		 }
	     }
	     break;
	 case kBlue:
        if (HasSubMenu())
        {
           UpdateCurrent();
           return Switch();
        }
	     if (EPGSearchConfig.bluekeymode==toggleKeys)
		 return Switch();
	     else
		 return ExtendedSearch();
	     break;
	case kInfo:
	case kOk:
	   if (Count())
	       return ShowSummary();
	   break;
	 default:
	     break;
	}
    }
    if (!HasSubMenu()) {
      cChannel *ch = cMenuWhatsOnSearch::ScheduleChannel();
      InWhatsOnMenu = false;
      InFavoritesMenu = false;
      if (ch) {
	// when switch from the other menus to the schedule, try to keep the same time
       	if (cMenuWhatsOnSearch::shiftTime)
	  {
	    time_t diff = cMenuWhatsOnSearch::seekTime - time(NULL);
	    shiftTime = (diff + (diff>0?30:-30)) / 60 ;
	  }
	else
	  shiftTime = 0;

	PrepareSchedule(ch);
	if (ch->Number() != cDevice::CurrentChannel()) {
	  otherChannel = ch->Number();
	}
	Display();
      }
      else if ((HadSubMenu || gl_TimerProgged) && Update())
      {
	  if (gl_TimerProgged) // when using epgsearch's timer edit menu, update is delayed because of SVDRP
	  {
	      gl_TimerProgged = 0;
	      SetHelpKeys();
	  }
	  Display();
      }
      if (Key != kNone)
	  SetHelpKeys();
      if (gl_InfoConflict)
      {
	  gl_InfoConflict = 0;
	  if (Interface->Confirm(tr("Timer conflict! Show?")))
	      return AddSubMenu(new cMenuConflictCheck());
      }
  }
  return state;
}