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 <Mailbox.h> 20 21unsigned intMailboxClass::readMessage(uint8_t*buff,unsigned int size) { 22uint8_t tmp[] = {'m'}; 23return bridge.transfer(tmp,1, buff, size); 24} 25 26voidMailboxClass::readMessage(String &str,unsigned int maxLength) { 27uint8_t tmp[] = {'m'}; 28// XXX: Is there a better way to create the string? 29uint8_t buff[maxLength +1]; 30int l = bridge.transfer(tmp,1, buff, maxLength); 31 buff[l] =0; 32 str = (const char*)buff; 33} 34 35voidMailboxClass::writeMessage(const uint8_t*buff,unsigned int size) { 36uint8_t cmd[] = {'M'}; 37 bridge.transfer(cmd,1, buff, size, NULL,0); 38} 39 40voidMailboxClass::writeMessage(const String& str) { 41writeMessage((uint8_t*) str.c_str(), str.length()); 42} 43 44voidMailboxClass::writeJSON(const String& str) { 45uint8_t cmd[] = {'J'}; 46 bridge.transfer(cmd,1, (uint8_t*) str.c_str(), str.length(), NULL,0); 47} 48 49unsigned intMailboxClass::messageAvailable() { 50uint8_t tmp[] = {'n'}; 51uint8_t res[2]; 52 bridge.transfer(tmp,1, res,2); 53return(res[0] <<8) + res[1]; 54} 55 56MailboxClass Mailbox(Bridge);