<commit_before>#include "TLogReplayLink.h"
#include <QFile>
#include <QDebug>
#include <QDateTime>
#include "UASManager.h"
#include "UAS.h"
#include "MainWindow.h"
#include "QGCMAVLinkUASFactory.h"
TLogReplayLink::TLogReplayLink(QObject *parent) :
    LinkInterface(),
    m_toBeDeleted(false),
    m_threadRun(false),
    m_speedVar(50),
    m_posVar(0),
    m_mavlinkDecoder(new MAVLinkDecoder()),
    m_mavlinkInspector(NULL)
{
}
int TLogReplayLink::getId() const
{
    return 1;
}
QString TLogReplayLink::getName() const
{
    return "AP2SimulationLink";
}
void TLogReplayLink::requestReset()
{

}
bool TLogReplayLink::isConnected() const
{
    return false;
}
qint64 TLogReplayLink::getConnectionSpeed() const
{
    return 115200;
}

bool TLogReplayLink::connect()
{
    start();
    return true;
}
bool TLogReplayLink::disconnect()
{
    return false;
}
qint64 TLogReplayLink::bytesAvailable()
{
    return 0;
}
void TLogReplayLink::writeBytes(const char *bytes, qint64 length)
{

}
void TLogReplayLink::readBytes()
{

}
void TLogReplayLink::setSpeed(int speed)
{
    m_variableAccessMutex.lock();
    m_speedVar = speed;
    m_variableAccessMutex.unlock();
}
void TLogReplayLink::setPosition(qint64 pos)
{
    m_variableAccessMutex.lock();
    m_posVar = pos;
    m_variableAccessMutex.unlock();
}

void TLogReplayLink::play()
{
    m_pause = false;
}

void TLogReplayLink::pause()
{
    m_pause = true;
}
bool TLogReplayLink::isPaused()
{
    return m_pause;
}
void TLogReplayLink::setMavlinkDecoder(MAVLinkDecoder *decoder)
{
    m_mavlinkDecoder = decoder;
}
void TLogReplayLink::setMavlinkInspector(QGCMAVLinkInspector *inspector)
{
    m_mavlinkInspector = inspector;
}

