コード例 #1
0
ファイル: cxAndroid.cpp プロジェクト: cxuhua/cxengine
void cxAndroid::SetWindow(ANativeWindow* window)
{
    pthread_mutex_lock(&mutex);
    if (pendingWindow != NULL) {
        writecmd(APP_CMD_TERM_WINDOW);
    }
    pendingWindow = window;
    if (window != NULL) {
        writecmd(APP_CMD_INIT_WINDOW);
    }
    while (window != pendingWindow) {
        pthread_cond_wait(&cond, &mutex);
    }
    pthread_mutex_unlock(&mutex);
}
コード例 #2
0
ファイル: monitoritem.cpp プロジェクト: NilByMouth/bareos
bool MonitorItem::docmd(const char* command)
{
   if (!doconnect()) {
      return false;
   }

   if (command[0] != 0) {
      writecmd(command);
   }

   emit clearText(get_name());
   bool jobRunning = false;

   while (1) {
      int stat;
      if ((stat = bnet_recv(d->DSock)) >= 0) {
         strip_trailing_newline(d->DSock->msg);
         QString msg = QString::fromUtf8(d->DSock->msg);
         emit appendText(QString::fromUtf8(get_name()), msg);
         if (d->type == R_CLIENT) {
             if (msg.contains("Job started:"))
                jobRunning = true;
         }
      } else if (stat == BNET_SIGNAL) {
         if (d->DSock->msglen == BNET_EOD) {
            // qDebug() << "<< EOD >>";
             if (d->type == R_CLIENT)
                emit jobIsRunning (jobRunning);
            return true;
         }
         else if (d->DSock->msglen == BNET_SUB_PROMPT) {
            // qDebug() << "<< PROMPT >>";
            return false;
         }
         else if (d->DSock->msglen == BNET_HEARTBEAT) {
            bnet_sig(d->DSock, BNET_HB_RESPONSE);
         }
         else {
            qDebug() << bnet_sig_to_ascii(d->DSock);
         }
      } else { /* BNET_HARDEOF || BNET_ERROR */
         d->DSock = NULL;
         d->state = MonitorItem::Error;
         emit statusChanged(get_name(), d->state);
         emit showStatusbarMessage("Error : BNET_HARDEOF or BNET_ERROR");
         //fprintf(stderr, "<< ERROR >>\n"));
         return false;
      } /* if ((stat = bnet_recv(d->DSock)) >= 0) */

      if (is_bnet_stop(d->DSock)) {
         d->DSock = NULL;
         d->state = MonitorItem::Error;
         emit statusChanged(get_name(), d->state);
         emit showStatusbarMessage("Error : Connection closed.");
         //fprintf(stderr, "<< STOP >>\n");
         return false;            /* error or term */
      } /* if (is_bnet_stop(d->DSock) */

   } /* while (1) */
}
コード例 #3
0
ファイル: cxAndroid.cpp プロジェクト: cxuhua/cxengine
void cxAndroid::SetActivityState(int8_t cmd)
{
    pthread_mutex_lock(&mutex);
    writecmd(cmd);
    while (activityState != cmd) {
        pthread_cond_wait(&cond, &mutex);
    }
    pthread_mutex_unlock(&mutex);
}
コード例 #4
0
ファイル: monitoritem.cpp プロジェクト: NilByMouth/bareos
void MonitorItem::disconnect()
{
   if (d->DSock) {
      writecmd("quit");
      d->DSock->signal(BNET_TERMINATE); /* send EOF */
      d->DSock->close();
      delete d->DSock;
      d->DSock = NULL;
   }
}
コード例 #5
0
ファイル: cxAndroid.cpp プロジェクト: cxuhua/cxengine
void cxAndroid::SetInput(AInputQueue* inputQueue)
{
    pthread_mutex_lock(&mutex);
    pendingInputQueue = inputQueue;
    writecmd(APP_CMD_INPUT_CHANGED);
    while (inputQueue != pendingInputQueue) {
        pthread_cond_wait(&cond, &mutex);
    }
    pthread_mutex_unlock(&mutex);
}
コード例 #6
0
ファイル: monitoritem.cpp プロジェクト: NilByMouth/bareos
void MonitorItem::get_list(const char *cmd, QStringList &lst)
{
   doconnect();
   writecmd(cmd);
   while (bnet_recv(d->DSock) >= 0) {
      strip_trailing_newline(d->DSock->msg);
      if (*(d->DSock->msg)) {
         lst << QString(d->DSock->msg);
      }
   }
}
コード例 #7
0
ファイル: cobra.c プロジェクト: rene-dev/Cobra
int handle_client(const int sock,int tty_fd){
   char line[BUF_SIZE];
   int pos1,pos2,pos3,pos4,pos5,pos6;
   while(receiveLine(sock,line,BUF_SIZE)){
      if(!strcmp(line,"q")){
         return 0;
      }
      if(sscanf(line,"D %i %i %i %i %i %i",&pos1,&pos2,&pos3,&pos4,&pos5,&pos6) == 6){
         printf("received D %i %i %i %i %i %i, sending...\n",pos1,pos2,pos3,pos4,pos5,pos6);
         writecmd(line,tty_fd);
         printf("done!\n");
      }
   }

   return 0;
}
コード例 #8
0
ファイル: dcmc.c プロジェクト: infocelab/embedded-projects
void dectime()											// decrease time
  {
  	int q;  				
	keydly();											// key debounce delay
	writecmd(0xC0);
	if(t>20) 											// if not min time 
	  {
		t-=20;											// decrease it		  
	 	q=t/20;
	 	q=q+0x30;										// do same as above 	
	 	writestr("time:");
	 	writedata(q);
	 	writestr("sec");
	  }
	else if(t==20) writestr("min time: 1 sec");			// if min time display message	 
  }
コード例 #9
0
ファイル: dcmc.c プロジェクト: infocelab/embedded-projects
void inctime()											// increase time 
  {
  	int p;  	
	keydly();											// key debounce delay
	writecmd(0xC0);										
	if(t<180)											// if not max time 
	  {
		t+=20;											// increase it by 1 sec		
		p=t/20;
		p=p+0x30;										// convert it in to ASCII		
		writestr("time: ");								// display it
		writedata(p);
		writestr(" sec    ");
	  }
	else if(t==180) writestr("max time: 9 sec");		// if max time display message	 
  }
コード例 #10
0
ファイル: dcmc.c プロジェクト: infocelab/embedded-projects
void incspeed()											// increase speed 
   {
   		int w; 
		keydly();  	
		writecmd(0xC0);									// key debounce								
		if(y>6) 										// if not minimum width
	  	  {
		  	x++;
	  		y-- ;										// decrease it				  
			w=y-5+0x30;									// do same as above		
			writestr("speed: ");
			writedata(w);
			writestr("       ");
		  }
		 else if(y==6) writestr("max speed: 1  ");		// if min width display message	  	  
	}
コード例 #11
0
ファイル: dcmc.c プロジェクト: infocelab/embedded-projects
 void decspeed()									// increase speed 
   {
   		int z;   		
		keydly();									// key debounce
		writecmd(0xC0);								// select second line on LCD
		if(y<14) 									// if not max pulse width
	  	  {
		  	x--;
	  		y++;									// increase it convert it in to			  	  	
			z=y-5+0x30;								// 1 to 10 scale and ASCII
			writestr("speed: ");					// diaplay speed on LCD
			writedata(z);
			writestr("       ");
		  }
		  else if(y==14) writestr("min speed: 9  ");	// if max width display message	
	}
コード例 #12
0
ファイル: dcmc.c プロジェクト: infocelab/embedded-projects
 void mode()								// change mode of rotation
   {
   	keydly();								// key debounce delay
	writecmd(0x80);							// display message on first line first column
	m++;									// increment count	
	if(m==3) m=0;							// if it is 3 reset it
	if(m==0)
	  { writestr("mode:continuous ");	// otherwise display mode
	  time(15);
	  }
	else if(m==1) 
    {writestr("mode:reversible ");
	   time(15);
	}
	else if(m==2) 
	{writestr("mode:jogging    "); 
	time(15); 	
   }
   }
