| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  Hamlib Rotator backend - Fodtrack parallel port | 
					
						
							| 
									
										
										
										
											2005-04-03 12:27:17 +00:00
										 |  |  |  *  Copyright (c) 2001-2005 by Stephane Fillod | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-03 12:27:17 +00:00
										 |  |  |  *	$Id: fodtrack.c,v 1.8 2005-04-03 12:27:15 fillods Exp $ | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  *   This library is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  *   it under the terms of the GNU Library General Public License as | 
					
						
							|  |  |  |  *   published by the Free Software Foundation; either version 2 of | 
					
						
							|  |  |  |  *   the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  *   GNU Library General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   You should have received a copy of the GNU Library General Public | 
					
						
							|  |  |  |  *   License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>  /* String function definitions */
 | 
					
						
							|  |  |  | #include <unistd.h>  /* UNIX standard function definitions */
 | 
					
						
							| 
									
										
										
										
											2003-04-07 22:42:11 +00:00
										 |  |  | #ifdef HAVE_SYS_IOCTL_H
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | #include <sys/ioctl.h>
 | 
					
						
							| 
									
										
										
										
											2003-04-07 22:42:11 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  | #ifdef HAVE_LINUX_PARPORT_H
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | #include <linux/parport.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-07 22:42:11 +00:00
										 |  |  | #include "hamlib/rotator.h"
 | 
					
						
							| 
									
										
										
										
											2004-10-02 20:37:24 +00:00
										 |  |  | #include "parallel.h"
 | 
					
						
							| 
									
										
										
										
											2003-04-07 22:42:11 +00:00
										 |  |  | #include "misc.h"
 | 
					
						
							| 
									
										
										
										
											2003-04-16 22:30:43 +00:00
										 |  |  | #include "register.h"
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "fodtrack.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-25 22:26:42 +00:00
										 |  |  | #ifndef PARPORT_CONTROL_AUTOFD
 | 
					
						
							|  |  |  | #define PARPORT_CONTROL_AUTOFD 0x2
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifndef PARPORT_CONTROL_STROBE
 | 
					
						
							|  |  |  | #define PARPORT_CONTROL_STROBE 0x1
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  | #ifndef CP_ACTIVE_LOW_BITS
 | 
					
						
							|  |  |  | #define CP_ACTIVE_LOW_BITS 0x0B
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** outputs an direction to the interface */ | 
					
						
							| 
									
										
										
										
											2005-04-03 12:27:17 +00:00
										 |  |  | static int setDirection(hamlib_port_t *port, unsigned char outputvalue, int direction) | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   unsigned char outputstatus; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  |   par_lock (port); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   // set the data bits
 | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  |   par_write_data(port, outputvalue); | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // autofd=true --> azimuth otherwhise elevation
 | 
					
						
							|  |  |  |   if(direction) | 
					
						
							|  |  |  |     outputstatus = PARPORT_CONTROL_AUTOFD; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     outputstatus=0; | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  |   par_write_control(port, outputstatus^CP_ACTIVE_LOW_BITS); | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   // and now the strobe impulse
 | 
					
						
							|  |  |  |   usleep(1); | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   if(direction) | 
					
						
							|  |  |  |     outputstatus = PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     outputstatus = PARPORT_CONTROL_STROBE; | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  |   par_write_control(port, outputstatus^CP_ACTIVE_LOW_BITS); | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   usleep(1); | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   if (direction) | 
					
						
							|  |  |  |     outputstatus= PARPORT_CONTROL_AUTOFD; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     outputstatus=0; | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  |   par_write_control(port, outputstatus^CP_ACTIVE_LOW_BITS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   par_unlock (port); | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return RIG_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | fodtrack_set_position(ROT *rot, azimuth_t az, elevation_t el) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |  int retval; | 
					
						
							| 
									
										
										
										
											2005-04-03 12:27:17 +00:00
										 |  |  |  hamlib_port_t *pport; | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __FUNCTION__, az, el); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  |   pport = &rot->state.rotport; | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  |   retval = setDirection(pport, el/(float)rot->state.max_el*255.0, 0); | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   if (retval != RIG_OK) | 
					
						
							|  |  |  | 	  return retval; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-22 19:52:40 +00:00
										 |  |  |   retval = setDirection(pport, az/(float)rot->state.max_az*255.0, 1); | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   if (retval != RIG_OK) | 
					
						
							|  |  |  | 	  return retval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return RIG_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Fodtrack rotator capabilities. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Fodtrack implement essentially only the set position function.
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const struct rot_caps fodtrack_rot_caps = { | 
					
						
							|  |  |  |   .rot_model =      ROT_MODEL_FODTRACK, | 
					
						
							|  |  |  |   .model_name =     "Fodtrack", | 
					
						
							|  |  |  |   .mfg_name =       "XQ2FOD", | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  |   .version =        "0.2", | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   .copyright = 	    "LGPL", | 
					
						
							| 
									
										
										
										
											2003-09-28 15:34:44 +00:00
										 |  |  |   .status =         RIG_STATUS_STABLE, | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  |   .rot_type =       ROT_TYPE_OTHER, | 
					
						
							|  |  |  |   .port_type =      RIG_PORT_PARALLEL, | 
					
						
							|  |  |  |   .write_delay =  0, | 
					
						
							|  |  |  |   .post_write_delay =  0, | 
					
						
							|  |  |  |   .timeout =  200, | 
					
						
							|  |  |  |   .retry =  3, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   .min_az = 	0, | 
					
						
							|  |  |  |   .max_az =  	450, | 
					
						
							|  |  |  |   .min_el = 	0, | 
					
						
							|  |  |  |   .max_el =  	180, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   .priv =  NULL,	/* priv */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   .set_position =  fodtrack_set_position, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-16 22:30:43 +00:00
										 |  |  | DECLARE_INITROT_BACKEND(fodtrack) | 
					
						
							| 
									
										
										
										
											2002-11-28 22:24:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rot_register(&fodtrack_rot_caps); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return RIG_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | /* end of file */ |