1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-19 08:52:15 +01:00

Bugfix and fix compilation erro with new-extensions branch

This commit is contained in:
mlafauci 2011-05-18 08:39:47 +02:00
parent 8d1761f009
commit 4f7e2f1201
12 changed files with 144 additions and 29 deletions

View File

@ -3,6 +3,7 @@ extern "C" {
#include "utility/wl_types.h"
#include "socket.h"
#include "string.h"
#include "utility/debug.h"
}
#include "WProgram.h"
@ -35,25 +36,28 @@ uint8_t Client::connect() {
void Client::write(uint8_t b) {
if (_sock != 255)
{
while (!ServerDrv::isDataSent(_sock));
START();
ServerDrv::sendData(_sock, &b, 1);
while (!ServerDrv::isDataSent(_sock));
END();
}
}
void Client::write(const char *str) {
if (_sock != 255)
{
while (!ServerDrv::isDataSent(_sock));
unsigned int len = strlen(str);
ServerDrv::sendData(_sock, (const uint8_t *)str, len);
while (!ServerDrv::isDataSent(_sock));
}
}
void Client::write(const uint8_t *buf, size_t size) {
if (_sock != 255)
{
while (!ServerDrv::isDataSent(_sock));
ServerDrv::sendData(_sock, buf, size);
while (!ServerDrv::isDataSent(_sock));
}
}

View File

@ -66,10 +66,7 @@ void Server::write(const uint8_t *buffer, size_t size)
client.status() == ESTABLISHED)
{
client.write(buffer, size);
}else{
delay(20);
}
}
}
}

View File

@ -191,5 +191,11 @@ uint8_t WiFiClass::status()
return WiFiDrv::getConnectionStatus();
}
uint8_t WiFiClass::test()
{
return WiFiDrv::testCmd();
}
WiFiClass WiFi;

View File

@ -86,6 +86,9 @@ public:
// Return Connection status
uint8_t status();
// function used for test
uint8_t test();
friend class Client;
friend class Server;
};

View File

@ -10,6 +10,7 @@
*/
#include <WiFi.h>
#include <IPAddress.h>
#define _PRINT_
byte mac[6] = { 0 };
IPAddress ip;
@ -103,11 +104,13 @@ int startWiFiWpa()
{
Serial.println("\nSetup WiFi Wpa...");
//strcpy(ssid, "AndroidAP9647");
//strcpy(ssid, "AndroidAP3551");
strcpy(ssid, "Cariddi");
Serial.print("SSID: ");
Serial.println(ssid);
const char *pass = "1234567890";
status = WiFi.begin(ssid, pass);
//status = WiFi.begin(ssid);
if ( status != WL_CONNECTED)
{
Serial.println("Connection Failed");
@ -146,9 +149,12 @@ void setup()
void execCmd(char* buf)
{
#ifdef _PRINT_
Serial.print("\nExecuting command: ");
Serial.println(buf);
server.write(buf);
#endif
//server.write(buf);
server.print(buf);
}
@ -166,12 +172,18 @@ void loop()
}
static byte idx = 0;
int c = 0;
while (client.available())
do
{
dataBuf[idx] = client.read();
c = client.read();
if (c!=-1)
{
dataBuf[idx] = c;
#ifdef _PRINT_
if (idx == 0) Serial.print("Client chatting...: ");
Serial.print(dataBuf[idx]);
#endif
if ((dataBuf[idx] == 0xa)/*||(dataBuf[idx] == 0xd)*/)
{
dataBuf[idx+1]=0;
@ -181,7 +193,8 @@ void loop()
}else{
++idx;
}
}
}
}while (c!=-1);
}
}
}

View File

@ -114,12 +114,12 @@ void setup()
{
Serial.begin(9600);
Serial.println("*** Start WiFi example ***");
WiFi.begin();
//scanNetworks();
delay(3000);
int _status = startWiFi();
//int _status = startWiFi();
/*
if ( _status == WL_CONNECTED)
{
Serial.println("Wifi Connected!");
@ -129,17 +129,53 @@ void setup()
printCurrNet();
scanNetworks();
/*
Serial.println("Starting server...");
server.begin();
delay(1000);
*/
}
*/
}
void loop()
{
static boolean free = false;
// if (free) Serial.println(WiFi.test(),10);
if (free) WiFi.test();
byte c = Serial.read();
if (c!=255)
{
switch (c)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
{
int i = 0;
for (;i<(c-0x30);++i)
{
int num = WiFi.test();
//Serial.println(num,10);
}
break;
}
case 'c':
free = true;
break;
case 's':
free = false;
break;
}
}
/*
Client client = server.available();
static uint8_t count = 0;
Serial.println("Retry connect...");
status = WiFi.begin(ssid);

View File

@ -13,8 +13,6 @@
#include <stdio.h>
#include <string.h>
#include "HardwareSerial.h"
#define INFO_0 1
#define INFO_1 2
#define INFO_2 4

View File

@ -12,7 +12,8 @@ extern "C" {
#define SPICLOCK 13//sck
#define SLAVESELECT 2//ss
#define SLAVEREADY 3
#define DELAY_100NS asm volatile("nop")
void SpiDrv::begin()
{
@ -60,6 +61,16 @@ void SpiDrv::spiSlaveDeselect()
digitalWrite(SLAVESELECT,HIGH);
}
void delaySpi()
{
int i = 0;
const int DELAY = 1000;
for (;i<DELAY;++i)
{
int a =a+1;
}
}
char SpiDrv::spiTransfer(volatile char data)
{
SPDR = data; // Start the transmission
@ -67,7 +78,9 @@ char SpiDrv::spiTransfer(volatile char data)
{
};
char result = SPDR;
delayMicroseconds(SPI_TX_DELAY);
DELAY_100NS;
DELAY_100NS;
//delayMicroseconds(SPI_TX_DELAY);
return result; // return the received byte
}
@ -104,14 +117,18 @@ int SpiDrv::waitSpiChar(unsigned char waitChar)
int SpiDrv::readAndCheckChar(char checkChar, char* readChar)
{
*readChar = spiTransfer(DUMMY_DATA); //get data byte
//*readChar = spiTransfer(DUMMY_DATA); //get data byte
getParam((uint8_t*)readChar);
return (*readChar == checkChar);
}
char SpiDrv::readChar()
{
return spiTransfer(DUMMY_DATA); //get data byte
uint8_t readChar = 0;
getParam(&readChar);
return readChar;
//return spiTransfer(DUMMY_DATA); //get data byte
}
//#define WAIT_START_CMD(x) waitSpiChar(START_CMD, &x)
@ -130,18 +147,37 @@ char SpiDrv::readChar()
#define CHECK_DATA(check, x) \
if (!readAndCheckChar(check, &x)) \
{ \
TOGGLE_TRIGGER() \
WARN("Reply error"); \
INFO2(check, (uint8_t)x); \
return 0; \
}else \
#define waitSlaveReady() (digitalRead(SLAVEREADY) == LOW)
#define waitSlaveSign() (digitalRead(SLAVEREADY) == HIGH)
#define waitSlaveSignalH() while(digitalRead(SLAVEREADY) != HIGH){}
#define waitSlaveSignalL() while(digitalRead(SLAVEREADY) != LOW){}
void SpiDrv::waitForSlaveSign()
{
while (!waitSlaveSign());
}
void SpiDrv::waitForSlaveReady()
{
while (!waitSlaveReady());
}
void SpiDrv::getParam(uint8_t* param)
{
// Get Params data
*param = spiTransfer(DUMMY_DATA);
DELAY_100NS;
DELAY_100NS;
DELAY_100NS;
DELAY_100NS;
}
int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len)
{
char _data = 0;
@ -157,7 +193,8 @@ int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8
for (ii=0; ii<(*param_len); ++ii)
{
// Get Params data
param[ii] = spiTransfer(DUMMY_DATA);
//param[ii] = spiTransfer(DUMMY_DATA);
getParam(&param[ii]);
}
}
@ -470,6 +507,7 @@ void SpiDrv::sendCmd(uint8_t cmd, uint8_t numParam)
// Send Spi START CMD
spiTransfer(START_CMD);
//waitForSlaveSign();
//wait the interrupt trigger on slave
delayMicroseconds(SPI_START_CMD_DELAY);

View File

@ -4,12 +4,7 @@
#include <inttypes.h>
#include "wifi_spi.h"
#define WAIT_CHAR_DELAY 100
#define TIMEOUT_CHAR_DELAY 1 //10
#define TIMEOUT_READY_SLAVE 1000
#define SPI_TX_DELAY 1
#define SPI_START_CMD_DELAY 10
#define SPI_START_CMD_DELAY 10
#define NO_LAST_PARAM 0
#define LAST_PARAM 1
@ -25,7 +20,9 @@
class SpiDrv
{
private:
static bool waitSlaveReady();
//static bool waitSlaveReady();
static void waitForSlaveSign();
static void getParam(uint8_t* param);
public:
static void begin();

View File

@ -351,4 +351,25 @@ int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem)
return networkRssi;
}
uint8_t WiFiDrv::testCmd()
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(TEST_CMD, PARAM_NUMS_0);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
SpiDrv::waitResponseCmd(TEST_CMD, PARAM_NUMS_1, &_data, &_dataLen);
SpiDrv::spiSlaveDeselect();
return _data;
}
WiFiDrv wiFiDrv;

View File

@ -62,6 +62,7 @@ public:
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
static uint8_t testCmd();
};
extern WiFiDrv wiFiDrv;

View File

@ -23,6 +23,7 @@ enum {
SET_NET_CMD = 0x10,
SET_PASSPHRASE_CMD = 0x11,
SET_KEY_CMD = 0x12,
TEST_CMD = 0x13,
GET_CONN_STATUS_CMD = 0x20,
GET_IPADDR_CMD = 0x21,