CDEVCOM.H

//=========================================================================== 
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
// Copyright (c) 1992 - 1997 Microsoft Corporation. All Rights Reserved.
//
//===========================================================================
//
//filename: cdevcom.h
//
//header for devcom.cpp - External Device Communications Class
//for an SVO-type RS-422 Controlled Tape Machine and
//SVBK-type RS-232 Controlled machines
//
//
#ifndef CDEVCOM_H
#defineCDEVCOM_H1

//----------------------------------------------------------
//
// Structures and definitions for this implementation
//
// communications and low-level protocol defines
// device ports
#define DEV_PORT_SIM1
#define DEV_PORT_COM12// standard serial ports
#define DEV_PORT_COM23
#define DEV_PORT_COM34
#define DEV_PORT_COM45
#define DEV_PORT_DIAQ6// Diaquest driver
#define DEV_PORT_ARTI7// ARTI driver
#define DEV_PORT_13948// IEEE 1394 Bus
#define DEV_PORT_USB9// Universal Serial Bus
#define DEV_PORT_MINDEV_PORT_SIM
#define DEV_PORT_MAXDEV_PORT_USB

// machine commands - ****The order of these must match the order
// of the commands in the command list in devcom.cpp!!!
#define PLAY0
#define STOP1
#define READ_TC2
#define TIMER_MODE_SELECT_LTC 3
#define REWIND4
#define FREEZE_ON 5
#define FREEZE_OFF 6
#define STANDBY_OFF 7
#define STANDBY_ON 8
#define DEVICE_TYPE_REQUEST 9
#define REQUEST_STATUS 10
#define EJECT 11
#define LOCAL_ON 12
#define LOCAL_OFF 13
#define FFWD 14
#define RECORD 15
#define DEVICE_CLEAR 16

// error values
#define DEV_COMM_ERR_COMMAND_NOT_SENT_YET1L
#define DEV_COMM_ERR_QUEUE_OVERFLOW2L
#define DEV_COMM_ERR_COMMUNICATION_ERROR3L
#define DEV_COMM_ERR_RESPONSE_MISMATCH4L
#define DEV_COMM_ERR_RESPONSE_TIMEOUT5L
#define DEV_COMM_ERR_RESPONSE_CHECKSUM6L
#define DEV_COMM_ERR_COMMAND_MISSING7L
#define DEV_COMM_ERR_RESPONSE_OVERFLOW8L
#define DEV_COMM_ERR_RESPONSE_MISSING9L
#define DEV_COMM_ERR_COMMAND_NOT_SUPPORTED10L

// low level machine status structure filled in after
// REQUEST_STATUS command from above. This structure would
// grow in a full implementation
typedef struct tagVCRSTATUS{
BOOL bCassetteOut;// OATRUE means no cassette
BOOL bLocal;// OATRUE means front panel switch in local
} VCRSTATUS;

typedef VCRSTATUS far *PVCRSTATUS;

typedef struct tagCOMMANDOBJECT {
int Command;
int Cookie;
DWORD Timestamp;
} COMMANDOBJECT;
typedef COMMANDOBJECT far *PCOMMANDOBJECT;

typedef struct tagRESPONSEOBJECT {
int Cookie;
int ResponseByteCount;
TCHAR buf[16];
} RESPONSEOBJECT;
typedef RESPONSEOBJECT far *PRESPONSEOBJECT;

//----------------------------------------------------------
//
//The communications object
//
//----------------------------------------------------------
class CDevCom : public CCritSec{
public:
// constructor
CDevCom(CBaseFilter *pFilter, HRESULT *phr);

~CDevCom();

// all of these methods return 0 for success
// Initialize Device Port accepts the following:
//DEV_PORT_COM1 | DEV_PORT_COM2 |DEV_PORT_COM3 |
//DEV_PORT_COM3 | DEV_PORT_DIAQ | DEV_PORT_ARTI etc.
DWORD OpenDevPort(int port);

// Close Device Port
DWORD CloseDevPort(void);

// Flush Device Response Buffer
DWORD FlushDevResponseBuffer(void);

// Send command to device.
DWORD SendDevCmd(int, int *);

// Read response from device - accepts pointer to response buffer
// Must pass cookie in to get proper command. If command hasn't
// actually been sent, method returns with and error value
DWORD GetDevResponse(TCHAR *, int);
// this one sits around (by sleeping) until either the proper
// response comes back, a timeout occurs, or an error happens.
DWORD Wait4DevResponse(TCHAR *, int);

// convert response to device type request to a string
void ProcessDeviceTypeResponse( TCHAR *bufin, TCHAR *bufout);

// convert status request response to something meaningful
BOOL ProcessDeviceStatusResponse( TCHAR *bufin, PVCRSTATUS pStatus );

// convert raw machine timecode to something usable
DWORD ProcessVcrTC(TCHAR * RawTC, DWORD * pdwFCM, long * ptimecode,
long * puserbits);

protected:
CCritSec *m_pCritSec;// Object we use for locking

private:
CTimecode *m_pTimecode;
CBaseFilter *m_pFilter;// our filter

static HANDLEm_hDevPort;// handle of opened comm port
static TCHAR *m_pcDevPort;// name of opened comm port
static BYTEm_bLastCmd;
static BYTEm_LastMotionCmd;// need this for effective
// simulation
static DCB m_dcb;// initialize this with
// GetCommState
static int m_PendingResponseCnt;// for synchronizing responses
static BOOLm_bSimulateHardware;// TRUE if no VCR connected
static COMMTIMEOUTS m_ctmoTimeout;// communications timeout structure
static COMSTATm_csCommStat;// communications status structure
static intm_CurCmdCookie;// used for command queueing
static intm_LastSentCmdCookie;// so we know immediately which
// command was just sent

DWORD GetSimulatedResponse( TCHAR *buf );// for the big fake out
BOOL m_isMotionCmd( BYTE Cmd );
PCOMMANDOBJECT AddCommand(int Cmd, int Cookie);
void RemoveCommand(PCOMMANDOBJECT pCmd);
DWORD ReallySendDevCmd(int, int);
DWORD ReallyGetDevResponse( TCHAR *buf, int bytecnt );
BOOL TestResponse( TCHAR *buf, int Count );
DWORD BufferResponse(void);
DWORD GetBufferedResponse( TCHAR *buf, int Cookie);
BOOL IsResponseBuffered( int Cookie, int *index);
void GetSimulatedTimecode(TCHAR * timecode, long framecount);
};

#endif// #ifndef CDEVCOM_H
// eof cdevcom.h