1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Added Client connection and WebClient example

This commit is contained in:
mlafauci
2011-04-24 00:45:47 +02:00
parent ca1a1d8a9d
commit c10210a881
6 changed files with 139 additions and 13 deletions

View File

@ -33,6 +33,29 @@ void ServerDrv::StartServer(uint16_t port, uint8_t sock)
SpiDrv::spiSlaveDeselect();
}
// Start server TCP on port specified
void ServerDrv::StartClient(uint32_t ipAddress, uint16_t port, uint8_t sock)
{
WAIT_FOR_SLAVE_SELECT();
INFO2(ipAddress,port);
// Send Command
SpiDrv::sendCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_3);
SpiDrv::sendParam((uint8_t*)&ipAddress, sizeof(ipAddress));
SpiDrv::sendParam(port);
SpiDrv::sendParam(&sock, 1, LAST_PARAM);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
if (!SpiDrv::waitResponseCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse");
}
SpiDrv::spiSlaveDeselect();
}
uint8_t ServerDrv::getState(uint8_t sock)
{

View File

@ -9,6 +9,8 @@ class ServerDrv
public:
// Start server TCP on port specified
static void StartServer(uint16_t port, uint8_t sock);
static void StartClient(uint32_t ipAddress, uint16_t port, uint8_t sock);
static uint8_t getState(uint8_t sock);

View File

@ -426,7 +426,6 @@ void SpiDrv::sendParamLen8(uint8_t param_len)
spiTransfer(param_len);
}
void SpiDrv::sendParamLen16(uint16_t param_len)
{
// Send Spi paramLen
@ -434,7 +433,6 @@ void SpiDrv::sendParamLen16(uint16_t param_len)
spiTransfer((uint8_t)(param_len & 0xff));
}
uint8_t SpiDrv::readParamLen8(uint8_t* param_len)
{
uint8_t _param_len = spiTransfer(DUMMY_DATA);

View File

@ -38,6 +38,7 @@ enum {
DATA_SENT_TCP_CMD = 0x2A,
AVAIL_DATA_TCP_CMD = 0x2B,
GET_DATA_TCP_CMD = 0x2C,
START_CLIENT_TCP_CMD= 0x2D,
DISCONNECT_CMD = 0x30,
// All command with DATA_FLAG 0x40 send a 16bit Len
@ -113,4 +114,22 @@ typedef struct __attribute__((__packed__))
unsigned char nParam;
}tSpiHdr;
typedef struct __attribute__((__packed__))
{
uint8_t paramLen;
uint32_t param;
}tLongParam;
typedef struct __attribute__((__packed__))
{
uint8_t paramLen;
uint16_t param;
}tIntParam;
typedef struct __attribute__((__packed__))
{
uint8_t paramLen;
uint8_t param;
}tByteParam;
#endif