kopia lustrzana https://github.com/Hamlib/Hamlib
removed old open_port2() using old rig_caps
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@110 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.0
rodzic
29b80d060a
commit
24f0478b7c
214
common/serial.c
214
common/serial.c
|
@ -5,7 +5,7 @@
|
||||||
* Provides useful routines for read/write serial data for communicating
|
* Provides useful routines for read/write serial data for communicating
|
||||||
* via serial interface .
|
* via serial interface .
|
||||||
*
|
*
|
||||||
* $Id: serial.c,v 1.10 2000-09-16 01:29:35 f4cfe Exp $
|
* $Id: serial.c,v 1.11 2000-09-16 18:14:18 javabear Exp $
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -254,184 +254,6 @@ int serial_open(struct rig_state *rs) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Open serial port using rig_caps data
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* input: ptr to rig_caps structure, with serial port
|
|
||||||
* populated. (eg: "/dev/ttyS1").
|
|
||||||
*
|
|
||||||
* returns:
|
|
||||||
*
|
|
||||||
* fd - the file descriptor on success or -1 on error.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
int open_port2(struct rig_caps *rc) {
|
|
||||||
|
|
||||||
int fd; /* File descriptor for the port */
|
|
||||||
struct termios options;
|
|
||||||
|
|
||||||
/* Show calling structure */
|
|
||||||
|
|
||||||
printf("rig = %s \n", rc->rig_name);
|
|
||||||
printf("rig serial_rate_min = = %u \n", rc->serial_rate_min);
|
|
||||||
printf("rig serial_rate_max = = %u \n", rc->serial_rate_max);
|
|
||||||
printf("rig serial_port_name = %s \n", rc->serial_port_name);
|
|
||||||
printf("rig serial_data_bits = %u \n", rc->serial_data_bits);
|
|
||||||
printf("rig serial_stop_bits = %u \n", rc->serial_stop_bits);
|
|
||||||
printf("rig serial_parity = %u \n", rc->serial_parity);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fd = open(rc->serial_port_name, O_RDWR | O_NOCTTY | O_NDELAY);
|
|
||||||
|
|
||||||
if (fd == -1) {
|
|
||||||
|
|
||||||
/* Could not open the port. */
|
|
||||||
|
|
||||||
printf("open_port: Unable to open %s - ",rc->serial_port_name);
|
|
||||||
return -1; /* bad */
|
|
||||||
}
|
|
||||||
|
|
||||||
fcntl(fd, F_SETFL, 0); /* */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the current options for the port...
|
|
||||||
*/
|
|
||||||
|
|
||||||
tcgetattr(fd, &options);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the baud rates to requested values
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
switch(rc->serial_rate_max) {
|
|
||||||
case 4800:
|
|
||||||
cfsetispeed(&options, B4800);
|
|
||||||
cfsetospeed(&options, B4800);
|
|
||||||
break;
|
|
||||||
case 9600:
|
|
||||||
cfsetispeed(&options, B9600);
|
|
||||||
cfsetospeed(&options, B9600);
|
|
||||||
break;
|
|
||||||
case 57600:
|
|
||||||
cfsetispeed(&options, B57600);
|
|
||||||
cfsetospeed(&options, B57600);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("serial:incorrect rate specified \n");
|
|
||||||
return -1; /* die */
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enable the receiver and set local mode...
|
|
||||||
*/
|
|
||||||
|
|
||||||
options.c_cflag |= (CLOCAL | CREAD);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set data to requested values.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch(rc->serial_data_bits) {
|
|
||||||
case 7:
|
|
||||||
options.c_cflag &= ~CSIZE;
|
|
||||||
options.c_cflag |= CS7;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
options.c_cflag &= ~CSIZE;
|
|
||||||
options.c_cflag |= CS8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("serial:incorrect serial_data_bits specified \n");
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set stop bits to requested values.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch(rc->serial_stop_bits) {
|
|
||||||
case 1:
|
|
||||||
options.c_cflag &= ~CSTOPB;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
options.c_cflag |= CSTOPB;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printf("serial:incorrect serial_stop_bits specified \n");
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set parity to requested values.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch(rc->serial_parity) {
|
|
||||||
case RIG_PARITY_NONE:
|
|
||||||
options.c_cflag &= ~PARENB;
|
|
||||||
break;
|
|
||||||
case RIG_PARITY_EVEN:
|
|
||||||
options.c_cflag |= PARENB;
|
|
||||||
options.c_cflag &= ~PARODD;
|
|
||||||
break;
|
|
||||||
case RIG_PARITY_ODD:
|
|
||||||
options.c_cflag |= PARENB;
|
|
||||||
options.c_cflag |= PARODD;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("serial:incorrect serial_parity specified \n");
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set 8N2
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* options.c_cflag &= ~PARENB; */
|
|
||||||
/* options.c_cflag |= CSTOPB; */
|
|
||||||
/* options.c_cflag &= ~CSIZE; */
|
|
||||||
/* options.c_cflag |= CS8; */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chose raw input, no preprocessing please ..
|
|
||||||
*/
|
|
||||||
|
|
||||||
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chose raw output, no preprocessing please ..
|
|
||||||
*/
|
|
||||||
|
|
||||||
options.c_oflag &= ~OPOST;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the new options for the port...
|
|
||||||
*/
|
|
||||||
|
|
||||||
tcsetattr(fd, TCSANOW, &options);
|
|
||||||
|
|
||||||
return (fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open serial port
|
* Open serial port
|
||||||
*
|
*
|
||||||
|
@ -546,40 +368,6 @@ void pause2() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Write a 5 character block to a file descriptor,
|
|
||||||
* with a pause between each character.
|
|
||||||
*
|
|
||||||
* This is for Yaesu type rigs..require 5 character
|
|
||||||
* sequence to bsent with 50-200msec between each char.
|
|
||||||
*
|
|
||||||
* input:
|
|
||||||
*
|
|
||||||
* fd - file descriptor to write to
|
|
||||||
* data - pointer to a command sequence array
|
|
||||||
*
|
|
||||||
* returns:
|
|
||||||
*
|
|
||||||
* 0 = OK
|
|
||||||
* -1 = NOT OK
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
int write_block(int fd, unsigned char *txbuffer) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i<5; i++) {
|
|
||||||
|
|
||||||
if(write(fd, &txbuffer[i] , 1) < 0) {
|
|
||||||
fputs("write() of byte failed!\n", stderr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pause2(); /* 50 msec */
|
|
||||||
}
|
|
||||||
dump_hex(txbuffer,5,16);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Ładowanie…
Reference in New Issue