parent
3a349d35bc
commit
7b5c7a8c3c
@ -0,0 +1,8 @@
|
||||
/********************************************************************/
|
||||
# ht_iec104.conf
|
||||
# date : 2018.09.01
|
||||
# auther : huatek by liuyx
|
||||
# Copyright (C) 2018, huatek, Inc.
|
||||
/********************************************************************/
|
||||
[IEC_DEVCOUNT]
|
||||
# 涓诲彉璁惧鎬绘暟閲
|
@ -0,0 +1,8 @@
|
||||
/********************************************************************/
|
||||
# ht_iec104.conf
|
||||
# date : 2018.09.01
|
||||
# auther : huatek by liuyx
|
||||
# Copyright (C) 2018, huatek, Inc.
|
||||
/********************************************************************/
|
||||
[IEC_DEVCOUNT]
|
||||
# 涓诲彉璁惧鎬绘暟閲
|
@ -0,0 +1,52 @@
|
||||
/********************************************************************/
|
||||
# ht_service.conf
|
||||
# date : 2018.09.01
|
||||
# auther : huatek by liuyx
|
||||
# Copyright (C) 2018, huatek, Inc.
|
||||
/********************************************************************/
|
||||
[HT_MONITOR]
|
||||
# server monitor flag, true: monitor, false:no monitor
|
||||
monitor_enable = true
|
||||
|
||||
[HT_VERSION]
|
||||
# server version info, max length=32(byte)
|
||||
ht_server_version = 2019.06.11
|
||||
|
||||
[HT_LOCAL_HOST]
|
||||
local_host_addr = 127.0.0.1
|
||||
local_tcp_port = 2404
|
||||
|
||||
[HT_REMOTE_HOST]
|
||||
#remote_host_addr = 192.168.1.1
|
||||
remote_host_addr = 127.0.0.1
|
||||
remote_host_port = 2404
|
||||
|
||||
[HT_SOCKET]
|
||||
max_epoll_limit = 2000
|
||||
timeout_t0 = 30
|
||||
timeout_t1 = 15
|
||||
timeout_t2 = 10
|
||||
timeout_t3 = 20
|
||||
iec_k = 8
|
||||
iec_w = 3
|
||||
|
||||
# application database config parameter
|
||||
[HT_DATABASE]
|
||||
db_host_addr = 192.168.128.86
|
||||
db_host_port = 3306
|
||||
db_name = hmf_0617
|
||||
db_username = root
|
||||
db_password = 123456
|
||||
db_min_conn = 5
|
||||
db_max_conn = 8
|
||||
|
||||
[HT_THREAD_NUMBER]
|
||||
thread_recv_num = 2
|
||||
thread_parse_num = 5
|
||||
|
||||
thread_opration_num = 3
|
||||
thread_respone_num = 2
|
||||
|
||||
[HT_LOGGER]
|
||||
logger = console,debug,error,warning,package
|
||||
#logger = error,warning
|
@ -0,0 +1,15 @@
|
||||
/********************************************************************/
|
||||
# htimg.conf
|
||||
# date : 2018.09.01
|
||||
# auther : huatek by liuyx
|
||||
# Copyright (C) 2006-2018, huatek, Inc.
|
||||
# -------------------------------------------------------------------
|
||||
# 浠〃鍗曚綅绫诲瀷鍙婂崟浣嶅畾涔夊搴斿叧绯昏〃
|
||||
# ----------------------------------------
|
||||
# 绫诲瀷 | 鍗曚綅瀹氫箟 |
|
||||
# -------------+-------------------------+
|
||||
# meter_type | meter_units |
|
||||
# -------------+-------------------+-----+
|
||||
# | 0 | 1 | 2 | 3 |
|
||||
# = 0 +-------------------+-----+
|
||||
# (鐢垫祦) | 寰畨 | 姣畨 | 瀹
|
@ -0,0 +1,15 @@
|
||||
/********************************************************************/
|
||||
# htimg.conf
|
||||
# date : 2018.09.01
|
||||
# auther : huatek by liuyx
|
||||
# Copyright (C) 2006-2018, huatek, Inc.
|
||||
# -------------------------------------------------------------------
|
||||
# 浠〃鍗曚綅绫诲瀷鍙婂崟浣嶅畾涔夊搴斿叧绯昏〃
|
||||
# ----------------------------------------
|
||||
# 绫诲瀷 | 鍗曚綅瀹氫箟 |
|
||||
# -------------+-------------------------+
|
||||
# meter_type | meter_units |
|
||||
# -------------+-------------------+-----+
|
||||
# | 0 | 1 | 2 | 3 |
|
||||
# = 0 +-------------------+-----+
|
||||
# (鐢垫祦) | 寰畨 | 姣畨 | 瀹
|
@ -0,0 +1,14 @@
|
||||
rtsp://192.168.1.12/stream65.sdp
|
||||
rtsp://192.168.1.12/stream66.sdp
|
||||
rtsp://192.168.1.12/stream67.sdp
|
||||
rtsp://192.168.1.12/stream68.sdp
|
||||
rtsp://192.168.1.12/stream69.sdp
|
||||
rtsp://192.168.1.12/stream70.sdp
|
||||
rtsp://192.168.1.12/stream71.sdp
|
||||
rtsp://192.168.1.12/stream72.sdp
|
||||
rtsp://192.168.1.12/stream73.sdp
|
||||
rtsp://192.168.1.12/stream74.sdp
|
||||
rtsp://192.168.1.12/stream75.sdp
|
||||
rtsp://192.168.1.12/stream76.sdp
|
||||
rtsp://192.168.1.12/stream80.sdp
|
||||
rtsp://192.168.1.12/stream81.sdp
|
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
** File name : HTCP56Time.h
|
||||
** Description : define data type
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_CP56TIME_H
|
||||
#define __HT_CP56TIME_H
|
||||
//
|
||||
// CP56Time IEC 60870-5-104 time data type implementation
|
||||
//
|
||||
#pragma pack (push ,1)
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
typedef struct _SYSTEMTIME {
|
||||
unsigned short wYear;
|
||||
unsigned short wMonth;
|
||||
unsigned short wDayOfWeek;
|
||||
unsigned short wDay;
|
||||
unsigned short wHour;
|
||||
unsigned short wMinute;
|
||||
unsigned short wSecond;
|
||||
unsigned short wMilliseconds;
|
||||
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
|
||||
|
||||
typedef struct _FILETIME {
|
||||
unsigned long dwLowDateTime;
|
||||
unsigned long dwHighDateTime;
|
||||
} FILETIME, *PFILETIME, *LPFILETIME;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct cp56time {
|
||||
u_short msec;
|
||||
u_char min :6;
|
||||
u_char res1 :1;
|
||||
u_char iv :1;
|
||||
u_char hour :5;
|
||||
u_char res2 :2;
|
||||
u_char su :1;
|
||||
u_char mday :5;
|
||||
u_char wday :3;
|
||||
u_char month :4;
|
||||
u_char res3 :4;
|
||||
u_char year :7;
|
||||
u_char res4 :1;
|
||||
} cp56time ;
|
||||
|
||||
|
||||
class CP56Time
|
||||
{
|
||||
private:
|
||||
SYSTEMTIME stime;
|
||||
bool valid;
|
||||
bool genuine;
|
||||
bool summer;
|
||||
|
||||
public:
|
||||
CP56Time(unsigned char *data);
|
||||
~CP56Time(void);
|
||||
|
||||
void GetTimeString(char *buf, size_t size);
|
||||
FILETIME _GetFileTime(void);
|
||||
SYSTEMTIME _GetSystemTime(void);
|
||||
|
||||
void ActualTimeToCP56Time(unsigned char *data);
|
||||
|
||||
void TimeToCP56Time(FILETIME *ft, unsigned char *data);
|
||||
void TimeToCP56Time(SYSTEMTIME *st, unsigned char *data);
|
||||
|
||||
void CP56TimeToTime(unsigned char *data, FILETIME *ft);
|
||||
void CP56TimeToTime(unsigned char *data, SYSTEMTIME *st);
|
||||
};
|
||||
#pragma pack (pop)
|
||||
#endif // end __HT_CP56TIME_H
|
||||
|
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
** File name : HTCP56Time2a.h
|
||||
** Description : define data type
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_CP56TIME2A_H
|
||||
#define __HT_CP56TIME2A_H
|
||||
//
|
||||
// CP56Time2a IEC 60870-5-104 time data type implementation
|
||||
//
|
||||
#pragma pack (push ,1)
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
typedef struct _SYSTEMTIME {
|
||||
unsigned short wYear;
|
||||
unsigned short wMonth;
|
||||
unsigned short wDayOfWeek;
|
||||
unsigned short wDay;
|
||||
unsigned short wHour;
|
||||
unsigned short wMinute;
|
||||
unsigned short wSecond;
|
||||
unsigned short wMilliseconds;
|
||||
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
|
||||
|
||||
typedef struct _FILETIME {
|
||||
unsigned long dwLowDateTime;
|
||||
unsigned long dwHighDateTime;
|
||||
} FILETIME, *PFILETIME, *LPFILETIME;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct cp56time2a {
|
||||
u_short msec;
|
||||
u_char min :6;
|
||||
u_char res1 :1;
|
||||
u_char iv :1;
|
||||
u_char hour :5;
|
||||
u_char res2 :2;
|
||||
u_char su :1;
|
||||
u_char mday :5;
|
||||
u_char wday :3;
|
||||
u_char month :4;
|
||||
u_char res3 :4;
|
||||
u_char year :7;
|
||||
u_char res4 :1;
|
||||
} cp56time2a ;
|
||||
|
||||
|
||||
class CP56Time2a
|
||||
{
|
||||
private:
|
||||
SYSTEMTIME stime;
|
||||
bool valid;
|
||||
bool genuine;
|
||||
bool summer;
|
||||
|
||||
public:
|
||||
CP56Time2a(unsigned char *data);
|
||||
~CP56Time2a(void);
|
||||
|
||||
void GetTimeString(char *buf, size_t size);
|
||||
FILETIME _GetFileTime(void);
|
||||
SYSTEMTIME _GetSystemTime(void);
|
||||
|
||||
void ActualTimeToCP56Time(unsigned char *data);
|
||||
|
||||
void TimeToCP56Time2a(FILETIME *ft, unsigned char *data);
|
||||
void TimeToCP56Time2a(SYSTEMTIME *st, unsigned char *data);
|
||||
|
||||
void CP56Time2aToTime(unsigned char *data, FILETIME *ft);
|
||||
void CP56Time2aToTime(unsigned char *data, SYSTEMTIME *st);
|
||||
};
|
||||
#pragma pack (pop)
|
||||
#endif // end __HT_TYPE_H
|
||||
|
@ -0,0 +1,179 @@
|
||||
/****************************************************************************
|
||||
** File name : HTConfig.h
|
||||
** Description : config parameter
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_CONFIG_H
|
||||
#define __HT_CONFIG_H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <list>
|
||||
// 配置文件路径
|
||||
#ifdef _WIN32
|
||||
static const char HT_CONFIG_FILE[] = "../etc/ht_service.conf";
|
||||
#else
|
||||
static const char HT_CONFIG_FILE[] = "../etc/ht_service.conf" ;
|
||||
#endif
|
||||
|
||||
class TConfig
|
||||
{
|
||||
public:
|
||||
TConfig();
|
||||
virtual ~TConfig();
|
||||
|
||||
static TConfig *getInstance();
|
||||
|
||||
// 读取配置文件参数
|
||||
bool getIniConfig();
|
||||
void showConfig();
|
||||
|
||||
// 设置本地服务器IP
|
||||
void setLocalAddr(char *pszAddr);
|
||||
|
||||
// 获取本地服务器IP
|
||||
char *getLocalAddr();
|
||||
|
||||
// 设置本地服务器端口
|
||||
void setLocalPort(unsigned short iPort);
|
||||
|
||||
// 获取本地服务器端口
|
||||
unsigned short getLocalPort();
|
||||
|
||||
|
||||
// 设置远程服务器IP
|
||||
void setRemoteAddr(char *pszAddr);
|
||||
|
||||
// 获取远程服务器IP
|
||||
char *getRemoteAddr();
|
||||
|
||||
// 设置远程服务器端口
|
||||
void setRemotePort(unsigned short iPort);
|
||||
|
||||
// 获取远程服务器端口
|
||||
unsigned short getRemotePort();
|
||||
|
||||
|
||||
void setRecvThreadNumber(unsigned int n) ; // 接收线程数
|
||||
void setParseThreadNumber(unsigned int n) ; // 解析104线程数
|
||||
void setOprationThreadNumber(unsigned int n) ; // 入库线程数
|
||||
void setResponeThreadNumber(unsigned int n) ; // 应答线程数
|
||||
|
||||
unsigned int getRecvThreadNumber() ; // 接收线程数
|
||||
unsigned int getParseThreadNumber() ; // 解析104线程数
|
||||
unsigned int getOprationThreadNumber() ; // 入库线程数
|
||||
unsigned int getResponeThreadNumber() ; // 应答线程数
|
||||
|
||||
|
||||
// 配置数据库配置参数接口
|
||||
unsigned int getdbPort() ;
|
||||
unsigned int getdbMaxConnect();
|
||||
unsigned int getdbMinConnect() ;
|
||||
char *getdbHostIP() ;
|
||||
char *getdbName() ;
|
||||
char *getdbUserName() ;
|
||||
char *getdbUserPass() ;
|
||||
|
||||
void setdbPort(unsigned int port);
|
||||
void setdbMaxConnect(unsigned int max);
|
||||
void setdbMinConnect(unsigned int min);
|
||||
void setdbHostIP(char *pszDBHostIP);
|
||||
void setdbName(char *pszDBName);
|
||||
void setdbUserName(char *pszDBUserName);
|
||||
void setdbUserPass(char *pszDBUserPass);
|
||||
|
||||
|
||||
// socket 相关属性参数配置
|
||||
void setFdLimit(unsigned int iCount);
|
||||
unsigned int getFdLimit();
|
||||
|
||||
void setTimeout0(unsigned int t);
|
||||
void setTimeout1(unsigned int t);
|
||||
void setTimeout2(unsigned int t);
|
||||
void setTimeout3(unsigned int t);
|
||||
unsigned int getTimeout0();
|
||||
unsigned int getTimeout1();
|
||||
unsigned int getTimeout2();
|
||||
unsigned int getTimeout3();
|
||||
|
||||
void setK(unsigned int k);
|
||||
unsigned int getK();
|
||||
|
||||
void setW(unsigned int w);
|
||||
unsigned int getW();
|
||||
|
||||
void setLogDebug(char yes);
|
||||
void setLogError(char yes);
|
||||
void setLogWarning(char yes);
|
||||
void setLogPack(char yes);
|
||||
void setLogConsole(char yes);
|
||||
void setLogMessage(char yes);
|
||||
char isLogDebug(void);
|
||||
char isLogError(void);
|
||||
char isLogWarning(void);
|
||||
char isLogPack(void);
|
||||
char isLogConsole(void);
|
||||
char isLogMessage(void);
|
||||
|
||||
// version infomation functios
|
||||
void setServerVersion(char *pver) ;
|
||||
char *getServerVersion();
|
||||
|
||||
void setMonitor(bool bMonitor);
|
||||
bool getMonitor();
|
||||
// 读取配置文件函数
|
||||
int iniGetString(const char *pszSection, const char *pszEntry, char *pszRetBuf, unsigned int uiBufLen);
|
||||
|
||||
private:
|
||||
static TConfig *p_TConfig;
|
||||
|
||||
|
||||
bool b_monitor_enable ; // 监控标志 true:启用 false: 不启用
|
||||
|
||||
// server version infomations
|
||||
char m_version[32+1]; // format 2013.00.100
|
||||
|
||||
// database config parameter
|
||||
char m_dbHostIP[16];
|
||||
char m_dbName[16];
|
||||
char m_dbUserName[16];
|
||||
char m_dbUserPass[16];
|
||||
|
||||
unsigned int m_dbMaxConnect;
|
||||
unsigned int m_dbMinConnect;
|
||||
unsigned int m_dbPort;
|
||||
|
||||
char m_local_addr[16];
|
||||
unsigned m_local_port;
|
||||
char m_remote_addr[16] ;
|
||||
unsigned int m_remote_port ;
|
||||
// socket config
|
||||
unsigned int m_fd_limit;
|
||||
unsigned int t0,t1,t2,t3,uK,uW;
|
||||
|
||||
|
||||
unsigned int m_recv_num;
|
||||
unsigned int m_parse_num;
|
||||
unsigned int m_opration_num;
|
||||
unsigned int m_respone_num;
|
||||
|
||||
|
||||
// logger
|
||||
char m_logdebug; // debug logger
|
||||
char m_logwarning; // warning logger
|
||||
char m_logerror; // error logger
|
||||
char m_logpack; // package print logger
|
||||
char m_logconsole; // console print
|
||||
char m_logmessage; // message print
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
** File name : HTConst.h
|
||||
** Description : define const
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_CONST_H
|
||||
#define __HT_CONST_H
|
||||
|
||||
// ASCI字符数字定义
|
||||
#define KEY0 '0'
|
||||
#define KEY1 '1'
|
||||
#define KEY2 '2'
|
||||
#define KEY3 '3'
|
||||
#define KEY4 '4'
|
||||
#define KEY5 '5'
|
||||
#define KEY6 '6'
|
||||
#define KEY7 '7'
|
||||
#define KEY8 '8'
|
||||
#define KEY9 '9'
|
||||
|
||||
// 数字定义
|
||||
#define KEY_0 0x00
|
||||
#define KEY_1 0x01
|
||||
#define KEY_2 0x02
|
||||
#define KEY_3 0x03
|
||||
#define KEY_4 0x04
|
||||
#define KEY_9 0x09
|
||||
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 260
|
||||
#endif
|
||||
|
||||
// use buffer size define
|
||||
#define DEF_BUFFER_32 32
|
||||
#define DEF_BUFFER_128 128
|
||||
#define DEF_BUFFER_256 256
|
||||
#define DEF_BUFFER_1K 1024
|
||||
#define DEF_BUFFER_2K 2048
|
||||
#define DEF_BUFFER_4K 4096
|
||||
#define DEF_BUFFER_8K 8192
|
||||
#define DEF_BUFFER_512K 1024*512
|
||||
|
||||
#define MAX_SLEEP_EMPTY 5 // ms
|
||||
|
||||
#define CHANNEL_DOWN 1 // MEC下行通道UDP
|
||||
#define CHANNEL_UP 0 // MEC上行通道UDP
|
||||
|
||||
#define MAX_FLT_EXTERN 24 // 最大内部报文扩展项个数
|
||||
|
||||
// 809平台间报文类型
|
||||
#define PALT_PKG_QUERY 0 // 平台查岗
|
||||
#define PALT_PKG_MESG 1 // 平台间报文消息
|
||||
|
||||
// 来源
|
||||
#define MSG_SOURCE_MARGE 0 // 上级监管平台
|
||||
#define MSG_SOURCE_LOACL 1 // 企业平台
|
||||
|
||||
#define HT_INVALID_VALUE 0x7FFFFFFF // 无效值
|
||||
|
||||
#endif // end __HT_CONST_H
|
||||
|
@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
** File name : HTDatabase.h
|
||||
** Description : define database api
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_DATABASE_H
|
||||
#define __HT_DATABASE_H
|
||||
|
||||
#include "HTPublic.h"
|
||||
#include "HTDataStruct.h"
|
||||
#include "mysql.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
//#pragma comment(lib,"ociliba.lib")
|
||||
#pragma comment(lib,"libmysql.lib")
|
||||
#endif
|
||||
|
||||
typedef std::list<MYSQL *> CONNECTION_HANDLE_LIST;
|
||||
typedef std::list<MYSQL *>::iterator ITER_CONNECTION_HANDLE_LIST;
|
||||
|
||||
#define CONNECTION_NUM 10 //同时打开的连接数
|
||||
|
||||
class CDBMySQL
|
||||
{
|
||||
public:
|
||||
CDBMySQL();
|
||||
CDBMySQL(const char *host, const char *user, const char *password, const char *db, unsigned int port=3306);
|
||||
virtual ~CDBMySQL();
|
||||
|
||||
public:
|
||||
|
||||
bool dbConnectPool(); //连接数据库
|
||||
void dbFreeConnectPool() ; //释放链接资源
|
||||
|
||||
bool dbAutoCommit(MYSQL *pMysql, bool bStart); // 开始事务处理
|
||||
bool dbCommit(MYSQL *pMysql);
|
||||
bool InsertRecordBitch(const char pszSql[][256], int count);
|
||||
bool AddInsertRecord(MYSQL *pHandle, const char *szSql);
|
||||
|
||||
MYSQL_RES* SelectRecord(const char *szSql); //选择记录,返回结果集
|
||||
bool SelectDB(const char *szDB); //选择数据库
|
||||
bool UpdateRecord(const char *szSql); //更新记录
|
||||
bool InsertRecord(const char *szSql); //插入记录
|
||||
bool DelRecord(const char *szSql); //删除记录
|
||||
|
||||
bool IsEnd(MYSQL_RES *myquery); //是否最后
|
||||
void SeekData(MYSQL_RES *myquery, int offset); //查找指定数据
|
||||
void FreeRecord(MYSQL_RES *myquery); //释放结果集
|
||||
unsigned int GetFieldNum(MYSQL_RES *myquery); //得到字段数
|
||||
MYSQL_ROW GetRecord(MYSQL_RES *myquery); //得到结果(一个记录)
|
||||
my_ulonglong GetRowNum(MYSQL_RES *myquery); //得到记录数
|
||||
char* getLastError(MYSQL* pMySql); //输出错误信息
|
||||
|
||||
char* GetState(); //服务器状态
|
||||
char* GetServerInfo(); //服务器信息
|
||||
int GetProtocolInfo(); //协议信息
|
||||
char* GetHostInfo(); //主机信息
|
||||
char* GetClientInfo(); //客户机信息
|
||||
char* GetFieldName(MYSQL_RES *myquery, int FieldNum); //字段名
|
||||
|
||||
bool LockTable(const char *TableName, const char *Priority); //对特定表加锁
|
||||
bool UnlockTable(); //解锁
|
||||
bool SetCharset();
|
||||
//int CreateDB(char *db); //创建数据库,返回错误信息
|
||||
//int DropDB(char *db); //删除数据库,返回错误信息
|
||||
|
||||
MYSQL* GetIdleMySql(); //提取一个空闲句柄供使用
|
||||
void SetIdleMysql(MYSQL* pMySql); //从使用队列中释放一个使用完毕的句柄,插入到空闲队列
|
||||
static CDBMySQL* Instance();
|
||||
|
||||
public:
|
||||
//MYSQL m_mysql; //数据库连接句柄
|
||||
MYSQL_ROW m_row; //记录集(单行)
|
||||
MYSQL_FIELD *m_field; //字段信息(结构体)
|
||||
|
||||
//创建两个队列
|
||||
CONNECTION_HANDLE_LIST m_lsBusyList; //正在使用的连接句柄
|
||||
CONNECTION_HANDLE_LIST m_lsIdleList; //未使用的连接句柄
|
||||
|
||||
mutex m_csList;
|
||||
|
||||
private:
|
||||
static CDBMySQL* p_dbHandle ;
|
||||
|
||||
char m_host[20]; //主机
|
||||
char m_user[20]; //用户名
|
||||
char m_password[20]; //密码
|
||||
char m_db[20]; //数据库名
|
||||
unsigned int m_port; //端口
|
||||
unsigned int m_min; // 链接数
|
||||
};
|
||||
|
||||
#endif // __HT_DATABASE_H
|
@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
** File name : HTError.h
|
||||
** Description : define error code
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_ERROR_H
|
||||
#define __HT_ERROR_H
|
||||
|
||||
#define RET_OK 0
|
||||
#define RET_FAIL -1
|
||||
#define RET_IPPORT_INVALID -2 // IP地址或端口无效
|
||||
#define RET_UDP_BIND_PORT -3 // UDP绑定端口错误
|
||||
#define RET_LENGTH_INVALID -4 // 数据长度无效
|
||||
#define RET_VALUE_INVALID -5 // 域值无效
|
||||
#define RET_TYPE_INVALID -6 // 业务类型无效
|
||||
#define RET_CALLOC_FAIL -7 // 申请内存失败
|
||||
#define RET_SUB_ID_INVALID -8 // 域ID标识无效/不支持的ID标识码
|
||||
#define RET_CALL_OCI_FAILED -9 // OCI调用失败
|
||||
#define RET_NOT_FOUND_RECORD -10 // 无原请求业务流水
|
||||
#define RET_ERROR_AUTHID -11 // 无效接入码
|
||||
#define RET_UDP_STATUS_EXP -12 // UDP链接状态异常
|
||||
#define RET_NOT_EXTERN_PACK -13 // 无扩展报文
|
||||
#define RET_NOT_FOUND_ACCESSID -14 // 没有检索到接入码
|
||||
#define RET_TERM_NOT_ONLINE -15 // 终端不在线
|
||||
#define RET_SUB_COMMAND_INVALID -16 // 采集数据的子命令无效
|
||||
#define RET_MAJOR_CONN_ERR -17 // TCP主链路状态错误
|
||||
#define RET_NOT_FILE_EXIST -18 // 文件不存在
|
||||
#define RET_NOT_DATA -19 // 采集行驶记录无数据
|
||||
#define RET_SET_ERROR_PIC -20 // 插入拍照下发指令记录失败
|
||||
#define RET_SERVER_ID_ERR -21 // 连接服务器名称无效
|
||||
#define RET_JT809_VERSION -22 // 数据库配置了无效的JT809协议版本号
|
||||
#define RET_JT808_VERSION -23 // 808内部报文协议类型无效
|
||||
#define RET_JT809_CRC_ERROR -24 // CRC16校验错误
|
||||
#define RET_LINK_CHECK_ERROR -25 // 链路校验码错误
|
||||
#define RET_RECORD_ORG_ID_NULL -26 // 记录仪ID或企业ID为空
|
||||
#endif // end __HT_ERROR_H
|
||||
|
@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
** File name : HTGolbal.h
|
||||
** Description : global variable define
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#pragma warning (disable:4786)
|
||||
#ifndef __HT_GLOBAL_H
|
||||
#define __HT_GLOBAL_H
|
||||
|
||||
#include "HTType.h"
|
||||
#include "HTConst.h"
|
||||
#include "HTMutex.h"
|
||||
#include "HTPublic.h"
|
||||
#include "HTLogger.h"
|
||||
#include "HTConfig.h"
|
||||
#include "HTDatabase.h"
|
||||
#include "HTDataStruct.h"
|
||||
#include "HTHP104Table.h"
|
||||
#include "HTMemCacheData.h"
|
||||
#include "HTInitUtils.h"
|
||||
#include "HTCP56Time.h"
|
||||
#include "HTError.h"
|
||||
#include "HTTcpSocket.h"
|
||||
#include "HTIEC104.h"
|
||||
#include "HTThread.h"
|
||||
#include "HTImageBusi.h"
|
||||
#include "HTOpencvImg.h"
|
||||
#include "HTTestOpencv.h"
|
||||
#include "HTUnit.h"
|
||||
#include "HTVersion.h"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#define _HT_OPENCV_APP // 图片分析处理程序
|
||||
#define _HT_IEC104_APP // IEC104通讯程序
|
||||
#define _DEF_HMF_VOLTAGE // 黑麋峰高压侧电流计算
|
||||
#define _DEF_DB_CHANGERATE // 启用偏差率入库功能,否则以设定的间隔时间入库
|
||||
|
||||
|
||||
using namespace std;
|
||||
//#define _CRT_SECURE_NO_WARNINGS 1
|
||||
|
||||
|
||||
extern int g_Running;
|
||||
extern TConfig g_TConfig;
|
||||
extern TTcpSocket g_Tcp;
|
||||
|
||||
extern ST_IEC104_CTRL g_IecCtrl; // socket linker info and status
|
||||
extern mutex g_IecCtrl_mutex; // socket linker on mutex
|
||||
|
||||
extern map<string, ST_BYQWORK_STATUS> g_map_work; // 主变工作状态缓存
|
||||
extern mutex g_map_work_mutex; // 主变工作状态缓存队列锁
|
||||
|
||||
//extern map<string,ST_BYQ_CACHE> g_map_byq; // 变压器缓存数据
|
||||
extern map<string, ST_BYQ_RUN_STATE_THRESHOLD> g_map_thres_byq; // 变压器缓存数据
|
||||
extern mutex g_map_byq_mutex; // 变压器缓存数据信息队列锁
|
||||
|
||||
//extern map<string,ST_GIS_CACHE> g_map_gis; // GIS缓存数据
|
||||
//extern mutex g_map_gis_mutex; // GIS缓存数据信息队列锁
|
||||
|
||||
extern multimap<string, ST_DEV_RELATION> g_map_relation; // 主设备与外挂设备关系
|
||||
extern mutex g_map_relation_mutex; // GIS缓存数据信息队列锁
|
||||
|
||||
//extern map<string, ST_GIS_IEC104_DATA> g_map_gis_104; // GIS最近一次104上传数据缓存
|
||||
//extern mutex g_map_gis_104_mutex;
|
||||
|
||||
//extern map<string, ST_BLQ_CACHE> g_map_blq; // BLQ缓存数据
|
||||
//extern mutex g_map_blq_mutex; // BLQ缓存数据信息队列锁
|
||||
|
||||
extern map<unsigned int, ST_IECPOINT_TABLE> g_map_iec; // 104报文解析缓存数据
|
||||
extern mutex g_map_iec_mutex; // 104报文解析缓存数据信息队列锁
|
||||
|
||||
extern map<unsigned int, ST_SADR_MATCH> g_map_sadr; // 点表匹配关系
|
||||
extern mutex g_map_sadr_mutex;
|
||||
|
||||
extern map<string, ST_IMG_THRESHOLD> g_map_img_thres; // 图片识别阈值
|
||||
extern mutex g_map_img_thres_mutex;
|
||||
|
||||
//extern list<ST_LIST_MONITOR> g_list_monitor; // 监控消息数据队列
|
||||
//extern mutex g_list_monitor_mutex;
|
||||
extern map<string, ST_DEVICE_TIME_STAT> g_map_dev_time_stat;
|
||||
extern mutex g_map_dev_time_stat_mutex;
|
||||
|
||||
extern map<unsigned int, ST_BREAK_EQM_CODE> g_map_gis_state; // 断路器状态位与电流电压关系匹配表
|
||||
extern mutex g_map_gis_state_mutex;
|
||||
|
||||
extern int g_seqno; // 与MEC之间交换的流水号
|
||||
extern mutex g_seq_mutex; // 流水号
|
||||
|
||||
extern pthread_t thread_handle_monitor; // 监控线程句柄
|
||||
|
||||
extern pthread_t thread_handle_parse; // 104报文解析线程
|
||||
//extern pthread_t thread_handle_setdb; // 入库线程
|
||||
//extern pthread_t thread_handle_getdata; // 数据提取线程
|
||||
extern pthread_t thread_handle_timer; // 应答线程
|
||||
|
||||
extern pthread_t thread_handle_client; // 客户端链接线程
|
||||
extern pthread_t thread_handle_warning; // 报警处理及入库线程句柄
|
||||
extern pthread_t thread_handle_origin; // 原始数据如何线程句柄
|
||||
extern pthread_t thread_handle_pingce; // IEC104评测数据入库线程句柄
|
||||
extern pthread_t thread_handle_gishold; // 断路器断开数据入库线程句柄
|
||||
|
||||
extern pthread_t thread_handle_active; // 心跳线程
|
||||
extern pthread_t thread_handle_linkmgr; // 链路管理线程
|
||||
extern pthread_t thread_handle_cache; // 内存同步线程句柄
|
||||
extern pthread_t thread_handle_opecvimg; // 图片识别线程句柄
|
||||
|
||||
|
||||
#endif // end __HT_GLOBAL_H
|
||||
|
@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
** File name : HTInitUtils.h
|
||||
** Description : Defines service initialization API
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_INIT_UTILS_H
|
||||
#define __HT_INIT_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 初始化服务运行环境
|
||||
int loadServiceEvent();
|
||||
void reloadServiceEvent(int platform_id);
|
||||
int unLoadServiceEvent();
|
||||
|
||||
int get_seqno(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // end __HT_INIT_UTILS_H
|
||||
|
@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
** File name : HTLogger.h
|
||||
** Description : logger function define
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_LOGGER_H
|
||||
#define __HT_LOGGER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
// logger config parameter
|
||||
#ifdef _WIN32
|
||||
static const char *DEF_LOG_PATH_NAME = "..\\log" ; //日志文件目录名
|
||||
static const char *DEF_RUN_INFO_PATH = "..\\run" ; // 服务运行状态日志目录
|
||||
#else
|
||||
static const char *DEF_LOG_PATH_NAME = "../log" ; //日志文件目录名
|
||||
static const char *DEF_RUN_INFO_PATH = "../run" ; // 服务运行状态日志目录
|
||||
#endif
|
||||
|
||||
// 打印报文类型,日志
|
||||
#define PRT_PACK_SEND 0 // 打印发送报文类型
|
||||
#define PRT_PACK_RECV 1 // 打印接收报文类型
|
||||
#define PRT_PACK_DATA 2 // 打印报文
|
||||
|
||||
#define DEF_LOG_FILESZIE 1048576*50 /* logfile size define 50M byte */
|
||||
|
||||
#ifdef LOG_DEBUG
|
||||
#undef LOG_DEBUG
|
||||
#endif
|
||||
#define __LOG_DEBUG 0 // 跟踪日志
|
||||
#define LOG_DEBUG __LINE__, _FILE_, __LOG_DEBUG
|
||||
|
||||
#ifdef LOG_WARNG
|
||||
#undef LOG_WARNG
|
||||
#endif
|
||||
#define __LOG_WARNG 1 // 告警日志
|
||||
#define LOG_WARNG __LINE__, _FILE_, __LOG_WARNG
|
||||
|
||||
#ifdef LOG_ERROR
|
||||
#undef LOG_ERROR
|
||||
#endif
|
||||
#define __LOG_ERROR 2 // 错误日志
|
||||
#define LOG_ERROR __LINE__, _FILE_, __LOG_ERROR
|
||||
|
||||
#ifdef LOG_PACK
|
||||
#undef LOG_PACK
|
||||
#endif
|
||||
#define __LOG_PACK 3 // 报文日志
|
||||
#define LOG_PACK __LINE__, _FILE_, __LOG_PACK
|
||||
|
||||
// 日志记录相关函数
|
||||
void vInitLogMutex(void);
|
||||
void vFreeLogMutex(void);
|
||||
|
||||
void vPrtLogMsg(int line, const char *pszFileName, char logLevel, int iCode, ...);
|
||||
void vPrtLogHex(int line, const char *pszFileName, char logLevel, int sockid, /* unsigned short msg_id, */
|
||||
char pszMsgType, unsigned char *pusMsg,int uiMsgLen);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __HT_LOGGER_H
|
||||
|
@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
** File name : HTMutex.cpp
|
||||
** Description : define mutex type
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_MUTEX_H
|
||||
#define __HT_MUTEX_H
|
||||
|
||||
#ifndef _WIN32 //for unix
|
||||
#define mutex pthread_mutex_t
|
||||
#define mutex_create(X) pthread_mutex_init(&X, NULL)
|
||||
#define mutex_close(X) pthread_mutex_destroy(&X)
|
||||
#define mutex_lock(X) pthread_mutex_lock(&X)
|
||||
#define mutex_unlock(X) pthread_mutex_unlock(&X)
|
||||
#else //for winX
|
||||
#define mutex HANDLE
|
||||
#define mutex_create(X) X = CreateMutex(NULL, FALSE, NULL)
|
||||
#define mutex_close(X) CloseHandle(X)
|
||||
#define mutex_lock(X) WaitForSingleObject(X, INFINITE)
|
||||
#define mutex_unlock(X) ReleaseMutex(X)
|
||||
#endif
|
||||
|
||||
// delay tims, millisecond(ms)
|
||||
#ifndef _WIN32 //for unix
|
||||
#define _SLEEP(X) usleep(X * 1000)
|
||||
#else //for winX
|
||||
#define _SLEEP(X) Sleep(X) //ms
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32 //for unix
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#endif // end __HT_MUTEX_H
|
||||
|
@ -0,0 +1,548 @@
|
||||
/****************************************************************************
|
||||
** File name : HTOpencvImg.h
|
||||
** Description : define Opencv function
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_OPENCV_IMG_H
|
||||
#define __HT_OPENCV_IMG_H
|
||||
#pragma warning(disable: 4819)
|
||||
#include <stdio.h>
|
||||
#include "HTGlobal.h"
|
||||
//#include "opencv/cv.h"
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/ml.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
|
||||
//#define _HT_OPENCV_TEST_ENV // 测试环境,产生随机数作为分析表的数据
|
||||
|
||||
#pragma pack (push ,1)
|
||||
|
||||
//OpencvDirTraverse.cpp : Defines the entry point for the console application.
|
||||
#ifdef _WIN32
|
||||
#pragma comment(lib,"opencv_world300d.lib")
|
||||
//#pragma comment(lib,"opencv_ts300d.lib")
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
#if (defined _WIN32) || (defined _WIN64)
|
||||
static const char HT_CONFIMG_FILE[] = "..\\etc\\htimg-win.conf";
|
||||
#else
|
||||
static const char HT_CONFIMG_FILE[] = "../etc/htimg.conf";
|
||||
#endif
|
||||
|
||||
#define eps 0.0000000001
|
||||
#define PI acos(-1.0)
|
||||
//#define MAX_FILE_SIZE 8294454 // 图片文件大小(字节)
|
||||
//#define MAX_FILE_SIZE 177400
|
||||
//#define _IM_SHOW // 显示图片
|
||||
//#define _IMG_MIDILL_SAVE // 保存最终变换图片
|
||||
|
||||
typedef struct _CONF_IMG {
|
||||
//[CAMERA_01]
|
||||
int seqno; // 序列号,001-999之间
|
||||
unsigned char eqm_type[2]; // 主设备类型, T-主变 G-GIS B-避雷器
|
||||
unsigned char site_id[DEF_EQM_CODE_SIZE]; // 站点ID
|
||||
unsigned char eqm_code[DEF_EQM_CODE_SIZE]; // 主设备编码
|
||||
unsigned char sys_code[DEF_EQM_CODE_SIZE]; // 主设备系统编码
|
||||
unsigned char table_type[32]; // 仪表类型名称
|
||||
unsigned char name[32]; //# 拍摄对象名称,变压器放电拍照设备
|
||||
unsigned char sersorid[DEF_EQM_CODE_SIZE]; //# 设备的sersor_id, 与数据库一一对应
|
||||
unsigned int base_angle; //# 仪表基准度数, 180° 或360°
|
||||
unsigned char meter_type; //# 仪表的数据单位类型, 0:电流 1 : 压力 2 : 容量(油位) 3: 温度
|
||||
unsigned char meter_units; //# 对应于meter_type的单位
|
||||
unsigned char direct_Clockwise;// 仪表读数的方向, 正时针 = 1 反时针 = 0
|
||||
double dInitVal; // 初始值
|
||||
unsigned int max_pointer_len; //# 最大指针长度(mm), 20mm~200mm, 默认:100
|
||||
unsigned char img_path[MAX_PATH]; // 图片文件路径及类型: ../img01/*.* or ../img01/*.jpg ...
|
||||
unsigned char img_bak[MAX_PATH]; // 图片文件备份路径../img01/bak ...
|
||||
bool is_replace; //true: 覆盖原文件,不保留原文件,文件名不变;false: 保留原文件,并将截图文件命名为 xxx_cut.xxx
|
||||
//# 截图区域配置
|
||||
int s_height; //# 起始行 / 高度 / Y / H / rows
|
||||
int e_height; //# 结束行 / 高度 / Y / H / rows
|
||||
int s_width; //# 起始列 / 宽度 / X / W / cols
|
||||
int e_width; //# 结束列 / 宽度 / X / W / cols
|
||||
int img_min_size; // 图片文件最小字节数
|
||||
}ST_OPENCV_CONF;
|
||||
|
||||
|
||||
typedef struct _YB_TYPE {
|
||||
int len; // 线长度
|
||||
double du; // 角度
|
||||
double val; // 对应的值
|
||||
}ST_YB_TYPE;
|
||||
|
||||
static const ST_YB_TYPE g_YB_3EX5050[] =
|
||||
{
|
||||
{ 156, 139.00, 0 },
|
||||
{ 156, 127.00, 1 },
|
||||
{ 156, 116.00, 2 },
|
||||
{ 156, 105.00, 3 },
|
||||
{ 156, 90.00, 10 },
|
||||
{ 156, 75.00, 20 },
|
||||
{ 156, 52.00, 30 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
static const ST_YB_TYPE g_YB_JSY10[] =
|
||||
{
|
||||
{ 306, 90.00, 0 },
|
||||
{ 306, 54.00, 1 },
|
||||
{ 306, 18.00, 2 },
|
||||
{ 306, 342.00, 3 },
|
||||
{ 306, 306.00, 4 },
|
||||
{ 306, 270.00, 5 },
|
||||
{ 306, 234.00, 6 },
|
||||
{ 306, 198.00, 7 },
|
||||
{ 306, 162.00, 8 },
|
||||
{ 306, 126.00, 9 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
|
||||
static const ST_YB_TYPE g_YB_YZFTH[] =
|
||||
{
|
||||
{ 220, 45.00, 10.00 },
|
||||
{ 220, 47.70, 9.90 },
|
||||
{ 220, 50.40, 9.80 },
|
||||
{ 220, 53.10, 9.70 },
|
||||
{ 220, 55.80, 9.60 },
|
||||
{ 220, 58.50, 9.50 },
|
||||
{ 220, 61.20, 9.40 },
|
||||
{ 220, 63.90, 9.30 },
|
||||
{ 220, 66.60, 9.20 },
|
||||
{ 220, 69.30, 9.10 },
|
||||
{ 220, 72.00, 9.00 },
|
||||
{ 220, 74.70, 8.90 },
|
||||
{ 220, 77.40, 8.80 },
|
||||
{ 220, 80.10, 8.70 },
|
||||
{ 220, 82.80, 8.60 },
|
||||
{ 220, 85.50, 8.50 },
|
||||
{ 220, 88.20, 8.40 },
|
||||
{ 220, 90.90, 8.30 },
|
||||
{ 220, 93.60, 8.20 },
|
||||
{ 220, 96.30, 8.10 },
|
||||
{ 220, 99.00, 8.00 },
|
||||
{ 220, 101.70, 7.90 },
|
||||
{ 220, 104.40, 7.80 },
|
||||
{ 220, 107.10, 7.70 },
|
||||
{ 220, 109.80, 7.60 },
|
||||
{ 220, 112.50, 7.50 },
|
||||
{ 220, 115.20, 7.40 },
|
||||
{ 220, 117.90, 7.30 },
|
||||
{ 220, 120.60, 7.20 },
|
||||
{ 220, 123.30, 7.10 },
|
||||
{ 220, 126.00, 7.00 },
|
||||
{ 220, 128.70, 6.90 },
|
||||
{ 220, 131.40, 6.80 },
|
||||
{ 220, 134.10, 6.70 },
|
||||
{ 220, 136.80, 6.60 },
|
||||
{ 220, 139.50, 6.50 },
|
||||
{ 220, 142.20, 6.40 },
|
||||
{ 220, 144.90, 6.30 },
|
||||
{ 220, 147.60, 6.20 },
|
||||
{ 220, 150.30, 6.10 },
|
||||
{ 220, 153.00, 6.00 },
|
||||
{ 220, 155.70, 5.90 },
|
||||
{ 220, 158.40, 5.80 },
|
||||
{ 220, 161.10, 5.70 },
|
||||
{ 220, 163.80, 5.60 },
|
||||
{ 220, 166.50, 5.50 },
|
||||
{ 220, 169.20, 5.40 },
|
||||
{ 220, 171.90, 5.30 },
|
||||
{ 220, 174.60, 5.20 },
|
||||
{ 220, 177.30, 5.10 },
|
||||
{ 220, 180.00, 5.00 },
|
||||
{ 220, 182.70, 4.90 },
|
||||
{ 220, 185.40, 4.80 },
|
||||
{ 220, 188.10, 4.70 },
|
||||
{ 220, 190.80, 4.60 },
|
||||
{ 220, 193.50, 4.50 },
|
||||
{ 220, 196.20, 4.40 },
|
||||
{ 220, 198.90, 4.30 },
|
||||
{ 220, 201.60, 4.20 },
|
||||
{ 220, 204.30, 4.10 },
|
||||
{ 220, 207.00, 4.00 },
|
||||
{ 220, 209.70, 3.90 },
|
||||
{ 220, 212.40, 3.80 },
|
||||
{ 220, 215.10, 3.70 },
|
||||
{ 220, 217.80, 3.60 },
|
||||
{ 220, 220.50, 3.50 },
|
||||
{ 220, 223.20, 3.40 },
|
||||
{ 220, 225.90, 3.30 },
|
||||
{ 220, 228.60, 3.20 },
|
||||
{ 220, 231.30, 3.10 },
|
||||
{ 220, 234.00, 3.00 },
|
||||
{ 220, 236.70, 2.90 },
|
||||
{ 220, 239.40, 2.80 },
|
||||
{ 220, 242.10, 2.70 },
|
||||
{ 220, 244.80, 2.60 },
|
||||
{ 220, 247.50, 2.50 },
|
||||
{ 220, 250.20, 2.40 },
|
||||
{ 220, 252.90, 2.30 },
|
||||
{ 220, 255.60, 2.20 },
|
||||
{ 220, 258.30, 2.10 },
|
||||
{ 220, 261.00, 2.00 },
|
||||
{ 220, 263.70, 1.90 },
|
||||
{ 220, 266.40, 1.80 },
|
||||
{ 220, 269.10, 1.70 },
|
||||
{ 220, 271.80, 1.60 },
|
||||
{ 220, 274.50, 1.50 },
|
||||
{ 220, 277.20, 1.40 },
|
||||
{ 220, 279.90, 1.30 },
|
||||
{ 220, 282.60, 1.20 },
|
||||
{ 220, 285.30, 1.10 },
|
||||
{ 220, 288.00, 1.00 },
|
||||
{ 220, 290.70, 0.90 },
|
||||
{ 220, 293.40, 0.80 },
|
||||
{ 220, 296.10, 0.70 },
|
||||
{ 220, 298.80, 0.60 },
|
||||
{ 220, 301.50, 0.50 },
|
||||
{ 220, 304.20, 0.40 },
|
||||
{ 220, 306.90, 0.30 },
|
||||
{ 220, 309.60, 0.20 },
|
||||
{ 220, 312.30, 0.10 },
|
||||
{ 220, 315.00, 0.00 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
|
||||
// 150摄氏度的油温表读数
|
||||
static const ST_YB_TYPE g_YB_WSS150[] =
|
||||
{
|
||||
{ 183, 225.00, 0.00 },
|
||||
{ 183, 219.60, 3.00 },
|
||||
{ 183, 214.20, 6.00 },
|
||||
{ 183, 208.80, 9.00 },
|
||||
{ 183, 203.40, 12.00 },
|
||||
{ 183, 198.00, 15.00 },
|
||||
{ 183, 192.60, 18.00 },
|
||||
{ 183, 187.20, 21.00 },
|
||||
{ 183, 181.80, 24.00 },
|
||||
{ 183, 176.40, 27.00 },
|
||||
{ 183, 171.00, 30.00 },
|
||||
{ 183, 165.60, 33.00 },
|
||||
{ 183, 160.20, 36.00 },
|
||||
{ 183, 154.80, 39.00 },
|
||||
{ 183, 149.40, 42.00 },
|
||||
{ 183, 144.00, 45.00 },
|
||||
{ 183, 138.60, 48.00 },
|
||||
{ 183, 133.20, 51.00 },
|
||||
{ 183, 127.80, 54.00 },
|
||||
{ 183, 122.40, 57.00 },
|
||||
{ 183, 117.00, 60.00 },
|
||||
{ 183, 111.60, 63.00 },
|
||||
{ 183, 106.20, 66.00 },
|
||||
{ 183, 100.80, 69.00 },
|
||||
{ 183, 95.40, 72.00 },
|
||||
{ 183, 90.00, 75.00 },
|
||||
{ 183, 84.60, 78.00 },
|
||||
{ 183, 79.20, 81.00 },
|
||||
{ 183, 73.80, 84.00 },
|
||||
{ 183, 68.40, 87.00 },
|
||||
{ 183, 63.00, 90.00 },
|
||||
{ 183, 57.60, 93.00 },
|
||||
{ 183, 52.20, 96.00 },
|
||||
{ 183, 46.80, 99.00 },
|
||||
{ 183, 41.40, 102.00 },
|
||||
{ 183, 36.00, 105.00 },
|
||||
{ 183, 30.60, 108.00 },
|
||||
{ 183, 25.20, 111.00 },
|
||||
{ 183, 19.80, 114.00 },
|
||||
{ 183, 14.40, 117.00 },
|
||||
{ 183, 9.00, 120.00 },
|
||||
{ 183, 3.60, 123.00 },
|
||||
{ 183, 358.20, 126.00 },
|
||||
{ 183, 325.80, 129.00 },
|
||||
{ 183, 347.40, 132.00 },
|
||||
{ 183, 342.00, 135.00 },
|
||||
{ 183, 336.60, 138.00 },
|
||||
{ 183, 331.20, 141.00 },
|
||||
{ 183, 325.80, 144.00 },
|
||||
{ 183, 320.40, 147.00 },
|
||||
{ 183, 315.00, 150.00 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
// 100摄氏度的温度表读数
|
||||
static const ST_YB_TYPE g_YB_WSS100[] =
|
||||
{
|
||||
{ 183, 225.00, 0.00 },
|
||||
{ 183, 219.60, 2.00 },
|
||||
{ 183, 214.20, 4.00 },
|
||||
{ 183, 208.80, 6.00 },
|
||||
{ 183, 203.40, 8.00 },
|
||||
{ 183, 198.00, 10.00 },
|
||||
{ 183, 192.60, 12.00 },
|
||||
{ 183, 187.20, 14.00 },
|
||||
{ 183, 181.80, 16.00 },
|
||||
{ 183, 176.40, 18.00 },
|
||||
{ 183, 171.00, 20.00 },
|
||||
{ 183, 165.60, 22.00 },
|
||||
{ 183, 160.20, 24.00 },
|
||||
{ 183, 154.80, 26.00 },
|
||||
{ 183, 149.40, 28.00 },
|
||||
{ 183, 144.00, 30.00 },
|
||||
{ 183, 138.60, 32.00 },
|
||||
{ 183, 133.20, 34.00 },
|
||||
{ 183, 127.80, 36.00 },
|
||||
{ 183, 122.40, 38.00 },
|
||||
{ 183, 117.00, 40.00 },
|
||||
{ 183, 111.60, 42.00 },
|
||||
{ 183, 106.20, 44.00 },
|
||||
{ 183, 100.80, 46.00 },
|
||||
{ 183, 95.40, 48.00 },
|
||||
{ 183, 90.00, 50.00 },
|
||||
{ 183, 84.60, 52.00 },
|
||||
{ 183, 79.20, 54.00 },
|
||||
{ 183, 73.80, 56.00 },
|
||||
{ 183, 68.40, 58.00 },
|
||||
{ 183, 63.00, 60.00 },
|
||||
{ 183, 57.60, 62.00 },
|
||||
{ 183, 52.20, 64.00 },
|
||||
{ 183, 46.80, 66.00 },
|
||||
{ 183, 41.40, 68.00 },
|
||||
{ 183, 36.00, 70.00 },
|
||||
{ 183, 30.60, 72.00 },
|
||||
{ 183, 25.20, 74.00 },
|
||||
{ 183, 19.80, 76.00 },
|
||||
{ 183, 14.40, 78.00 },
|
||||
{ 183, 9.00, 80.00 },
|
||||
{ 183, 3.60, 82.00 },
|
||||
{ 183, 361.80, 84.00 },
|
||||
{ 183, 356.40, 86.00 },
|
||||
{ 183, 351.00, 88.00 },
|
||||
{ 183, 345.60, 90.00 },
|
||||
{ 183, 340.20, 92.00 },
|
||||
{ 183, 334.80, 94.00 },
|
||||
{ 183, 329.40, 96.00 },
|
||||
{ 183, 324.00, 98.00 },
|
||||
{ 180, 318.60, 100.00 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
// 1.6MPa压力表读数
|
||||
static const ST_YB_TYPE g_YB_OCR17NI12MO2_16[] =
|
||||
{
|
||||
{ 183, 225.00, 0.00 },
|
||||
{ 183, 221.63, 0.02 },
|
||||
{ 183, 218.25, 0.04 },
|
||||
{ 183, 214.88, 0.06 },
|
||||
{ 183, 211.50, 0.08 },
|
||||
{ 183, 208.13, 0.10 },
|
||||
{ 183, 204.75, 0.12 },
|
||||
{ 183, 201.38, 0.14 },
|
||||
{ 183, 198.00, 0.16 },
|
||||
{ 183, 194.63, 0.18 },
|
||||
{ 183, 191.25, 0.20 },
|
||||
{ 183, 187.88, 0.22 },
|
||||
{ 183, 184.50, 0.24 },
|
||||
{ 183, 181.13, 0.26 },
|
||||
{ 183, 177.75, 0.28 },
|
||||
{ 183, 174.38, 0.30 },
|
||||
{ 183, 171.00, 0.32 },
|
||||
{ 183, 167.63, 0.34 },
|
||||
{ 183, 164.25, 0.36 },
|
||||
{ 183, 160.88, 0.38 },
|
||||
{ 183, 157.50, 0.40 },
|
||||
{ 183, 154.13, 0.42 },
|
||||
{ 183, 150.75, 0.44 },
|
||||
{ 183, 147.38, 0.46 },
|
||||
{ 183, 144.00, 0.48 }, // 144.74 - 0.5
|
||||
{ 183, 140.63, 0.50 },
|
||||
{ 183, 137.25, 0.52 },
|
||||
{ 183, 133.88, 0.54 },
|
||||
{ 183, 130.50, 0.56 },
|
||||
{ 183, 127.13, 0.58 },
|
||||
{ 183, 123.75, 0.60 },
|
||||
{ 183, 120.38, 0.62 },
|
||||
{ 183, 117.00, 0.64 },
|
||||
{ 183, 113.63, 0.66 },
|
||||
{ 183, 110.25, 0.68 },
|
||||
{ 183, 106.88, 0.70 },
|
||||
{ 183, 103.50, 0.72 },
|
||||
{ 183, 100.13, 0.74 },
|
||||
{ 183, 96.75, 0.76 },
|
||||
{ 183, 93.38, 0.78 },
|
||||
{ 183, 90.00, 0.80 },
|
||||
{ 183, 86.63, 0.82 },
|
||||
{ 183, 83.25, 0.84 },
|
||||
{ 183, 79.88, 0.86 },
|
||||
{ 183, 76.50, 0.88 },
|
||||
{ 183, 73.13, 0.90 },
|
||||
{ 183, 69.75, 0.92 },
|
||||
{ 183, 66.38, 0.94 },
|
||||
{ 183, 63.00, 0.96 },
|
||||
{ 183, 59.63, 0.98 },
|
||||
{ 183, 56.25, 1.00 },
|
||||
{ 183, 52.88, 1.02 },
|
||||
{ 183, 49.50, 1.04 },
|
||||
{ 183, 46.13, 1.06 },
|
||||
{ 183, 42.75, 1.08 },
|
||||
{ 183, 39.38, 1.10 },
|
||||
{ 183, 36.00, 1.12 },
|
||||
{ 183, 32.63, 1.14 },
|
||||
{ 183, 29.25, 1.16 },
|
||||
{ 183, 25.88, 1.18 },
|
||||
{ 183, 22.50, 1.20 },
|
||||
{ 183, 19.13, 1.22 },
|
||||
{ 183, 15.75, 1.24 },
|
||||
{ 183, 12.38, 1.26 },
|
||||
{ 183, 9.00, 1.28 },
|
||||
{ 183, 5.63, 1.30 },
|
||||
{ 183, 2.25, 1.32 },
|
||||
{ 183, 361.13, 1.34 },
|
||||
{ 183, 357.75, 1.36 },
|
||||
{ 183, 354.38, 1.38 },
|
||||
{ 183, 351.00, 1.40 },
|
||||
{ 183, 347.63, 1.42 },
|
||||
{ 183, 344.25, 1.44 },
|
||||
{ 183, 340.88, 1.46 },
|
||||
{ 183, 337.50, 1.48 },
|
||||
{ 183, 334.13, 1.50 },
|
||||
{ 183, 330.75, 1.52 },
|
||||
{ 183, 327.38, 1.54 },
|
||||
{ 183, 324.00, 1.56 },
|
||||
{ 183, 320.63, 1.58 },
|
||||
{ 180, 317.25, 1.60 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
|
||||
// 2.5MPa压力表读数
|
||||
static const ST_YB_TYPE g_YB_OCR17NI12MO2_25[] =
|
||||
{
|
||||
{ 183, 225.00, 0.00 },
|
||||
{ 183, 219.60, 0.05 },
|
||||
{ 183, 214.20, 0.10 },
|
||||
{ 183, 208.80, 0.15 },
|
||||
{ 183, 203.40, 0.20 },
|
||||
{ 183, 198.00, 0.25 },
|
||||
{ 183, 192.60, 0.30 },
|
||||
{ 183, 187.20, 0.35 },
|
||||
{ 183, 181.80, 0.40 },
|
||||
{ 183, 176.40, 0.45 },
|
||||
{ 183, 171.00, 0.50 },
|
||||
{ 183, 165.60, 0.55 },
|
||||
{ 183, 160.20, 0.60 },
|
||||
{ 183, 154.80, 0.65 },
|
||||
{ 183, 149.40, 0.70 },
|
||||
{ 183, 144.00, 0.75 },
|
||||
{ 183, 138.60, 0.80 },
|
||||
{ 183, 133.20, 0.85 },
|
||||
{ 183, 127.80, 0.90 },
|
||||
{ 183, 122.40, 0.95 },
|
||||
{ 183, 117.00, 1.00 },
|
||||
{ 183, 111.60, 1.05 },
|
||||
{ 183, 106.20, 1.10 },
|
||||
{ 183, 100.80, 1.15 },
|
||||
{ 183, 95.40, 1.20 },
|
||||
{ 183, 90.00, 1.25 },
|
||||
{ 183, 84.60, 1.30 },
|
||||
{ 183, 79.20, 1.35 },
|
||||
{ 183, 73.80, 1.40 },
|
||||
{ 183, 68.40, 1.45 },
|
||||
{ 183, 63.00, 1.50 },
|
||||
{ 183, 57.60, 1.55 },
|
||||
{ 183, 52.20, 1.60 },
|
||||
{ 183, 46.80, 1.65 },
|
||||
{ 183, 41.40, 1.70 },
|
||||
{ 183, 36.00, 1.75 },
|
||||
{ 183, 30.60, 1.80 },
|
||||
{ 183, 25.20, 1.85 },
|
||||
{ 183, 19.80, 1.90 },
|
||||
{ 183, 14.40, 1.95 },
|
||||
{ 183, 9.00, 2.00 },
|
||||
{ 183, 3.60, 2.05 },
|
||||
{ 183, 361.80, 2.10 },
|
||||
{ 183, 356.40, 2.15 },
|
||||
{ 183, 351.00, 2.20 },
|
||||
{ 183, 345.60, 2.25 },
|
||||
{ 183, 340.20, 2.30 },
|
||||
{ 183, 334.80, 2.35 },
|
||||
{ 183, 329.40, 2.40 },
|
||||
{ 183, 324.00, 2.45 },
|
||||
{ 183, 318.60, 2.50 },
|
||||
{ -1, 0, 0 }
|
||||
};
|
||||
#pragma pack (pop)
|
||||
|
||||
|
||||
//181 - 0 = 181
|
||||
//530 -
|
||||
//495
|
||||
//224
|
||||
//135
|
||||
//123
|
||||
//92
|
||||
|
||||
|
||||
//自定义直线
|
||||
class MyLine
|
||||
{
|
||||
public:
|
||||
int id; //编号
|
||||
int k; //倾斜角[0-360)
|
||||
int l; //长度
|
||||
public:
|
||||
MyLine(int ID = 0, int K = 0, int L = 0){ id = ID, k = K, l = L; } //构造函数
|
||||
|
||||
bool operator<(const MyLine &A) { return k < A.k; } //重定义小于号
|
||||
|
||||
void print(){ printf("id: %3d k: %3d° l: %3d\n", id, k, l); }//输出函数
|
||||
};
|
||||
|
||||
|
||||
//显示图片
|
||||
void showImg(const char *title, Mat &img);
|
||||
|
||||
//点到线段的距离
|
||||
double DistancetoSegment(Point P, Point A, Point B);
|
||||
//向量模长
|
||||
double Length(Point A);
|
||||
|
||||
double gtest(double du, double base, int linelen); // for test
|
||||
|
||||
// 读取仪表指针数值
|
||||
//double dReadPointValue(const char *tbale_type, const char *jpg_file, double base);
|
||||
double dReadPointValue_JSY10(ST_OPENCV_CONF *stConf, const char *jpg_file);
|
||||
double dReadPointValue_3EX5050(ST_OPENCV_CONF *stConf, const char *jpg_file);
|
||||
//double dReadPointValue_YZF250TH_T4(ST_OPENCV_CONF *stConf, const char *jpg_file);
|
||||
double dReadPointValues(ST_OPENCV_CONF *stConf, const char *jpg_file);
|
||||
//double dGetReadValueOfYZFTH(double du, double base, int linelen);
|
||||
|
||||
/*
|
||||
pPath : path, eg: /usr/local/img/*.jpg
|
||||
: "D:\\Photo and Video\\destop1\\*.jpg";
|
||||
*/
|
||||
int iGetImgFileList(const char *pPath, std::vector<cv::String> & image_files);
|
||||
|
||||
// 播放视频流
|
||||
int showRtspVideoStream(const char* rtsp_url);
|
||||
int showRtspVideoStreams(const char *rtsp_url);
|
||||
|
||||
// 截取图片指定区域并保存
|
||||
// isReplace = true: 覆盖原文件,不保留原文件,文件名不变
|
||||
// = false: 保留原文件,并将截图文件命名为 xxx_cut.xxx
|
||||
//int vCutImageSave(char* path_filename, int shigh, int ehigh, int swidth, int ewidth, bool isReplace);
|
||||
int vCutImageSave(ST_OPENCV_CONF *stConf, char* path_filename);
|
||||
|
||||
// 仪表盘的单位转换
|
||||
double dChangeUnits(unsigned char *sersorid, double inVal);
|
||||
|
||||
// 图片识别处理线程
|
||||
void* thread_opencv_proc(void * arg);
|
||||
|
||||
bool bBakFilename(char *filename, char *pBakPath);
|
||||
|
||||
|
||||
double dReadPointValue_Wss411_150_T1(ST_OPENCV_CONF *stConf, const char *jpg_file);
|
||||
|
||||
#endif // !__HT_OPENCV_IMG_H_
|
||||
|
@ -0,0 +1,226 @@
|
||||
/****************************************************************************
|
||||
** File name : HTPublic.h
|
||||
** Description : define common api
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_PUBLIC_H
|
||||
#define __HT_PUBLIC_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma comment(lib,"ws2_32.lib")
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h> /* timespec{} for pselect() */
|
||||
#include <errno.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h> /* for nonblocking */
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include "HTType.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#include <winsock2.h>
|
||||
#include <objbase.h>
|
||||
#include <guiddef.h>
|
||||
#else
|
||||
#include <sys/io.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h> /* sockaddr_in{} and other Internet defns */
|
||||
#include <arpa/inet.h> /* inet(3) functions */
|
||||
#include <netdb.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/time.h>
|
||||
#include <pthread.h>
|
||||
#include <strings.h>
|
||||
#include <dirent.h>
|
||||
#include <asm/unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <uuid/uuid.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
#if defined(__linux__) && defined(__NR_gettid)
|
||||
#define GETTID() syscall(__NR_gettid)
|
||||
#else
|
||||
#define GETTID() getpid()
|
||||
#endif
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#define GETTID() GetCurrentThreadId() // 获取线程ID
|
||||
#define GETPID() GetCurrentProcessId() // 获取主进程ID
|
||||
#else
|
||||
#define GETTID() syscall(__NR_gettid)
|
||||
#define GETPID() getpid() // 获取主进程ID
|
||||
#endif
|
||||
|
||||
#define DEF_PID_FILE "../run/pid_file.pid" // 程序主进程ID文件
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void vSetPid();
|
||||
int iGetPid();
|
||||
|
||||
// 时间函数
|
||||
void vGetHostTime (char *pszTime) ;
|
||||
time_t vGetHostTimeFmt (char *pszTime) ;
|
||||
time_t vGetHostTimeFmtBeforBay(char *pszTime, int beforbay);
|
||||
void vTranHostTimeFmt (time_t t, char *pszTime);
|
||||
time_t strTime2int(char *pszTime);
|
||||
time_t strTimeFmt2int(char *pszTime);
|
||||
void getCurrentBefor360Hour(char *pstime, char *petime);
|
||||
time_t vGeOneDayTimeFmt(char *pSTime, char *pETime);
|
||||
void vFormatTimes(char *pszInTimeStr, char *pszOutFormatTime);
|
||||
time_t getUTCLongTime (void) ;
|
||||
void getUTCFmtTime (char *pszTime) ;
|
||||
void UTC2FmtTime (time_t utc, char *pszTime) ;
|
||||
void UTC2LocalTime (time_t utc, char *pszTime) ;
|
||||
void diffTimes(unsigned int c, char *pszTime);
|
||||
unsigned int uiTime (void) ;
|
||||
int getCurrTimeDiff(unsigned char *bcd_t) ;
|
||||
|
||||
time_t local2Utc(unsigned char *pTime, int iLen);
|
||||
time_t local2UtcTime(time_t localTime);
|
||||
|
||||
int getuuid(char *str, int inlen);
|
||||
|
||||
void vGetHostTimeOnMillsecond(char *pszTime); // 获取时间,YYYYMMDDHH24MISS:MLSS
|
||||
time_t vGetHostTimeFmtOnMillsecond(char *pszTime); // 获取时间,YYYY-MM-DD HH24:MI:SS+MLSS
|
||||
|
||||
unsigned int getWarnID(unsigned char *pTime, int iLen, unsigned int id);
|
||||
|
||||
|
||||
// 目录操作函数
|
||||
int iDirOrFileExist(const char *pszName);
|
||||
int iBuildDirent(const char *pName);
|
||||
int iSplitNumberFiled(char *pstr, char node, int no);
|
||||
int iSplitStringFiled(char *pstr, char node, char no, char *pFiled);
|
||||
int get_file_size(const char *path);
|
||||
int getFileCreateTime(const char *path, char *pCreateTime);
|
||||
|
||||
bool bSplitFilenameByFullPath(char *pFullPath, char *pPrantPath, char *pFilename, char *pExt);
|
||||
// 将Linux文件路径转为Windows的路径格式
|
||||
void Unix2WindowPath(char *pszPath);
|
||||
void Window2UnixPath(char *pszPath);
|
||||
void getGnssData(unsigned char *p_date);
|
||||
void getGnssTime(unsigned char *p_time);
|
||||
void setPostionDate(unsigned char *pDate, unsigned char *pTime);
|
||||
void setPostionTime(unsigned char *pDate, unsigned char *pTime);
|
||||
|
||||
int iTrimVersionHeadChar(char *strver);
|
||||
void LRTrim(unsigned char *str);
|
||||
int RigthTrim(unsigned char *str);
|
||||
int LeftTrim(unsigned char *str);
|
||||
void MiddleTrim(unsigned char *str);
|
||||
bool isStringDigit(char *pstr);
|
||||
|
||||
int stringcasecmp(const char *ps1, const char *ps2);
|
||||
int stringncasecmp(const char *ps1, const char *ps2, int length);
|
||||
|
||||
int bits_check(unsigned char *map, int field_no);
|
||||
|
||||
void getDateFromTime(char* p_time,char* p_date);
|
||||
void getTimeFromTime(char* p_time,char* p_times);
|
||||
|
||||
void bcd_to_asc(unsigned char *pusFrom, unsigned int uiFromLen,unsigned char *pusTo);
|
||||
void asc_to_bcd(unsigned char *pusFrom, unsigned int uiFromLen, unsigned char *pusTo);
|
||||
|
||||
unsigned int htoni(unsigned int us);
|
||||
unsigned int ntohi(unsigned int us);
|
||||
double getRandByTime();
|
||||
|
||||
#ifdef ntohll
|
||||
utint64 ntohll(utint64 arg64) ;
|
||||
#endif
|
||||
#ifdef htonll
|
||||
utint64 htonll(utint64 arg64) ;
|
||||
#endif
|
||||
unsigned int int64To32(utint64 u64);
|
||||
void LocalTime2Bcd(char *pLocalTime, char *pBcd);
|
||||
|
||||
int getStringLen(unsigned char *pstr, int length);
|
||||
int getHexString(unsigned char *str, int length, unsigned char *pstr);
|
||||
|
||||
/*************************************************************************
|
||||
Function : 32位整数转二进制字符串
|
||||
Param in :
|
||||
num : source uint
|
||||
Param out :
|
||||
pBin : object strings.(min length = 32)
|
||||
Return Code : none
|
||||
*************************************************************************/
|
||||
void uint32_binstr(unsigned int num, char* pBin);
|
||||
|
||||
/*************************************************************************
|
||||
Function : 64位整数转二进制字符串
|
||||
Param in :
|
||||
num : source uint
|
||||
Param out :
|
||||
pBin : object strings.(min length = 64)
|
||||
Return Code : none
|
||||
*************************************************************************/
|
||||
void uint64_binstr(utint64 num, char* pBin);
|
||||
|
||||
/*************************************************************************
|
||||
Function : 二进制字符串转32位整数
|
||||
Param in :
|
||||
pBin : source bin string(eg. 1010101001111), need '\0' end.
|
||||
Param out :
|
||||
: none
|
||||
Return Code : uint32 interger
|
||||
*************************************************************************/
|
||||
unsigned int binstr_uint32(char *pBin);
|
||||
|
||||
/*************************************************************************
|
||||
Function : 二进制字符串转64位整数
|
||||
Param in :
|
||||
pBin : source bin string(eg. 1010101001111), need '\0' end.
|
||||
Param out :
|
||||
: none
|
||||
Return Code : utint64 interger
|
||||
*************************************************************************/
|
||||
utint64 binstr_uint64(char *pBin);
|
||||
|
||||
/*************************************************************************
|
||||
Function : 字符串反转
|
||||
Param in :
|
||||
str : source string(eg. 1010101001111), need '\0' end.
|
||||
len : source length
|
||||
Param out :
|
||||
: str
|
||||
Return Code : str, null is faild
|
||||
*************************************************************************/
|
||||
char* strSwap(char* szT,int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // end __HT_PUBLIC_H
|
||||
|
@ -0,0 +1,97 @@
|
||||
/****************************************************************************
|
||||
** File name : HTTcpSocket.h
|
||||
** Description : define common api for tcp socket
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_TCP_SOCKET_H
|
||||
#define __HT_TCP_SOCKET_H
|
||||
|
||||
#include "HTPublic.h"
|
||||
//#include <mstcpip.h>
|
||||
|
||||
static const int MAX_SEND_INFO = 512; //最大发送包长度
|
||||
static const int MAX_SBUFF_TCP = 2048; //发送最大包长度
|
||||
// static const int MAX_DATA_INFO = 1024; //数据包做大长度
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef ECONNRESET
|
||||
#define ECONNRESET WSAECONNRESET //errno= 104 = Connection reset by peer
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INVALID_HANDLE
|
||||
#define INVALID_HANDLE -1 // 无效句柄
|
||||
#endif
|
||||
|
||||
/* socket listen number */
|
||||
#define LISTENQ 20
|
||||
#define MAX_TEMP_BUFFER_SIZE 2048
|
||||
|
||||
/* error code define */
|
||||
#define ErrOpenServer -1000 /* Open Server Fail */
|
||||
#define ErrSockParam -1001 /* Socket Param error */
|
||||
#define ErrSendFail -1002 /* send data fail or socket exception*/
|
||||
#define ErrRecvTimeOut -1003 /* recv data time out */
|
||||
#define ErrRecvFail -1004 /* recv data fail */
|
||||
#define ErrOpenFile -1005 /* open dest file fail */
|
||||
#define ErrSetSockOpt -1006 /* set socket options */
|
||||
#define ErrBindFail -1007 /* set socket bind fail*/
|
||||
#define ErrGetPeerIP -1008 /* Get PeerIP Fail */
|
||||
#define ErrListenFail -1009 /* socket listen error */
|
||||
#define ErrTimeStrFmt -1020 /* Input time string error */
|
||||
#define ErrEintr -1021 /* Interrupted system call,EINTR*/
|
||||
#define ErrException -1022 /* socket exceptions close */
|
||||
|
||||
|
||||
class TTcpSocket
|
||||
{
|
||||
public:
|
||||
void clear_tcp_buffer(int socket_fd, int nbytes);
|
||||
|
||||
bool tcpIsConnected(int sockid);
|
||||
|
||||
// 根据sockid获取源地址和源端口
|
||||
int getPeerInfo(int sockid, unsigned char *sip, unsigned short *sport);
|
||||
int getLocalSocketInfo(int sockid, unsigned char *sip, unsigned short *sport);
|
||||
|
||||
int tcpRecvBuffer(int sockid, char* pBuffer,int nMaxLength, int timeout=6);
|
||||
int tcpSendBuffer(int sockid, const char *pBuffer, int length);
|
||||
|
||||
int tcpAcceptSocket(int sockid);
|
||||
int tcpCloseSocket(int sockfd);
|
||||
int tcpOpenServer(const char *ip,unsigned short port);
|
||||
int tcpSetlinger(int sockid);
|
||||
int tcpSetNodelay(int sockid) ;
|
||||
int tcpConnect(const char *pszIP, short port, int iTimeout);
|
||||
void tcpSetServerfd(int fd);
|
||||
void tcpSetSockID(int fd);
|
||||
int tcpGetServerfd();
|
||||
int tcpGetSockID();
|
||||
|
||||
TTcpSocket();
|
||||
virtual ~TTcpSocket();
|
||||
|
||||
//长连接测试函数
|
||||
//bool tcpClient_Keep() ;
|
||||
private:
|
||||
#ifndef _WIN32
|
||||
void SetSocketMode(int sockid,int iMode=O_NONBLOCK) ; //O_NONBLOCK=04000
|
||||
#else
|
||||
void SetSocketMode(int sockid,int iMode=04000) ; //O_NONBLOCK=04000
|
||||
#endif
|
||||
private:
|
||||
unsigned short m_tcpPort;
|
||||
bool m_tcpConnected;
|
||||
int m_sockid;
|
||||
int m_server_fd;
|
||||
};
|
||||
|
||||
#endif // end __HT_TCP_SOCKET_H
|
||||
|
@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
** File name : HTTestOpencv.h
|
||||
** Description : define Opencv Test function
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_TESTOPENCV__H
|
||||
#define __HT_TESTOPENCV__H
|
||||
#pragma warning(disable: 4819)
|
||||
|
||||
#include "HTGlobal.h"
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv/cv.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#pragma pack (push ,1)
|
||||
|
||||
//OpencvDirTraverse.cpp : Defines the entry point for the console application.
|
||||
#ifdef _WIN32
|
||||
#pragma comment(lib,"opencv_world300d.lib")
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
|
||||
int HTCanny(char *filename);
|
||||
// 图片矫正
|
||||
void ImageRecify(const char* pInFileName);
|
||||
|
||||
void ImgRotate(const char *img_file);
|
||||
|
||||
void SendMessageOne(char *rtsp_url);
|
||||
|
||||
// 鼠标选取区域,实现截图功能并保持图片
|
||||
void vCutPicture(char *filename);
|
||||
|
||||
// 检测矩形
|
||||
int iCheckFangXiang(char *filename);
|
||||
|
||||
//检测圆方法
|
||||
int iCheckCircles(char *filename);
|
||||
|
||||
//检测直线方法
|
||||
int iCheckLine(char *filename);
|
||||
|
||||
|
||||
void CannyThreshold(int, void*);
|
||||
void vHoughLines(int, void*);
|
||||
void HTImgAnalys(const char *img_file);
|
||||
|
||||
|
||||
void vInitPress_OCR17NI12MO2_16();
|
||||
|
||||
#endif // !__HT_OPENCV_IMG_H_
|
||||
|
@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
** File name : HTThread.h
|
||||
** Description : define service threads
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_THREAD_H
|
||||
#define __HT_THREAD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
// 线程接口定义
|
||||
int HTInitThreadHandle(void);
|
||||
void HTFreeThreadHandle(void);
|
||||
void pthread_testcancels(void);
|
||||
|
||||
int ht_pthread_create_background(pthread_t *thread_handle, void *(*pfunc)(void *), void *data);
|
||||
|
||||
|
||||
|
||||
// void *thread_parser_proc(void * arg);
|
||||
// void *thread_opration_proc(void *arg) ;
|
||||
// void *thread_respone_proc(void *arg) ;
|
||||
//
|
||||
// void *thread_client_proc(void * arg);
|
||||
// void *thread_active_proc(void *arg) ;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // end __HT_THREAD_H
|
||||
|
@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
** File name : HTType.h
|
||||
** Description : define data type
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_TYPE_H
|
||||
#define __HT_TYPE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef int64
|
||||
typedef __int64 tint64;
|
||||
#endif
|
||||
#else
|
||||
#ifndef int64
|
||||
typedef long long tint64 ;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef utint64
|
||||
typedef unsigned __int64 utint64;
|
||||
#endif
|
||||
#else
|
||||
#ifndef utint64
|
||||
typedef unsigned long long utint64 ;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef uint
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
|
||||
#ifndef ulong
|
||||
typedef unsigned long ulong;
|
||||
#endif
|
||||
|
||||
#ifndef byte
|
||||
typedef unsigned char byte;
|
||||
#endif
|
||||
|
||||
#ifndef uchar
|
||||
typedef unsigned char uchar;
|
||||
#endif
|
||||
|
||||
#ifndef ushort
|
||||
typedef unsigned short ushort;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef pthread_t
|
||||
typedef unsigned long pthread_t;
|
||||
#endif
|
||||
/*#else // Linux
|
||||
#ifndef pthread_t
|
||||
typedef pthread_t pthread_t; // bits/pthreadtypes.h typedef unsigned long int pthread_t;
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
#endif // end __HT_TYPE_H
|
||||
|
@ -0,0 +1,24 @@
|
||||
/****************************************************************************
|
||||
** File name : HTUnit.h
|
||||
** Description : define const
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_UNIT_H
|
||||
#define __HT_UNIT_H
|
||||
|
||||
|
||||
// 计量单位转换
|
||||
double getChangeUnit(short Unit, short sysUnit, double val);
|
||||
|
||||
bool bCompare(double ov, double nv, double rate);
|
||||
|
||||
|
||||
#endif // end __HT_UNIT_H
|
||||
|
@ -0,0 +1,19 @@
|
||||
/****************************************************************************
|
||||
** File name : HTVersion.h
|
||||
** Description : define mutex type
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#ifndef __HT_VERSION_H
|
||||
#define __HT_VERSION_H
|
||||
|
||||
#define HT_VERSION_BUILD_ID "20200526"
|
||||
|
||||
#endif // end __HT_VERSION_H
|
||||
|
@ -0,0 +1,179 @@
|
||||
#ifndef __HX_IEC104_H
|
||||
#define __HX_IEC104_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "HTGlobal.h"
|
||||
|
||||
#define NS_IEC_104_YK_BASE_PORT 16
|
||||
#define NS_IEC104_YK_PERMIT_TIME 16
|
||||
|
||||
|
||||
#define NS_IEC_104_TOTAL_YX_TIMES 9
|
||||
#define NS_IEC_104_ONCE_YX 120
|
||||
#define NS_IEC_104_ONCE_YX_BYTES 120/8
|
||||
|
||||
#define NS_IEC_104_TOTAL_YC_TIMES 16
|
||||
#define NS_IEC_104_ONCE_YC 32
|
||||
|
||||
#define NS_IEC_104_TOTAL_YM_TIMES 8
|
||||
#define NS_IEC_104_ONCE_YM 16
|
||||
|
||||
#define NS_IEC_104_MIN_LENGTH 6
|
||||
#define NS_IEC_104_HEAD 0x68
|
||||
#define NS_IEC_104_STARTDT 0x04
|
||||
#define NS_IEC_104_STOPDT 0x10
|
||||
|
||||
#define NS_IEC_104_TESTFR 0x40
|
||||
#define NS_IEC_104_QCC_POSITION 15
|
||||
#define NS_IEC_104_TIME_POSITION 15
|
||||
|
||||
|
||||
|
||||
#define NS_IEC_104_REASONBYTE 2
|
||||
#define NS_IEC_104_ASDUADDRESSBYTE 2
|
||||
#define NS_IEC_104_INFORMATIONBYTE 3
|
||||
|
||||
|
||||
/* Location Which Bytes In Receive Buffer */
|
||||
#define NS_STARTREASON 8
|
||||
#define NS_STARTASDUADDRESS 10
|
||||
#define NS_STARTINFORMATION 12
|
||||
#define NS_STARTQUALIFIER 15
|
||||
#define NS_IEC_104_GROUP_BYTE 15
|
||||
|
||||
|
||||
#define NS_IEC104_GROUP_BEGIN 21
|
||||
#define NS_IEC104_GROUP_END 36
|
||||
|
||||
|
||||
|
||||
#define NS_IEC104_YX_START_OBJECT 0x01
|
||||
#define NS_IEC104_YC_START_OBJECT 0x701
|
||||
#define NS_IEC104_YCYX_OBJECT_INDEX 0x80
|
||||
|
||||
|
||||
|
||||
|
||||
#define NS_IEC104_SENDBUFFER 256
|
||||
#define NS_IEC104_RECEIVEBUFFER 128
|
||||
#define NS_CONNECTED 0x02
|
||||
#define NS_DISCONNECTED 0x20
|
||||
#define NS_IEC104_PERMIT_TIME 30
|
||||
|
||||
|
||||
#define NS_IEC104_MAX_K 12
|
||||
#define NS_IEC104_MAX_W 8
|
||||
#define NS_IEC104_MAX_GROUP 30
|
||||
|
||||
#define NS_IEC104_MAX_YC 512
|
||||
#define NS_IEC104_CHANGE_YC_CYCLE 16
|
||||
#define NS_IEC104_ONCE_YC_COUNT 32
|
||||
|
||||
#define OFF false
|
||||
|
||||
|
||||
typedef struct NS_IEC_104_NS_
|
||||
{
|
||||
struct sockaddr_in ServerAddress;
|
||||
int NsNewSocketId;
|
||||
unsigned char LinkState;
|
||||
unsigned long LinkValidTime;
|
||||
unsigned char Card;
|
||||
short Port;
|
||||
|
||||
unsigned char ReceiveBuffer[NS_IEC104_RECEIVEBUFFER];
|
||||
unsigned char SendBuffer[NS_IEC104_SENDBUFFER];
|
||||
short SendLength;
|
||||
short ReceiveLength;
|
||||
unsigned short ReceiveIndex;
|
||||
short ReceiveIndexLength;
|
||||
|
||||
unsigned char ApciCode;
|
||||
|
||||
unsigned char TransmitReason[2];
|
||||
unsigned char CommonAsduAddress[2];
|
||||
unsigned char InformationObject[4];
|
||||
unsigned char FormatType;
|
||||
unsigned char UCommand;
|
||||
unsigned char ReceiveHimNumber[2];
|
||||
unsigned short SendMeNumber;
|
||||
unsigned short ApduLength;
|
||||
unsigned char AsduType;
|
||||
unsigned char AsduQualifier;
|
||||
unsigned char Qcc;
|
||||
unsigned char FreezeSign;
|
||||
unsigned char PulseGroup;
|
||||
|
||||
unsigned char TimeSave[8];
|
||||
|
||||
unsigned char Table;
|
||||
unsigned short HasSendNumber;
|
||||
unsigned short NeedSendNumber;
|
||||
unsigned short LeftSendNumber;
|
||||
unsigned short K;
|
||||
unsigned short W;
|
||||
|
||||
|
||||
unsigned short ReceiveYkId;
|
||||
unsigned char YkCellAction;
|
||||
unsigned short YkCellNumber;
|
||||
unsigned short YkKgNumber;
|
||||
unsigned char YkNowState;
|
||||
unsigned short MediaNumber;
|
||||
unsigned char YkError;
|
||||
unsigned char YkYtType;
|
||||
unsigned char YkStartSign;
|
||||
unsigned long YkStartTime;
|
||||
unsigned short SystemState;
|
||||
unsigned char DataBuff[160];
|
||||
unsigned char SetTimeFlag;
|
||||
|
||||
unsigned char GroupSendBuffer[NS_IEC104_MAX_GROUP][NS_IEC104_SENDBUFFER];
|
||||
unsigned short GroupSendLength[NS_IEC104_MAX_GROUP];
|
||||
|
||||
short YcLastValue[NS_IEC104_MAX_YC];
|
||||
unsigned char YcNap[NS_IEC104_MAX_YC];
|
||||
unsigned char YcChangeCycle;
|
||||
unsigned short YcLibIndex;
|
||||
unsigned short YcChangeCount;
|
||||
unsigned char CosSign;
|
||||
unsigned char NetRunSign;
|
||||
unsigned char SetNetSign;
|
||||
|
||||
unsigned char TableNo;
|
||||
/*unsigned short XYxNum;
|
||||
|
||||
unsigned short XYmNum;*/
|
||||
unsigned short XYcNum;
|
||||
unsigned short XYcCycleNum;
|
||||
|
||||
} NS_IEC104_MAIN;
|
||||
|
||||
#define NS_IEC104_USE_CYCLE 5
|
||||
|
||||
typedef struct _CYCLE
|
||||
{
|
||||
time_t LastTime;
|
||||
time_t TimeNap ;
|
||||
time_t TimeSign;
|
||||
|
||||
}NS_SEND_TIME_NAP;
|
||||
|
||||
typedef struct _SYS_DATE
|
||||
{
|
||||
unsigned short NsYxTableNumber;
|
||||
unsigned short NsYmTableNumber;
|
||||
unsigned short NsYcTableNumber;
|
||||
}NS_SYSTEM_DATA_MODE ;
|
||||
|
||||
|
||||
NS_IEC104_MAIN NsIec104Struct;
|
||||
static NS_SEND_TIME_NAP NsIec104Cycle[NS_IEC104_USE_CYCLE];
|
||||
static unsigned short NsIec104Nap[NS_IEC104_USE_CYCLE]={/*5*/120,15,20,25,30};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,137 @@
|
||||
/****************************************************************************
|
||||
** File name : CP56Time.cpp
|
||||
** Description : CP56Time IEC 60870-5-104 time data type implementation
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyrigth By: xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#include "HTGlobal.h"
|
||||
|
||||
static const char *_FILE_ ="HTCP56Time.cpp";
|
||||
|
||||
// Constructor: decode CP56Time data
|
||||
CP56Time::CP56Time(unsigned char *data)
|
||||
{
|
||||
CP56TimeToTime(data, &stime);
|
||||
}
|
||||
|
||||
CP56Time::~CP56Time(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// return time string of CP56Time decoded
|
||||
//
|
||||
void CP56Time::GetTimeString(char *buf, size_t size)
|
||||
{
|
||||
sprintf(buf,"%2.2d-%2.2d-%4.4d %2.2d:%2.2d:%2.2d.%3.3d", stime.wDay,
|
||||
stime.wMonth, stime.wYear, stime.wHour, stime.wMinute,
|
||||
stime.wSecond, stime.wMilliseconds);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// return SYSTEMTIME structure of CP56Time decoded
|
||||
//
|
||||
SYSTEMTIME CP56Time::_GetSystemTime(void)
|
||||
{
|
||||
return stime;
|
||||
}
|
||||
|
||||
//
|
||||
// return FILETIME structure of CP56Time decoded
|
||||
//
|
||||
FILETIME CP56Time::_GetFileTime(void)
|
||||
{
|
||||
FILETIME ft = {0};
|
||||
//SystemTimeToFileTime(&stime, &ft);
|
||||
return ft;
|
||||
}
|
||||
|
||||
//
|
||||
// return CP56Time data of actual time.
|
||||
//
|
||||
void CP56Time::ActualTimeToCP56Time(unsigned char *data)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
//GetSystemTime(&st);
|
||||
TimeToCP56Time(&st, data);
|
||||
}
|
||||
|
||||
//
|
||||
// convert FILETIME to CP56Time
|
||||
//
|
||||
void CP56Time::TimeToCP56Time(FILETIME *ft, unsigned char *data)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
//FileTimeToSystemTime(ft, &st);
|
||||
TimeToCP56Time(&st, data);
|
||||
}
|
||||
|
||||
//
|
||||
// convert SYSTEMTIME to CP56Time
|
||||
//
|
||||
void CP56Time::TimeToCP56Time(SYSTEMTIME *st, unsigned char *data)
|
||||
{
|
||||
unsigned int m;
|
||||
m = st->wMilliseconds + 1000 * st->wSecond;
|
||||
data[0] = m & 0xFF;
|
||||
data[1] = (m & 0xFF00)>>8;
|
||||
data[2] = st->wMinute & 0x00FF; // add valid flag and genuine flag
|
||||
data[3] = st->wHour & 0x00FF; // add summer flag
|
||||
data[4] = ((st->wDayOfWeek%7)&0x03)<<5 | (st->wDay&0x1F);
|
||||
data[5] = st->wMonth & 0x0F;
|
||||
data[6] = st->wYear - 2000;
|
||||
}
|
||||
|
||||
//
|
||||
// convert CP56Time to FILETIME
|
||||
//
|
||||
void CP56Time::CP56TimeToTime(unsigned char *data, FILETIME *ft)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
CP56TimeToTime(data, &st);
|
||||
//SystemTimeToFileTime(&st, ft);
|
||||
}
|
||||
|
||||
//
|
||||
// convert CP56Time to SYSTEMTIME
|
||||
//
|
||||
void CP56Time::CP56TimeToTime(unsigned char *data, SYSTEMTIME *st)
|
||||
{
|
||||
unsigned int mili = data[0] | data[1]<<8;
|
||||
st->wSecond = mili / 1000;
|
||||
st->wMilliseconds = mili - st->wSecond*1000;
|
||||
|
||||
if(data[2] & 0x40)
|
||||
genuine = true;
|
||||
else
|
||||
genuine = false;
|
||||
|
||||
if(data[2] & 0x80)
|
||||
valid = true;
|
||||
else
|
||||
valid = false;
|
||||
|
||||
st->wMinute = data[2] & 0x3F;
|
||||
st->wHour = data[3] & 0x1F;
|
||||
|
||||
if(data[3] & 0x80)
|
||||
summer = true;
|
||||
else
|
||||
summer = false;
|
||||
|
||||
st->wDay = data[4] & 0x1F;
|
||||
st->wDayOfWeek = (data[4] & 0xE0 ) >> 5;
|
||||
if(st->wDayOfWeek) // if zero day of week not used.
|
||||
st->wDayOfWeek = (st->wDayOfWeek + 1)%7;
|
||||
st->wMonth = data[5] & 0x0F;
|
||||
st->wYear = 2000 + (data[6] & 0x7F);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,137 @@
|
||||
/****************************************************************************
|
||||
** File name : CP56Time2a.cpp
|
||||
** Description : CP56Time2a IEC 60870-5-104 time data type implementation
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyrigth By: xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#include "HTGlobal.h"
|
||||
|
||||
static const char *_FILE_ ="HTCP56Time2a.cpp";
|
||||
|
||||
// Constructor: decode CP56Time2a data
|
||||
CP56Time2a::CP56Time2a(unsigned char *data)
|
||||
{
|
||||
CP56Time2aToTime(data, &stime);
|
||||
}
|
||||
|
||||
CP56Time2a::~CP56Time2a(void)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// return time string of CP56Time2a decoded
|
||||
//
|
||||
void CP56Time2a::GetTimeString(char *buf, size_t size)
|
||||
{
|
||||
sprintf(buf,"%2.2d-%2.2d-%4.4d %2.2d:%2.2d:%2.2d.%3.3d", stime.wDay,
|
||||
stime.wMonth, stime.wYear, stime.wHour, stime.wMinute,
|
||||
stime.wSecond, stime.wMilliseconds);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// return SYSTEMTIME structure of CP56Time2a decoded
|
||||
//
|
||||
SYSTEMTIME CP56Time2a::_GetSystemTime(void)
|
||||
{
|
||||
return stime;
|
||||
}
|
||||
|
||||
//
|
||||
// return FILETIME structure of CP56Time2a decoded
|
||||
//
|
||||
FILETIME CP56Time2a::_GetFileTime(void)
|
||||
{
|
||||
FILETIME ft = {0};
|
||||
//SystemTimeToFileTime(&stime, &ft);
|
||||
return ft;
|
||||
}
|
||||
|
||||
//
|
||||
// return CP56Time2a data of actual time.
|
||||
//
|
||||
void CP56Time2a::ActualTimeToCP56Time(unsigned char *data)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
//GetSystemTime(&st);
|
||||
TimeToCP56Time2a(&st, data);
|
||||
}
|
||||
|
||||
//
|
||||
// convert FILETIME to CP56Time2a
|
||||
//
|
||||
void CP56Time2a::TimeToCP56Time2a(FILETIME *ft, unsigned char *data)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
//FileTimeToSystemTime(ft, &st);
|
||||
TimeToCP56Time2a(&st, data);
|
||||
}
|
||||
|
||||
//
|
||||
// convert SYSTEMTIME to CP56Time2a
|
||||
//
|
||||
void CP56Time2a::TimeToCP56Time2a(SYSTEMTIME *st, unsigned char *data)
|
||||
{
|
||||
unsigned int m;
|
||||
m = st->wMilliseconds + 1000 * st->wSecond;
|
||||
data[0] = m & 0xFF;
|
||||
data[1] = (m & 0xFF00)>>8;
|
||||
data[2] = st->wMinute & 0x00FF; // add valid flag and genuine flag
|
||||
data[3] = st->wHour & 0x00FF; // add summer flag
|
||||
data[4] = ((st->wDayOfWeek%7)&0x03)<<5 | (st->wDay&0x1F);
|
||||
data[5] = st->wMonth & 0x0F;
|
||||
data[6] = st->wYear - 2000;
|
||||
}
|
||||
|
||||
//
|
||||
// convert CP56Time2a to FILETIME
|
||||
//
|
||||
void CP56Time2a::CP56Time2aToTime(unsigned char *data, FILETIME *ft)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
CP56Time2aToTime(data, &st);
|
||||
//SystemTimeToFileTime(&st, ft);
|
||||
}
|
||||
|
||||
//
|
||||
// convert CP56Time2a to SYSTEMTIME
|
||||
//
|
||||
void CP56Time2a::CP56Time2aToTime(unsigned char *data, SYSTEMTIME *st)
|
||||
{
|
||||
unsigned int mili = data[0] | data[1]<<8;
|
||||
st->wSecond = mili / 1000;
|
||||
st->wMilliseconds = mili - st->wSecond*1000;
|
||||
|
||||
if(data[2] & 0x40)
|
||||
genuine = true;
|
||||
else
|
||||
genuine = false;
|
||||
|
||||
if(data[2] & 0x80)
|
||||
valid = true;
|
||||
else
|
||||
valid = false;
|
||||
|
||||
st->wMinute = data[2] & 0x3F;
|
||||
st->wHour = data[3] & 0x1F;
|
||||
|
||||
if(data[3] & 0x80)
|
||||
summer = true;
|
||||
else
|
||||
summer = false;
|
||||
|
||||
st->wDay = data[4] & 0x1F;
|
||||
st->wDayOfWeek = (data[4] & 0xE0 ) >> 5;
|
||||
if(st->wDayOfWeek) // if zero day of week not used.
|
||||
st->wDayOfWeek = (st->wDayOfWeek + 1)%7;
|
||||
st->wMonth = data[5] & 0x0F;
|
||||
st->wYear = 2000 + (data[6] & 0x7F);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,690 @@
|
||||
/****************************************************************************
|
||||
** File name : HTConfig.cpp
|
||||
** Description : config parameter
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
//#include "StdAfx.h"
|
||||
#include "HTPublic.h"
|
||||
#include "HTConst.h"
|
||||
#include "HTConfig.h"
|
||||
#include "HTLogger.h"
|
||||
|
||||
static const char *_FILE_ = "HTConfig.cpp" ;
|
||||
|
||||
TConfig::TConfig()
|
||||
{
|
||||
b_monitor_enable = false ; // 监控标志 true:启用 false: 不启用
|
||||
|
||||
// database config parameter
|
||||
memset(m_dbHostIP,0x00, sizeof(m_dbHostIP));
|
||||
memset(m_dbName, 0x00, sizeof(m_dbName));
|
||||
memset(m_dbUserName, 0x00, sizeof(m_dbUserName));
|
||||
memset(m_dbUserPass, 0x00, sizeof(m_dbUserPass));
|
||||
|
||||
m_dbMaxConnect = 1 ;
|
||||
m_dbMinConnect = 1 ;
|
||||
m_dbPort = 3306 ;
|
||||
|
||||
|
||||
memset(m_remote_addr, 0x00, sizeof(m_remote_addr));
|
||||
m_remote_port = 2404 ;
|
||||
// socket config
|
||||
m_fd_limit = 1024 ;
|
||||
|
||||
|
||||
m_recv_num = 1 ;
|
||||
m_parse_num = 1 ;
|
||||
m_opration_num = 1;
|
||||
m_respone_num = 1 ;
|
||||
|
||||
}
|
||||
|
||||
TConfig::~TConfig()
|
||||
{
|
||||
b_monitor_enable = false ; // 监控标志 true:启用 false: 不启用
|
||||
|
||||
// database config parameter
|
||||
memset(m_dbHostIP,0x00, sizeof(m_dbHostIP));
|
||||
memset(m_dbName, 0x00, sizeof(m_dbName));
|
||||
memset(m_dbUserName, 0x00, sizeof(m_dbUserName));
|
||||
memset(m_dbUserPass, 0x00, sizeof(m_dbUserPass));
|
||||
|
||||
m_dbMaxConnect = 0 ;
|
||||
m_dbMinConnect = 0 ;
|
||||
m_dbPort = 3306 ;
|
||||
|
||||
memset(m_remote_addr, 0x00, sizeof(m_remote_addr));
|
||||
m_remote_port = 2404 ;
|
||||
|
||||
m_recv_num = 0 ;
|
||||
m_parse_num = 0 ;
|
||||
m_opration_num = 0;
|
||||
m_respone_num = 0 ;
|
||||
}
|
||||
|
||||
// 设置数据库连接端口
|
||||
void TConfig::setdbPort(unsigned int port)
|
||||
{
|
||||
m_dbPort= port;
|
||||
}
|
||||
|
||||
// 设置数据库连接端口
|
||||
unsigned int TConfig::getdbPort()
|
||||
{
|
||||
return m_dbPort;
|
||||
}
|
||||
|
||||
// 设置数据库主机地址
|
||||
void TConfig::setdbHostIP(char *pszDBHostIP)
|
||||
{
|
||||
if(!pszDBHostIP) return ;
|
||||
strcpy(m_dbHostIP, pszDBHostIP);
|
||||
}
|
||||
// 获取数据库主机地址
|
||||
char *TConfig::getdbHostIP()
|
||||
{
|
||||
return m_dbHostIP;
|
||||
}
|
||||
|
||||
// 设置数据库最大连接池数
|
||||
void TConfig::setdbMaxConnect(unsigned int max)
|
||||
{
|
||||
m_dbMaxConnect = max;
|
||||
}
|
||||
// 获取数据库最大连接池数
|
||||
unsigned int TConfig::getdbMaxConnect()
|
||||
{
|
||||
return m_dbMaxConnect;
|
||||
}
|
||||
|
||||
// 设置数据库最小连接池数
|
||||
void TConfig::setdbMinConnect(unsigned int min)
|
||||
{
|
||||
m_dbMinConnect = min;
|
||||
}
|
||||
// 获取数据库最小连接池数
|
||||
unsigned int TConfig::getdbMinConnect()
|
||||
{
|
||||
return m_dbMinConnect;
|
||||
}
|
||||
|
||||
// 设置数据库服务名称
|
||||
void TConfig::setdbName(char *pszDBName)
|
||||
{
|
||||
if(!pszDBName) return ;
|
||||
strcpy(m_dbName, pszDBName);
|
||||
}
|
||||
// 获取数据库服务名称
|
||||
char *TConfig::getdbName()
|
||||
{
|
||||
return m_dbName;
|
||||
}
|
||||
// 设置数据库用户名
|
||||
void TConfig::setdbUserName(char *pszDBUserName)
|
||||
{
|
||||
if(!pszDBUserName) return ;
|
||||
strcpy(m_dbUserName, pszDBUserName);
|
||||
}
|
||||
// 获取数据库用户名
|
||||
char *TConfig::getdbUserName()
|
||||
{
|
||||
return m_dbUserName;
|
||||
}
|
||||
|
||||
// 设置数据库用户密码
|
||||
void TConfig::setdbUserPass(char *pszDBUserPass)
|
||||
{
|
||||
if(!pszDBUserPass) return ;
|
||||
strcpy(m_dbUserPass, pszDBUserPass);
|
||||
}
|
||||
// 获取数据库用户密码
|
||||
char *TConfig::getdbUserPass()
|
||||
{
|
||||
return m_dbUserPass;
|
||||
}
|
||||
|
||||
// 设置本地服务器IP
|
||||
void TConfig::setLocalAddr(char *pszAddr)
|
||||
{
|
||||
if (!pszAddr) return;
|
||||
strcpy(m_local_addr, pszAddr);
|
||||
}
|
||||
// 获取本地服务器IP
|
||||
char *TConfig::getLocalAddr()
|
||||
{
|
||||
return m_local_addr;
|
||||
}
|
||||
|
||||
// 设置本地服务器端口
|
||||
void TConfig::setLocalPort(unsigned short iPort)
|
||||
{
|
||||
m_local_port = iPort;
|
||||
}
|
||||
|
||||
// 获取本地服务器端口
|
||||
unsigned short TConfig::getLocalPort()
|
||||
{
|
||||
return m_local_port;
|
||||
}
|
||||
|
||||
|
||||
// 设置远程服务器IP
|
||||
void TConfig::setRemoteAddr(char *pszAddr)
|
||||
{
|
||||
if(!pszAddr) return ;
|
||||
strcpy(m_remote_addr, pszAddr);
|
||||
}
|
||||
// 获取远程服务器IP
|
||||
char *TConfig::getRemoteAddr()
|
||||
{
|
||||
return m_remote_addr;
|
||||
}
|
||||
|
||||
// 设置远程服务器端口
|
||||
void TConfig::setRemotePort(unsigned short iPort)
|
||||
{
|
||||
m_remote_port = iPort;
|
||||
}
|
||||
|
||||
// 获取远程服务器端口
|
||||
unsigned short TConfig::getRemotePort()
|
||||
{
|
||||
return m_remote_port;
|
||||
}
|
||||
|
||||
// socket 相关属性参数配置
|
||||
void TConfig::setFdLimit(unsigned int iCount)
|
||||
{
|
||||
m_fd_limit = iCount;
|
||||
}
|
||||
|
||||
unsigned int TConfig::getFdLimit()
|
||||
{
|
||||
return m_fd_limit;
|
||||
}
|
||||
|
||||
void TConfig::setK(unsigned int k)
|
||||
{
|
||||
uK = k;
|
||||
}
|
||||
void TConfig::setW(unsigned int w)
|
||||
{
|
||||
uW = w;
|
||||
}
|
||||
unsigned int TConfig::getK()
|
||||
{
|
||||
return uK;
|
||||
}
|
||||
unsigned int TConfig::getW()
|
||||
{
|
||||
return uW;
|
||||
}
|
||||
void TConfig::setTimeout0(unsigned int t)
|
||||
{
|
||||
t0 = t;
|
||||
}
|
||||
void TConfig::setTimeout1(unsigned int t)
|
||||
{
|
||||
t1 = t;
|
||||
}
|
||||
unsigned int TConfig::getTimeout0()
|
||||
{
|
||||
return t0;
|
||||
}
|
||||
unsigned int TConfig::getTimeout1()
|
||||
{
|
||||
return t1;
|
||||
}
|
||||
void TConfig::setTimeout2(unsigned int t)
|
||||
{
|
||||
t2 = t;
|
||||
}
|
||||
unsigned int TConfig::getTimeout2()
|
||||
{
|
||||
return t2;
|
||||
}
|
||||
void TConfig::setTimeout3(unsigned int t)
|
||||
{
|
||||
t3 = t;
|
||||
}
|
||||
unsigned int TConfig::getTimeout3()
|
||||
{
|
||||
return t3;
|
||||
}
|
||||
|
||||
void TConfig::setLogDebug(char yes)
|
||||
{
|
||||
m_logdebug = yes; // debug logger
|
||||
}
|
||||
void TConfig::setLogError(char yes)
|
||||
{
|
||||
m_logerror = yes; //error logger
|
||||
}
|
||||
void TConfig::setLogWarning(char yes)
|
||||
{
|
||||
m_logwarning = yes; // warning logger
|
||||
}
|
||||
void TConfig::setLogPack(char yes)
|
||||
{
|
||||
m_logpack = yes; // package print logger
|
||||
}
|
||||
void TConfig::setLogConsole(char yes)
|
||||
{
|
||||
m_logconsole = yes; // console print logger
|
||||
}
|
||||
void TConfig::setLogMessage(char yes)
|
||||
{
|
||||
m_logmessage = yes; // message print logger
|
||||
}
|
||||
char TConfig::isLogDebug(void)
|
||||
{
|
||||
return m_logdebug; // debug logger
|
||||
}
|
||||
char TConfig::isLogError(void)
|
||||
{
|
||||
return m_logerror; //error logger
|
||||
}
|
||||
char TConfig::isLogWarning(void)
|
||||
{
|
||||
return m_logwarning ; // warning logger
|
||||
}
|
||||
char TConfig::isLogPack(void)
|
||||
{
|
||||
return m_logpack ; // package print logger
|
||||
}
|
||||
char TConfig::isLogConsole(void)
|
||||
{
|
||||
return m_logconsole; // console print logger
|
||||
}
|
||||
char TConfig::isLogMessage(void)
|
||||
{
|
||||
return m_logmessage; // message print logger
|
||||
}
|
||||
|
||||
void TConfig::setServerVersion(char *pver)
|
||||
{
|
||||
if(pver == NULL) {
|
||||
strcpy(m_version, "000.00.000");
|
||||
return ;
|
||||
}
|
||||
strcpy(m_version, pver);
|
||||
}
|
||||
char *TConfig::getServerVersion()
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
|
||||
//JT/T809 服务数据交换监控
|
||||
void TConfig::setMonitor(bool status)
|
||||
{
|
||||
b_monitor_enable = status;
|
||||
}
|
||||
bool TConfig::getMonitor()
|
||||
{
|
||||
return b_monitor_enable;
|
||||
}
|
||||
|
||||
void TConfig::setRecvThreadNumber(unsigned int n)
|
||||
{
|
||||
m_recv_num = n ;
|
||||
}
|
||||
unsigned int TConfig::getRecvThreadNumber()
|
||||
{
|
||||
return m_recv_num ;
|
||||
}
|
||||
|
||||
void TConfig::setParseThreadNumber(unsigned int n) // 解析104线程数
|
||||
{
|
||||
m_parse_num = n ;
|
||||
}
|
||||
unsigned int TConfig::getParseThreadNumber()
|
||||
{
|
||||
return m_parse_num ;
|
||||
}
|
||||
|
||||
void TConfig::setOprationThreadNumber(unsigned int n) // 入库线程数
|
||||
{
|
||||
m_opration_num = n ;
|
||||
}
|
||||
unsigned int TConfig::getOprationThreadNumber()
|
||||
{
|
||||
return m_opration_num ;
|
||||
}
|
||||
|
||||
void TConfig::setResponeThreadNumber(unsigned int n) // 应答线程数
|
||||
{
|
||||
m_respone_num = n ;
|
||||
}
|
||||
unsigned int TConfig::getResponeThreadNumber()
|
||||
{
|
||||
return m_respone_num ;
|
||||
}
|
||||
/*************************************************************************
|
||||
Function iniGetString
|
||||
Rectives a character string from the specified section in the
|
||||
specified inifile
|
||||
Param In :
|
||||
pszSection : address of section
|
||||
pszEntry : address of entry
|
||||
uiBufLen : size of destination buffer
|
||||
pszFileName: address of inifile name
|
||||
Param Out :
|
||||
pszRetBuf : destination buffer
|
||||
Return Code :
|
||||
0 : success
|
||||
<0 : failed
|
||||
*************************************************************************/
|
||||
int TConfig::iniGetString(const char *pszSection, const char *pszEntry, char *pszRetBuf, unsigned int uiBufLen)
|
||||
{
|
||||
FILE *fpIni;
|
||||
char szBuf[DEF_BUFFER_1K+1], *psz1, *psz2, *psz;
|
||||
int iSectFlag, iLen;
|
||||
|
||||
if((fpIni= fopen(HT_CONFIG_FILE,"r")) == NULL) return (-1);
|
||||
|
||||
/*** check section ***/
|
||||
iSectFlag= 0;
|
||||
while(!feof(fpIni)) {
|
||||
if (fgets(szBuf,DEF_BUFFER_1K,fpIni) == NULL) break;
|
||||
psz= szBuf;
|
||||
|
||||
while(*psz!='[' && *psz!='#' && *psz!='\0') psz++;
|
||||
if (*psz!='[') continue;
|
||||
psz++;
|
||||
while(*psz==' ' || *psz=='\t') psz++;
|
||||
psz1= psz;
|
||||
while(*psz!=']' && *psz!='\0') psz++;
|
||||
if (*psz=='\0') continue;
|
||||
while(*(psz-1)==' ' || *(psz-1)=='\t') psz--;
|
||||
*psz= '\0';
|
||||
if (!strcmp(psz1, pszSection)) {
|
||||
iSectFlag= 1;
|
||||
break;
|
||||
}
|
||||
}/*** while ***/
|
||||
if (!iSectFlag) {
|
||||
fclose(fpIni);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*** check entry ***/
|
||||
while(!feof(fpIni)) {
|
||||
if(fgets(szBuf,DEF_BUFFER_1K,fpIni) == NULL) break;
|
||||
psz= szBuf;
|
||||
while(*psz==' ' || *psz=='\t') psz++;
|
||||
if (*psz=='#' || *psz=='\0') continue;
|
||||
if (*psz=='[') break;
|
||||
|
||||
psz1= psz;
|
||||
while(*psz!='=' && *psz!='\0') psz++;
|
||||
if (*psz=='\0') continue;
|
||||
psz2= psz+1;
|
||||
if (psz1==psz) continue;
|
||||
while(*(psz-1)==' ' || *(psz-1)=='\t') psz--;
|
||||
*psz= '\0';
|
||||
|
||||
#ifdef _WIN32
|
||||
if(strcmp(psz1,pszEntry)) continue;
|
||||
#else
|
||||
if(strcasecmp(psz1, pszEntry)) continue;
|
||||
#endif
|
||||
fclose(fpIni);
|
||||
|
||||
psz= psz2;
|
||||
while(*psz==' ' || *psz=='\t') psz++;
|
||||
psz2= psz;
|
||||
while(*psz!='#' && *psz!='\0' && !(*psz=='/' && (*(psz+1)=='*'||*(psz+1)=='/'))) psz++;
|
||||
while(*(psz-1)==' ' || *(psz-1)=='\t' || *(psz-1)==0x0a || *(psz-1)==0x0d)
|
||||
{
|
||||
*(psz-1)= '\0';
|
||||
psz--;
|
||||
}
|
||||
//*psz= '\0';
|
||||
iLen= strlen(psz2);
|
||||
if (iLen==0) return (-1);
|
||||
if (iLen > (int)uiBufLen) iLen= uiBufLen;
|
||||
memcpy(pszRetBuf, psz2, iLen);
|
||||
*(pszRetBuf+iLen)= '\0';
|
||||
return (0);
|
||||
}
|
||||
fclose(fpIni);
|
||||
return (-1);
|
||||
}
|
||||
// 加载服务配置参数
|
||||
bool TConfig::getIniConfig()
|
||||
{
|
||||
int iRet = -1;
|
||||
char szTmp[64];
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_LOGGER","logger", szTmp, sizeof(szTmp))) < 0) {
|
||||
printf("get logger parameter failed, %s\n", szTmp);
|
||||
}
|
||||
|
||||
if(strstr(szTmp, "debug") == NULL) setLogDebug(0x00);
|
||||
else setLogDebug(0x01);
|
||||
|
||||
if(strstr(szTmp, "error") == NULL) setLogError(0x00);
|
||||
else setLogError(0x01);
|
||||
|
||||
if(strstr(szTmp, "warning") == NULL) setLogWarning(0x00);
|
||||
else setLogWarning(0x01);
|
||||
|
||||
if(strstr(szTmp, "package") == NULL) setLogPack(0x00);
|
||||
else setLogPack(0x01);
|
||||
|
||||
if(strstr(szTmp, "console") == NULL) setLogConsole(0x00);
|
||||
else setLogConsole(0x01);
|
||||
|
||||
if(strstr(szTmp, "message") == NULL) setLogMessage(0x00);
|
||||
else setLogMessage(0x01);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_MONITOR","monitor_enable", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get monitor_enable parameter failed");
|
||||
return false;
|
||||
}
|
||||
if(stringcasecmp(szTmp, "true") == 0)
|
||||
setMonitor(true); // 启用监控报文功能
|
||||
else setMonitor(false) ;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_VERSION","ht_server_version", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get ht_server_version parameter failed");
|
||||
return false;
|
||||
}
|
||||
setServerVersion(szTmp);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// 加载数据库配置参数
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_host_addr", szTmp, sizeof(szTmp))) < 0) {
|
||||
// vPrtLogMsg(LOG_ERROR, iRet, "get db_host_addr parameter failed");
|
||||
// return false;
|
||||
setdbHostIP((char*)"127.0.0.1");
|
||||
}
|
||||
else setdbHostIP(szTmp);
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_host_port", szTmp, sizeof(szTmp))) < 0) {
|
||||
//vPrtLogMsg(LOG_ERROR, iRet, "get db_host_port parameter failed");
|
||||
//return false;
|
||||
setdbPort(3306);
|
||||
}
|
||||
else setdbPort((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_name", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get db_name parameter failed");
|
||||
return false;
|
||||
}
|
||||
setdbName(szTmp);
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_username", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get db_username parameter failed");
|
||||
return false;
|
||||
}
|
||||
setdbUserName(szTmp);
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_password", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get db_password parameter failed");
|
||||
return false;
|
||||
}
|
||||
setdbUserPass(szTmp);
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_min_conn", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get db_min_conn parameter failed");
|
||||
return false;
|
||||
}
|
||||
setdbMinConnect((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_DATABASE","db_max_conn", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get db_max_conn parameter failed");
|
||||
return false;
|
||||
}
|
||||
setdbMaxConnect((unsigned int)atoi(szTmp));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// 加载服务器端参数
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if ((iRet = iniGetString("HT_LOCAL_HOST", "local_host_addr", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get local_host_addr parameter failed");
|
||||
return false;
|
||||
}
|
||||
setLocalAddr(szTmp);
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp)); // 服务器端口
|
||||
if ((iRet = iniGetString("HT_LOCAL_HOST", "local_tcp_port", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get local_tcp_port parameter failed,set define:2404!");
|
||||
strcpy(szTmp, "2404");
|
||||
//return false;
|
||||
}
|
||||
setLocalPort((unsigned int)atoi(szTmp));
|
||||
|
||||
// 加载服务器端参数
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_REMOTE_HOST","remote_host_addr", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get remote_host_addr parameter failed");
|
||||
return false;
|
||||
}
|
||||
setRemoteAddr(szTmp);
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp)); // 服务器端口
|
||||
if((iRet = iniGetString("HT_REMOTE_HOST","remote_host_port", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get remote_host_port parameter failed,set define:2404!");
|
||||
strcpy(szTmp, "2404") ;
|
||||
//return false;
|
||||
}
|
||||
setRemotePort((unsigned int)atoi(szTmp));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// socket 相关属性参数配置
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_SOCKET","max_epoll_limit", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get max_epoll_limit parameter failed");
|
||||
return false;
|
||||
}
|
||||
setFdLimit((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if ((iRet = iniGetString("HT_SOCKET", "timeout_t0", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get timeout_t0 parameter failed");
|
||||
return false;
|
||||
}
|
||||
setTimeout0((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_SOCKET","timeout_t1", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get timeout_t1 parameter failed");
|
||||
return false;
|
||||
}
|
||||
setTimeout1((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_SOCKET","timeout_t2", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get timeout_t2 parameter failed");
|
||||
return false;
|
||||
}
|
||||
setTimeout2((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_SOCKET","timeout_t3", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get timeout_t3 parameter failed");
|
||||
return false;
|
||||
}
|
||||
setTimeout3((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if ((iRet = iniGetString("HT_SOCKET", "iec_k", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get iec_k parameter failed");
|
||||
return false;
|
||||
}
|
||||
setK((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if ((iRet = iniGetString("HT_SOCKET", "iec_w", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get iec_w parameter failed");
|
||||
return false;
|
||||
}
|
||||
setW((unsigned int)atoi(szTmp));
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_THREAD_NUMBER","thread_recv_num", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get thread_recv_num parameter failed");
|
||||
return false;
|
||||
}
|
||||
setRecvThreadNumber((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_THREAD_NUMBER","thread_parse_num", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get thread_parse_num parameter failed");
|
||||
return false;
|
||||
}
|
||||
setParseThreadNumber((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp));
|
||||
if((iRet = iniGetString("HT_THREAD_NUMBER","thread_opration_num", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get thread_opration_num parameter failed");
|
||||
return false;
|
||||
}
|
||||
setOprationThreadNumber((unsigned int)atoi(szTmp));
|
||||
|
||||
memset(szTmp, 0x00, sizeof(szTmp)); //
|
||||
if((iRet = iniGetString("HT_THREAD_NUMBER","thread_respone_num", szTmp, sizeof(szTmp))) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, iRet, "get thread_respone_num parameter failed");
|
||||
return false;
|
||||
}
|
||||
setResponeThreadNumber((unsigned int)atoi(szTmp));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TConfig::showConfig()
|
||||
{
|
||||
// vPrtLogMsg(LOG_DEBUG, 0, "local_server_name=%s local_host_addr=%s local_tcp_port=%d\n"
|
||||
// "db_host_addr=%s db_port=%d db_name=%s db_username=%s db_password=%s\n"
|
||||
// "db_min_conn=%d db_max_conn=%d max_epoll_limit=%d loacl_active_interval=%d\n"
|
||||
// "local_tcp_recv_timeout=%d local_udp_recv_timeout=%d\n"
|
||||
// //"gov_user_name=%s gov_user_pass=%s gov_host_addr=%s gov_tcp_port=%d gov_tcp_recv_timeout=%d",
|
||||
// "gov_tcp_recv_timeout=%d",
|
||||
// m_LocalName, m_LocalAddr, m_LocalTcpPort,
|
||||
// m_dbHostIP,m_dbPort,m_dbName,m_dbUserName,m_dbUserPass,m_dbMinConnect,m_dbMaxConnect,
|
||||
// m_fd_limit,m_active_interval,m_tcp_recv_timeout,m_udp_recv_timeout,
|
||||
// //m_GovUserName,m_GovUserPass,m_GovHostAddr,m_GovTcpPort,m_GovTcpRecvTimeout);
|
||||
// m_GovTcpRecvTimeout);
|
||||
}
|
@ -0,0 +1,458 @@
|
||||
/****************************************************************************
|
||||
** File name : HTDatabase.cpp
|
||||
** Description : mysql database member function
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#include "HTGlobal.h"
|
||||
#include "HTDatabase.h"
|
||||
static const char *_FILE_ = "HTDatabase.cpp" ;
|
||||
|
||||
CDBMySQL::CDBMySQL()
|
||||
{
|
||||
strcpy(m_host,g_TConfig.getdbHostIP());
|
||||
strcpy(m_db, g_TConfig.getdbName());
|
||||
strcpy(m_user,g_TConfig.getdbUserName());
|
||||
strcpy(m_password,g_TConfig.getdbUserPass());
|
||||
m_port = g_TConfig.getdbPort();
|
||||
m_min = g_TConfig.getdbMinConnect();
|
||||
mutex_create(m_csList);
|
||||
}
|
||||
|
||||
CDBMySQL::CDBMySQL(const char *host, const char *user, const char *password, const char *db, unsigned int port/* =3306 */)
|
||||
{
|
||||
strcpy(m_host, host);
|
||||
strcpy(m_user, user);
|
||||
strcpy(m_password, password);
|
||||
strcpy(m_db, db);
|
||||
m_port = port;
|
||||
m_min = g_TConfig.getdbMinConnect();
|
||||
mutex_create(m_csList);
|
||||
}
|
||||
|
||||
CDBMySQL::~CDBMySQL()
|
||||
{
|
||||
dbFreeConnectPool();
|
||||
}
|
||||
|
||||
CDBMySQL* CDBMySQL::Instance()
|
||||
{
|
||||
if(p_dbHandle == NULL)
|
||||
{
|
||||
try {
|
||||
p_dbHandle = new CDBMySQL();
|
||||
}
|
||||
catch(...) {
|
||||
vPrtLogMsg(LOG_WARNG, RET_FAIL, "CDBMySQL::Instance exceptions.");
|
||||
}
|
||||
}
|
||||
return p_dbHandle;
|
||||
}
|
||||
void CDBMySQL::dbFreeConnectPool()
|
||||
{
|
||||
ITER_CONNECTION_HANDLE_LIST iter;
|
||||
for (iter=m_lsBusyList.begin(); iter != m_lsBusyList.end(); iter++)
|
||||
{
|
||||
mysql_close((*iter));
|
||||
}
|
||||
|
||||
for (iter=m_lsIdleList.begin(); iter != m_lsIdleList.end(); iter++)
|
||||
{
|
||||
mysql_close((*iter));
|
||||
}
|
||||
mysql_library_end();
|
||||
mutex_close(m_csList);
|
||||
}
|
||||
|
||||
bool CDBMySQL::dbConnectPool()
|
||||
{
|
||||
try
|
||||
{
|
||||
vPrtLogMsg(LOG_DEBUG,0, "connect database:%s/%s@%s -h %s:%d start...", m_user,m_password,m_db,m_host,m_port);
|
||||
for (int i=0; i < (int)m_min; ++i)
|
||||
{
|
||||
char value = 1;
|
||||
MYSQL *pMySql = mysql_init((MYSQL*)NULL);
|
||||
//mysql_options(pMySql, MYSQL_SET_CHARSET_NAME, "gbk");
|
||||
mysql_options(pMySql, MYSQL_OPT_RECONNECT, (char *)&value); //设置自动连接
|
||||
if (pMySql != NULL)
|
||||
{
|
||||
if (!mysql_real_connect(pMySql,m_host,m_user,m_password,m_db,m_port,NULL,0))
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR,errno, "connect database:%s/%s@%s -h %s:%d failed! err:%s", m_user,m_password,m_db,m_host,m_port, getLastError(pMySql));
|
||||
return false;
|
||||
}
|
||||
mysql_set_character_set(pMySql, "GBK");
|
||||
m_lsIdleList.push_back(pMySql);
|
||||
}
|
||||
else{
|
||||
vPrtLogMsg(LOG_ERROR,errno, "connect database:%s/%s@%s -h %s:%d failed! err:%s", m_user,m_password,m_db,m_host,m_port, getLastError(pMySql));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR,errno, "connect database:%s/%s@%s -h %s:%d failed!", m_user,m_password,m_db,m_host,m_port);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MYSQL* CDBMySQL::GetIdleMySql()
|
||||
{
|
||||
MYSQL* pMySql = NULL;
|
||||
|
||||
mutex_lock(m_csList);
|
||||
if (m_lsIdleList.size() > 0)
|
||||
{
|
||||
pMySql = m_lsIdleList.front();
|
||||
if (pMySql ) {
|
||||
m_lsIdleList.pop_front();
|
||||
m_lsBusyList.push_back(pMySql);
|
||||
mysql_ping(pMySql); // 检查连接是否正常
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pMySql = NULL;
|
||||
}
|
||||
mutex_unlock(m_csList);
|
||||
return pMySql;
|
||||
}
|
||||
|
||||
void CDBMySQL::SetIdleMysql(MYSQL* pMySql)
|
||||
{
|
||||
mutex_lock(m_csList);
|
||||
if (pMySql) {
|
||||
if (m_lsBusyList.size() > 0)
|
||||
m_lsBusyList.remove(pMySql);
|
||||
m_lsIdleList.push_back(pMySql);
|
||||
}
|
||||
mutex_unlock(m_csList);
|
||||
}
|
||||
//bStart = false : close auto commit
|
||||
// = true : open auto commit
|
||||
bool CDBMySQL::dbAutoCommit(MYSQL *pMysql, bool bStart) // 开始事务处理
|
||||
{
|
||||
return mysql_autocommit(pMysql, bStart) ? false : true;
|
||||
}
|
||||
|
||||
bool CDBMySQL::dbCommit(MYSQL *pMysql)
|
||||
{
|
||||
return mysql_commit(pMysql) ? false : true;
|
||||
}
|
||||
|
||||
MYSQL_RES* CDBMySQL::SelectRecord(const char *szSql)
|
||||
{
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(mysql_query(pMySql,szSql))
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR,errno, "SelectRecord failed! SQL:[%s] err:%s", szSql, getLastError(pMySql));
|
||||
SetIdleMysql(pMySql);
|
||||
return NULL;
|
||||
}
|
||||
MYSQL_RES *myquery = NULL;
|
||||
if(!(myquery = mysql_store_result(pMySql))) {
|
||||
vPrtLogMsg(LOG_ERROR,errno, "SelectRecord failed! SQL:[%s] err:%s", szSql, getLastError(pMySql));
|
||||
myquery = NULL;
|
||||
}
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return myquery;
|
||||
}
|
||||
|
||||
|
||||
bool CDBMySQL::InsertRecordBitch(const char pszSql[][256], int count)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
dbAutoCommit(pMySql, false); // 开始批量提交事务
|
||||
//mysql_query(pMySql, "START TRANSACTION"); // 开启事务, 如果没有开启事务,那么效率会变得非常低下!
|
||||
// return 0: successed !0: failed
|
||||
for (int n = 0; n < count; n++)
|
||||
{
|
||||
if (!mysql_query(pMySql, pszSql[n]))
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else {
|
||||
vPrtLogMsg(LOG_ERROR, errno, "InsertRecordBitch failed! ERROR SQL[%d]:[%s] err:%s", n+1, pszSql[n], getLastError(pMySql));
|
||||
}
|
||||
}
|
||||
dbCommit(pMySql);
|
||||
dbAutoCommit(pMySql, true); // 结束批量提交事务
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
||||
bool CDBMySQL::AddInsertRecord(MYSQL *pHandle, const char *szSql)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
// return 0: successed !0: failed
|
||||
if (!mysql_query(pHandle, szSql))
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else {
|
||||
vPrtLogMsg(LOG_ERROR, errno, "AddInsertRecord failed! SQL:[%s] err:%s", szSql, getLastError(pHandle));
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CDBMySQL::InsertRecord(const char *szSql)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// return 0: successed !0: failed
|
||||
if(!mysql_query(pMySql,szSql))
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else {
|
||||
vPrtLogMsg(LOG_ERROR,errno, "InsertRecord failed! SQL:[%s] err:%s", szSql, getLastError(pMySql));
|
||||
}
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CDBMySQL::UpdateRecord(const char *szSql)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!mysql_query(pMySql,szSql))
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else {
|
||||
vPrtLogMsg(LOG_ERROR,errno, "UpdateRecord failed! SQL:[%s] err:%s", szSql, getLastError(pMySql));
|
||||
}
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CDBMySQL::DelRecord(const char *szSql)
|
||||
{
|
||||
bool bRet = false;
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!mysql_query(pMySql,szSql))
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else {
|
||||
vPrtLogMsg(LOG_ERROR,errno, "DelRecord failed! SQL:[%s] err:%s", szSql, getLastError(pMySql));
|
||||
}
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CDBMySQL::SelectDB(const char *szDB)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
|
||||
if (pMySql == NULL) return false;
|
||||
|
||||
if (mysql_select_db(pMySql,szDB)) {
|
||||
vPrtLogMsg(LOG_ERROR,errno, "SelectDB failed! dbname:[%s] err:%s", szDB, getLastError(pMySql));
|
||||
bRet = false;
|
||||
}
|
||||
else bRet = true;
|
||||
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
my_ulonglong CDBMySQL::GetRowNum(MYSQL_RES *myquery)
|
||||
{
|
||||
return mysql_num_rows(myquery);
|
||||
}
|
||||
|
||||
MYSQL_ROW CDBMySQL::GetRecord(MYSQL_RES *myquery)
|
||||
{
|
||||
m_row = mysql_fetch_row(myquery);
|
||||
|
||||
return m_row;
|
||||
}
|
||||
|
||||
unsigned int CDBMySQL::GetFieldNum(MYSQL_RES *myquery)
|
||||
{
|
||||
return mysql_num_fields(myquery);
|
||||
}
|
||||
|
||||
void CDBMySQL::FreeRecord(MYSQL_RES *myquery)
|
||||
{
|
||||
mysql_free_result(myquery);
|
||||
}
|
||||
|
||||
//int CDBMySQL::CreateDB(char *db)
|
||||
//{
|
||||
// return mysql_create_db(&m_mysql,db);
|
||||
//}
|
||||
|
||||
void CDBMySQL::SeekData(MYSQL_RES *myquery, int offset)
|
||||
{
|
||||
mysql_data_seek(myquery,offset);
|
||||
}
|
||||
|
||||
|
||||
char * CDBMySQL::getLastError(MYSQL *pMySql)
|
||||
{
|
||||
return const_cast<char *>(mysql_error(pMySql));
|
||||
}
|
||||
|
||||
bool CDBMySQL::IsEnd(MYSQL_RES *myquery)
|
||||
{
|
||||
return (mysql_eof(myquery)?true:false);
|
||||
}
|
||||
|
||||
char* CDBMySQL::GetFieldName(MYSQL_RES *myquery, int FieldNum)
|
||||
{
|
||||
m_field = mysql_fetch_field_direct(myquery, FieldNum);
|
||||
|
||||
return m_field->name;
|
||||
}
|
||||
|
||||
char * CDBMySQL::GetClientInfo()
|
||||
{
|
||||
return const_cast<char *>(mysql_get_client_info());
|
||||
}
|
||||
|
||||
char* CDBMySQL::GetHostInfo()
|
||||
{
|
||||
char *p = NULL;
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
p = const_cast<char *>(mysql_get_host_info(pMySql));
|
||||
SetIdleMysql(pMySql);
|
||||
return p ;
|
||||
}
|
||||
|
||||
int CDBMySQL::GetProtocolInfo()
|
||||
{
|
||||
int iRet = 0;
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
iRet = mysql_get_proto_info(pMySql);
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return iRet;
|
||||
}
|
||||
|
||||
char* CDBMySQL::GetServerInfo()
|
||||
{
|
||||
static char szRet[1024] = {0};
|
||||
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
strcpy(szRet, const_cast<char *>(mysql_get_server_info(pMySql)));
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return szRet;
|
||||
}
|
||||
|
||||
char* CDBMySQL::GetState()
|
||||
{
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL) return NULL;
|
||||
|
||||
static char szRet[1024] = {0} ;
|
||||
strcpy(szRet,const_cast<char *>(mysql_stat(pMySql)));
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return szRet;
|
||||
}
|
||||
|
||||
bool CDBMySQL::SetCharset()
|
||||
{
|
||||
bool bRet = false;
|
||||
//char szSql[50] = {0};
|
||||
|
||||
//strcpy(szSql, "set names gb2312");
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL) return false;
|
||||
if(mysql_set_character_set(pMySql, "GBK"))
|
||||
//if (mysql_query(pMySql, szSql))
|
||||
bRet = true;
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
//LOCK TABLES tbl1 READ, tbl2 WRITE
|
||||
bool CDBMySQL::LockTable(const char *TableName, const char *Priority)
|
||||
{
|
||||
bool bRet = false;
|
||||
char szSql[50] = {0} ;
|
||||
|
||||
sprintf(szSql, "LOCK TABLES %s %s", TableName, Priority);
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
if (pMySql == NULL) return false;
|
||||
|
||||
if (mysql_query(pMySql, szSql))
|
||||
bRet = true;
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CDBMySQL::UnlockTable()
|
||||
{
|
||||
bool bRet = false;
|
||||
MYSQL *pMySql = GetIdleMySql();
|
||||
|
||||
if (pMySql == NULL) return false;
|
||||
|
||||
if(mysql_query(pMySql,"UNLOCK TABLES")) bRet = true;
|
||||
|
||||
SetIdleMysql(pMySql);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
** File name : FLTGlobal.h
|
||||
** Description : global variable define
|
||||
** Create date : 2012.10.10
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyrigth By: xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#pragma warning (disable:4786)
|
||||
//#include "StdAfx.h"
|
||||
#include "HTGlobal.h"
|
||||
|
||||
TConfig g_TConfig ;
|
||||
TTcpSocket g_Tcp;
|
||||
int g_Running;
|
||||
|
||||
ST_IEC104_CTRL g_IecCtrl; // socket linker info and status
|
||||
mutex g_IecCtrl_mutex; // socket linker on mutex
|
||||
|
||||
int g_seqno; // 与MEC之间交换的流水号
|
||||
mutex g_seq_mutex; // 流水号
|
||||
|
||||
map<string, ST_BYQWORK_STATUS> g_map_work; // 主变工作状态缓存
|
||||
mutex g_map_work_mutex; // 主变工作状态缓存队列锁
|
||||
|
||||
//map<string,ST_BYQ_CACHE> g_map_byq; // 变压器缓存数据
|
||||
map<string, ST_BYQ_RUN_STATE_THRESHOLD> g_map_thres_byq;
|
||||
mutex g_map_byq_mutex; // 变压器缓存数据信息队列锁
|
||||
|
||||
//map<string,ST_GIS_CACHE> g_map_gis; // GIS缓存数据
|
||||
//mutex g_map_gis_mutex; // GIS缓存数据信息队列锁
|
||||
|
||||
multimap<string, ST_DEV_RELATION> g_map_relation; // 主设备与外挂设备关系
|
||||
mutex g_map_relation_mutex; // GIS缓存数据信息队列锁
|
||||
|
||||
//map<string, ST_GIS_IEC104_DATA> g_map_gis_104; // GIS最近一次104上传数据缓存
|
||||
//mutex g_map_gis_104_mutex;
|
||||
|
||||
//map<string, ST_BLQ_CACHE> g_map_blq; // BLQ缓存数据
|
||||
//mutex g_map_blq_mutex; // BLQ缓存数据信息队列锁
|
||||
|
||||
map<unsigned int, ST_IECPOINT_TABLE> g_map_iec; // 104点表报文解析缓存数据
|
||||
mutex g_map_iec_mutex; // 104报文解析缓存数据信息队列锁
|
||||
|
||||
map<unsigned int, ST_SADR_MATCH> g_map_sadr; // 点表匹配关系
|
||||
mutex g_map_sadr_mutex;
|
||||
|
||||
map<string, ST_IMG_THRESHOLD> g_map_img_thres; // 图片识别阈值
|
||||
mutex g_map_img_thres_mutex;
|
||||
|
||||
map<string, ST_DEVICE_TIME_STAT> g_map_dev_time_stat;
|
||||
mutex g_map_dev_time_stat_mutex;
|
||||
|
||||
map<unsigned int, ST_BREAK_EQM_CODE> g_map_gis_state; // 断路器状态位与电流电压关系匹配表
|
||||
mutex g_map_gis_state_mutex;
|
||||
|
||||
|
||||
pthread_t thread_handle_parse; // 104报文解析线程
|
||||
//pthread_t thread_handle_setdb; // 入库线程
|
||||
pthread_t thread_handle_timer; // 超时监测线程
|
||||
//pthread_t thread_handle_getdata; // 数据提取线程
|
||||
|
||||
pthread_t thread_handle_client; // 客户端链接线程
|
||||
pthread_t thread_handle_warning; // 报警处理及入库线程句柄
|
||||
pthread_t thread_handle_origin; // 原始数据如何线程句柄
|
||||
pthread_t thread_handle_pingce; // IEC104评测数据入库线程句柄
|
||||
pthread_t thread_handle_gishold; // 断路器断开数据入库线程句柄
|
||||
|
||||
pthread_t thread_handle_active; // 心跳线程
|
||||
pthread_t thread_handle_linkmgr; // 链路管理线程
|
||||
pthread_t thread_handle_cache; // 内存同步线程句柄
|
||||
|
||||
pthread_t thread_handle_opecvimg; // 图片识别线程句柄
|
||||
|
@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
** File name : HTInitUtils.cpp
|
||||
** Description : Defines service initialization API
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#include "HTGlobal.h"
|
||||
#include "HTInitUtils.h"
|
||||
|
||||
static const char *_FILE_ = "HTInitUtils.cpp" ;
|
||||
|
||||
// make and get a globle seq number
|
||||
int get_seqno(void)
|
||||
{
|
||||
int iseq = 0;
|
||||
mutex_lock(g_seq_mutex);
|
||||
iseq = ++g_seqno ;
|
||||
if(g_seqno >= 255 )
|
||||
g_seqno = 0;
|
||||
mutex_unlock(g_seq_mutex);
|
||||
return iseq;
|
||||
}
|
||||
|
||||
int loadServiceEvent()
|
||||
{
|
||||
// 初始化日志共享资源锁
|
||||
vInitLogMutex(); // 初始化log文件锁与句柄
|
||||
mutex_create(g_seq_mutex);
|
||||
mutex_create(g_IecCtrl_mutex);
|
||||
mutex_create(g_map_byq_mutex);
|
||||
//mutex_create(g_map_gis_mutex);
|
||||
//mutex_create(g_map_blq_mutex);
|
||||
//mutex_create(g_map_gis_104_mutex);
|
||||
mutex_create(g_map_iec_mutex);
|
||||
mutex_create(g_map_relation_mutex);
|
||||
mutex_create(g_map_sadr_mutex);
|
||||
mutex_create(g_map_img_thres_mutex);
|
||||
mutex_create(g_map_work_mutex);
|
||||
mutex_create(g_map_dev_time_stat_mutex);
|
||||
mutex_create(g_map_gis_state_mutex);
|
||||
memset(&g_IecCtrl, 0x00, sizeof(ST_IEC104_CTRL));
|
||||
g_Running = 1 ; // 服务启动标志
|
||||
g_TConfig.getIniConfig();
|
||||
IEC104EnvLoad();
|
||||
if(!CDBMySQL::Instance()->dbConnectPool()) {
|
||||
vFreeLogMutex(); // 释放log文件锁与句柄
|
||||
mutex_close(g_seq_mutex);
|
||||
mutex_close(g_IecCtrl_mutex);
|
||||
mutex_close(g_map_byq_mutex);
|
||||
//mutex_close(g_map_gis_mutex);
|
||||
//mutex_close(g_map_blq_mutex);
|
||||
//mutex_close(g_map_gis_104_mutex);
|
||||
mutex_close(g_map_iec_mutex);
|
||||
mutex_close(g_map_relation_mutex);
|
||||
mutex_close(g_map_sadr_mutex);
|
||||
mutex_close(g_map_img_thres_mutex);
|
||||
mutex_close(g_map_work_mutex);
|
||||
mutex_close(g_map_dev_time_stat_mutex);
|
||||
mutex_close(g_map_gis_state_mutex);
|
||||
IEC104EnvFree();
|
||||
g_Running = 0 ;
|
||||
return RET_FAIL;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
// 重新从数据库加载配置
|
||||
void reloadServiceEvent(int platform_id)
|
||||
{
|
||||
//TDatabase* g_TDatabase = NULL;
|
||||
//g_TDatabase = TDatabase::Instance();
|
||||
}
|
||||
|
||||
int unLoadServiceEvent()
|
||||
{
|
||||
CDBMySQL::Instance()->dbFreeConnectPool();
|
||||
g_Running = 0 ;
|
||||
HTFreeThreadHandle();
|
||||
// 释放日志共享资源锁
|
||||
|
||||
mutex_close(g_seq_mutex);
|
||||
mutex_close(g_IecCtrl_mutex);
|
||||
mutex_close(g_map_byq_mutex);
|
||||
// mutex_close(g_map_gis_mutex);
|
||||
// mutex_close(g_map_blq_mutex);
|
||||
//mutex_close(g_map_gis_104_mutex);
|
||||
mutex_close(g_map_iec_mutex);
|
||||
mutex_close(g_map_relation_mutex);
|
||||
mutex_close(g_map_sadr_mutex);
|
||||
mutex_close(g_map_img_thres_mutex);
|
||||
mutex_close(g_map_work_mutex);
|
||||
mutex_close(g_map_dev_time_stat_mutex);
|
||||
mutex_close(g_map_gis_state_mutex);
|
||||
IEC104EnvFree();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,283 @@
|
||||
/****************************************************************************
|
||||
** File name : FLTLogger.cpp
|
||||
** Description : logger function define
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************
|
||||
|
||||
++++++++++ 关于64位整数的打印说明 ++++++++++
|
||||
(1) windows os
|
||||
printf("int_64 = %I64d\n", int64); -- 打印有符号64位整数
|
||||
printf("int_64 = %I64u\n", int64); -- 打印无符号64位整数
|
||||
|
||||
(2) Linux os
|
||||
printf("int_64 = %lld\n", int64); -- 打印有符号64位整数
|
||||
printf("int_64 = %llu\n", int64); -- 打印无符号64位整数
|
||||
|
||||
****************************************************************************/
|
||||
//#include "StdAfx.h"
|
||||
#include "HTGlobal.h"
|
||||
#include "HTPublic.h"
|
||||
#include "HTLogger.h"
|
||||
|
||||
static const char *_FILE_="HTLogger.cpp";
|
||||
static char g_logger_time[15] ; // 日志文件名称时间(YYYYMMDD)
|
||||
|
||||
/* mutex define */
|
||||
static mutex mutex_Debug ; //跟踪日志
|
||||
static FILE *g_fp;
|
||||
/****************************************************************
|
||||
** Description : 初始化日志文件句柄锁
|
||||
** param in : None
|
||||
** :
|
||||
** param out : None
|
||||
** return code : None
|
||||
****************************************************************/
|
||||
void vInitLogMutex(void)
|
||||
{
|
||||
char szFile[DEF_BUFFER_256];
|
||||
|
||||
mutex_create(mutex_Debug);
|
||||
|
||||
// 创建日志文件并打开文件
|
||||
memset(szFile, 0x00, sizeof(szFile)) ;
|
||||
memset(g_logger_time, 0x00, sizeof(g_logger_time)); // 记录当前日志文件的时间(YYYYMMDD)
|
||||
vGetHostTime(g_logger_time) ;
|
||||
|
||||
#ifdef _WIN32
|
||||
sprintf(szFile,"%s\\debug%.8s.log", DEF_LOG_PATH_NAME,g_logger_time) ;
|
||||
#else
|
||||
sprintf(szFile,"%s/debug%.8s.log",DEF_LOG_PATH_NAME, g_logger_time) ;
|
||||
#endif
|
||||
if(iDirOrFileExist(DEF_LOG_PATH_NAME) != 0) {
|
||||
//文件或目录不存在时, 创建文件或目录
|
||||
if(iBuildDirent(DEF_LOG_PATH_NAME) != 0) {
|
||||
printf("line:%d file:%s Create Directory:[%s] failed.\n",__LINE__,_FILE_, DEF_LOG_PATH_NAME);
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_fp = fopen((const char*)szFile, (const char*)"a+");
|
||||
if(NULL == g_fp) {
|
||||
printf("line:%d file:%s Can't open file:[%s] failed.\n",__LINE__,_FILE_, szFile);
|
||||
return;
|
||||
}
|
||||
if(iDirOrFileExist(DEF_RUN_INFO_PATH) != 0) {
|
||||
//文件或目录不存在时, 创建文件或目录
|
||||
if((iBuildDirent(DEF_RUN_INFO_PATH)) != 0) {
|
||||
vPrtLogMsg(LOG_ERROR, errno, "Create Directory:[%s] failed,%s.", DEF_RUN_INFO_PATH,strerror(errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
/****************************************************************
|
||||
** Description : 释放日志文件句柄锁
|
||||
** param in : None
|
||||
** :
|
||||
** param out : None
|
||||
** return code : None
|
||||
****************************************************************/
|
||||
void vFreeLogMutex(void)
|
||||
{
|
||||
mutex_close(mutex_Debug);
|
||||
if(g_fp) fclose(g_fp);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
** Description : 打印错误日志
|
||||
** param in : iLine -- 行号
|
||||
** : *szFileName -- 文件名
|
||||
** : *szErrMsg -- 错误信息
|
||||
** : iCode -- 报文代码 或 错误码
|
||||
** param out : None
|
||||
** return code :
|
||||
** : None
|
||||
** : None
|
||||
**********************************************************************/
|
||||
void vPrtLogMsg(int line, const char *pszFileName, char logLevel, int iCode, /* const char *pszMsg,*/ ...)
|
||||
{
|
||||
char szTime[30],szFile[DEF_BUFFER_128]; // 128
|
||||
char *p=NULL, szBuf[DEF_BUFFER_2K+1];
|
||||
va_list vl ;
|
||||
|
||||
if(logLevel == __LOG_DEBUG ) {
|
||||
if(g_TConfig.isLogDebug() == 0x00 /*&& g_TConfig.isLogConsole() == 0x00 && g_TConfig.isLogMessage() == 0x00 */) return;
|
||||
}
|
||||
else if(logLevel == __LOG_WARNG) {
|
||||
if(g_TConfig.isLogWarning() == 0x00 /*&& g_TConfig.isLogConsole() == 0x00 && g_TConfig.isLogMessage() == 0x00 */) return;
|
||||
}
|
||||
else if(logLevel == __LOG_ERROR) {
|
||||
if(g_TConfig.isLogError() == 0x00 /*&& g_TConfig.isLogConsole() == 0x00 && g_TConfig.isLogMessage() == 0x00 */) return;
|
||||
}
|
||||
|
||||
if(g_fp == NULL) return ;
|
||||
mutex_lock(mutex_Debug); //lock
|
||||
|
||||
//fseek(g_fp, 0l, SEEK_END) ;
|
||||
vGetHostTime(szTime) ;
|
||||
// if( ftell(g_fp) >= DEF_LOG_FILESZIE) { // 日志大小已经制定字节数时备份文件,并重新打开新文件
|
||||
if( memcmp(szTime, g_logger_time, 8) != 0x00 ) { // 检查日志文件的时间是否为同一天,不是同一天时,重新产生新一天的日志文件名称
|
||||
fclose(g_fp) ;
|
||||
|
||||
char szNFile[DEF_BUFFER_256];
|
||||
memset(szNFile, 0x00, sizeof(szNFile)) ;
|
||||
#ifdef _WIN32
|
||||
sprintf(szNFile, "%s\\debug%.12s.bak", DEF_LOG_PATH_NAME,szTime) ;
|
||||
sprintf(szFile, "%s\\debug%.8s.log", DEF_LOG_PATH_NAME,szTime) ;
|
||||
#else
|
||||
sprintf(szNFile, "%s/debug%.12s.bak", DEF_LOG_PATH_NAME,szTime) ;
|
||||
sprintf(szFile, "%s/debug%.8s.log",DEF_LOG_PATH_NAME, szTime) ;
|
||||
#endif
|
||||
rename(szFile, szNFile) ;
|
||||
if((g_fp = fopen(szFile,"a+")) == NULL) {
|
||||
mutex_unlock(mutex_Debug); //unlock
|
||||
printf("line:%d file:%s Can't open file:[%s] failed.\n",__LINE__,_FILE_, szFile);
|
||||
return ;
|
||||
}
|
||||
strncpy(g_logger_time, szTime, 14); // 记录最近一次变更过的时间(YYYYMMDD)
|
||||
}
|
||||
memset(szTime,0,sizeof(szTime)) ;
|
||||
memset(szBuf, 0x00, sizeof(szBuf));
|
||||
|
||||
vGetHostTimeFmt(szTime);
|
||||
|
||||
if(logLevel == __LOG_DEBUG) { // 跟踪日志
|
||||
//if(g_TConfig.isLogConsole() == 0x00)
|
||||
fprintf(g_fp,"[%s] [DEBUG]-%ld Line:%d %s --> RetCode:%d ",szTime, GETTID(),line, pszFileName, iCode);
|
||||
sprintf(szBuf,"[%s] [DEBUG]-%ld Line:%d %s --> RetCode:%d ",szTime, GETTID(),line, pszFileName, iCode);
|
||||
}
|
||||
else if(logLevel == __LOG_WARNG) { // 告警日志
|
||||
//if(g_TConfig.isLogConsole() == 0x00)
|
||||
fprintf(g_fp,"[%s] [WARNING]-%ld Line:%d %s --> RetCode:%d ",szTime, GETTID(),line, pszFileName, iCode);
|
||||
sprintf(szBuf,"[%s] [WARNING]-%ld Line:%d %s --> RetCode:%d ",szTime, GETTID(),line, pszFileName, iCode);
|
||||
}
|
||||
else if(logLevel == __LOG_ERROR) { // 错误日志
|
||||
//if(g_TConfig.isLogConsole() == 0x00)
|
||||
fprintf(g_fp,"[%s] [ERROR]-%ld Line:%d %s --> RetCode:%d ",szTime, GETTID(),line, pszFileName, iCode);
|
||||
sprintf(szBuf,"[%s] [ERROR]-%ld Line:%d %s --> RetCode:%d ",szTime, GETTID(),line, pszFileName, iCode);
|
||||
}
|
||||
if(g_TConfig.isLogConsole() == 0x01) { // 屏幕输出
|
||||
printf("%s ", szBuf) ;
|
||||
}
|
||||
va_start(vl, iCode);
|
||||
|
||||
while((p = va_arg(vl, char *))) {
|
||||
#ifdef _WIN32
|
||||
_vsnprintf(szBuf, sizeof(szBuf), p, vl);
|
||||
#else
|
||||
vsnprintf(szBuf, sizeof(szBuf), p, vl);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
va_end(vl);
|
||||
if(g_TConfig.isLogConsole() == 0x01) { // 屏幕输出
|
||||
printf("%s\n", szBuf) ;
|
||||
}
|
||||
fprintf(g_fp,"%s\n",szBuf);
|
||||
fflush(g_fp);
|
||||
|
||||
mutex_unlock(mutex_Debug); //unlock
|
||||
}
|
||||
/*************************************************************************
|
||||
** Description : 打印日志文件(16进制数据报文的打印)
|
||||
** param in : iLine -- 打印的出处,行号
|
||||
** : *szFileName -- 文件名
|
||||
** : *pszTitle -- 主题提示信息
|
||||
** : *pusMsg -- 报文数据
|
||||
** : uiMsgLen -- 报文长度
|
||||
** param out : None
|
||||
** return code : None
|
||||
************************************************************************/
|
||||
void vPrtLogHex(int line, const char *pszFileName,char logLevel, int sockid, /* unsigned short msg_id, */
|
||||
const char pszMsgType, unsigned char *pusMsg,int uiMsgLen)
|
||||
{
|
||||
int i, j;
|
||||
char szBuf1[80+1], szBuf2[80+1];
|
||||
char szTime[20+1], szHex[3+1];
|
||||
char szFile[DEF_BUFFER_256];
|
||||
char szTitle[1024]={0};
|
||||
|
||||
if(g_TConfig.isLogPack() == 0x00) return ;
|
||||
|
||||
if(g_fp == NULL) return ;
|
||||
mutex_lock(mutex_Debug); //lock
|
||||
|
||||
//fseek(g_fp, 0l, SEEK_END) ;
|
||||
vGetHostTime(szTime) ;
|
||||
if( memcmp(szTime, g_logger_time, 8) != 0x00) { // 检查日志文件的时间是否为同一天,不是同一天时,重新产生新一天的日志文件名称
|
||||
// if(ftell(g_fp) >= DEF_LOG_FILESZIE) {
|
||||
fclose(g_fp) ;
|
||||
|
||||
char szNFile[DEF_BUFFER_256];
|
||||
memset(szNFile, 0x00, sizeof(szNFile)) ;
|
||||
#ifdef _WIN32
|
||||
sprintf(szNFile, "%s\\debug%.12s.bak", DEF_LOG_PATH_NAME,szTime) ;
|
||||
sprintf(szFile, "%s\\debug%.8s.log",DEF_LOG_PATH_NAME, szTime) ;
|
||||
#else
|
||||
sprintf(szNFile, "%s/debug%.12s.bak", DEF_LOG_PATH_NAME,szTime) ;
|
||||
sprintf(szFile, "%s/debug%.8s.log",DEF_LOG_PATH_NAME, szTime) ;
|
||||
#endif
|
||||
rename(szFile, szNFile) ;
|
||||
if((g_fp = fopen(szFile,"a+")) == NULL) {
|
||||
mutex_unlock(mutex_Debug); //unlock
|
||||
printf("line:%d file:%s Can't open file:[%s] failed.\n",__LINE__, _FILE_, szFile);
|
||||
return ;
|
||||
}
|
||||
strncpy(g_logger_time, szTime,14); // 记录最近一次变更过的时间(YYYYMMDD)
|
||||
}
|
||||
vGetHostTimeFmt( szTime ) ; /* 获取系统时间 */
|
||||
if(pszMsgType == PRT_PACK_SEND) {
|
||||
fprintf(g_fp, "[%s] [DEBUG]-%ld Line:%d %s --> [SendData] sockid:%d length:%d\n",szTime, GETTID(),line,pszFileName,sockid,uiMsgLen);
|
||||
sprintf(szTitle, "[%s] [DEBUG]-%ld Line:%d %s --> [SendData] sockid:%d length:%d\n",szTime, GETTID(),line,pszFileName,sockid,uiMsgLen);
|
||||
}
|
||||
else if(pszMsgType == PRT_PACK_RECV) {
|
||||
fprintf(g_fp, "[%s] [DEBUG]-%ld Line:%d %s --> [RecvData] sockid:%d length:%d\n",szTime, GETTID(),line,pszFileName,sockid,uiMsgLen);
|
||||
sprintf(szTitle, "[%s] [DEBUG]-%ld Line:%d %s --> [RecvData] sockid:%d length:%d\n",szTime, GETTID(),line,pszFileName,sockid,uiMsgLen);
|
||||
}
|
||||
else {
|
||||
fprintf(g_fp, "[%s] [DEBUG]-%ld Line:%d %s --> [PrntData] sockid:%d length:%d\n",szTime, GETTID(),line,pszFileName,sockid,uiMsgLen);
|
||||
sprintf(szTitle, "[%s] [DEBUG]-%ld Line:%d %s --> [PrntData] sockid:%d length:%d\n",szTime, GETTID(),line,pszFileName,sockid,uiMsgLen);
|
||||
}
|
||||
if(g_TConfig.isLogConsole() == 0x01) { // 屏幕输出
|
||||
printf("%s", szTitle);
|
||||
}
|
||||
sprintf(szTitle, "[%s] [DEBUG]-%ld Line:%d %s", szTime,GETTID(),line,pszFileName) ;
|
||||
|
||||
for(i=0; i<uiMsgLen; i+=16, pusMsg+=16)
|
||||
{
|
||||
memset(szBuf1, 0, sizeof(szBuf1));
|
||||
sprintf(szBuf1, "%04XH ",i);
|
||||
memset(szBuf2, 0, sizeof(szBuf2));
|
||||
for(j=0; j<16; j++)
|
||||
{
|
||||
if( (uiMsgLen-i) < 16 && j >= (uiMsgLen%16) )
|
||||
break;
|
||||
sprintf(szHex, "%02X ", pusMsg[j]&0xFF);
|
||||
strcat(szBuf1, szHex);
|
||||
if(j==7)
|
||||
strcat(szBuf1, " ");
|
||||
if(pusMsg[j]>0x20 && pusMsg[j]<0x0ff)
|
||||
szBuf2[j] = pusMsg[j];
|
||||
else
|
||||
szBuf2[j] = '_';
|
||||
}
|
||||
for(; j<16; j++)
|
||||
{
|
||||
if(j==7)
|
||||
strcat(szBuf1, " ");
|
||||
strcat(szBuf1, " ");
|
||||
}
|
||||
fprintf(g_fp, "%s --> %s %s\n", szTitle, szBuf1, szBuf2);
|
||||
if(g_TConfig.isLogConsole() == 0x01) { // 屏幕输出
|
||||
printf("%s --> %s %s\n", szTitle, szBuf1, szBuf2);
|
||||
}
|
||||
}
|
||||
fflush(g_fp); // 写入文件
|
||||
mutex_unlock(mutex_Debug); //unlock
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,518 @@
|
||||
/****************************************************************************
|
||||
** File name : FLTTcpSocket.h
|
||||
** Description : define common api for tcp socket
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
// #include "StdAfx.h"
|
||||
#include <errno.h>
|
||||
#include "HTGlobal.h"
|
||||
#include "HTTcpSocket.h"
|
||||
|
||||
static const char *_FILE_ ="HTTcpSocket.cpp" ;
|
||||
|
||||
TTcpSocket::TTcpSocket()
|
||||
{
|
||||
m_tcpPort = 0 ;
|
||||
m_server_fd = -1;
|
||||
m_sockid = -1;
|
||||
#ifdef _WIN32
|
||||
WSADATA Data ;
|
||||
WSAStartup(MAKEWORD(2, 2), &Data) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
TTcpSocket::~TTcpSocket()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void TTcpSocket::tcpSetServerfd(int fd)
|
||||
{
|
||||
if (fd > 0) m_server_fd = fd;
|
||||
}
|
||||
void TTcpSocket::tcpSetSockID(int fd)
|
||||
{
|
||||
if (fd > 0) m_sockid = fd;
|
||||
}
|
||||
|
||||
int TTcpSocket::tcpGetServerfd()
|
||||
{
|
||||
return m_server_fd;
|
||||
}
|
||||
int TTcpSocket::tcpGetSockID()
|
||||
{
|
||||
return m_sockid;
|
||||
}
|
||||
//关闭socket
|
||||
int TTcpSocket::tcpCloseSocket(int sockfd)
|
||||
{
|
||||
if(sockfd > 0) {
|
||||
#ifdef _WIN32
|
||||
//if(_close(sockfd) == -1)
|
||||
if(shutdown(sockfd, 2) == -1)
|
||||
#else
|
||||
if(close(sockfd) == -1)
|
||||
#endif
|
||||
// vPrtLogMsg(LOG_WARNG, RET_FAIL, "_close sockid=%d return:%d:%s",sockfd, errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
void TTcpSocket::SetSocketMode(int sockid, int iMode)
|
||||
{
|
||||
//将SOCKET置为非阻塞的I/O
|
||||
#ifndef _WIN32
|
||||
if (fcntl(sockid, F_SETFL, (fcntl(sockid, F_GETFL) | O_NONBLOCK)) == -1) {
|
||||
vPrtLogMsg(LOG_WARNG, errno,"error occured when fcntl,sockid:%d msg:%s.",sockid, strerror(errno));
|
||||
return ;
|
||||
}
|
||||
#else
|
||||
unsigned long flag = iMode ; //0:阻塞模式 1:非阻塞方式
|
||||
if((ioctlsocket(sockid, FIONBIO, &flag)) < 0) {
|
||||
vPrtLogMsg(LOG_WARNG, errno,"error occured when ioctlsocket,sockid:%d msg:%s.",sockid, strerror(errno));
|
||||
return ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// 根据sockid获取源地址和源端口
|
||||
int TTcpSocket::getPeerInfo(int sockid, unsigned char *sip, unsigned short *sport)
|
||||
{
|
||||
if(sockid < 0) return -1;
|
||||
struct sockaddr_in clientaddr;
|
||||
#ifndef _WIN32
|
||||
socklen_t clilen =sizeof(struct sockaddr_in); ;
|
||||
#else
|
||||
int clilen = sizeof(struct sockaddr_in) ;
|
||||
#endif
|
||||
|
||||
if(getpeername(sockid, (struct sockaddr *)&clientaddr, &clilen) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, errno, "getpeername failed, sockid=%d", sockid);
|
||||
return -1;
|
||||
}
|
||||
strcpy((char*)sip, inet_ntoa(clientaddr.sin_addr));
|
||||
*sport = ntohs(clientaddr.sin_port);
|
||||
return 0;
|
||||
}
|
||||
// 根据sockid获取目标地址和目标端口
|
||||
int TTcpSocket::getLocalSocketInfo(int sockid, unsigned char *sip, unsigned short *sport)
|
||||
{
|
||||
if(sockid < 0) return -1;
|
||||
struct sockaddr_in clientaddr;
|
||||
#ifndef _WIN32
|
||||
socklen_t clilen =sizeof(struct sockaddr_in); ;
|
||||
#else
|
||||
int clilen = sizeof(struct sockaddr_in) ;
|
||||
#endif
|
||||
|
||||
if(getsockname(sockid, (struct sockaddr *)&clientaddr, &clilen) < 0) {
|
||||
vPrtLogMsg(LOG_ERROR, errno, "getpeername failed, sockid=%d", sockid);
|
||||
return -1;
|
||||
}
|
||||
strcpy((char*)sip, inet_ntoa(clientaddr.sin_addr));
|
||||
*sport = ntohs(clientaddr.sin_port);
|
||||
return 0;
|
||||
}
|
||||
//创建socket TCP服务。
|
||||
// return val : 0 -- successed
|
||||
// : <0 -- failed
|
||||
int TTcpSocket::tcpOpenServer(const char *ip,unsigned short port)
|
||||
{
|
||||
int m_sockfd = -1;
|
||||
|
||||
if(!(port > 1024 && port < 65535) )
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, ErrSockParam, "server port:%d is invalid(1024-65535)", port);
|
||||
return ErrSockParam;
|
||||
}
|
||||
|
||||
m_tcpPort = port;
|
||||
setvbuf(stdin,NULL,_IONBF,MAX_SBUFF_TCP);
|
||||
setvbuf(stdout, NULL, _IONBF, MAX_SBUFF_TCP);
|
||||
|
||||
//创建SOCKET对象
|
||||
m_sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(m_sockfd == -1)
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, ErrOpenServer, "create socket error,msg:%s.",strerror(errno));
|
||||
return ErrOpenServer;
|
||||
}
|
||||
|
||||
//将SOCKET置为非阻塞的I/O
|
||||
// SetSocketMode(m_sockfd) ;
|
||||
|
||||
struct sockaddr_in fsock;
|
||||
int iRet = -1;
|
||||
#ifndef _WIN32
|
||||
bzero((char *)&fsock, sizeof(struct sockaddr_in)) ;
|
||||
#else
|
||||
memset(&fsock, 0x00, sizeof(struct sockaddr_in)) ;
|
||||
#endif
|
||||
fsock.sin_family=AF_INET;
|
||||
fsock.sin_port=htons(m_tcpPort);
|
||||
fsock.sin_addr.s_addr=htoni(INADDR_ANY);
|
||||
if (ip) fsock.sin_addr.s_addr=inet_addr(ip);
|
||||
|
||||
int iFlag = 1;
|
||||
#ifndef _WIN32
|
||||
if(setsockopt(m_sockfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&iFlag, sizeof(iFlag)) != 0)
|
||||
#else
|
||||
if(setsockopt(m_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&iFlag, sizeof(iFlag)) != 0)
|
||||
#endif
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, ErrSetSockOpt,"setsockopt of so_reuseaddr error."
|
||||
"sockid:%d msg:%s.",m_sockfd, strerror(errno)) ;
|
||||
tcpCloseSocket(m_sockfd) ;
|
||||
return ErrSetSockOpt ;
|
||||
}
|
||||
|
||||
if((iRet = bind(m_sockfd, (struct sockaddr*)&fsock, sizeof(fsock))) == -1)
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, ErrBindFail, "socket bind error,sockid:%d msg:%s.",m_sockfd, strerror(errno)) ;
|
||||
tcpCloseSocket(m_sockfd) ;
|
||||
return ErrBindFail;
|
||||
}
|
||||
if((iRet = listen(m_sockfd, LISTENQ)) == -1)
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, ErrListenFail,"socket listen error,sockid:%d msg:%s.",m_sockfd, strerror(errno)) ;
|
||||
tcpCloseSocket(m_sockfd) ;
|
||||
return ErrListenFail;
|
||||
}
|
||||
|
||||
// m_tcpConnected = true ;
|
||||
vPrtLogMsg(LOG_DEBUG, 0, "Acceptting on %s:%d, waitting request...",ip,m_tcpPort) ;
|
||||
return m_sockfd ;
|
||||
}
|
||||
|
||||
//侦听是否有连接请求
|
||||
int TTcpSocket::tcpAcceptSocket(int sockid)
|
||||
{
|
||||
fd_set fd_Read ;
|
||||
struct timeval st_TimeOut ;
|
||||
int isel = 0 ;
|
||||
int iClientID = -1 ;
|
||||
struct sockaddr_in cliaddr;
|
||||
|
||||
#ifndef _WIN32
|
||||
socklen_t cliAddrLen = sizeof(sockaddr_in) ;
|
||||
#else
|
||||
int cliAddrLen = sizeof(sockaddr_in) ;
|
||||
#endif
|
||||
|
||||
st_TimeOut.tv_sec = 5 ;
|
||||
st_TimeOut.tv_usec = 0;
|
||||
FD_ZERO(&fd_Read);
|
||||
FD_SET((unsigned int)sockid, &fd_Read);
|
||||
isel = select(sockid + 1 , &fd_Read, NULL, NULL, &st_TimeOut);
|
||||
if(isel == 0 || isel == EINTR) {
|
||||
// vPrtLogMsg(LOG_DEBUG, errno, "accept...isel=%d errno=%d",isel, errno);
|
||||
return -1 ;
|
||||
}
|
||||
else if( FD_ISSET(sockid , &fd_Read) )
|
||||
{
|
||||
iClientID = accept(sockid, (struct sockaddr*)&cliaddr, &cliAddrLen);
|
||||
if(iClientID > 0)
|
||||
{
|
||||
vPrtLogMsg(LOG_DEBUG, 0,"Have once new link from %s:%d sockid:%d.",
|
||||
inet_ntoa(cliaddr.sin_addr),ntohs(cliaddr.sin_port), iClientID) ;
|
||||
}
|
||||
else {
|
||||
vPrtLogMsg(LOG_DEBUG, errno, "accept...isel=%d errno=%d",isel, errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
SetSocketMode(iClientID); //设置为非阻塞
|
||||
int iFlag = 1;
|
||||
#ifndef _WIN32
|
||||
if(setsockopt(iClientID, SOL_SOCKET, SO_REUSEADDR, (const void *)&iFlag, sizeof(iFlag)) != 0)
|
||||
#else
|
||||
if(setsockopt(iClientID, SOL_SOCKET, SO_REUSEADDR, (const char *)&iFlag, sizeof(iFlag)) != 0)
|
||||
#endif
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, ErrSetSockOpt,"setsockopt of so_reuseaddr error,sockid:%d msg:%s.",iClientID, strerror(errno)) ;
|
||||
tcpCloseSocket(iClientID) ;
|
||||
return ErrSetSockOpt ;
|
||||
}
|
||||
tcpSetlinger(iClientID);
|
||||
return iClientID ;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
** Description : send data for TCP/IP
|
||||
** Para in : tcpID TCP/IP socket description
|
||||
** *buf send data buffer
|
||||
** length send data size
|
||||
** Para out : None
|
||||
** Return Code : >0 send data length
|
||||
** <0 error
|
||||
************************************************************/
|
||||
int TTcpSocket::tcpSendBuffer(int sockid, const char *pBuffer, int length)
|
||||
{
|
||||
if ((sockid <= 0) || (pBuffer == NULL) )
|
||||
return -1 ;
|
||||
if(length <= 0) length = strlen(pBuffer);
|
||||
|
||||
int iSendLen = 0,iLen=0,i=0,iCnt=0,len=length ;
|
||||
char *p = (char *)pBuffer;
|
||||
fd_set fd_Write, fd_Except ;
|
||||
struct timeval st_TimeOut ;
|
||||
|
||||
if(length > MAX_SBUFF_TCP)
|
||||
iCnt = length/MAX_SBUFF_TCP ;
|
||||
else
|
||||
iCnt = 0 ;
|
||||
for(;;)
|
||||
{
|
||||
FD_ZERO(&fd_Write) ;
|
||||
FD_ZERO(&fd_Except) ;
|
||||
FD_SET((unsigned int)sockid, &fd_Write) ;
|
||||
FD_SET((unsigned int)sockid, &fd_Except) ;
|
||||
iSendLen = -1 ;
|
||||
st_TimeOut.tv_sec = 0 ;
|
||||
st_TimeOut.tv_usec = 10 ;
|
||||
|
||||
iSendLen = select (sockid+1 , NULL, &fd_Write, &fd_Except, &st_TimeOut) ;
|
||||
if((iSendLen == 0 && errno == EPIPE) || (iSendLen < 0)) { // EPIPE =32 Broken pipe EBADF=9 Bad file number
|
||||
vPrtLogMsg(LOG_ERROR,errno, "socket execption close,sockid:%d ret:%d msg:%s", sockid, iSendLen, strerror(errno));
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrException;
|
||||
}
|
||||
if( FD_ISSET(sockid, &fd_Except) )
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR,errno, "socket execption,sockid:%d msg:%s", sockid, strerror(errno));
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrSendFail ; //socket exception
|
||||
}
|
||||
else if( FD_ISSET(sockid , &fd_Write) )
|
||||
{
|
||||
iSendLen = 0 ;
|
||||
for(i=0; i< iCnt; i++)
|
||||
{
|
||||
iLen = send(sockid, p+(i*MAX_SBUFF_TCP), MAX_SBUFF_TCP,0);
|
||||
if( iLen < 0 )
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR,errno, "send buffer fail,sockid:%d toplen:%ld sendlen:%d msg:%s",
|
||||
sockid, len, iSendLen, strerror(errno));
|
||||
if(errno == 0 && iLen == -1) {
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrException;
|
||||
}
|
||||
if(errno == EPIPE || errno == EBADF || errno == ECONNRESET || errno == EINVAL) {
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrException;
|
||||
}
|
||||
else {
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrSendFail ; // send data fail
|
||||
}
|
||||
}
|
||||
length -= MAX_SBUFF_TCP;
|
||||
iSendLen += iLen ;
|
||||
}
|
||||
if(length == 0 ) {
|
||||
//add_monitor_mesg(len, 0x01, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return iSendLen ;
|
||||
}
|
||||
if(length >0)
|
||||
{
|
||||
iLen = send(sockid, p+(i*MAX_SBUFF_TCP), length,0);
|
||||
if(iLen < 0)
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR, errno, "send buffer fail! sockid:%d toplen:%ld sendlen:%d msg:%s",
|
||||
sockid, len, iSendLen, strerror(errno));
|
||||
if(errno == 0 && iLen == -1) {
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrException;
|
||||
}
|
||||
if(errno == EPIPE || errno == EBADF || errno == ECONNRESET || errno == EINVAL) {
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrException;
|
||||
}
|
||||
else {
|
||||
//add_monitor_mesg(len, 0x00, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return ErrSendFail ; // send data fail
|
||||
}
|
||||
}
|
||||
break ;
|
||||
}
|
||||
}
|
||||
} //end for(;;)
|
||||
//add_monitor_mesg(iSendLen+iLen, 0x01, (unsigned char*)pBuffer); // 添加监控消息到监控发送队列
|
||||
return (iSendLen+iLen);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
** Description : recv data for TCP/IP
|
||||
** Para in : tcpID TCP/IP socket description
|
||||
** *buf send data buffer
|
||||
** length send data size
|
||||
** Para out : None
|
||||
** Return Code : >0 recv data length
|
||||
** <0 error
|
||||
************************************************************/
|
||||
int TTcpSocket::tcpRecvBuffer(int sockid, char* pBuffer,int nMaxLength, int timeout)
|
||||
{
|
||||
int nLength = -2;
|
||||
int iTop = 0;
|
||||
fd_set fd_Read,fd_Except;
|
||||
struct timeval st_TimeOut;
|
||||
int isel = 0;
|
||||
|
||||
if( sockid <= 0 || pBuffer == NULL) return -1;
|
||||
while(iTop != nMaxLength)
|
||||
{
|
||||
st_TimeOut.tv_sec = timeout ;
|
||||
st_TimeOut.tv_usec = 0;
|
||||
FD_ZERO(&fd_Read);
|
||||
FD_ZERO(&fd_Except) ;
|
||||
FD_SET((unsigned int)sockid, &fd_Read) ;
|
||||
FD_SET((unsigned int)sockid, &fd_Except) ;
|
||||
isel= select (sockid + 1 , &fd_Read, NULL, &fd_Except, &st_TimeOut) ;
|
||||
|
||||
if(isel <= 0 || isel == EINTR)
|
||||
{
|
||||
// vPrtLogMsg(LOG_DEBUG,errno, "select socket timeout,isel=%d",isel);
|
||||
break ;
|
||||
}
|
||||
else if( FD_ISSET(sockid, &fd_Except) )
|
||||
{
|
||||
vPrtLogMsg(LOG_ERROR,errno,"socket execption,sockid:%d errno:%d iselect:%d", sockid, errno, isel) ;
|
||||
return ErrRecvFail; // recv fail
|
||||
}
|
||||
else if (isel > 0) //EINTR
|
||||
{
|
||||
if (FD_ISSET(sockid,&fd_Read)) //检测Socket读状态
|
||||
{
|
||||
nLength = recv(sockid, pBuffer, MAX_SBUFF_TCP, MSG_PEEK); // MSG_PEEK
|
||||
if ( nLength < 0 && (errno == EPIPE || errno == EBADF || errno == ECONNRESET || errno == EINVAL))
|
||||
return ErrException;
|
||||
else if( isel == 1 && nLength == 0 && (errno == EPIPE || errno == EBADF || errno == ECONNRESET || errno == EINVAL)) {
|
||||
vPrtLogMsg(LOG_DEBUG,errno, "select socket timeout,isel=%d nLength=%d",isel,nLength);
|
||||
return ErrException; // iTop; //检查到客户端主动断开连接.
|
||||
}
|
||||
else if(nLength < 0 && errno == 0)
|
||||
return ErrException ;
|
||||
else if (nLength < 0)
|
||||
return ErrRecvFail; // recv fail
|
||||
else if (nLength == 0)
|
||||
return ErrException;
|
||||
else {
|
||||
iTop += nLength;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
}
|
||||
}
|
||||
return iTop;
|
||||
}
|
||||
|
||||
//连接是否已经建立
|
||||
bool TTcpSocket::tcpIsConnected(int sockid)
|
||||
{
|
||||
char msg[5] = {0};
|
||||
int err = 0;
|
||||
if(sockid <= 0 ) return false ;
|
||||
err = recv(sockid, msg, sizeof(msg), MSG_PEEK);
|
||||
/* client already close connection. */
|
||||
if(err < 0 && (errno == EPIPE || errno == EBADF || errno == ECONNRESET))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int TTcpSocket::tcpSetlinger(int sockid)
|
||||
{
|
||||
struct linger lingerStruct={1,0};
|
||||
|
||||
if(setsockopt(sockid, SOL_SOCKET, SO_LINGER, (char *)&lingerStruct, sizeof(lingerStruct)) == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
int TTcpSocket::tcpSetNodelay(int sockid)
|
||||
{
|
||||
int nodelay = 1;
|
||||
#ifdef TCP_NODELAY
|
||||
if(setsockopt(sockid, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay)) == -1)
|
||||
return -1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 连接TCP 服务器
|
||||
int TTcpSocket::tcpConnect(const char *pszIP, short port, int iTimeout)
|
||||
{
|
||||
int iRet = -1, sockid=-1;
|
||||
struct sockaddr_in addr;
|
||||
int on = 1;
|
||||
|
||||
if(!pszIP || !((unsigned int)port > 1024 && (unsigned int)port < 65535)) {
|
||||
vPrtLogMsg(LOG_ERROR, ErrSockParam, "in parameter ip/port %s:%d(1024-65535) invalid.", pszIP, port);
|
||||
return ErrSockParam;
|
||||
}
|
||||
// Create socket
|
||||
sockid = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(sockid < 0 )
|
||||
{
|
||||
vPrtLogMsg (LOG_ERROR, errno, "create socket failed! errno[%d],msg:%s", errno,strerror(errno));
|
||||
sockid = -1;
|
||||
return sockid; // break;
|
||||
}
|
||||
|
||||
memset(&addr, 0x00, sizeof(struct sockaddr_in));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = inet_addr(pszIP); //htoni(INADDR_ANY);
|
||||
|
||||
/* set socket options */
|
||||
#ifdef _WIN32
|
||||
//setsockopt(sockid, SOL_SOCKET, SO_ERROR, (const char*)&on, sizeof(int));
|
||||
if(setsockopt(sockid, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(int)) < 0) {
|
||||
#else
|
||||
if(setsockopt(sockid, SOL_SOCKET, SO_REUSEADDR, (const void*)&on, sizeof(int)) < 0) {
|
||||
#endif
|
||||
vPrtLogMsg (LOG_ERROR, errno, "setsockopt error! errno[%d],msg:%s", errno,strerror(errno));
|
||||
tcpCloseSocket(sockid);
|
||||
sockid = -1;
|
||||
return sockid; // break;
|
||||
}
|
||||
//SetSocketMode(sockid); // 将建立的新连接置为非阻塞
|
||||
iRet = connect(sockid, (struct sockaddr *)&addr, sizeof(addr));
|
||||
if (iRet == 0) {
|
||||
tcpSetlinger(sockid); // 建链成功
|
||||
SetSocketMode(sockid); // 将建立的新连接置为非阻塞
|
||||
return sockid;
|
||||
}
|
||||
tcpCloseSocket(sockid);
|
||||
sockid = -1;
|
||||
|
||||
return sockid;
|
||||
}
|
||||
|
||||
void TTcpSocket::clear_tcp_buffer(int socket_fd, int nbytes)
|
||||
{
|
||||
char buffer[MAX_TEMP_BUFFER_SIZE]={0};
|
||||
int recv_len;
|
||||
int i;
|
||||
if(nbytes == 0) return ; // 如果需要清除的字节数为0 则直接返回成功
|
||||
for(i = 0; i < (int)(nbytes / MAX_TEMP_BUFFER_SIZE); i++) {
|
||||
recv_len = recv(socket_fd, buffer, MAX_TEMP_BUFFER_SIZE, 0);
|
||||
if(recv_len >= 0 && recv_len < MAX_TEMP_BUFFER_SIZE) { // 期间如果发现缓冲区的数据已经被清空了则返回
|
||||
return ;
|
||||
}
|
||||
else if(recv_len < 0) { // 异常了
|
||||
return ;
|
||||
}
|
||||
}
|
||||
recv_len = recv(socket_fd, buffer, (nbytes % MAX_TEMP_BUFFER_SIZE), 0);
|
||||
if(recv_len >= 0) return ;
|
||||
else return ;
|
||||
}
|
@ -0,0 +1 @@
|
||||
锘
|
@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
** File name : HTThread.h
|
||||
** Description : define server worker thread group
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyrigth By: xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#include "HTGlobal.h"
|
||||
#include "HTThread.h"
|
||||
|
||||
static const char *_FILE_ ="HTThread.cpp";
|
||||
|
||||
/********************************************************************
|
||||
* function : 创建线程句柄
|
||||
* param in : none
|
||||
* param out : None
|
||||
* return val: 0 -- successed
|
||||
* : <0 -- failed
|
||||
********************************************************************/
|
||||
static int HTNewThreadHandle(pthread_t **pThreadHandle, int thread_count)
|
||||
{
|
||||
*pThreadHandle = (pthread_t*)calloc(1, sizeof(pthread_t)*thread_count);
|
||||
if(*pThreadHandle == NULL) {
|
||||
vPrtLogMsg(LOG_ERROR, errno, "calloc for thread handle failed.");
|
||||
return -1;
|
||||
}
|
||||
memset(*pThreadHandle, 0xff, sizeof(pthread_t)*thread_count);
|
||||
return 0;
|
||||
}
|
||||
// 释放系统线程句柄
|
||||
static int HTDelThreadHandle(pthread_t **pThreadHandle)
|
||||
{
|
||||
if(*pThreadHandle) {
|
||||
free(*pThreadHandle);
|
||||
*pThreadHandle = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// 释放句柄
|
||||
void HTFreeThreadHandle(void)
|
||||
{
|
||||
//HTDelThreadHandle(&thread_handle_recv);
|
||||
//HTDelThreadHandle(&thread_handle_parse);
|
||||
//HTDelThreadHandle(&thread_handle_setdb);
|
||||
//HTDelThreadHandle(&thread_handle_respone);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* function : 初始化线程句柄
|
||||
* param in : none
|
||||
* param out : None
|
||||
* return val: 0 -- successed
|
||||
* : <0 -- failed
|
||||
********************************************************************/
|
||||
int HTInitThreadHandle(void)
|
||||
{
|
||||
// if(HTNewThreadHandle(&thread_handle_recv,g_TConfig.getRecvThreadNumber()) != RET_OK) {
|
||||
// HTFreeThreadHandle();
|
||||
// return RET_FAIL;
|
||||
// }
|
||||
// if(HTNewThreadHandle(&thread_handle_parse,g_TConfig.getParseThreadNumber()) != RET_OK) {
|
||||
// HTFreeThreadHandle();
|
||||
// return RET_FAIL;
|
||||
// }
|
||||
//if(HTNewThreadHandle(&thread_handle_setdb,g_TConfig.getOprationThreadNumber()) != RET_OK) {
|
||||
// HTFreeThreadHandle();
|
||||
// return RET_FAIL;
|
||||
//}
|
||||
// if(HTNewThreadHandle(&thread_handle_respone,g_TConfig.getResponeThreadNumber()) != RET_OK) {
|
||||
// HTFreeThreadHandle();
|
||||
// return RET_FAIL;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* function : 创建链接政府监管平台主链路线程
|
||||
* param in : none
|
||||
* param out : None
|
||||
* return val: 0 -- successed
|
||||
* : <0 -- failed
|
||||
********************************************************************/
|
||||
int ht_pthread_create_background(pthread_t *thread_handle, void *(*pfunc)(void *), void *data)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE handle = NULL;
|
||||
handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)pfunc,(LPVOID)data, 0, thread_handle);
|
||||
if (!handle) {
|
||||
::CloseHandle(handle);
|
||||
return -1 ;
|
||||
}
|
||||
#else
|
||||
if(pthread_create(thread_handle, NULL, pfunc, data) !=0 ) {
|
||||
return -1 ;
|
||||
}
|
||||
#endif
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
void pthread_testcancels(void)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
pthread_testcancel();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,912 @@
|
||||
/****************************************************************************
|
||||
** File name : HTConfig.cpp
|
||||
** Description : config parameter
|
||||
** Create date : 2018.09.01
|
||||
** Auther by : Liuyx
|
||||
** Version info : V1.0.01
|
||||
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
|
||||
** Update record:
|
||||
** DATE AUTHER DESC
|
||||
** -------------------------------------------------------------------------
|
||||
** 2018.09.01 Liuyx first build
|
||||
****************************************************************************/
|
||||
#include "HTGlobal.h"
|
||||
#include "HXIec104.h"
|
||||
|
||||
|
||||
|
||||
void NsNetServerProcess(void);
|
||||
|
||||
static void NsIec104Process(void);
|
||||
static void NsIec104Init(unsigned char Card,short Port);
|
||||
static void NsIec104NetInit(void);
|
||||
|
||||
static void NsIec104Reset(void);
|
||||
static void NsIec104ProcessFormatI(void);
|
||||
static void NsIec104ProcessFormatS(void);
|
||||
static void NsIec104ProcessFormatU(void);
|
||||
static void NsIec104Interrogation(void);
|
||||
static void NsIec104InterrogationGroup(void);
|
||||
static void NsIec104InterrogationAll(void);
|
||||
static void NsIec104ProcessYxGroup(unsigned char Group);
|
||||
static void NsIec104ProcessYcGroup(unsigned char Group);
|
||||
static void NsIec104ProcessCellGroup(unsigned char Group);
|
||||
static void NsIec104ProcessTime(void);
|
||||
static void NsIec104ProcessYkYt(void);
|
||||
static void NsIec104ProcessPulse(void);
|
||||
static void NsIec104DefaultGroup(unsigned char Group);
|
||||
static void NsIec104ProcessPulseData(void);
|
||||
static void NsIec104SendGroup(void);
|
||||
|
||||
static void NsIec104SendYkMessage(short Who,unsigned char Action);
|
||||
static void NsIec104ReceiveYkReturn(void);
|
||||
static void NsIec104SendYkSelectConfirm(void);
|
||||
static void NsIec104SendYkExeConfirm(void);
|
||||
static void NsIec104SendYkEscConfirm(void);
|
||||
static unsigned char NsIec104SendCosSoe(void);
|
||||
static void NsIec104InitYk(void);
|
||||
static void NsIec104CycleCount(void);
|
||||
static void NsIec104SendChangeYc(void);
|
||||
/*
|
||||
static void Iec104testCosSoe(void);
|
||||
void debug104(void);
|
||||
*/
|
||||
static void NsIec104Init(unsigned char Card,short Port)
|
||||
{
|
||||
unsigned short i;
|
||||
int Result;
|
||||
// char Buff[32];
|
||||
// char Ip0Buff[64],Ip0Route[64];
|
||||
//// char Ip1Buff[64],Ip1Route[64];
|
||||
NS_SYSTEM_DATA_MODE SysData;
|
||||
|
||||
NsIec104Struct.LinkState=NS_DISCONNECTED;
|
||||
NsIec104Struct.NsNewSocketId=0;
|
||||
// getforsecond(&NsIec104Struct.LinkValidTime);
|
||||
NsIec104Struct.ReceiveIndex=0;
|
||||
NsIec104Struct.ReceiveIndexLength=0;
|
||||
NsIec104Struct.SendMeNumber=0;
|
||||
NsIec104Struct.HasSendNumber=0;
|
||||
NsIec104Struct.NeedSendNumber=0;
|
||||
NsIec104Struct.LeftSendNumber=0;
|
||||
NsIec104Struct.Card=Card;
|
||||
NsIec104Struct.Port=Port;
|
||||
NsIec104Struct.YkStartSign=OFF;
|
||||
NsIec104Struct.Table=0;
|
||||
NsIec104Struct.NetRunSign=OFF;
|
||||
NsIec104Struct.SetNetSign=OFF;
|
||||
|
||||
// Result=ReadNsc200Ini("NsIec104","SetTimeFlag",Buff);
|
||||
if(Result)
|
||||
{
|
||||
NsIec104Struct.SetTimeFlag=1;
|
||||
}
|
||||
|
||||
for(i=0;i<NS_IEC104_USE_CYCLE;i++)
|
||||
{
|
||||
// getforsecond(&NsIec104Cycle[i].LastTime);
|
||||
NsIec104Cycle[i].TimeNap= NsIec104Nap[i];
|
||||
NsIec104Cycle[i].TimeSign=OFF;
|
||||
}
|
||||
|
||||
for(i=0;i<NS_IEC104_MAX_YC;i++)
|
||||
NsIec104Struct.YcNap[i]=5;
|
||||
NsIec104Struct.YcChangeCycle=0;
|
||||
|
||||
// NsIec104Struct.TableNo = NsGetCommTable(Port);
|
||||
// GetSysDataMode(NsIec104Struct.TableNo,&SysData);
|
||||
/*NsIec104Struct.XYxNum = SysData.NsYxTableNumber;
|
||||
|
||||
NsIec104Struct.XYmNum = SysData.NsYmTableNumber;*/
|
||||
NsIec104Struct.XYcNum = SysData.NsYcTableNumber;
|
||||
NsIec104Struct.XYcCycleNum = (NsIec104Struct.XYcNum + NS_IEC104_ONCE_YC_COUNT - 1) / NS_IEC104_ONCE_YC_COUNT;
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void NsIec104NetInit(void)
|
||||
{
|
||||
int Result;
|
||||
char Buff[32];
|
||||
char Ip0Buff[64],Ip0Route[64];
|
||||
char Ip1Buff[64],Ip1Route[64];
|
||||
|
||||
NsTcpServerInit(NsIec104Struct.Card,NsIec104Struct.Port,"10.14.127.200");
|
||||
switch(NsIec104Struct.Card)
|
||||
{
|
||||
case 0:
|
||||
Result=ReadNsc200Ini("NsIec104","Route0Sign",Buff);
|
||||
if(Result)
|
||||
{
|
||||
NsReadIpAddress("NsIec104","Route0Net",Ip0Buff);
|
||||
NsReadIpAddress("NsIec104","Route0Ip",Ip0Route);
|
||||
NsAddRoute(Ip0Buff,Ip0Route);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
Result=ReadNsc200Ini("NsIec104","Route1Sign",Buff);
|
||||
if(Result)
|
||||
{
|
||||
NsReadIpAddress("NsIec104","Route1Net",Ip1Buff);
|
||||
NsReadIpAddress("NsIec104","Route1Ip",Ip1Route);
|
||||
NsAddRoute(Ip1Buff,Ip1Route);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void NsIec104InitYk(void)
|
||||
{
|
||||
|
||||
NsIec104Struct.YkStartSign=OFF;
|
||||
NsIec104Struct.YkNowState=0xff;
|
||||
NsIec104Struct.YkCellNumber=0xff;
|
||||
NsIec104Struct.YkKgNumber=0xff;
|
||||
|
||||
}
|
||||
|
||||
void NsNetServerProcessv(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
taskDelay(88);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NsNetServerProcess(void)
|
||||
{
|
||||
unsigned long Now,Nap;
|
||||
unsigned short Card;
|
||||
int Result;
|
||||
char Buff[32];
|
||||
|
||||
Card=0;
|
||||
Result=ReadNsc200Ini("NsTasks","NsServerCard",Buff);
|
||||
if(Result)
|
||||
{
|
||||
Card=Result;
|
||||
if(Card<=2&&Card>0)
|
||||
{
|
||||
Card-=1;
|
||||
}
|
||||
}
|
||||
NsIec104Init(Card,2404);
|
||||
for(;;)
|
||||
{
|
||||
NsIec104Struct.SystemState = NsGetSysParameter(NS_NSCC_STATE);
|
||||
NsIec104Struct.NetRunSign = NsNetConfigState();
|
||||
|
||||
if(NsIec104Struct.NetRunSign==ON&&NsIec104Struct.SetNetSign==OFF&&NsIec104Struct.SystemState==DUTY)
|
||||
{
|
||||
NsIec104NetInit();
|
||||
NsIec104Struct.SetNetSign=ON;
|
||||
}
|
||||
if(NsIec104Struct.NetRunSign==ON&&NsIec104Struct.SetNetSign==ON&&NsIec104Struct.SystemState==DUTY)
|
||||
{
|
||||
getforsecond(&Now);
|
||||
Nap=DiffMsLong(Now,NsIec104Struct.LinkValidTime);
|
||||
if(Nap>NS_IEC104_PERMIT_TIME)
|
||||
{
|
||||
NsIec104Struct.LinkState=NS_DISCONNECTED;
|
||||
}
|
||||
if(NsIec104Struct.YkStartSign==ON)
|
||||
{
|
||||
Nap=DiffMsLong(Now,NsIec104Struct.YkStartTime);
|
||||
if(Nap>NS_IEC104_YK_PERMIT_TIME)
|
||||
{
|
||||
NsIec104InitYk();
|
||||
}
|
||||
}
|
||||
if(NsIec104Struct.LinkState==NS_DISCONNECTED)
|
||||
{
|
||||
|
||||
NsIec104Struct.NsNewSocketId=NsTcpConnect(NsIec104Struct.NsNewSocketId,NsIec104Struct.Card);
|
||||
|
||||
if(NsIec104Struct.NsNewSocketId>0)
|
||||
{
|
||||
NsIec104Struct.LinkState=NS_CONNECTED;
|
||||
NsIec104Struct.SendMeNumber=0;
|
||||
getforsecond(&NsIec104Struct.LinkValidTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*NsIec104Init(NsIec104Struct.Card,NsIec104Struct.Port);*/
|
||||
|
||||
/* NsTcpServerInit(NsIec104Struct.Card,NsIec104Struct.Port,"10.14.8.23");*/
|
||||
NsIec104Struct.LinkState=NS_DISCONNECTED;
|
||||
NsIec104Reset();
|
||||
taskDelay(866);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
NsIec104Struct.ReceiveIndexLength=recv(NsIec104Struct.NsNewSocketId,&NsIec104Struct.ReceiveBuffer[NsIec104Struct.ReceiveIndex],198,0);
|
||||
|
||||
if(NsIec104Struct.ReceiveIndexLength>0)
|
||||
{
|
||||
NsIec104Struct.ReceiveLength+=NsIec104Struct.ReceiveIndexLength;
|
||||
if(NsIec104Struct.ReceiveLength<NS_IEC104_RECEIVEBUFFER)
|
||||
{
|
||||
NsIec104Process();
|
||||
}
|
||||
else
|
||||
{
|
||||
NsIec104Reset();
|
||||
}
|
||||
/*
|
||||
debug104();
|
||||
Iec104testCosSoe();
|
||||
*/
|
||||
getforsecond(&NsIec104Struct.LinkValidTime);
|
||||
}
|
||||
|
||||
NsIec104ReceiveYkReturn();
|
||||
NsIec104SendGroup();
|
||||
|
||||
if(NsIec104Struct.LeftSendNumber==0)
|
||||
{
|
||||
NsIec104Struct.CosSign=NsIec104SendCosSoe();
|
||||
if(NsIec104Struct.CosSign==0)
|
||||
{
|
||||
NsIec104SendChangeYc();
|
||||
}
|
||||
}
|
||||
}
|
||||
NsIec104CycleCount();
|
||||
}
|
||||
taskDelay(18);
|
||||
}
|
||||
}
|
||||
|
||||
static void NsIec104SendChangeYc(void)
|
||||
{
|
||||
|
||||
unsigned short General,Index;
|
||||
unsigned char *P;
|
||||
unsigned short i,RealNumber;
|
||||
short *Pyc,YcValue,YcNap;
|
||||
float fYc;
|
||||
|
||||
|
||||
|
||||
Index=0;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x68;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
|
||||
RealNumber=(NsIec104Struct.SendMeNumber<<1);
|
||||
P=(unsigned char *)&RealNumber;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0]; /* send number */
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendMeNumber=(NsIec104Struct.SendMeNumber+1)%65535;
|
||||
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[0]; /* receive number */
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[1];
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=9; /* asdu type */
|
||||
NsIec104Struct.SendBuffer[Index++]=0; /* information object count No 7 Byte */
|
||||
|
||||
/* REASONBYTE now is two */
|
||||
NsIec104Struct.SendBuffer[Index++]=3; /* reason */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x0; /* reason */
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=0x01;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
/*
|
||||
for(i=0;i<NS_IEC_104_ASDUADDRESSBYTE;i++)
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.CommonAsduAddress[i];
|
||||
*/
|
||||
NsIec104Struct.YcLibIndex=NsIec104Struct.YcChangeCycle*NS_IEC104_ONCE_YC_COUNT;
|
||||
/*NsIec104Struct.YcChangeCycle=(NsIec104Struct.YcChangeCycle+1)%NS_IEC104_CHANGE_YC_CYCLE;*/
|
||||
NsIec104Struct.YcChangeCycle=(NsIec104Struct.YcChangeCycle+1)%NsIec104Struct.XYcCycleNum;
|
||||
|
||||
NsIec104Struct.YcChangeCount=0;
|
||||
|
||||
switch(NsIec104Struct.Table)
|
||||
{
|
||||
case 0:
|
||||
NsGetDd1Lib(NS_YC_DATA,NsIec104Struct.YcLibIndex,NsIec104Struct.DataBuff,NS_IEC104_ONCE_YC_COUNT);
|
||||
break;
|
||||
case 1:
|
||||
NsGetDd2Lib(NS_YC_DATA,NsIec104Struct.YcLibIndex,NsIec104Struct.DataBuff,NS_IEC104_ONCE_YC_COUNT);
|
||||
break;
|
||||
case 2:
|
||||
NsGetDd3Lib(NS_YC_DATA,NsIec104Struct.YcLibIndex,NsIec104Struct.DataBuff,NS_IEC104_ONCE_YC_COUNT);
|
||||
break;
|
||||
case 3:
|
||||
NsGetDd4Lib(NS_YC_DATA,NsIec104Struct.YcLibIndex,NsIec104Struct.DataBuff,NS_IEC104_ONCE_YC_COUNT);
|
||||
break;
|
||||
}
|
||||
|
||||
for(i=0;i<NS_IEC104_ONCE_YC_COUNT;i++)
|
||||
{
|
||||
/*Pyc=(short *)&NsIec104Struct.DataBuff[2*i];
|
||||
YcValue= *Pyc;
|
||||
YcNap=YcValue-NsIec104Struct.YcLastValue[NsIec104Struct.YcLibIndex+i];
|
||||
if(YcNap<0)
|
||||
YcNap=NsIec104Struct.YcLastValue[NsIec104Struct.YcLibIndex+i]-YcValue;
|
||||
|
||||
if(YcNap>NsIec104Struct.YcNap[NsIec104Struct.YcLibIndex+i])
|
||||
{
|
||||
NsIec104Struct.YcChangeCount++;
|
||||
NsIec104Struct.YcLastValue[NsIec104Struct.YcLibIndex+i]=YcValue;*/
|
||||
/* Information Object Address Now Three Bytes */
|
||||
General=0x701+NsIec104Struct.YcLibIndex+i;
|
||||
P=(unsigned char *)&General;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendBuffer[Index++]=0;
|
||||
|
||||
/*fYc = YcValue * 1.0;
|
||||
P=(unsigned char *)&fYc;
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[2];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[3];*/
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.DataBuff[2*i];
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.DataBuff[2*i + 1];
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00; /*qds*/
|
||||
/*}*/
|
||||
}
|
||||
|
||||
/* Repair Length and Count*/
|
||||
NsIec104Struct.SendBuffer[1]=Index-2;
|
||||
NsIec104Struct.SendBuffer[7]=NsIec104Struct.YcChangeCount;
|
||||
if(NsIec104Struct.YcChangeCount>0)
|
||||
{/*
|
||||
printf("\n Co=%d Ind=%dGe=%d",NsIec104Struct.YcChangeCount,NsIec104Struct.YcLibIndex,General);
|
||||
*/
|
||||
if((NsIec104Struct.SendLength=send(NsIec104Struct.NsNewSocketId,&NsIec104Struct.SendBuffer[0],Index,0x0))<0)
|
||||
{
|
||||
perror ("Client FirstWrite Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void NsIec104SendGroup(void)
|
||||
{
|
||||
if(NsIec104Struct.NeedSendNumber>0&&NsIec104Struct.HasSendNumber<NS_IEC104_MAX_K)
|
||||
{
|
||||
/*
|
||||
printf("\n GroupId=%d",NsIec104Struct.NsNewSocketId);
|
||||
*/
|
||||
if((NsIec104Struct.SendLength=send(NsIec104Struct.NsNewSocketId,&NsIec104Struct.GroupSendBuffer[NsIec104Struct.LeftSendNumber][0],NsIec104Struct.GroupSendLength[NsIec104Struct.LeftSendNumber],0x0))<0)
|
||||
{
|
||||
perror ("GRoup Erroe");
|
||||
}
|
||||
|
||||
NsIec104Struct.LeftSendNumber++;
|
||||
/*
|
||||
printf("\n Send Group=%d",NsIec104Struct.SendLength);
|
||||
*/
|
||||
if(NsIec104Struct.LeftSendNumber>=NsIec104Struct.NeedSendNumber)
|
||||
{
|
||||
NsIec104Struct.HasSendNumber=0;
|
||||
NsIec104Struct.NeedSendNumber=0;
|
||||
NsIec104Struct.LeftSendNumber=0;
|
||||
}
|
||||
}
|
||||
taskDelay(108);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void NsIec104Process(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* printf("r:");
|
||||
for(i=0;i<NsIec104Struct.ReceiveLength;i++)
|
||||
printf("%4x",NsIec104Struct.ReceiveBuffer[i]);
|
||||
printf("\n");
|
||||
*/
|
||||
if(NsIec104Struct.ReceiveLength>=NS_IEC_104_MIN_LENGTH && NsIec104Struct.ReceiveBuffer[0]==NS_IEC_104_HEAD)
|
||||
{
|
||||
NsIec104Struct.FormatType=NsIec104Struct.ReceiveBuffer[2]&0x03;
|
||||
if(NsIec104Struct.FormatType==0||NsIec104Struct.FormatType==2) /* I */
|
||||
{
|
||||
NsIec104ProcessFormatI();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(NsIec104Struct.FormatType==1) /* S */
|
||||
NsIec104ProcessFormatS();
|
||||
else
|
||||
{
|
||||
if(NsIec104Struct.FormatType==3)/* U */
|
||||
NsIec104ProcessFormatU();
|
||||
}
|
||||
}
|
||||
NsIec104Reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void NsIec104ProcessFormatI(void)
|
||||
{
|
||||
int i;
|
||||
unsigned char *p;
|
||||
unsigned short NoWay;
|
||||
/*
|
||||
printf("\nFormatI");
|
||||
*/
|
||||
NsIec104Struct.ApduLength=NsIec104Struct.ReceiveBuffer[1];
|
||||
if(NsIec104Struct.ApduLength>NS_IEC_104_MIN_LENGTH)
|
||||
{
|
||||
NsIec104Struct.ReceiveHimNumber[0]=NsIec104Struct.ReceiveBuffer[2];
|
||||
NsIec104Struct.ReceiveHimNumber[1]=NsIec104Struct.ReceiveBuffer[3];
|
||||
NoWay=*(unsigned short *)&NsIec104Struct.ReceiveHimNumber[0];
|
||||
NoWay>>=1;
|
||||
NoWay+=1;
|
||||
NoWay<<=1;
|
||||
p=(unsigned char *)&NoWay;
|
||||
NsIec104Struct.ReceiveHimNumber[0]=p[0];
|
||||
NsIec104Struct.ReceiveHimNumber[1]=p[1];
|
||||
|
||||
NsIec104Struct.AsduType=NsIec104Struct.ReceiveBuffer[6];
|
||||
|
||||
for(i=0;i< NS_IEC_104_REASONBYTE;i++)
|
||||
NsIec104Struct.TransmitReason[i]=NsIec104Struct.ReceiveBuffer[NS_STARTREASON+i];
|
||||
|
||||
for(i=0;i<NS_IEC_104_ASDUADDRESSBYTE;i++)
|
||||
NsIec104Struct.CommonAsduAddress[i]=NsIec104Struct.ReceiveBuffer[NS_STARTASDUADDRESS+i];
|
||||
|
||||
for(i=0;i<NS_IEC_104_INFORMATIONBYTE;i++)
|
||||
NsIec104Struct.InformationObject[i]=NsIec104Struct.ReceiveBuffer[NS_STARTINFORMATION+i];
|
||||
|
||||
NsIec104Struct.AsduQualifier=NsIec104Struct.ReceiveBuffer[NS_STARTQUALIFIER];
|
||||
|
||||
switch(NsIec104Struct.AsduType)
|
||||
{
|
||||
case 46:
|
||||
case 47:
|
||||
NsIec104Struct.YkYtType=NsIec104Struct.AsduType;
|
||||
NsIec104ProcessYkYt();
|
||||
break;
|
||||
case 100: /* Interrogation */
|
||||
NsIec104Interrogation();
|
||||
break;
|
||||
case 101:
|
||||
NsIec104ProcessPulse();
|
||||
break;
|
||||
case 103:
|
||||
NsIec104ProcessTime();
|
||||
/*
|
||||
printf("\n Time1");
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static unsigned char NsIec104SendCosSoe(void)
|
||||
{
|
||||
unsigned short Number;
|
||||
NS_SOE_FORMAT SoeData;
|
||||
NS_COS_FORMAT CosData;
|
||||
unsigned short Index,SendCount;
|
||||
unsigned char *P,i,CosSendSign;
|
||||
unsigned short RealNumber,Object,Msecond;
|
||||
|
||||
Index=0;
|
||||
CosSendSign=0;
|
||||
Number=NsCheckDd1Cos();
|
||||
if(Number>0)
|
||||
{
|
||||
if(Number>36)
|
||||
Number=36;
|
||||
SendCount=0;
|
||||
Index=0;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x68;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
|
||||
RealNumber=(NsIec104Struct.SendMeNumber<<1);
|
||||
P=(unsigned char *)&RealNumber;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0]; /* send number */
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendMeNumber=(NsIec104Struct.SendMeNumber+1)%65535;
|
||||
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[0]; /* receive number */
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[1];
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=0x01; /* 0x01--->0x02 asdu type */
|
||||
NsIec104Struct.SendBuffer[Index++]=1; /* information object count */
|
||||
|
||||
/* REASONBYTE now is two */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x03; /* reason */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00; /* reason */
|
||||
|
||||
|
||||
for(i=0;i<NS_IEC_104_ASDUADDRESSBYTE;i++)
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.CommonAsduAddress[i];
|
||||
for(i=0;i<Number;i++)
|
||||
{
|
||||
if(NsGetDd1CosLib(&CosData)==ON)
|
||||
{
|
||||
SendCount++;
|
||||
/* Information Object Address now three byte: 0xc01---0xc80 */
|
||||
Object=CosData.SendNumber+0x01;
|
||||
P=(unsigned char *)&Object;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
NsIec104Struct.SendBuffer[Index++]=CosData.State;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Repair Length */
|
||||
NsIec104Struct.SendBuffer[7]=SendCount; /* vsq number */
|
||||
NsIec104Struct.SendBuffer[1]=Index-2;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Number=NsCheckDd1Soe();
|
||||
if(Number>0)
|
||||
{
|
||||
if(Number>18)
|
||||
Number=18;
|
||||
SendCount=0;
|
||||
Index=0;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x68;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
|
||||
RealNumber=(NsIec104Struct.SendMeNumber<<1);
|
||||
P=(unsigned char *)&RealNumber;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0]; /* send number */
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendMeNumber=(NsIec104Struct.SendMeNumber+1)%65535;
|
||||
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[0]; /* receive number */
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[1];
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=30; /* asdu type */
|
||||
NsIec104Struct.SendBuffer[Index++]=1; /* information object count */
|
||||
|
||||
/* REASONBYTE now is two */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x03; /* reason */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00; /* reason */
|
||||
|
||||
|
||||
for(i=0;i<NS_IEC_104_ASDUADDRESSBYTE;i++)
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.CommonAsduAddress[i];
|
||||
|
||||
for(i=0;i<Number;i++)
|
||||
{
|
||||
if(NsGetDd1SoeLib(&SoeData)==ON)
|
||||
{
|
||||
SendCount++;
|
||||
/* Information Object Address now three byte: 0xc01---0xc80 */
|
||||
Object=SoeData.SendNumber+0x01;
|
||||
P=(unsigned char *)&Object;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
NsIec104Struct.SendBuffer[Index++]=SoeData.State;
|
||||
Msecond=SoeData.Msecond+SoeData.Second*1000;
|
||||
P=(unsigned char *)&Msecond;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendBuffer[Index++]=SoeData.Minute;
|
||||
NsIec104Struct.SendBuffer[Index++]=SoeData.Hour;
|
||||
NsIec104Struct.SendBuffer[Index++]=SoeData.Day;
|
||||
NsIec104Struct.SendBuffer[Index++]=SoeData.Month;
|
||||
NsIec104Struct.SendBuffer[Index++]=(SoeData.Year-2000);
|
||||
|
||||
}
|
||||
}
|
||||
/* Repair Length */
|
||||
NsIec104Struct.SendBuffer[7]=SendCount; /* vsq number */
|
||||
NsIec104Struct.SendBuffer[1]=Index-2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(NsIec104Cycle[0].TimeSign== ON)
|
||||
{
|
||||
Index=0;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x68;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x04;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x43;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
NsIec104Cycle[0].TimeSign=OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Index>0)
|
||||
{
|
||||
NsIec104Struct.SendLength=send(NsIec104Struct.NsNewSocketId,&NsIec104Struct.SendBuffer[0],Index,0x0);
|
||||
CosSendSign=0x01;
|
||||
}
|
||||
return CosSendSign;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void NsIec104ProcessYkYt(void)
|
||||
{
|
||||
|
||||
unsigned char YkInformation,YkReason,YkWhat;
|
||||
unsigned short YkObject;
|
||||
unsigned char Media,YkAction;
|
||||
NS_RELATION Dear;
|
||||
|
||||
/*
|
||||
Information Object Address 0xb01---0xb80
|
||||
for(i=0;i< NS_IEC_104_REASONBYTE;i++)
|
||||
NsIec104Struct.TransmitReason[i]=NsIec104Struct.ReceiveBuffer[NS_STARTREASON+i];
|
||||
for(i=0;i<NS_IEC_104_INFORMATIONBYTE;i++)
|
||||
NsIec104Struct.InformationObject[i]=NsIec104Struct.ReceiveBuffer[NS_STARTINFORMATION+i];
|
||||
|
||||
*/
|
||||
|
||||
YkInformation=NsIec104Struct.ReceiveBuffer[NS_STARTINFORMATION+NS_IEC_104_INFORMATIONBYTE];
|
||||
YkReason=NsIec104Struct.ReceiveBuffer[NS_STARTREASON];
|
||||
|
||||
YkObject=NsIec104Struct.ReceiveBuffer[NS_STARTINFORMATION]+NsIec104Struct.ReceiveBuffer[NS_STARTINFORMATION+1]*256;
|
||||
YkObject-=0xb01;
|
||||
|
||||
YkWhat=0; /* nothing */
|
||||
if(YkReason==6)
|
||||
{
|
||||
if(YkInformation&0x80) /* YkSelect */
|
||||
YkWhat=1;
|
||||
else
|
||||
YkWhat=2; /* YkExe*/
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
if(YkReason==8) /* Esc*/
|
||||
YkWhat=3;
|
||||
|
||||
switch(YkWhat)
|
||||
{
|
||||
case 1: /* select */
|
||||
NsIec104Struct.ReceiveYkId=YkObject;
|
||||
YkAction=YkInformation&0x03;
|
||||
switch(YkAction)
|
||||
{
|
||||
case 1: /* Open */
|
||||
NsIec104Struct.YkCellAction=NS_TRIP;
|
||||
break;
|
||||
case 2: /* close */
|
||||
NsIec104Struct.YkCellAction=NS_CLOSE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
NsIec104Struct.YkCellNumber=NsGetYkCell(NS_YK_CELL_NUMBER,NsIec104Struct.ReceiveYkId);
|
||||
NsIec104Struct.YkKgNumber=NsGetYkCell(NS_YK_CELL_KG,NsIec104Struct.ReceiveYkId);
|
||||
NsIec104Struct.YkNowState=NS_YK_SELECT;
|
||||
Media=NsGetYkCell(NS_YK_CELL_CPU,NsIec104Struct.ReceiveYkId);
|
||||
Dear.NsYkPort=NsIec104Struct.Card+NS_IEC_104_YK_BASE_PORT;
|
||||
Dear.NsYkSlavePort=Media;
|
||||
NsPutDear(&Dear,6);
|
||||
NsIec104SendYkMessage(NS_YK_SELECT,NsIec104Struct.YkCellAction);
|
||||
NsIec104Struct.YkStartSign=ON;
|
||||
getforsecond(&NsIec104Struct.YkStartTime);
|
||||
/*
|
||||
printf("\n Send Yk SelectId=%d Cell=%d Kg=%d",NsIec104Struct.ReceiveYkId,NsIec104Struct.YkCellNumber,NsIec104Struct.YkKgNumber);
|
||||
*/
|
||||
break;
|
||||
case 2: /* YkExe */
|
||||
NsIec104Struct.ReceiveYkId=YkObject;
|
||||
YkAction=YkInformation&0x03;
|
||||
switch(YkAction)
|
||||
{
|
||||
case 1: /* Open */
|
||||
NsIec104Struct.YkCellAction=NS_TRIP;
|
||||
break;
|
||||
case 2: /* close */
|
||||
NsIec104Struct.YkCellAction=NS_CLOSE;
|
||||
break;
|
||||
default:
|
||||
NsIec104Struct.YkCellAction=0xff;
|
||||
break;
|
||||
}
|
||||
NsIec104Struct.YkCellNumber=NsGetYkCell(NS_YK_CELL_NUMBER,NsIec104Struct.ReceiveYkId);
|
||||
NsIec104Struct.YkKgNumber=NsGetYkCell(NS_YK_CELL_KG,NsIec104Struct.ReceiveYkId);
|
||||
NsIec104Struct.YkNowState=NS_YK_EXE;
|
||||
Media=NsGetYkCell(NS_YK_CELL_CPU,NsIec104Struct.ReceiveYkId);
|
||||
Dear.NsYkPort=NsIec104Struct.Card+NS_IEC_104_YK_BASE_PORT;
|
||||
Dear.NsYkSlavePort=Media;
|
||||
NsPutDear(&Dear,6);
|
||||
NsIec104SendYkMessage(NS_YK_EXE,NsIec104Struct.YkCellAction);
|
||||
NsIec104Struct.YkStartSign=ON;
|
||||
getforsecond(&NsIec104Struct.YkStartTime);
|
||||
/*
|
||||
printf("\n Send Yk ExeId=%d Cell=%d Kg=%d",NsIec104Struct.ReceiveYkId,NsIec104Struct.YkCellNumber,NsIec104Struct.YkKgNumber);
|
||||
*/
|
||||
break;
|
||||
case 3:
|
||||
NsIec104Struct.ReceiveYkId=YkObject;
|
||||
YkAction=YkInformation&0x03;
|
||||
switch(YkAction)
|
||||
{
|
||||
case 1: /* Open */
|
||||
NsIec104Struct.YkCellAction=NS_TRIP;
|
||||
break;
|
||||
case 2: /* close */
|
||||
NsIec104Struct.YkCellAction=NS_CLOSE;
|
||||
break;
|
||||
default:
|
||||
NsIec104Struct.YkCellAction=0xff;
|
||||
break;
|
||||
}
|
||||
NsIec104Struct.YkCellNumber=NsGetYkCell(NS_YK_CELL_NUMBER,NsIec104Struct.ReceiveYkId);
|
||||
NsIec104Struct.YkKgNumber=NsGetYkCell(NS_YK_CELL_KG,NsIec104Struct.ReceiveYkId);
|
||||
NsIec104Struct.YkNowState=NS_YK_ESC;
|
||||
Media=NsGetYkCell(NS_YK_CELL_CPU,NsIec104Struct.ReceiveYkId);
|
||||
Dear.NsYkPort=NsIec104Struct.Card+NS_IEC_104_YK_BASE_PORT;
|
||||
Dear.NsYkSlavePort=Media;
|
||||
NsPutDear(&Dear,6);
|
||||
NsIec104SendYkMessage(NS_YK_ESC,NsIec104Struct.YkCellAction);
|
||||
NsIec104Struct.YkStartSign=ON;
|
||||
getforsecond(&NsIec104Struct.YkStartTime);
|
||||
/*
|
||||
printf("\n Send Yk EscId=%d Cell=%d Kg=%d",NsIec104Struct.ReceiveYkId,NsIec104Struct.YkCellNumber,NsIec104Struct.YkKgNumber);
|
||||
*/
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void NsIec104SendYkMessage(short Who,unsigned char Action)
|
||||
{
|
||||
|
||||
char Dd1Message[16];
|
||||
|
||||
switch(Who)
|
||||
{
|
||||
case NS_YK_ESC:
|
||||
Dd1Message[0]=SEND_YK_HOST_DD1;
|
||||
Dd1Message[1]=NS_YK_ESC;
|
||||
Dd1Message[2]=NsIec104Struct.YkCellNumber;
|
||||
Dd1Message[3]=NsIec104Struct.YkKgNumber;
|
||||
Dd1Message[4]=NsIec104Struct.YkCellAction;
|
||||
NsHostSendYkMessage(SEND_YK_HOST_DD1,8,Dd1Message);
|
||||
break;
|
||||
case NS_YK_EXE:
|
||||
Dd1Message[0]=SEND_YK_HOST_DD1;
|
||||
Dd1Message[1]=NS_YK_EXE;
|
||||
Dd1Message[2]=NsIec104Struct.YkCellNumber;
|
||||
Dd1Message[3]=NsIec104Struct.YkKgNumber;
|
||||
Dd1Message[4]=NsIec104Struct.YkCellAction;
|
||||
NsHostSendYkMessage(SEND_YK_HOST_DD1,8,Dd1Message);
|
||||
break;
|
||||
case NS_YK_SELECT:
|
||||
Dd1Message[0]=SEND_YK_HOST_DD1;
|
||||
Dd1Message[1]=NS_YK_SELECT;
|
||||
Dd1Message[2]=NsIec104Struct.YkCellNumber;
|
||||
Dd1Message[3]=NsIec104Struct.YkKgNumber;
|
||||
Dd1Message[4]=NsIec104Struct.YkCellAction;
|
||||
NsHostSendYkMessage(SEND_YK_HOST_DD1,8,Dd1Message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void NsIec104ReceiveYkReturn(void)
|
||||
{
|
||||
char ReturnMessage[16];
|
||||
int Length,HasMessage;
|
||||
NS_RELATION Dear;
|
||||
|
||||
if(NsIec104Struct.YkStartSign==ON)
|
||||
{
|
||||
NsGetDear(&Dear);
|
||||
if(Dear.NsYkPort==(NsIec104Struct.Card+NS_IEC_104_YK_BASE_PORT))
|
||||
{
|
||||
/*
|
||||
printf("\n Yk Return");
|
||||
*/
|
||||
if(NsHostReceiveYkMessage(SEND_YK_HOST_DD1,ReturnMessage)==1)
|
||||
{
|
||||
|
||||
/*
|
||||
printf("\nYkMes0=%0x--1=%0x--2=%0x---3=%0x---4=%0x",
|
||||
ReturnMessage[0],ReturnMessage[1],ReturnMessage[2],ReturnMessage[3],ReturnMessage[4]);
|
||||
*/
|
||||
|
||||
if(ReturnMessage[0]==SEND_YK_HOST_DD1)
|
||||
{
|
||||
if(NsIec104Struct.YkNowState==ReturnMessage[1])
|
||||
{
|
||||
if((ReturnMessage[2]==NsIec104Struct.YkCellNumber)&&
|
||||
(ReturnMessage[3]==NsIec104Struct.YkKgNumber)&&
|
||||
(ReturnMessage[4]==NsIec104Struct.YkCellAction))
|
||||
{
|
||||
NsIec104Struct.YkError=ReturnMessage[5];
|
||||
if(NsIec104Struct.YkNowState==NS_YK_SELECT)
|
||||
{
|
||||
NsIec104SendYkSelectConfirm();
|
||||
/*
|
||||
printf("\n Selec Confim");
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
if(NsIec104Struct.YkNowState==NS_YK_EXE)
|
||||
NsIec104SendYkExeConfirm();
|
||||
else
|
||||
{
|
||||
if(NsIec104Struct.YkNowState==NS_YK_ESC)
|
||||
NsIec104SendYkEscConfirm();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void NsIec104SendYkSelectConfirm(void)
|
||||
{
|
||||
|
||||
|
||||
unsigned short YkObject,Index;
|
||||
unsigned char *P,i;
|
||||
unsigned short RealNumber;
|
||||
|
||||
|
||||
|
||||
Index=0;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x68;
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
|
||||
RealNumber=(NsIec104Struct.SendMeNumber<<1);
|
||||
P=(unsigned char *)&RealNumber;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0]; /* send number */
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendMeNumber=(NsIec104Struct.SendMeNumber+1)%65535;
|
||||
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[0]; /* receive number */
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.ReceiveHimNumber[1];
|
||||
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.YkYtType; /* asdu type */
|
||||
NsIec104Struct.SendBuffer[Index++]=1; /* information object count */
|
||||
|
||||
/* REASONBYTE now is two */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x07; /* reason */
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00; /* reason */
|
||||
|
||||
|
||||
for(i=0;i<NS_IEC_104_ASDUADDRESSBYTE;i++)
|
||||
NsIec104Struct.SendBuffer[Index++]=NsIec104Struct.CommonAsduAddress[i];
|
||||
|
||||
/* Information Object Address now three byte: 0xc01---0xc80 */
|
||||
YkObject=NsIec104Struct.ReceiveYkId+0xb01;
|
||||
P=(unsigned char *)&YkObject;
|
||||
NsIec104Struct.SendBuffer[Index++]=P[0];
|
||||
NsIec104Struct.SendBuffer[Index++]=P[1];
|
||||
NsIec104Struct.SendBuffer[Index++]=0x00;
|
||||
/* Value */
|
||||
if(NsIec104Struct.YkCellAction==NS_TRIP)
|
||||
NsIec104Struct.SendBuffer[Index++]=0x81;
|
||||
else
|
||||
if(NsIec104Struct.YkCellAction==NS_CLOSE)
|
||||
NsIec104Struct.SendBuffer[Index++]=0x82;
|
||||
else
|
||||
|
@ -0,0 +1,59 @@
|
||||
#############################################################################
|
||||
# HTService project makefile
|
||||
#
|
||||
# 说明:
|
||||
# CFLAGS: 宏BIG_ENDIAN在Sun Solaris下必须设定,而在Linux系统下不能设定此宏.
|
||||
# LIBS : 在Sun Solaris下必须指定库"-lsocket",在Linux下必须去除该库.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
# flags
|
||||
CC = g++
|
||||
CFLAGS = -Wall
|
||||
LFLAGS =
|
||||
|
||||
# args
|
||||
RELEASE =0
|
||||
BITS =
|
||||
|
||||
# [args] 生成模式. 0代表debug模式, 1代表release模式. make RELEASE=1.
|
||||
ifeq ($(RELEASE),0)
|
||||
# debug
|
||||
CFLAGS += -g
|
||||
else
|
||||
# release
|
||||
CFLAGS += -static -O3 -DNDEBUG
|
||||
LFLAGS += -static
|
||||
endif
|
||||
|
||||
# [args] 程序位数. 32代表32位程序, 64代表64位程序, 其他默认. make BITS=32.
|
||||
ifeq ($(BITS),32)
|
||||
CFLAGS += -m32
|
||||
LFLAGS += -m32
|
||||
else
|
||||
ifeq ($(BITS),64)
|
||||
CFLAGS += -m64
|
||||
LFLAGS += -m64
|
||||
else
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
.PHONY : all clean
|
||||
|
||||
# files
|
||||
TARGETS = gcc64_make
|
||||
OBJS = gcc64_make.o
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
gcc64_make : $(OBJS)
|
||||
$(CC) $(LFLAGS) -o $@ $^
|
||||
|
||||
|
||||
gcc64_make.o : gcc64_make.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
|
||||
clean :
|
||||
rm -f $(OBJS) $(TARGETS) $(addsuffix .exe,$(TARGETS))
|
@ -0,0 +1,50 @@
|
||||
#############################################################################
|
||||
# HTService project makefile
|
||||
#
|
||||
# 说明:
|
||||
# CFLAGS: 宏BIG_ENDIAN在Sun Solaris下必须设定,而在Linux系统下不能设定此宏.
|
||||
# LIBS : 在Sun Solaris下必须指定库"-lsocket",在Linux下必须去除该库.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
CC = g++
|
||||
|
||||
MYSQL_PATH = /usr/local/mysql-5.5.61
|
||||
MYSQL_LIB_FILE = mysqlclient
|
||||
|
||||
#CFLAGS = -c -Werror -g -D_REENTRANT -Wformat -Wsign-compare -O3 -ansi
|
||||
CFLAGS = -c -Werror -g -D_DEBUG -D_REENTRANT -Wformat -Wsign-compare -O3 -ansi
|
||||
LIBS = -L$(MYSQL_PATH)/lib -l$(MYSQL_LIB_FILE) `pkg-config --libs opencv` -lnsl -lpthread -lm -lc -lstdc++
|
||||
|
||||
INCPATH = -I../include -I$(MYSQL_PATH)/include `pkg-config --cflags opencv`
|
||||
|
||||
# global file
|
||||
OBJS_PATH = ../obj
|
||||
OBJS = $(OBJS_PATH)/HTService.o $(OBJS_PATH)/HTGlobal.o \
|
||||
$(OBJS_PATH)/HTPublic.o $(OBJS_PATH)/HTThread.o \
|
||||
$(OBJS_PATH)/HTInitUtils.o $(OBJS_PATH)/HTLogger.o \
|
||||
$(OBJS_PATH)/HTDatabase.o $(OBJS_PATH)/HTTcpSocket.o \
|
||||
$(OBJS_PATH)/HTConfig.o $(OBJS_PATH)/HTIEC104.o \
|
||||
$(OBJS_PATH)/NsIec104Server.o $(OBJS_PATH)/HTCP56Time2a.o \
|
||||
$(OBJS_PATH)/HTOpencvImg.o $(OBJS_PATH)/HTTestOpencv.o
|
||||
|
||||
TARGET = ../bin/HTService
|
||||
|
||||
# for link
|
||||
$(TARGET):$(OBJS)
|
||||
$(CC) -Wall -O3 -o $(TARGET) $(OBJS) $(LIBS)
|
||||
|
||||
$(OBJS_PATH)/%.o : ./%.cpp
|
||||
$(CC) $(CFLAGS) $(INCPATH) $< -o $@
|
||||
$(OBJS_PATH)/%.o : ./compress/%.c
|
||||
cc $(CFLAGS) $(INCPATH) $< -o $@
|
||||
|
||||
################################################################
|
||||
# clean flag str....
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS_PATH)/*.o ../bin/core.* ../log/*.log $(TARGET)
|
||||
log :
|
||||
rm -rf ../log/*.log ../bin/core.*
|
||||
obj:
|
||||
rm -rf $(OBJS_PATH)/*.o
|
@ -0,0 +1,55 @@
|
||||
#############################################################################
|
||||
# HTService project makefile
|
||||
#
|
||||
# 说明:
|
||||
# CFLAGS: 宏BIG_ENDIAN在Sun Solaris下必须设定,而在Linux系统下不能设定此宏.
|
||||
# LIBS : 在Sun Solaris下必须指定库"-lsocket",在Linux下必须去除该库.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
CC = g++
|
||||
|
||||
#MYSQL_PATH = /usr/local/mysql-5.5.43
|
||||
MYSQL_PATH = /usr/local/mysql-5.7.28
|
||||
MYSQL_LIB_FILE = mysqlclient
|
||||
|
||||
#CFLAGS = -c -Werror -g -D_REENTRANT -Wformat -Wsign-compare -O3 -ansi
|
||||
CFLAGS = -c -Werror -g -D_DEBUG -D_REENTRANT -Wformat -Wsign-compare -O3 -ansi
|
||||
LIBS = -L$(MYSQL_PATH)/lib -l$(MYSQL_LIB_FILE) `pkg-config --libs opencv` -lnsl -luuid -lpthread -lm -lc -lstdc++
|
||||
|
||||
INCPATH = -I../include -I$(MYSQL_PATH)/include `pkg-config --cflags opencv`
|
||||
|
||||
# global file
|
||||
OBJS_PATH = ../obj
|
||||
OBJS = $(OBJS_PATH)/HTService.o $(OBJS_PATH)/HTGlobal.o \
|
||||
$(OBJS_PATH)/HTPublic.o $(OBJS_PATH)/HTThread.o \
|
||||
$(OBJS_PATH)/HTInitUtils.o $(OBJS_PATH)/HTLogger.o \
|
||||
$(OBJS_PATH)/HTDatabase.o $(OBJS_PATH)/HTTcpSocket.o \
|
||||
$(OBJS_PATH)/HTConfig.o $(OBJS_PATH)/HTIEC104.o \
|
||||
$(OBJS_PATH)/HXIec104.o $(OBJS_PATH)/HTCP56Time.o \
|
||||
$(OBJS_PATH)/HTImageBusi.o $(OBJS_PATH)/HTMemCacheData.o \
|
||||
$(OBJS_PATH)/HTOpencvImg.o $(OBJS_PATH)/HTUnit.o
|
||||
# $(OBJS_PATH)/HTTestOpencv.o
|
||||
|
||||
|
||||
TARGET = ../bin/iecserver
|
||||
#TARGET = ../bin/IMGService
|
||||
|
||||
# for link
|
||||
$(TARGET):$(OBJS)
|
||||
$(CC) -Wall -O3 -o $(TARGET) $(OBJS) $(LIBS)
|
||||
|
||||
$(OBJS_PATH)/%.o : ./%.cpp
|
||||
$(CC) $(CFLAGS) $(INCPATH) $< -o $@
|
||||
$(OBJS_PATH)/%.o : ./compress/%.c
|
||||
cc $(CFLAGS) $(INCPATH) $< -o $@
|
||||
|
||||
################################################################
|
||||
# clean flag str....
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS_PATH)/*.o ../bin/core.* ../log/*.log $(TARGET)
|
||||
log :
|
||||
rm -rf ../log/*.log ../bin/core.*
|
||||
obj:
|
||||
rm -rf $(OBJS_PATH)/*.o
|
@ -0,0 +1,59 @@
|
||||
#############################################################################
|
||||
# HTService project makefile
|
||||
#
|
||||
# 说明:
|
||||
# CFLAGS: 宏BIG_ENDIAN在Sun Solaris下必须设定,而在Linux系统下不能设定此宏.
|
||||
# LIBS : 在Sun Solaris下必须指定库"-lsocket",在Linux下必须去除该库.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
# flags
|
||||
CC = g++
|
||||
CFLAGS = -Wall
|
||||
LFLAGS =
|
||||
|
||||
# args
|
||||
RELEASE =0
|
||||
BITS =
|
||||
|
||||
# [args] 生成模式. 0代表debug模式, 1代表release模式. make RELEASE=1.
|
||||
ifeq ($(RELEASE),0)
|
||||
# debug
|
||||
CFLAGS += -g
|
||||
else
|
||||
# release
|
||||
CFLAGS += -static -O3 -DNDEBUG
|
||||
LFLAGS += -static
|
||||
endif
|
||||
|
||||
# [args] 程序位数. 32代表32位程序, 64代表64位程序, 其他默认. make BITS=32.
|
||||
ifeq ($(BITS),32)
|
||||
CFLAGS += -m32
|
||||
LFLAGS += -m32
|
||||
else
|
||||
ifeq ($(BITS),64)
|
||||
CFLAGS += -m64
|
||||
LFLAGS += -m64
|
||||
else
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
.PHONY : all clean
|
||||
|
||||
# files
|
||||
TARGETS = gcc64_make
|
||||
OBJS = gcc64_make.o
|
||||
|
||||
all : $(TARGETS)
|
||||
|
||||
gcc64_make : $(OBJS)
|
||||
$(CC) $(LFLAGS) -o $@ $^
|
||||
|
||||
|
||||
gcc64_make.o : gcc64_make.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
|
||||
clean :
|
||||
rm -f $(OBJS) $(TARGETS) $(addsuffix .exe,$(TARGETS))
|
Loading…
Reference in New Issue