Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
frank1789 committed Feb 9, 2020
2 parents 75925ec + 75a2df1 commit 88fe409
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 418 deletions.
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

rm -rf build
mkdir build && cd build
lcov --directory . --zerocounters
cmake -D CMAKE_BUILD_TYPE=Debug ..
make
make -j3
EXECUTABLE=$(find $PWD -name "FlirLepton")
${EXECUTABLE}
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target_link_libraries(${LEPTONCAMERA}
${raspicam_LIBS}
)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_options(${LEPTONCAMERA} PUBLIC -fpic -O0)
target_compile_options(${LEPTONCAMERA} PUBLIC -fpic -O0 -g)
add_definitions(-DLOGGER)
if(COVERAGE)
target_link_libraries(coverage_config)
Expand Down
2 changes: 1 addition & 1 deletion src/log/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const char *levels_color[] = {YELLOW, CYAN, GREEN, LIGHT_RED, RED, MAGENTA};

void logger(level_t level, const char *file, int line, const char *fmt, ...) {
va_list args;
fprintf(stderr, "[%s %s %s %s:%d] ", levels_color[level], levels_name[level],
fprintf(stderr, "[%s %s %s %s:%d] \n\t", levels_color[level], levels_name[level],
RESET, file, line);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
Expand Down
5 changes: 0 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "leptonthread.hpp"
#include "mainwindow.hpp"
#include "socket/tcpserver.hpp"

int main(int argc, char **argv) {
QApplication a(argc, argv);
Expand Down Expand Up @@ -36,10 +35,6 @@ int main(int argc, char **argv) {
// open window
w.show();

// init server
QPointer<TcpServer> server = new TcpServer();
server->show();

// start thread
lepton->start();
return a.exec();
Expand Down
17 changes: 12 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "mainwindow.hpp"
#include "ui_mainwindow.h"

#include <QColor>
#include <QComboBox>
Expand All @@ -14,6 +13,7 @@

#include "log/logger.h"
#include "palettes.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
Expand Down Expand Up @@ -42,10 +42,10 @@ MainWindow::MainWindow(QWidget *parent)
}
}

client = new TcpClient();
server = new TCPServer();
m_group_all->addLayout(create_label_preview(), 0, 0);
m_group_all->addLayout(create_bar_control(), 0, 1);
m_group_all->addWidget(client, 0, 2);
// m_group_all->addWidget(client, 0, 2);
widget->setLayout(m_group_all);

// connect signal from this to respective classes label
Expand Down Expand Up @@ -75,13 +75,20 @@ MainWindow::MainWindow(QWidget *parent)
// connect Camera to TcpClient
connect(this, &MainWindow::update_rgb_image, [=](QImage image) {
QImage image_resized = image.scaled(512, 512, Qt::KeepAspectRatio);
client->sendImage(image_resized);
QPixmap img = QPixmap::fromImage(image_resized);
QByteArray bImage;
QBuffer bBuffer(&bImage);
// Putting every image in the buffer
bBuffer.open(QIODevice::ReadWrite);
img.save(&bBuffer, "JPG");
// Sending to TCPServer function to display the image
server->is_newImg(bImage);
});
}

MainWindow::~MainWindow() {
delete ui;
delete client;
delete server;
}

void MainWindow::set_thermal_image(QImage img) {
Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QPainter>

#include "mylabel.hpp"
#include "socket/tcpclient.hpp"
#include "socket/tcpserver.h"

QT_BEGIN_NAMESPACE
namespace Ui {
Expand Down Expand Up @@ -154,6 +154,6 @@ class MainWindow : public QMainWindow {
void addOp(QPainter::CompositionMode mode, const QString &name);

// socket client layout
TcpClient *client{nullptr};
TCPServer *server{nullptr};
};
#endif // MAINWINDOW_HPP
4 changes: 2 additions & 2 deletions src/socket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
add_library(${NAME_PROJECT} ${SOURCES})
target_link_libraries(${NAME_PROJECT} Qt5::Widgets Qt5::Network LOG)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_options(${NAME_PROJECT} PUBLIC -fpic -O0)
add_definitions(-DLOGGER_SERVER)
target_compile_options(${NAME_PROJECT} PUBLIC -fpic -O0 -g)
add_definitions(-D LOGGER_CLIENT)
if(COVERAGE)
target_link_libraries(coverage_config)
endif()
Expand Down
13 changes: 7 additions & 6 deletions src/socket/commonconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void send_message_text(QTcpSocket *socket, const QString &message) {
}
// prepare datastream
QByteArray ba_message;
QDataStream out(&ba_message, QIODevice::ReadWrite);
QDataStream out(&ba_message, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
// serialize information
out << QString(GROUP_SEPARATOR_ASCII_CODE)
Expand All @@ -64,17 +64,18 @@ void send_message_image(QTcpSocket *socket, const QImage &image) {
#endif
return;
}
// prepare datastream

// prepare datastream and serialize information
QByteArray ba_message;
QDataStream out(&ba_message, QIODevice::ReadWrite);
QDataStream out(&ba_message, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
// serialize information
out << QString(RECORD_SEPARATOR_ASCII_CODE)
<< static_cast<quint32>(image.sizeInBytes()) << image;
socket->write(ba_message);
#if LOGGER_CLIENT || LOGGER_SERVER
LOG(DEBUG, "sending image:")
LOG(TRACE, "serialized image")
qDebug() << "\theader: " << QString(RECORD_SEPARATOR_ASCII_CODE)
<< "\tsize:" << static_cast<quint32>(image.sizeInBytes()) << "\n";
qDebug() << ba_message;
#endif
socket->write(ba_message);
}
21 changes: 12 additions & 9 deletions src/socket/commonconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ constexpr int RECORD_SEPARATOR_ASCII_CODE{30};
constexpr int GROUP_SEPARATOR_ASCII_CODE{29};

/**
* \file commonconnection.hpp
* @enum MessageType
*
* @brief The MessageType is a strongly typed enum class representing the type
* of message.
* @enum mapper::MessageType
*
*/
enum class MessageType : quint8 {
Text, /**< is coded as quint8 of value 0 */
Expand All @@ -27,9 +30,9 @@ enum class MessageType : quint8 {
* @brief identifies_message_type allows to identify the message from the
* header.
*
* The function allows to identify the message from the header. Once the
* QDatastream is obtained from the socket and the transition is started, the
* header and dimensions, which represent the input parameters, are extracted.
* Once the QDatastream is obtained from the socket and the transition is
* started, the header and dimensions, which represent the input parameters, are
* extracted.
* Then the checking of incoming messages by identifying the header:
* - message containing text if the header corresponds to the UTF-8 code
* '\u001D' or to the ASCII code 29.
Expand All @@ -38,7 +41,7 @@ enum class MessageType : quint8 {
*
* @param[in] header string containing the message header.
* @param[in] size message size expressed in bytes.
* @return a message type as indicated by ::::MessageType.
* @return a message type as indicated by ::MessageType.
*/
MessageType identifies_message_type(const QString &header, const qint32 &size);

Expand All @@ -50,8 +53,8 @@ MessageType identifies_message_type(const QString &header, const qint32 &size);
* stream are constructed. the message is composed of the header, then the size,
* the text of the message.
*
* @param socket[in] tcp-socket required to send the buffer.
* @param message[in] string containing the text message.
* @param[in] socket tcp-socket required to send the buffer.
* @param[in] message string containing the text message.
*/
void send_message_text(QTcpSocket *socket, const QString &message);

Expand All @@ -63,8 +66,8 @@ void send_message_text(QTcpSocket *socket, const QString &message);
* stream are constructed. the message is composed of the header, then the size,
* the image.
*
* @param socket[in] tcp-socket required to send the buffer.
* @param image[in] containing the picture.
* @param[in] socket tcp-socket required to send the buffer.
* @param[in] image containing the picture.
*/
void send_message_image(QTcpSocket *socket, const QImage &image);

Expand Down
47 changes: 10 additions & 37 deletions src/socket/tcpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <QString>
#include <QTextEdit>

#include "../log/logger.h"
#include "commonconnection.hpp"
#include "log/logger.h"

TcpClient::TcpClient(QWidget *parent)
: QWidget(parent), m_tcp_socket(new QTcpSocket(this)) {
Expand Down Expand Up @@ -60,8 +60,6 @@ TcpClient::TcpClient(QWidget *parent)
&TcpClient::enableConnectButton);
connect(m_port_linedit, &QLineEdit::textChanged, this,
&TcpClient::enableConnectButton);
// connect(m_tcp_socket, &QIODevice::readyRead, this,
// &TcpClient::readFortune);

// connect error
connect(m_tcp_socket,
Expand Down Expand Up @@ -94,18 +92,12 @@ TcpClient::TcpClient(QWidget *parent)
LOG(INFO, "Opening network session.")
networkSession->open();
}
#if LOGGER
QTimer *timer = new QTimer(this);
timer->setInterval(1000);
timer->start();
#if TEST_IMAGE
connect(timer, &QTimer::timeout, [=]() { this->sendImageMessage(); });
#else
connect(timer, &QTimer::timeout, [=]() { this->sendTestMessageStream(); });
#endif
#endif
}

//////////////////////////////////////////////////////////////////////////////
//// Slot function
//////////////////////////////////////////////////////////////////////////////

void TcpClient::sendImage(QImage image) {
if (m_tcp_socket->state() != QAbstractSocket::ConnectedState) {
#if LOGGER_CLIENT
Expand All @@ -116,10 +108,6 @@ void TcpClient::sendImage(QImage image) {
send_message_image(m_tcp_socket, image);
}

//////////////////////////////////////////////////////////////////////////////
//// Slot function
//////////////////////////////////////////////////////////////////////////////

void TcpClient::connectedToServer() {
#if LOGGER_CLIENT
LOG(INFO, "update connection status: Connect to server.")
Expand Down Expand Up @@ -188,24 +176,6 @@ void TcpClient::enableConnectButton() {
!m_port_linedit->text().isEmpty());
}

void TcpClient::readFortune() {
m_data.startTransaction();

QString nextFortune;
m_data >> nextFortune;

if (!m_data.commitTransaction()) return;

if (nextFortune == currentFortune) {
QTimer::singleShot(100, this, &TcpClient::connectedToServer);
return;
}

currentFortune = nextFortune;
m_log_text->append(currentFortune);
connectButton->setEnabled(true);
}

void TcpClient::readyRead() {
if (m_tcp_socket->state() != QAbstractSocket::ConnectedState) {
#if LOGGER_CLIENT
Expand All @@ -231,13 +201,16 @@ void TcpClient::readyRead() {
if (header == QString(GROUP_SEPARATOR_ASCII_CODE)) {
QString message;
m_data >> message;
if (!message.isEmpty()) {
m_log_text->append(message);
}
#if LOGGER_CLIENT
LOG(DEBUG, "check message is not empty: %s",
(!message.isEmpty()) ? "true" : "false")
LOG(DEBUG, "server read message in redyRead()\n\tmessage received:")
LOG(DEBUG, "server read message in readyRead()\n\tmessage received:")
qDebug() << "\t" << message << "\n";
#endif
if (!message.isEmpty()) m_log_text->append(message);

} else if (header == QString(RECORD_SEPARATOR_ASCII_CODE)) {
#if LOGGER_CLIENT
LOG(DEBUG, "image incoming")
Expand Down
6 changes: 0 additions & 6 deletions src/socket/tcpclient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ class TcpClient : public QWidget {
*/
void enableConnectButton();

/**
* @brief
*
*/
void readFortune();

/**
* @brief Read from socket.
*
Expand Down
Loading

0 comments on commit 88fe409

Please sign in to comment.