增加ToHex,实现字节码到十六进制字符串的转换
This commit is contained in:
parent
5b008f3491
commit
a65c0157cc
|
@ -151,6 +151,15 @@ byte NRF24L01::WriteReg(byte reg, byte dat)
|
||||||
// 配置
|
// 配置
|
||||||
void NRF24L01::Config()
|
void NRF24L01::Config()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
debug_printf(" Address:");
|
||||||
|
Sys.ShowHex(Address, 5, '-');
|
||||||
|
debug_printf("\r\n");
|
||||||
|
debug_printf(" Channel: %d\r\n", Channel);
|
||||||
|
debug_printf(" AutoAns: %d\r\n", AutoAnswer);
|
||||||
|
debug_printf(" Payload: %d\r\n", PayloadWidth);
|
||||||
|
#endif
|
||||||
|
|
||||||
CEDown();
|
CEDown();
|
||||||
|
|
||||||
WriteBuf(TX_ADDR, Address, ArrayLength(Address));
|
WriteBuf(TX_ADDR, Address, ArrayLength(Address));
|
||||||
|
|
26
Sys.cpp
26
Sys.cpp
|
@ -483,10 +483,10 @@ uint TSys::Crc(const void* rgBlock, int len, uint crc)
|
||||||
// 显示十六进制数据,指定分隔字符
|
// 显示十六进制数据,指定分隔字符
|
||||||
void TSys::ShowHex(byte* buf, uint len, char sep)
|
void TSys::ShowHex(byte* buf, uint len, char sep)
|
||||||
{
|
{
|
||||||
for(int i=0; i<len; i++)
|
for(int i=0; i < len; i++)
|
||||||
{
|
{
|
||||||
debug_printf("%02X", *buf++);
|
debug_printf("%02X", *buf++);
|
||||||
if(!sep) debug_printf("%c", sep);
|
if(i < len - 1 && sep != '\0') debug_printf("%c", sep);
|
||||||
//if(((i + 1) & 0xF) == 0) debug_printf("\r\n");
|
//if(((i + 1) & 0xF) == 0) debug_printf("\r\n");
|
||||||
}
|
}
|
||||||
//debug_printf("\r\n");
|
//debug_printf("\r\n");
|
||||||
|
@ -498,12 +498,34 @@ void TSys::ShowString(byte* buf, uint len)
|
||||||
if(len == 0) len = 1000;
|
if(len == 0) len = 1000;
|
||||||
for(int i=0; i<len; i++)
|
for(int i=0; i<len; i++)
|
||||||
{
|
{
|
||||||
|
if(buf[i] == 0) return;
|
||||||
if(buf[i] >= 32 && buf[i] <= 126 || buf[i] == 0x0A || buf[i] == 0x0D || buf[i] == 0x09)
|
if(buf[i] >= 32 && buf[i] <= 126 || buf[i] == 0x0A || buf[i] == 0x0D || buf[i] == 0x09)
|
||||||
debug_printf("%c", buf[i]);
|
debug_printf("%c", buf[i]);
|
||||||
else
|
else
|
||||||
debug_printf("%02X", buf[i]);
|
debug_printf("%02X", buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 源数据转为十六进制字符编码再放入目标字符,比如0x28在目标放两个字节0x02 0x08
|
||||||
|
void TSys::ToHex(byte* buf, byte* src, uint len)
|
||||||
|
{
|
||||||
|
for(int i=0; i < len; i++, src++)
|
||||||
|
{
|
||||||
|
byte n = *src >> 4;
|
||||||
|
if(n < 10)
|
||||||
|
n += '0';
|
||||||
|
else
|
||||||
|
n += 'A' - 10;
|
||||||
|
*buf++ = n;
|
||||||
|
|
||||||
|
n = *src & 0x0F;
|
||||||
|
if(n < 10)
|
||||||
|
n += '0';
|
||||||
|
else
|
||||||
|
n += 'A' - 10;
|
||||||
|
*buf++ = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define __TASK__MODULE__ 1
|
#define __TASK__MODULE__ 1
|
||||||
|
|
1
Sys.h
1
Sys.h
|
@ -85,6 +85,7 @@ public:
|
||||||
|
|
||||||
void ShowHex(byte* buf, uint len, char sep = '\0');// 显示十六进制数据,指定分隔字符
|
void ShowHex(byte* buf, uint len, char sep = '\0');// 显示十六进制数据,指定分隔字符
|
||||||
void ShowString(byte* buf, uint len = 0); // 显示字符串,不指定长度时自动找\0
|
void ShowString(byte* buf, uint len = 0); // 显示字符串,不指定长度时自动找\0
|
||||||
|
void ToHex(byte* buf, byte* src, uint len); // 源数据转为十六进制字符编码再放入目标字符,比如0x28在目标放两个字节0x02 0x08
|
||||||
private:
|
private:
|
||||||
int _Index; // MCU在型号表中的索引
|
int _Index; // MCU在型号表中的索引
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue