00001 #ifndef __CPHIDGET
00002 #define __CPHIDGET
00003
00012 typedef struct _CPhidget *CPhidgetHandle;
00013
00017 typedef struct _CPhidget_Timestamp {
00018 int seconds;
00019 int microseconds;
00020 } CPhidget_Timestamp, *CPhidget_TimestampHandle;
00021
00022 #include "cphidgetattr.h"
00023 #ifndef EXTERNALPROTO
00024
00025 #ifndef _WINDOWS
00026
00029 typedef long long __int64;
00030 typedef unsigned long long __uint64;
00031 #endif
00032
00033 #include "cphidgetconstantsinternal.h"
00034 #include "cphidgetconstants.h"
00035 #include "cthread.h"
00036
00037 typedef enum {EVENTMODE_DATARATE=1, EVENTMODE_CHANGETRIGGER} CPhidget_EventMode;
00038
00039 typedef struct _CPhidget CPhidget;
00040
00041 typedef struct __CPhidgetSocketClient {
00042 int socket;
00043 char *port;
00044 char *address;
00045 void *pdcs;
00046 int status;
00047 CThread_mutex_t lock;
00048 CThread_mutex_t pdc_lock;
00049 CThread auth_thread;
00050 CThread auth_error_thread;
00051
00052 TIME lastHeartbeatTime;
00053 unsigned char waitingForHeartbeat;
00054 int heartbeatCount;
00055 double avgHeartbeatTime;
00056 int avgHeartbeatTimeCount;
00057 int heartbeat_listen_id;
00058 int runningEvent;
00059 } CPhidgetSocketClient, *CPhidgetSocketClientHandle;
00060
00061 typedef struct __CPhidgetSocketClientList
00062 {
00063 struct __CPhidgetSocketClientList *next;
00064 CPhidgetSocketClientHandle client;
00065 } CPhidgetSocketClientList, *CPhidgetSocketClientListHandle;
00066
00067 typedef struct __CPhidgetRemote {
00068 CPhidgetSocketClientHandle server;
00069 char *requested_port;
00070 char *requested_address;
00071 char *requested_serverID;
00072 char *password;
00073 int listen_id;
00074 int mdns;
00075 char *zeroconf_name;
00076 char *zeroconf_domain;
00077 char *zeroconf_type;
00078 char *zeroconf_host;
00079 char *zeroconf_port;
00080 char *zeroconf_ipaddr;
00081 char *zeroconf_server_id;
00082 int zeroconf_interface;
00083 int zeroconf_auth;
00084 void *zeroconf_ref;
00085 int cancelSocket;
00086 CThread_mutex_t zeroconf_ref_lock;
00087 int uniqueConnectionID;
00088 } CPhidgetRemote, *CPhidgetRemoteHandle;
00089
00090 typedef struct __CPhidgetRemoteList
00091 {
00092 struct __CPhidgetRemoteList *next;
00093 CPhidgetRemoteHandle networkInfo;
00094 } CPhidgetRemoteList, *CPhidgetRemoteListHandle;
00095
00096 typedef struct {
00097 CPhidget_DeviceID pdd_sdid;
00098 CPhidget_DeviceClass pdd_did;
00099 int pdd_vid;
00100 int pdd_pid;
00101 int pdd_iid;
00102 CPhidgetAttr pdd_attr;
00103 const char *pdd_name;
00104 } CPhidgetDeviceDef;
00105
00106 typedef struct {
00107 CPhidget_DeviceUID pdd_uid;
00108 CPhidget_DeviceID pdd_id;
00109 int pdd_vlow;
00110 int pdd_vhigh;
00111 } CPhidgetUniqueDeviceDef;
00112
00113 struct _CPhidget {
00114 CPhidgetRemoteHandle networkInfo;
00115 int(CCONV *fptrError)(CPhidgetHandle , void *, int, const char *);
00116 void *fptrErrorptr;
00117 int(CCONV *fptrServerConnect)(CPhidgetHandle , void *);
00118 void *fptrServerConnectptr;
00119 int(CCONV *fptrServerDisconnect)(CPhidgetHandle , void *);
00120 void *fptrServerDisconnectptr;
00121 CThread_mutex_t lock;
00122 int status;
00123 CThread_mutex_t openCloseLock;
00124 int keyCount;
00125 int initKeys;
00126 CThread_mutex_t writelock;
00127 CThread readThread;
00128 CThread writeThread;
00129 HANDLE deviceHandle;
00130 #ifdef _WINDOWS
00131 OVERLAPPED asyncRead;
00132 BOOL readPending;
00133 EVENT closeReadEvent;
00134 OVERLAPPED asyncWrite;
00135 unsigned char inbuf[MAX_IN_PACKET_SIZE+1];
00136 #endif
00137 int specificDevice;
00138 CPhidget_DeviceClass deviceID;
00139 CPhidget_DeviceID deviceIDSpec;
00140 CPhidget_DeviceUID deviceUID;
00141 const CPhidgetDeviceDef *deviceDef;
00142
00143 int deviceVersion;
00144 unsigned short ProductID;
00145 unsigned short VendorID;
00146 int serialNumber;
00147 const char *deviceType;
00148 unsigned short outputReportByteLength;
00149 unsigned short inputReportByteLength;
00150 char label[MAX_LABEL_STORAGE];
00151 char *escapedLabel;
00152 char usbProduct[64];
00153 char firmwareUpgradeName[30];
00154 unsigned char GPPResponse;
00155 int(CCONV *fptrInit)(CPhidgetHandle);
00156 int(CCONV *fptrClear)(CPhidgetHandle);
00157 int(CCONV *fptrEvents)(CPhidgetHandle);
00158 int(CCONV *fptrClose)(CPhidgetHandle);
00159 int(CCONV *fptrFree)(CPhidgetHandle);
00160 int(CCONV *fptrData)(CPhidgetHandle, unsigned char *buffer, int length);
00161 int(CCONV *fptrGetPacket)(CPhidgetHandle, unsigned char *buffer,
00162 unsigned int *length);
00163 unsigned char lastReadPacket[MAX_IN_PACKET_SIZE];
00164 unsigned char awdc_enabled;
00165 void *dnsServiceRef;
00166 void *errEventList;
00167 #if defined(_MACOSX) && !defined(_IPHONE)
00168 io_object_t CPhidgetFHandle;
00169 #else
00170 void *CPhidgetFHandle;
00171 #endif
00172 #ifdef _LINUX
00173 int tryAgainCounter;
00174 #endif
00175 #if !defined(_WINDOWS) || defined(WINCE)
00176 unsigned char interruptOutEndpoint;
00177 #endif
00178 CThread_mutex_t outputLock;
00179 EVENT writeAvailableEvent;
00180 EVENT writtenEvent;
00181 int writeStopFlag;
00182 int(CCONV *fptrAttach)(CPhidgetHandle , void *);
00183 void *fptrAttachptr;
00184 int(CCONV *fptrDetach)(CPhidgetHandle , void *);
00185 void *fptrDetachptr;
00186 CPhidgetAttr attr;
00187 };
00188
00189 struct _CPhidgetList
00190 {
00191 struct _CPhidgetList *next;
00192 CPhidgetHandle phid;
00193 } typedef CPhidgetList, *CPhidgetListHandle;
00194
00195 extern const char LibraryVersion[];
00196 extern const char *Phid_DeviceName[PHIDGET_DEVICE_CLASS_COUNT];
00197 extern const char Phid_UnknownErrorDescription[];
00198 extern const char *Phid_ErrorDescriptions[PHIDGET_ERROR_CODE_COUNT];
00199
00200 extern CPhidgetList *ActiveDevices;
00201 extern CPhidgetList *AttachedDevices;
00202 extern int phidgetLocksInitialized;
00203 extern CThread_mutex_t activeDevicesLock, attachedDevicesLock;
00204
00205 extern const CPhidgetDeviceDef Phid_Device_Def[];
00206 extern const CPhidgetUniqueDeviceDef Phid_Unique_Device_Def[];
00207
00208 void CPhidgetFHandle_free(void *arg);
00209 int CPhidget_read(CPhidgetHandle phid);
00210 int CPhidget_write(CPhidgetHandle phid);
00211 int CPhidget_statusFlagIsSet(int status, int flag);
00212 int CPhidget_setStatusFlag(int *status, int flag, CThread_mutex_t *lock);
00213 int CPhidget_clearStatusFlag(int *status, int flag, CThread_mutex_t *lock);
00214 char translate_bool_to_ascii(char value);
00215 const char *CPhidget_strerror(int error);
00216 void throw_error_event(CPhidgetHandle phid, const char *error, int errcode);
00217 int findActiveDevice(CPhidgetHandle attachedDevice);
00218 int findActiveDevices();
00219 int attachActiveDevice(CPhidgetHandle activeDevice, CPhidgetHandle attachedDevice);
00220 double timestampdiff(CPhidget_Timestamp time1, CPhidget_Timestamp time2);
00221 double timeSince(TIME *start);
00222 void setTimeNow(TIME *now);
00223 int encodeLabelString(const char *buffer, char *out, int *outLen);
00224 int decodeLabelString(char *labelBuf, char *out, int serialNumber);
00225 int UTF16toUTF8(char *in, int inBytes, char *out);
00226 int labelHasWrapError(int serialNumber, char *labelBuf);
00227 void CPhidgetErrorEvent_free(void *arg);
00228 CPhidget_DeviceUID CPhidget_getUID(CPhidget_DeviceID id, int version);
00229 int deviceSupportsGeneralUSBProtocol(CPhidgetHandle phid);
00230
00231 PHIDGET21_API int CCONV CPhidget_areEqual(void *arg1, void *arg2);
00232 PHIDGET21_API int CCONV CPhidget_areExtraEqual(void *arg1, void *arg2);
00233 PHIDGET21_API int CCONV CPhidgetHandle_areEqual(void *arg1, void *arg2);
00234 PHIDGET21_API void CCONV CPhidget_free(void *arg);
00235 PHIDGET21_API int CCONV phidget_type_to_id(const char *Type);
00236 PHIDGET21_API int CCONV CPhidget_create(CPhidgetHandle *phid);
00237
00238 PHIDGET21_API int CCONV CPhidget_calibrate_gainoffset(CPhidgetHandle phid, int index, unsigned short offset, unsigned long gain);
00239
00240
00241
00242
00243 #define PHID_USB_GENERAL_PACKET_FLAG 0x80
00244
00245
00246 #define PHID_USB_GENERAL_PACKET_SUCCESS 0x00
00247 #define PHID_USB_GENERAL_PACKET_FAIL 0x40
00248
00249
00250 #define PHID_USB_GENERAL_PACKET_IGNORE 0x00
00251 #define PHID_USB_GENERAL_PACKET_REBOOT_FIRMWARE_UPGRADE 0x01
00252 #define PHID_USB_GENERAL_PACKET_REBOOT_ISP 0x02
00253
00254 #define PHID_USB_GENERAL_PACKET_CONTINUATION 0x03
00255 #define PHID_USB_GENERAL_PACKET_ZERO_CONFIG 0x04
00256 #define PHID_USB_GENERAL_PACKET_WRITE_FLASH 0x05
00257 #define PHID_USB_GENERAL_PACKET_FIRMWARE_UPGRADE_WRITE_SECTOR 0x06
00258 #define PHID_USB_GENERAL_PACKET_SET_DS_TABLE 0x07
00259 #define PHID_USB_GENERAL_PACKET_SET_DW_TABLE 0x08
00260 #define PHID_USB_GENERAL_PACKET_FIRMWARE_UPGRADE_ERASE 0x09
00261 #define PHID_USB_GENERAL_PACKET_ERASE_CONFIG 0x0A
00262
00263 #endif
00264
00265 #if !defined(EXTERNALPROTO) || defined(DEBUG)
00266 PHIDGET21_API int CCONV CPhidgetGPP_reboot_firmwareUpgrade(CPhidgetHandle phid);
00267 PHIDGET21_API int CCONV CPhidgetGPP_reboot_ISP(CPhidgetHandle phid);
00268 PHIDGET21_API int CCONV CPhidgetGPP_setLabel(CPhidgetHandle phid, const char *buffer);
00269 PHIDGET21_API int CCONV CPhidgetGPP_setDeviceSpecificConfigTable(CPhidgetHandle phid, unsigned char *data, int length, int index);
00270 PHIDGET21_API int CCONV CPhidgetGPP_setDeviceWideConfigTable(CPhidgetHandle phid, unsigned char *data, int length, int index);
00271 PHIDGET21_API int CCONV CPhidgetGPP_upgradeFirmware(CPhidgetHandle phid, unsigned char *data, int length);
00272 PHIDGET21_API int CCONV CPhidgetGPP_eraseFirmware(CPhidgetHandle phid);
00273 PHIDGET21_API int CCONV CPhidgetGPP_eraseConfig(CPhidgetHandle phid);
00274 PHIDGET21_API int CCONV CPhidgetGPP_writeFlash(CPhidgetHandle phid);
00275 #endif
00276
00277 #include "cphidgetmacros.h"
00278
00284 PHIDGET21_API int CCONV CPhidget_open(CPhidgetHandle phid, int serialNumber);
00290 PHIDGET21_API int CCONV CPhidget_openLabel(CPhidgetHandle phid, const char *label);
00295 PHIDGET21_API int CCONV CPhidget_close(CPhidgetHandle phid);
00300 PHIDGET21_API int CCONV CPhidget_delete(CPhidgetHandle phid);
00307 PHIDGET21_API int CCONV CPhidget_set_OnDetach_Handler(CPhidgetHandle phid, int(CCONV *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
00314 PHIDGET21_API int CCONV CPhidget_set_OnAttach_Handler(CPhidgetHandle phid, int(CCONV *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
00321 PHIDGET21_API int CCONV CPhidget_set_OnServerConnect_Handler(CPhidgetHandle phid, int (CCONV *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
00328 PHIDGET21_API int CCONV CPhidget_set_OnServerDisconnect_Handler(CPhidgetHandle phid, int (CCONV *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
00335 PHIDGET21_API int CCONV CPhidget_set_OnError_Handler(CPhidgetHandle phid, int(CCONV *fptr)(CPhidgetHandle phid, void *userPtr, int errorCode, const char *errorString), void *userPtr);
00341 PHIDGET21_API int CCONV CPhidget_getDeviceName(CPhidgetHandle phid, const char **deviceName);
00347 PHIDGET21_API int CCONV CPhidget_getSerialNumber(CPhidgetHandle phid, int *serialNumber);
00353 PHIDGET21_API int CCONV CPhidget_getDeviceVersion(CPhidgetHandle phid, int *deviceVersion);
00359 PHIDGET21_API int CCONV CPhidget_getDeviceStatus(CPhidgetHandle phid, int *deviceStatus);
00364 PHIDGET21_API int CCONV CPhidget_getLibraryVersion(const char **libraryVersion);
00370 PHIDGET21_API int CCONV CPhidget_getDeviceType(CPhidgetHandle phid, const char **deviceType);
00376 PHIDGET21_API int CCONV CPhidget_getDeviceLabel(CPhidgetHandle phid, const char **deviceLabel);
00382 PHIDGET21_API int CCONV CPhidget_setDeviceLabel(CPhidgetHandle phid, const char *deviceLabel);
00388 PHIDGET21_API int CCONV CPhidget_getErrorDescription(int errorCode, const char **errorString);
00394 PHIDGET21_API int CCONV CPhidget_waitForAttachment(CPhidgetHandle phid, int milliseconds);
00400 PHIDGET21_API int CCONV CPhidget_getServerID(CPhidgetHandle phid, const char **serverID);
00407 PHIDGET21_API int CCONV CPhidget_getServerAddress(CPhidgetHandle phid, const char **address, int *port);
00413 PHIDGET21_API int CCONV CPhidget_getServerStatus(CPhidgetHandle phid, int *serverStatus);
00419 PHIDGET21_API int CCONV CPhidget_getDeviceID(CPhidgetHandle phid, CPhidget_DeviceID *deviceID);
00425 PHIDGET21_API int CCONV CPhidget_getDeviceClass(CPhidgetHandle phid, CPhidget_DeviceClass *deviceClass);
00426
00427 #ifdef _MACOSX
00428
00435 PHIDGET21_API int CCONV CPhidget_set_OnWillSleep_Handler(int(CCONV *fptr)(void *userPtr), void *userPtr);
00443 PHIDGET21_API int CCONV CPhidget_set_OnWakeup_Handler(int(CCONV *fptr)(void *userPtr), void *userPtr);
00444 #endif
00445
00448 #endif