00001 /************************************************************************* 00002 ***** PTU BINARY OPCODES INCLUDE FILE ***** 00003 ***** ***** 00004 ***** (C)1992..2000 Directed Perception, Inc. ***** 00005 ***** All Rights Reserved. ***** 00006 ***** ***** 00007 ***** Licensed users may freely distribute compiled code including ***** 00008 ***** this code and data. Source data and code may NOT be ***** 00009 ***** distributed without the prior written consent from ***** 00010 ***** Directed Perception, Inc. ***** 00011 ***** Directed Perception, Inc. reserves the right to make ***** 00012 ***** changes without further notice to any content herein to ***** 00013 ***** improve reliability, function or design. Directed Perception ***** 00014 ***** shall not assume any liability arising from the application ***** 00015 ***** or use of this code, data or function. ***** 00016 ***** ***** 00017 ************************************************************************** 00018 00019 CHANGE HISTORY: 00020 12/10/99: v1.09.12 added a write and wait after open in open_host_port 00021 for networked operation 00022 11/10/99: v1.09.11. Added asynchronous event status handling functions. 00023 8/10/98: v1.08.09. In firmware_version_OK, removed addressing to string constant. 00024 7/15/97: v1.08.00. Compiles with MSVC v1.52. Unified with Win16/32 00025 PTU interface calls. 00026 6/20/97: #define of ALL misdefined. Fixed to equal PAN+TILT 00027 11/2/95: v1.07.07d. Firmware version check bug fixed. 00028 7/11/95: v1.07.06d. Updated opcode structure and added new support. 00029 2/19/95: v1.07.04d. Generalized for Windows, DOS, & UNIX. 00030 Added networking. 00031 10/12/94: v1.07.03d. Pre-release working version. 00032 XON/XOFF removed from PTU firmware to allow for binary mode. 00033 00034 00035 **************************************************************************/ 00036 #define _UNIX 00037 00038 /*** Conditionally include the required serial interface declarations. ***/ 00039 /*** If your compiler doesn't have the macro symbol defined, you can ***/ 00040 /*** manually select the right include file yourself. ***/ 00041 //#if defined(_WIN32) 00042 //#include "..\include\W32SERIA.H" 00043 //#elif defined(_WIN16) 00044 //#include "..\include\W16SERIA.H" 00045 //#elif defined(_DOS) 00046 //#include "..\include\DOSSERIA.H" 00047 //#elif defined(_UNIX) 00048 #include "linuxser.h" 00049 //#endif 00050 00051 #include "opcodes.h" 00052 #include <math.h> 00053 00054 /* return status codes */ 00055 #define PTU_OK 0 00056 #define PTU_ILLEGAL_COMMAND_ARGUMENT 1 00057 #define PTU_ILLEGAL_COMMAND 2 00058 #define PTU_ILLEGAL_POSITION_ARGUMENT 3 00059 #define PTU_ILLEGAL_SPEED_ARGUMENT 4 00060 #define PTU_ACCEL_TABLE_EXCEEDED 5 00061 #define PTU_DEFAULTS_EEPROM_FAULT 6 00062 #define PTU_SAVED_DEFAULTS_CORRUPTED 7 00063 #define PTU_LIMIT_HIT 8 00064 #define PTU_CABLE_DISCONNECTED 9 00065 #define PTU_ILLEGAL_UNIT_ID 10 00066 #define PTU_ILLEGAL_POWER_MODE 11 00067 #define PTU_RESET_FAILED 12 00068 #define PTU_NOT_RESPONDING 13 00069 #define PTU_FIRMWARE_VERSION_TOO_LOW 14 00070 00071 /******************************************************************** 00072 ***** ***** 00073 ***** For all of these commands, a non-zero return status ***** 00074 ***** indicates an error, and it returns that error code. ***** 00075 ***** ***** 00076 ********************************************************************/ 00077 00078 /* open_host_port(<portname>) ==> <portstream> */ 00079 extern portstream_fd open_host_port(char *); 00080 00081 /* close_host_port(<portstream>) ==> <status> */ 00082 extern char close_host_port(portstream_fd); 00083 00084 00085 00086 typedef short int PTU_PARM_PTR; 00087 00088 /* reset_PTU_parser(<timeout_in_msec>) ==> [PTU_OK|PTU_NOT_RESPONDING] */ 00089 extern char reset_PTU_parser(long); 00090 00091 /* set_desired([PAN|TILT], 00092 [POSITION|SPEED|ACCELERATION|BASE|UPPER_SPEED_LIMIT|LOWER_SPEED_LIMIT], 00093 [<position>|<speed>|<acceleration>], 00094 [RELATIVE|ABSOLUTE]) ==> <status> 00095 set_desired([PAN|TILT], 00096 HOLD_POWER_LEVEL, 00097 <power mode>, 00098 NULL) ==> <status> 00099 set_desired([PAN|TILT], 00100 [HOLD_POWER_LEVEL,MOVE_POWER_LEVEL], 00101 [PTU_REG_POWER|PTU_LOW_POWER|PTU_OFF_POWER], 00102 NULL) ==> <status> */ 00103 extern char set_desired(char, char, PTU_PARM_PTR *, char); 00104 00105 00106 /* get_current([PAN|TILT], 00107 [POSITION|SPEED|ACCELERATION|BASE|UPPER_SPEED_LIMIT|LOWER_SPEED_LIMIT| 00108 HOLD_POWER_LEVEL|MOVE_POWER_LEVEL|RESOLUTION]) ==> <value> */ 00109 extern long get_current(char, char); 00110 00111 00112 /* get_desired([PAN|TILT], 00113 [POSITION|SPEED|ACCELERATION|BASE|UPPER_SPEED_LIMIT|LOWER_SPEED_LIMIT| 00114 HOLD_POWER_LEVEL|MOVE_POWER_LEVEL|RESOLUTION]) ==> <value> */ 00115 extern long get_desired(char, char); 00116 00117 00118 /* set_mode(COMMAND_EXECUTION_MODE, 00119 [EXECUTE_IMMEDIATELY|EXECUTE_UPON_IMMEDIATE_OR_AWAIT]) ==> <status> 00120 set_mode(ASCII_VERBOSE_MODE, [VERBOSE|TERSE|QUERY_MODE]) ==> <status> 00121 set_mode(ASCII_ECHO_MODE, [ON_MODE|OFF_MODE|QUERY_MODE]) ==> <status> 00122 set_mode(POSITION_LIMITS_MODE, [ON_MODE|OFF_MODE|QUERY_MODE]) ==> <status> 00123 set_mode(DEFAULTS,[SAVE_CURRENT_SETTINGS|RESTORE_SAVED_SETTINGS| 00124 RESTORE_FACTORY_SETTINGS]) ==> <status> */ 00125 extern char set_mode(char,char); 00126 00127 00128 /* halt([ALL|PAN|TILT]) ==> <status> */ 00129 extern char halt(char); 00130 00131 00132 /* await_completion() ==> <status> */ 00133 extern char await_completion(void); 00134 00135 00136 /* reset_PTU() ==> <status> */ 00137 extern char reset_ptu(void); 00138 00139 00140 /* firmware_version() ==> <version ID string> */ 00141 extern char* firmware_version(void); 00142 00143 00144 /*** multiple unit support ***/ 00145 typedef unsigned short int UID_fd; 00146 00147 /* in general, should not be used or required... */ 00148 extern char select_host_port(portstream_fd); 00149 00150 /* select_unit(<portstream>, <unit ID>) ==> <status> */ 00151 extern char select_unit(UID_fd); 00152 00153 extern char set_unit_id(UID_fd); // This call should be made only 00154 // when one unit is on the current 00155 // host serial port 00156 00157 00158 /*** asynchronous event status handling functions ***/ 00159 00160 typedef unsigned char (*event_handler_fn_ptr_type) (unsigned char); 00161 00162 extern unsigned char default_async_event_handler(unsigned char); 00163 /* Call this function to set the function handler for asynchronous events. 00164 Defaults to a null function. Example call: 00165 if ( set_async_event_handler( (unsigned char (*) (unsigned char)) default_async_event_handler ) ) 00166 printf("ASYNCH handler installed properly!"); 00167 else printf("ERROR: ASYNCH handler not installed properly!"); 00168 */ 00169 extern unsigned char set_async_event_handler( void (*) (unsigned char) ); 00170 00171 00172 00173 /********************* function call constants ***********************/ 00174 00175 #define PAN 1 00176 #define TILT 2 00177 00178 #define POSITION 1 00179 #define SPEED 2 00180 #define ACCELERATION 3 00181 #define BASE 4 00182 #define UPPER_SPEED_LIMIT 5 00183 #define LOWER_SPEED_LIMIT 6 00184 #define MINIMUM_POSITION 7 00185 #define MAXIMUM_POSITION 8 00186 #define HOLD_POWER_LEVEL 9 00187 #define MOVE_POWER_LEVEL 10 00188 #define RESOLUTION 11 00189 00190 /* specifies changes relative to current position */ 00191 /* (Had to add conditional compilation since WIN32 already defines these values */ 00192 #ifndef RELATIVE 00193 #define RELATIVE 1 00194 #endif 00195 #ifndef ABSOLUTE 00196 #define ABSOLUTE 2 00197 #endif 00198 00199 00200 #define QUERY NULL 00201 00202 /* power modes */ 00203 #define PTU_HI_POWER 1 00204 #define PTU_REG_POWER 2 00205 #define PTU_LOW_POWER 3 00206 #define PTU_OFF_POWER 4 00207 00208 /* PTU mode types */ 00209 #define COMMAND_EXECUTION_MODE 1 00210 #define ASCII_VERBOSE_MODE 2 00211 #define ASCII_ECHO_MODE 3 00212 #define POSITION_LIMITS_MODE 4 00213 #define DEFAULTS 5 00214 #define SPEED_CONTROL_MODE 6 /* v1.9.7 and higher */ 00215 00216 #define EXECUTE_IMMEDIATELY 1 /* default */ 00217 #define EXECUTE_UPON_IMMEDIATE_OR_AWAIT 2 00218 00219 #define VERBOSE 1 /* default */ 00220 #define TERSE 0 00221 00222 #define ON_MODE 1 /* default */ 00223 #define OFF_MODE 0 00224 00225 #define SAVE_CURRENT_SETTINGS 0 00226 #define RESTORE_SAVED_SETTINGS 1 00227 #define RESTORE_FACTORY_SETTINGS 2 00228 00229 #define QUERY_MODE 3 00230 00231 #define ALL 3 00232