kopia lustrzana https://github.com/Hamlib/Hamlib
initial import
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@15 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.0.0
rodzic
27bfac064c
commit
d5a340429d
|
@ -0,0 +1,34 @@
|
||||||
|
# hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Simple Make file for common parts.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# $Id: Makefile,v 1.1 2000-07-25 01:01:00 javabear Exp $
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
INCLUDE = -I/usr/include -I/usr/local/include -I. -I../include
|
||||||
|
OBJ = serial.o
|
||||||
|
LDFLAG = -lm
|
||||||
|
CFLAGS = -g -Wall -ansi -pedantic -O2 -D__USE_FIXED_PROTOTYPES__
|
||||||
|
MAKEALL = serial.o
|
||||||
|
|
||||||
|
all: $(MAKEALL)
|
||||||
|
|
||||||
|
serial.o: serial.c serial.h
|
||||||
|
$(CC) $(CFLAGS) $(INCLUDE) -c serial.c
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
|
||||||
|
clean:
|
||||||
|
make cleanlocal
|
||||||
|
|
||||||
|
# clean up local directory
|
||||||
|
|
||||||
|
.PHONY: cleanlocal
|
||||||
|
cleanlocal:
|
||||||
|
rm -f *.o serial
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
* hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
|
||||||
|
*
|
||||||
|
* serial.c - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
|
||||||
|
* Provides useful routines for read/write serial data for communicating
|
||||||
|
* via serial interface .
|
||||||
|
*
|
||||||
|
* $Id: serial.c,v 1.1 2000-07-25 01:01:00 javabear Exp $
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h> /* Standard input/output definitions */
|
||||||
|
#include <string.h> /* String function definitions */
|
||||||
|
#include <unistd.h> /* UNIX standard function definitions */
|
||||||
|
#include <fcntl.h> /* File control definitions */
|
||||||
|
#include <errno.h> /* Error number definitions */
|
||||||
|
#include <termios.h> /* POSIX terminal control definitions */
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open serial port
|
||||||
|
*
|
||||||
|
* Set to 4800 8N2
|
||||||
|
*
|
||||||
|
* input:
|
||||||
|
*
|
||||||
|
* serial_port - ptr to a char (string) indicating port
|
||||||
|
* to open (eg: "/dev/ttyS1").
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
*
|
||||||
|
* fd - the file descriptor on success or -1 on error.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
int open_port(char *serial_port) {
|
||||||
|
|
||||||
|
int fd; /* File descriptor for the port */
|
||||||
|
struct termios options;
|
||||||
|
|
||||||
|
|
||||||
|
fd = open(serial_port, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
|
|
||||||
|
if (fd == -1) {
|
||||||
|
|
||||||
|
/* Could not open the port. */
|
||||||
|
|
||||||
|
printf("open_port: Unable to open %s - ",serial_port);
|
||||||
|
return -1; /* bad */
|
||||||
|
}
|
||||||
|
|
||||||
|
fcntl(fd, F_SETFL, 0); /* */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the current options for the port...
|
||||||
|
*/
|
||||||
|
|
||||||
|
tcgetattr(fd, &options);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the baud rates to 4800...
|
||||||
|
*/
|
||||||
|
|
||||||
|
cfsetispeed(&options, B4800);
|
||||||
|
cfsetospeed(&options, B4800);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enable the receiver and set local mode...
|
||||||
|
*/
|
||||||
|
|
||||||
|
options.c_cflag |= (CLOCAL | CREAD);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 'close_port()' - Close serial port
|
||||||
|
*
|
||||||
|
* fd - file descriptor for open port
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Returns success (0) or -1 on error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int close_port(int fd) {
|
||||||
|
|
||||||
|
if (close(fd) <0 ) {
|
||||||
|
printf("close_port: Unable to close port using fd %i - ",fd);
|
||||||
|
return -1; /* oops */
|
||||||
|
}
|
||||||
|
return 0; /* ok */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provides delay for block formation.
|
||||||
|
* Should be 50-200 msec according to YAESU docs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pause2() {
|
||||||
|
usleep(50 * 1000); /* 50 msec */
|
||||||
|
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 *data) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<5; i++) {
|
||||||
|
if(write(fd, &data[i] , 1) < 0) {
|
||||||
|
fputs("write() of byte failed!\n", stderr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pause2(); /* 50 msec */
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
|
||||||
|
*
|
||||||
|
* serial.h - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
|
||||||
|
* Provides useful routines for read/write serial data for communicating
|
||||||
|
* via serial interface .
|
||||||
|
*
|
||||||
|
* $Id: serial.h,v 1.1 2000-07-25 01:01:00 javabear Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int open_port(char *serial_port);
|
||||||
|
int write_block(int fd, unsigned char *data);
|
||||||
|
int close_port(int fd);
|
||||||
|
|
Ładowanie…
Reference in New Issue