Пример #1
0
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;       
		case WM_KEYDOWN:
			switch (wParam) {
				case VK_ESCAPE: case 'q': case 'Q':
					DestroyWindow(hWnd);
					break;
				case VK_SPACE:
					g_Sim.tick();
					break;
				case 'r': case 'R':
					initSim();
					break;
				case 'f': case 'F':
					g_Sim.point(0).setFixed(false);
					break;
			}		
			return 0;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}
Пример #2
0
//====================================
void loadCurrentProj()
//====================================
{
  int x,res;
  char syscom[120],temp[200];

  g_warning = S_NO;
  putMsg(1,"Loading ...");
  res = loadSketch(confSketchFile);
  if(res == 0)
  {
    if(confSteps < 0) confSteps = 100;
    if(confSteps > MAX_STEP) confSteps = MAX_STEP-1;
    sprintf(syscom,"cd servuino;./servuino %d %d;",confSteps,g_scenSource);
    x=system(syscom);
    initSim();
    resetSim();
    readSimulation();
    readSketchInfo();
    setRange(confBoardType);
    init(confWinMode);
    saveConfig(currentConf);
    unoInfo();
    sprintf(temp,"Sketch load ready: %s",confSketchFile);
    putMsg(msg_h-2,temp);
  }
}
Пример #3
0
void* naCreate() {
	struct tkState* gState = (struct tkState*) malloc(sizeof(struct tkState));
	if(gState) {
		gState->simTok = NULL;
		// Initialise the Simulator
		initSim(gState);
		// Initialise the items in the simulation
		initBodies(gState);
	}
	return (void *) gState;
}
Пример #4
0
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

	initSim();

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = "WindowClass";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL, "WindowClass", "Direct3D",
                          WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                          NULL, NULL, hInstance, NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    initD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message == WM_QUIT)
            break;

        render_frame();
    }

    // clean up DirectX and COM
    cleanD3D();

    return msg.wParam;
}
Пример #5
0
/*
 * Grund für den letzten Start der CPU
 */
void init_type()
{
	//info("Ermittelt den Startgrund");
	adl_InitType_e result =
			adl_InitGetType();

	//info("Behandelt des Startgrund");
	switch(result)
	{
	case ADL_INIT_POWER_ON:
		info("Startgrund: Normaler Start");
		break;
	case ADL_INIT_REBOOT_FROM_EXCEPTION:
		info("Startgrund: Neustart nach schwerem Fehler durch die ADL");
		break;
	case ADL_INIT_DOWNLOAD_SUCCESS:
		info("Startgrund: Neustart nach erfolgreicher Installation");
		break;
	case ADL_INIT_DOWNLOAD_ERROR:
		info("Startgrund: Neustart nach gescheiterter Installation");
		break;
	case ADL_INIT_RTC:
		info("Startgrund: Start durch Wecksignal der Echtzeituhr");
		break;
	default:
		info("Unbekanntes Ereignis");
		break;
	}

	// UART2 muss mit 'at+wmfm=0,1,2' aktiviert worden sein!

	// Konfiguriert UART2 Bus für den GPS Empfänger
	adl_atCmdCreate("AT+IPR=38400", ADL_AT_PORT_TYPE(ADL_PORT_UART2, FALSE), (adl_atRspHandler_t) NULL, NULL);
	adl_atCmdCreate("AT+ICF=3",     ADL_AT_PORT_TYPE(ADL_PORT_UART2, FALSE), (adl_atRspHandler_t) NULL, NULL);
	adl_atCmdCreate("AT+IFC=0,0",   ADL_AT_PORT_TYPE(ADL_PORT_UART2, FALSE), (adl_atRspHandler_t) NULL, NULL);

	// Aktiviert den GPS Empfänger
	gps_io_handle = adl_ioSubscribe(1, &gps_io_label, 0, 0, 0);
	adl_ioWriteSingle(gps_io_handle, &gps_io_write, TRUE);

	// Verarbeitet die Daten des GPS Empfängers
	gps_fcm_handle = adl_fcmSubscribe(ADL_PORT_UART2, gps_fcm_ctrl_handler, gps_fcm_data_handler);

	gps_data = ",,,,,,,,,,,";

	if(!INIT_CONFIG)
		//info("Die Anwenderapplikation wird gestartet");
		appli_mainTask();
	else
		//info("Das Modul wird im Netz registriert");
		initSim();
}
Пример #6
0
//------------------------------------------------------------------------------
int main (int argc, char* argv[])
{  
    cudaGLSetGLDevice(0); 
    glutInit(&argc, argv);
    glutInitContextVersion(3, 3);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutCreateWindow("");
	glewExperimental = TRUE;
	glewInit();
    initGL();
    initSim();
	glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(mouseMotion);
	glutKeyboardFunc(keyboard);
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, 
        GLUT_ACTION_GLUTMAINLOOP_RETURNS);
    glutMainLoop();
    return 0;
}
Пример #7
0
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(windowWidth, windowHeight);
	glutCreateWindow("Water Simulation 2D");

	initGL();
	initSim();

	glutReshapeFunc(reshape);
	glutIdleFunc(idle);
	glutDisplayFunc(display);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);
	glutKeyboardFunc(keyboard);

	fps.init();

	glutMainLoop();

	return 0;
}
Пример #8
0
//====================================
int main(int argc, char *argv[])
//====================================
{
  char syscom[120];
  int ch,i,x;

  currentStep = 1;
  currentLoop = 0;



  strcpy(gplFile,"gpl.txt");

  inrpt[0] = IR0;
  inrpt[1] = IR1;
  inrpt[2] = IR2;
  inrpt[3] = IR3;
  inrpt[4] = IR4;
  inrpt[5] = IR5;


  sprintf(syscom,"ls *.conf > %s;",fileProjList);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileTemp,fileTemp);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileError,fileError);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileServError,fileServError);
  x=system(syscom);
  sprintf(syscom,"rm %s;touch %s;",fileCopyError,fileCopyError);
  x=system(syscom);

  err = fopen(fileError,"w"); // Issue 15

  readSetting();
  readConfig(currentConf);


  initSim();

  resetSim();

  readSimulation();

  readSketchInfo();

  setRange(confBoardType);

  init(confWinMode);

  unoInfo();
  show(slog);

  if(confLogFile == S_YES)resetFile("log.txt");

  readMsg(gplFile);

  openCommand();
  
  delwin(uno);
  delwin(ser);
  delwin(slog);
  delwin(msg);
  endwin();

  fclose(err);

}
Пример #9
0
//====================================
void runMode(int stop)
//====================================
{
  int ch,x,step,tmp,res=0,a=0,b=0,ir,ok=0,n=0;
  char tempName[80],syscom[120],temp[80];
  char command[40][40];

  strcpy(tempName,"help.txt");

  s_mode = S_RUN;


  if(stop > 1)
    {
      if(stop > g_steps)stop = g_steps;
      //if(stop > currentStep)
	runAll(stop);
      return;
    }

  putMsg(3,"Run Mode. Press h for help.");

  while(1)  
    {
      anyErrors();
      if(g_silent==S_NO )mvwprintw(uno,board_h-2,1,"R%1d>",confWinMode);
      if(g_silent==S_YES)mvwprintw(uno,board_h-2,1,"R%1d<",confWinMode);
      unoInfo();

      if(g_debug == 1) 
	readFile(confSketchFile,g_lineSketch[currentStep]);


      ch = getchar();

      if (ch=='q')
	{
	  return;
	}

      if (ch=='h')
        {
          readMsg(fileInfoRun);
        }
      else if (ch=='c')
        {
          readMsg(currentConf);
        }
      else if (ch=='d')
        {
          readMsg(fileServTime);
        }
      else if(ch=='y' ) // scenario
	{
	  readMsg(fileServScen);
	}
      else if (ch=='x')
	{
	  readMsg(fileServScenario);
	}
      else if (ch=='G')
	{
	  runAll(g_steps);
	}
      else if (ch=='l')
	{
	  showLoops();
	}
      else if (ch=='s')
	{
	  g_debug++;
	  if(g_debug > 1)g_debug = 0;
	}
      else if (ch=='w')
	{
	  confWinMode++;
	  if(confWinMode > WIN_MODES)confWinMode = 0;
          init(confWinMode);
	  mvwprintw(uno,board_h-2,1,"R%1d>",confWinMode);
	  unoInfo();
	}
      else if (ch=='a')
	{
          goStep(1);
	}
      else if (ch=='r')
	{
          goStep(loopStep[currentLoop+1]);
	}
      else if (ch=='o')
	{
          goStep(loopStep[currentLoop]);
	}
      else if (ch=='p')
	{
          goStep(loopStep[currentLoop-1]);
	}
      else if (ch=='z')
	{
          goStep(g_steps);
	}
      else if (ch=='k')
	{
	  resetSim();
	  init(confWinMode);
	  unoInfo();
	  mvwprintw(uno,board_h-2,1,"R%1d>",confWinMode);
	  show(uno);
	}
      else if (ch=='f')// Up Arrow 
	{
	  goStep(currentStep+1);
	}
      else if (ch=='b')// Down Arrow
	{
	  goStep(currentStep-1);
	}
      else if (ch=='R') // Right Arrow
	{
	  runLoop(S_FORWARD);
	}
      else if (ch=='P') // Left Arrow
	{
	  runLoop(S_BACKWARD);
	}
      else if (ch=='t')
	{
	  runNextRead();
	}
      else if (ch=='j')
	{
	  runPrevRead();
	}
      else if (ch=='i') 
	{
          step = currentStep;
	  sprintf(temp,"(Step:%d) Enter: d/a pin value (q - cancel)",step);
          putMsg(2,temp);
	  wgetstr(uno,temp);
	  n = tokCommand(command,temp);
      
	  if(strstr(command[0],"q") == NULL && n == 3)
	    {
	      g_pinNo = atoi(command[1]);
	      x = atoi(command[2]);
	      printf("%s %d %d",command[0],g_pinNo,x);
	      if(strstr(command[0],"a"))
		{
		  ok = ok + checkRange(S_OK,"anapin",g_pinNo);
		  ok = ok + checkRange(S_OK,"anaval",x);
		  g_pinType = ANA;
		}
	      if(strstr(command[0],"d"))
		{
		  ok = ok + checkRange(S_OK,"digpin",g_pinNo);
		  ok = ok + checkRange(S_OK,"digval",x);
		  g_pinType = DIG;
		}
	      if(ok == S_OK)
		{ 
		  g_scenSource = 1;
		  // steps, source, pintype, pinno, pinvalue, pinstep
		  sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,x,currentStep,S_ADD);
		  tmp=system(syscom);
		  initSim();
		  readSketchInfo();
		  readSimulation();
		  goStep(currentStep);
		  readMsg(fileServScen);
		}
	    }
	  else
	    putMsg(2,"Cancelled!");
	}
      else if (ch=='v') 
	{
          step = currentStep ;
	  sprintf(temp," Enter value to be read at step %d (q - cancel)",step);
          putMsg(2,temp);
	  res = analyzeEvent(simulation[step]);
          if(res > 0)
	    {
	      wgetstr(uno,temp);

	      if(strstr(temp,"q") == NULL)
		{
		  x = atoi(temp); 
		  ok = S_OK;
		  if(res == ANA)ok = ok + checkRange(S_OK,"anaval",x);
		  if(res == DIG)ok = ok + checkRange(S_OK,"digval",x);
		  if(ok == S_OK)
		    {         
		      g_scenSource = 1;
		      // steps, source, pintype, pinno, pinvalue, pinstep
		      sprintf(syscom,"cd servuino;./servuino %d %d %d %d %d %d %d;",confSteps,g_scenSource,g_pinType,g_pinNo,x,currentStep,S_ADD);
		      tmp=system(syscom);
		      initSim();
		      readSketchInfo();
		      readSimulation();
		      goStep(currentStep);
		      readMsg(fileServScen);
		    }
		}
	      else
		putMsg(2,"Cancelled!");
	    }
	  else
	    putMsg(2,"Next step is not a Read event");
	}
      else
	{
	  sprintf(temp,"Unknown command: %c",ch);
	  putMsg(msg_h-2,temp);
	}
    }
  return;
}
Пример #10
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");
	}
    }
}
Пример #11
0
void boidInit(int numberOfDesires, RulesParameters *applyingRules, SimulationParameters simParams,InfoCache infoCache,Vector *leaderPosition)
{
	initSim(&simParams,applyingRules,&infoCache,numberOfDesires,leaderPosition);
}