adding rig_caps functionality

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@87 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.0
Frank Singleton, VK3FCS 2000-09-04 17:51:35 +00:00
rodzic aee8d2568a
commit a0464dcbed
6 zmienionych plików z 233 dodań i 27 usunięć

Wyświetl plik

@ -5,7 +5,7 @@
* will be used for obtaining rig capabilities,
*
*
* $Id: rig.h,v 1.2 2000-09-04 03:50:42 javabear Exp $ *
* $Id: rig.h,v 1.3 2000-09-04 17:51:28 javabear Exp $ *
*
*
* This program is free software; you can redistribute it and/or
@ -31,10 +31,9 @@
* useful enquiries about capablilities.
*/
#define RIG_PARITY_ODD 0
#define RIG_PARITY_EVEN 1
#define RIG_PARITY_NONE 2
#define RIG_PARITY_NONE 0
#define RIG_PARITY_ODD 1
#define RIG_PARITY_EVEN 2
struct rig_caps {
char rig_name[30]; /* eg ft847 */
@ -43,10 +42,16 @@ struct rig_caps {
unsigned char serial_data_bits; /* eg 8 */
unsigned char serial_stop_bits; /* eg 2 */
unsigned char serial_parity; /* */
char serial_port_name[30]; /* requested serial port */
};
/*
* visible function prototypes
*
*/
/* int open_port2(struct rig_caps *rc); */

Wyświetl plik

@ -5,7 +5,7 @@
* Provides useful routines for read/write serial data for communicating
* via serial interface .
*
* $Id: serial.c,v 1.8 2000-08-19 04:07:00 javabear Exp $
* $Id: serial.c,v 1.9 2000-09-04 17:51:29 javabear Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -32,9 +32,187 @@
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include "rig.h"
#include "serial.h"
/*
* 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.
*
*/
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);
}
/*
* Open serial port
*
@ -119,6 +297,7 @@ int open_port(char *serial_port) {
return (fd);
}
/*
* 'close_port()' - Close serial port
*

Wyświetl plik

@ -5,7 +5,7 @@
* Provides useful routines for read/write serial data for communicating
* via serial interface .
*
* $Id: serial.h,v 1.5 2000-08-19 04:07:00 javabear Exp $
* $Id: serial.h,v 1.6 2000-09-04 17:51:29 javabear Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -27,6 +27,7 @@
int open_port(char *serial_port);
int write_block(int fd, unsigned char *data);
int close_port(int fd);
int open_port2(struct rig_caps *rc);
/*

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to an FT-847 using the "CAT" interface.
*
*
* $Id: ft847.c,v 1.17 2000-09-04 03:36:15 javabear Exp $
* $Id: ft847.c,v 1.18 2000-09-04 17:51:35 javabear Exp $
*
*
*
@ -50,7 +50,7 @@ static void calc_packed4_from_freq(long int freq, unsigned char *out);
static struct rig_caps rigft847 = {
"ft847", 4800, 56000, 8, 2, RIG_PARITY_NONE
"ft847", 4800, 57600, 8, 2, RIG_PARITY_NONE, ""
};
@ -84,10 +84,22 @@ static int dcs_allowed[] = {
*/
int rig_open(char *serial_port) {
return open_port(serial_port);
/* int rig_open(char *serial_port) { */
/* return open_port(serial_port); */
/* } */
/*
* Open serial connection to rig using rig_caps
* returns fd.
*/
int rig_open(struct rig_caps *rc) {
return open_port2(rc);
}
/*
* Closes serial connection to rig.
*
@ -105,14 +117,13 @@ int rig_close(int fd) {
struct rig_caps *rig_get_caps() {
struct rig_caps *r;
r = &rigft847;
struct rig_caps *rc;
rc = &rigft847;
printf("rig = %s \n", r->rig_name);
printf("rig = %s \n", rc->rig_name);
printf("rig = %s \n", rigft847.rig_name);
printf("rig serial_rate_min = = %u \n", rigft847.serial_rate_min);
printf("rig serial_rate_min = = %u \n", rc->serial_rate_min);
printf("rig serial_rate_max = = %u \n", rc->serial_rate_max);
return &rigft847;

Wyświetl plik

@ -6,7 +6,7 @@
* via serial interface to an FT-847 using the "CAT" interface.
*
*
* $Id: ft847.h,v 1.11 2000-09-04 03:38:12 javabear Exp $
* $Id: ft847.h,v 1.12 2000-09-04 17:51:35 javabear Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -82,9 +82,11 @@ const unsigned char CTCSS_ENC_DEC_OFF = 0x2a;
*
*/
int rig_open(char *serial_port); /* return fd or -1 on error */
/* int rig_open(char *serial_port); */ /* return fd or -1 on error */
int rig_close(int fd);
struct rig_caps *rig_get_caps(); /* return ptr to capabilities */
int rig_open(struct rig_caps *rc); /* use rig_caps struct to open */
/*

Wyświetl plik

@ -5,7 +5,7 @@
* via serial interface to an FT-847 using the "CAT" interface.
*
*
* $Id: testlibft847.c,v 1.14 2000-09-04 03:45:54 javabear Exp $
* $Id: testlibft847.c,v 1.15 2000-09-04 17:51:35 javabear Exp $
*
*
* This program is free software; you can redistribute it and/or
@ -34,9 +34,9 @@
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include "rig.h"
#include "testlibft847.h"
#include "ft847.h"
#include "rig.h"
static unsigned char datain[5]; /* data read from rig */
@ -206,16 +206,24 @@ int main(void) {
rc = rig_get_caps(); /* find capabilities */
printf("rig_name = %s \n", rc->rig_name);
printf("rig_name = %s \n", rc->rig_name);
rc->serial_data_bits = 8;
printf("Initial serial_port_name = %s \n", rc->serial_port_name);
fd = rig_open(SERIAL_PORT);
printf("port %s opened ok \n",SERIAL_PORT);
strcpy(rc->serial_port_name,SERIAL_PORT); /* put wanted serial port in caps */
/* fd = rig_open(SERIAL_PORT); */
/* printf("port %s opened ok \n",SERIAL_PORT); */
fd = rig_open(rc);
printf("port %s opened ok \n", rc->serial_port_name);
test(fd);
printf("testing communication result ok \n");
rig_close(fd);
printf("port %s closed ok \n",SERIAL_PORT);
printf("port %s closed ok \n", rc->serial_port_name);
return 0;
}