-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugmanager.cpp
More file actions
241 lines (208 loc) · 7.29 KB
/
Copy pathdebugmanager.cpp
File metadata and controls
241 lines (208 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "debugmanager.h"
#include "sensormanager.h"
#include "carcontrolmanager.h"
#include "internalwifimanager.h"
#include "mediamanager.h"
#include "cameramanager.h"
#include "audiomanager.h"
#include <QDebug>
#include <QProcess>
#include <QJsonDocument>
#include <QJsonObject>
#include <QCoreApplication>
#include <QDateTime>
DebugManager::DebugManager(QObject *parent)
: QObject(parent)
{
m_checkTimer = new QTimer(this);
m_checkTimer->setInterval(30000); // Check every 30 seconds
connect(m_checkTimer, &QTimer::timeout, this, &DebugManager::checkTimers);
}
DebugManager::~DebugManager()
{
}
void DebugManager::runDiagnostics()
{
m_issues.clear();
m_running = true;
emit runningChanged();
qDebug() << "DebugManager: Starting diagnostics...";
checkSensorManager();
checkCarControlManager();
checkInternalWiFi();
checkMediaManager();
checkCameraManager();
checkAudioManager();
checkGStreamerPlugins();
generateReport();
m_running = false;
emit runningChanged();
emit reportUpdated();
qDebug() << "DebugManager: Diagnostics complete. Issues found:" << m_issues.count();
}
void DebugManager::saveReport(const QString &path)
{
QFile file(path);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << "=== Carputer Debug Report ===\n";
out << "Generated: " << QDateTime::currentDateTime().toString() << "\n";
if (QCoreApplication::instance()) {
out << "App Version: " << QCoreApplication::applicationVersion() << "\n\n";
}
out << m_lastReport << "\n";
file.close();
qDebug() << "DebugManager: Report saved to" << path;
}
}
void DebugManager::checkTimers()
{
// Periodic checks
if (m_sensorManager && m_sensorManager->connected()) {
// Check if receiving data
static QDateTime lastDataTime = QDateTime::currentDateTime();
// This would need a signal from SensorManager to track last data time
}
}
void DebugManager::checkSensorManager()
{
if (!m_sensorManager) {
addIssue("SensorManager", "Not initialized");
return;
}
if (!m_sensorManager->connected()) {
addIssue("SensorManager", "Not connected - UDP socket not bound");
} else {
qDebug() << "DebugManager: SensorManager OK (UDP 5001)";
}
// Check if we have valid data
if (m_sensorManager->speed() == 0 && m_sensorManager->fuelLevel() == 0) {
addIssue("SensorManager", "No sensor data received (speed=0, fuel=0)");
}
}
void DebugManager::checkCarControlManager()
{
if (!m_carControlManager) {
addIssue("CarControlManager", "Not initialized");
return;
}
if (!m_carControlManager->connected()) {
addIssue("CarControlManager", "Not connected to ESP32 at " + m_carControlManager->portName());
} else {
qDebug() << "DebugManager: CarControlManager OK (connected to" << m_carControlManager->portName() << ")";
}
// Check if properties are being updated
if (m_carControlManager->fanSpeed() == 0 && m_carControlManager->hvacEnabled() == false) {
// This is normal if HVAC is off - just log
qDebug() << "DebugManager: CarControlManager - HVAC off (normal)";
}
}
void DebugManager::checkInternalWiFi()
{
if (!m_internalWiFiManager) {
addIssue("InternalWiFiManager", "Not initialized");
return;
}
if (!m_internalWiFiManager->connected()) {
addIssue("InternalWiFiManager", "Not connected to WiFi");
} else {
qDebug() << "DebugManager: InternalWiFiManager OK (SSID:" << m_internalWiFiManager->ssid() << ")";
}
if (m_internalWiFiManager->ipAddress().isEmpty()) {
addIssue("InternalWiFiManager", "No IP address assigned");
}
if (m_internalWiFiManager->signalStrength() < -80) {
addIssue("InternalWiFiManager", "Weak signal: " + QString::number(m_internalWiFiManager->signalStrength()) + " dBm");
}
}
void DebugManager::checkMediaManager()
{
if (!m_mediaManager) {
addIssue("MediaManager", "Not initialized");
return;
}
// Check GStreamer pipeline
qDebug() << "DebugManager: MediaManager OK (current track:" << m_mediaManager->currentTrack() << ")";
}
void DebugManager::checkCameraManager()
{
if (!m_cameraManager) {
addIssue("CameraManager", "Not initialized");
return;
}
qDebug() << "DebugManager: CameraManager OK";
}
void DebugManager::checkAudioManager()
{
if (!m_audioManager) {
addIssue("AudioManager", "Not initialized");
return;
}
qDebug() << "DebugManager: AudioManager OK";
}
void DebugManager::checkGStreamerPlugins()
{
// Check for required GStreamer plugins
QStringList requiredPlugins = {
"id3demux", "mpg123audiodec", "flacdec", "alsasink", "playbin"
};
for (const QString &plugin : requiredPlugins) {
QProcess proc;
proc.setProgram("gst-inspect-1.0");
proc.setArguments({plugin});
proc.start();
proc.waitForFinished(3000);
if (proc.exitCode() != 0) {
addIssue("GStreamer", "Plugin not found: " + plugin);
} else {
qDebug() << "DebugManager: GStreamer plugin OK:" << plugin;
}
}
}
void DebugManager::addIssue(const QString &component, const QString &issue)
{
QString entry = "[" + component + "] " + issue;
m_issues.append(entry);
qWarning() << "DebugManager:" << entry;
emit issueFound(component, issue);
}
void DebugManager::generateReport()
{
QStringList report;
report << "=== CARPUTER DEBUG REPORT ===";
report << "Generated: " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
report << "";
if (m_issues.isEmpty()) {
report << "✅ NO ISSUES FOUND - All systems operational";
} else {
report << "❌ ISSUES FOUND: " + QString::number(m_issues.count());
report << "";
for (const QString &issue : m_issues) {
report << " - " + issue;
}
}
report << "";
report << "=== SYSTEM STATUS ===";
// SensorManager
if (m_sensorManager) {
report << "SensorManager: " + QString(m_sensorManager->connected() ? "✅ Connected" : "❌ Disconnected");
report << " Speed: " + QString::number(m_sensorManager->speed()) + " MPH";
report << " Fuel: " + QString::number(m_sensorManager->fuelLevel()) + "%";
report << " Coolant: " + QString::number(m_sensorManager->coolantTemp()) + "°F";
}
// CarControlManager
if (m_carControlManager) {
report << "CarControlManager: " + QString(m_carControlManager->connected() ? "✅ Connected" : "❌ Disconnected");
report << " HVAC: " + QString(m_carControlManager->hvacEnabled() ? "ON" : "OFF");
report << " Fan Speed: " + QString::number(m_carControlManager->fanSpeed());
}
// InternalWiFiManager
if (m_internalWiFiManager) {
report << "InternalWiFi: " + QString(m_internalWiFiManager->connected() ? "✅ Connected" : "❌ Disconnected");
report << " SSID: " + m_internalWiFiManager->ssid();
report << " IP: " + m_internalWiFiManager->ipAddress();
report << " Signal: " + QString::number(m_internalWiFiManager->signalStrength()) + " dBm";
}
m_lastReport = report.join("\n");
qDebug() << "DebugManager: Report generated";
}