Major wip refactor

Allow running without gui
Remove serialPortMultiplexer broadcast use
Add TcpServer and TcpClient
Introduce the concept of an item source
This commit is contained in:
Carl Philipp Klemm 2026-03-01 14:39:27 +01:00
parent cbeb8d49a7
commit 6d742e60db
38 changed files with 928 additions and 825 deletions

View file

@ -3,8 +3,6 @@
#include <chrono>
#include <thread>
static constexpr bool debug = true;
void Microcontroller::relayToggle(int state, int relay)
{
char buffer[8];
@ -40,7 +38,6 @@ void Microcontroller::changeRgbColor(const QColor color)
char buffer[64];
int length = sprintf(buffer, "rgb set %03d %03d %03d\n", color.red(), color.green(), color.blue());
write(buffer, length);
std::cout<<buffer;
}
void Microcontroller::setAuxPwm(int duty)
@ -52,9 +49,6 @@ void Microcontroller::setAuxPwm(int duty)
void Microcontroller::write(const QByteArray& buffer)
{
#ifndef Q_OS_ANDROID
if constexpr(debug) std::cerr<<buffer.data();
#endif
if(_port != nullptr)
{
_port->write(buffer);
@ -65,9 +59,6 @@ void Microcontroller::write(const QByteArray& buffer)
void Microcontroller::write(char* buffer, const size_t length)
{
#ifndef Q_OS_ANDROID
if constexpr(debug) std::cerr<<buffer;
#endif
if(_port != nullptr)
{
_port->write(buffer, length);
@ -95,7 +86,7 @@ bool Microcontroller::connected()
else return false;
}
void Microcontroller::requestState()
void Microcontroller::refresh()
{
write("state\n");
}
@ -147,12 +138,13 @@ void Microcontroller::processList(const QString& buffer)
if(bufferList.size() >= 8 && buffer.startsWith("ITEM NUMBER:"))
{
relayList.push_back(processRelayLine(buffer));
qDebug()<<"Micro item recived:"<<relayList.back()->getName();
}
else if(buffer.contains("EOL"))
{
listMode = false;
qDebug()<<"got relay list " << relayList.size();
gotRelayList(relayList);
gotItems(relayList);
relayList.clear();
}
else listMode = false;
@ -160,7 +152,7 @@ void Microcontroller::processList(const QString& buffer)
void Microcontroller::processRelayState(const QString& buffer)
{
itemChanged(static_cast<ItemData>(*processRelayLine(buffer)));
updateItems({static_cast<ItemData>(*processRelayLine(buffer))});
}
void Microcontroller::processSensorState(const QString& buffer)
@ -172,7 +164,11 @@ void Microcontroller::processSensorState(const QString& buffer)
void Microcontroller::processMicroReturn()
{
if(listMode) processList(_buffer);
qDebug()<<_buffer;
if(listMode)
{
processList(_buffer);
}
else
{
if(_buffer.startsWith("Items:"))
@ -192,7 +188,9 @@ void Microcontroller::isReadyRead()
while(_port->getChar(&charBuf))
{
_buffer.push_back(charBuf);
if( _buffer.endsWith('\n') )
qDebug()<<_buffer;
if(_buffer.endsWith('\n') )
{
_buffer.remove('\n');
processMicroReturn();