Compare commits

..

No commits in common. "features/translate" and "master" have entirely different histories.

2 changed files with 32 additions and 30 deletions

View File

@ -1,5 +1,4 @@
/* NBNS service client /* Klient sluzby NBNS
Pavel Brychta pablo@xpablo.cz
*/ */
#include "ESP8266NetBIOS.h" #include "ESP8266NetBIOS.h"
@ -25,65 +24,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
// NBNS query structure (at least things that I've discovered): // Definice struktury NBNS dotazu (alespon veci, ktere jsem vypozoroval):
struct NBNSQUESTION { struct NBNSQUESTION {
uint16_t NBNSQ_ID; // query ID uint16_t NBNSQ_ID; // ID dotazu
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; // following string length uint8_t NBNSQ_NAMESIZE; // delka nasledujiciho retezce
char NBNSQ_NAME[32+1]; // CAUTION!!! maybe this entry is not of constant length char NBNSQ_NAME[32+1]; // POZOR!!! mozna tato polozka muze byt ruzne dlouha
uint16_t NBNSQ_TYPE; uint16_t NBNSQ_TYPE;
uint16_t NBNSQ_CLASS; uint16_t NBNSQ_CLASS;
} __attribute__((packed)); } __attribute__((packed));
// NBNS response structure (again at least things that I've discovered) // Definice struktury NBNS odpovedi (stejne jako u dotazu)
struct NBNSANSWER { struct NBNSANSWER {
uint16_t NBNSA_ID; // query ID uint16_t NBNSA_ID; // ID dotazu
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; // length of the following string uint8_t NBNSA_NAMESIZE; // delka nasledujiciho retezce
char NBNSA_NAME[32 + 1]; // CAUTION!!! maybe this entry is not of constant length char NBNSA_NAME[32 + 1]; // POZOR!!! mozna tato polozka muze byt ruzne dlouha
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; // CAUTION!!! I'm really not sure about this uint16_t NBNSA_NODEFLAGS; // POZOR!!! tady si nejsem moc jisty
uint32_t NBNSA_NODEADDRESS; uint32_t NBNSA_NODEADDRESS;
} __attribute__((packed)); } __attribute__((packed));
// structure of NBNS response to name query // Definice struktury NBNS odpovedi na dotaz na jmeno
struct NBNSANSWERN { struct NBNSANSWERN {
uint16_t NBNSAN_ID; // query ID uint16_t NBNSAN_ID; // ID dotazu
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; // length of the following string uint8_t NBNSAN_NAMESIZE; // delka nasledujiciho retezce
char NBNSAN_NAME[32 + 1]; // CAUTION!!! maybe this entry is not of constant length char NBNSAN_NAME[32 + 1]; // POZOR!!! mozna tato polozka muze byt ruzne dlouha
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]; // node name char NBNSAN_NNAME[15]; // jmeno nodu
uint8_t NBNSAN_NTYPE; // type of name uint8_t NBNSAN_NTYPE; // typ jmena
uint16_t NBNSAN_NFLAGS; // node flags uint16_t NBNSAN_NFLAGS; // node flags
} __attribute__((packed)); } __attribute__((packed));
/** Method to get NETBIOS name encoding. /** Metoda pro ziskani jmena z kodovani NETBIOS.
* \param nbname Pointer to NETBIOS encoded name. * \param nbname Ukazatel na jmeno v NETBIOS kodovani.
* \param name Pointer where to decode the name. * \param name Ukazatel na misto, kam prevadime jmeno.
* \param maxlen Maximum of characters allowed in the nbname. * \param maxlen Maximalni pocet znaku v nbname.
*/ */
void ESP8266NetBIOS::_getnbname(char *nbname, char *name, uint8_t maxlen) void ESP8266NetBIOS::_getnbname(char *nbname, char *name, uint8_t maxlen)
{ {
@ -91,15 +90,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; // correct the nibble and move it to upper bits b = (*nbname++ - 'A') << 4; // opravime nibble a prevedeme ho do vyssich bitu
c++; // removed byte counter c++; // pocitame pocet odebranych bytu
if (*nbname != 0x0) { if (*nbname != 0x0) {
b |= *nbname++ - 'A'; // add lower nibble b |= *nbname++ - 'A'; // pridame nizsi nibble
c++; // again removed byte counter c++; // opet spocitame pocet odebranych znaku
} }
*name++ = b; // store decoded character and bump pointer *name++ = b; // ulozime znak do vysledku a posuneme ukazatel
} }
*name = 0x0; // store trailing zero (made C character string) *name = 0x0; // ulozime ukoncovaci 0
} }
/** Prevod zadaneho textu do NETBIOS kodovani /** Prevod zadaneho textu do NETBIOS kodovani

View File

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