1/* 2 Copyright (c) 2013 Arduino LLC. All right reserved. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17*/ 18 19#include <BridgeServer.h> 20#include <BridgeClient.h> 21 22BridgeServer::BridgeServer(uint16_t _p, BridgeClass &_b) : 23bridge(_b),port(_p),listening(false),useLocalhost(false) { 24} 25 26voidBridgeServer::begin() { 27uint8_t tmp[] = { 28'N', 29static_cast<uint8_t>(port >>8), 30static_cast<uint8_t>(port) 31}; 32uint8_t res[1]; 33 String address =F("127.0.0.1"); 34if(!useLocalhost) 35 address =F("0.0.0.0"); 36 bridge.transfer(tmp,3, (const uint8_t*)address.c_str(), address.length(), res,1); 37 listening = (res[0] ==1); 38} 39 40BridgeClient BridgeServer::accept() { 41uint8_t cmd[] = {'k'}; 42uint8_t res[1]; 43unsigned int l = bridge.transfer(cmd,1, res,1); 44if(l ==0) 45returnBridgeClient(); 46returnBridgeClient(res[0]); 47} 48 49size_tBridgeServer::write(uint8_t c) { 50uint8_t cmd[] = {'b', c }; 51 bridge.transfer(cmd,2); 52return1; 53} 54