⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 old_common.h

📁 linux serial example
💻 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 + -