Sys不再提供显示字符串或字节数组的功能
This commit is contained in:
parent
2d05ae979d
commit
74ea976b13
|
@ -386,16 +386,14 @@ bool NRF24L01::Config()
|
|||
if(st.Beken) debug_printf("上海Beken芯片\r\n");
|
||||
|
||||
debug_printf(" 本地地址: ");
|
||||
Sys.ShowHex(Address, 5, '-');
|
||||
debug_printf("\r\n");
|
||||
ByteArray(Address, 5).Show(true);
|
||||
|
||||
// 根据AddrBits决定相应通道是否打开
|
||||
byte bits = AddrBits >> 1;
|
||||
if(bits & 0x01)
|
||||
{
|
||||
debug_printf(" Addres1: ");
|
||||
Sys.ShowHex(Address1, 5, '-');
|
||||
debug_printf("\r\n");
|
||||
ByteArray(Address1, 5).Show(true);
|
||||
}
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
|
@ -403,10 +401,8 @@ bool NRF24L01::Config()
|
|||
if(bits & 0x01)
|
||||
{
|
||||
debug_printf(" Addres%d: ", i + 2);
|
||||
Sys.ShowHex(Addr2_5 + i, 1, '-');
|
||||
debug_printf("-");
|
||||
Sys.ShowHex(Address1 + 1, 4, '-');
|
||||
debug_printf("\r\n");
|
||||
ByteArray(Addr2_5 + i, 1).Show(true);
|
||||
ByteArray(Address1 + 1, 4).Show(true);
|
||||
}
|
||||
}
|
||||
static const short powers[] = {-12, -6, -4, 0, 1, 3, 4, 7};
|
||||
|
|
|
@ -64,16 +64,14 @@ uint Controller::Dispatch(ITransport* port, ByteArray& bs, void* param, void* pa
|
|||
#if MSG_DEBUG
|
||||
/*msg_printf("TinyNet::Dispatch[%d] ", len);
|
||||
// 输出整条信息
|
||||
Sys.ShowHex(buf, len, '-');
|
||||
msg_printf("\r\n");*/
|
||||
ByteArray(buf, len).Show(true);*/
|
||||
#endif
|
||||
if(len > control->Port->MaxSize)
|
||||
{
|
||||
#if MSG_DEBUG
|
||||
msg_printf("TinyNet::Dispatch[%d] ", len);
|
||||
// 输出整条信息
|
||||
Sys.ShowHex(buf, len, '-');
|
||||
msg_printf("\r\n");
|
||||
ByteArray(buf, len).Show(true);
|
||||
#endif
|
||||
msg_printf("数据长度 %d 超过控制器可接受最大长度 %d \r\n", len, control->Port->MaxSize);
|
||||
//assert_param2(len <= control->Port->MaxSize, "数据长度超过控制器可接受最大长度");
|
||||
|
@ -102,8 +100,7 @@ uint Controller::Dispatch(ITransport* port, ByteArray& bs, void* param, void* pa
|
|||
|
||||
msg_printf("TinyNet::DispatchError[%d] ", len);
|
||||
// 输出整条信息
|
||||
Sys.ShowHex(buf, len, '-');
|
||||
msg_printf("\r\n");
|
||||
ByteArray(buf, len).Show(true);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ void Dhcp::Process(ByteArray& bs, const IPEndPoint& ep)
|
|||
if(opt)
|
||||
{
|
||||
debug_printf(" ");
|
||||
Sys.ShowString(&opt->Data, opt->Length);
|
||||
String(&opt->Data, opt->Length).Show(true);
|
||||
}
|
||||
debug_printf("\r\n");
|
||||
}
|
||||
|
|
57
Sys.cpp
57
Sys.cpp
|
@ -368,11 +368,10 @@ void TSys::ShowInfo()
|
|||
debug_printf(" R%dp%d", cpu->Revision, cpu->Variant);
|
||||
debug_printf("\r\n");
|
||||
debug_printf("ChipID:");
|
||||
ShowHex(ID, ArrayLength(ID), '-');
|
||||
ByteArray(ID, ArrayLength(ID)).Show(true);
|
||||
|
||||
debug_printf("\t");
|
||||
ShowString(ID, 12, false);
|
||||
debug_printf("\r\n");
|
||||
String(ID, 12).Show(true);
|
||||
|
||||
// 输出堆信息
|
||||
uint start = (uint)&__heap_base;
|
||||
|
@ -393,62 +392,12 @@ void TSys::ShowInfo()
|
|||
Time.Now().Show(true);
|
||||
// 系统启动时间
|
||||
debug_printf("Start: %dms (Inited: %dms)\r\n", (uint)(Time.Current() - StartTime), (uint)(initedTime - StartTime));
|
||||
debug_printf("技术支持: http://www.NewLifeX.com\r\n");
|
||||
debug_printf("Support: http://www.NewLifeX.com\r\n");
|
||||
|
||||
debug_printf("\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#define __HELP__MODULE__ 1
|
||||
#ifdef __HELP__MODULE__
|
||||
// 显示十六进制数据,指定分隔字符
|
||||
void TSys::ShowHex(byte* buf, uint len, char sep)
|
||||
{
|
||||
for(int i=0; i < len; i++)
|
||||
{
|
||||
debug_printf("%02X", *buf++);
|
||||
if(i < len - 1 && sep != '\0') debug_printf("%c", sep);
|
||||
//if(((i + 1) & 0xF) == 0) debug_printf("\r\n");
|
||||
}
|
||||
//debug_printf("\r\n");
|
||||
}
|
||||
|
||||
// 显示字符串,不指定长度时自动找\0
|
||||
void TSys::ShowString(byte* buf, uint len, bool autoEnd)
|
||||
{
|
||||
if(len == 0) len = 1000;
|
||||
for(int i=0; i<len; i++)
|
||||
{
|
||||
if(buf[i] == 0 && autoEnd) return;
|
||||
if(buf[i] >= 32 && buf[i] <= 126 || buf[i] == 0x0A || buf[i] == 0x0D || buf[i] == 0x09)
|
||||
debug_printf("%c", buf[i]);
|
||||
else
|
||||
debug_printf("%02X", buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 源数据src转为十六进制字符编码再放入目标字符buf,比如0xA8在目标放两个字节0x41(A) 0x38(8)
|
||||
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
|
||||
|
||||
#define __TASK__MODULE__ 1
|
||||
#ifdef __TASK__MODULE__
|
||||
|
||||
|
|
7
Sys.h
7
Sys.h
|
@ -108,13 +108,6 @@ public:
|
|||
void Reset(); // 重启系统
|
||||
bool (*OnError)(uint code); // 系统出错时引发,返回值决定是否停止系统
|
||||
Func OnStop;
|
||||
|
||||
// 显示十六进制数据,指定分隔字符
|
||||
void ShowHex(byte* buf, uint len, char sep = '\0');
|
||||
// 显示字符串,不指定长度时自动找\0
|
||||
void ShowString(byte* buf, uint len = 0, bool autoEnd = true);
|
||||
// 源数据src转为十六进制字符编码再放入目标字符buf,比如0xA8在目标放两个字节0x41(A) 0x38(8)
|
||||
void ToHex(byte* buf, byte* src, uint len);
|
||||
private:
|
||||
int _Index; // MCU在型号表中的索引
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ void TestCrc()
|
|||
uint data = 0x12345678;
|
||||
uint crc = Crc::Hash((byte*)&data, 4, 0);
|
||||
uint crc2 = Crc::Hash(&data, 4);
|
||||
Sys.ShowHex((byte*)&data, 4);
|
||||
ByteArray((byte*)&data, 4)).Show();
|
||||
debug_printf("\r\n\tSoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 无初值时,两者一样
|
||||
|
||||
|
@ -88,7 +88,7 @@ void TestCrc()
|
|||
// 试试二次计算Crc
|
||||
crc = Crc::Hash((byte*)&crc, 4, 0);
|
||||
crc2 = Crc::Hash(&crc2, 4);
|
||||
Sys.ShowHex((byte*)&temp, 4);
|
||||
ByteArray((byte*)&temp, 4)).Show();
|
||||
debug_printf("\r\n\t");
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 结果相同,但都不是0
|
||||
|
@ -99,7 +99,7 @@ void TestCrc()
|
|||
data2 += data;
|
||||
crc = Crc::Hash((byte*)&data2, 8, 0);
|
||||
crc2 = Crc::Hash(&data2, 8);
|
||||
Sys.ShowHex((byte*)&data2, 8);
|
||||
ByteArray((byte*)&data2, 8)).Show();
|
||||
debug_printf("\r\n\t");
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 结果相同,但都不是0
|
||||
|
@ -108,14 +108,14 @@ void TestCrc()
|
|||
// 实际上就是数字为初值,对它自身进行校验码计算
|
||||
crc = Crc::Hash((byte*)&temp, 4, data);
|
||||
crc2 = HardCrc(&temp, 4, data);
|
||||
Sys.ShowHex((byte*)&temp, 4);
|
||||
ByteArray((byte*)&temp, 4)).Show();
|
||||
debug_printf(" <= 0x%08x\r\n\t", data);
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 结果不同,HardCrc结果跟8字节测试相同
|
||||
|
||||
crc = Crc::Hash((byte*)&temp, 4, temp);
|
||||
crc2 = HardCrc(&temp, 4, temp);
|
||||
Sys.ShowHex((byte*)&temp, 4);
|
||||
ByteArray((byte*)&temp, 4)).Show();
|
||||
debug_printf(" <= 0x%08x\r\n\t", temp);
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 结果不同,SoftCrc结果跟8字节测试相同
|
||||
|
@ -125,7 +125,7 @@ void TestCrc()
|
|||
|
||||
crc = Crc::Hash((byte*)DataBuffer, size*4, 0);
|
||||
crc2 = Crc::Hash(DataBuffer, size*4);
|
||||
Sys.ShowHex((byte*)DataBuffer, 0x20);
|
||||
ByteArray((byte*)DataBuffer, 0x20)).Show();
|
||||
debug_printf("\r\n\t");
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 无初值时,两者一样
|
||||
|
@ -135,7 +135,7 @@ void TestCrc()
|
|||
// 实际应用中,先计算数据的校验,然后接着附加校验码部分
|
||||
crc = Crc::Hash((byte*)&temp, 4, temp);
|
||||
crc2 = HardCrc((byte*)&temp, 4, temp);
|
||||
Sys.ShowHex((byte*)&temp, 4);
|
||||
ByteArray((byte*)&temp, 4)).Show();
|
||||
debug_printf(" <= 0x%08x\r\n\t", temp);
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
// 有初值时,两者不一样
|
||||
|
@ -146,7 +146,7 @@ void TestCrc()
|
|||
crc = Crc::Hash((byte*)&crc, 4, crc);
|
||||
crc2 = HardCrc(DataBuffer, size*4, 0);
|
||||
crc2 = HardCrc((byte*)&crc2, 4, crc2);
|
||||
Sys.ShowHex((byte*)DataBuffer, 0x20);
|
||||
ByteArray((byte*)DataBuffer, 0x20).Show();
|
||||
debug_printf(" <= 0x%08x\r\n\t", temp);
|
||||
debug_printf("SoftCrc:0x%08x HardCrc:0x%08x \r\n", crc, crc2);
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ bool OnUdpReceived(UdpSocket* socket, UDP_HEADER* udp, byte* buf, uint len)
|
|||
debug_printf("Udp::On %d From ", socket->LocalPort);
|
||||
TinyIP::ShowIP(socket->RemoteIP);
|
||||
debug_printf(":%d with Payload=%d ", socket->RemotePort, len);
|
||||
Sys.ShowString(buf, len);
|
||||
debug_printf(" \r\n");
|
||||
String(buf, len).Show(true);
|
||||
|
||||
return socket->LocalPort == 888;
|
||||
}
|
||||
|
@ -63,8 +62,7 @@ bool OnTcpReceived(TcpSocket* socket, TCP_HEADER* tcp, byte* buf, uint len)
|
|||
debug_printf("Tcp::Received From ");
|
||||
TinyIP::ShowIP(socket->RemoteIP);
|
||||
debug_printf(":%d with Payload=%d ", socket->RemotePort, len);
|
||||
Sys.ShowString(buf, len);
|
||||
debug_printf(" \r\n");
|
||||
String(buf, len).Show(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -74,8 +72,7 @@ bool HttpReceived(TcpSocket* socket, TCP_HEADER* tcp, byte* buf, uint len)
|
|||
debug_printf("HttpClient::Received From ");
|
||||
TinyIP::ShowIP(socket->RemoteIP);
|
||||
debug_printf(":%d with Payload=%d ", socket->RemotePort, len);
|
||||
Sys.ShowString(buf, len);
|
||||
debug_printf(" \r\n");
|
||||
String(buf, len).Show(true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -31,19 +31,12 @@ void OnReceive(void* param)
|
|||
uint len = nrf->Read(bs);
|
||||
if(len)
|
||||
{
|
||||
//Sys.ShowString(buf, len);
|
||||
//debug_printf("\r\n");
|
||||
bs.Show(true);
|
||||
}
|
||||
}
|
||||
|
||||
uint OnReceive(ITransport* transport, ByteArray& bs, void* param, void* param2)
|
||||
{
|
||||
/*if(len)
|
||||
{
|
||||
Sys.ShowString(buf, len);
|
||||
debug_printf("\r\n");
|
||||
}*/
|
||||
bs.Show(true);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
uint OnUsartRead(ITransport* transport, ByteArray& bs, void* param, void* param2)
|
||||
{
|
||||
debug_printf("收到:");
|
||||
//Sys.ShowString(buf, len);
|
||||
//debug_printf("\r\n");
|
||||
bs.Show(true);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -213,8 +213,7 @@ void TcpSocket::OnDataReceive(TCP_HEADER* tcp, uint len)
|
|||
debug_printf("Tcp Receive(%d) From ", len);
|
||||
TinyIP::ShowIP(RemoteIP);
|
||||
debug_printf(" : ");
|
||||
Sys.ShowString(tcp->Next(), len);
|
||||
debug_printf("\r\n");
|
||||
String(tcp->Next(), len).Show(true);
|
||||
#endif
|
||||
}
|
||||
// 发送ACK,通知已收到
|
||||
|
|
|
@ -87,8 +87,7 @@ bool IcmpSocket::Process(IP_HEADER& ip, Stream& ms)
|
|||
debug_printf(" Payload=%d ", len);
|
||||
// 越过2个字节标识和2字节序列号
|
||||
debug_printf("ID=0x%04X Seq=0x%04X ", __REV16(icmp->Identifier), __REV16(icmp->Sequence));
|
||||
Sys.ShowString(icmp->Next(), len);
|
||||
debug_printf(" \r\n");
|
||||
String(icmp->Next(), len).Show(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -235,8 +235,7 @@ void TcpSocket::OnDataReceive(TCP_HEADER& tcp, uint len)
|
|||
debug_printf("Tcp:Receive(%d) From ", len);
|
||||
Remote.Show();
|
||||
debug_printf(" ");
|
||||
Sys.ShowString(data, len);
|
||||
debug_printf("\r\n");
|
||||
String(data, len).Show(true);
|
||||
#endif
|
||||
}
|
||||
// 发送ACK,通知已收到
|
||||
|
|
|
@ -285,8 +285,7 @@ bool TinyIP::SendEthernet(ETH_TYPE type, const MacAddress& remote, const byte* b
|
|||
debug_printf(" => ");
|
||||
remote.Show();
|
||||
debug_printf("\r\n");*/
|
||||
/*Sys.ShowHex((byte*)eth->Next(), len, '-');
|
||||
debug_printf("\r\n");*/
|
||||
/*ByteArray((byte*)eth->Next(), len).Show(true);*/
|
||||
|
||||
ByteArray bs((byte*)eth, len);
|
||||
return _port->Write(bs);
|
||||
|
|
|
@ -99,8 +99,7 @@ void UdpSocket::OnProcess(IP_HEADER& ip, UDP_HEADER& udp, Stream& ms)
|
|||
CurLocal.Show();
|
||||
debug_printf(" Payload=%d udp_len=%d \r\n", len, __REV16(udp.Length));
|
||||
|
||||
Sys.ShowHex(data, len);
|
||||
debug_printf(" \r\n");
|
||||
ByteArray(data, len).Show(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +119,7 @@ void UdpSocket::SendPacket(UDP_HEADER& udp, uint len, IPAddress& ip, ushort port
|
|||
debug_printf("SendUdp: len=%d(0x%x) %d => ", tlen, tlen, __REV16(udp.SrcPort));
|
||||
ip.Show();
|
||||
debug_printf(":%d ", port);
|
||||
if(tlen > 0) Sys.ShowHex(udp.Next(), tlen > 64 ? 64 : tlen, false);
|
||||
if(tlen > 0) ByteArray(udp.Next(), tlen > 64 ? 64 : tlen).Show();
|
||||
debug_printf("\r\n");
|
||||
#else
|
||||
Sys.Sleep(1);
|
||||
|
|
|
@ -135,9 +135,7 @@ void TokenMessage::Show() const
|
|||
{
|
||||
assert_ptr(Data);
|
||||
debug_printf(" Data[%d]=", Length);
|
||||
//Sys.ShowHex(Data, Length, false);
|
||||
ByteArray bs(Data, Length);
|
||||
bs.Show();
|
||||
ByteArray(Data, Length).Show();
|
||||
}
|
||||
debug_printf("\r\n");
|
||||
#endif
|
||||
|
@ -223,8 +221,7 @@ bool TokenController::Valid(const Message& msg)
|
|||
#if MSG_DEBUG
|
||||
/*msg_printf("TokenController::Dispatch ");
|
||||
// 输出整条信息
|
||||
Sys.ShowHex(buf, ms.Length, '-');
|
||||
msg_printf("\r\n");*/
|
||||
ByteArray(buf, ms.Length).Show(true);*/
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
|
4
Type.h
4
Type.h
|
@ -472,8 +472,8 @@ public:
|
|||
String(int length = 0) : Array(length) { }
|
||||
String(char item, int count) : Array(count) { Set(item, 0, count); }
|
||||
// 因为使用外部指针,这里初始化时没必要分配内存造成浪费
|
||||
String(char* str, int len = 0) : Array(0) { Set(str, len); }
|
||||
String(const char* str, int len = 0) : Array(0) { Set(str, len); }
|
||||
String(void* str, int len = 0) : Array(0) { Set(str, len); }
|
||||
String(const void* str, int len = 0) : Array(0) { Set(str, len); }
|
||||
String(const String& str) : Array(str.Length()) { Copy(str); }
|
||||
|
||||
// 输出对象的字符串表示方式
|
||||
|
|
Loading…
Reference in New Issue