You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
7.6 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/****************************************************************************
** 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 <stdio.h>
#include <iostream>
#include <string>
#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 <iconv.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
#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);
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);
// Ŀ¼²Ù×÷º¯Êý
char* getBaseName(char* path, char *basename);
char* getDirName(char* path, char *dirname);
int iDirOrFileExist(const char *pszName);
int iBuildDirent(const char *pName);
bool bMoveFile(char *filename, char *pBakPath);
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);
bool bSplitFilenameByPath(char *pFullPath, char *pPrantPath, char *pFilename);
int iGetFileBeforString(char *pinstr, int pstrlen, char *poutstr);
// ½«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);
char *str2lower(char *s);
char *str2upper(char *s);
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);
float n2hf(float value);
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);
//´ÓµÍλµ½¸ßλ,È¡nµÄµÚmλ,m=1...32
int getBit(int n, int m);
//´ÓµÍλµ½¸ßλ.½«nµÄµÚmλÖÃ1, m=1...32
int setBitToOne(int n, int m);
//´ÓµÍλµ½¸ßλ, ½«nµÄµÚmλÖÃ0,m=1...32
int setBitToZero(int n, int m);
#ifdef __cplusplus
}
#endif
#endif // end __HT_PUBLIC_H