コード例 #1
0
//====================================
void openCommand()
//====================================
{
  struct stat st;
  int ch,nsteps=1000,x,i,n,stop=0,loop,projNo = 0,ok=0,tmp;
  char *p,str[120],sstr[20],fileName[120],temp[120],syscom[120];
  char command[40][40];

  s_mode = S_ADMIN;
  g_silent = 0;

  readMsg(gplFile);

  while(strstr(str,"ex") == NULL)
    {
      anyErrors();
      unoInfo();

      wmove(uno,board_h-2,1);
      wprintw(uno,"                                                  ");
      if(g_silent==S_NO )mvwprintw(uno,board_h-2,1,"A%1d>",confWinMode);
      if(g_silent==S_YES)mvwprintw(uno,board_h-2,1,"A%1d<",confWinMode);

      strcpy(command[0],"");

      wgetstr(uno,str);

      n = tokCommand(command,str);

      strcpy(sstr,command[0]);

      p = str;

      projNo = atoi(sstr);

      if(strstr(sstr,"gpl"))
        {
          readMsg(gplFile);
        }
      else if(strstr(sstr,"err"))
        {
          readMsg(fileTemp);
        }
      else if(strstr(sstr,"run"))
	{
	  stop = 1;
          if(n == 2)stop = atoi(command[1]);
	  stop = checkRange(HEAL,"step",stop);

	  runMode(stop);
          if(stop==0)putMsg(2,"Back in Admin Mode!");
	}
      else if(strstr(sstr,"res")) // reset simulation
	{
	  resetSim();
	  init(confWinMode);
	  unoInfo();
	  readMsg(currentConf);
	}
      else if(strstr(sstr,"help")) //
	{
	  strcpy(fileName,fileInfoAdmin);
	  readMsg(fileName);
	}
      else if(strstr(sstr,"rem")) //
	{
	  if(n == 4)
	    {
	      if(strstr(command[1],"a"))g_pinType = ANA;
	      if(strstr(command[1],"d"))g_pinType = DIG;
	      g_pinNo   = atoi(command[2]);
	      g_pinStep = atoi(command[3]);
	      if(g_pinType == ANA)
		ok = checkRange(S_OK,"anapin",g_pinNo);
	      if(g_pinType == DIG)
		ok = checkRange(S_OK,"digpin",g_pinNo);
	      if(ok == S_OK)
		{
		  g_scenSource = 1;
		  sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,0,g_pinStep,S_DELETE);
		  //putMsg(2,syscom);
		  tmp=system(syscom);
		  initSim();
		  readSketchInfo();
		  readSimulation();
		  runStep(S_FORWARD);
		  readMsg(fileServScen);
		}
	      else
		putMsg(2,"Wrong pin number or pin type!");
	    }
	  else
	    putMsg(2,"Syntax: rem <a or d> <pin> <step>");
	}
      else if(strstr(sstr,"add")) //
	{
	  if(n == 5)
	    {
	      if(strstr(command[1],"a"))g_pinType = ANA;
	      if(strstr(command[1],"d"))g_pinType = DIG;

	      g_pinNo    = atoi(command[2]);
	      g_pinStep  = atoi(command[3]);
	      g_pinValue = atoi(command[4]);

	      ok = S_OK;
	      if(g_pinType == ANA)
		ok = checkRange(S_OK,"anapin",g_pinNo);
	      if(g_pinType == DIG)
		ok = checkRange(S_OK,"digpin",g_pinNo);

	      ok = ok + checkRange(S_OK,"step",g_pinStep);

	      if(ok == S_OK)
		{
		  g_scenSource = 1;
		  sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,g_pinValue,g_pinStep,S_ADD);
		  tmp=system(syscom);
		  initSim();
		  readSketchInfo();
		  readSimulation();
		  runStep(S_FORWARD);
		  readMsg(fileServScen);
		}
	    }
	  else
	    putMsg(2,"Syntax: add <a or d> <pin> <step> <value>");
	}
      else if(strstr(sstr,"info"))
	{
	  if(n == 2)
	    {
	      if(strstr(command[1],"conf"))
		{
		  readMsg(fileDefault);
		}
	      else if(strstr(command[1],"err"))
		{
		  readMsg(fileServError);
		}
	      else if(strstr(command[1],"g++"))
		{
		  readMsg(fileServComp);
		}
	      else if(strstr(command[1],"help"))
		{
		  readMsg(fileInfoAdmin);
		}
	      else if(strstr(command[1],"loop")) 
		{
		  showLoops();
		}
	      else if(strstr(command[1],"scen")) // scenario
		{
		  readMsg(fileServScen);
		}
	    }
	  else
	    {
	      readMsg(fileInfoAdmin);
	    }
	}

      else if(strstr(sstr,"proj"))
	{
	  if(n == 2)
	    {
	      strcpy(currentConf,command[1]);
	      strcat(currentConf,".conf");
	      readConfig(currentConf);
              g_warning = S_YES;
	      unoInfo();
	    }
	  readMsg(currentConf);
	}
      else if(strstr(sstr,"list"))
	{
	  readMsg(fileProjList);	
	}
      else if(strstr(sstr,"sketch"))
	{
	  if(n == 2)
	    {
	      if(strstr(command[1],"conf"))
		{
		  readMsg(confSketchFile);
		}
	      else if(strstr(command[1],"work"))
		{
		  readMsg(fileServSketch);
		}
	    }
	  else
	    readMsg(fileServSketch);	
	}
      else if(strstr(sstr,"conf"))
	{
	  if(n == 3)
	    {
	      if(strstr(command[1],"sim"))
		{
		  confSteps = atoi(command[2]);	
		}
	      else if(strstr(command[1],"win"))
		{
		  confWinMode = atoi(command[2]);
		  if(confWinMode > WIN_MODES)confWinMode = 0;
		  init(confWinMode);
		  unoInfo();
		}
	      else if(strstr(command[1],"sketch"))
		{
		  strcpy(temp,command[2]);
		  if(stat(temp,&st) == 0)
		    {
		      strcpy(confSketchFile,command[2]);
		    }
		  else
		    {
		      sprintf(temp,"Sketch not found: %s",command[2]);// Issue 16
		      putMsg(msg_h-2,temp);
		    }
		}
	      saveConfig(currentConf);
	    }
	  readMsg(currentConf); 
	}
      
      
      else if(strstr(sstr,"sav")) //save config
	{
	  if(n == 2)
	    {
	      strcpy(currentConf,command[1]);
	      strcat(currentConf,".conf");
              
	    }
	  saveConfig(currentConf);
	  readMsg(currentConf);
	  sprintf(syscom,"ls *.conf > %s;",fileProjList);
	  x=system(syscom);
	}
      else if(strstr(sstr,"del")) //delete config
	{
	  if(n == 2)
	    {
	      strcpy(currentConf,command[1]);
	      strcat(currentConf,".conf");
              
	    }
          if(strstr(currentConf,"default") == NULL)
	    {
	      sprintf(syscom,"rm %s;",currentConf);
	      x=system(syscom);
	      sprintf(syscom,"ls *.conf > %s;",fileProjList);
	      x=system(syscom);
	      readMsg(fileProjList);
	      strcpy(currentConf,fileDefault);
	    }	
	}
      else if(strstr(sstr,"win")) //windows layout
        {
          if(n == 2)
	    {
              confWinMode = atoi(command[1]);
              if(confWinMode > WIN_MODES)confWinMode = 0;
              init(confWinMode);
              unoInfo();
	    }
        }
      else if(strstr(sstr,"loop"))
	{
          if(n == 2)loop = atoi(command[1]);
	  loop = checkRange(HEAL,"loop",loop);
	  runLoops(loop);
	}
      else if(strstr(sstr,"clear"))
	{
	  sprintf(syscom,"rm servuino/sketch.ino;rm servuino/data.su;rm servuino/data.scen;");
	  x=system(syscom);
	}
      else if(strstr(sstr,"load"))
	{
          if(n == 2)
	    {
	      confSteps = atoi(command[1]);
	    }
          g_scenSource = 0;
	  loadCurrentProj();
	}
      else if(projNo > 0 && projNo < 10)
        {
	  selectProj(projNo,currentConf);
	  readConfig(currentConf);
	  g_warning = S_YES;
	  unoInfo();
	  readMsg(currentConf);   
        }
      else if(strstr(sstr,"data"))
	{
	  if(n == 2)
	    {
	      if(strstr(command[1],"ard"))
		{
		  readMsg(fileServArduino);
		}
	      else if(strstr(command[1],"cus"))
		{
		  readMsg(fileServCustom);
		}
	      else if(strstr(command[1],"cod"))
		{
		  readMsg(fileServCode);
		}
	      else if(strstr(command[1],"err"))
		{
		  readMsg(fileServError);
		}
	      else if(strstr(command[1],"sce"))
		{
		  readMsg(fileServScen);
		}
	    }
	  else
	    readMsg(fileServArduino);
	}
      else 
	{
	  putMsg(msg_h-2,"Unknown Admin command");
	}
    }
}
コード例 #2
0
bool ValgrindTool::canRun(RunConfiguration *, RunMode mode) const
{
    return mode == runMode();
}