15 #include <sys/types.h> 40 #if PLATFORM_IS_LINUX || PLATFORM_IS_APPLE 42 #include <sys/statvfs.h> 53 bool corrupt = (hdr !=
NULL &&
95 for (
unsigned int i = 0; i <
m_devices.size(); i++)
116 for (
unsigned int i = 0; i <
m_devices.size(); i++)
127 static const int minFileCount = 50;
128 static const int maxFileCount = 10000;
135 maxDiskSpacePercent =
_CLAMP(maxDiskSpacePercent, 0.01
f, 0.99
f);
137 m_maxDiskSpace = (maxDiskSpacePercent <= 0.0f ? availableSpace : (uint64_t)(availableSpace * maxDiskSpacePercent));
156 if (useSubFolderTimestamp)
162 if (!subDirectory.empty())
171 string str =
m_directory +
"/" + subDirectory +
"/stats.txt";
184 #if PLATFORM_IS_EVB_2 186 #if USE_RTC_DATE_TIME // use RTC 189 #else // use uINS GPS time 198 struct tm * timeinfo = localtime(&rawtime);
199 strftime(buf, 80,
"%Y%m%d_%H%M%S", timeinfo);
215 if (timeStamp.length() == 0)
225 return InitSaveCommon(logType, directory, subDirectory, numDevices, maxDiskSpacePercent, maxFileSize, useSubFolderTimestamp);
237 for (
int i = 0; i < numDevices; i++)
243 #if !defined(PLATFORM_IS_EVB_2) || !PLATFORM_IS_EVB_2 264 string fileExtensionRegex;
278 vector<ISFileManager::file_info_t> files;
280 if (files.size() == 0)
285 for (
size_t i = 0; i < files.size(); i++)
291 if (endOfLogPrefixIndex != string::npos)
294 size_t serialNumberEndIndex = name.find(
'_', endOfLogPrefixIndex);
295 if (serialNumberEndIndex != string::npos)
297 string serialNumber = name.substr(endOfLogPrefixIndex, serialNumberEndIndex - endOfLogPrefixIndex);
303 size_t timestampIndex = name.find_last_of(
'_');
304 if (timestampIndex == string::npos)
306 timestampIndex = name.find_last_of(
'.');
315 if (serialNumbers.find(serialNumber) == serialNumbers.end())
317 if (serials.size() == 0 || ((find(serials.begin(), serials.end(),
"SN" + serialNumber) != serials.end() ||
318 find(serials.begin(), serials.end(),
"ALL") != serials.end())))
320 serialNumbers.insert(serialNumber);
327 #if !defined(PLATFORM_IS_EVB_2) || !PLATFORM_IS_EVB_2 340 for (uint32_t i = 0; i <
m_devices.size(); i++)
364 m_errorFile->
lprintf(
"Corrupt log header, id: %lu, offset: %lu, size: %lu\r\n", (
unsigned long)dataHdr->
id, (
unsigned long)dataHdr->
offset, (
unsigned long)dataHdr->
size);
367 else if (!
m_devices[device]->SaveData(dataHdr, dataBuf))
382 std::ostringstream outFilePath;
383 outFilePath <<
m_directory <<
"/diagnostic_" <<
m_devices[device]->GetDeviceInfo()->serialNumber <<
".txt";
388 std::string msg = (((
diag_msg_t*)dataBuf)->message);
389 outfile->write(msg.c_str(), msg.length());
390 if (msg.length() > 0 && *msg.end() !=
'\n')
392 outfile->putch(
'\n');
441 for(
unsigned int i = 0; i <
m_devices.size(); i++ )
453 for (
unsigned int i = 0; i <
m_devices.size(); i++)
463 for (
size_t i = 0; i <
m_devices.size(); i++)
495 return m_devices[device]->LogSize() * 0.000001f;
506 return m_devices[device]->FileSize() * 0.000001f;
527 m_devices[device]->SetDeviceInfo( info );
538 return m_devices[device]->GetDeviceInfo();
563 if (logType == eLogType::LOGTYPE_CSV)
577 LogData(dev, &hdr, (uint8_t*)&ins1);
596 unsigned int deviceId = 0;
597 unsigned int lastDeviceId = 0xFFFFFEFE;
599 vector<vector<uint8_t>>* currentDeviceData =
NULL;
601 uint8_t* ptr, *ptrEnd;
608 if (deviceId != lastDeviceId)
610 lastDeviceId = deviceId;
616 assert(currentDeviceData !=
NULL);
619 while (currentDeviceData->size() < p->
hdr.
id)
621 currentDeviceData->push_back(vector<uint8_t>());
626 vector<uint8_t>& stream = (*currentDeviceData)[p->
hdr.
id];
627 for (ptr = p->
buf; ptr != ptrEnd; ptr++)
629 stream.push_back(*ptr);
639 averageTimeDelta = 0.0;
640 totalTimeDelta = 0.0;
642 lastTimestampDelta = 0.0;
643 maxTimestampDelta = 0.0;
644 minTimestampDelta = 1.0E6;
645 timestampDeltaCount = 0;
646 timestampDropCount = 0;
652 if (
_ISNAN(timestamp) || timestamp < 0.0 || timestamp > 999999999999.0)
656 else if (lastTimestamp > 0.0)
658 double delta = fabs(timestamp - lastTimestamp);
659 minTimestampDelta =
_MIN(delta, minTimestampDelta);
660 maxTimestampDelta =
_MAX(delta, maxTimestampDelta);
661 totalTimeDelta += delta;
662 averageTimeDelta = (totalTimeDelta / (double)++timestampDeltaCount);
663 if (lastTimestampDelta != 0.0 && (fabs(delta - lastTimestampDelta) > (lastTimestampDelta * 0.5)))
665 timestampDropCount++;
667 lastTimestampDelta = delta;
669 lastTimestamp = timestamp;
675 #if !PLATFORM_IS_EMBEDDED 677 printf(
" Count: %llu, Errors: %llu\r\n", (
unsigned long long)
count, (
unsigned long long)errorCount);
678 printf(
" Time delta: (ave, min, max) %f, %f, %f\r\n", averageTimeDelta, minTimestampDelta, maxTimestampDelta);
679 printf(
" Time delta drop: %llu\r\n", (
unsigned long long)timestampDropCount);
692 memset(dataIdStats, 0,
sizeof(dataIdStats));
693 for (uint32_t
id = 0;
id <
DID_COUNT;
id++)
695 dataIdStats[id].minTimestampDelta = 1.0E6;
728 if (timestamp != 0.0)
738 #if !PLATFORM_IS_EMBEDDED 742 printf(
"Count: %llu, Errors: %llu\r\n", (
unsigned long long)
count, (
unsigned long long)errorCount);
743 for (uint32_t
id = 0;
id <
DID_COUNT;
id++)
745 if (dataIdStats[
id].count != 0)
747 printf(
" DID: %d\r\n",
id);
748 dataIdStats[id].Printf();
764 statsFile->
lprintf(
"Total count: %d, Total errors: \r\n\r\n",
count, errorCount);
765 for (uint32_t
id = 0;
id <
DID_COUNT;
id++)
784 stats << fixed << setprecision(6);
785 stats <<
"Total count: " <<
count <<
", Total errors: " << errorCount << CRLF << CRLF;
786 for (uint32_t
id = 0;
id <
DID_COUNT;
id++)
795 stats <<
"Count: " << stat.
count <<
", Errors: " << stat.
errorCount << CRLF;
801 statsFile->
puts(stats.str().c_str());
static const char * GetDataSetName(uint32_t dataId)
vector< cDeviceLog * > m_devices
void convertIns2ToIns1(ins_2_t *ins2, ins_1_t *result)
bool InitSave(eLogType logType=LOGTYPE_DAT, const string &directory=g_emptyString, int numDevices=1, float maxDiskSpacePercent=0.5f, uint32_t maxFileSize=1024 *1024 *5, bool useSubFolderTimestamp=true)
bool CopyLog(cISLogger &log, const string ×tamp=g_emptyString, const string &outputDir=g_emptyString, eLogType logType=LOGTYPE_DAT, float maxDiskSpacePercent=0.5f, uint32_t maxFileSize=1024 *1024 *5, bool useSubFolderTimestamp=true)
bool InitDevicesForWriting(int numDevices=1)
uint32_t FileCount(unsigned int device=0)
void LogTimestamp(double timestamp)
static bool ReadAllLogDataIntoMemory(const string &directory, map< uint32_t, vector< vector< uint8_t >>> &data)
float LogSizeMB(unsigned int device=0)
uint32_t GetDeviceCount()
uint64_t timestampDropCount
void rtc_get_time(Rtc *p_rtc, uint32_t *pul_hour, uint32_t *pul_minute, uint32_t *pul_second)
Get the RTC time value.
bool PathIsDir(const std::string &path)
void LogDataAndTimestamp(uint32_t dataId, double timestamp)
size_t count(InputIterator first, InputIterator last, T const &item)
void LogData(uint32_t dataId)
void LogError(const p_data_hdr_t *hdr)
char copyDataPToStructP(void *sptr, const p_data_t *data, const unsigned int maxsize)
cISLogFileBase * CreateISLogFile()
p_data_t * ReadData(unsigned int device=0)
#define DEFAULT_LOGS_DIRECTORY
void CloseISLogFile(cISLogFileBase *&logFile)
const dev_info_t * GetDeviceInfo(unsigned int device=0)
virtual int lprintf(const char *format,...)=0
void EnableLogging(bool enabled)
bool LogData(unsigned int device, p_data_hdr_t *dataHdr, const uint8_t *dataBuf)
static double GetTimestamp(const p_data_hdr_t *hdr, const uint8_t *buf)
uint64_t GetDirectorySpaceAvailable(const std::string &directory)
cISLogFileBase * m_errorFile
static bool LogHeaderIsCorrupt(const p_data_hdr_t *hdr)
static bool LogDataIsCorrupt(const p_data_t *data)
bool InitSaveTimestamp(const string &timeStamp, const string &directory=g_emptyString, const string &subDirectory=g_emptyString, int numDevices=1, eLogType logType=LOGTYPE_DAT, float maxDiskSpacePercent=0.5f, uint32_t maxFileSize=1024 *1024 *5, bool useSubFolderTimestamp=true)
#define IS_LOG_FILE_PREFIX
#define DID_DIAGNOSTIC_MESSAGE
#define _ARRAY_BYTE_COUNT(a)
virtual int puts(const char *str)=0
double m_iconUpdatePeriodSec
float FileSizeMB(unsigned int device=0)
#define _CLAMP(v, minV, maxV)
date_time_t g_gps_date_time
USBInterfaceDescriptor data
time_t m_timeoutFlushSeconds
bool InitSaveCommon(eLogType logType, const string &directory, const string &subDirectory, int numDevices, float maxDiskSpacePercent, uint32_t maxFileSize, bool useSubFolderTimestamp)
std::string GetFileName(const std::string &path)
bool LoadFromDirectory(const string &directory, eLogType logType=LOGTYPE_DAT, vector< string > serials={})
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
uint64_t GetDirectorySpaceUsed(const std::string &directory, bool recursive)
static const string g_emptyString
bool SetDeviceInfo(const dev_info_t *info, unsigned int device=0)
void rtc_get_date(Rtc *p_rtc, uint32_t *pul_year, uint32_t *pul_month, uint32_t *pul_day, uint32_t *pul_week)
Get the RTC date value.
static string CreateCurrentTimestamp()
uint64_t LogSize(unsigned int device=0)
uint8_t buf[MAX_DATASET_SIZE]
#define IS_LOG_TIMESTAMP_LENGTH
bool TouchFile(const std::string &path)
#define IS_LOG_FILE_PREFIX_LENGTH
#define RTC
(RTC ) Base Address
void WriteToFile(const string &fileName)
p_data_t * ReadNextData(unsigned int &device)