Compare commits

..

1 Commits

Author SHA1 Message Date
e3d68e1b25 Translated partially 2018-05-06 21:52:40 +02:00
2 changed files with 30 additions and 32 deletions

View File

@ -1,4 +1,5 @@
/* Klient sluzby NBNS /* NBNS service client
Pavel Brychta pablo@xpablo.cz
*/ */
#include "ESP8266NetBIOS.h" #include "ESP8266NetBIOS.h"
@ -24,65 +25,65 @@ extern "C" {
#define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) )) #define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
#endif #endif
// Definice struktury NBNS dotazu (alespon veci, ktere jsem vypozoroval): // NBNS query structure (at least things that I've discovered):
struct NBNSQUESTION { struct NBNSQUESTION {
uint16_t NBNSQ_ID; // ID dotazu uint16_t NBNSQ_ID; // query ID
uint8_t NBNSQ_FLAGS1; uint8_t NBNSQ_FLAGS1;
uint8_t NBNSQ_FLAGS2; uint8_t NBNSQ_FLAGS2;
uint16_t NBNSQ_QUESTIONCOUNT; uint16_t NBNSQ_QUESTIONCOUNT;
uint16_t NBNSQ_ANSWERCOUNT; uint16_t NBNSQ_ANSWERCOUNT;
uint16_t NBNSQ_AUTHORITYCOUNT; uint16_t NBNSQ_AUTHORITYCOUNT;
uint16_t NBNSQ_ADDITIONALRECORDCOUNT; uint16_t NBNSQ_ADDITIONALRECORDCOUNT;
uint8_t NBNSQ_NAMESIZE; // delka nasledujiciho retezce uint8_t NBNSQ_NAMESIZE; // following string length
char NBNSQ_NAME[32+1]; // POZOR!!! mozna tato polozka muze byt ruzne dlouha char NBNSQ_NAME[32+1]; // CAUTION!!! maybe this entry is not of constant length
uint16_t NBNSQ_TYPE; uint16_t NBNSQ_TYPE;
uint16_t NBNSQ_CLASS; uint16_t NBNSQ_CLASS;
} __attribute__((packed)); } __attribute__((packed));
// Definice struktury NBNS odpovedi (stejne jako u dotazu) // NBNS response structure (again at least things that I've discovered)
struct NBNSANSWER { struct NBNSANSWER {
uint16_t NBNSA_ID; // ID dotazu uint16_t NBNSA_ID; // query ID
uint8_t NBNSA_FLAGS1; uint8_t NBNSA_FLAGS1;
uint8_t NBNSA_FLAGS2; uint8_t NBNSA_FLAGS2;
uint16_t NBNSA_QUESTIONCOUNT; uint16_t NBNSA_QUESTIONCOUNT;
uint16_t NBNSA_ANSWERCOUNT; uint16_t NBNSA_ANSWERCOUNT;
uint16_t NBNSA_AUTHORITYCOUNT; uint16_t NBNSA_AUTHORITYCOUNT;
uint16_t NBNSA_ADDITIONALRECORDCOUNT; uint16_t NBNSA_ADDITIONALRECORDCOUNT;
uint8_t NBNSA_NAMESIZE; // delka nasledujiciho retezce uint8_t NBNSA_NAMESIZE; // length of the following string
char NBNSA_NAME[32 + 1]; // POZOR!!! mozna tato polozka muze byt ruzne dlouha char NBNSA_NAME[32 + 1]; // CAUTION!!! maybe this entry is not of constant length
uint16_t NBNSA_TYPE; uint16_t NBNSA_TYPE;
uint16_t NBNSA_CLASS; uint16_t NBNSA_CLASS;
uint32_t NBNSA_TIMETOLIVE; uint32_t NBNSA_TIMETOLIVE;
uint16_t NBNSA_LENGTH; uint16_t NBNSA_LENGTH;
uint16_t NBNSA_NODEFLAGS; // POZOR!!! tady si nejsem moc jisty uint16_t NBNSA_NODEFLAGS; // CAUTION!!! I'm really not sure about this
uint32_t NBNSA_NODEADDRESS; uint32_t NBNSA_NODEADDRESS;
} __attribute__((packed)); } __attribute__((packed));
// Definice struktury NBNS odpovedi na dotaz na jmeno // structure of NBNS response to name query
struct NBNSANSWERN { struct NBNSANSWERN {
uint16_t NBNSAN_ID; // ID dotazu uint16_t NBNSAN_ID; // query ID
uint8_t NBNSAN_FLAGS1; uint8_t NBNSAN_FLAGS1;
uint8_t NBNSAN_FLAGS2; uint8_t NBNSAN_FLAGS2;
uint16_t NBNSAN_QUESTIONCOUNT; uint16_t NBNSAN_QUESTIONCOUNT;
uint16_t NBNSAN_ANSWERCOUNT; uint16_t NBNSAN_ANSWERCOUNT;
uint16_t NBNSAN_AUTHORITYCOUNT; uint16_t NBNSAN_AUTHORITYCOUNT;
uint16_t NBNSAN_ADDITIONALRECORDCOUNT; uint16_t NBNSAN_ADDITIONALRECORDCOUNT;
uint8_t NBNSAN_NAMESIZE; // delka nasledujiciho retezce uint8_t NBNSAN_NAMESIZE; // length of the following string
char NBNSAN_NAME[32 + 1]; // POZOR!!! mozna tato polozka muze byt ruzne dlouha char NBNSAN_NAME[32 + 1]; // CAUTION!!! maybe this entry is not of constant length
uint16_t NBNSAN_TYPE; uint16_t NBNSAN_TYPE;
uint16_t NBNSAN_CLASS; uint16_t NBNSAN_CLASS;
uint32_t NBNSAN_TIMETOLIVE; uint32_t NBNSAN_TIMETOLIVE;
uint16_t NBNSAN_LENGTH; uint16_t NBNSAN_LENGTH;
uint8_t NBNSAN_NUMBER; // number of names uint8_t NBNSAN_NUMBER; // number of names
char NBNSAN_NNAME[15]; // jmeno nodu char NBNSAN_NNAME[15]; // node name
uint8_t NBNSAN_NTYPE; // typ jmena uint8_t NBNSAN_NTYPE; // type of name
uint16_t NBNSAN_NFLAGS; // node flags uint16_t NBNSAN_NFLAGS; // node flags
} __attribute__((packed)); } __attribute__((packed));
/** Metoda pro ziskani jmena z kodovani NETBIOS. /** Method to get NETBIOS name encoding.
* \param nbname Ukazatel na jmeno v NETBIOS kodovani. * \param nbname Pointer to NETBIOS encoded name.
* \param name Ukazatel na misto, kam prevadime jmeno. * \param name Pointer where to decode the name.
* \param maxlen Maximalni pocet znaku v nbname. * \param maxlen Maximum of characters allowed in the nbname.
*/ */
void ESP8266NetBIOS::_getnbname(char *nbname, char *name, uint8_t maxlen) void ESP8266NetBIOS::_getnbname(char *nbname, char *name, uint8_t maxlen)
{ {
@ -90,15 +91,15 @@ void ESP8266NetBIOS::_getnbname(char *nbname, char *name, uint8_t maxlen)
uint8_t c = 0; uint8_t c = 0;
while ((*nbname != 0x0) && (c < maxlen)) { while ((*nbname != 0x0) && (c < maxlen)) {
b = (*nbname++ - 'A') << 4; // opravime nibble a prevedeme ho do vyssich bitu b = (*nbname++ - 'A') << 4; // correct the nibble and move it to upper bits
c++; // pocitame pocet odebranych bytu c++; // removed byte counter
if (*nbname != 0x0) { if (*nbname != 0x0) {
b |= *nbname++ - 'A'; // pridame nizsi nibble b |= *nbname++ - 'A'; // add lower nibble
c++; // opet spocitame pocet odebranych znaku c++; // again removed byte counter
} }
*name++ = b; // ulozime znak do vysledku a posuneme ukazatel *name++ = b; // store decoded character and bump pointer
} }
*name = 0x0; // ulozime ukoncovaci 0 *name = 0x0; // store trailing zero (made C character string)
} }
/** Prevod zadaneho textu do NETBIOS kodovani /** Prevod zadaneho textu do NETBIOS kodovani
@ -174,7 +175,7 @@ void ESP8266NetBIOS::end()
} }
} }
#if LWIP_VERSION_MAJOR == 1 #if LWIP_VERSION_MAJOR == 1
void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, ip_addr_t *addr, uint16_t port) void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, ip_addr_t *addr, uint16_t port)
#else #else
void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port) void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port)

View File

@ -6,14 +6,11 @@ const char* ssid = "............";
const char* password = ".............."; const char* password = "..............";
ESP8266WebServer wwwserver(80); ESP8266WebServer wwwserver(80);
String content; const char PAGE[] PROGMEM = "<!DOCTYPE HTML>\n<html>Hello world from ESP8266<p></html>"
static void handleRoot(void) { static void handleRoot(void) {
content = F("<!DOCTYPE HTML>\n<html>Hello world from ESP8266");
content += F("<p>");
content += F("</html>");
wwwserver.send(200, F("text/html"), content); wwwserver.send_P(200, F("text/html"), PAGE);
} }
void setup() { void setup() {