From ab6fb33717690e99d216b6fb400ec429bba6207b Mon Sep 17 00:00:00 2001 From: bruno vicente Date: Thu, 22 Aug 2024 13:32:18 +0100 Subject: [PATCH] push to banana --- src/main.cpp | 30 +++++++- src/pilot.cpp | 29 ++++++-- src/pilot.h | 7 ++ src/references/bson_var.h | 6 +- src/store.cpp | 142 ++++++++++++++++++++++++++++++------ src/store.h | 28 +++++-- src/voidsterdebugwindow.cpp | 22 +++++- src/voidsterdebugwindow.h | 5 ++ 8 files changed, 230 insertions(+), 39 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b0b5963..a15e2c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,11 @@ #include #include #include +//static store* store_ref; +//void check_menu(int i); +//VoidsterdebugWindow debugWindow; +//PilotWindow pl; int main(int argc, char *argv[]){ @@ -37,12 +41,16 @@ int main(int argc, char *argv[]){ break; } } - + + #ifdef __LART_T24__ #ifdef __LART_DEBUG__ - // VoidsterdebugWindow debugWindow; + // debugWindow.show(); + /* QObject::connect(store_ref,&store::menuChanged,[](int value){ + check_menu(value); + });*/ PilotWindow pl; pl.show(); @@ -66,3 +74,21 @@ int main(int argc, char *argv[]){ return a.exec(); } + +/*void check_menu(int i) +{ + + switch (i) { + case 0: + pl.show(); + debugWindow.hide(); + break; + case 1: + pl.hide(); + debugWindow.show(); + break; + default: + break; + } +} +*/ diff --git a/src/pilot.cpp b/src/pilot.cpp index c368d21..e50c44e 100644 --- a/src/pilot.cpp +++ b/src/pilot.cpp @@ -34,8 +34,9 @@ PilotWindow::PilotWindow(QWidget *parent, QString serialDev) setWindowTitle("Pilotamos"); - store_ref = new store(serialDev); + + store_ref = new store(serialDev); //store_ref->setParent(this); //store_ref->requestSlotAttachment(); @@ -66,11 +67,11 @@ PilotWindow::PilotWindow(QWidget *parent, QString serialDev) //connect(store_ref, &store::rpmChanged,SPEED_DISPLAY, (void (QLCDNumber::*)(short, short))&QLCDNumber::show; - connect(store_ref, &store::vehicleSpeedChanged, INVERTER_TEMP_DISPLAY, QOverload::of(&QLCDNumber::display)); + connect(store_ref, &store::inverterTemperatureChanged, INVERTER_TEMP_DISPLAY, QOverload::of(&QLCDNumber::display)); INVERTER_TEMP_DISPLAY->show(); - connect(store_ref, &store::vehicleSpeedChanged, MOTOR_TEMP_DISPLAY, QOverload::of(&QLCDNumber::display)); + connect(store_ref, &store::motorTemperatureChanged, MOTOR_TEMP_DISPLAY, QOverload::of(&QLCDNumber::display)); MOTOR_TEMP_DISPLAY->show(); connect(store_ref, &store::vehicleSpeedChanged, ACUMULATOR_TEMP_DISPLAY, QOverload::of(&QLCDNumber::display)); @@ -88,13 +89,14 @@ PilotWindow::PilotWindow(QWidget *parent, QString serialDev) LV_SOC_BAR->setValue(soc); }); - connect(store_ref,&store::socChanged,[POWER_SOC_BAR](int soc){ - POWER_SOC_BAR->setValue(soc); + connect(store_ref,&store::power_limitChanged,[POWER_SOC_BAR](int powerlimit){ + POWER_SOC_BAR->setValue(powerlimit); }); connect(store_ref,&store::socChanged,[CONSUMED_POWER_BAR](int soc){ CONSUMED_POWER_BAR->setValue(soc); }); +// QObject::connect(store_ref,&store::menuChanged,this,&PilotWindow::handleValueChanged); } @@ -114,7 +116,24 @@ store* PilotWindow::getStore(){ **/ PilotWindow::~PilotWindow(){ store_ref->~store(); + //delete store_ref; delete ui; } +/*void PilotWindow::handleValueChanged(int newValue) { + // Close the current window + + if(store_ref->getMenu() == 1) + { + delete store_ref; + VoidsterdebugWindow *debugWindow = new VoidsterdebugWindow(); + this->close(); + debugWindow->show(); + + } + +} + + +*/ diff --git a/src/pilot.h b/src/pilot.h index 1d3c4ca..39104a6 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -24,7 +24,14 @@ class PilotWindow : public QMainWindow private: Ui::pilot *ui; + +/*public slots: + void handleValueChanged(int newValue); +*/ }; + + + #endif // PILOT_H diff --git a/src/references/bson_var.h b/src/references/bson_var.h index 3984e5b..7d55b1c 100644 --- a/src/references/bson_var.h +++ b/src/references/bson_var.h @@ -12,8 +12,9 @@ **/ #define BSON_RPM "rpm" #define BSON_VEHICLESPEED "vel" -#define BSON_ENGINETEMPERATURE "eng_t" +#define BSON_MOTORTEMPERATURE "eng_t" #define BSON_BATTERYVOLTAGE "bat_v" + #ifdef __LART_T14__ #define BSON_GEARSHIFT "gear" #define BSON_OILPRESSURE "oil_p" @@ -31,7 +32,8 @@ #define BSON_LAPCOUNT "lap_c" #define BSON_LAPTIME "lap_t" #define BSON_HV "hv" - #define BSON_PAGE "page" + #define BSON_MENU "menu" + #define BSON_POWER_LIMIT "power_available" #endif diff --git a/src/store.cpp b/src/store.cpp index f4c3972..662253a 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -11,8 +11,11 @@ #include "mainwindow.h" #include "references/bson_var.h" #include "flabel.h" - - +#include "pilot.h" +#include "voidsterdebugwindow.h" +#include "qdebug.h" +//VoidsterdebugWindow debugWindow; +//PilotWindow pl; using json = nlohmann::json; /** * @brief Arguably the boilerplate code, necessary to run an Asynchronous Serial Uart communication. Also responsible for handling @b slots and other callback logic @@ -20,8 +23,8 @@ using json = nlohmann::json; * wow the above was suggested by copilot. how many times did people have issues with this? **/ int store::setupSerial() { - - QSerialPort* serial= new QSerialPort(); + + QSerialPort* serial= new QSerialPort(); serial->setPortName(this->dev); serial->setBaudRate(this->baud); serial->setDataBits(QSerialPort::Data8); @@ -155,7 +158,12 @@ store::store( QString dev, QSerialPort::BaudRate baud, QObject *parent): QObject }else{ this->dev = dev; } - setupSerial(); + // if(store::initialized){ + setupSerial(); + // } + // store::initialized = true; + + //int8_t retries = LOG_MAX_RETRIES; //TODO wtf? retry system startGeneralErrorLog(); @@ -284,9 +292,9 @@ void store::parseBson(std::vector v){ this->setRpm(j[BSON_RPM]); } - if(j.contains(BSON_ENGINETEMPERATURE)){ + /*if(j.contains(BSON_ENGINETEMPERATURE)){ this->setEngineTemperature(j[BSON_ENGINETEMPERATURE]); - } + }*/ if(j.contains(BSON_BATTERYVOLTAGE)){ EncodingUnion t; @@ -328,11 +336,50 @@ void store::parseBson(std::vector v){ } #endif #ifdef __LART_T24__ - if(j.contains(BSON_SOC)){ - EncodingUnion t; - t.encoded=j[BSON_SOC]; - this->setSoc(t.decoded); - } + if(j.contains(BSON_MENU)) + { + int t; + t =j[BSON_MENU]; + this->setMenu(t); + if(m_menu != t) + { + //store::closeSerial(); + //VoidsterdebugWindow debugWindow; + //PilotWindow pl; + // VoidsterdebugWindow debugWindow = new VoidsterdebugWindow(); + //PilotWindow pl = new PilotWindow(); + switch(t) + { + case 0: + //pl.show(); + + break; + case 1: + // debugWindow.show(); + //QMessageBox::information(nullptr, "Menu 0", "Menu 0 has been selected."); + break; + default: + break; + } + } + } + if(j.contains(BSON_SOC)){ + EncodingUnion t; + t.encoded=j[BSON_SOC]; + this->setSoc(t.decoded); + } + if(j.contains(BSON_MOTORTEMPERATURE)){ + // EncodingUnion t; + // t.encoded=j[BSON_MOTORTEMPERATURE]; + // this->setmotorTemperature(t.decoded); + this->setmotorTemperature(j[BSON_MOTORTEMPERATURE]); + } + if(j.contains(BSON_POWER_LIMIT)){ + EncodingUnion t; + t.encoded=j[BSON_POWER_LIMIT]; + this->setPowerLimit(t.decoded); + qDebug()<< t.decoded; + } if(j.contains(BSON_BATTERYTEMPERATURE)){ EncodingUnion t; @@ -340,7 +387,8 @@ void store::parseBson(std::vector v){ this->setBatteryTemperature(t.decoded); } if(j.contains(BSON_INVERTERTEMPERATURE)){ - this->setInverterTemperature(j[BSON_INVERTERTEMPERATURE]); + int temp = j[BSON_INVERTERTEMPERATURE]; + this->setInverterTemperature(temp); } if(j.contains(BSON_POWER)){ short temp = j[BSON_POWER]; @@ -399,6 +447,7 @@ int store::closeSerial(){ } return 0; } + /** * @brief getter for the rpm variable * @return The rpm variable @@ -406,6 +455,17 @@ int store::closeSerial(){ int store::getRpm() const{ return this->m_rotationsPerMinute; } + + +void store::updateValue(int newValue) { + if (m_menu != newValue) { + m_menu = newValue; + emit valueChanged(m_menu); // Emitir o sinal de mudança + } +} + + + /** * @brief setter for the rpm variable * @param rpm The new value for the rpm variable @@ -641,8 +701,19 @@ void store::setTcLaunch(int tcLaunch){ * @return The state of charge variable **/ float store::getSoc() const{ - return this->m_stateOfCharge; + return this->m_stateOfCharge; } + + +/** +* @brief getter for the state of charge variable +* @return The state of charge variable +**/ +float store::getPowerLimit() const{ + return this->m_power_limit; +} + + /** * @brief getter for the battery temperature variable * @return The battery temperature variable @@ -655,14 +726,18 @@ float store::getBatteryTemperature() const{ * @return The inverter temperature variable **/ int store::getInverterTemperature() const{ - return this->m_inverterTemperature; + return this->m_inverterTemperature; +} + +int store::getmotorTemperature() const{ + return this->m_motorTemperature; } /** * @brief getter for the power variable * @return The power variable **/ short store::getPower() const{ - return this->m_power; + return this->m_power_limit; } /** * @brief getter for the lap time @b Double-Word Integer variable, @@ -698,10 +773,25 @@ short store::getHV() const{ * @param soc The new value for the state of charge variable **/ void store::setSoc(float soc){ - float oldSoc = this->m_stateOfCharge; - this->m_stateOfCharge=soc; - emit socChanged(this->m_stateOfCharge, oldSoc); + float oldSoc = this->m_stateOfCharge; + this->m_stateOfCharge=soc; + emit socChanged(this->m_stateOfCharge, oldSoc); +} + + + + +/** +* @brief setter for the power limit +* @param power limit The new value for the state of charge variable +**/ +void store::setPowerLimit(float powerl){ + float oldlimit = this->m_power_limit; + this->m_power_limit=powerl; + emit power_limitChanged(this->m_power_limit, oldlimit); } + + /** * @brief setter for the battery temperature variable * @param batteryTemperature The new value for the battery temperature variable @@ -716,9 +806,17 @@ void store::setBatteryTemperature(float batteryTemperature){ * @param inverterTemperature The new value for the inverter temperature variable **/ void store::setInverterTemperature(int inverterTemperature){ - int oldInverterTemperature = this->m_inverterTemperature; - this->m_inverterTemperature=inverterTemperature; - emit inverterTemperatureChanged(this->m_inverterTemperature, oldInverterTemperature); + int oldInverterTemperature = this->m_inverterTemperature; + this->m_inverterTemperature=inverterTemperature; + emit inverterTemperatureChanged(this->m_inverterTemperature, oldInverterTemperature); +} + + +void store::setmotorTemperature(int motorTemperature){ + int oldmotorTemperature = this->m_motorTemperature; + this->m_motorTemperature=motorTemperature; + emit motorTemperatureChanged(this->m_motorTemperature, oldmotorTemperature); + qDebug()< #include #include "references/bson_var.h" +#include "QtWidgets" +#include "QMessageBox" /** * @brief Go big or go home, :) **/ @@ -47,6 +49,7 @@ #define DEFAULT_DEVICE "/dev/ttyS3" #else #define DEFAULT_DEVICE "/dev/ttyUSB0" + //#define DEFAULT_DEVICE "/dev/ttyACM0" #endif #endif #else @@ -120,6 +123,7 @@ class store: public QObject{ void setEngineTemperature(int engineTemperature); void setBatteryVoltage(float batteryVoltage); void setVehicleSpeed(int vehicleVelocity); + void updateValue(int newValue); #ifdef __LART_T14__ int getGearShift() const; float getOilPressure() const; @@ -139,8 +143,10 @@ class store: public QObject{ #endif #ifdef __LART_T24__ float getSoc() const; + float getPowerLimit() const; float getBatteryTemperature() const; - int getInverterTemperature() const; + int getInverterTemperature() const; + int getmotorTemperature() const; short getPower() const; int getLapTime() const; short getLapCount() const; @@ -148,18 +154,21 @@ class store: public QObject{ //int getTyreTemperature() const; - void setSoc(float soc); + void setSoc(float soc); + void setPowerLimit(float powerl); void setBatteryTemperature(float batteryTemperature); - void setInverterTemperature(int inverterTemperature); + void setInverterTemperature(int inverterTemperature); + void setmotorTemperature(int inverterTemperature); void setPower(short power); void setLapTime(int lapTime); void setLapCount(short lapCount); - void setHV(short hv); + void setHV(short hv); //void setTyreTemperature(int tyreTemperature); #endif void setBaudRate(QSerialPort::BaudRate baud); + static bool initialized; protected: int startGeneralErrorLog(uint depth=0); void stopGeneralErrorLog(); @@ -169,6 +178,7 @@ class store: public QObject{ int closeSerial(); signals: + void valueChanged(int newValue); void rpmChanged(int newRpm, int oldRpm); void menuChanged(int newMenu, int oldMenu); void engineTemperatureChanged(int newEngineTemperature, int oldEngineTemperature); @@ -185,8 +195,10 @@ class store: public QObject{ #endif #ifdef __LART_T24__ void socChanged(float newSoc, float oldSoc); + void power_limitChanged(float newlimit, float oldlimit); void batteryTemperatureChanged(float newBatteryTemperature, float oldBatteryTemperature); - void inverterTemperatureChanged(int newInverterTemperature, int oldInverterTemperature); + void inverterTemperatureChanged(int newInverterTemperature, int oldInverterTemperature); + void motorTemperatureChanged(int newmotorTemperature, int oldmotorTemperature); void powerChanged(short newPower, short oldPower); void lapTimeChanged(QTime newLapTime, QTime oldLapTime); void diffLapTimeChanged(QTime newDiffLapTime, QTime oldDiffLapTime); @@ -194,7 +206,7 @@ class store: public QObject{ void hvChanged(short newHV, short oldHV ); //void tyreTemperatureChanged(int newTyreTemperature, int oldTyreTemperature); - #endif + #endif private: QSerialPort::BaudRate baud; @@ -215,8 +227,10 @@ class store: public QObject{ #endif #ifdef __LART_T24__ float m_stateOfCharge=0; + float m_power_limit = 0; float m_batteryTemperature=0; - int m_inverterTemperature=0; + int m_inverterTemperature=0; + int m_motorTemperature=0; short m_power=0; int m_lapTime=0; short m_lapCount=0; diff --git a/src/voidsterdebugwindow.cpp b/src/voidsterdebugwindow.cpp index 8abae1d..50f1f6a 100644 --- a/src/voidsterdebugwindow.cpp +++ b/src/voidsterdebugwindow.cpp @@ -15,6 +15,7 @@ #include #include #include "flabel.h" +#include "pilot.h" static store* store_ref; /** @@ -66,6 +67,7 @@ VoidsterdebugWindow::VoidsterdebugWindow(QWidget *parent, QString serialDev) connect(store_ref, &store::socChanged, SOC_Label, (void (FLabel::*)(float, float))&FLabel::setVisual); //connect(store_ref, &store::batteryTemperatureChanged, ) connect(store_ref, &store::hvChanged,InverterVoltage_Label, (void (FLabel::*)(short, short))&FLabel::setVisual ); + //QObject::connect(store_ref,&store::menuChanged,this,&VoidsterdebugWindow::handleValueChanged); //connect(store_ref, &store::rpmChanged,VcuState_label,(void(FLabel::*)(short,short))&FLabel::setVisual); /*TotalPowerDraw_Label->setText("Isto é um teste 1"); @@ -109,6 +111,24 @@ store* VoidsterdebugWindow::getStore(){ * @b Deletes the store object. which can cause some odd behaviour to happen **/ VoidsterdebugWindow::~VoidsterdebugWindow(){ - store_ref->~store(); + //store_ref->~store(); + delete store_ref; delete ui; } + +/* +void VoidsterdebugWindow::handleValueChanged(int newValue) { + // Close the current window + if(store_ref->getMenu() == 0) + { + + delete store_ref; + PilotWindow *pl = new PilotWindow(); + this->close(); + pl->show(); + + } + + } + +*/ diff --git a/src/voidsterdebugwindow.h b/src/voidsterdebugwindow.h index 616da18..32665be 100644 --- a/src/voidsterdebugwindow.h +++ b/src/voidsterdebugwindow.h @@ -20,5 +20,10 @@ class VoidsterdebugWindow : public QMainWindow private: Ui::VoidsterdebugWindow *ui; + +/* +public slots: + void handleValueChanged(int newValue); +*/ }; #endif // VOIDSTERDEBUGWINDOW_H