@@ -109,19 +109,59 @@ void Logger::setMonitor(std::vector<monitor::Monitor*> vmonitor)
109109
110110void 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
120126void 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
127167void Logger::updateDataLog ()
0 commit comments