Skip to content

Commit 5c7a6f2

Browse files
committed
writing all data to file
1 parent cca8094 commit 5c7a6f2

4 files changed

Lines changed: 50 additions & 17 deletions

File tree

logging/logging.cpp

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,59 @@ void Logger::setMonitor(std::vector<monitor::Monitor*> vmonitor)
109109

110110
void Logger::ModCellVolts(const can::messages::Tesla::TSModCellVoltages::CellVoltageData &mod_cell_volts)
111111
{
112-
std::ostringstream ss;
113-
ss << "Module " << mod_cell_volts.module_num << " Cell Voltages: ";
114-
for (unsigned i=0; i<6; i++) {
115-
ss << mod_cell_volts.voltages[i] << " ";
116-
}
117-
info(ss, __FILENAME__, __LINE__);
112+
// the code assumes that data is received in order!
113+
// ModCelVotls first, then ModVoltTemp
114+
// so that the module cell volts and module volt/temp data are in sync
115+
// when they are logged to file in ModVoltTemps() function
116+
memcpy(&m_mod_cell_volts, &mod_cell_volts, sizeof(mod_cell_volts));
117+
118+
// std::ostringstream ss;
119+
// ss << "Module " << mod_cell_volts.module_num << " Cell Voltages: ";
120+
// for (unsigned i=0; i<6; i++) {
121+
// ss << mod_cell_volts.voltages[i] << " ";
122+
// }
123+
// info(ss, __FILENAME__, __LINE__);
118124
}
119125

120126
void Logger::ModVoltTemps(const can::messages::Tesla::TSModVoltTemp::VoltTempData &mod_volt_temp_data)
121127
{
122-
std::ostringstream ss;
123-
ss << "Module " << mod_volt_temp_data.module_num << " Voltage: " << mod_volt_temp_data.voltage << " V, Temperatures: " << mod_volt_temp_data.temperatures[0] << " C, " << mod_volt_temp_data.temperatures[1] << " C";
124-
info(ss, __FILENAME__, __LINE__);
128+
// see comment above in ModCellVolts() function about data being received in order
129+
// write module cell voltage and total voltage and temps to a file
130+
std:stringstream strstm;
131+
std::string str,strt;
132+
struct stat file_info;
133+
unsigned long fsize;
134+
char msgbuf[1024];
135+
136+
std::time_t t = std::time(0);
137+
std::tm* now = std::localtime(&t);
138+
139+
// write the date and time in quotes
140+
strstm << std::put_time(now, "\"%Y-%m-%d %H:%M:%S\",");
141+
// write the data in quotes
142+
strstm << "\"" << to_string(mod_volt_temp_data.module_num) << "\",";
143+
for (unsigned i=0; i<6; i++)
144+
{
145+
strstm << "\"" << floatToString(m_mod_cell_volts.voltages[i]) << "\",";
146+
}
147+
strstm << "\"" << floatToString(mod_volt_temp_data.voltage) << "\",";
148+
strstm << "\"" << floatToString(mod_volt_temp_data.temperatures[0]) << "\",";
149+
strstm << "\"" << floatToString(mod_volt_temp_data.temperatures[1]) << "\"\n";
150+
str = strstm.str();
151+
152+
// replace any nan with -99.9
153+
str = std::regex_replace(str, std::regex("nan"), "-99.9");
154+
155+
// write the pertanent data to a file
156+
std::ofstream file;
157+
file.open(dataFileNameMods.c_str(), ios::out|ios::app);
158+
file << str;
159+
file.close();
160+
debug("Module data written to file in build directory.");
161+
162+
// std::ostringstream ss;
163+
// ss << "Module " << mod_volt_temp_data.module_num << " Voltage: " << mod_volt_temp_data.voltage << " V, Temperatures: " << mod_volt_temp_data.temperatures[0] << " C, " << mod_volt_temp_data.temperatures[1] << " C";
164+
// info(ss, __FILENAME__, __LINE__);
125165
}
126166

127167
void Logger::updateDataLog()

logging/logging.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ namespace logging
192192
#define DATA_COUNT 9
193193
AvgMinMax m_bat_data[DATA_COUNT][MAX_BATTERIES];
194194

195+
can::messages::Tesla::TSModCellVoltages::CellVoltageData m_mod_cell_volts;
195196

196197
// unsigned int logSize; // Size of a log file in bytes
197198
// unsigned int maxLogFiles; // Maximum number of log files

monitor/Tesla/TeslaSlaveMonitor.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,11 @@ void TeslaSlaveMonitor::sink(const can::messages::Tesla::Message& message)
134134
void TeslaSlaveMonitor::process(const can::messages::Tesla::TSModVoltTemp& mod_volt_temp)
135135
{
136136
m_log->ModVoltTemps( mod_volt_temp.getVoltTempData());
137-
// jfs m_log->info("volt/temp data received", __FILENAME__, __LINE__);
138137
}
139138

140139
void TeslaSlaveMonitor::process(const can::messages::Tesla::TSModCellVoltages& mod_cell_volts)
141140
{
142-
// jfs m_mod_cell_data = mod_cell_volts.getCellVoltages();
143-
144141
m_log->ModCellVolts(mod_cell_volts.getCellVoltages());
145-
146-
// jfs m_log->info("cell data received", __FILENAME__, __LINE__);
147142
}
148143

149144
void TeslaSlaveMonitor::process(const TSBatteryStatus& battery_status)

monitor/Tesla/TeslaSlaveMonitor.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ class TeslaSlaveMonitor: public monitor::Monitor, public can::messages::Tesla::M
121121
uint32_t m_volt_temp_status;
122122
uint32_t m_failsafe_status;
123123

124-
// can::messages::Tesla::TSModCellVoltages::CellVoltageData &m_mod_cell_data;
125-
// can::messages::Tesla::TSModVoltTemp::VoltTempData &m_mod_volt_temp_data;
126-
127124
class CurrentLimitSmoothing {
128125
public:
129126
CurrentLimitSmoothing(float init_value);

0 commit comments

Comments
 (0)