Esempio n. 1
0
void GlobalCleanup()
{
	int t;

	stop_timer();
	for (t=0;t<GLOBAL.objects;t++) objects[t]->session_stop();
	
	while (GLOBAL.objects>0)   free_object(0);
	
	BreakDownCommPort();
	// for (t=0;t<GLOBAL.objects;t++) free_object(0);

    CloseHandle(TTY.ThreadExitEvent);
	for (t=0;t<GLOBAL.midiports;t++)
  	  if (MIDIPORTS[t].midiout) midiOutClose(MIDIPORTS[t].midiout);

	if (CAPTFILE.filehandle!=0) CloseHandle(CAPTFILE.filehandle);

	SDLNet_Quit();
	SDL_Quit();

	DeleteObject(DRAW.brush_blue);
	DeleteObject(DRAW.pen_blue);
	DeleteObject(DRAW.pen_white);
	write_logfile("BrainBay normal shutdown.");

    return;
}
Esempio n. 2
0
BOOL load_configfile(LPCTSTR pszFileName)
{

    HANDLE hFile;
	int t, act_samplingrate=DEF_PACKETSPERSECOND; 
	int act_type,num_objects, save_toolbox, save_connected, try_connect;
	const char * d_name;
	char new_name[256],szdata[20];

	write_logfile("loading design configuration: %s",(char *)pszFileName);

    hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if(hFile != INVALID_HANDLE_VALUE)
    {
		GLOBAL.loading=1;
		d_name=pszFileName;
		while (strstr(d_name,"\\")) d_name=strstr(d_name,"\\")+1;
		strcpy(new_name,"BrainBay - ");strcat(new_name,d_name);
	    SetWindowText(ghWndMain,new_name);
		strcpy(GLOBAL.configfile,pszFileName);
		save_settings();
		save_toolbox=-1;

		save_connected=TTY.CONNECTED;
		SendMessage(ghWndStatusbox,WM_COMMAND, IDC_STOPSESSION,0);
		
		//TTY.read_pause=1;
		close_captfile();

		if (ghWndAnimation!=NULL) SendMessage(ghWndAnimation,WM_CLOSE,0,0);
		ghWndAnimation=NULL;

		close_toolbox();actobject=NULL;
		//InvalidateRect(ghWndMain, NULL, TRUE);

		while (GLOBAL.objects>0)
		    free_object(0);

		GLOBAL.run_exception=0;
		GLOBAL.minimized=FALSE;

	     load_next_config_buffer(hFile);
		 load_property("objects",P_INT,&GLOBAL.objects);
		 load_property("main-top",P_INT,&GLOBAL.top);
		 load_property("main-left",P_INT,&GLOBAL.left);
		 load_property("main-right",P_INT,&GLOBAL.right);
		 load_property("main-bottom",P_INT,&GLOBAL.bottom);
		 load_property("anim-top",P_INT,&GLOBAL.anim_top);
		 load_property("anim-left",P_INT,&GLOBAL.anim_left);
		 load_property("anim-right",P_INT,&GLOBAL.anim_right);
		 load_property("anim-bottom",P_INT,&GLOBAL.anim_bottom);
		 load_property("design-top",P_INT,&GLOBAL.design_top);
		 load_property("design-left",P_INT,&GLOBAL.design_left);
		 load_property("design-right",P_INT,&GLOBAL.design_right);
		 load_property("design-bottom",P_INT,&GLOBAL.design_bottom);
		 load_property("tool-top",P_INT,&GLOBAL.tool_top);
		 load_property("tool-left",P_INT,&GLOBAL.tool_left);
		 load_property("tool-right",P_INT,&GLOBAL.tool_right);
		 load_property("tool-bottom",P_INT,&GLOBAL.tool_bottom);
		 load_property("showdesign",P_INT,&GLOBAL.showdesign);
		 load_property("hidestatus",P_INT,&GLOBAL.hidestatus);
		 load_property("showtoolbox",P_INT,&GLOBAL.showtoolbox);
		 load_property("autorun",P_INT,&GLOBAL.autorun);
		 load_property("minimized",P_INT,&GLOBAL.minimized);
		 save_toolbox=GLOBAL.showtoolbox;


		 TTY.PORT=0;try_connect=0;
		 load_property("comport",P_INT,&TTY.PORT);		 
		 load_property("connected",P_INT,&try_connect);	 
		 load_property("bidirect",P_INT,&TTY.BIDIRECT);
		 load_property("devicetype",P_INT,&TTY.devicetype);
		 load_property("samplingtype",P_INT,&TTY.samplingrate);
		 load_property("baudtype",P_INT,&TTY.BAUDRATE);
		 load_property("flow_control",P_INT,&TTY.FLOW_CONTROL);

		 if (save_connected) { update_p21state(); save_connected=TTY.CONNECTED; }
		 BreakDownCommPort();  
		 if (try_connect) { TTY.CONNECTED=SetupCommPort(TTY.PORT); update_p21state(); }
		
		 load_property("captfilename",P_STRING,CAPTFILE.filename);
		 load_property("captfiletype",P_INT,&CAPTFILE.filetype);
		 load_property("captfileoffset",P_INT,&CAPTFILE.offset);
	 	 load_property("dialoginterval",P_INT,&GLOBAL.dialog_interval);
		 load_property("drawinterval",P_INT,&GLOBAL.draw_interval);
		 load_property("samplingrate",P_INT,&act_samplingrate);
		 PACKETSPERSECOND=act_samplingrate;

		 MoveWindow(ghWndMain,GLOBAL.left,GLOBAL.top,GLOBAL.right-GLOBAL.left,GLOBAL.bottom-GLOBAL.top,TRUE);
		 MoveWindow(ghWndDesign,GLOBAL.design_left,GLOBAL.design_top,GLOBAL.design_right-GLOBAL.design_left,GLOBAL.design_bottom-GLOBAL.design_top,TRUE);
		 if (!GLOBAL.showdesign)
		 {  
			 ShowWindow(ghWndDesign, FALSE); 
			 SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Show Design"); 
		 }
		 else 
		 {
			 ShowWindow(ghWndDesign,TRUE);
		     SetWindowPos(ghWndDesign,0,0,0,0,0,SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE);
			 SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Hide Design"); 
		 }
		 if (!GLOBAL.hidestatus)
		 	 ShowWindow(ghWndStatusbox, TRUE); 
		 else	 ShowWindow(ghWndStatusbox,FALSE);
		     
		 num_objects=GLOBAL.objects;
		 GLOBAL.objects=0;
   		 for (t=0;t<num_objects;t++)
		 {
			act_type=load_next_config_buffer(hFile);
			if (act_type>=0)
			{	
				create_object(act_type);
				if (actobject != NULL )
				{
					actobject->load(hFile);
					link_object(actobject);
				}
				else critical_error("Could not load all objects, quitting ...\ndelete brainbay.cfg to prevent this at program startup ... ");

			}
		 }
		 CloseHandle(hFile);
		 for (t=0;t<num_objects;t++) objects[t]->update_inports();
		 update_dimensions();

		 CAPTFILE.filehandle=INVALID_HANDLE_VALUE;
		 CAPTFILE.do_read=0;
		 if (strcmp(CAPTFILE.filename,"none"))
		 {
			 char st[150];
			 reduce_filepath(st,CAPTFILE.filename);
			 strcpy(CAPTFILE.filename,GLOBAL.resourcepath);
			 strcat(CAPTFILE.filename,"ARCHIVES\\");
			 strcat(CAPTFILE.filename,st);			 
			 open_captfile(CAPTFILE.filename);
		 }

		 init_system_time();
		 reset_oscilloscopes();
		 PACKET.readstate=0;
		 ShowWindow( ghWndMain, TRUE ); UpdateWindow( ghWndMain ); 

 		 update_samplingrate(act_samplingrate);
		 update_devicetype();
		 get_session_length();


		 SetDlgItemInt(ghWndStatusbox,IDC_SAMPLINGRATE,act_samplingrate,0);
		 SetDlgItemText(ghWndStatusbox,IDC_STATUS,"Configuration loaded");
		 SetDlgItemText(ghWndStatusbox,IDC_TIME,"0.0");
		 SetDlgItemText(ghWndStatusbox,IDC_JUMPPOS,"0.0");
		 sprintf(szdata, "%.1f", (float)GLOBAL.session_length/(float)PACKETSPERSECOND);
		 SetDlgItemText(ghWndStatusbox,IDC_SESSLEN,szdata);
 		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)0);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,(LONG)0);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,(LONG)0);

		 SetWindowPos(ghWndMain,0,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		 InvalidateRect(ghWndMain,NULL,TRUE);
 		 InvalidateRect(ghWndDesign,NULL,TRUE);

		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,0);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,1000);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)(0));
		 if (GLOBAL.minimized) ShowWindow(ghWndMain, SW_MINIMIZE);

		 GLOBAL.loading=0;
		 if ((GLOBAL.autorun) && (!GLOBAL.run_exception)) SendMessage(ghWndStatusbox,WM_COMMAND, IDC_RUNSESSION,0);
  	    
		 if (save_toolbox!=-1)
		 {
			GLOBAL.showtoolbox=save_toolbox;
			actobject=objects[GLOBAL.showtoolbox];
			actobject->make_dialog();
		 } 
		 
		write_logfile("load successful");
		return TRUE;
		 
    }
	write_logfile("could not load design configuration file.");
	return FALSE;    	
}
Esempio n. 3
0
/*-----------------------------------------------------------------------------

FUNCTION: SetupCommPort( int Port )

PURPOSE: Setup Communication Port with our settings

-----------------------------------------------------------------------------*/
BOOL SetupCommPort(int port)
{
    DWORD dwReadStatId;
    DWORD dwWriteStatId;
	int sav_port,sav_pause;
    DCB dcb = {0};
	char PORTNAME[10];

	if (!port) return(false);

	sav_port=TTY.PORT;
	sav_pause=TTY.read_pause;
    TTY.read_pause=1;
    
	BreakDownCommPort();

	TTY.PORT = port ;

	// set tty structure for the specified port
	
	sprintf(PORTNAME,"\\\\.\\COM%d",port);
	PACKET.readstate=0;
	PACKET.number=0;
	PACKET.old_number=0;
	PACKET.info=0;

    // open communication port handle
//    TTY.COMDEV = CreateFile( PORTNAME,GENERIC_READ | GENERIC_WRITE, 
//                  0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,0);

    TTY.COMDEV = CreateFile( PORTNAME,GENERIC_READ | GENERIC_WRITE, 
                  0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

    if (TTY.COMDEV == INVALID_HANDLE_VALUE) goto failed;
    
    if (!GetCommState(TTY.COMDEV, &dcb))      // get current DCB settings
	{ report_error("GetCommState");goto failed; }

   
    // update DCB rate, byte size, parity, and stop bits size
   
	dcb.DCBlength = sizeof(dcb);
    dcb.BaudRate = TTY.BAUDRATE;
    dcb.ByteSize = 8;
    
	dcb.Parity   = NOPARITY;
    dcb.StopBits = ONESTOPBIT;
	dcb.EvtChar = '\0';

   
    // update flow control settings
   
    dcb.fDtrControl     =  DTR_CONTROL_ENABLE;
    dcb.fRtsControl     =  RTS_CONTROL_ENABLE;

	if (TTY.FLOW_CONTROL)
	{
      dcb.fOutxCtsFlow    = TRUE;
      dcb.fOutxDsrFlow    = TRUE;
	}
	else
	{
      dcb.fOutxCtsFlow    = FALSE;
      dcb.fOutxDsrFlow    = FALSE;
	}

    dcb.fDsrSensitivity = FALSE;;
    dcb.fOutX           = FALSE;
    dcb.fInX            = FALSE;
    dcb.fTXContinueOnXoff = FALSE;
    dcb.XonChar         = 0;
    dcb.XoffChar        = 0;
    dcb.XonLim          = 0;
    dcb.XoffLim         = 0;
    dcb.fParity = FALSE; //TRUE;

    if (!SetCommState(TTY.COMDEV, &dcb))     // set new state
	{ report_error("SetCommState failed"); goto failed;}
	
	// set comm buffer sizes
    if (!SetupComm(TTY.COMDEV, 1024, 1024))
	{  report_error("SetupComm failed");goto failed;}

    if (!EscapeCommFunction(TTY.COMDEV, SETDTR))        // raise DTR
	{  report_error("EscapeCommFunction failed");goto failed;}

	  SetCommMask (TTY.COMDEV, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);

      
    // start the reader and writer threads

	fThreadDone = FALSE;

    TTY.READERTHREAD =  
		CreateThread( NULL, 1000, (LPTHREAD_START_ROUTINE) ReaderProc, 0, 0, &dwReadStatId);
    if (TTY.READERTHREAD == NULL)
	{ report_error("CreateThread failed"); goto failed;}

	TTY.WRITERTHREAD =
		CreateThread( NULL, 1000, (LPTHREAD_START_ROUTINE) WriterProc, 0, 0, &dwWriteStatId);
    if (TTY.WRITERTHREAD == NULL)
	{ report_error("CreateWriterThread failed"); goto failed;}

	write_logfile("COMPORT opened: %s", PORTNAME);
	TTY.amount_to_write=0;	
	TTY.read_pause=sav_pause;

    return TRUE;

failed:
		{  
			char sztemp[100];
 	        write_logfile("COMPORT open failed");
		
			sprintf(sztemp, "The Port COM%d is not available. Please select another Com-Port.",TTY.PORT);
			report_error(sztemp);
		
			TTY.read_pause=sav_pause;
			TTY.PORT=sav_port;
			TTY.COMDEV=INVALID_HANDLE_VALUE;
			TTY.CONNECTED=FALSE;
			TTY.amount_to_write=0;
			return FALSE;
		}
}