コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: Ereaey/Linux_Projet
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    SerialWindow = new ConnexionSerie(this);
    ProtocoleBeagleBone = new Protocole;
    QObject::connect(SerialWindow, SIGNAL(InitSerialConnection(QString)), this, SLOT(SerialConnect(QString)));
    //connect(serial,SIGNAL(readyRead()),this,SLOT(donnee_recue()));
}
コード例 #2
0
ファイル: main.c プロジェクト: seishuku/gauges
void android_main(struct android_app *state)
{
	system("su -c \"chmod 0777 /dev/ttyUSB0\"");

	app_dummy();

	state->userData=NULL;
	state->onAppCmd=engine_handle_cmd;
	state->onInputEvent=engine_handle_input;

	app=state;

	assetManager=state->activity->assetManager;

	SerialConnect("/dev/ttyUSB0");

	while(1)
	{
		int ident, events;
		struct android_poll_source *source;

		while((ident=ALooper_pollAll(0, NULL, &events, (void**)&source))>=0)
		{
			if(source!=NULL)
				source->process(state, source);

			if(state->destroyRequested!=0)
			{
				engine_term_display();
				return;
			}
		}

		memcpy(&StartTime, &EndTime, sizeof(struct timespec));
		clock_gettime(CLOCK_MONOTONIC, &EndTime);

		engine_draw_frame();

		fTimeStep=(float)timespecDiff(&EndTime, &StartTime)/1000000000.0f;

		fTime+=fTimeStep;
		FPSTemp+=1.0f/fTimeStep;

		if(Frames++>15)
		{
			FPS=FPSTemp/Frames;
			FPSTemp=0.0f;
			Frames=0;
		}
	}

	close(tty_fd);
}
コード例 #3
0
void Xbox360Peripheral::ChatPadTimerAction(IOTimerEventSource *sender)
{
	int nextTime, serialGot;
	
	serialGot = 0;
	nextTime = 1000;
	switch (serialTimerState)
	{
		case tsToggle:
			SendToggle();
			if (serialActive)
			{
				if (!serialHeard)
				{
					serialActive = false;
					serialGot = 2;
				}
			}
			else
			{
				if (serialHeard)
				{
					serialTimerState = tsReset1;
					serialResetCount = 0;
					nextTime = 40;
				}
			}
			break;
			
		case tsMiniToggle:
			SendToggle();
			if (serialHeard)
			{
				serialTimerState = tsSet1;
				nextTime = 40;
			}
			else
			{
				serialResetCount++;
				if (serialResetCount > 3)
				{
					serialTimerState = tsToggle;
				}
				else
				{
					serialTimerState = tsReset1;
					nextTime = 40;
				}
			}
			break;
			
		case tsReset1:
			SendSpecial(0x1B);
			serialTimerState = tsReset2;
			nextTime = 35;
			break;
			
		case tsReset2:
			SendSpecial(0x1B);
			serialTimerState = tsMiniToggle;
			nextTime = 150;
			break;
			
		case tsSet1:
			SendSpecial(0x18);
			serialTimerState = tsSet2;
			nextTime = 10;
			break;
			
		case tsSet2:
			SendSpecial(0x10);
			serialTimerState = tsSet3;
			nextTime = 10;
			break;
			
		case tsSet3:
			SendSpecial(0x03);
			serialTimerState = tsToggle;
			nextTime = 940;
			serialActive = true;
			serialGot = 1;
			break;
	}
	sender->setTimeoutMS(nextTime);	// Todo: Make it take into account function execution time?
	serialHeard = false;
	// Make it happen after the timer's set, for minimum impact
	switch (serialGot)
	{
		case 1:
			SerialConnect();
			break;
			
		case 2:
			SerialDisconnect();
			break;
			
		default:
			break;
	}
}
int main( int argc, char **argv )
{
 APIRET      rc;
 COMMAND     cmd = {0,0};
 int         n;
 char       *cp;
 char        rc_string[12];
 CONNECTION  Connection;

 EXCEPTIONREGISTRATIONRECORD  reg_rec;

 ESP_QUE_ELEMENT Qelement;


 if( argc == 1 )
  SayMsg(HELP_INVOCATION_ESP);

 /****************************************************************************/
 /*                                                                          */
 /* Parse the invocation options.                                            */
 /*                                                                          */
 /* - If this is a child debugger, then these additional parameters will     */
 /*   precede the invocation parameters inherited from the parent.           */
 /*                                                                          */
 /*   - /child=xxxxx  where child  = child debugger and                      */
 /*                         xxxxx  = child pid (for serial connections only.)*/
 /*                                                                          */
 /*   - /handle=xxxxx where handle = switch for com handle( serial only )    */
 /*                         xxxxx  = parent's com handle - inherited by      */
 /*                                  the child.                              */
 /*                                                                          */
 /****************************************************************************/
 memset( &EspParms,   0, sizeof( ESP_PARMS ) );
 memset( &Connection, 0, sizeof(Connection) );
 if( strstr( argv[1], "/child" ) )
 {
  ParseEspChildOptions( argc, argv, &EspParms, &Connection );
 }
 else
 {
  ParseOptions( argc, argv, &EspParms, &Connection );
 }

 printf("\nESP Version 5.00 \n");fflush(0);

 /****************************************************************************/
 /* - Send connection info to the router.                                    */
 /****************************************************************************/
 SendConnectionToRouter( &Connection );

 /****************************************************************************/
 /* - Make the connection.                                                   */
 /****************************************************************************/
 {
  int RcMoreInfo = 0;

  rc = ConnectInit( &RcMoreInfo );

  if( rc != 0 )
  {
   char  BadConnectMsg[32] = "";
   int   MsgId;

   if( (Connection.ConnectType == _NETBIOS) && (RcMoreInfo != 0) )
   {
    /*************************************************************************/
    /* - handle netbios specific connect errors.                             */
    /*************************************************************************/
    n     = 1;
    MsgId = ERR_NB_INADEQUATE_RESOURCES;

    switch( RcMoreInfo )
    {
     case CANT_LOAD_NETB_DLL:
      n     = 0;
      MsgId = ERR_NB_CANT_LOAD_DLL;
      break;

     case INADEQUATE_SESSIONS:
      strcpy( BadConnectMsg,"sessions");
      break;

     case INADEQUATE_COMMANDS:
      strcpy( BadConnectMsg,"commands");
      break;

     case INADEQUATE_NAMES:
      strcpy( BadConnectMsg,"names");
      break;

     default:
      n = 1;
      MsgId = ERR_BAD_CONNECT;
      sprintf( BadConnectMsg, "NetBios error rc=%d", rc );
      break;
    }
   }
   else if( (Connection.ConnectType == SOCKET) && (RcMoreInfo != 0) )
   {
    /*************************************************************************/
    /* - handle tcpip specific connect errors.                               */
    /*************************************************************************/
    switch( RcMoreInfo )
    {
     case CANT_LOAD_TCPIP_DLL:
      n     = 1;
      MsgId = ERR_TCPIP_CANT_LOAD_DLL;

      sprintf( BadConnectMsg, "%d", rc );
      break;

     case TCPIP_NOT_RUNNING:
      n     = 0;
      MsgId = ERR_TCPIP_NOT_RUNNING;
      break;

     case TCPIP_ERROR:
      n     = 0;
      MsgId = ERR_TCPIP_ERROR;
      break;

     case TCPIP_NO_SERVICES_PORT:
      n     = 0;
      MsgId = ERR_TCPIP_NO_SERVICES_PORT;
      break;

     default:
      n = 1;
      MsgId = ERR_BAD_CONNECT;
      sprintf( BadConnectMsg, "tcpip error rc=%d", rc );
      break;
    }
   }
   else
   {
    /*************************************************************************/
    /* - handle generic connect errors.                                      */
    /*************************************************************************/
    n = 1;
    MsgId = ERR_BAD_CONNECT;
    sprintf( BadConnectMsg, "rc=%d", rc );
   }
   ErrorPrintf( MsgId, n, BadConnectMsg );
  }
 }

 /****************************************************************************/
 /* - register an exception handler for the probe.                           */
 /****************************************************************************/
 reg_rec.ExceptionHandler = Handler;
 DosSetExceptionHandler(&reg_rec);

 /****************************************************************************/
 /* - Add a connect sema4 for serial connections and wait to be posted.      */
 /****************************************************************************/
 if( (SerialParallel() == SERIAL) && ( IsParent() == FALSE ) )
 {
  USHORT   EspPid;
  TIB     *pTib;
  PIB     *pPib;
  ALLPIDS *p;

  SetComHandle( EspParms.handle );

  DosGetInfoBlocks(&pTib,&pPib);
  EspPid = (USHORT)pPib->pib_ulpid;
  CreateConnectSema4( EspPid, _ESP );
  SerialConnect( JUST_WAIT, 0, _ESP, SendMsgToEspQue );
  p = GetEspPid( EspPid );
  p->Connect = CONNECTED;
 }

 /****************************************************************************/
 /* - Each child debugger will have a termination que so we can kill the     */
 /*   child debuggers on quit/restart.                                       */
 /****************************************************************************/
 if( IsParent() == FALSE )
 {
  rc = StartEspTermQue( );
  if( rc != 0 )
  {
   sprintf(rc_string, "%d",rc);
   ErrorPrintf( ERR_CANT_START_QUE, TRUE, 1, rc_string );
  }
 }
 /****************************************************************************/
 /* - Now, start the command processing loop.                                */
 /****************************************************************************/
 for(;;)
 {
  memset(&cmd,0,sizeof(cmd) );
  RmtRecv(DEFAULT_HANDLE, (char*)&cmd, sizeof(cmd));
  if( IsVerbose() ) PrintCmdMessage( cmd.api ) ;
  switch( cmd.api )
  {
   case FINDEXE:
    RxFindExe(cmd);
    break;

   case STARTUSER:
    RxStartUser( cmd );
    break;

   case GOINIT:
    RxGoInit(cmd);
    break;

   case GOENTRY:
    RxGoEntry(cmd);
    break;

   case DEFBRK:
    RxDefBrk(cmd);
    break;

   case UNDBRK:
    RxUndBrk(cmd);
    break;

   case PUTINBRK:
    RxPutInBrk(cmd);
    break;

   case PULLOUTBRK:
    RxPullOutBrk(cmd);
    break;

   case INSERTALLBRK:
    RxInsertAllBrk();
    break;

   case REMOVEALLBRK:
    RxRemoveAllBrk();
    break;

   case SELECT_SESSION:
    /*************************************************************************/
    /* - Only the parent probe can select one of the debuggee sessions, so   */
    /*   we send a message and tell him to do it.                            */
    /*************************************************************************/
    Qelement.ChildPid = GetEspProcessID();
    SendMsgToEspQue( ESP_QMSG_SELECT_SESSION, &Qelement, sizeof(Qelement) );

    memset(&cmd,0,sizeof(cmd) );

    cmd.api = SELECT_SESSION;
    RmtSend( DEFAULT_HANDLE, &cmd, sizeof(cmd) );
    break;

   case GOSTEP:
    RxGoStep(cmd);
    break;

   case GOFAST:
    RxGoFast(cmd);
    break;

   case DOSDEBUG:
    RxDosDebug( cmd );
    break;

   case GETTHREADINFO:
    RxGetThreadInfo( cmd );
    break;

   case FREEZETHREAD:
    RxFreezeThread( cmd );
    break;

   case THAWTHREAD:
    RxThawThread( cmd );
    break;

   case GETCALLSTACK:
    RxGetCallStack(cmd);
    break;

   case GETEXEORDLLENTRY:
    RxGetExeOrDllEntryOrExitPt(cmd);
    break;

   case NORMALQUIT:
    RxNormalQuit(cmd);

    /*************************************************************************/
    /* - The que has to be up until after the normal quit because the        */
    /*   system will need to post an end session message to the queue.       */
    /*************************************************************************/
    if( IsParent() )
    {
     if( SingleMultiple() == MULTIPLE )
     {
      ALLPIDS *p;
      /***********************************************************************/
      /* - Send a message to all of the child probes telling them that       */
      /*   they are going to be killed.                                      */
      /***********************************************************************/
      for( p = GetAllpids(); p ; p = p->next )
      {
       if( (p->PidFlags.IsDebug) == TRUE && (p->pid != GetEspProcessID()) )
       {
        ESP_QUE_ELEMENT Qelement;

        Qelement.ChildPid = p->EspPid;

        SendMsgToEspTermQue(ESP_PROBE_TERM, &Qelement, sizeof(Qelement) );
       }
      }
      /***********************************************************************/
      /* - send a message to the que to kill all the child probes and        */
      /*   then wait until they are all dead.                                */
      /***********************************************************************/
      ResetAllProbesAreDeadFlag( );
      SendMsgToEspQue(ESP_QMSG_PARENT_TERM,NULL,0);
      while( AllProbesAreDead() == FALSE ){ DosSleep(100) ;}
     }
     SendMsgToEspQue(ESP_QMSG_QUE_TERM,NULL,0);
    }

    CloseConnectSema4();

    cmd.api  = NORMALQUIT;
    cmd.len  = sizeof(rc);

    /*************************************************************************/
    /* - Now, tell dbg that we're finished normal quitting.                  */
    /*************************************************************************/
    RmtSend(DEFAULT_HANDLE, &cmd , sizeof(cmd) );
    RmtSend(DEFAULT_HANDLE, &rc, cmd.len );
    break;

   case SETEXECADDR:
    RxSetExecAddr(cmd);
    break;

   case DEFWPS:
    RxDefWps(cmd);
    break;

   case PUTINWPS:
    RxPutInWps(cmd);
    break;

   case PULLOUTWPS:
    RxPullOutWps(cmd);
    break;

   case GETDATABYTES:
    RxGetDataBytes(cmd);
    break;

   case GETMEMBLKS:
    RxGetMemBlocks(cmd);
    break;

   case SETXCPTNOTIFY:
    RxSetExceptions(cmd);
    break;

   case SETEXECTHREAD:
    RxSetExecThread(cmd);
    break;

   case WRITEREGS:
    RxWriteRegs(cmd);
    break;

   case GETCOREGS:
    RxGetCoRegs(cmd);
    break;

   case SETESPRUNOPTS:
    RxSetEspRunOpts(cmd);
    break;

   case TERMINATEESP:
    if( IsParent() == FALSE )
    {
     memset( &Qelement, 0, sizeof(Qelement) );
     Qelement.ChildPid = GetEspProcessID();

     SendMsgToEspQue( ESP_QMSG_CHILD_TERM, &Qelement, sizeof(Qelement) );
    }
    DosUnsetExceptionHandler(&reg_rec);
    RmtSend(DEFAULT_HANDLE, &cmd , sizeof(cmd) );
    ConnectClose( DEFAULT_HANDLE );
    exit(0);
    break;

   case START_QUE_LISTEN:
    SendMsgToEspQue(ESP_QMSG_OPEN_CONNECT,NULL,0);
    break;

   case START_ESP_QUE:
    RxStartEspQue(cmd);
    break;

   case CONNECT_ESP:
    /*************************************************************************/
    /* - Serial connection only.                                             */
    /*************************************************************************/
    {
     USHORT   GoToPid;
     USHORT   YieldPid;
     ALLPIDS *pYield;
     ALLPIDS *pGoTo;
     BOOL     TorF;

     /************************************************************************/
     /* - Receive the pid to be connected and mark it connected.             */
     /* - If this pid has not yet been assigned to a probe, then pGoTo       */
     /*   will be NULL.                                                      */
     /* - There MUST be a probe with a pid==0, so we release that probe.     */
     /*   ( The pid will be stuffed into the structure at goinit() time.)    */
     /* - Post the connect sema4 for the goto pid.                           */
     /************************************************************************/
     RmtRecv( DEFAULT_HANDLE, &GoToPid, cmd.len );
     pGoTo          = GetPid( GoToPid );

     if( pGoTo == NULL )
      pGoTo = GetPid(0);

     pGoTo->Connect = CONNECTED;


     TorF = TRUE;
     if( GoToPid == GetEspProcessID() )
      TorF = FALSE;

     /************************************************************************/
     /* - Send back verification that the connection has been made.          */
     /************************************************************************/
     memset(&cmd,0,sizeof(cmd) );

     cmd.api = SERIAL_POLL;
     RmtSend( DEFAULT_HANDLE, &cmd, sizeof(cmd) );

     PostConnectSema4( &pGoTo->ConnectSema4, TorF );

     /************************************************************************/
     /* - Disconnect/block this probe.                                       */
     /************************************************************************/
     YieldPid        = (USHORT)GetEspProcessID();
     pYield          = GetPid( YieldPid );
     pYield->Connect = DISCONNECTED;

     SerialConnect( SET_WAIT, YieldPid, _ESP, SendMsgToEspQue );
    }
    break;

   case CTRL_BREAK:
    {
     USHORT          ThisPid;
     USHORT          CtrlBreakPid;

     RmtRecv( DEFAULT_HANDLE, &CtrlBreakPid, cmd.len );

     ThisPid = (USHORT)GetEspProcessID();

     Qelement.ChildPid = CtrlBreakPid;
     Qelement.ChildSid = ThisPid;

     SendMsgToEspQue(ESP_QMSG_CTRL_BREAK, &Qelement, sizeof(Qelement));

     SerialConnect( SET_WAIT, ThisPid,  _ESP, SendMsgToEspQue );
    }
    break;

   case SERIAL_POLL:
    ReportMessage();
    break;

   default:
    cp = (char*)&cmd;
    for( n=1; n<=sizeof(cmd); n++,cp++)
     printf("%c",*cp);
    AsyncFlushModem();
    break;
  }
 }
}