void TLogReplayLink::run()
{
    m_pause = false;
    m_threadRun = true;
    emit connected(this);
    emit connected(true);
    emit connected();
    QFile file(m_logFile);
    file.open(QIODevice::ReadOnly);
    int bytesize = 0;
    qint64 msecs = QDateTime::currentMSecsSinceEpoch();
    MainWindow::instance()->toolBar().disableConnectWidget(true);
    MainWindow::instance()->toolBar().overrideDisableConnectWidget(true);
    int privSpeedVar = 100;
    mavlink_message_t message;
    mavlink_status_t status;
    QByteArray timebuf;
    bool firsttime = true;
    int delay = 0;
    qint64 lastLogTime = 0;
    qint64 lastPcTime = 0;
    bool nexttime = false;
    qint64 privatepos = 0;
    while (!file.atEnd() && m_threadRun)
    {
        if (QDateTime::currentMSecsSinceEpoch() - msecs > 1000)
        {
            msecs = QDateTime::currentMSecsSinceEpoch();
            m_variableAccessMutex.lock();

            //m_speedVar is a value, between 25 and 175. These are speed percentages.
            privSpeedVar = m_speedVar; //50 - ((m_speedVar) / 4);
            if (privatepos != m_posVar)
            {
                privatepos = m_posVar;
                if (privatepos > 0 && privatepos < 100)
                {
                    file.seek((privatepos / 100.0) * file.size());
                }
            }
            m_variableAccessMutex.unlock();
        }
        emit logProgress(file.pos(),file.size());
        QByteArray bytes = file.read(128);
        bytesize+=128;

        for (int i=0;i<bytes.size();i++)
        {
            unsigned int decodeState = mavlink_parse_char(14, (uint8_t)(bytes[i]), &message, &status);
            if (decodeState != 1)
            {
                //Not a mavlink byte!
                if (nexttime)
                {
                    timebuf.append(bytes[i]);
                }
                if (timebuf.size() == 8)
                {
                    nexttime = false;

                    //Should be a timestamp for the next packet.
                    unsigned long logmsecs = static_cast<unsigned char>(timebuf.at(0)) << 56;
                    logmsecs += static_cast<unsigned char>(timebuf.at(1)) << 48;
                    logmsecs += static_cast<unsigned char>(timebuf.at(2)) << 40;
                    logmsecs += static_cast<unsigned char>(timebuf.at(3)) << 32;
                    logmsecs = static_cast<unsigned char>(timebuf.at(4)) << 24;
                    logmsecs += static_cast<unsigned char>(timebuf.at(5)) << 16;
                    logmsecs += static_cast<unsigned char>(timebuf.at(6)) << 8;
                    logmsecs += static_cast<unsigned char>(timebuf.at(7)) << 0;

                    timebuf.clear();
<commit_msg>Comms: Cannot shift a char by 56 bits; ulong not guaranteed to be 64 bits<commit_after>#include "TLogReplayLink.h"
#include <QFile>
#include <QDebug>
#include <QDateTime>
#include "UASManager.h"
#include "UAS.h"
#include "MainWindow.h"
#include "QGCMAVLinkUASFactory.h"
TLogReplayLink::TLogReplayLink(QObject *parent) :
    LinkInterface(),
    m_toBeDeleted(false),
    m_threadRun(false),
    m_speedVar(50),
    m_posVar(0),
    m_mavlinkDecoder(new MAVLinkDecoder()),
    m_mavlinkInspector(NULL)
{
}
int TLogReplayLink::getId() const
{
    return 1;
}
QString TLogReplayLink::getName() const
{
    return "AP2SimulationLink";
}
void TLogReplayLink::requestReset()
{

}
bool TLogReplayLink::isConnected() const
{
    return false;
}
qint64 TLogReplayLink::getConnectionSpeed() const
{
    return 115200;
}

bool TLogReplayLink::connect()
{
    start();
    return true;
}
bool TLogReplayLink::disconnect()
{
    return false;
}
qint64 TLogReplayLink::bytesAvailable()
{
    return 0;
}
void TLogReplayLink::writeBytes(const char *bytes, qint64 length)
{

}
void TLogReplayLink::readBytes()
{

}
void TLogReplayLink::setSpeed(int speed)
{
    m_variableAccessMutex.lock();
    m_speedVar = speed;
    m_variableAccessMutex.unlock();
}
void TLogReplayLink::setPosition(qint64 pos)
{
    m_variableAccessMutex.lock();
    m_posVar = pos;
    m_variableAccessMutex.unlock();
}

void TLogReplayLink::play()
{
    m_pause = false;
}

void TLogReplayLink::pause()
{
    m_pause = true;
}
bool TLogReplayLink::isPaused()
{
    return m_pause;
}
void TLogReplayLink::setMavlinkDecoder(MAVLinkDecoder *decoder)
{
    m_mavlinkDecoder = decoder;
}
void TLogReplayLink::setMavlinkInspector(QGCMAVLinkInspector *inspector)
{
    m_mavlinkInspector = inspector;
}

void TLogReplayLink::run()
{
    m_pause = false;
    m_threadRun = true;
    emit connected(this);
    emit connected(true);
    emit connected();
    QFile file(m_logFile);
    file.open(QIODevice::ReadOnly);
    int bytesize = 0;
    qint64 msecs = QDateTime::currentMSecsSinceEpoch();
    MainWindow::instance()->toolBar().disableConnectWidget(true);
    MainWindow::instance()->toolBar().overrideDisableConnectWidget(true);
    int privSpeedVar = 100;
    mavlink_message_t message;
    mavlink_status_t status;
    QByteArray timebuf;
    bool firsttime = true;
    int delay = 0;
    qint64 lastLogTime = 0;
    qint64 lastPcTime = 0;
    bool nexttime = false;
    qint64 privatepos = 0;
    while (!file.atEnd() && m_threadRun)
    {
        if (QDateTime::currentMSecsSinceEpoch() - msecs > 1000)
        {
            msecs = QDateTime::currentMSecsSinceEpoch();
            m_variableAccessMutex.lock();

            //m_speedVar is a value, between 25 and 175. These are speed percentages.
            privSpeedVar = m_speedVar; //50 - ((m_speedVar) / 4);
            if (privatepos != m_posVar)
            {
                privatepos = m_posVar;
                if (privatepos > 0 && privatepos < 100)
                {
                    file.seek((privatepos / 100.0) * file.size());
                }
            }
            m_variableAccessMutex.unlock();
        }
        emit logProgress(file.pos(),file.size());
        QByteArray bytes = file.read(128);
        bytesize+=128;

        for (int i=0;i<bytes.size();i++)
        {
            unsigned int decodeState = mavlink_parse_char(14, (uint8_t)(bytes[i]), &message, &status);
            if (decodeState != 1)
            {
                //Not a mavlink byte!
                if (nexttime)
                {
                    timebuf.append(bytes[i]);
                }
                if (timebuf.size() == 8)
                {
                    nexttime = false;

                    //Should be a timestamp for the next packet.
                    quint64 logmsecs = static_cast<quint64>(timebuf.at(0)) << 56;
                    logmsecs += static_cast<quint64>(timebuf.at(1)) << 48;
                    logmsecs += static_cast<quint64>(timebuf.at(2)) << 40;
                    logmsecs += static_cast<quint64>(timebuf.at(3)) << 32;
                    logmsecs = static_cast<quint64>(timebuf.at(4)) << 24;
                    logmsecs += static_cast<quint64>(timebuf.at(5)) << 16;
                    logmsecs += static_cast<quint64>(timebuf.at(6)) << 8;
                    logmsecs += static_cast<quint64>(timebuf.at(7)) << 0;

                    timebuf.clear();

{'fraction_non_alphanumeric': 0.1216308040770102, 'fraction_numerical': 0.02287655719139298, 'mean_word_length': 2.5380608974358974, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 33, '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': '6582472', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2895, 'n_words': 546}