1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Adding SPI library and revising Ethernet library (Christian Maglie).

This commit is contained in:
David A. Mellis
2010-08-02 18:59:44 +00:00
parent 78e093b482
commit e24b135755
24 changed files with 1429 additions and 2524 deletions

View File

@ -1,13 +1,12 @@
#include "w5100.h"
#include "socket.h"
extern "C" {
#include "types.h"
#include "w5100.h"
#include "socket.h"
#include "string.h"
#include "string.h"
}
#include "Ethernet.h"
#include "Client.h"
#include "Server.h"
#include "ethernet.h"
#include "client.h"
#include "server.h"
Server::Server(uint16_t port)
{
@ -18,8 +17,8 @@ void Server::begin()
{
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
Client client(sock);
if (client.status() == SOCK_CLOSED) {
socket(sock, Sn_MR_TCP, _port, 0);
if (client.status() == SnSR::CLOSED) {
socket(sock, SnMR::TCP, _port, 0);
listen(sock);
EthernetClass::_server_port[sock] = _port;
break;
@ -30,19 +29,20 @@ void Server::begin()
void Server::accept()
{
int listening = 0;
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
Client client(sock);
if (EthernetClass::_server_port[sock] == _port) {
if (client.status() == SOCK_LISTEN) {
if (client.status() == SnSR::LISTEN) {
listening = 1;
} else if (client.status() == SOCK_CLOSE_WAIT && !client.available()) {
}
else if (client.status() == SnSR::CLOSE_WAIT && !client.available()) {
client.stop();
}
}
}
if (!listening) {
begin();
}
@ -51,19 +51,19 @@ void Server::accept()
Client Server::available()
{
accept();
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
Client client(sock);
if (EthernetClass::_server_port[sock] == _port &&
client.status() == SOCK_ESTABLISHED) {
client.status() == SnSR::ESTABLISHED) {
if (client.available()) {
// XXX: don't always pick the lowest numbered socket.
return client;
}
}
}
return Client(255);
return Client();
}
void Server::write(uint8_t b)
@ -79,12 +79,12 @@ void Server::write(const char *str)
void Server::write(const uint8_t *buffer, size_t size)
{
accept();
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
Client client(sock);
if (EthernetClass::_server_port[sock] == _port &&
client.status() == SOCK_ESTABLISHED) {
client.status() == SnSR::ESTABLISHED) {
client.write(buffer, size);
}
}