libdrmconf
0.12.0
A library to program DMR radios.
|
Interface to TyT (and Retevis) devices. More...
#include <tyt_interface.hh>
Public Member Functions | |
TyTInterface (const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr) | |
Constructor. More... | |
~TyTInterface () | |
Destructor. | |
bool | isOpen () const |
Return true if a connection to the device has been established. | |
RadioInfo | identifier (const ErrorStack &err=ErrorStack()) |
Returns a device identifier. | |
void | close () |
Closes the connection to the device. | |
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. More... | |
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). More... | |
bool | read_finish (const ErrorStack &err=ErrorStack()) |
This function ends a series of read operations. More... | |
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. More... | |
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 . More... | |
bool | write_finish (const ErrorStack &err=ErrorStack()) |
This function ends a series of write operations. More... | |
bool | reboot (const ErrorStack &err=ErrorStack()) |
Some radios need to be rebooted after being read or programmed. More... | |
bool | erase (unsigned start, unsigned size, void(*progress)(unsigned, void *)=nullptr, void *ctx=nullptr, const ErrorStack &err=ErrorStack()) |
Erases a memory section at start of size size . | |
Public Member Functions inherited from DFUSEDevice | |
DFUSEDevice (const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), uint16_t blocksize=32, QObject *parent=nullptr) | |
Constructor, also connects to the specified VID/PID device found first. More... | |
void | close () |
Closes the connection. | |
uint16_t | blocksize () const |
Returns the blocksize in bytes. | |
bool | setAddress (uint32_t address, const ErrorStack &err=ErrorStack()) |
Sets the read/write reference address. More... | |
bool | readBlock (unsigned block, uint8_t *data, const ErrorStack &err=ErrorStack()) |
Reads a block of data from the device. More... | |
bool | writeBlock (unsigned block, const uint8_t *data, const ErrorStack &err=ErrorStack()) |
Writes a block of data to the device. More... | |
bool | erasePage (uint32_t address, const ErrorStack &err=ErrorStack()) |
Erases an entire page of memory at the specified address. More... | |
bool | eraseAll (const ErrorStack &err=ErrorStack()) |
Erases the entire memory. More... | |
bool | releaseReadLock (const ErrorStack &err=ErrorStack()) |
Releases the read lock. More... | |
bool | leaveDFU (const ErrorStack &err=ErrorStack()) |
Leaves the DFU mode, may boot into the application code. | |
Public Member Functions inherited from DFUDevice | |
DFUDevice (const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr) | |
Opens a connection to the USB-DFU device at vendor vid and product pid . | |
virtual | ~DFUDevice () |
Destructor. | |
bool | isOpen () const |
Returns true if the DFU device interface is open. | |
void | close () |
Closes the DFU interface. | |
int | download (unsigned block, uint8_t *data, unsigned len, const ErrorStack &err=ErrorStack()) |
Downloads some data to the device. | |
int | upload (unsigned block, uint8_t *data, unsigned len, const ErrorStack &err=ErrorStack()) |
Uploads some data from the device. | |
Public Member Functions inherited from RadioInterface | |
virtual | ~RadioInterface () |
Destructor. | |
Static Public Member Functions | |
static USBDeviceInfo | interfaceInfo () |
Returns some information about the interface. | |
static QList< USBDeviceDescriptor > | detect (bool saveOnly=true) |
Tries to find all interfaces connected TyT radios. | |
Static Public Member Functions inherited from DFUDevice | |
static QList< USBDeviceDescriptor > | detect (uint16_t vid, uint16_t pid) |
Finds all DFU interfaces with the specified VID/PID combination. | |
Protected Member Functions | |
int | md380_command (uint8_t a, uint8_t b, const ErrorStack &err=ErrorStack()) |
Internal used function to send a control command to the device. | |
int | set_address (uint32_t address, const ErrorStack &err=ErrorStack()) |
Internal used function to set the current I/O address. | |
int | erase_block (uint32_t address, const ErrorStack &err=ErrorStack()) |
Internal used function to erase a specific block. | |
const char * | identify (const ErrorStack &err=ErrorStack()) |
Internal used function to read the device identifier. | |
Protected Member Functions inherited from DFUDevice | |
int | detach (int timeout, const ErrorStack &err=ErrorStack()) |
Internal used function to detach the device. | |
int | get_status (const ErrorStack &err=ErrorStack()) |
Internal used function to read the current status. | |
int | clear_status (const ErrorStack &err=ErrorStack()) |
Internal used function to clear the status. | |
int | get_state (int &pstate, const ErrorStack &err=ErrorStack()) |
Internal used function to read the state. | |
int | abort (const ErrorStack &err=ErrorStack()) |
Internal used function to abort the current operation. | |
int | wait_idle (const ErrorStack &err=ErrorStack()) |
Internal used function to busy-wait for a response from the device. | |
Protected Member Functions inherited from RadioInterface | |
RadioInterface () | |
Hidden constructor. | |
Protected Attributes | |
RadioInfo | _ident |
Read identifier. | |
Protected Attributes inherited from DFUSEDevice | |
uint16_t | _blocksize |
Holds the block size in bytes. | |
Protected Attributes inherited from DFUDevice | |
libusb_context * | _ctx |
USB context. | |
libusb_device_handle * | _dev |
USB device object. | |
status_t | _status |
Device status. | |
Interface to TyT (and Retevis) devices.
This class extends the DFUDevice
and implements the RadioInterface
to identify the radio, reading/writing and erasing codeplugs or the callsign DB.
The communication with the device is kind of weird. It all happens through memory reads and writes. This is not unusual as such, but they implemented a weird memory mapping. Everything written to block 0 (i.e., memory address 0x00000000) is a command to the radio. Responses to these commands are read back from the same address/block.
The funny thing is, however, that there is a command that sets the memory read and write address, although the DFU interface actually provides means to specify that address. Moreover, commands and data are sent and written to the same DFU interface number. Someone did not understand the DFU interface.
The following commands has been seen.
The request written is
There is no explicit response read back.
The request written is
There is no explicit response read back.
The request written is
There is always some response read back. The size varies with whatever is read back.
WhatCode | Resp. Len. | Description> |
---|---|---|
0x01 | 32 | The radio identifier as a string + some unknown information. |
0x02 | 4 | Unknown |
0x03 | 24 | Unknown |
0x04 | 8 | Unknown |
0x07 | 16 | Unknown |
TyTInterface::TyTInterface | ( | const USBDeviceDescriptor & | descr, |
const ErrorStack & | err = ErrorStack() , |
||
QObject * | parent = nullptr |
||
) |
Constructor.
Opens an interface to the specified interface.
|
virtual |
Reads a chunk of data from the block-address bno
(block number).
bank | Specifies the memory bank to read from. Usually there is only one bank. Some radios, however, to have several memory banks to hold the codeplug. For example the Open GD77 has EEPROM and Flash memory banks with independent addresses. |
addr | Specifies the address to read from. |
data | Pointer where to store the read data. |
nbytes | Specifies the number of bytes to read. |
err | Passes an error stack to put error messages on. |
true
on success. Implements RadioInterface.
|
virtual |
This function ends a series of read
operations.
This function will be re-implemented by certain interfaces that need completion of read operations (e.g., HID).
err | Passes an error stack to put error messages on. |
Implements RadioInterface.
|
virtual |
Starts the read process from the specified bank and at the given address.
bank | Specifies the memory bank to read from. Usually there is only one bank. Some radios, however, to have several memory banks to hold the codeplug. For example the Open GD77 has EEPROM and Flash memory banks with independent addresses. |
addr | Specifies the address to read from. |
err | Passes an error stack to put error messages on. |
Implements RadioInterface.
|
virtual |
Some radios need to be rebooted after being read or programmed.
This function will be re-implemented by some interfaces (e.g., DFUDevice) to reboot the radio. By default this function does nothing.
err | Passes an error stack to put error messages on. |
Reimplemented from RadioInterface.
|
virtual |
Writes a chunk of data
at the address addr
.
bank | Specifies the memory bank to write to. Usually there is only one bank. Some radios, however, to have several memory banks to hold the codeplug. For example the Open GD77 has EEPROM and Flash memory banks with independent addresses. |
addr | Specifies the address to write to. |
data | Pointer to the actual data to be written. |
nbytes | Specifies the number of bytes to write. |
err | Passes an error stack to put error messages on. |
true
on success. Implements RadioInterface.
|
virtual |
This function ends a series of write
operations.
This function will be implemented by certain interfaces that need completion of write operations (e.g., HID).
err | Passes an error stack to put error messages on. |
Implements RadioInterface.
|
virtual |
Starts the write process into the specified bank and at the given address.
bank | Specifies the memory bank to write to. Usually there is only one bank. Some radios, however, to have several memory banks to hold the codeplug. For example the Open GD77 has EEPROM and Flash memory banks with independent addresses. |
addr | Specifies the address to write to. |
err | Passes an error stack to put error messages on. |
Implements RadioInterface.