306 lines
8.4 KiB
C++
306 lines
8.4 KiB
C++
// protocol for control SevenOcean's Machine
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
#ifndef AFX_SO7_Proto_Aux_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
|
#define AFX_SO7_Proto_Aux_H__B422904C_2CEB_495B_B7BD_B45AB30286DD__INCLUDED_
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
#include "..\Tools\UsbUtility\logger.h"
|
|
#include "CMD_H.h"
|
|
#include "..\..\..\..\..\ThirdParty\UsbSupport\LibUsb_Win\Include\lusb0_usb.h"
|
|
#include "..\Tools\UsbUtility\MachineInterfaceDll\MachineInterfaceDll.h"
|
|
|
|
|
|
#define MAX_BUFF_SIZE 0x200
|
|
#define USB_R_SEQ_NUMBER 1
|
|
#define RSPEEDGEAR 1
|
|
#define ONE_R_PULSE 590000
|
|
#define TYPER1 0
|
|
#define TYPER2 1
|
|
|
|
#define USB_ENDPOINT_TYPE_CONTROL 0
|
|
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
|
|
#define USB_ENDPOINT_TYPE_BULK 2
|
|
#define USB_ENDPOINT_TYPE_INTERRUPT 3
|
|
|
|
#define USB_DEVICE_DESCRIPTOR_TYPE 1
|
|
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
|
|
|
|
#define THREAD_RUNNING_STATE1 0
|
|
#define THREAD_RUNNING_STATE2 2
|
|
#define THREAD_PAUSED 1
|
|
#define THREAD_EXIT -1
|
|
|
|
// Device configuration and interface id.
|
|
#define SO7_USB_CONFIG 1
|
|
#define SO7_USB_INTF 0
|
|
|
|
#define EP_S07_01 0x01
|
|
#define EP_S07_02 0x02
|
|
#define EP_S07_03 0x03
|
|
#define EP_S07_81 0x81
|
|
#define EP_S07_82 0x82
|
|
#define EP_S07_84 0x84
|
|
|
|
#define EP_01_CMD_IDX 0 // index to usb buffers
|
|
#define EP_81_DATA_IDX 1 //
|
|
#define EP_02_CMD_IDX 2 //
|
|
#define EP_82_DATA_IDX 3 //
|
|
#define EP_03_CMD_IDX 4 //
|
|
#define EP_84_DATA_IDX 5 //
|
|
|
|
#define lEPSIZE 6
|
|
#define MAXRINGS 5 // for MicroVu Vertex 220
|
|
#define MAXSEGS 8
|
|
|
|
#define TWO_RINGS 2
|
|
#define EIGHT_SEGS 8
|
|
#define FIVE_RINGS 5
|
|
|
|
enum EMACHINERTYPE
|
|
{
|
|
MACHINE_SO7_R_CONTROLLER,
|
|
MACHINE_METRONICS_CONTROLLER_R,
|
|
MACHINE_TOTAL_R=255
|
|
};
|
|
enum EFirmwareRVer
|
|
{
|
|
FirmwareVer_3_X_R=0,
|
|
FirmwareVer_6_X_R,
|
|
FirmwareVer_Total_R
|
|
};
|
|
|
|
#pragma pack(push)
|
|
#pragma pack(1)
|
|
//****************************************************************************************************
|
|
// Set the _status to Idle after reply data has been received.
|
|
// How to recover? In order to send data, _status must be Idle. If the system is not available
|
|
// for 1 second, assume something wrong and treat it as "TimeOut".
|
|
// Another way to do this is to lock this structure is to use a mutex to ensure single-threaded
|
|
// access.
|
|
//****************************************************************************************************
|
|
//====================================================================================================
|
|
|
|
typedef struct s_so7_r_axis // axis parameters
|
|
{
|
|
char _Move_Speed_Gear;
|
|
char _MoveTo_Speed_Gear;
|
|
union
|
|
{
|
|
long _long_;
|
|
char _char_[4];
|
|
}_pos_fixed;
|
|
union
|
|
{
|
|
long _long_;
|
|
char _char_[4];
|
|
}_scale_pos;
|
|
union
|
|
{
|
|
long _long_;
|
|
char _char_[4];
|
|
}_ZSignal_pos;
|
|
double _d_cur_pos_;
|
|
long _scale_probe;
|
|
double _dSet_Zero_Pos;
|
|
long _lSet_Zero_Pos;
|
|
} SO7RAXIS;
|
|
|
|
struct s_so7_r_axis_config // axis configuration
|
|
{
|
|
double _motor_precision;//set precision
|
|
double _motor_wheelbase;//set wheelbase
|
|
char _speed_base[5];
|
|
char _speed_fresh[5];
|
|
char _speed_start[5];
|
|
char _speed_max[5];
|
|
double _speed_slow_dis[5];
|
|
|
|
double _MoveToSpeed[2];
|
|
double _MotionSpeedScale;
|
|
|
|
long _scale_range;
|
|
double _neg_working_limit;
|
|
double _pos_working_limit;
|
|
double _scale_resolution;
|
|
bool _bhomed;
|
|
};
|
|
|
|
struct s_so7_r_machine_interface_config
|
|
{
|
|
BOOL _EnCloseLoop;
|
|
int _RetryTimes;
|
|
double _ShiftPositionR;
|
|
char GetInterruptMsgMethod;
|
|
INT m_WriteDataSleepTime;
|
|
INT m_AccuraErrPulseR;
|
|
INT m_EQUIDIS_R;
|
|
INT m_SDK3000_CntThreadSleepVal;
|
|
INT m_SV4000E_DenoisePara[4];
|
|
INT m_MachineType;
|
|
INT m_VideoCardType;
|
|
};
|
|
|
|
//======================
|
|
typedef struct s_so7_r
|
|
{
|
|
bool bFast;
|
|
long from;
|
|
long to;
|
|
long speed;
|
|
long acc;
|
|
long dec;
|
|
double dFromMM;
|
|
double dToMM;
|
|
} SO7RAXISMOVE;
|
|
//--------------------------------------------------------------------
|
|
//
|
|
//--------------------------------------------------------------------
|
|
struct struct_so7_r_machine
|
|
{ // g_machine structure
|
|
struct s_machine_r_config
|
|
{
|
|
double _dRSpeed[2];
|
|
|
|
struct s_so7_r_axis_config r_axis;
|
|
struct s_so7_r_machine_interface_config motion;
|
|
} s_machine_r_config;
|
|
|
|
struct s_rstatus
|
|
{
|
|
bool _homed;
|
|
bool _machine_running;
|
|
bool _bRMoving;
|
|
char _bIsZMMotionFinished;
|
|
bool _bRIdle;
|
|
} s_rstatus;
|
|
|
|
char ADC_Number;
|
|
int ADC_Value;
|
|
char Sys_Reset_Flag;
|
|
char cVerNumber;
|
|
char InterruptFlag[2];
|
|
char FPGAData;
|
|
char InPortStatus;
|
|
int _motor_pulse_num;
|
|
char FirmwareInfo[10];
|
|
int FirmwareVer;
|
|
char GetInterruptMsg[20][2];
|
|
BOOL IsOffline;
|
|
BOOL IsSupportReadInterrputMsg;
|
|
double dRotaryCirclDis;
|
|
char SEQ_NUMBER;
|
|
struct s_so7_r_axis r;
|
|
struct s_so7_r_axis r1;
|
|
};
|
|
|
|
#define SEVENOCEAN_VID 0x4532
|
|
#define SEVENOCEAN_PID 0x5567
|
|
//****************************************************************************************************
|
|
// Binary SevenOcean command structure, out going
|
|
//
|
|
//****************************************************************************************************
|
|
#define pSO7_CMD_02 ((s_SO7_CMD_BUFF_02 *) ep_buff[EP_02_CMD_IDX]._buffer)
|
|
|
|
struct s_SO7_R_CMD_BUFF_02
|
|
{
|
|
UCHAR uCmdByte;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
BYTE uSubCmdByte;
|
|
char data[12];
|
|
}s_SO7_CMD_MOVE_TO_XYZ;
|
|
struct
|
|
{
|
|
BYTE uSubCmdByte;
|
|
char data[12];
|
|
}s_SO7_CMD_MOVETOXYZV;
|
|
struct
|
|
{
|
|
BYTE uSubCmdByte;
|
|
BYTE uStartCmdByte;
|
|
char _bottom_light;
|
|
char _top_light;
|
|
char _ring_light;
|
|
char _coaxial_light;
|
|
char _spare_light1;
|
|
char _outer_ring_light_switch;
|
|
char _inner_ring_light_switch;
|
|
BYTE uEndCmdByte;
|
|
}s_SO7_CMD_SET_LIGHT;
|
|
};
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
//======================
|
|
struct struct_so7_r_ep_buff
|
|
{
|
|
int _ep;
|
|
BYTE _save_send_cmd;
|
|
BYTE _save_send_cmd0;
|
|
BYTE _save_send_cmd1;
|
|
char *_buffer; // MAX_BUFF_SIZE
|
|
int _size;
|
|
void *_async_context;
|
|
BOOL _hProtoPending;
|
|
HANDLE _event;
|
|
};
|
|
|
|
//======================================================================================
|
|
class CSO7_Proto_Aux
|
|
{
|
|
public:
|
|
// EP 81/82 channel threads.
|
|
static int g_hEP8x_Thread_State;
|
|
static unsigned __stdcall g_EP8x_Thread(LPVOID pThis);
|
|
static HANDLE g_hEP8x_Thread_Id;
|
|
|
|
// EP 02channel threads.
|
|
static int g_hEP02_Thread_State;
|
|
static unsigned __stdcall g_EP02_Thread(LPVOID pThis);
|
|
static HANDLE g_hEP02_Thread_Id;
|
|
static HANDLE g_hEP02_Serial_Mutex; // EP02
|
|
|
|
static HANDLE g_hHomedEvent;
|
|
|
|
static struct_so7_r_ep_buff ep_buff[lEPSIZE];
|
|
static struct_so7_r_machine g_machine;
|
|
|
|
static CLogger* g_pLogger1;
|
|
static usb_dev_handle *g_dev;
|
|
bool m_bHomingActive;
|
|
|
|
//
|
|
CSO7_Proto_Aux();
|
|
virtual ~CSO7_Proto_Aux();
|
|
|
|
// Global Structures
|
|
SSI_STATUS_MOTION Init_SO7Usb();
|
|
SSI_STATUS_MOTION Exit_SO7Usb();
|
|
|
|
usb_dev_handle* _open_usb_dev(unsigned short sSeqNumber);
|
|
int Get_R_SeqNumber(usb_dev_handle *udev);
|
|
SSI_STATUS_MOTION _send_usb_cmd(int iEP_Base);
|
|
SSI_STATUS_MOTION _write_usb_data_only(int iEP_Base);
|
|
SSI_STATUS_MOTION _read_data_8x(int iEP_Base);
|
|
static void _process_rcv_transfer_data(int iEP);
|
|
SSI_STATUS_MOTION _do_single_threaded_usb_comm(int iEP);
|
|
|
|
static SSI_STATUS_MOTION _process_SO7_CMD_READ_AXIS_R();
|
|
static SSI_STATUS_MOTION _process_SO7_CMD_READ_ZSIGNAL_POS_R();
|
|
SSI_STATUS_MOTION _send_cmd_SO7_CMD_RESET_R(int iType);
|
|
SSI_STATUS_MOTION _send_cmd_SO7_CMD_MOVE_R(int iType, int iMoveAngle);
|
|
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_AXIS_R();
|
|
SSI_STATUS_MOTION _send_cmd_SO7_CMD_READ_ZSIGNAL_POS_R(int iType);
|
|
long GetRCurrentPosition(int iType);
|
|
SSI_STATUS_MOTION _send_cmd_SO7_CMD_STOP_R(int iType);
|
|
SSI_STATUS_MOTION _send_cmd_SO7_CMD_SET_SEQ_NUMBER();
|
|
};
|
|
#endif
|