Exemplo n.º 1
0
//append valid data to each ostream in v_os, as well as pvValidData
int DataFeed::SaveValidData(const vector<ostream*>& v_os, vector< vector<double> >* pvValidData)
{
	int num_saved = 0;

	//copy valid data into pvValidData

	if (pvValidData)
		pvValidData->push_back(vector<double>(channels.size()));

	for (size_t iChannel = 0; iChannel < channels.size(); iChannel++)
	{
		int precision = channels[iChannel]->GetPrecision();

		for (size_t i_os = 0; i_os < v_os.size(); i_os++)
		{
			*v_os[i_os] << setw(precision + 5) << setprecision(precision) << fixed;
			*v_os[i_os] << channels[iChannel]->value << ", ";
		}

		if (pvValidData)
			pvValidData->back()[iChannel] = channels[iChannel]->value;

		channels[iChannel]->UpdateStats(channels[iChannel]->value);
	}

	for (size_t i_os = 0; i_os < v_os.size(); i_os++)
		*v_os[i_os] << fixed << setprecision(3) << CurrentTime_s() << endl;

	num_saved++;

	return num_saved;
}
Exemplo n.º 2
0
void MonitorDataLogger::setConfig(bool bLogData_in, unsigned int logEvery_in)
{
	if (bLogData_in && !bLogData)
	{
		// generate the file name
		double t0 = CurrentTime_s();
		QString sDir = "C:/data/SuperLaserLand/";
		QString fileName = sDir + QString::fromStdString(GetDateTimeString(t0)) + ".csv";
		
		// Set up the file
		logFile.setFileName(fileName);
		if (logFile.open(QIODevice::WriteOnly | QIODevice::Text))
		{
			printf("Starting log file %s\n", fileName.toLatin1().constData());

			logTextStream.setDevice(&logFile);
			logTextStream << "TIME [s], ";
			for (int i = 0; i < 7; i ++)
			{
				logTextStream << channelNames->value(i);
				if (i < 6)
					logTextStream << ", ";
			}
			logTextStream << "\n";
			logTextStream.flush();
			
			bLogData = true;
			logEvery = logEvery_in;

			logCounter = 0;

			timer.restart();
		}
		else
		{
			printf("Cannot open log file %s\n", fileName.toLatin1().constData());
		}
	}
	else
	{
		bLogData = false;
		logFile.close();
	}
}