- tts_fd=open(tts,O_RDWR);
- if(tts_fd<0) {
- perror("tts open");
- return tts_fd;
- }
-
- /*
- * configure serial device
- */
-
- tcgetattr(tts_fd,&term);
-
- // input/output baudrate
-
- cfsetispeed(&term,B9600);
- cfsetospeed(&term,B9600);
-
- // control options -> 8n1
-
- term.c_cflag&=~PARENB; // no parity
- term.c_cflag&=~CSTOPB; // only 1 stop bit
- term.c_cflag&=~CSIZE; // no bit mask for data bits
- term.c_cflag|=CS8; // 8 data bits
-
- // line options -> raw input
-
- term.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG);
-
- // input options -> disable flow control
-
- term.c_iflag&=~(IXON|IXOFF|IXANY);
-
- // more control options -> timeout
-
- term.c_cc[VMIN]=0;
- term.c_cc[VTIME]=10; // 1 second timeout
-
- tcsetattr(tts_fd,TCSANOW,&term);
-
- /* auto baud sequence */
-
- printf("auto baud sequence ...\n");
- write(tts_fd,"?",1);
- len=0;
- txrx(tts_fd,buf,&len,info);
- if(strncmp(buf,"Synchronized\r\n",14)) {
- printf("auto baud detection failed\n");
- return -1;
- }
-
- /* tell bl that we are synchronized (it's allready in buf) */
-
- printf("sync sequence ...\n");
- len=14;
- txrx(tts_fd,buf,&len,info);
- if(strncmp(buf,"OK\r\n",4)) {
- printf("sync failed\n");
- return -1;
- }
-
- /* tell bl the crystal frequency */
-
- printf("frequency setting sequence ...\n");
- len=strlen(cfreq)+2;
- strncpy(buf,cfreq,BUFSIZE);
- buf[len-2]='\r';
- buf[len-1]='\n';
- txrx(tts_fd,buf,&len,info);
- if(strncmp(buf,"OK\r\n",4)) {
- printf("freq set failed\n");
- return -1;
- }