2017-11-28 00:17:11 +00:00
|
|
|
#ifndef UARTSTYLEDECODER_H
|
|
|
|
#define UARTSTYLEDECODER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include "isobufferbuffer.h"
|
|
|
|
#include "isobuffer.h"
|
2018-07-26 01:16:48 +01:00
|
|
|
#include <mutex>
|
2018-12-11 09:25:14 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
enum class UartParity : uint8_t
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Even,
|
|
|
|
Odd
|
|
|
|
};
|
2017-11-28 00:17:11 +00:00
|
|
|
|
|
|
|
class uartStyleDecoder : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-03-18 07:14:49 +00:00
|
|
|
explicit uartStyleDecoder(double baudRate, QObject *parent = NULL);
|
|
|
|
~uartStyleDecoder() = default;
|
|
|
|
|
|
|
|
|
2017-11-28 00:17:11 +00:00
|
|
|
private:
|
2019-03-18 07:14:49 +00:00
|
|
|
isoBuffer *m_parent;
|
|
|
|
|
|
|
|
// Indicates the current bit being decoded.
|
2018-07-26 01:16:48 +01:00
|
|
|
int serialPtr_bit;
|
2019-03-18 07:14:49 +00:00
|
|
|
|
2017-11-28 00:17:11 +00:00
|
|
|
bool uartTransmitting = false;
|
|
|
|
bool newUartSymbol = false;
|
2018-12-11 09:25:14 +00:00
|
|
|
uint32_t dataBit_current = 0;
|
|
|
|
uint32_t parityIndex = UINT_MAX;
|
|
|
|
uint32_t dataBit_max = 7;
|
2017-11-28 00:17:11 +00:00
|
|
|
unsigned short currentUartSymbol = 0;
|
|
|
|
bool jitterCompensationNeeded = true;
|
2019-03-18 07:14:49 +00:00
|
|
|
|
|
|
|
void updateSerialPtr(bool current_bit);
|
|
|
|
bool getNextUartBit() const;
|
|
|
|
void decodeNextUartBit(bool bitValue);
|
|
|
|
bool jitterCompensationProcedure(bool current_bit);
|
|
|
|
|
2019-06-23 04:26:47 +01:00
|
|
|
bool m_hexDisplay = false;
|
|
|
|
|
2017-11-28 00:17:11 +00:00
|
|
|
QPlainTextEdit *console;
|
2019-03-18 07:14:49 +00:00
|
|
|
isoBufferBuffer m_serialBuffer;
|
|
|
|
public:
|
|
|
|
double m_baudRate;
|
|
|
|
QTimer m_updateTimer; // IMPORTANT: must be after m_serialBuffer. construction / destruction order matters
|
|
|
|
void serialDecode();
|
|
|
|
int serialDistance() const;
|
2019-06-23 04:26:47 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void wireDisconnected(int);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void updateConsole();
|
|
|
|
void setParityMode(UartParity newParity);
|
|
|
|
void setHexDisplay(bool enabled);
|
|
|
|
|
2019-03-18 07:14:49 +00:00
|
|
|
private:
|
|
|
|
char decodeDatabit(int mode, short symbol) const;
|
|
|
|
char decodeBaudot(short symbol) const;
|
|
|
|
|
2018-07-26 01:16:48 +01:00
|
|
|
std::mutex mutex;
|
2018-12-11 09:25:14 +00:00
|
|
|
UartParity parity = UartParity::None;
|
2019-03-18 07:14:49 +00:00
|
|
|
|
|
|
|
bool isParityCorrect(uint32_t bitField) const;
|
|
|
|
UartParity parityOf(uint32_t bitField) const;
|
|
|
|
|
2018-12-11 09:25:14 +00:00
|
|
|
bool parityCheckFailed = false;
|
2019-06-23 04:26:47 +01:00
|
|
|
|
2017-11-28 00:17:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // UARTSTYLEDECODER_H
|