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

1 year ago
/****************************************************************************
** 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> /*<2A>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>*/
#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() // <20><>ȡ<EFBFBD>߳<EFBFBD>ID
#define GETPID() GetCurrentProcessId() // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
#else
#define GETTID() syscall(__NR_gettid)
#define GETPID() getpid() // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void vSetPid();
int iGetPid();
// ʱ<><EFBFBD><E4BAAF>
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); // <20><>ȡʱ<C8A1><CAB1>,YYYYMMDDHH24MISS:MLSS
time_t vGetHostTimeFmtOnMillsecond(char *pszTime); // <20><>ȡʱ<C8A1><CAB1>,YYYY-MM-DD HH24:MI:SS+MLSS
unsigned int getWarnID(unsigned char *pTime, int iLen, unsigned int id);
// Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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);
// <20><>Linux<75>ļ<EFBFBD>·<EFBFBD><C2B7>תΪWindows<77><73>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ʽ
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λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
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λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
Param in :
num : source uint
Param out :
pBin : object strings.(min length = 64)
Return Code : none
*************************************************************************/
void uint64_binstr(utint64 num, char* pBin);
/*************************************************************************
Function : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת32λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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 : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ת64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Param in :
pBin : source bin string(eg. 1010101001111), need '\0' end.
Param out :
: none
Return Code : utint64 interger
*************************************************************************/
utint64 binstr_uint64(char *pBin);
/*************************************************************************
Function : <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
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);
//<2F>ӵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>λ,ȡn<C8A1>ĵ<EFBFBD>mλ,m=1...32
int getBit(int n, int m);
//<2F>ӵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>λ.<2E><>n<EFBFBD>ĵ<EFBFBD><6D><CEBB>1, m=1...32
int setBitToOne(int n, int m);
//<2F>ӵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>λ, <20><>n<EFBFBD>ĵ<EFBFBD><6D><CEBB>0,m=1...32
int setBitToZero(int n, int m);
#ifdef __cplusplus
}
#endif
#endif // end __HT_PUBLIC_H