📄 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>//#define __DEBUG__#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 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;int SocketReadLength;static unsigned char WMode;static unsigned char RWMode;static unsigned char MLoop;//----------------------------------------------------------------------------//函数定义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 UPLEFT 1#define UPRIGHT 0#define DOWNLEFT 3#define DOWNRIGHT 2 #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忙int CardKeep; //卡卡int MAPCState; unsigned int DeviceWord; //子设备状态字unsigned char DataType; //接收设备类型unsigned char DataLength; //转换后的数据长度unsigned char RDataLength; //接收到的数据长度unsigned char WDataLength; //写入串口的数据长度CardPublish PCMachine[4];DevicesStatus AllDevices;//----------------------------------------------------------------------------//函数定义//初始化串口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);//数据报发送和接收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 InitVoice();int InitMAPC();int InitIOCO();int Leap(unsigned char chCommand,unsigned char chAddress,unsigned char chLeap);int VoiceControl(unsigned char VoiceType);int ExecIOCOFunc(unsigned char cm);int PublishCard(int DeviceIndex); //0==上卡机 1==下卡机int mTerminalControl();int MainInitialize();#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -