コード例 #1
0
ファイル: bluemote.c プロジェクト: NovaCygni/aur-mirror
int quit()
{
 printf("Quit request from user.\nResetting serial port... ");
 logger("INFO", "Quit request from user. Quitting.\n");
 close_consumer();
 closeport();
 printf("Done\n");
 exit(0);
}
コード例 #2
0
ファイル: bluemote.c プロジェクト: NovaCygni/aur-mirror
int tempdisconn()
{
 manual = TRUE;
 printf("Disconnecting for a minute...\n");
 logger("INFO","Disconnecting for a minute...");
 closeport();
 sleep(60);
 return 1;
}
コード例 #3
0
ファイル: bluemote.c プロジェクト: NovaCygni/aur-mirror
void signal_handler(int signal)
{
 switch(signal)
 {
  case SIGINT:
  case SIGTERM:
	printf("Interrupted by user.\nResetting serial port... ");
	logger("INFO", "Interrupted by user. Exiting.\n");
	close_consumer();
	closeport();
	printf("Done\n");
 	exit(0);
	break;
  case SIGALRM:
	break;
  default:
	close_consumer();
	closeport();
	exit(1);
 }
}
コード例 #4
0
ファイル: rterm.c プロジェクト: jwise/ipaq-debrick
int main(int argc, char** argv)
{
	unsigned long data;
	struct termios term;
	char data2;
	int hasdat;
	int fd;
	
	if (argc != 1)
	{
usage:
		fprintf(stderr,
			"%s: a program to watch for stuff coming out over the console over jtag.\n", argv[0]);
		exit(1);
	}
	
	openport();
	
	test_reset();		// returns us in reset state
	clockin(0, 0);		// this leaves us in run-test/idle
	look_for_pxa();		// returns us in run-test/idle state
	
	set_instr(DBGTX);	
	/* We do not do any of the high-level stuff here. Just wait for RR and read. */
	while(1)
	{
		int lcount = 0;
		hasdat = 0;
		while (!hasdat)
		{
			hasdat = gettxword(&data);
			if (!hasdat)
				lcount++;
			if (lcount > 10)
				set_instr(DBGTX);
		}
 		data2 = data & 0xFF;
 		write(1, &data2, 1);
	}
	
	closeport();
	return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: huntu2/apcombo
//===========================================
int main (int argc, char * argv[])
{
    //------------------
    //debugging option
    char dump,showlastonly;

    //-------------------
    int i,j,k,len,cl;
    unsigned int c;
    unsigned char data[1024];
    char buffer[1024];
    char * pb;

	//evaluate cmdline line argument
	if(argc < 4 ){
        printf("usage %s <device> <baudrate> <ussdcommand>\n",argv[0]);
	    return 1;
	}

	//dump verbose option
	if     (!memcmp("-vvv",argv[1],4)){cl=1;showlastonly=1;dump=1;verbose=1;}
	else if(!memcmp("-vv" ,argv[1],3)){cl=1;showlastonly=1;dump=1;verbose=0;}
	else if(!memcmp("-v"  ,argv[1],2)){cl=1;showlastonly=1;dump=0;verbose=0;}
    else {cl=0;showlastonly=0,dump=0,verbose=0;}

    //setting up baudrate
    serial.baudrate=atoi(argv[cl+2]);
    if(getbaudrate(serial.baudrate)==1){
        fprintf(stderr,"Fatal Error, cannot set baudrate: %d\n",serial.baudrate);
        return 1;
    }

	serial.port=strdup(argv[cl+1]);
    //opening the port
    if (openport()){
        fprintf(stderr,"Fatal Error, cannot open device: %s\n",serial.port);
        return 1;
    }

    ///*
    if(dump)printf("AT\n");
    serial_port_write("AT\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    if(dump)printf("ATE0\n");
    serial_port_write("ATE0\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }   
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    if(dump)printf("AT^CURC=0\n");
    serial_port_write("AT^CURC=0\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    if(dump)printf("AT^USSDMODE=0\n");
    serial_port_write("AT^USSDMODE=0\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    //sending the ussd sequence start at argv[3];
    for (i=cl+3;i<argc;i++){
        memset(buffer,0,sizeof(buffer));
        strcpy(buffer,"AT+CUSD=1,\"");
        strcat(buffer,argv[i]);
        strcat(buffer,"\",15\r\n");
        //strcat(buffer,"\"\r\n");

        if(dump){printf(buffer);}
        serial_port_write(buffer);
        len=getser(data,timeoutussd);

        //see if this is not ascii
        //skip respon daOKda+CUSSD: 1,", start at 18
        //end ,68"da at len-6

        if(len>22){
            //data received nicely, dump to stdout if only last ussd sequence
            if( showlastonly || i == (argc-1)) {
                //check wheter ascii transparent or encoded 7bit ascii
                //if(dump)fwrite(&data[18],1,len-18-6,stdout);
                k=0;
                for (j=18;j<22;j++){
                    if (((data[j] >= '0') && (data[j] <='9')) ||
                        ((data[j] >= 'A') && (data[j] <='F')) ||
                        ((data[j] >= 'a') && (data[j] <='f'))
                        ) {k++;}
                    else {k=0;break;}
                }
                if(k){
                    //data not ascii encoded 7bit ascii integer (2byte char)
                    //printf("not ascii\n");
                    //printf("length  %d bagi 4 %d sisa %d\n",(len-18-6),((len-18-6)/4),(len-18-6) % 4 );
                    //printf("\n");
                    for(k=18;k<(len-6);k+=4){
                        c=0;
                        for(j=0;j<4;j++){
                            c=c<<4;
                            if      ((data[k+j] >= '0') && (data[k+j] <='9'))c+=data[k+j]-'0';
                            else if ((data[k+j] >= 'A') && (data[k+j] <='F'))c+=data[k+j]-'A'+0x0a;
                            else if ((data[k+j] >= 'a') && (data[k+j] <='f'))c+=data[k+j]-'a'+0x0a;
                            else {perror ("failed 7bit decode\n");return 1;}
                        }
                        putchar(c);//putchar(0x20);
                    }
                    printf("\n");
                }
                //data is ascii transparent, continue
                else {fwrite(&data[18],1,len-18-6,stdout);printf("\n");}
            }//if(i==argc-1)
        }//if(len>22)
        else{
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            break;
            //goto endsession;
            //return 1;
        }
    }//for (i=3;i<argc;i++)
    
    endsession:
    //end ussd session
    if(dump)printf("AT+CUSD=2\r\n");
    serial_port_write("AT+CUSD=2\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }

    closeport();
    return 0;
}
コード例 #6
0
ファイル: writethread.cpp プロジェクト: lctagnes/gitpro
WriteThread::~WriteThread()
{
    closeport(wFD);
}
コード例 #7
0
ファイル: writethread.cpp プロジェクト: lctagnes/gitpro
void WriteThread::Stop()
{
    stopped = false;
    closeport(wFD);
}
コード例 #8
0
ファイル: uartthread.cpp プロジェクト: lctagnes/gitpro
void CUartThread::Stop()
{
    m_bRun = false;     //停止
    closeport(m_nFD);
}
コード例 #9
0
ファイル: uartthread.cpp プロジェクト: lctagnes/gitpro
CUartThread::~CUartThread()
{
    closeport(m_nFD);
}
コード例 #10
0
int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		"B:c:D:F:m:p:P:q:S:uvw",
		"",
		"Atheros Serial Line Device Settings",
		"B n\tbaud rate is (n) [" LITERAL (UART_BAUDRATE) "]",
		"c s\tsend custom serial line command (s)",
		"D n\tuse (n) data bits [" LITERAL (UART_DATABITS) "]",
		"F n\tflow control is (n) ["LITERAL (UART_FLOWCTRL) "]",
		"m n\tcommand mode is (n)",
		"p f\tserial port is (f) [" DEVICE "]",
		"P n\tuse (n) parity bits [" LITERAL (UART_PARITY) "]",
		"q\tquiet mode",
		"S n\tuse (n) stop bits [" LITERAL (UART_STOPBITS) "]",
		"u\tforce default host port settings [115200 8N1]",
		"v\tverbose mode",
		"w\twake device [+++]",
		(char const *) (0)
	};
	struct uart uart =
	{
		{
			0,
			DEVICE
		},
		(char *)(0),
		UART_MODE,
		UART_BAUDRATE,
		UART_DATABITS,
		UART_PARITY,
		UART_STOPBITS,
		UART_FLOWCTRL,
		0
	};
	signed c;
	if (getenv (UART_PORT))
	{
		uart.port.name = strdup (getenv (UART_PORT));
	}
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'B':
			_setbits (uart.flags, UART_ATBR);
			uart.baudrate = (uint64_t)(uintspec (optarg, 1, ULONG_MAX));
			break;
		case 'c':
			_setbits (uart.flags, UART_COMMAND);
			uart.string = optarg;
			break;
		case 'D':
			_setbits (uart.flags, UART_ATBR);
			uart.databits = (byte)(uintspec (optarg, 7, 8));
			break;
		case 'F':
			_setbits (uart.flags, UART_ATBR);
			uart.flowctrl = (byte)(uintspec (synonym (optarg, flowctrls, FLOWCTRLS), 0, UCHAR_MAX));
			break;
		case 'm':
			_setbits (uart.flags, UART_ATBR);
			uart.mode = (byte)(uintspec (synonym (optarg, modes, MODES), 0, UCHAR_MAX));
		case 'P':
			_setbits (uart.flags, UART_ATBR);
			uart.parity = (byte)(uintspec (synonym (optarg, paritybits, PARITYBITS), 0, UCHAR_MAX));
			break;
		case 'q':
			_setbits (uart.flags, UART_SILENCE);
			break;
		case 'p':
			uart.port.name = optarg;
			break;
		case 'S':
			_setbits (uart.flags, UART_ATBR);
			uart.stopbits = (unsigned)(uintspec (optarg, 1, 2));
			break;
		case 'u':
			_setbits (uart.flags, UART_DEFAULT);
			break;
		case 'v':
			_setbits (uart.flags, UART_VERBOSE);
			break;
		case 'w':
			_setbits (uart.flags, UART_WAKE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc)
	{
		error (1, ENOTSUP, ERROR_TOOMANY);
	}
	openport (&uart.port, uart.flags);
	manager (&uart);
	closeport (&uart.port);
	return (0);
}
コード例 #11
0
ファイル: bluemote.c プロジェクト: NovaCygni/aur-mirror
int main(int argc, char *argv[])
{
 if(!init_cfg())
 {
  fprintf(stderr, "Unable to open config file or invalid content in config file.\n");
  exit(1);
 }
 
 parseopts(argc, argv, conf);

 if(conf->msg)
 {
  if(!open_producer())
  {
   printf("Unable to contact Bluemote server!\n");
   exit(1);
  }
  if(ipc_write(conf->device, strlen(conf->device))<=0)
  {
   printf("Unable to send message to Bluemote server!\n");
   close_producer();
   exit(1);
  }
  close_producer();
  exit(0);
 }
 else
 {
  if(!get_lock())
  {
   printf("Another instance of Bluemote already running!\n");
   exit(1);
  }

  if(!open_consumer())
  {
   printf("Unable to listen for messages!\n");
   exit(1);
  }
 }

 strcpy(logfile, getenv("HOME"));
 strcat(logfile, BLUEMOTEDIR);
 strcat(logfile, LOGFILE);

 printf("Setting up signal handlers.\n");
 logger("INIT", "Setting up signal handlers");
 if(!init_signals())
 {
  perror("init_signals()");
  exit(1);
 }

 if(conf->daemon)
 {
  printf("Entering daemon mode.\n");
  logger("INIT", "Entering daemon mode.\n");
  if(daemon(TRUE, FALSE)==-1)
  {
   printf("Unable to enter daemon mode. Exiting.\n");
   logger("ERROR", "Unable to enter daemon mode. Exiting.\n");
   exit(1);
  }
 }

 while(TRUE)
 {
  closeport();

  printf("Connecting to phone...\n");
  logger("INIT", "Connecting to phone...");
  while(openport(conf->device) == -1)
  {
   sprintf(buf,"Unable to connect to phone. Will retry after %d secs.",conf->retrysecs);
   logger("INIT", buf);
   sleep(conf->retrysecs);
   logger("INIT", "Retrying...");
  }
  printf("Connected to phone.\n");
  logger("INIT", "Connected to phone.");
  
  printf("Initialising the connection.\n");
  logger("INIT", "Initialising the connection.\n");
  if(!initport()) exit(1);

  printf("Waiting for commands from phone\n");
  logger("INIT", "Waiting for commands from phone\n");

  /* Not looping to take care of timeout because timeout is very unlikely and
   * this function is called again inside remote(). In the worst case, the I/O
   * commands for Connect event won't have any effect. */
  if(init_mainmenu()==-1) continue;

  exec_event("Connect");
  if(!manual)
  {
   exec_event("MoveIn");
  }
  manual = FALSE;
  remote();
  if(!manual)
  {
   exec_event("MoveOut");
  }
  exec_event("Disconnect");
 }
 return(0);
}
コード例 #12
0
ファイル: cominit.c プロジェクト: huntu2/apcombo
//===========================================
int main (int argc, char * argv[])
{
    //------------------
    //debugging option
    char dump,showlastonly;

    //-------------------
    int i,j,k,len,cl;
    unsigned int c;
    unsigned char data[1024];
    char buffer[1024];
    char * pb;

	//evaluate cmdline line argument
	if(argc < 3 ){
        printf("usage %s <device> <baudrate>\n",argv[0]);
	    return 1;
	}

	//dump verbose option
	if     (!memcmp("-vvv",argv[1],4)){cl=1;showlastonly=1;dump=1;verbose=1;}
	else if(!memcmp("-vv" ,argv[1],3)){cl=1;showlastonly=1;dump=1;verbose=0;}
	else if(!memcmp("-v"  ,argv[1],2)){cl=1;showlastonly=1;dump=0;verbose=0;}
    else {cl=0;showlastonly=0,dump=0,verbose=0;}

    //setting up baudrate
    serial.baudrate=atoi(argv[cl+2]);
    if(getbaudrate(serial.baudrate)==1){
        fprintf(stderr,"Fatal Error, cannot set baudrate: %d\n",serial.baudrate);
        return 1;
    }

	serial.port=strdup(argv[cl+1]);
    //opening the port
    if (openport()){
        fprintf(stderr,"Fatal Error, cannot open device: %s\n",serial.port);
        return 1;
    }

    ///*
    if(dump)printf("AT\n");
    serial_port_write("AT\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    if(dump)printf("ATE0\n");
    serial_port_write("ATE0\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }   
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    if(dump)printf("AT^CURC=0\n");
    serial_port_write("AT^CURC=0\r\n");
    len=getser(data,timeout);
    if(len){
        if(dump)fwrite(data,1,len,stdout);
        pb=(char *) buffer;
        pb=strstr((char *)data,"OK");
        if(memcmp("OK",pb,2)){
            perror("ERROR data!\n");
            fwrite(data,1,len,stdout);
            return 1;
        }
    }else{
        perror("ERROR timeout!\n");
        return 1;
    }
    //if(len)printhex(data,len);

    closeport();
    return 0;
}