libdrmconf  0.12.0
A library to program DMR radios.
anytone_interface.hh
1 #ifndef ANYTONEINTERFACE_HH
2 #define ANYTONEINTERFACE_HH
3 
4 #include "usbserial.hh"
5 
15 {
16  Q_OBJECT
17 
18 public:
20  struct RadioVariant {
22  QString name;
24  char bands;
26  QString version;
27 
29  RadioVariant();
31  bool isValid() const;
32  };
33 
34 public:
37  explicit AnytoneInterface(const USBDeviceDescriptor &descriptor,
38  const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
40  virtual ~AnytoneInterface();
41 
43  void close();
44 
47 
50  bool getInfo(RadioVariant &info);
51 
52  bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
53  bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
54  bool read_finish(const ErrorStack &err=ErrorStack());
55 
56  bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
57  bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
58  bool write_finish(const ErrorStack &err=ErrorStack());
59 
60  bool reboot(const ErrorStack &err=ErrorStack());
61 
62 public:
66  static QList<USBDeviceDescriptor> detect(bool saveOnly=true);
67 
68 protected:
70  bool enter_program_mode(const ErrorStack &err=ErrorStack());
72  bool request_identifier(RadioVariant &info, const ErrorStack &err=ErrorStack());
74  bool leave_program_mode(const ErrorStack &err=ErrorStack());
76  bool send_receive(const char *cmd, int clen, char *resp, int rlen, const ErrorStack &err=ErrorStack());
77 
78 protected:
80  struct __attribute__((packed)) ReadRequest {
81  char cmd;
82  uint32_t addr;
83  uint8_t size;
85  ReadRequest(uint32_t addr);
86  };
87 
89  struct __attribute__((packed)) ReadResponse {
90  char cmd;
91  uint32_t addr;
92  uint8_t size;
93  char data[16];
94  uint8_t sum;
95  uint8_t ack;
99  bool check(uint32_t addr, QString &msg) const;
100  };
101 
103  struct __attribute__((packed)) WriteRequest {
104  char cmd;
105  uint32_t addr;
106  uint8_t size;
107  char data[16];
108  uint8_t sum;
109  uint8_t ack;
110 
114  WriteRequest(uint32_t addr, const char *data);
115  };
116 
118  struct __attribute__((packed)) RadioInfoResponse {
119  char prefix;
120  char model[7];
121  uint8_t bands;
122  char version[6];
123  uint8_t eot;
124  };
125 
127  enum State {
132  STATE_ERROR
134  };
135 
140 };
141 
142 #endif // ANYTONEINTERFACE_HH
Implements the interface to Anytone D868UV, D878UV, etc radios.
Definition: anytone_interface.hh:15
bool leave_program_mode(const ErrorStack &err=ErrorStack())
Sends a command message to radio to leave program state and reboot.
Definition: anytone_interface.cc:342
void close()
Closes the interface to the device.
Definition: anytone_interface.cc:126
bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack())
Reads a chunk of data from the block-address bno (block number).
Definition: anytone_interface.cc:230
bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack())
Starts the write process into the specified bank and at the given address.
Definition: anytone_interface.cc:172
bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack())
Writes a chunk of data at the address addr.
Definition: anytone_interface.cc:182
State _state
Holds the state of the interface.
Definition: anytone_interface.hh:137
RadioInfo identifier(const ErrorStack &err=ErrorStack())
Returns an identifier of the radio.
Definition: anytone_interface.cc:142
bool read_finish(const ErrorStack &err=ErrorStack())
This function ends a series of read operations.
Definition: anytone_interface.cc:263
bool enter_program_mode(const ErrorStack &err=ErrorStack())
Send command message to radio to ender program state.
Definition: anytone_interface.cc:283
State
Possible states of the radio interface.
Definition: anytone_interface.hh:127
@ STATE_CLOSED
Interface to radio is closed (captive final state).
Definition: anytone_interface.hh:131
@ STATE_ERROR
An error occurred (captive final state), use errorMessage() to get an error message.
Definition: anytone_interface.hh:132
@ STATE_OPEN
Interface to radio is open.
Definition: anytone_interface.hh:129
@ STATE_PROGRAM
Radio is in program mode.
Definition: anytone_interface.hh:130
@ STATE_INITIALIZED
Initial state.
Definition: anytone_interface.hh:128
static USBDeviceInfo interfaceInfo()
Returns some information about this interface.
Definition: anytone_interface.cc:114
AnytoneInterface(const USBDeviceDescriptor &descriptor, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructs a new interface to Anytone radios.
Definition: anytone_interface.cc:88
bool reboot(const ErrorStack &err=ErrorStack())
Some radios need to be rebooted after being read or programmed.
Definition: anytone_interface.cc:269
virtual ~AnytoneInterface()
Destructor.
Definition: anytone_interface.cc:108
bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack())
Starts the read process from the specified bank and at the given address.
Definition: anytone_interface.cc:220
bool send_receive(const char *cmd, int clen, char *resp, int rlen, const ErrorStack &err=ErrorStack())
Internal used method to send messages to and receive responses from radio.
Definition: anytone_interface.cc:363
RadioVariant _info
Holds the radio info.
Definition: anytone_interface.hh:139
bool getInfo(RadioVariant &info)
Reads the radio info from the device and returns it.
Definition: anytone_interface.cc:163
bool request_identifier(RadioVariant &info, const ErrorStack &err=ErrorStack())
Sends a request to radio to identify itself.
Definition: anytone_interface.cc:314
bool write_finish(const ErrorStack &err=ErrorStack())
This function ends a series of write operations.
Definition: anytone_interface.cc:214
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Provides some information about a radio model.
Definition: radioinfo.hh:16
Base class for all radio interface descriptors representing a unique interface to a connected radio.
Definition: usbdevice.hh:197
Generic information about a possible radio interface.
Definition: usbdevice.hh:121
Implements a serial connection to a radio via USB.
Definition: usbserial.hh:16
static QList< USBDeviceDescriptor > detect()
Searches for all USB serial ports.
Definition: usbserial.cc:133
Structure of radio information response.
Definition: anytone_interface.hh:118
uint8_t eot
Fixed 0x06 on success.
Definition: anytone_interface.hh:123
uint8_t bands
Frequency bands supported by radio.
Definition: anytone_interface.hh:121
char prefix
Fixed prefix. Set to 'I' on success.
Definition: anytone_interface.hh:119
Collects information about the particular radio being accessed.
Definition: anytone_interface.hh:20
char bands
A code for which bands are supported.
Definition: anytone_interface.hh:24
RadioVariant()
Empty constructor.
Definition: anytone_interface.cc:73
bool isValid() const
Returns true if the radio info is valid.
Definition: anytone_interface.cc:80
QString version
The (firmware/hardware) version.
Definition: anytone_interface.hh:26
QString name
The name of the radio.
Definition: anytone_interface.hh:22
Binary representation of a read request to the radio.
Definition: anytone_interface.hh:80
uint8_t size
Fixed to 16.
Definition: anytone_interface.hh:83
char cmd
Fixed to 'R'.
Definition: anytone_interface.hh:81
uint32_t addr
Memory address in little-endian.
Definition: anytone_interface.hh:82
Binary representation of a read response from the radio.
Definition: anytone_interface.hh:89
char cmd
Fixed to 'W'.
Definition: anytone_interface.hh:90
uint8_t ack
Fixed to 0x06.
Definition: anytone_interface.hh:95
uint8_t sum
Sum over address, size and data.
Definition: anytone_interface.hh:94
uint8_t size
Fixed to 16.
Definition: anytone_interface.hh:92
uint32_t addr
Memory address in big-endian.
Definition: anytone_interface.hh:91
Binary representation of a write request to the radio.
Definition: anytone_interface.hh:103
uint8_t size
Fixed to 16.
Definition: anytone_interface.hh:106
uint32_t addr
Memory address in big-endian.
Definition: anytone_interface.hh:105
uint8_t ack
Fixed to 0x06;.
Definition: anytone_interface.hh:109
uint8_t sum
Sum over addr, size and data.
Definition: anytone_interface.hh:108
char cmd
Fixed to 'W'.
Definition: anytone_interface.hh:104