From 9419ada73e5f95d58dc583c83492f897bc825018 Mon Sep 17 00:00:00 2001 From: "Frank Singleton, VK3FCS" Date: Tue, 18 Jul 2000 20:55:08 +0000 Subject: [PATCH] Initial revision git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- README | 39 +++++ TODO.skeleton | 15 ++ ft747/Makefile | 85 ++++++++++ ft747/README.ft747 | 34 ++++ ft747/TODO.ft747 | 16 ++ ft747/ft747.c | 346 ++++++++++++++++++++++++++++++++++++++ ft747/ft747.h | 99 +++++++++++ ft747/test/Makefile | 62 +++++++ ft747/test/testlibft747.c | 262 +++++++++++++++++++++++++++++ ft747/test/testlibft747.h | 15 ++ 10 files changed, 973 insertions(+) create mode 100644 README create mode 100644 TODO.skeleton create mode 100644 ft747/Makefile create mode 100644 ft747/README.ft747 create mode 100644 ft747/TODO.ft747 create mode 100644 ft747/ft747.c create mode 100644 ft747/ft747.h create mode 100644 ft747/test/Makefile create mode 100644 ft747/test/testlibft747.c create mode 100644 ft747/test/testlibft747.h diff --git a/README b/README new file mode 100644 index 000000000..c2a2b0c49 --- /dev/null +++ b/README @@ -0,0 +1,39 @@ +hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + +The purpose of this project is to provide stable, flexible, +shared libraries that enable quicker development of Amateur +Radio Equipment Control Applications. + +Many Amateur Radio Transceivers come with serial interfaces +that allows software to control the radio. This project will +endeavour to provide shared libraries that greatly simplify +the application programmers interaction with radio equipment. + +The shared libs will provide functions for both radio control, +and data retrieval from the radio. + +Examples are: + +1.libft747.so will provide connectivity to Yeasu + FT 747GX Transceiver via a standard API. + +2. libft847.so will provide connectivity to Yaesu FT 847 + "Earth Station" via a standard API. + +3. libxxxx.so will provide connectivity to the Wiz-bang + moon-melter 101A (yikes..) + +These libraries will also enable developers to develop +professional looking GUI's towards a standard control library +API, and they would not have to worry about the underlying +connection towards physical hardware. + +Initially serial (RS232) connectivity will be handled, but +I expect that IP connectivity will follow afterwards. + + +Have Fun / Frank S. + + 73's de vk3fcs/km5ws + + diff --git a/TODO.skeleton b/TODO.skeleton new file mode 100644 index 000000000..1f7dac7c6 --- /dev/null +++ b/TODO.skeleton @@ -0,0 +1,15 @@ +hamlib - (C) Frank Singleton 2000 + +TODO. - (C) 2000 +This shared library provides an API for communicating +via serial interface to a using the interface. + +TODO +---- + +1. Complete pcodes +2. Write More extensive Test Suite +3. Document API +4. Document Limitations/Assumptions. +5. + diff --git a/ft747/Makefile b/ft747/Makefile new file mode 100644 index 000000000..c6c7fb61a --- /dev/null +++ b/ft747/Makefile @@ -0,0 +1,85 @@ +# +# +# Make file for FT-747GX CAT program shared lib +# +# creates: libft747.so +# +# $Id: Makefile,v 1.1 2000-07-18 20:53:46 frank Exp $ +# +# +# .h files go in INSTALL_INCLUDEDIR +# .so files go in INSTALL_LIBDIR +# +# + + +INSTALL_LIBDIR = ./lib/ +INSTALL_INCLUDEDIR = ./include/ + +LIB_NAME = libft747.so +LIB_SONAME = libft747.so.1 +LIB_RELEASE = libft747.so.1.0.1 +LIB_HEADER = ft747.h +LIB_SRC = ft747.c +LIB_OBJECTS = ft747.o + +all: lib + +.PHONY: lib +lib: + gcc -fPIC -g -Wall -c $(LIB_SRC) + gcc -shared -Wl,-soname,$(LIB_SONAME) -o $(LIB_RELEASE) $(LIB_OBJECTS) -lc + +# install header and lib + +install: + make install_lib + make install_header + +# install lib in MYLIBDIR + +.PHONY: install_lib +install_lib: + mv $(LIB_RELEASE) $(INSTALL_LIBDIR) + cd $(INSTALL_LIBDIR); /sbin/ldconfig -n . + cd $(INSTALL_LIBDIR); ln -s $(LIB_SONAME) $(LIB_NAME) + +# install libft747.h in INSTALL_INCLUDEDIR + +.PHONY: install_header +install_header: + cp -f $(LIB_HEADER) $(INSTALL_INCLUDEDIR) + + +# clean up local directory, my include and lib +# directories also. + +clean: + make cleanlocal + make cleanlib + make cleaninclude + +# clean up local directory + +.PHONY: cleanlocal +cleanlocal: + rm -f *.o *.so* + +# clean up local lib directory + +.PHONY: cleanlib +cleanlib: + cd $(INSTALL_LIBDIR); rm -f $(LIB_NAME)* + + + +# clean up local include directory + +.PHONY: cleaninclude +cleaninclude: + cd $(INSTALL_INCLUDEDIR); rm -f $(LIB_HEADER) + + + + + diff --git a/ft747/README.ft747 b/ft747/README.ft747 new file mode 100644 index 000000000..fff73d549 --- /dev/null +++ b/ft747/README.ft747 @@ -0,0 +1,34 @@ +hamlib - (C) Frank Singleton 2000 + +libft747.so - (C) Frank Singleton 2000 +This shared library provides an API for communicating +via serial interface to an FT-747GX using the "CAT" interface +box (FIF-232C) or similar. + + +Reference Documentation +----------------------- + +Operating Manual +FT-747GX +Yaesu Musen Co, LTD. + + +Status +------ + +Handles >90% of all opcodes + + +Warnings +-------- + +NA + + +Contributors +------------ + + + + diff --git a/ft747/TODO.ft747 b/ft747/TODO.ft747 new file mode 100644 index 000000000..0f0ac8e20 --- /dev/null +++ b/ft747/TODO.ft747 @@ -0,0 +1,16 @@ +hamlib - (C) Frank Singleton 2000 + +TODO.ft747 - (C) Frank Singleton 2000 +This shared library provides an API for communicating +via serial interface to an FT-747GX using the "CAT" interface +box (FIF-232C) or similar. + +TODO +---- + +1. Complete pcodes +2. Write More extensive Test Suite +3. +4. +5. + diff --git a/ft747/ft747.c b/ft747/ft747.c new file mode 100644 index 000000000..b1c44ac3d --- /dev/null +++ b/ft747/ft747.c @@ -0,0 +1,346 @@ +/* + * hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + * + * ft747.c - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + * This shared library provides an API for communicating + * via serial interface to an FT-747GX using the "CAT" interface + * box (FIF-232C) or similar + * + * + * $Id: ft747.c,v 1.1 2000-07-18 20:54:22 frank Exp $ + * + */ + +#include +#include /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include /* POSIX terminal control definitions */ +#include + +#include "ft747.h" + +static unsigned char datain[350]; /* data read from rig */ + +struct ft747_update_data { + unsigned char displayed_status; + unsigned char displayed_freq[5]; + unsigned char current_band_data; + unsigned char vfo_a_status; + unsigned char vfo_a_freq_block[5]; +}; + + +/* + * Function definitions below + */ + + +/* + * Provides delay for block formation. + * Should be 50-200 msec according to YAESU docs. + */ + +static void pause2() { + usleep(50 * 1000); /* 50 msec */ + return; +} + +/* + * Write a 5 character block to a file descriptor, + * with a pause between each character. + * + * input: + * + * fd - file descriptor to write to + * data - pointer to a command sequence array + * + * returns: + * + * 0 = OK + * -1 = NOT OK + * + */ + +static 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; +} + +/* + * 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 */ +} + +/* + * Implement OPCODES + */ + +void cmd_split_yes(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x01, 0x01 }; /* split = on */ + write_block(fd,data); +} + +void cmd_split_no(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x01 }; /* split = off */ + write_block(fd,data); +} + +void cmd_recall_memory(int fd, int mem) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x02 }; /* recall memory*/ + + data[3] = mem; + write_block(fd,data); +} + +void cmd_vfo_to_memory(int fd, int mem) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x03 }; /* vfo to memory*/ + + data[3] = mem; + write_block(fd,data); +} + +void cmd_dlock_off(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x04 }; /* dial lock = off */ + write_block(fd,data); +} + +void cmd_dlock_on(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x01, 0x04 }; /* dial lock = on */ + write_block(fd,data); + +} + +void cmd_select_vfo_a(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x05 }; /* select vfo A */ + write_block(fd,data); +} + +void cmd_select_vfo_b(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x01, 0x05 }; /* select vfo B */ + write_block(fd,data); +} + +void cmd_memory_to_vfo(int fd, int mem) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x06 }; /* memory to vfo*/ + + data[3] = mem; + write_block(fd,data); +} + +void cmd_up500k(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x07 }; /* up 500 khz */ + write_block(fd,data); +} + +void cmd_down500k(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x08 }; /* down 500 khz */ + write_block(fd,data); +} + +void cmd_clarify_off(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x09 }; /* clarify off */ + write_block(fd,data); + printf("cmd_clarify_off complete \n"); +} + +void cmd_clarify_on(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x01, 0x09 }; /* clarify on */ + write_block(fd,data); + printf("cmd_clarify_on complete \n"); +} + +void cmd_freq_set(int fd, unsigned int freq) { + printf("cmd_freq_set not implemented yet \n"); +} + + +void cmd_mode_set(int fd, int mode) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x0c }; /* mode set */ + + data[3] = mode; + write_block(fd,data); + printf("cmd_mode_set complete \n"); + +} + +void cmd_pacing_set(int fd, int delay) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x0e }; /* pacing set */ + + data[3] = delay; + write_block(fd,data); + printf("cmd_pacing_set complete \n"); + +} + +void cmd_ptt_off(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x0f }; /* ptt off */ + write_block(fd,data); + printf("cmd_ptt_off complete \n"); + +} + +void cmd_ptt_on(int fd) { + +#ifndef TX_DISABLED + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x01, 0x0f }; /* ptt on */ + write_block(fd,data); + printf("cmd_ptt_on complete \n"); +#elsif + printf("cmd_ptt_on disabled \n"); +#endif + +} + +void cmd_update(int fd) { + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x10 }; /* request update from rig */ + write_block(fd,data); + printf("cmd_update complete \n"); +} + +/* + * Read data from rig and store in buffer provided + * by the user. + */ + +void cmd_update_store(int fd, unsigned char *buffer) { + int bytes; /* read from rig */ + int i,n; /* counters */ + + static unsigned char data[] = { 0x00, 0x00, 0x00, 0x00, 0x10 }; /* request update from rig */ + write_block(fd,data); + + /* + * Sleep regularly until the buffer contains all 345 bytes + * This should handle most values used for pacing. + */ + + bytes = 0; + while(bytes < 345) { + ioctl(fd, FIONREAD, &bytes); /* get bytes in buffer */ + printf("bytes = %i\n", bytes); + sleep(1); /* wait 1 second */ + } + + /* this should not block now */ + + n = read(fd,datain,345); /* grab 345 bytes from rig */ + + for(i=0; i +#include /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include /* POSIX terminal control definitions */ +#include + +#include "testlibft747.h" +#include "ft747.h" + +static unsigned char datain[350]; /* data read from rig */ + +struct ft747_update_data { + unsigned char displayed_status; + unsigned char displayed_freq[5]; + unsigned char current_band_data; + unsigned char vfo_a_status; + unsigned char vfo_a_freq_block[5]; +}; + + + +/* + * Decode routines for status update map + */ + +static void decode_status_flags(unsigned char flags) { + + if((flags & SF_DLOCK) != 0 ) { + printf("Dial Lock = SET \n"); + } else { + printf("Dial Lock = CLEAR \n"); + } + + if((flags & SF_SPLIT) != 0 ) { + printf("Split = SET \n"); + } else { + printf("Split = CLEAR \n"); + } + + if((flags & SF_CLAR) != 0 ) { + printf("Clar = SET \n"); + } else { + printf("Clar = CLEAR \n"); + } + + if((flags & SF_VFOAB) != 0 ) { + printf("VFO = B \n"); + } else { + printf("VFO = A \n"); + } + + if((flags & SF_VFOMR) != 0 ) { + printf("VFO/MR = MR \n"); + } else { + printf("VFO/MR = VFO \n"); + } + + if((flags & SF_RXTX) != 0 ) { + printf("RX/TX = TX \n"); + } else { + printf("RX/TX = RX \n"); + } + + if((flags & SF_PRI) != 0 ) { + printf("Priority Monitoring = ON \n"); + } else { + printf("Priority Monitoring = OFF \n"); + } + + +} + + +/* + * Decode routines for status update map + */ + +static void decode_mode_bit_map(unsigned char mbm) { + unsigned char mask = 0x1f; + unsigned char mode = mbm & mask; /* grab operating mode */ + + printf("mbm = %x, mode = %x \n",mbm, mode); + + switch(mode) { + case 1: + printf("Current Mode = FM \n"); + break; + case 2: + printf("Current Mode = AM \n"); + break; + case 4: + printf("Current Mode = CW \n"); + break; + case 8: + printf("Current Mode = USB \n"); + break; + case 16: + printf("Current Mode = LSB \n"); + break; + default: + printf("Current mode = XXXXX \n"); + break; + } + + if((mbm & MODE_NAR) != 0 ) { + printf("Narrow = SET \n"); + } else { + printf("Narrow = CLEAR \n"); + } + +} + + +/* + * Decode routines for status update map + */ + +static void decode_band_data(unsigned char data) { + unsigned char mask = 0x0f; + unsigned char bd = data & mask; /* grab band data */ + + printf("Band data is %f - %f \n", band_data[bd], band_data[bd+1]); + + +} + +/* + * Do a hex dump of the unsigned car array. + */ + +static void dump_hex(unsigned char *ptr, int size, int length) { + int i; + + printf("Memory Dump \n\n"); + for(i=0; idisplayed_freq[1], + header->displayed_freq[2], + header->displayed_freq[3], + header->displayed_freq[4] + ); + + decode_status_flags(datain[0]); /* decode flags */ + printf("Displayed Memory = %i \n", datain[23]); + decode_mode_bit_map(datain[24]); /* decode mode bit map */ + decode_band_data(datain[6]); /* decode current band data */ + + dump_hex(datain, 345, 16); /* do a hex dump */ + + return 0; +} + + +/* + * Main program starts here.. + */ + + +int main(void) { + + + int fd; + + fd = open_port(SERIAL_PORT); + printf("port opened ok \n"); + + test(fd); + printf("testing communication result ok \n"); + + close(fd); + printf("port closed ok \n"); + + return 0; +} + diff --git a/ft747/test/testlibft747.h b/ft747/test/testlibft747.h new file mode 100644 index 000000000..de29e2256 --- /dev/null +++ b/ft747/test/testlibft747.h @@ -0,0 +1,15 @@ +/* + * hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + * + * testlibft747.h - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + * This program tests the libft747.so API for communicating + * via serial interface to an FT-747GX using the "CAT" interface + * box (FIF-232C) or similar. + * + * + * $Id: testlibft747.h,v 1.1 2000-07-18 20:55:08 frank Exp $ + */ + + +#define SERIAL_PORT "/dev/ttyS1" +