int SDCardLogger::begin()
{
	end();

	DATA(F("SD card begin"));

	if (f_mount(&fatFs, "", 1) != FR_OK)
	{
		WARNING(F("SD card not mount"));
		return -3;
	}
	if (f_open(&logFile, getDateStr(), FA_WRITE | FA_OPEN_ALWAYS) != FR_OK)
	{
		WARNING(F("Log file not created"));
		return -2;
	}
	if (f_lseek(&logFile, f_size(&logFile)) != FR_OK)
	{
		WARNING(F("Log file seek error"));
		return -1;
	}
	INFO(F("SD card mounted"));
	return 0;
}
Exemple #2
0
	//-------------------------------------------------------------------------
	// Fetch the formatted UTC date
	//-------------------------------------------------------------------------
	void Date::getUTCDateStr(const string &format, string &cont) {
		getDateStr(utc, format, cont);
	}
Exemple #3
0
	void Date::getNowDateStr(const string &format, string &cont) {
		tt = time(&tt);
		local = localtime(&tt);
		getDateStr(local, format, cont);
	}
Exemple #4
0
	void Date::getNow(string& cont) {
		tt = time(&tt);
		local = localtime(&tt);
		getDateStr(local,cont);
	} 
Exemple #5
0
	//-------------------------------------------------------------------------
	// Fetch the formatted Local date
	//-------------------------------------------------------------------------
	void Date::getLocalDateStr(const string &format, string &cont) {
		getDateStr(local, format, cont);
	}
string asnCertificate::getValidTo() {
	return getDateStr(validityPeriod->contents[1]);
	}
void
nata_Log(logLevelT lv,
         int debugLevel,
         const char *file,
         int line,
         const char *func,
         const char *fmt, ...) {
    if (lv != log_Debug ||
        (lv == log_Debug &&
         debugLevel <= dbgLevel)) {

        va_list args;
        char dateBuf[32];
        char msg[4096];
        size_t hdrLen;
        size_t leftLen;
        char thdInfoBuf[1024];
        uint32_t tId;
        const char *thdName = NULL;

        if (doDate == true) {
            getDateStr(dateBuf, sizeof(dateBuf));
        } else {
            dateBuf[0] = '\0';
        }

#if defined(NATA_API_POSIX)
        tId = (unsigned int)pthread_self();
#elif defined(NATA_API_WIN32API)
        tId = (unsigned int)GetCurrentThreadId();
#else
#error Unknown/Non-supported API.
#endif // NATA_API_POSIX, NATA_API_WIN32API

        thdName = Thread::findThreadName(tId);

#ifdef NATA_API_POSIX
#ifdef NATA_OS_LINUX
        tId = Thread::getLinuxThreadId();
#endif // NATA_OS_LINUX
#endif // NATA_API_POSIX

        if (isValidString(thdName) == true) {
            snprintf(thdInfoBuf, sizeof(thdInfoBuf), "[%u:%u:%s]",
                     (unsigned int)getpid(), 
                     (unsigned int)tId,
                     thdName);
        } else {
            snprintf(thdInfoBuf, sizeof(thdInfoBuf), "[%u:%u]",
                     (unsigned int)getpid(), 
                     (unsigned int)tId);
        }

        va_start(args, fmt);
        va_end(args);

        hdrLen = snprintf(msg, sizeof(msg),
                          "%s%s%s:%s:%d:%s: ",
                          dateBuf,
                          getLevelStr(lv),
                          thdInfoBuf,
                          file, line, func);

        /*
         * hdrLen indicates the buffer length WITHOUT '\0'.
         */
        leftLen = sizeof(msg) - hdrLen;
        if (leftLen > 1) {
            (void)vsnprintf(msg + hdrLen, leftLen -1, fmt, args);
        }

        doLog(lv, msg);
    }
}
char* getDateStr(time_t time) {
    // TRACE("getDateStr");
    struct tm* ctime = gmtime(&time);
    char*      str   = getDateStr(ctime);
    return str;
}