1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-29 18:52:13 +01:00

Avoid to print Warning Messages on Arduino monitor.

Add debug command on wifi shield to enable debug msgs.
Solved issue on repeat quick refresh or stop and go web server
This commit is contained in:
Mimmo La Fauci 2012-02-10 00:49:42 +01:00
parent 4558c021b7
commit fa9393f7c4
6 changed files with 67 additions and 64 deletions

View File

@ -1,8 +1,6 @@
#include "wifi_drv.h"
#include "WiFi.h"
#define _DEBUG_
extern "C" {
#include "utility/wl_definitions.h"
#include "utility/wl_types.h"
@ -101,6 +99,7 @@ int WiFiClass::begin(char* ssid, const char *passphrase)
{
delay(WL_DELAY_START_CONNECTION);
status = WiFiDrv::getConnectionStatus();
INFO("Status: %d", status);
}
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
}else{

View File

@ -52,25 +52,29 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
}
size_t WiFiClient::write(uint8_t b) {
if (_sock != 255)
{
START();
ServerDrv::sendData(_sock, &b, 1);
while (!ServerDrv::isDataSent(_sock));
END();
return 1;
}
return 0;
return write(&b, 1);
}
size_t WiFiClient::write(const uint8_t *buf, size_t size) {
if (_sock != 255)
if (_sock >= MAX_SOCK_NUM)
{
ServerDrv::sendData(_sock, buf, size);
while (!ServerDrv::isDataSent(_sock));
return size;
setWriteError();
return 0;
}
return 0;
if (size==0)
{
setWriteError();
return 0;
}
if ((!ServerDrv::sendData(_sock, buf, size)) ||
(!ServerDrv::checkDataSent(_sock)))
{
setWriteError();
return 0;
}
return size;
}
int WiFiClient::available() {
@ -86,6 +90,7 @@ int WiFiClient::read() {
uint8_t b;
if (!available())
return -1;
ServerDrv::getData(_sock, &b);
return b;
}
@ -109,7 +114,6 @@ void WiFiClient::flush() {
void WiFiClient::stop() {
INFO("1)Stop WiFi client sock:%d state:%d status:%d", _sock, WiFiClass::_state[_sock], status());
if (_sock == 255)
return;
@ -121,24 +125,16 @@ void WiFiClient::stop() {
while (status() != CLOSED && millis() - start < 1000)
delay(1);
// if it hasn't closed, close it forcefully
if (status() != CLOSED)
{
//TODO force close
//close(_sock);
}
INFO("2)Stop WiFi client sock:%d state:%d status:%d", _sock, WiFiClass::_state[_sock], status());
_sock = 255;
}
uint8_t WiFiClient::connected() {
if (_sock == 255) {
return 0;
} else {
uint8_t s = status();
INFO("Client status: %d", s);
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 || s == FIN_WAIT_2 ||
(s == CLOSE_WAIT && !available()));
}

View File

@ -9,8 +9,6 @@ extern "C" {
#include "WiFiClient.h"
#include "WiFiServer.h"
WiFiServer::WiFiServer(uint16_t port)
{
_port = port;
@ -28,10 +26,8 @@ void WiFiServer::begin()
WiFiClient WiFiServer::available(byte* status)
{
//accept();
static byte tmp_cli_status = 0;
static byte tmp_ser_status = 0;
static int cycle = 0;
static int cycle_server_down = 0;
const int TH_SERVER_DOWN = 50;
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
{
@ -40,21 +36,16 @@ WiFiClient WiFiServer::available(byte* status)
WiFiClient client(sock);
uint8_t _status = client.status();
uint8_t _ser_status = this->status();
if ((tmp_cli_status != _status)||(tmp_ser_status != _ser_status))
{
INFO("%d)Sock: %d Client Status: %d Server Status: %d port: %d", cycle, sock, _status, _ser_status, WiFiClass::_server_port[sock]);
tmp_cli_status = _status;
tmp_ser_status = _ser_status;
cycle = 0;
}else{
++cycle;
}
if (status != NULL)
*status = _status;
//server not in listen state, restart it
if (this->status()==0)
if ((_ser_status == 0)&&(cycle_server_down++ > TH_SERVER_DOWN))
{
ServerDrv::startServer(_port, sock);
cycle_server_down = 0;
}
if (_status == ESTABLISHED)
{

View File

@ -52,9 +52,13 @@
#define INFO(format, args...) do {} while(0);
#endif
#if 0
#define WARN(args) do { PRINT_FILE_LINE() \
Serial.print("-W-"); Serial.println(args); \
}while (0);
#else
#define WARN(args) do {} while (0);
#endif
#define DBG_PIN2 5
#define DBG_PIN 4
@ -65,9 +69,9 @@
#define RST_TRIGGER() digitalWrite(DBG_PIN, LOW);
#define INIT_TRIGGER() pinMode(DBG_PIN, OUTPUT); \
pinMode(DBG_PIN2, OUTPUT); \
pinMode(DBG_PIN2, OUTPUT); \
RST_TRIGGER()
#define TOGGLE_TRIGGER() SET_TRIGGER() \
#define TOGGLE_TRIGGER() SET_TRIGGER() \
delayMicroseconds(2); \
RST_TRIGGER()

View File

@ -3,8 +3,6 @@
#include "Arduino.h"
#include "spi_drv.h"
#define _DEBUG_
extern "C" {
#include "wl_types.h"
#include "debug.h"
@ -223,26 +221,41 @@ bool ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
}
uint8_t ServerDrv::isDataSent(uint8_t sock)
uint8_t ServerDrv::checkDataSent(uint8_t sock)
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1);
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
const uint16_t TIMEOUT_DATA_SENT = 250;
static uint16_t timeout = 0;
uint8_t _data = 0;
uint8_t _dataLen = 0;
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
do {
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1);
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
if (!SpiDrv::waitResponseCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse isDataSent");
}
SpiDrv::spiSlaveDeselect();
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
return _data;
// Wait for reply
if (!SpiDrv::waitResponseCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse isDataSent");
}
SpiDrv::spiSlaveDeselect();
if (_data) timeout = 0;
else{
++timeout;
if (timeout > TIMEOUT_DATA_SENT)
{
timeout = 0;
INFO1("Timeout wainting for data sent");
}
}
}while((_data==0)&&(timeout<TIMEOUT_DATA_SENT));
return (timeout==TIMEOUT_DATA_SENT)?0:1;
}
ServerDrv serverDrv;

View File

@ -26,7 +26,7 @@ public:
static uint8_t availData(uint8_t sock);
static uint8_t isDataSent(uint8_t sock);
static uint8_t checkDataSent(uint8_t sock);
};
extern ServerDrv serverDrv;