2011-03-08 22:13:54 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2011-05-18 15:37:29 +02:00
|
|
|
#include "Arduino.h"
|
2011-03-08 22:13:54 +01:00
|
|
|
#include "spi_drv.h"
|
|
|
|
#include "wifi_drv.h"
|
|
|
|
|
|
|
|
#define _DEBUG_
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "wifi_spi.h"
|
|
|
|
#include "wl_types.h"
|
|
|
|
#include "debug.h"
|
|
|
|
}
|
|
|
|
|
2012-03-07 00:05:54 +01:00
|
|
|
// Array of data to cache the information related to the networks discovered
|
2011-04-05 23:24:17 +02:00
|
|
|
char WiFiDrv::_networkSsid[][WL_SSID_MAX_LENGTH] = {{"1"},{"2"},{"3"},{"4"},{"5"}};
|
2012-03-04 11:42:48 +01:00
|
|
|
int32_t WiFiDrv::_networkRssi[WL_NETWORKS_LIST_MAXNUM] = { 0 };
|
|
|
|
uint8_t WiFiDrv::_networkEncr[WL_NETWORKS_LIST_MAXNUM] = { 0 };
|
|
|
|
|
2012-03-07 00:05:54 +01:00
|
|
|
// Cached values of retrieved data
|
2011-03-08 22:13:54 +01:00
|
|
|
char WiFiDrv::_ssid[] = {0};
|
|
|
|
uint8_t WiFiDrv::_bssid[] = {0};
|
|
|
|
uint8_t WiFiDrv::_mac[] = {0};
|
|
|
|
uint8_t WiFiDrv::_localIp[] = {0};
|
|
|
|
uint8_t WiFiDrv::_subnetMask[] = {0};
|
|
|
|
uint8_t WiFiDrv::_gatewayIp[] = {0};
|
|
|
|
|
|
|
|
|
|
|
|
// Private Methods
|
|
|
|
|
|
|
|
void WiFiDrv::getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip)
|
|
|
|
{
|
|
|
|
tParam params[PARAM_NUMS_3] = { {0, (char*)ip}, {0, (char*)mask}, {0, (char*)gwip}};
|
|
|
|
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_IPADDR_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, sizeof(_dummy), LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
2011-04-21 07:47:54 +02:00
|
|
|
SpiDrv::waitResponseParams(GET_IPADDR_CMD, PARAM_NUMS_3, params);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public Methods
|
|
|
|
|
|
|
|
|
|
|
|
void WiFiDrv::wifiDriverInit()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::begin();
|
2011-03-08 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(SET_NET_CMD, PARAM_NUMS_1);
|
|
|
|
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _data = 0;
|
|
|
|
uint8_t _dataLen = 0;
|
2011-04-21 07:47:54 +02:00
|
|
|
if (!SpiDrv::waitResponseCmd(SET_NET_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
2011-03-08 22:13:54 +01:00
|
|
|
{
|
|
|
|
WARN("error waitResponse");
|
|
|
|
}
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return(_data == WIFI_SPI_ACK) ? WL_SUCCESS : WL_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len)
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(SET_PASSPHRASE_CMD, PARAM_NUMS_2);
|
|
|
|
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, NO_LAST_PARAM);
|
|
|
|
SpiDrv::sendParam((uint8_t*)passphrase, len, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _data = 0;
|
|
|
|
uint8_t _dataLen = 0;
|
2011-04-21 07:47:54 +02:00
|
|
|
if (!SpiDrv::waitResponseCmd(SET_PASSPHRASE_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
2011-03-08 22:13:54 +01:00
|
|
|
{
|
|
|
|
WARN("error waitResponse");
|
|
|
|
}
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len)
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(SET_KEY_CMD, PARAM_NUMS_3);
|
|
|
|
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, NO_LAST_PARAM);
|
|
|
|
SpiDrv::sendParam(&key_idx, KEY_IDX_LEN, NO_LAST_PARAM);
|
|
|
|
SpiDrv::sendParam((uint8_t*)key, len, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _data = 0;
|
|
|
|
uint8_t _dataLen = 0;
|
2011-04-21 07:47:54 +02:00
|
|
|
if (!SpiDrv::waitResponseCmd(SET_KEY_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
2011-03-08 22:13:54 +01:00
|
|
|
{
|
|
|
|
WARN("error waitResponse");
|
|
|
|
}
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::disconnect()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(DISCONNECT_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _data = 0;
|
|
|
|
uint8_t _dataLen = 0;
|
2011-04-21 07:47:54 +02:00
|
|
|
uint8_t result = SpiDrv::waitResponseCmd(DISCONNECT_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::getConnectionStatus()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Send Command
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::sendCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_0);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _data = 0;
|
|
|
|
uint8_t _dataLen = 0;
|
2011-04-21 07:47:54 +02:00
|
|
|
SpiDrv::waitResponseCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* WiFiDrv::getMacAddress()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_MACADDR_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _dataLen = 0;
|
2012-02-04 17:01:24 +01:00
|
|
|
SpiDrv::waitResponseCmd(GET_MACADDR_CMD, PARAM_NUMS_1, _mac, &_dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return _mac;
|
|
|
|
}
|
|
|
|
|
2011-05-18 15:37:29 +02:00
|
|
|
void WiFiDrv::getIpAddress(IPAddress& ip)
|
2011-03-08 22:13:54 +01:00
|
|
|
{
|
|
|
|
getNetworkData(_localIp, _subnetMask, _gatewayIp);
|
2011-05-18 15:37:29 +02:00
|
|
|
ip = _localIp;
|
2011-03-08 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-07 00:05:54 +01:00
|
|
|
void WiFiDrv::getSubnetMask(IPAddress& mask)
|
2011-03-08 22:13:54 +01:00
|
|
|
{
|
|
|
|
getNetworkData(_localIp, _subnetMask, _gatewayIp);
|
2012-03-07 00:05:54 +01:00
|
|
|
mask = _subnetMask;
|
2011-03-08 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
2011-05-18 15:37:29 +02:00
|
|
|
void WiFiDrv::getGatewayIP(IPAddress& ip)
|
2011-03-08 22:13:54 +01:00
|
|
|
{
|
|
|
|
getNetworkData(_localIp, _subnetMask, _gatewayIp);
|
2011-05-18 15:37:29 +02:00
|
|
|
ip = _gatewayIp;
|
2011-03-08 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char* WiFiDrv::getCurrentSSID()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_CURR_SSID_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _dataLen = 0;
|
2012-02-04 17:01:24 +01:00
|
|
|
SpiDrv::waitResponseCmd(GET_CURR_SSID_CMD, PARAM_NUMS_1, (uint8_t*)_ssid, &_dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return _ssid;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* WiFiDrv::getCurrentBSSID()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_CURR_BSSID_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _dataLen = 0;
|
2012-02-04 17:01:24 +01:00
|
|
|
SpiDrv::waitResponseCmd(GET_CURR_BSSID_CMD, PARAM_NUMS_1, _bssid, &_dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return _bssid;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t WiFiDrv::getCurrentRSSI()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _dataLen = 0;
|
|
|
|
int32_t rssi = 0;
|
2012-02-04 17:01:24 +01:00
|
|
|
SpiDrv::waitResponseCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&rssi, &_dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return rssi;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::getCurrentEncryptionType()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
uint8_t _dummy = DUMMY_DATA;
|
|
|
|
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t dataLen = 0;
|
|
|
|
uint8_t encType = 0;
|
2012-03-04 11:42:48 +01:00
|
|
|
SpiDrv::waitResponseCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)&encType, &dataLen);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return encType;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::scanNetworks()
|
|
|
|
{
|
2011-04-05 23:24:17 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
// Send Command
|
2011-04-30 07:48:10 +02:00
|
|
|
SpiDrv::sendCmd(SCAN_NETWORKS, PARAM_NUMS_0);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
//Wait the reply elaboration
|
2011-04-05 23:24:17 +02:00
|
|
|
SpiDrv::waitForSlaveReady();
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t ssidListNum = 0;
|
2012-02-04 17:01:24 +01:00
|
|
|
SpiDrv::waitResponse(SCAN_NETWORKS, &ssidListNum, (uint8_t**)_networkSsid, WL_NETWORKS_LIST_MAXNUM);
|
2011-03-08 22:13:54 +01:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return ssidListNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* WiFiDrv::getSSIDNetoworks(uint8_t networkItem)
|
|
|
|
{
|
|
|
|
if (networkItem >= WL_NETWORKS_LIST_MAXNUM)
|
|
|
|
return NULL;
|
|
|
|
|
2011-04-05 23:24:17 +02:00
|
|
|
return _networkSsid[networkItem];
|
2011-03-08 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t WiFiDrv::getEncTypeNetowrks(uint8_t networkItem)
|
|
|
|
{
|
|
|
|
if (networkItem >= WL_NETWORKS_LIST_MAXNUM)
|
|
|
|
return NULL;
|
|
|
|
|
2012-03-04 11:42:48 +01:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_IDX_ENCT_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
SpiDrv::sendParam(&networkItem, 1, LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
|
|
|
SpiDrv::waitForSlaveReady();
|
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t dataLen = 0;
|
|
|
|
uint8_t encType = 0;
|
|
|
|
SpiDrv::waitResponseCmd(GET_IDX_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)&encType, &dataLen);
|
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return encType;
|
2011-03-08 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem)
|
|
|
|
{
|
|
|
|
if (networkItem >= WL_NETWORKS_LIST_MAXNUM)
|
|
|
|
return NULL;
|
|
|
|
int32_t networkRssi = 0;
|
|
|
|
|
2011-05-18 08:39:47 +02:00
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
|
|
|
// Send Command
|
2012-03-04 11:42:48 +01:00
|
|
|
SpiDrv::sendCmd(GET_IDX_RSSI_CMD, PARAM_NUMS_1);
|
|
|
|
|
|
|
|
SpiDrv::sendParam(&networkItem, 1, LAST_PARAM);
|
2011-05-18 08:39:47 +02:00
|
|
|
|
|
|
|
//Wait the reply elaboration
|
|
|
|
SpiDrv::waitForSlaveReady();
|
|
|
|
|
|
|
|
// Wait for reply
|
2012-03-04 11:42:48 +01:00
|
|
|
uint8_t dataLen = 0;
|
|
|
|
SpiDrv::waitResponseCmd(GET_IDX_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&networkRssi, &dataLen);
|
2011-05-18 08:39:47 +02:00
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
2012-03-04 11:42:48 +01:00
|
|
|
return networkRssi;
|
2011-05-18 08:39:47 +02:00
|
|
|
}
|
|
|
|
|
2012-03-15 01:18:43 +01:00
|
|
|
uint8_t WiFiDrv::reqHostByName(const char* aHostname)
|
|
|
|
{
|
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
|
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1);
|
|
|
|
SpiDrv::sendParam((uint8_t*)aHostname, strlen(aHostname), LAST_PARAM);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
|
|
|
SpiDrv::waitForSlaveReady();
|
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _data = 0;
|
|
|
|
uint8_t _dataLen = 0;
|
|
|
|
uint8_t result = SpiDrv::waitResponseCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
|
|
|
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WiFiDrv::getHostByName(IPAddress& aResult)
|
|
|
|
{
|
|
|
|
uint8_t _ipAddr[WL_IPV4_LENGTH];
|
|
|
|
IPAddress dummy(0xFF,0xFF,0xFF,0xFF);
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
WAIT_FOR_SLAVE_SELECT();
|
|
|
|
// Send Command
|
|
|
|
SpiDrv::sendCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_0);
|
|
|
|
|
|
|
|
//Wait the reply elaboration
|
|
|
|
SpiDrv::waitForSlaveReady();
|
|
|
|
|
|
|
|
// Wait for reply
|
|
|
|
uint8_t _dataLen = 0;
|
|
|
|
if (!SpiDrv::waitResponseCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_1, _ipAddr, &_dataLen))
|
|
|
|
{
|
|
|
|
WARN("error waitResponse");
|
|
|
|
}else{
|
|
|
|
aResult = _ipAddr;
|
|
|
|
result = (aResult != dummy);
|
|
|
|
}
|
|
|
|
SpiDrv::spiSlaveDeselect();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WiFiDrv::getHostByName(const char* aHostname, IPAddress& aResult)
|
|
|
|
{
|
|
|
|
uint8_t retry = 10;
|
|
|
|
if (reqHostByName(aHostname))
|
|
|
|
{
|
|
|
|
while(!getHostByName(aResult) && --retry > 0)
|
|
|
|
{
|
2012-05-20 23:54:32 +02:00
|
|
|
delay(1000);
|
2012-03-15 01:18:43 +01:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-05-20 23:54:32 +02:00
|
|
|
return (retry>0);
|
2012-03-15 01:18:43 +01:00
|
|
|
}
|
|
|
|
|
2011-03-08 22:13:54 +01:00
|
|
|
WiFiDrv wiFiDrv;
|