From 3ae2e4d56088ff748c4904fcfb8356903c4ec3f4 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 29 Apr 2020 18:26:05 +0100 Subject: [PATCH] New dump function in Util, removal of old --- inputudp.cc | 147 ------------------------------------------- util.cc | 31 +++++++++ util.h | 2 +- vdrresponsepacket.cc | 6 +- 4 files changed, 37 insertions(+), 149 deletions(-) diff --git a/inputudp.cc b/inputudp.cc index 6b26064..6b70778 100644 --- a/inputudp.cc +++ b/inputudp.cc @@ -163,150 +163,3 @@ std::string InputUDP::getHardwareKeyName(HWC_TYPE /* hardwareKey */) std::string retval; return retval; } - - - - - - -/* - -//void dump(unsigned char* data, USHORT size); -//unsigned char dcc(UCHAR c); - -void dump(unsigned char* data, USHORT size) -{ - printf("Size = %u\n", size); - - USHORT c = 0; - while(c < size) - { - if ((size - c) > 15) - { - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], data[c+15], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]), dcc(data[c+14]), dcc(data[c+15])); - c += 16; - } - else - { - switch (size - c) - { - case 15: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], data[c+14], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13]), dcc(data[c+14])); - c += 15; - break; - case 14: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], data[c+13], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12]), dcc(data[c+13])); - c += 14; - break; - case 13: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], data[c+10], data[c+11], data[c+12], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11]), dcc(data[c+12])); - c += 13; - break; - case 12: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], data[c+10], data[c+11], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10]), dcc(data[c+11])); - c += 12; - break; - case 11: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], data[c+10], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9]), dcc(data[c+10])); - c += 11; - break; - case 10: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], data[c+9], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8]), dcc(data[c+9])); - c += 10; - break; - case 9: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - data[c+8], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7]), - dcc(data[c+8])); - c += 9; - break; - case 8: - printf(" %02X %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], data[c+7], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6]), dcc(data[c+7])); - c += 8; - break; - case 7: - printf(" %02X %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], data[c+6], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5]), dcc(data[c+6])); - c += 7; - break; - case 6: - printf(" %02X %02X %02X %02X %02X %02X %c%c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], data[c+5], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4]), dcc(data[c+5])); - c += 6; - break; - case 5: - printf(" %02X %02X %02X %02X %02X %c%c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], data[c+4], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3]), dcc(data[c+4])); - c += 5; - break; - case 4: - printf(" %02X %02X %02X %02X %c%c%c%c\n", - data[c], data[c+1], data[c+2], data[c+3], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2]), dcc(data[c+3])); - c += 4; - break; - case 3: - printf(" %02X %02X %02X %c%c%c\n", - data[c], data[c+1], data[c+2], - dcc(data[c]), dcc(data[c+1]), dcc(data[c+2])); - c += 3; - break; - case 2: - printf(" %02X %02X %c%c\n", - data[c], data[c+1], - dcc(data[c]), dcc(data[c+1])); - c += 2; - break; - case 1: - printf(" %02X %c\n", - data[c], - dcc(data[c])); - c += 1; - break; - } - } - } -} - -unsigned char dcc(UCHAR c) -{ - if (isspace(c)) return ' '; - if (isprint(c)) return c; - return '.'; -} -*/ diff --git a/util.cc b/util.cc index 550de1f..8d53208 100644 --- a/util.cc +++ b/util.cc @@ -18,7 +18,10 @@ */ #include +#include #include +#include +#include #ifdef WIN32 #include @@ -51,6 +54,34 @@ std::string tp2str(const std::chrono::time_point& tp) return ss.str(); } +void dump(void* vdata, int remaining) +{ + UCHAR* data = reinterpret_cast(vdata); + int pos{}, ntp, spaces; + std::stringstream ascii; + + while(remaining) + { + ascii.str(std::string()); + ntp = 16; + if (ntp > remaining) ntp = remaining; + std::cout << " " << std::hex << std::setfill('0'); + for (int i = 0; i < ntp; i++) + { + std::cout << std::setw(2) << int(data[pos + i]) << " " << (i == 7 ? " " : ""); + if (std::isspace(data[pos + i])) ascii << " "; + else if (std::isprint(data[pos + i])) ascii << data[pos + i]; + else ascii << '.'; + } + spaces = (16 - ntp) * 3 + 3; + if (ntp < 8) spaces += 2; + std::cout << std::setfill(' ') << std::setw(spaces) << "" << ascii.str() << std::endl; + pos += ntp; + remaining -= ntp; + } + std::cout << std::endl << std::endl; +} + /* ULLONG htonll(ULLONG a) { diff --git a/util.h b/util.h index 6701048..b4a9153 100644 --- a/util.h +++ b/util.h @@ -27,7 +27,7 @@ void MILLISLEEP(ULONG a); std::string tp2str(const std::chrono::time_point& tp); - +void dump(void* data, int length); //ULLONG htonll(ULLONG a); //ULLONG ntohll(ULLONG a); diff --git a/vdrresponsepacket.cc b/vdrresponsepacket.cc index 26e2302..83713c1 100644 --- a/vdrresponsepacket.cc +++ b/vdrresponsepacket.cc @@ -18,10 +18,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +// FIXME + #include "vdrresponsepacket.h" #include "vdr.h" +#include "util.h" + VDR_ResponsePacket::VDR_ResponsePacket() { userDataLength = 0; @@ -68,7 +72,7 @@ bool VDR_ResponsePacket::end() void VDR_ResponsePacket::dumpUD() { - // FIXME TODO - use generic stdout hex printer for userData, userDataLength + dump(userData, userDataLength); } int VDR_ResponsePacket::serverError() -- 2.39.5