Added json broadcasting
This commit is contained in:
parent
df27b622a0
commit
3cbe947408
37 changed files with 514 additions and 487 deletions
|
|
@ -95,38 +95,16 @@ bool Microcontroller::connected()
|
|||
else return false;
|
||||
}
|
||||
|
||||
void Microcontroller::run()
|
||||
{
|
||||
abort();
|
||||
|
||||
loop.reset(new QEventLoop);
|
||||
QTimer timer;
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||
timer.setInterval(500);
|
||||
timer.start();
|
||||
|
||||
loop->exec();
|
||||
}
|
||||
|
||||
void Microcontroller::requestState()
|
||||
{
|
||||
write("state\n");
|
||||
}
|
||||
|
||||
void Microcontroller::abort()
|
||||
{
|
||||
if (!loop.isNull())
|
||||
{
|
||||
loop->quit();
|
||||
}
|
||||
}
|
||||
|
||||
//housekeeping
|
||||
|
||||
Microcontroller::Microcontroller(QIODevice* port): _port(port)
|
||||
Microcontroller::Microcontroller(QIODevice* port)
|
||||
{
|
||||
_port->readAll();
|
||||
_port->write("\n");
|
||||
setIODevice(port);
|
||||
}
|
||||
|
||||
Microcontroller::Microcontroller()
|
||||
|
|
@ -135,14 +113,12 @@ Microcontroller::Microcontroller()
|
|||
|
||||
Microcontroller::~Microcontroller()
|
||||
{
|
||||
if(_port != nullptr) delete _port;
|
||||
}
|
||||
|
||||
void Microcontroller::setIODevice(QIODevice *port)
|
||||
{
|
||||
_port = port;
|
||||
_port->readAll();
|
||||
_port->write("\n");
|
||||
QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead);
|
||||
}
|
||||
|
||||
std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
|
||||
|
|
@ -193,7 +169,6 @@ void Microcontroller::processSensorState(const QString& buffer)
|
|||
|
||||
void Microcontroller::processMicroReturn()
|
||||
{
|
||||
qDebug()<<_buffer;
|
||||
if(listMode) processList(_buffer);
|
||||
else
|
||||
{
|
||||
|
|
@ -208,21 +183,18 @@ void Microcontroller::processMicroReturn()
|
|||
|
||||
}
|
||||
|
||||
void Microcontroller::doTick()
|
||||
void Microcontroller::isReadyRead()
|
||||
{
|
||||
if(_port != nullptr)
|
||||
char charBuf;
|
||||
while(_port->getChar(&charBuf))
|
||||
{
|
||||
char charBuf;
|
||||
while(_port->getChar(&charBuf))
|
||||
_buffer.push_back(charBuf);
|
||||
if( _buffer.endsWith('\n') )
|
||||
{
|
||||
_buffer.push_back(charBuf);
|
||||
if( _buffer.endsWith('\n') )
|
||||
{
|
||||
_buffer.remove('\n');
|
||||
processMicroReturn();
|
||||
textRecived(_buffer);
|
||||
_buffer.clear();
|
||||
}
|
||||
_buffer.remove('\n');
|
||||
processMicroReturn();
|
||||
textRecived(_buffer);
|
||||
_buffer.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue