[MOD] Improved regdump and hexdump
This commit is contained in:
parent
bd258380c8
commit
b014a1f748
2 changed files with 45 additions and 29 deletions
|
@ -188,7 +188,7 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPIreadRegisterBurst(uint16_t reg, uint8_t numBytes, uint8_t* inBytes) {
|
void Module::SPIreadRegisterBurst(uint16_t reg, size_t numBytes, uint8_t* inBytes) {
|
||||||
if(!SPIstreamType) {
|
if(!SPIstreamType) {
|
||||||
SPItransfer(SPIreadCommand, reg, NULL, inBytes, numBytes);
|
SPItransfer(SPIreadCommand, reg, NULL, inBytes, numBytes);
|
||||||
} else {
|
} else {
|
||||||
|
@ -208,7 +208,7 @@ uint8_t Module::SPIreadRegister(uint16_t reg) {
|
||||||
return(resp);
|
return(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, uint8_t numBytes) {
|
void Module::SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, size_t numBytes) {
|
||||||
if(!SPIstreamType) {
|
if(!SPIstreamType) {
|
||||||
SPItransfer(SPIwriteCommand, reg, data, NULL, numBytes);
|
SPItransfer(SPIwriteCommand, reg, data, NULL, numBytes);
|
||||||
} else {
|
} else {
|
||||||
|
@ -226,7 +226,7 @@ void Module::SPIwriteRegister(uint16_t reg, uint8_t data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
|
void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes) {
|
||||||
// start SPI transaction
|
// start SPI transaction
|
||||||
this->SPIbeginTransaction();
|
this->SPIbeginTransaction();
|
||||||
|
|
||||||
|
@ -279,11 +279,11 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d
|
||||||
this->SPIendTransaction();
|
this->SPIendTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPIreadStream(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForGpio, bool verify) {
|
int16_t Module::SPIreadStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||||
return(this->SPIreadStream(&cmd, 1, data, numBytes, waitForGpio, verify));
|
return(this->SPIreadStream(&cmd, 1, data, numBytes, waitForGpio, verify));
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForGpio, bool verify) {
|
int16_t Module::SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||||
// send the command
|
// send the command
|
||||||
int16_t state = this->SPItransferStream(cmd, cmdLen, false, NULL, data, numBytes, waitForGpio, 5000);
|
int16_t state = this->SPItransferStream(cmd, cmdLen, false, NULL, data, numBytes, waitForGpio, 5000);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
@ -296,11 +296,11 @@ int16_t Module::SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPIwriteStream(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForGpio, bool verify) {
|
int16_t Module::SPIwriteStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||||
return(this->SPIwriteStream(&cmd, 1, data, numBytes, waitForGpio, verify));
|
return(this->SPIwriteStream(&cmd, 1, data, numBytes, waitForGpio, verify));
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForGpio, bool verify) {
|
int16_t Module::SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||||
// send the command
|
// send the command
|
||||||
int16_t state = this->SPItransferStream(cmd, cmdLen, true, data, NULL, numBytes, waitForGpio, 5000);
|
int16_t state = this->SPItransferStream(cmd, cmdLen, true, data, NULL, numBytes, waitForGpio, 5000);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
@ -333,7 +333,7 @@ int16_t Module::SPIcheckStream() {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForGpio, uint32_t timeout) {
|
int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes, bool waitForGpio, uint32_t timeout) {
|
||||||
#if defined(RADIOLIB_VERBOSE)
|
#if defined(RADIOLIB_VERBOSE)
|
||||||
uint8_t debugBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
uint8_t debugBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||||
#endif
|
#endif
|
||||||
|
@ -364,7 +364,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
|
|
||||||
// send/receive all bytes
|
// send/receive all bytes
|
||||||
if(write) {
|
if(write) {
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
// send byte
|
// send byte
|
||||||
uint8_t in = this->SPItransfer(dataOut[n]);
|
uint8_t in = this->SPItransfer(dataOut[n]);
|
||||||
#if defined(RADIOLIB_VERBOSE)
|
#if defined(RADIOLIB_VERBOSE)
|
||||||
|
@ -393,7 +393,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
|
|
||||||
// read the data
|
// read the data
|
||||||
if(state == RADIOLIB_ERR_NONE) {
|
if(state == RADIOLIB_ERR_NONE) {
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
dataIn[n] = this->SPItransfer(this->SPInopCommand);
|
dataIn[n] = this->SPItransfer(this->SPInopCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
RADIOLIB_VERBOSE_PRINT("DAT");
|
RADIOLIB_VERBOSE_PRINT("DAT");
|
||||||
if(write) {
|
if(write) {
|
||||||
RADIOLIB_VERBOSE_PRINT("W\t");
|
RADIOLIB_VERBOSE_PRINT("W\t");
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
RADIOLIB_VERBOSE_PRINT(debugBuff[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(debugBuff[n], HEX);
|
||||||
|
@ -445,7 +445,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
||||||
RADIOLIB_VERBOSE_PRINT(debugBuff[0], HEX);
|
RADIOLIB_VERBOSE_PRINT(debugBuff[0], HEX);
|
||||||
RADIOLIB_VERBOSE_PRINT('\t')
|
RADIOLIB_VERBOSE_PRINT('\t')
|
||||||
|
|
||||||
for(uint8_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
RADIOLIB_VERBOSE_PRINT(this->SPInopCommand, HEX);
|
RADIOLIB_VERBOSE_PRINT(this->SPInopCommand, HEX);
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
||||||
|
@ -713,17 +713,29 @@ uint16_t Module::flipBits16(uint16_t i) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::hexdump(uint8_t* data, size_t len) {
|
void Module::hexdump(uint8_t* data, size_t len, uint32_t offset, uint8_t width, bool be) {
|
||||||
size_t rem_len = len;
|
size_t rem_len = len;
|
||||||
for(size_t i = 0; i < len; i+=16) {
|
for(int32_t i = 0; i < len; i+=16) {
|
||||||
char str[80];
|
char str[80];
|
||||||
sprintf(str, "%07x ", i);
|
sprintf(str, "%07x ", i+offset);
|
||||||
size_t line_len = 16;
|
size_t line_len = 16;
|
||||||
if(rem_len < line_len) {
|
if(rem_len < line_len) {
|
||||||
line_len = rem_len;
|
line_len = rem_len;
|
||||||
}
|
}
|
||||||
for(size_t j = 0; j < line_len; j++) {
|
for(int32_t j = 0; j < line_len; j+=width) {
|
||||||
sprintf(&str[8 + j*3], "%02x ", data[i+j]);
|
if(width > 1) {
|
||||||
|
int m = 0;
|
||||||
|
int step = width/2;
|
||||||
|
if(be) {
|
||||||
|
step *= -1;
|
||||||
|
}
|
||||||
|
for(int32_t k = width - 1; k >= -width + 1; k+=step) {
|
||||||
|
sprintf(&str[8 + (j+m)*3], "%02x ", data[i+j+k+m]);
|
||||||
|
m++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sprintf(&str[8 + (j)*3], "%02x ", data[i+j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for(size_t j = line_len; j < 16; j++) {
|
for(size_t j = line_len; j < 16; j++) {
|
||||||
sprintf(&str[8 + j*3], " ");
|
sprintf(&str[8 + j*3], " ");
|
||||||
|
@ -745,14 +757,14 @@ void Module::hexdump(uint8_t* data, size_t len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::regdump(uint8_t start, uint8_t len) {
|
void Module::regdump(uint16_t start, size_t len) {
|
||||||
#if defined(RADIOLIB_STATIC_ONLY)
|
#if defined(RADIOLIB_STATIC_ONLY)
|
||||||
uint8_t buff[RADIOLIB_STATIC_ARRAY_SIZE];
|
uint8_t buff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||||
#else
|
#else
|
||||||
uint8_t* buff = new uint8_t[len];
|
uint8_t* buff = new uint8_t[len];
|
||||||
#endif
|
#endif
|
||||||
SPIreadRegisterBurst(start, len, buff);
|
SPIreadRegisterBurst(start, len, buff);
|
||||||
hexdump(buff, len);
|
hexdump(buff, len, start);
|
||||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||||
delete[] buff;
|
delete[] buff;
|
||||||
#endif
|
#endif
|
||||||
|
|
24
src/Module.h
24
src/Module.h
|
@ -250,7 +250,7 @@ class Module {
|
||||||
|
|
||||||
\param inBytes Pointer to array that will hold the read data.
|
\param inBytes Pointer to array that will hold the read data.
|
||||||
*/
|
*/
|
||||||
void SPIreadRegisterBurst(uint16_t reg, uint8_t numBytes, uint8_t* inBytes);
|
void SPIreadRegisterBurst(uint16_t reg, size_t numBytes, uint8_t* inBytes);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
|
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
|
||||||
|
@ -270,7 +270,7 @@ class Module {
|
||||||
|
|
||||||
\param numBytes Number of bytes that will be written.
|
\param numBytes Number of bytes that will be written.
|
||||||
*/
|
*/
|
||||||
void SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, uint8_t numBytes);
|
void SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, size_t numBytes);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
|
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
|
||||||
|
@ -294,7 +294,7 @@ class Module {
|
||||||
|
|
||||||
\param numBytes Number of bytes to transfer.
|
\param numBytes Number of bytes to transfer.
|
||||||
*/
|
*/
|
||||||
void SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes);
|
void SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to check the result of last SPI stream transfer.
|
\brief Method to check the result of last SPI stream transfer.
|
||||||
|
@ -318,7 +318,7 @@ class Module {
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t SPIreadStream(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForGpio = true, bool verify = true);
|
int16_t SPIreadStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to perform a read transaction with SPI stream.
|
\brief Method to perform a read transaction with SPI stream.
|
||||||
|
@ -337,7 +337,7 @@ class Module {
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForGpio = true, bool verify = true);
|
int16_t SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to perform a write transaction with SPI stream.
|
\brief Method to perform a write transaction with SPI stream.
|
||||||
|
@ -354,7 +354,7 @@ class Module {
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t SPIwriteStream(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForGpio = true, bool verify = true);
|
int16_t SPIwriteStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Method to perform a write transaction with SPI stream.
|
\brief Method to perform a write transaction with SPI stream.
|
||||||
|
@ -373,7 +373,7 @@ class Module {
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForGpio = true, bool verify = true);
|
int16_t SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI single transfer method for modules with stream-type SPI interface (SX126x, SX128x etc.).
|
\brief SPI single transfer method for modules with stream-type SPI interface (SX126x, SX128x etc.).
|
||||||
|
@ -396,7 +396,7 @@ class Module {
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForGpio, uint32_t timeout);
|
int16_t SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes, bool waitForGpio, uint32_t timeout);
|
||||||
|
|
||||||
// pin number access methods
|
// pin number access methods
|
||||||
|
|
||||||
|
@ -684,8 +684,12 @@ class Module {
|
||||||
\param data Data to dump.
|
\param data Data to dump.
|
||||||
|
|
||||||
\param len Number of bytes to dump.
|
\param len Number of bytes to dump.
|
||||||
|
|
||||||
|
\param width Word width (1 for uint8_t, 2 for uint16_t, 4 for uint32_t).
|
||||||
|
|
||||||
|
\param be Print multi-byte data as big endian. Defaults to false.
|
||||||
*/
|
*/
|
||||||
static void hexdump(uint8_t* data, size_t len);
|
static void hexdump(uint8_t* data, size_t len, uint32_t offset = 0, uint8_t width = 1, bool be = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Function to dump device registers as hex into the debug port.
|
\brief Function to dump device registers as hex into the debug port.
|
||||||
|
@ -694,7 +698,7 @@ class Module {
|
||||||
|
|
||||||
\param len Number of bytes to dump.
|
\param len Number of bytes to dump.
|
||||||
*/
|
*/
|
||||||
void regdump(uint8_t start, uint8_t len);
|
void regdump(uint16_t start, size_t len);
|
||||||
|
|
||||||
#if !defined(RADIOLIB_GODMODE)
|
#if !defined(RADIOLIB_GODMODE)
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue