GB2312 转UTF8

main
Matthew 2 years ago
parent 23aece1267
commit 05fcaeac89

@ -19,11 +19,15 @@ extern "C" {
// logger config parameter
#ifdef _WIN32
static const char *DEF_LOG_PATH_NAME = "..\\log" ; //日志文件目录名
static const char *DEF_RUN_INFO_PATH = "..\\run" ; // 服务运行状态日志目录
// static const char *DEF_LOG_PATH_NAME = "..\\log" ; //日志文件目录名
// static const char *DEF_RUN_INFO_PATH = "..\\run" ; // 服务运行状态日志目录
extern const char *DEF_LOG_PATH_NAME; // = "..\\log"; //日志文件目录名
extern const char *DEF_RUN_INFO_PATH; // = "..\\run"; // 服务运行状态日志目录
#else
static const char *DEF_LOG_PATH_NAME = "../log" ; //日志文件目录名
static const char *DEF_RUN_INFO_PATH = "../run" ; // 服务运行状态日志目录
// static const char *DEF_LOG_PATH_NAME = "../log" ; //日志文件目录名
// static const char *DEF_RUN_INFO_PATH = "../run" ; // 服务运行状态日志目录
extern const char *DEF_LOG_PATH_NAME; // = "../log"; //日志文件目录名
extern const char *DEF_RUN_INFO_PATH; // = "../run"; // 服务运行状态日志目录
#endif
// 打印报文类型,日志

@ -35,8 +35,11 @@
#endif
#ifdef _WIN32 //for unix
#if (_MSC_VER < 1910) // older than VS2017
#define snprintf _snprintf
#endif
#endif // (_MSC_VER < 1910)
#endif // _WIN32
#endif // end __HT_MUTEX_H

@ -16,13 +16,13 @@
#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"
#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 // 测试环境,产生随机数作为分析表的数据

@ -16,7 +16,7 @@
#include "HTGlobal.h"
#include "opencv2/opencv.hpp"
#include "opencv/cv.h"
// #include "opencv/cv.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

File diff suppressed because it is too large Load Diff

@ -29,6 +29,14 @@
static const char *_FILE_="HTLogger.cpp";
static char g_logger_time[15] ; // 日志文件名称时间(YYYYMMDD)
#ifdef _WIN32
static const char *DEF_LOG_PATH_NAME = "..\\log"; //日志文件目录名
static const char *DEF_RUN_INFO_PATH = "..\\run"; // 服务运行状态日志目录
#else
const char *DEF_LOG_PATH_NAME = "../log"; //日志文件目录名
const char *DEF_RUN_INFO_PATH = "../run"; // 服务运行状态日志目录
#endif
/* mutex define */
static mutex mutex_Debug ; //跟踪日志
static FILE *g_fp;

@ -791,4 +791,90 @@ unsigned char getGisOpenCloseState(unsigned char *site_id, unsigned char *s_eqm_
{
if (0 != stringncasecmp(
(const char*)site_id,
(const
(const char*)((m_pIter->second).site_id),
strlen((const char*)(m_pIter->second).site_id))) continue;
isClose = (m_pIter->second).bClose ;
}
}
mutex_unlock(g_map_relation_mutex);
return isClose;
}
// 从主设备关联关系中获取pszEqm_code设备的运行状态
unsigned char cGetCurrentWorkState(unsigned char *pszEqm_code)
{
unsigned char wstate[3] = { 0 };
map<string, ST_DEV_RELATION>::iterator m_pIter;
mutex_lock(g_map_relation_mutex);
m_pIter = g_map_relation.find((char*)pszEqm_code);
if (m_pIter != g_map_relation.end())
{ // pszEqm_code 为gis/ce/blq ID时
for (int c = 0; c < (int)g_map_relation.count((char*)pszEqm_code); c++, m_pIter++)
{
//if (0 != stringncasecmp(
// (const char*)pszSite_id,
// (const char*)((m_pIter->second).site_id),
// strlen((const char*)(m_pIter->second).site_id))) continue;
if (((m_pIter->second).wstate & 0xff) == 1){
wstate[0] = 1;
break;
}
else if(((m_pIter->second).wstate & 0xff) == 2){
wstate[1] = 2;
}
else wstate[2] = 3;
}
}
else {
// 当以主键(从属设备ID)没有找到时以主变设备ID再查找。
for (m_pIter = g_map_relation.begin(); m_pIter != g_map_relation.end(); m_pIter++)
{
//if (0 != stringncasecmp(
// (const char*)pszSite_id,
// (const char*)((m_pIter->second).site_id),
// strlen((const char*)(m_pIter->second).site_id))) continue;
if (0 != stringncasecmp(
(const char*)pszEqm_code,
(const char*)((m_pIter->second).m_eqm_code),
strlen((const char*)(m_pIter->second).m_eqm_code))) continue;
if (((m_pIter->second).wstate & 0xff) == 1){
wstate[0] = 1;
break;
}
else if (((m_pIter->second).wstate & 0xff) == 2){
wstate[1] = 2;
}
else wstate[2] = 3;
}
}
mutex_unlock(g_map_relation_mutex);
return (wstate[0] == 1 ? wstate[0] : (wstate[1] == 2 ? wstate[1] : (wstate[2] == 3 ? wstate[2] : 3)));
}
/***************************************************************************
** function name : thread_cache_proc
** deacription : data cache thread
** parameter : none
** return code : NULL
***************************************************************************/
void *thread_cache_proc(void *arg) // 同步内存数据线程
{
while (g_Running)
{
vLoadByqDeviceStateTable();
vLoadBYQThresholdTable(false);
vLoadDeviceRelationsTable();
vLoadIECPointTable();
vLoadImageThreshold();
//vPrtGisCacheRelation();
//vPrtBlqCacheRelation();
vPrtByqDeviceStateTable();
vPrtBYQThresholdTable();
vPrtDeviceRelationsTable();
vPrtIECPointTable();
vPrtTimeStat();
vPrtImageThreshold();
_SLEEP(1000 * 30);
}
return NULL;
}

File diff suppressed because it is too large Load Diff

@ -1009,4 +1009,279 @@ Note : 本函数入参为网络字节序列
*************************************************************************/
unsigned int int64To32(utint64 u64)
{
unsigned int hi = (unsigned int)(( u64 >> 32) & 0xFFFFFFFF
unsigned int hi = (unsigned int)(( u64 >> 32) & 0xFFFFFFFF);
return hi;
}
// YYYY-MM-DD HH:MI:SS
void LocalTime2Bcd(char *pLocalTime, char *pBcd)
{
char szDate[5]={0};
char tmpTime[13] = {0};
if(pLocalTime == NULL || pBcd == NULL)
return;
memcpy(tmpTime, pLocalTime+2, 2);
memcpy(tmpTime+2, pLocalTime+5, 2);
memcpy(tmpTime+4, pLocalTime+8, 2);
memcpy(tmpTime+6, pLocalTime+11, 2);
memcpy(tmpTime+8, pLocalTime+14, 2);
memcpy(tmpTime+10, pLocalTime+17, 2);
asc_to_bcd((unsigned char*)tmpTime, 12, (unsigned char*)pBcd);
return;
}
/*************************************************************************
Function :
Param in :
psz : source string
length : input string length, max 128(Byte)
Param out : none
Return Code : valid string length
*************************************************************************/
int getStringLen(unsigned char *pstr, int length)
{
unsigned char szTmp[128+1] = {0} ;
int i = 0;
memcpy(szTmp, pstr, length);
while(i < length) {
if((szTmp[i] & 0xff) != 0x00) {
length -= i;
memcpy(pstr, szTmp+i, length);
break;
}
i++;
}
pstr[length] = 0x00;
while(--length) {
if((pstr[length] & 0xff) != 0x00 ) return length+1;
}
return length;
}
int getHexString(unsigned char *str, int length, unsigned char *pstr)
{
int iLen = 0, iOff = 0;
char *p = (char*)str;
while ( *p == 0x00 ) {
p++;
length--;
}
memcpy( (char*)str, p,length );
str[length] = 0x00;
while(iLen < length) {
iOff = (iLen * 2);
sprintf((char*)pstr+iOff, "%.2X", (str[iLen] & 0xff));
iLen++;
}
return (length * 2);
}
/*************************************************************************
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)
{
int i;
if(pBin == NULL) return ;
for( i=0; i < (int)(sizeof(int)*8); i++)
{
pBin[(sizeof(int)*8-1)-i] = (char)(((num >> i) & 1) + '0');
}
pBin[(sizeof(int)*8)] = 0x00; // 结束符
return;
}
/*************************************************************************
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)
{
int i;
if(pBin == NULL) return ;
for(i=0; i < (int)(sizeof(utint64)*8); i++)
{
pBin[(sizeof(utint64)*8-1)-i] = (char)(((num >> i) & 1) + '0');
}
pBin[(sizeof(utint64)*8)] = 0x00; // 结束符
return;
}
/*************************************************************************
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)
{
unsigned int n = 0;
int i, len = 0 ;
if(pBin == NULL) return 0 ;
len = strlen(pBin) ;
if(len > (int)(sizeof(int)*8))
len = (int)(sizeof(int)*8) ;
for(i=0; i < len; i++) {
n = n * 2 + (pBin[i] - '0');
}
return n;
}
/*************************************************************************
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* str,int len)
{
if(len <= 1) return str;
char temp = *str;
*str = *(str+len-1);
*(str+len-1) = temp;
return (strSwap( str+1, len-2)-1);
}
/*************************************************************************
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)
{
utint64 n = 0;
int i, len = 0 ;
if(pBin == NULL) return 0 ;
len = strlen(pBin) ;
if(len > (int)(sizeof(utint64)*8))
len = (int)(sizeof(utint64)*8);
for(i=0; i < len; i++) {
n = n * 2 + (pBin[i] - '0');
}
return n;
}
/*************************************************************************
Function : LinuxWindows,
Param in :
pszPath: source path
Param out :
: pszBootPath
Return Code : none
*************************************************************************/
void Unix2WindowPath(char *pszPath)
{
// /mnt/fileserver/gathergps/10122045/p_gathergps_20130703123031.dat
char *p = NULL;
int i = 0;
if (pszPath == NULL) return;
p = pszPath;
while(p[i] != 0x00)
{
if( p[i] == '/') p[i] = '\\';
i++;
}
p[i] = 0x00;
}
/*************************************************************************
Function : WindowsLinux,
Param in : pszPath -- source path
Param out :
: pszPath
Return Code : none
*************************************************************************/
void Window2UnixPath(char *pszPath)
{
char *p = NULL;
int i = 0;
if (pszPath == NULL) return;
p = pszPath;
while (p[i] != 0x00) {
if (p[i] == '\\') p[i] = '/';
i++;
}
p[i] = 0x00;
}
int stringcasecmp(const char *ps1, const char *ps2)
{
#ifdef _WIN32
//return strcmpi(ps1, ps2);
return _strcmpi(ps1,ps2);
#else
return strcasecmp(ps1,ps2);
#endif
}
int stringncasecmp(const char *ps1, const char *ps2, int length)
{
#ifdef _WIN32
//return strnicmp(ps1,ps2,length);
return _strnicmp(ps1,ps2,length);
#else
return strncasecmp(ps1,ps2,length);
#endif
}
/*************************************************************************
Function : uuid
Param in :
Param out :
: pszPath
Return Code : none
*************************************************************************/
int getuuid(char *str, int inlen )
{
memset(str, 0x00, inlen);
#if defined(WIN32)||defined(WINCE)||defined(WIN64)
GUID guid;
if (!CoCreateGuid(&guid))
{
snprintf(str,inlen,
"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x", //小写
guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2],
guid.Data4[3], guid.Data4[4], guid.Data4[5],
guid.Data4[6], guid.Data4[7]);
}
#else
uuid_t uu;
uuid_generate(uu);
//uuid_generate_time(uu);
//uuid_generate_tims_safe(uu);
uuid_unparse(uu, str);
strMiddleTrim((unsigned char*)str);
#endif
return strlen(str);
}
/*************************************************************************
Function : 1-100
Param in :
Param out :
: pszPath
Return Code : none
*************************************************************************/
double getRandByTime()
{
srand((unsigned int)time(NULL));
return (double)((double)(rand()%100 + 1) / (double)(RAND_MAX / rand()));
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -9,14 +9,14 @@
CC = g++
MYSQL_PATH = /usr/local/mysql-5.5.61
MYSQL_LIB_PATH = /usr/lib64/mysql
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++
LIBS = -L$(MYSQL_LIB_PATH) -L/usr/local/lib64 -l$(MYSQL_LIB_FILE) -lopencv_core -lopencv_imgproc -lnsl -lpthread -lm -lc -lstdc++
INCPATH = -I../include -I$(MYSQL_PATH)/include `pkg-config --cflags opencv`
INCPATH = -I../include -I$(MYSQL_PATH)/include
# global file
OBJS_PATH = ../obj

@ -10,14 +10,14 @@
CC = g++
#MYSQL_PATH = /usr/local/mysql-5.5.43
MYSQL_PATH = /usr/local/mysql-5.7.28
MYSQL_LIB_PATH = /usr/lib64/mysql
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++
LIBS = -L$(MYSQL_LIB_PATH) -L/usr/local/lib64 -l$(MYSQL_LIB_FILE) -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lz -ldl -lpng -lnsl -luuid -lpthread -lm -lc -lstdc++
INCPATH = -I../include -I$(MYSQL_PATH)/include `pkg-config --cflags opencv`
INCPATH = -I../include -I$(MYSQL_PATH)/include
# global file
OBJS_PATH = ../obj

Loading…
Cancel
Save