Skip to content

Commit 15cbb56

Browse files
committed
WIP2 all mod data
1 parent e68ce27 commit 15cbb56

5 files changed

Lines changed: 82 additions & 13 deletions

File tree

can/messages/Tesla/TSModCellVoltages.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,34 @@ namespace {
1515

1616
TSModCellVoltages::TSModCellVoltages():
1717
Message(ID_TS_MOD_CELLS_VOLTS, GROUP_NONE),
18-
m_cell_voltage(),
19-
m_module_num()
18+
m_cell_data()
2019
{
2120
}
2221

2322
TSModCellVoltages::TSModCellVoltages(const DataFrame& frame):
2423
Message(ID_TS_MOD_CELLS_VOLTS, GROUP_NONE),
25-
m_cell_voltage(),
26-
m_module_num()
24+
m_cell_data()
2725
{
2826
if (frame.id() != id()) return;
2927
if (frame.size() != 8) return;
3028

31-
m_module_num = frame.getByte(1);
29+
m_cell_data.module_num = frame.getByte(1);
3230

3331
for (int i=0; i < 6; i++)
3432
{
35-
m_cell_voltage[i] = 2.0 + (frame.getByte(i+2) / 100.0f);
33+
m_cell_data.voltages[i] = 2.0 + (frame.getByte(i+2) / 100.0f);
3634
}
3735
setValid();
3836
}
3937

4038
float TSModCellVoltages::getCellVoltage(uint cell) const
4139
{
42-
return m_cell_voltage[cell];
40+
return m_cell_data.voltages[cell];
4341
}
4442

4543
uint16_t TSModCellVoltages::getModuleNum() const
4644
{
47-
return m_module_num;
45+
return m_cell_data.module_num;
4846
}
4947

5048

can/messages/Tesla/TSModCellVoltages.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ namespace Tesla {
1616
class TSModCellVoltages: public Message
1717
{
1818
public:
19+
struct CellVoltageData {
20+
uint16_t module_num;
21+
float voltages[6];
22+
};
23+
1924
TSModCellVoltages();
2025
TSModCellVoltages(const DataFrame& f);
2126

2227
uint16_t getModuleNum() const;
2328
float getCellVoltage(uint cell) const;
29+
const CellVoltageData& getCellVoltages() const { return m_cell_data; }
2430
virtual void toStream(logging::ostream&) const;
2531

2632
private:
27-
float m_cell_voltage[6];
28-
uint16_t m_module_num;
33+
CellVoltageData m_cell_data;
2934
};
3035

3136
}

logging/logging.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
using namespace std;
3232
using namespace logging;
33+
using namespace can::messages::Tesla;
34+
3335

3436
// Log file name. File name should be change from here only
3537
const string logFileName = "BatteryController.log";
@@ -42,7 +44,8 @@ Logger::Logger(LOG_LEVEL loglevel, core::Timer& timer, std::vector<monitor::Moni
4244
m_vmonitor(vmonitor),
4345
m_datalog_callback(*this, &Logger::updateDataLog),
4446
resetCallback(true),
45-
m_prev_minute(0)
47+
m_prev_minute(0),
48+
m_mod_cell_data(m_mod_cell_data) // just to initialize the reference, it will be set to the actual data in the process function when the first message is received
4649
{
4750
m_File.open(logFileName.c_str(), ios::out|ios::app);
4851
m_LogLevel = loglevel;
@@ -106,6 +109,41 @@ void Logger::setMonitor(std::vector<monitor::Monitor*> vmonitor)
106109
}
107110
}
108111

112+
void Logger::sink(const can::messages::Tesla::Message& message)
113+
{
114+
info("CAN message received in Logger", __FILENAME__, __LINE__);
115+
if (not message.valid()) return;
116+
117+
switch(message.id())
118+
{
119+
case can::messages::Tesla::ID_TS_MOD_CELLS_VOLTS:
120+
process(static_cast<const can::messages::Tesla::TSModCellVoltages&>(message));
121+
break;
122+
123+
default:
124+
// unknown id
125+
return;
126+
}
127+
}
128+
129+
// void TeslaSlaveMonitor::process(const TSBatteryStatus& battery_status)
130+
// {
131+
132+
void Logger::process(const can::messages::Tesla::TSModCellVoltages& mod_cell_volts)
133+
{
134+
m_mod_cell_data = mod_cell_volts.getCellVoltages();
135+
136+
std::string message = "TSModCellVoltages module=" + std::to_string(m_mod_cell_data.module_num);
137+
for (unsigned i = 0; i < 6; ++i)
138+
{
139+
message += " v" + std::to_string(m_mod_cell_data.voltages[i]);
140+
}
141+
142+
std::string debugMessage = message;
143+
info(debugMessage);
144+
}
145+
146+
109147
void Logger::updateDataLog()
110148
{
111149
// called once per DATALOG_CALLBACK_PERIOD

logging/logging.hpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#ifndef LOGGING_LOGGING_HPP_
22
#define LOGGING_LOGGING_HPP_
33

4+
#include "can/FrameSink.hpp"
5+
#include "can/messages/Tesla/TSModCellVoltages.hpp"
6+
#include "can/messages/Tesla/Message.hpp"
7+
8+
9+
10+
411
///////////////////////////////////////////////////////////////////////////////
512
// @File Name: Logger.h //
613
// @Author: Pankaj Choudhary //
@@ -52,6 +59,19 @@
5259

5360
#define __FILENAME__ (strrchr(__FILE__,47)+1)
5461

62+
namespace can {
63+
namespace messages {
64+
namespace Tesla {
65+
class Message;
66+
class TSTemperatures;
67+
// class CellVoltageRange;
68+
// class BatteryState;
69+
// class BatteryStatus;
70+
// class BatteryPowerLimits;
71+
}
72+
}
73+
}
74+
5575
namespace logging
5676
{
5777
// Default value for maximum number of log files
@@ -79,14 +99,16 @@ namespace logging
7999
FILE_LOG = 3,
80100
}LogType;
81101

82-
class Logger
102+
class Logger : public can::messages::Tesla::MessageSink
83103
{
84104
public:
85105
Logger(LOG_LEVEL loglevel, core::Timer& timer, std::vector<monitor::Monitor*> vmonitor);
86106
~Logger();
87107

88108
void setMonitor(std::vector<monitor::Monitor*> vmonitor);
89109

110+
virtual void sink(const can::messages::Tesla::Message&);
111+
90112
// Interface for Error Log
91113
void error(const char* text) throw();
92114
void error(std::string& text) throw();
@@ -161,6 +183,7 @@ namespace logging
161183
void logIntoFile(std::string& data);
162184
void logOnConsole(std::string& data);
163185
// void rollLogFiles();
186+
void process(const can::messages::Tesla::TSModCellVoltages& mod_cell_volts);
164187

165188
private:
166189
std::thread httpPostThread;
@@ -187,6 +210,9 @@ namespace logging
187210
#define DATA_COUNT 9
188211
AvgMinMax m_bat_data[DATA_COUNT][MAX_BATTERIES];
189212

213+
can::messages::Tesla::TSModCellVoltages::CellVoltageData &m_mod_cell_data;
214+
215+
190216
// unsigned int logSize; // Size of a log file in bytes
191217
// unsigned int maxLogFiles; // Maximum number of log files
192218
// unsigned int logFilesCount; // Count of existing log files

monitor/Tesla/TeslaSlaveMonitor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void TeslaSlaveMonitor::sink(const can::messages::Tesla::Message& message)
102102
process(static_cast<const TSBatteryStatus&>(message));
103103
break;
104104

105-
case ID_TS_TEMPS:
105+
case ID_TS_TEMPS:
106106
process(static_cast<const TSTemperatures&>(message));
107107
break;
108108

@@ -153,6 +153,8 @@ void TeslaSlaveMonitor::process(const TSBatteryStatus& battery_status)
153153
if (status != m_prev_battery_status && !m_battery_status_ok) m_log->alarm(ss,__FILENAME__,__LINE__);
154154
m_prev_battery_status = status;
155155
updateOperationalSafety();
156+
157+
m_log->info("TeslaSlaveMonitor: Battery Status processed", __FILENAME__, __LINE__);
156158
}
157159

158160
void TeslaSlaveMonitor::process(const TSVoltages& voltages)

0 commit comments

Comments
 (0)