cphidgetgeneric.c
Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include "cphidgetgeneric.h"
00003 #include "cusb.h"
00004 #include "csocket.h"
00005 #include "cthread.h"
00006 
00007 // === Internal Functions === //
00008 
00009 //clearVars - sets all device variables to unknown state
00010 CPHIDGETCLEARVARS(Generic)
00011         ZEROMEM(phid->lastPacket, MAX_IN_PACKET_SIZE);
00012 
00013         return EPHIDGET_OK;
00014 }
00015 
00016 //initAfterOpen - sets up the initial state of an object, reading in packets from the device if needed
00017 //                                used during attach initialization - on every attach
00018 CPHIDGETINIT(Generic)
00019         TESTPTR(phid);
00020 
00021         //Make sure no old writes are still pending
00022         phid->outputPacketLen = 0;
00023 
00024         ZEROMEM(phid->lastPacket, MAX_IN_PACKET_SIZE);
00025 
00026         phid->out = phid->phid.outputReportByteLength;
00027         phid->in = phid->phid.inputReportByteLength;
00028 
00029         return EPHIDGET_OK;
00030 }
00031 
00032 //dataInput - parses device packets
00033 CPHIDGETDATA(Generic)
00034         if (length<0) return EPHIDGET_INVALIDARG;
00035         TESTPTR(phid);
00036         TESTPTR(buffer);
00037 
00038         FIRE(Packet, buffer, length);
00039         memcpy(phid->lastPacket, buffer, length);
00040 
00041         return EPHIDGET_OK;
00042 }
00043 
00044 //eventsAfterOpen - sends out an event for all valid data, used during attach initialization
00045 CPHIDGETINITEVENTS(Generic)
00046         TESTPTR(phid);
00047         return EPHIDGET_OK;
00048 }
00049 
00050 //getPacket - used by write thread to get the next packet to send to device
00051 CGETPACKET_BUF(Generic)
00052 
00053 //sendpacket - sends a packet to the device asynchronously, blocking if the 1-packet queue is full
00054 CSENDPACKET_BUF(Generic)
00055 
00056 // === Exported Functions === //
00057 
00058 //create and initialize a device structure
00059 CCREATE(Generic, PHIDCLASS_GENERIC)
00060 
00061 //event setup functions
00062 CFHANDLE(Generic, Packet,const unsigned char *, int)
00063 
00064 CGET(Generic,INPacketLength,int)
00065         TESTPTRS(phid,pVal)     
00066         TESTDEVICETYPE(PHIDCLASS_GENERIC)
00067         TESTATTACHED
00068         MASGN(in)
00069 }
00070 
00071 CGET(Generic,OUTPacketLength,int)
00072         TESTPTRS(phid,pVal)     
00073         TESTDEVICETYPE(PHIDCLASS_GENERIC)
00074         TESTATTACHED
00075         MASGN(out)
00076 }
00077 
00078 int CCONV
00079 CPhidgetGeneric_setPacket(CPhidgetGenericHandle phid, unsigned char *packet, int length)
00080 {
00081         int ret = 0;
00082 
00083         TESTPTR(phid)
00084         TESTDEVICETYPE(PHIDCLASS_GENERIC)
00085         TESTATTACHED
00086 
00087         if(length!=phid->out)
00088                 return EPHIDGET_INVALIDARG;
00089 
00090         CThread_mutex_lock(&phid->phid.writelock);
00091         ret = CPhidgetGeneric_sendpacket(phid, packet);
00092         CThread_mutex_unlock(&phid->phid.writelock);
00093         if(ret) return ret;
00094 
00095         return EPHIDGET_OK;
00096 }
00097 
00098 int CCONV
00099 CPhidgetGeneric_getLastPacket(CPhidgetGenericHandle phid, const unsigned char **packet, int *length)
00100 {
00101         TESTPTRS(phid, packet)
00102         TESTPTR(length)
00103         TESTDEVICETYPE(PHIDCLASS_GENERIC)
00104         TESTATTACHED
00105 
00106         *packet = phid->lastPacket;
00107         *length = phid->in;
00108         return EPHIDGET_OK;
00109 }


pedal_monitor
Author(s): Pedro Mendes
autogenerated on Fri Jun 6 2014 18:37:20