<commit_before>/*=====================================================================
======================================================================*/
/**
 * @file
 *   @brief Cross-platform support for serial ports
 *
 *   @author <NAME> <<EMAIL>>
 *
 */

#include "QsLog.h"
#include "SerialLink.h"
#include "LinkManager.h"
#include "QGC.h"
#include "UASInterface.h"

#include <QTimer>

#include <QSettings>
#include <QMutexLocker>
//#include <QtSerialPort/QSerialPort>
//#include <QtSerialPort/QSerialPortInfo>

#include <qserialport.h>
#include <qserialportinfo.h>
#include <MG.h>
//These three defines specify which threading method is used
//ONLY have one of these active at a time.

//SERIALLINK_THREAD is the origonal method, where the entire creation, use, and destruction of the
//QSerialPort is done inside a run() loop. This is the method which has caused driver and other odd issues.
//#define SERIALLINK_THREAD

//SERIALLINK_NOTHREAD does not use threads at all, but instead uses the current (UI) event loop to handle
//all serial port access, via the readyRead signal.
//#define SERIALLINK_NOTHREAD

//SERIALLINK_HYBRIDTHREAD uses a combonation of the two styles. This uses a run() loop for the creation, use, and
//destruction like the first method, but it calls exec() inside run(), and allows the threads event loop to handle
//all serial port access. This is the most likely candidate for being implemented permanently.
#define SERIALLINK_HYBRIDTHREAD

SerialLink::SerialLink() :
    m_bytesRead(0),
    m_port(NULL),
    m_baud(QSerialPort::Baud115200),
    m_dataBits(QSerialPort::Data8),
    m_flowControl(QSerialPort::NoFlowControl),
    m_stopBits(QSerialPort::OneStop),
    m_parity(QSerialPort::NoParity),
    m_portName(""),
    m_stopp(false),
    m_reqReset(false),
    m_isConnected(false)
{
    QLOG_INFO() << "create SerialLink: Load Previous Settings ";
    qRegisterMetaType<QSerialPort::SerialPortError>("QSerialPort::SerialPortError");
    loadSettings();
    m_id = getNextLinkId();

    if (m_portName.length() == 0) {
        // Create a new serial link
        getCurrentPorts();
        if (!m_ports.isEmpty())
            m_portName = m_ports.first().trimmed();
        else
            m_portName = "No Devices";
    }

    QLOG_INFO() <<  m_portName << m_baud << m_flowControl
             << m_parity << m_dataBits << m_stopBits;

}<commit_msg>Fixed failure to set pointer to NUL causing crash on disconnect from the serial port when using a UDP connection.<commit_after>/*=====================================================================
======================================================================*/
/**
 * @file
 *   @brief Cross-platform support for serial ports
 *
 *   @author <NAME> <<EMAIL>>
 *
 */

#include "QsLog.h"
#include "SerialLink.h"
#include "LinkManager.h"
#include "QGC.h"
#include "UASInterface.h"

#include <QTimer>

#include <QSettings>
#include <QMutexLocker>
//#include <QtSerialPort/QSerialPort>
//#include <QtSerialPort/QSerialPortInfo>

#include <qserialport.h>
#include <qserialportinfo.h>
#include <MG.h>
//These three defines specify which threading method is used
//ONLY have one of these active at a time.

//SERIALLINK_THREAD is the origonal method, where the entire creation, use, and destruction of the
//QSerialPort is done inside a run() loop. This is the method which has caused driver and other odd issues.
//#define SERIALLINK_THREAD

//SERIALLINK_NOTHREAD does not use threads at all, but instead uses the current (UI) event loop to handle
//all serial port access, via the readyRead signal.
//#define SERIALLINK_NOTHREAD

//SERIALLINK_HYBRIDTHREAD uses a combonation of the two styles. This uses a run() loop for the creation, use, and
//destruction like the first method, but it calls exec() inside run(), and allows the threads event loop to handle
//all serial port access. This is the most likely candidate for being implemented permanently.
#define SERIALLINK_HYBRIDTHREAD

SerialLink::SerialLink() :
    m_bytesRead(0),
    m_port(NULL),
    m_baud(QSerialPort::Baud115200),
    m_dataBits(QSerialPort::Data8),
    m_flowControl(QSerialPort::NoFlowControl),
    m_stopBits(QSerialPort::OneStop),
    m_parity(QSerialPort::NoParity),
    m_portName(""),
    m_stopp(false),
    m_reqReset(false),
    m_isConnected(false),
    m_timeoutTimer(NULL)
{
    QLOG_INFO() << "create SerialLink: Load Previous Settings ";
    qRegisterMetaType<QSerialPort::SerialPortError>("QSerialPort::SerialPortError");
    loadSettings();
    m_id = getNextLinkId();

    if (m_portName.length() == 0) {
        // Create a new serial link
        getCurrentPorts();
        if (!m_ports.isEmpty())
            m_portName = m_ports.first().trimmed();
        else
            m_portName = "No Devices";
    }

    QLOG_INFO() <<  m_portName << m_baud << m_flowControl
             << m_parity << m_dataBits << m_stopBits;

}
{'fraction_non_alphanumeric': 0.16097560975609757, 'fraction_numerical': 0.003658536585365854, 'mean_word_length': 4.2239915074309975, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5288068', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1484, 'n_words': 452}