diff options
Diffstat (limited to 'confui/serial.cpp')
-rw-r--r-- | confui/serial.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/confui/serial.cpp b/confui/serial.cpp index 96c5c0f..93adf28 100644 --- a/confui/serial.cpp +++ b/confui/serial.cpp @@ -1,5 +1,7 @@ #include "serial.h" +#include "../shared/serial_parse.h" +#include <iostream> #include <QDebug> #include <QSerialPort> #include <QSerialPortInfo> @@ -7,7 +9,6 @@ CDSerialConnector::CDSerialConnector() { this->_serial = new QSerialPort; - _serial->setPortName("/Users/jregnier/ttypx"); if (!_serial->setBaudRate(QSerialPort::Baud9600)) qDebug() << _serial->errorString(); if (!_serial->setDataBits(QSerialPort::Data8)) // data is 8 bits qDebug() << _serial->errorString(); @@ -28,6 +29,12 @@ void CDSerialConnector::action() { _msg = _serial->readAll(); qDebug() << _msg; } + + // string std_string = _msg.toStdString(); + // size_t size = std_string.size(); + // const char* data = std_string.c_str(); + // for (size_t i = 0; i < size; i++) + // cd_serial_parse(data[i]); } void CDSerialConnector::write(QByteArray msg) { @@ -35,7 +42,8 @@ void CDSerialConnector::write(QByteArray msg) { qDebug() << _serial->errorString(); } -void CDSerialConnector::connect() { +void CDSerialConnector::connect(string port) { + _serial->setPortName(QString::fromStdString(port)); // QIODevice::ReadOnly if (!_serial->open(QIODevice::ReadWrite)) qDebug() << _serial->errorString(); @@ -47,7 +55,8 @@ void CDSerialConnector::connect() { } void CDSerialConnector::disconnect() { - // WIP? + if (_serial->isOpen() == false) return; + _serial->disconnect(); } QByteArray CDSerialConnector::get_data() { return _msg; } @@ -58,3 +67,19 @@ vector<string> CDSerialConnector::get_ports() { ports.push_back(port.portName().toStdString()); return ports; } + +string CDSerialConnector::get_port() { + return _serial->portName().toStdString(); +} + +extern "C" { + +void cd_cmd_response(cd_s_bin* data) { + (void) data; + + std::cout << "received!" << std::endl; + + return; +} + +} |