static void http_loop(word pos) { const char *request = (const char *)ether.buffer + pos; BufferFiller response = ether.tcpOffset(); // Process the request and build the response. process_http_request(request, response); // Send the response to the client. ether.httpServerReply(response.position()); }
static uint16_t homePage() { long t = millis() / 1000; word h = t / 3600; byte m = (t / 60) % 60; byte s = t % 60; bfill = ether.tcpOffset(); bfill.emit_p(PSTR( "HTTP/1.0 200 OK\r\n" "Content-Type: text/html\r\n" "Pragma: no-cache\r\n" "\r\n" "<meta http-equiv='refresh' content='1'/>" "<title>RBBB server</title>" "<h1>$D$D:$D$D:$D$D</h1>"), h/10, h%10, m/10, m%10, s/10, s%10); return bfill.position(); }
static word serverRequestTemperature(byte fd) { // filling state uint8_t data[16] = {0}; // 16 bytes block for encryption, which have to be send in hex data[0] = uint8_t(uint32_t(sharedState->currentTemperature)); // whole part data[1] = uint8_t(uint32_t(sharedState->currentTemperature * 100) % 100); // fraction part *(uint32_t*)(data + (16 - sizeof(uint32_t))) = sharedState->lastNonce; sharedState->lastNonce += 1; // encrypting the state aes128_enc_single(encKey, data); printlnDebug("Sending encrypted state"); BufferFiller bfill = ether.tcpOffset(); bfill.emit_p(sendTemperatureHeader); bfill.emit_raw((char*)data, sizeof(data)); temperatureSend = 1; sendEaseTime = millis() + SENDINGEASE; return bfill.position(); }
void ModbusIP::task() { word len = ether.packetReceive(); word pos = ether.packetLoop(len); if (pos) { int i = 0; while (i < 7) { _MBAP[i] = Ethernet::buffer[pos+i]; i++; } _len = _MBAP[4] << 8 | _MBAP[5]; _len--; // Do not count with last byte from MBAP if (_MBAP[2] !=0 | _MBAP[3] !=0) return; //Not a MODBUSIP packet if (_len > MODBUSIP_MAXFRAME) return; //Length is over MODBUSIP_MAXFRAME _frame = (byte*) malloc(_len); i = 0; while (i < _len){ _frame[i] = Ethernet::buffer[pos+7+i]; //Forget MBAP and take just modbus pdu i++; } this->receivePDU(_frame); if (_reply != MB_REPLY_OFF) { //MBAP _MBAP[4] = _len >> 8; _MBAP[5] = _len | 0x00FF; BufferFiller bfill = ether.tcpOffset(); bfill.emit_raw((const char *)_MBAP, 7); bfill.emit_raw((const char *)_frame, _len); ether.httpServerReply(bfill.position()); } free(_frame); _len = 0; }
strbuf++; } *strbuf='\0'; } // return the length of the value if (keyfound) *keyfound = found; return(i); } void rewind_ether_buffer() { bfill = ether.tcpOffset(); } void send_packet(bool final=false) { if(final) { ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V|TCP_FLAGS_FIN_V); } else { ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V); bfill=ether.tcpOffset(); } } /* Check available space (number of bytes) in the Ethernet buffer */ int available_ether_buffer() { return ETHER_BUFFER_SIZE - (int)bfill.position(); } #else void print_html_standard_header() { m_client->write((const uint8_t *)html200OK, strlen(html200OK)); m_client->write((const uint8_t *)htmlContentHTML, strlen(htmlContentHTML));
void WebServer::_respond(char command, char value) { BufferFiller bufferfill; bufferfill = ether.tcpOffset(); _responder(bufferfill, command, value); ether.httpServerReply(bufferfill.position()); }