123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #include <stdio.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <limits.h>
- #include <string.h>
- #include <ctype.h>
- #include <unistd.h>
- #include <stddef.h>
- #include <time.h>
- #include <errno.h>
- #include "main.h"
- #include "cmdopt.h"
- #include "error.h"
- #include "output.h"
- /////////////////////////////////////////////////////////////////////////////
- extern int g_nVerbosity;
- extern bool g_bPluginMode;
- /////////////////////////////////////////////////////////////////////////////
- int GfaTfuGetPercentString(uint32_t nCur, uint32_t nMax, char *pszString, size_t nCChString)
- {
- double fCur = (double)nCur;
- double fMax = (double)nMax;
- double fPerc = fCur / fMax * 100;
- int nPerc = (int)fPerc;
- snprintf(pszString, nCChString, "%3d %%", nPerc);
- return nPerc;
- }
- /////////////////////////////////////////////////////////////////////////////
- int GfaTfuPrintF(int verb, const char *pszFormat, ...)
- {
- if(verb <= g_nVerbosity)
- {
- int nRet;
- FILE *pf = (verb <= 1) ? stderr : stdout;
- va_list args;
- va_start(args, pszFormat);
- nRet = vfprintf(pf, pszFormat, args);
- fflush(pf);
- va_end(args);
- return nRet;
- }
- return 0;
- }
- int GfaTfuTaggedPrintF(int nTagNum, const char *pszFormat, ...)
- {
- if(g_bPluginMode)
- {
- int nRet;
- FILE *pf = stdout;
- char szFormat[256];
- va_list args;
- va_start(args, pszFormat);
- sprintf(szFormat, "<%d>%s</%d>\n", nTagNum, pszFormat, nTagNum);
- nRet = vfprintf(pf, szFormat, args);
- fflush(pf);
- va_end(args);
- return nRet;
- }
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- void GfaTfuDumpImageInfo(const char *pszContext, LPCGFA_IMG_INFO pii)
- {
- if((g_nVerbosity >= 2) && pszContext && pii)
- {
- TRACE2("%s Image Information:\n", pszContext);
- if( (pii->nImgLength != 0xFFFFFFFF) &&
- (pii->nImgCRC32 != 0xFFFFFFFF))
- {
- TRACE2(" Length: %u\n", pii->nImgLength);
- TRACE2(" CRC32: 0x%08X\n", pii->nImgCRC32);
- TRACE2(" Mat.Nr.: %s\n", pii->szImgMaterialNum);
- TRACE2(" Build: %s\n", pii->szImgNameBuild);
- }
- else
- {
- TRACE2(" No valid image found.\n");
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- uint64_t GfaTfuTimeval2Us(const struct timeval *ptv)
- {
- if(ptv)
- return (uint64_t)ptv->tv_sec * 1000000 + (uint64_t)ptv->tv_usec;
- return (uint64_t)-1;
- }
- /////////////////////////////////////////////////////////////////////////////
- const struct timeval* GfaTfuUs2Timeval(uint64_t usTime, struct timeval *ptv)
- {
- if(ptv)
- {
- ptv->tv_sec = usTime / 1000000;
- ptv->tv_usec = usTime % 1000000;
- }
- return ptv;
- }
- /////////////////////////////////////////////////////////////////////////////
- uint64_t GfaTfuTimespec2Ns(const struct timespec *pts)
- {
- if(pts)
- return (uint64_t)pts->tv_sec * 1000000000 + (uint64_t)pts->tv_nsec;
- return (uint64_t)-1;
- }
- /////////////////////////////////////////////////////////////////////////////
- const struct timespec* GfaTfuNs2Timespec(uint64_t nsTime, struct timespec *pts)
- {
- if(pts)
- {
- pts->tv_sec = nsTime / 1000000000;
- pts->tv_nsec = nsTime % 1000000000;
- }
- return pts;
- }
- /////////////////////////////////////////////////////////////////////////////
- int64_t GfaTfuClockDiff(const struct timespec *pts1, const struct timespec *pts2)
- {
- int64_t nRet = 0;
- if(pts1 && pts2)
- {
- uint64_t t1 = GfaTfuTimespec2Ns(pts1);
- uint64_t t2 = GfaTfuTimespec2Ns(pts2);
- nRet = (int64_t)(t1 - t2);
- }
- return nRet;
- }
- /////////////////////////////////////////////////////////////////////////////
- void GfaTfuGetClock(struct timespec *pts)
- {
- clock_gettime(CLOCK_MONOTONIC, pts);
- }
|