58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
//
|
|
//
|
|
// Utility functions
|
|
//
|
|
//
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include "Utility.h"
|
|
|
|
static String macToStr(const uint8_t * mac, char padd = ':');
|
|
|
|
String GetMacString(char padd) {
|
|
unsigned char mac[6];
|
|
WiFi.macAddress(mac);
|
|
String clientMac(macToStr(mac, padd));
|
|
return clientMac;
|
|
}
|
|
|
|
static String macToStr(const uint8_t * mac, char padd) {
|
|
String result;
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
result += String(mac[i], 16);
|
|
if (i < 5) {
|
|
if (padd)
|
|
result += padd;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void HexDump(const char * title, const uint8_t * p, int count)
|
|
{
|
|
int i;
|
|
char buf[100] = "0000: ";
|
|
char asc[17] = " ";
|
|
|
|
if (*title) {
|
|
printf("%s [@%08X]\n", title, (uint32_t)p);
|
|
}
|
|
for (i=0; i<count; ) {
|
|
sprintf(buf + strlen(buf), "%02X ", *(p+i));
|
|
asc[i % 16] = isprint(*(p+i)) ? *(p+i) : '.';
|
|
if ((++i & 0x0F) == 0x00) {
|
|
printf("%-55s | %s |\n", buf, asc);
|
|
if (i < count) {
|
|
sprintf(buf, "%04X: ", i);
|
|
} else {
|
|
buf[0] = '\0';
|
|
asc[0] = '\0';
|
|
}
|
|
}
|
|
}
|
|
if (strlen(buf)) {
|
|
printf("%-55s | %s |\n", buf, asc);
|
|
}
|
|
}
|