mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Bridge: Renamed YunClient/YunServer to BridgeClient/BridgeServer
This makes the library more consistent and not tied to a specific board.
This commit is contained in:
parent
954f59d9ce
commit
0c109b5242
@ -23,12 +23,12 @@
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <YunServer.h>
|
||||
#include <YunClient.h>
|
||||
#include <BridgeServer.h>
|
||||
#include <BridgeClient.h>
|
||||
|
||||
// Listen to the default port 5555, the Yún webserver
|
||||
// will forward there all the HTTP requests you send
|
||||
YunServer server;
|
||||
BridgeServer server;
|
||||
|
||||
void setup() {
|
||||
// Bridge startup
|
||||
@ -45,7 +45,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// Get clients coming from server
|
||||
YunClient client = server.accept();
|
||||
BridgeClient client = server.accept();
|
||||
|
||||
// There is a new client?
|
||||
if (client) {
|
||||
@ -59,7 +59,7 @@ void loop() {
|
||||
delay(50); // Poll every 50ms
|
||||
}
|
||||
|
||||
void process(YunClient client) {
|
||||
void process(BridgeClient client) {
|
||||
// read the command
|
||||
String command = client.readStringUntil('/');
|
||||
|
||||
@ -79,7 +79,7 @@ void process(YunClient client) {
|
||||
}
|
||||
}
|
||||
|
||||
void digitalCommand(YunClient client) {
|
||||
void digitalCommand(BridgeClient client) {
|
||||
int pin, value;
|
||||
|
||||
// Read pin number
|
||||
@ -107,7 +107,7 @@ void digitalCommand(YunClient client) {
|
||||
Bridge.put(key, String(value));
|
||||
}
|
||||
|
||||
void analogCommand(YunClient client) {
|
||||
void analogCommand(BridgeClient client) {
|
||||
int pin, value;
|
||||
|
||||
// Read pin number
|
||||
@ -148,7 +148,7 @@ void analogCommand(YunClient client) {
|
||||
}
|
||||
}
|
||||
|
||||
void modeCommand(YunClient client) {
|
||||
void modeCommand(BridgeClient client) {
|
||||
int pin;
|
||||
|
||||
// Read pin number
|
||||
|
@ -36,12 +36,12 @@
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <YunServer.h>
|
||||
#include <YunClient.h>
|
||||
#include <BridgeServer.h>
|
||||
#include <BridgeClient.h>
|
||||
|
||||
// Listen on default port 5555, the webserver on the Yún
|
||||
// will forward there all the HTTP requests for us.
|
||||
YunServer server;
|
||||
BridgeServer server;
|
||||
String startString;
|
||||
long hits = 0;
|
||||
|
||||
@ -76,7 +76,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// Get clients coming from server
|
||||
YunClient client = server.accept();
|
||||
BridgeClient client = server.accept();
|
||||
|
||||
// There is a new client?
|
||||
if (client) {
|
||||
|
@ -15,6 +15,8 @@ Mailbox KEYWORD1 YunMailboxConstructor
|
||||
HttpClient KEYWORD1 YunHttpClientConstructor
|
||||
YunServer KEYWORD1 YunServerConstructor
|
||||
YunClient KEYWORD1 YunClientConstructor
|
||||
BridgeServer KEYWORD1 YunServerConstructor
|
||||
BridgeClient KEYWORD1 YunClientConstructor
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
@ -72,7 +74,7 @@ getAsynchronously KEYWORD2
|
||||
ready KEYWORD2
|
||||
getResult KEYWORD2
|
||||
|
||||
# YunServer Class
|
||||
# BridgeServer Class
|
||||
accept KEYWORD2
|
||||
stop KEYWORD2
|
||||
connect KEYWORD2
|
||||
|
@ -16,26 +16,26 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <YunClient.h>
|
||||
#include <BridgeClient.h>
|
||||
|
||||
YunClient::YunClient(int _h, BridgeClass &_b) :
|
||||
BridgeClient::BridgeClient(int _h, BridgeClass &_b) :
|
||||
bridge(_b), handle(_h), opened(true), buffered(0) {
|
||||
}
|
||||
|
||||
YunClient::YunClient(BridgeClass &_b) :
|
||||
BridgeClient::BridgeClient(BridgeClass &_b) :
|
||||
bridge(_b), handle(0), opened(false), buffered(0) {
|
||||
}
|
||||
|
||||
YunClient::~YunClient() {
|
||||
BridgeClient::~BridgeClient() {
|
||||
}
|
||||
|
||||
YunClient& YunClient::operator=(const YunClient &_x) {
|
||||
BridgeClient& BridgeClient::operator=(const BridgeClient &_x) {
|
||||
opened = _x.opened;
|
||||
handle = _x.handle;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void YunClient::stop() {
|
||||
void BridgeClient::stop() {
|
||||
if (opened) {
|
||||
uint8_t cmd[] = {'j', handle};
|
||||
bridge.transfer(cmd, 2);
|
||||
@ -45,7 +45,7 @@ void YunClient::stop() {
|
||||
readPos = 0;
|
||||
}
|
||||
|
||||
void YunClient::doBuffer() {
|
||||
void BridgeClient::doBuffer() {
|
||||
// If there are already char in buffer exit
|
||||
if (buffered > 0)
|
||||
return;
|
||||
@ -56,13 +56,13 @@ void YunClient::doBuffer() {
|
||||
buffered = bridge.transfer(cmd, 3, buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
int YunClient::available() {
|
||||
int BridgeClient::available() {
|
||||
// Look if there is new data available
|
||||
doBuffer();
|
||||
return buffered;
|
||||
}
|
||||
|
||||
int YunClient::read() {
|
||||
int BridgeClient::read() {
|
||||
doBuffer();
|
||||
if (buffered == 0)
|
||||
return -1; // no chars available
|
||||
@ -72,7 +72,7 @@ int YunClient::read() {
|
||||
}
|
||||
}
|
||||
|
||||
int YunClient::read(uint8_t *buff, size_t size) {
|
||||
int BridgeClient::read(uint8_t *buff, size_t size) {
|
||||
int readed = 0;
|
||||
do {
|
||||
if (buffered == 0) {
|
||||
@ -86,7 +86,7 @@ int YunClient::read(uint8_t *buff, size_t size) {
|
||||
return readed;
|
||||
}
|
||||
|
||||
int YunClient::peek() {
|
||||
int BridgeClient::peek() {
|
||||
doBuffer();
|
||||
if (buffered == 0)
|
||||
return -1; // no chars available
|
||||
@ -94,7 +94,7 @@ int YunClient::peek() {
|
||||
return buffer[readPos];
|
||||
}
|
||||
|
||||
size_t YunClient::write(uint8_t c) {
|
||||
size_t BridgeClient::write(uint8_t c) {
|
||||
if (!opened)
|
||||
return 0;
|
||||
uint8_t cmd[] = {'l', handle, c};
|
||||
@ -102,7 +102,7 @@ size_t YunClient::write(uint8_t c) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t YunClient::write(const uint8_t *buf, size_t size) {
|
||||
size_t BridgeClient::write(const uint8_t *buf, size_t size) {
|
||||
if (!opened)
|
||||
return 0;
|
||||
uint8_t cmd[] = {'l', handle};
|
||||
@ -110,10 +110,10 @@ size_t YunClient::write(const uint8_t *buf, size_t size) {
|
||||
return size;
|
||||
}
|
||||
|
||||
void YunClient::flush() {
|
||||
void BridgeClient::flush() {
|
||||
}
|
||||
|
||||
uint8_t YunClient::connected() {
|
||||
uint8_t BridgeClient::connected() {
|
||||
if (!opened)
|
||||
return false;
|
||||
// Client is "connected" if it has unread bytes
|
||||
@ -126,7 +126,7 @@ uint8_t YunClient::connected() {
|
||||
return (res[0] == 1);
|
||||
}
|
||||
|
||||
int YunClient::connect(IPAddress ip, uint16_t port) {
|
||||
int BridgeClient::connect(IPAddress ip, uint16_t port) {
|
||||
String address;
|
||||
address.reserve(18);
|
||||
address += ip[0];
|
||||
@ -139,7 +139,7 @@ int YunClient::connect(IPAddress ip, uint16_t port) {
|
||||
return connect(address.c_str(), port);
|
||||
}
|
||||
|
||||
int YunClient::connect(const char *host, uint16_t port) {
|
||||
int BridgeClient::connect(const char *host, uint16_t port) {
|
||||
uint8_t tmp[] = {
|
||||
'C',
|
||||
(port >> 8) & 0xFF,
|
@ -16,18 +16,18 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _YUN_CLIENT_H_
|
||||
#define _YUN_CLIENT_H_
|
||||
#ifndef _BRIDGE_CLIENT_H_
|
||||
#define _BRIDGE_CLIENT_H_
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Client.h>
|
||||
|
||||
class YunClient : public Client {
|
||||
class BridgeClient : public Client {
|
||||
public:
|
||||
// Constructor with a user provided BridgeClass instance
|
||||
YunClient(int _h, BridgeClass &_b = Bridge);
|
||||
YunClient(BridgeClass &_b = Bridge);
|
||||
~YunClient();
|
||||
BridgeClient(int _h, BridgeClass &_b = Bridge);
|
||||
BridgeClient(BridgeClass &_b = Bridge);
|
||||
~BridgeClient();
|
||||
|
||||
// Stream methods
|
||||
// (read message)
|
||||
@ -45,7 +45,7 @@ class YunClient : public Client {
|
||||
return opened;
|
||||
}
|
||||
|
||||
YunClient& operator=(const YunClient &_x);
|
||||
BridgeClient& operator=(const BridgeClient &_x);
|
||||
|
||||
virtual void stop();
|
||||
virtual uint8_t connected();
|
||||
@ -67,4 +67,4 @@ class YunClient : public Client {
|
||||
|
||||
};
|
||||
|
||||
#endif // _YUN_CLIENT_H_
|
||||
#endif // _BRIDGE_CLIENT_H_
|
@ -16,14 +16,14 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <YunServer.h>
|
||||
#include <YunClient.h>
|
||||
#include <BridgeServer.h>
|
||||
#include <BridgeClient.h>
|
||||
|
||||
YunServer::YunServer(uint16_t _p, BridgeClass &_b) :
|
||||
BridgeServer::BridgeServer(uint16_t _p, BridgeClass &_b) :
|
||||
bridge(_b), port(_p), listening(false), useLocalhost(false) {
|
||||
}
|
||||
|
||||
void YunServer::begin() {
|
||||
void BridgeServer::begin() {
|
||||
uint8_t tmp[] = {
|
||||
'N',
|
||||
(port >> 8) & 0xFF,
|
||||
@ -37,16 +37,16 @@ void YunServer::begin() {
|
||||
listening = (res[0] == 1);
|
||||
}
|
||||
|
||||
YunClient YunServer::accept() {
|
||||
BridgeClient BridgeServer::accept() {
|
||||
uint8_t cmd[] = {'k'};
|
||||
uint8_t res[1];
|
||||
unsigned int l = bridge.transfer(cmd, 1, res, 1);
|
||||
if (l == 0)
|
||||
return YunClient();
|
||||
return YunClient(res[0]);
|
||||
return BridgeClient();
|
||||
return BridgeClient(res[0]);
|
||||
}
|
||||
|
||||
size_t YunServer::write(uint8_t c) {
|
||||
size_t BridgeServer::write(uint8_t c) {
|
||||
uint8_t cmd[] = { 'b', c };
|
||||
bridge.transfer(cmd, 2);
|
||||
return 1;
|
@ -16,21 +16,21 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _YUN_SERVER_H_
|
||||
#define _YUN_SERVER_H_
|
||||
#ifndef _BRIDGE_SERVER_H_
|
||||
#define _BRIDGE_SERVER_H_
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Server.h>
|
||||
|
||||
class YunClient;
|
||||
class BridgeClient;
|
||||
|
||||
class YunServer : public Server {
|
||||
class BridgeServer : public Server {
|
||||
public:
|
||||
// Constructor with a user provided BridgeClass instance
|
||||
YunServer(uint16_t port = 5555, BridgeClass &_b = Bridge);
|
||||
BridgeServer(uint16_t port = 5555, BridgeClass &_b = Bridge);
|
||||
|
||||
void begin();
|
||||
YunClient accept();
|
||||
BridgeClient accept();
|
||||
|
||||
virtual size_t write(uint8_t c);
|
||||
|
||||
@ -48,4 +48,4 @@ class YunServer : public Server {
|
||||
BridgeClass &bridge;
|
||||
};
|
||||
|
||||
#endif // _YUN_SERVER_H_
|
||||
#endif // _BRIDGE_SERVER_H_
|
Loading…
Reference in New Issue
Block a user