libdrmconf 0.15.0
A library to program DMR radios.
Loading...
Searching...
No Matches
xmodem.hh
1#ifndef XMODEM_HH
2#define XMODEM_HH
3
4#include "openrtx_link.hh"
5
11class XModem : public QObject
12{
13 Q_OBJECT
14
15protected:
17 enum class State {
18 Init, Transfer, Error
19 };
20
22 enum CtrlByte {
23 SOH = 0x01, STX = 0x02, EOT = 0x04, ACK = 0x06, NAK = 0x15, CAN = 0x18, CRC = 0x43
24 };
25
26public:
28 explicit XModem(OpenRTXLinkStream *transferLayer, QObject *parent=nullptr);
29
35 bool receive(QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack());
36
42 bool send(const QByteArray& buffer, int timeout=-1, const ErrorStack &err=ErrorStack());
43
44protected:
46 bool rxByte(uint8_t &b, int timeout=-1, const ErrorStack &err=ErrorStack());
48 bool txByte(uint8_t b, int timeout=-1, const ErrorStack &err=ErrorStack());
50 bool rxBytes(uint8_t *data, unsigned int size, int timeout=-1, const ErrorStack &err=ErrorStack());
52 bool txBytes(const uint8_t *data, unsigned int size, int timeout=-1, const ErrorStack &err=ErrorStack());
54 static uint16_t crc_ccitt(const QByteArray &data);
55
56private:
58 OpenRTXLinkStream *_link;
60 State _state;
62 unsigned int _maxRetry;
63};
64
65#endif // XMODEM_HH
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition errorstack.hh:43
An abstract stream encapsulated within OpenRTXLink.
Definition openrtx_link.hh:94
State
Possible states of the state machine.
Definition xmodem.hh:17
CtrlByte
Possible XMODEM control bytes.
Definition xmodem.hh:22
bool receive(QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack())
Receives an entire file from the device.
Definition xmodem.cc:13
bool rxBytes(uint8_t *data, unsigned int size, int timeout=-1, const ErrorStack &err=ErrorStack())
Receives exactly size bytes from the device.
Definition xmodem.cc:262
bool send(const QByteArray &buffer, int timeout=-1, const ErrorStack &err=ErrorStack())
Sends the contents of buffer to the device.
Definition xmodem.cc:144
bool rxByte(uint8_t &b, int timeout=-1, const ErrorStack &err=ErrorStack())
Recives a single byte from the device.
Definition xmodem.cc:231
static uint16_t crc_ccitt(const QByteArray &data)
Computes the CRC16 checksum.
Definition xmodem.cc:281
bool txByte(uint8_t b, int timeout=-1, const ErrorStack &err=ErrorStack())
Sends a single byte to the device.
Definition xmodem.cc:221
XModem(OpenRTXLinkStream *transferLayer, QObject *parent=nullptr)
Constructs a xmodem connection via the USB device specified by descriptor.
Definition xmodem.cc:5
bool txBytes(const uint8_t *data, unsigned int size, int timeout=-1, const ErrorStack &err=ErrorStack())
Sends exactly size bytes to the device.
Definition xmodem.cc:244