コード例 #13
0
ファイル: cobra.c プロジェクト: rene-dev/Cobra
int main(int argc,char** argv)
{
   struct termios tio;
   struct termios stdio;
   int tty_fd;
   FILE *file;
   fd_set rdset;
   
   char cmd[100];
   char buf[100];

   int s, c;
   socklen_t addr_len;
   struct sockaddr_in addr;
   
   if(argc < 3){
      printf("usage: %s device [read|write file|cal|home|clear|start|lbl num|D mot1 mot2 mot3 mot4 mot5 mot6]\r\n",argv[0]);
      exit(EXIT_FAILURE);
   }
   
   memset(&tio,0,sizeof(tio));
   tio.c_iflag=0;
   tio.c_oflag=0;
   tio.c_cflag=CS8|CREAD|CLOCAL|CSTOPB;//8n2
   tio.c_lflag=0;
   tio.c_cc[VMIN]=1;
   tio.c_cc[VTIME]=5;
   
   tty_fd=open(argv[1], O_RDWR | O_NONBLOCK);   
   if(tty_fd == -1){
      printf("cannot open device\r\n");
      exit(EXIT_FAILURE);
   }  
    
   cfsetospeed(&tio,B4800);
   cfsetispeed(&tio,B4800);
   tcsetattr(tty_fd,TCSANOW,&tio);
   
   if(strcmp(argv[2],"read") == 0){
      writecmd("C",tty_fd);//set program counter to 0
      while(cmd[0] != '*'){
         readcmd(cmd,tty_fd);
         if(cmd[0] != '*'){
            printf("%s",cmd);
         }
      }
   }
   else if(strcmp(argv[2],"cal") == 0){
      writecmd("N",tty_fd);
   }
   else if(strcmp(argv[2],"home") == 0){
      writecmd("H",tty_fd);
   }
   else if(strcmp(argv[2],"clear") == 0){
      writecmd("R",tty_fd);
   }
   else if(strcmp(argv[2],"start") == 0){
      writecmd("C",tty_fd);//set program counter to 0
      writecmd("E",tty_fd);//start
   }
   else if(argv[2][0] == 'D' && argc == 9){
      strcpy(cmd,"D ");
      strcat(cmd,argv[3]);
      strcat(cmd," ");
      strcat(cmd,argv[4]);
      strcat(cmd," ");
      strcat(cmd,argv[5]);
      strcat(cmd," ");
      strcat(cmd,argv[6]);
      strcat(cmd," ");
      strcat(cmd,argv[7]);
      strcat(cmd," ");
      strcat(cmd,argv[8]);
      writecmd(cmd,tty_fd);//send command
   }
   else if(strcmp(argv[2],"write") == 0 && argc == 4){
      file = fopen(argv[3],"r");
      if(!file){
         printf("cannot open file\r\n");
         exit(EXIT_FAILURE);
      }
      writecmd("R",tty_fd);//clear
      writecmd("C",tty_fd);//set program counter to 0
      while (fgets(buf, 50, file)){
         strcpy(cmd,"S");
         strcat(cmd,buf);
         writecmd(cmd,tty_fd);
      }
      fclose(file);
   }
   else if(strcmp(argv[2],"lbl") == 0 && argc == 4){
      strcpy(cmd,"E ");
      strcat(cmd,argv[3]);
      writecmd(cmd,tty_fd);//start
   
   }
   else if(strcmp(argv[2],"-d") == 0){
      printf("Starting Server...\n");
      
      s = socket(PF_INET, SOCK_STREAM, 0);
      if (s == -1){
         perror("socket() failed");
         return 1;
      }

      addr.sin_addr.s_addr = INADDR_ANY;
      addr.sin_port = htons(PORT);
      addr.sin_family = AF_INET;

      if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) == -1){
         perror("bind() failed");
         return 2;
      }

      if (listen(s, 3) == -1){
         perror("listen() failed");
         return 3;
      }
      printf("Listening...\n");

      for(;;){
         addr_len = sizeof(addr);
         c = accept(s, (struct sockaddr*)&addr, &addr_len);
         if (c == -1){
            perror("accept() failed");
            continue;
         }

         printf("Client %s connected\n", inet_ntoa(addr.sin_addr));
         handle_client(c,tty_fd);
         printf("Client %s quit\n", inet_ntoa(addr.sin_addr));
         close(c);
      }
   }
   
   close(tty_fd);
   exit(EXIT_SUCCESS);
}
コード例 #14
0
ファイル: cobra.c プロジェクト: rene-dev/Cobra
void readcmd(char* cmd,int tty_fd){
   writecmd("G",tty_fd);//request command
   usleep(200000);//wait for cobra to write data
   fgets(cmd,50,fdopen(tty_fd,"r"));
}
コード例 #15
0
ファイル: check_bacula.c プロジェクト: rkorzeniewski/bacula
int docmd(monitoritem* item, const char* command, char *answer) {

   int stat;
   char num;
   const char *dname;

   dname = "";

   if (!item->D_sock) {

      DIRRES* dird;
      CLIENT* filed;
      STORE* stored;

      switch (item->type) {
      case R_DIRECTOR:
                 dird = (DIRRES*)item->resource;
                 item->D_sock = new_bsock();
                 item->D_sock->connect(NULL, 0, 0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0);
                 dname = "Director";
                 break;
      case R_CLIENT:
                 filed = (CLIENT*)item->resource;
                 item->D_sock = new_bsock();
                 item->D_sock->connect(NULL, 0, 0, 0, "File daemon", filed->address, NULL, filed->FDport, 0);
                 dname = "FileDaemon";
                 break;
      case R_STORAGE:
                 stored = (STORE*)item->resource;
                 item->D_sock = new_bsock();
                 item->D_sock->connect(NULL, 0, 0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0);
                 dname = "StorageDaemon";
                 break;
      default:
                 printf("Error, currentitem is not a Client, a Storage or a Director..\n");
                 return STATE_UNKNOWN;
      }

      if (item->D_sock == NULL) {
                 sprintf (answer, "BACULA CRITICAL - Cannot connect to %s!", dname);
                 return STATE_CRITICAL;
      }

      if (!authenticate_daemon(item)) {
                sprintf (answer, "BACULA CRITICAL - Cannot authenticate to %s: %s", dname, item->D_sock->msg);
                item->D_sock = NULL;
                return STATE_CRITICAL;
      }

   }

   if (command[0] != 0)
      writecmd(item, command);

   while(1) {
      if ((stat = item->D_sock->recv()) >= 0) {

        /* welcome message of director */
        if ((item->type == R_DIRECTOR) && (strncmp(item->D_sock->msg, "Using ", 6) == 0))
                continue;

        if (sscanf(item->D_sock->msg, OKqstatus, &num) != 1) {
                /* Error, couldn't find OK */
                sprintf (answer, "BACULA CRITICAL - %s Status: %s", dname, item->D_sock->msg);
                return STATE_CRITICAL;
        } else {
                sprintf (answer, "BACULA OK - %s Status OK", dname);
                return STATE_OK;
        }
      }
      else if (stat == BNET_SIGNAL) {
                if (item->D_sock->msglen == BNET_EOD) {
                strcpy(answer, "BACULA WARNING - << EOD >>");
                return STATE_WARNING;
         }
         else if (item->D_sock->msglen == BNET_SUB_PROMPT) {
            strcpy(answer, "BACULA WARNING - BNET_SUB_PROMPT signal received.");
            return STATE_WARNING;
         }
         else if (item->D_sock->msglen == BNET_HEARTBEAT) {
            item->D_sock->signal(BNET_HB_RESPONSE);
         }
         else {
                sprintf(answer, "BACULA WARNING - Unexpected signal received : %s ", bnet_sig_to_ascii(item->D_sock));
         }
      }
      else { /* BNET_HARDEOF || BNET_ERROR */
                 strcpy(answer, "BACULA CRITICAL - ERROR: BNET_HARDEOF or BNET_ERROR");
                 item->D_sock = NULL;
                 return STATE_CRITICAL;
      }

      if (item->D_sock->is_stop()) {
                 item->D_sock = NULL;
                 return STATE_WARNING;
      }
   }
}
コード例 #16
0
ファイル: dcmc.c プロジェクト: infocelab/embedded-projects
void main()
  {
	TMOD=0x12;						// timer1 in 16 bit timer, timer 0 in 8 bit auto reload mode 
	P2=0xC0;						 // LEDs off, relays OFF
	P0=0x00;						 // P0, P3 output ports
	P3=0x00;
	writecmd(0x3C);					// initilize LCD
	writecmd(0x0E); 
	writecmd(0x01); 
	writecmd(0x84);					// display message
    writestr("DC Motor");			// DC motor controller in
	writecmd(0xC3);					// center of LCD
	writestr("Controller");	
agin:P1=0xFF;						  // P1 as input port
	while(P1==0xFF);				// wait until any key press
loop:switch(P1)
	  {
		case 0xFE:					 // for first key 
			keydly();				   // key debounce
			writecmd(0x01); 
			writestr("motor start");
			time(50);						// wait for 2.5 sec
			writecmd(0x80);	
    	writestr("mode:continuous ");	// display current mode and speed
			writecmd(0xC0);
			writestr("speed: 5       ");	
			led1=1;					// Run LED ON
			led2=0;					// stop LED OFF
			led3=1;					// clockwise direction ON
			led4=0;					// anticlockwise direction OFF
			start();				// sart rotating motor
			break;
		case 0xFD:					 // for second key
			keydly();				  // key debounce
			r=0;					   // run flag reset
			writecmd(0x01);			
			writestr("motor stoped");	// display message
			led1=0;					// Run OFF
			led2=1;					// stop LED ON
			led3=0;					// clockwise direction OFF
			led4=0;					// anticlockwise direction OFF
			RL1=0;				  // switch off RL1
			PWM=0;				  // send low on PWM pin 
			time(2);
			break;
		case 0xFB:					// for third key
      keydly();			  // key debounce
			writecmd(0x01);			
			writestr("key 3");	// display message
			time(1);
			mode();					// select mode					
			if(r==1) start();		// jump to start if run flag is set
			break;
		case 0xF7:					// for fourth key		
			direction();			// change direction			
			if(r==1) start();		// jump to start if run flag is set
			break;
		case 0xEF:					// for fifth key			
			incspeed();				// increase speed
			if(r==1) start();		// jump to start if run flag is set
			break;
		case 0xDF:					// for sixth key			
			decspeed();				// decrease speed		
			if(r==1) start();		// jump to start if run flag is set
			break;
		case 0xBF:					// for seventh key		
			inctime();				// increase time
			if(r==1) start();		// jump to start if run flag is set
			break;
		case 0x7F:					// for eigth key		
			dectime();				// decrease time			
			if(r==1) start();		// jump to start if run flag is set
			break;
	   }
	if(r==1) goto loop;				// if run flag is set jump of key detect
	else goto agin;					// if not jump to again
  }