mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-19 09:42:11 +03:00
WiFi API first draft
This commit is contained in:
78
WiFi/Server.cpp
Executable file
78
WiFi/Server.cpp
Executable file
@ -0,0 +1,78 @@
|
||||
#include <string.h>
|
||||
#include "HardwareSerial.h"
|
||||
#include "wifi_spi.h"
|
||||
#include "Server.h"
|
||||
#include "Client.h"
|
||||
#include "WiFi.h"
|
||||
#include "server_drv.h"
|
||||
#include "wiring.h"
|
||||
|
||||
Server::Server(uint16_t port)
|
||||
{
|
||||
_port = port;
|
||||
}
|
||||
|
||||
void Server::begin()
|
||||
{
|
||||
uint8_t _sock = WiFiClass::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::StartServer(_port, _sock);
|
||||
WiFiClass::_server_port[_sock] = _port;
|
||||
}
|
||||
}
|
||||
|
||||
Client Server::available(byte* status)
|
||||
{
|
||||
//accept();
|
||||
|
||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
||||
{
|
||||
if (WiFiClass::_server_port[sock] != 0)
|
||||
{
|
||||
Client client(sock);
|
||||
*status = client.status();
|
||||
|
||||
if (WiFiClass::_server_port[sock] == _port &&
|
||||
*status == ESTABLISHED)
|
||||
{
|
||||
return client; //TODO
|
||||
}else{
|
||||
delayMicroseconds(100);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return Client(255);
|
||||
}
|
||||
|
||||
void Server::write(uint8_t b)
|
||||
{
|
||||
write(&b, 1);
|
||||
}
|
||||
|
||||
void Server::write(const char *str)
|
||||
{
|
||||
write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
|
||||
void Server::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
||||
{
|
||||
if (WiFiClass::_server_port[sock] != 0)
|
||||
{
|
||||
Client client(sock);
|
||||
|
||||
if (WiFiClass::_server_port[sock] == _port &&
|
||||
client.status() == ESTABLISHED)
|
||||
{
|
||||
client.write(buffer, size);
|
||||
}else{
|
||||
delay(20);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user