?? common.h
字號:
//#ifndef __COMMON_H_DEF///#define __COMMON_H_DEF#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <termios.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/socket.h>#include <time.h>#include <sys/select.h>#include <sys/wait.h>#include <netinet/in.h>#include <netdb.h>#include "StructDef.h"//------------------------------------------------------------------------------------------static unsigned char DEBUG;//Debug State//設置調試狀態void SetDebug(unsigned char Debug);//返回設備可讀數據長度int GetCommDataLength(int Device_Handle);int AutoDetect(int Device_Handle);int ShortBlockDetect(int Device_Handle);void delay(unsigned long dly);//監聽所有設備的讀信息和錯誤信息void ListenAllDeviceOnRead_Error();//void AddDeviceToListenQueue(int Device);//void DeleteDeviceFromListenQueue(int Device);//void RAADeviceToListenQueue();void Initialize();void InitializeAllDevice();unsigned int FormatIntToInter(unsigned int arg);unsigned int FormatInterToInt(unsigned int arg);unsigned char FormatCharToInter(unsigned char arg);///---------------------------------------------------------------------------------------// 網絡部分 全局變量定義#define BEGIN {#define END }break;#define MAXCONNECTED 3#define MAXDATASIZE 50#define LISTENPORT 4050//---------------------------------------------------------------//Socket命令定義#define COMM_SET 0xf700 //設置命令#define COMM_GET 0xf800 //讀取命令#define COMM_REP 0xf900 //上報數據#define SIN_CCLOSE 0xe001 //關閉連接#define SIN_REBOOT 0xe002 //重新啟動#define SIN_CLOSE 0xe003 //關閉系統#define STA_DEBUG 0x0010 //調試狀態#define STA_ERROR 0x0012 //錯誤狀態#define WOR_PROF 0x0020 //工作-值班人員#define WOR_COMDEV 0x0021 //工作-串口設置#define WOR_STAT 0x0022 //工作-狀態#define WOR_TIME 0x0023#define WOR_NMODE 0x0024#define WOR_NEMODE 0x0025#define WOR_NRWMODE 0x0026#define WOR_RWMODE 0x0027 #define REP_CCARD 0x0030 //上報-剩余卡數#define REP_CBADCERD 0x0031 //上報-煥卡數#define REP_PUBCARD 0x0032 //上報-成功發行一張卡#define REP_PUBBAD 0x0033 //上報-卡發行失敗#define REP_OVERONE 0x0034 #define QUR_ALL 0x0040//----------------------------------------------------------------------------//全局變量int Connects;static int ListenPort; //Socket Listen Port Handlestruct sockaddr_in Listen_Addr; //Socket Listen Structpthread_t tid;struct __SOCKETCLIENT{ int Socket_Handle; struct sockaddr_in Socket_Info;}SocketConnect; //Client Socket Connects Managerstruct __SOCKETCOMMAND{ unsigned int Command; unsigned int Content; unsigned int DataLength; unsigned char Buffer[128];}SocketCommand; //Socket Command Bufferint SocketReadLength;static unsigned char WMode;static unsigned char RWMode;//----------------------------------------------------------------------------//函數定義int CreateSocket();int ListenProcess();int ProcessReceive(int Socket_Handle);void PrintToNetwork(unsigned char *buff);//--------------------------------------------------------------------------------------// 串口部分 全局變量定義//--------------------------------------------------------------------------------//設備類型定義#define IOCONTROL 0xf100 //IO控制器#define CARDRWUP 0xf201 //上讀寫器#define CARDRWDOWN 0xf202 //下讀寫器#define CARDMALUP 0xf301 //上左卡機#define CARDMARUP 0xf302 //上右卡機#define CARDMALDOWN 0xf303 //下左卡機#define CARDMARDOWN 0xf304 //下右卡機#define OUTCARD 0xf400 //出卡器//IO口子設備定義#define IO_AHRAILOD 0x08 //自動欄桿機輸出#define IO_AHRAILOU 0x10 //自動欄桿機輸出#define IO_ALERTO 0x20 //報警器#define IO_LEAPB 0x40 //交通燈#define IO_LEAPA 0x80 //雨棚燈#define IO_HHRAIL 0x04 //手動欄桿#define IO_ALERTI 0x08#define IO_PCOIL 0x10 //發卡線圈#define IO_ACOIL 0x20 //欄桿或抓拍線圈#define IO_AHRAILIU 0x40 //自動欄桿機輸入#define IO_AHRAILID 0x80 //自動欄桿機輸入#define TERMINAL 0xf100//--------------------------------------------------------------------------//串口地址#define COM1_BASE 0x10000140#define COM2_BASE 0xc0000000#define COM3_BASE 0xc0000100#define COM4_BASE 0xc0000200#define COM5_BASE 0xc0000300#define RDTS_VASE(base) base+4#define COM0_MCR 0x10000104 #define COM1_MCR 0x10000140#define COM2_MCR 0xc0000004#define COM3_MCR 0xc0000104#define COM4_MCR 0xc0000204#define COM5_MCR 0xc0000304#define DTR 0x01#define P6003H 0x60#define P6003E 0x03//------------------------------------------------------------------------------//全局變量static int HS0; //Com1static int HS1;static int HS2;static int HS3;static int HS4;static int HS5; //Com6char CancelRead; //初始化為false 如果為true 退出讀循環static unsigned int BCC;//Bad Card Countstatic unsigned char ReadBuffer[256]; //Com Device Read Bufferstatic unsigned char WriteBuffer[256]; //Com Device Write Bufferstatic unsigned char DataBuffer[256]; // 經過協議轉換后的數據unsigned char Command; //接收到的命令int Result; //設備的返回值int Result6003; int inBusy; //發卡忙標志 0x55aa忙 unsigned int DeviceWord; //子設備狀態字unsigned char DataType; //接收設備類型unsigned char DataLength; //轉換后的數據長度unsigned char RDataLength; //接收到的數據長度unsigned char WDataLength; //寫入串口的數據長度CardPublish PCMachine[4];DevicesStatus AllDevices;void (*DeviceLayerCall)(pDataReport,unsigned char); //指向設備抽象層的數據報接收函數指針void (*DataLayerCall)(pDataReport,unsigned char); //指向數據抽象層的數據報接收函數指針//----------------------------------------------------------------------------//函數定義//初始化串口int InitilizeComm(int comPort,int Baud,int DataLength,int StopLength,int Partery);//讀串口int ReadFromComm(int comPort,int Length);int ReadFromComm6003(int comPort,int Length);//寫串口int WriteToComm(int comPort,int Length);int WriteToComm6003(int comPort,int Length);//協議轉換int CanverContentToBSYN(int comPort);int CanverContentTo6003(int comPort);int CanverBSYNToContent(int comPort);int Canver6003ToContent(int comPort);//數據報發送和接收int PopDataReport();void PushDataReport(pDataReport pdr,unsigned char Debug);void SET_RTS(int comPort);void CLR_RTS(int comPort);int GET_RTS(int comPort);void SET_DTR(int comPort);void CLR_DTR(int comPort);int GET_DTR(int comPort);int ReadyCard(int DeviceIndex);int TestCard(unsigned char DeviceID);int OutCard(int State,unsigned char DeviceID);int VcoterOK(unsigned char State);int NeedSwitchMAPC(unsigned char State,int CurrentDevice);int InitCKKZ();int InitMAPC();int InitIOCO();int Leap(unsigned char chCommand,unsigned char chLeap);int ExecReadyCard(int DeviceIndex);int ExecCKKZFunc(unsigned char cm);int ExecIOCOFunc(unsigned char cm);int ExecCARWFunc(unsigned char cm,unsigned char DeviceID);int PublishCard();int MainInitialize();//#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -